2014-12-12 Marc Glisse <marc.glisse@inria.fr>
[official-gcc.git] / gcc / ada / sem_util.adb
blobfced97839664e3f33ed8ee271629cc0e85b76f39
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
38 with Lib; use Lib;
39 with Lib.Xref; use Lib.Xref;
40 with Namet.Sp; use Namet.Sp;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Output; use Output;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
47 with Sem; use Sem;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Attr; use Sem_Attr;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch13; use Sem_Ch13;
52 with Sem_Disp; use Sem_Disp;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Res; use Sem_Res;
56 with Sem_Warn; use Sem_Warn;
57 with Sem_Type; use Sem_Type;
58 with Sinfo; use Sinfo;
59 with Sinput; use Sinput;
60 with Stand; use Stand;
61 with Style;
62 with Stringt; use Stringt;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Ttypes; use Ttypes;
66 with Uname; use Uname;
68 with GNAT.HTable; use GNAT.HTable;
70 package body Sem_Util is
72 ----------------------------------------
73 -- Global_Variables for New_Copy_Tree --
74 ----------------------------------------
76 -- These global variables are used by New_Copy_Tree. See description of the
77 -- body of this subprogram for details. Global variables can be safely used
78 -- by New_Copy_Tree, since there is no case of a recursive call from the
79 -- processing inside New_Copy_Tree.
81 NCT_Hash_Threshold : constant := 20;
82 -- If there are more than this number of pairs of entries in the map, then
83 -- Hash_Tables_Used will be set, and the hash tables will be initialized
84 -- and used for the searches.
86 NCT_Hash_Tables_Used : Boolean := False;
87 -- Set to True if hash tables are in use
89 NCT_Table_Entries : Nat := 0;
90 -- Count entries in table to see if threshold is reached
92 NCT_Hash_Table_Setup : Boolean := False;
93 -- Set to True if hash table contains data. We set this True if we setup
94 -- the hash table with data, and leave it set permanently from then on,
95 -- this is a signal that second and subsequent users of the hash table
96 -- must clear the old entries before reuse.
98 subtype NCT_Header_Num is Int range 0 .. 511;
99 -- Defines range of headers in hash tables (512 headers)
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 function Build_Component_Subtype
106 (C : List_Id;
107 Loc : Source_Ptr;
108 T : Entity_Id) return Node_Id;
109 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
110 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
111 -- Loc is the source location, T is the original subtype.
113 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
114 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
115 -- with discriminants whose default values are static, examine only the
116 -- components in the selected variant to determine whether all of them
117 -- have a default.
119 function Has_Enabled_Property
120 (Item_Id : Entity_Id;
121 Property : Name_Id) return Boolean;
122 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
123 -- Determine whether an abstract state or a variable denoted by entity
124 -- Item_Id has enabled property Property.
126 function Has_Null_Extension (T : Entity_Id) return Boolean;
127 -- T is a derived tagged type. Check whether the type extension is null.
128 -- If the parent type is fully initialized, T can be treated as such.
130 ------------------------------
131 -- Abstract_Interface_List --
132 ------------------------------
134 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
135 Nod : Node_Id;
137 begin
138 if Is_Concurrent_Type (Typ) then
140 -- If we are dealing with a synchronized subtype, go to the base
141 -- type, whose declaration has the interface list.
143 -- Shouldn't this be Declaration_Node???
145 Nod := Parent (Base_Type (Typ));
147 if Nkind (Nod) = N_Full_Type_Declaration then
148 return Empty_List;
149 end if;
151 elsif Ekind (Typ) = E_Record_Type_With_Private then
152 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
153 Nod := Type_Definition (Parent (Typ));
155 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
156 if Present (Full_View (Typ))
157 and then
158 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
159 then
160 Nod := Type_Definition (Parent (Full_View (Typ)));
162 -- If the full-view is not available we cannot do anything else
163 -- here (the source has errors).
165 else
166 return Empty_List;
167 end if;
169 -- Support for generic formals with interfaces is still missing ???
171 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
172 return Empty_List;
174 else
175 pragma Assert
176 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
177 Nod := Parent (Typ);
178 end if;
180 elsif Ekind (Typ) = E_Record_Subtype then
181 Nod := Type_Definition (Parent (Etype (Typ)));
183 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
185 -- Recurse, because parent may still be a private extension. Also
186 -- note that the full view of the subtype or the full view of its
187 -- base type may (both) be unavailable.
189 return Abstract_Interface_List (Etype (Typ));
191 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
192 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
193 Nod := Formal_Type_Definition (Parent (Typ));
194 else
195 Nod := Type_Definition (Parent (Typ));
196 end if;
197 end if;
199 return Interface_List (Nod);
200 end Abstract_Interface_List;
202 --------------------------------
203 -- Add_Access_Type_To_Process --
204 --------------------------------
206 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
207 L : Elist_Id;
209 begin
210 Ensure_Freeze_Node (E);
211 L := Access_Types_To_Process (Freeze_Node (E));
213 if No (L) then
214 L := New_Elmt_List;
215 Set_Access_Types_To_Process (Freeze_Node (E), L);
216 end if;
218 Append_Elmt (A, L);
219 end Add_Access_Type_To_Process;
221 --------------------------
222 -- Add_Block_Identifier --
223 --------------------------
225 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
226 Loc : constant Source_Ptr := Sloc (N);
228 begin
229 pragma Assert (Nkind (N) = N_Block_Statement);
231 -- The block already has a label, return its entity
233 if Present (Identifier (N)) then
234 Id := Entity (Identifier (N));
236 -- Create a new block label and set its attributes
238 else
239 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
240 Set_Etype (Id, Standard_Void_Type);
241 Set_Parent (Id, N);
243 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
244 Set_Block_Node (Id, Identifier (N));
245 end if;
246 end Add_Block_Identifier;
248 -----------------------
249 -- Add_Contract_Item --
250 -----------------------
252 procedure Add_Contract_Item (Prag : Node_Id; Id : Entity_Id) is
253 Items : constant Node_Id := Contract (Id);
255 procedure Add_Classification;
256 -- Prepend Prag to the list of classifications
258 procedure Add_Contract_Test_Case;
259 -- Prepend Prag to the list of contract and test cases
261 procedure Add_Pre_Post_Condition;
262 -- Prepend Prag to the list of pre- and postconditions
264 ------------------------
265 -- Add_Classification --
266 ------------------------
268 procedure Add_Classification is
269 begin
270 Set_Next_Pragma (Prag, Classifications (Items));
271 Set_Classifications (Items, Prag);
272 end Add_Classification;
274 ----------------------------
275 -- Add_Contract_Test_Case --
276 ----------------------------
278 procedure Add_Contract_Test_Case is
279 begin
280 Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
281 Set_Contract_Test_Cases (Items, Prag);
282 end Add_Contract_Test_Case;
284 ----------------------------
285 -- Add_Pre_Post_Condition --
286 ----------------------------
288 procedure Add_Pre_Post_Condition is
289 begin
290 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
291 Set_Pre_Post_Conditions (Items, Prag);
292 end Add_Pre_Post_Condition;
294 -- Local variables
296 Nam : Name_Id;
297 PPC : Node_Id;
299 -- Start of processing for Add_Contract_Item
301 begin
302 -- The related context must have a contract and the item to be added
303 -- must be a pragma.
305 pragma Assert (Present (Items));
306 pragma Assert (Nkind (Prag) = N_Pragma);
308 Nam := Original_Aspect_Name (Prag);
310 -- Contract items related to [generic] packages or instantiations. The
311 -- applicable pragmas are:
312 -- Abstract_States
313 -- Initial_Condition
314 -- Initializes
315 -- Part_Of (instantiation only)
317 if Ekind_In (Id, E_Generic_Package, E_Package) then
318 if Nam_In (Nam, Name_Abstract_State,
319 Name_Initial_Condition,
320 Name_Initializes)
321 then
322 Add_Classification;
324 -- Indicator Part_Of must be associated with a package instantiation
326 elsif Nam = Name_Part_Of and then Is_Generic_Instance (Id) then
327 Add_Classification;
329 -- The pragma is not a proper contract item
331 else
332 raise Program_Error;
333 end if;
335 -- Contract items related to package bodies. The applicable pragmas are:
336 -- Refined_States
338 elsif Ekind (Id) = E_Package_Body then
339 if Nam = Name_Refined_State then
340 Add_Classification;
342 -- The pragma is not a proper contract item
344 else
345 raise Program_Error;
346 end if;
348 -- Contract items related to subprogram or entry declarations. The
349 -- applicable pragmas are:
350 -- Contract_Cases
351 -- Depends
352 -- Extensions_Visible
353 -- Global
354 -- Post
355 -- Postcondition
356 -- Pre
357 -- Precondition
358 -- Test_Case
360 elsif Ekind_In (Id, E_Entry, E_Entry_Family)
361 or else Is_Generic_Subprogram (Id)
362 or else Is_Subprogram (Id)
363 then
364 if Nam_In (Nam, Name_Pre,
365 Name_Precondition,
366 Name_uPre,
367 Name_Post,
368 Name_Postcondition,
369 Name_uPost)
370 then
371 -- Before we add a precondition or postcondition to the list, make
372 -- sure we do not have a disallowed duplicate, which can happen if
373 -- we use a pragma for Pre[_Class] or Post[_Class] instead of the
374 -- corresponding aspect.
376 if not From_Aspect_Specification (Prag)
377 and then Nam_In (Nam, Name_Pre,
378 Name_uPre,
379 Name_Post,
380 Name_Post_Class)
381 then
382 PPC := Pre_Post_Conditions (Items);
383 while Present (PPC) loop
384 if not Split_PPC (PPC)
385 and then Original_Aspect_Name (PPC) = Nam
386 then
387 Error_Msg_Sloc := Sloc (PPC);
388 Error_Msg_NE
389 ("duplication of aspect for & given#", Prag, Id);
390 return;
391 end if;
393 PPC := Next_Pragma (PPC);
394 end loop;
395 end if;
397 Add_Pre_Post_Condition;
399 elsif Nam_In (Nam, Name_Contract_Cases, Name_Test_Case) then
400 Add_Contract_Test_Case;
402 elsif Nam_In (Nam, Name_Depends,
403 Name_Extensions_Visible,
404 Name_Global)
405 then
406 Add_Classification;
408 -- The pragma is not a proper contract item
410 else
411 raise Program_Error;
412 end if;
414 -- Contract items related to subprogram bodies. Applicable pragmas are:
415 -- Refined_Depends
416 -- Refined_Global
417 -- Refined_Post
419 elsif Ekind (Id) = E_Subprogram_Body then
420 if Nam_In (Nam, Name_Refined_Depends, Name_Refined_Global) then
421 Add_Classification;
423 elsif Nam = Name_Refined_Post then
424 Add_Pre_Post_Condition;
426 -- The pragma is not a proper contract item
428 else
429 raise Program_Error;
430 end if;
432 -- Contract items related to variables. Applicable pragmas are:
433 -- Async_Readers
434 -- Async_Writers
435 -- Effective_Reads
436 -- Effective_Writes
437 -- Part_Of
439 elsif Ekind (Id) = E_Variable then
440 if Nam_In (Nam, Name_Async_Readers,
441 Name_Async_Writers,
442 Name_Effective_Reads,
443 Name_Effective_Writes,
444 Name_Part_Of)
445 then
446 Add_Classification;
448 -- The pragma is not a proper contract item
450 else
451 raise Program_Error;
452 end if;
453 end if;
454 end Add_Contract_Item;
456 ----------------------------
457 -- Add_Global_Declaration --
458 ----------------------------
460 procedure Add_Global_Declaration (N : Node_Id) is
461 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
463 begin
464 if No (Declarations (Aux_Node)) then
465 Set_Declarations (Aux_Node, New_List);
466 end if;
468 Append_To (Declarations (Aux_Node), N);
469 Analyze (N);
470 end Add_Global_Declaration;
472 --------------------------------
473 -- Address_Integer_Convert_OK --
474 --------------------------------
476 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
477 begin
478 if Allow_Integer_Address
479 and then ((Is_Descendent_Of_Address (T1)
480 and then Is_Private_Type (T1)
481 and then Is_Integer_Type (T2))
482 or else
483 (Is_Descendent_Of_Address (T2)
484 and then Is_Private_Type (T2)
485 and then Is_Integer_Type (T1)))
486 then
487 return True;
488 else
489 return False;
490 end if;
491 end Address_Integer_Convert_OK;
493 -----------------
494 -- Addressable --
495 -----------------
497 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
499 function Addressable (V : Uint) return Boolean is
500 begin
501 return V = Uint_8 or else
502 V = Uint_16 or else
503 V = Uint_32 or else
504 V = Uint_64;
505 end Addressable;
507 function Addressable (V : Int) return Boolean is
508 begin
509 return V = 8 or else
510 V = 16 or else
511 V = 32 or else
512 V = 64;
513 end Addressable;
515 ---------------------------------
516 -- Aggregate_Constraint_Checks --
517 ---------------------------------
519 procedure Aggregate_Constraint_Checks
520 (Exp : Node_Id;
521 Check_Typ : Entity_Id)
523 Exp_Typ : constant Entity_Id := Etype (Exp);
525 begin
526 if Raises_Constraint_Error (Exp) then
527 return;
528 end if;
530 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
531 -- component's type to force the appropriate accessibility checks.
533 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
534 -- type to force the corresponding run-time check
536 if Is_Access_Type (Check_Typ)
537 and then ((Is_Local_Anonymous_Access (Check_Typ))
538 or else (Can_Never_Be_Null (Check_Typ)
539 and then not Can_Never_Be_Null (Exp_Typ)))
540 then
541 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
542 Analyze_And_Resolve (Exp, Check_Typ);
543 Check_Unset_Reference (Exp);
544 end if;
546 -- This is really expansion activity, so make sure that expansion is
547 -- on and is allowed. In GNATprove mode, we also want check flags to
548 -- be added in the tree, so that the formal verification can rely on
549 -- those to be present. In GNATprove mode for formal verification, some
550 -- treatment typically only done during expansion needs to be performed
551 -- on the tree, but it should not be applied inside generics. Otherwise,
552 -- this breaks the name resolution mechanism for generic instances.
554 if not Expander_Active
555 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
556 then
557 return;
558 end if;
560 -- First check if we have to insert discriminant checks
562 if Has_Discriminants (Exp_Typ) then
563 Apply_Discriminant_Check (Exp, Check_Typ);
565 -- Next emit length checks for array aggregates
567 elsif Is_Array_Type (Exp_Typ) then
568 Apply_Length_Check (Exp, Check_Typ);
570 -- Finally emit scalar and string checks. If we are dealing with a
571 -- scalar literal we need to check by hand because the Etype of
572 -- literals is not necessarily correct.
574 elsif Is_Scalar_Type (Exp_Typ)
575 and then Compile_Time_Known_Value (Exp)
576 then
577 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
578 Apply_Compile_Time_Constraint_Error
579 (Exp, "value not in range of}??", CE_Range_Check_Failed,
580 Ent => Base_Type (Check_Typ),
581 Typ => Base_Type (Check_Typ));
583 elsif Is_Out_Of_Range (Exp, Check_Typ) then
584 Apply_Compile_Time_Constraint_Error
585 (Exp, "value not in range of}??", CE_Range_Check_Failed,
586 Ent => Check_Typ,
587 Typ => Check_Typ);
589 elsif not Range_Checks_Suppressed (Check_Typ) then
590 Apply_Scalar_Range_Check (Exp, Check_Typ);
591 end if;
593 -- Verify that target type is also scalar, to prevent view anomalies
594 -- in instantiations.
596 elsif (Is_Scalar_Type (Exp_Typ)
597 or else Nkind (Exp) = N_String_Literal)
598 and then Is_Scalar_Type (Check_Typ)
599 and then Exp_Typ /= Check_Typ
600 then
601 if Is_Entity_Name (Exp)
602 and then Ekind (Entity (Exp)) = E_Constant
603 then
604 -- If expression is a constant, it is worthwhile checking whether
605 -- it is a bound of the type.
607 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
608 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
609 or else
610 (Is_Entity_Name (Type_High_Bound (Check_Typ))
611 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
612 then
613 return;
615 else
616 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
617 Analyze_And_Resolve (Exp, Check_Typ);
618 Check_Unset_Reference (Exp);
619 end if;
621 -- Could use a comment on this case ???
623 else
624 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
625 Analyze_And_Resolve (Exp, Check_Typ);
626 Check_Unset_Reference (Exp);
627 end if;
629 end if;
630 end Aggregate_Constraint_Checks;
632 -----------------------
633 -- Alignment_In_Bits --
634 -----------------------
636 function Alignment_In_Bits (E : Entity_Id) return Uint is
637 begin
638 return Alignment (E) * System_Storage_Unit;
639 end Alignment_In_Bits;
641 ---------------------------------
642 -- Append_Inherited_Subprogram --
643 ---------------------------------
645 procedure Append_Inherited_Subprogram (S : Entity_Id) is
646 Par : constant Entity_Id := Alias (S);
647 -- The parent subprogram
649 Scop : constant Entity_Id := Scope (Par);
650 -- The scope of definition of the parent subprogram
652 Typ : constant Entity_Id := Defining_Entity (Parent (S));
653 -- The derived type of which S is a primitive operation
655 Decl : Node_Id;
656 Next_E : Entity_Id;
658 begin
659 if Ekind (Current_Scope) = E_Package
660 and then In_Private_Part (Current_Scope)
661 and then Has_Private_Declaration (Typ)
662 and then Is_Tagged_Type (Typ)
663 and then Scop = Current_Scope
664 then
665 -- The inherited operation is available at the earliest place after
666 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
667 -- relevant for type extensions. If the parent operation appears
668 -- after the type extension, the operation is not visible.
670 Decl := First
671 (Visible_Declarations
672 (Package_Specification (Current_Scope)));
673 while Present (Decl) loop
674 if Nkind (Decl) = N_Private_Extension_Declaration
675 and then Defining_Entity (Decl) = Typ
676 then
677 if Sloc (Decl) > Sloc (Par) then
678 Next_E := Next_Entity (Par);
679 Set_Next_Entity (Par, S);
680 Set_Next_Entity (S, Next_E);
681 return;
683 else
684 exit;
685 end if;
686 end if;
688 Next (Decl);
689 end loop;
690 end if;
692 -- If partial view is not a type extension, or it appears before the
693 -- subprogram declaration, insert normally at end of entity list.
695 Append_Entity (S, Current_Scope);
696 end Append_Inherited_Subprogram;
698 -----------------------------------------
699 -- Apply_Compile_Time_Constraint_Error --
700 -----------------------------------------
702 procedure Apply_Compile_Time_Constraint_Error
703 (N : Node_Id;
704 Msg : String;
705 Reason : RT_Exception_Code;
706 Ent : Entity_Id := Empty;
707 Typ : Entity_Id := Empty;
708 Loc : Source_Ptr := No_Location;
709 Rep : Boolean := True;
710 Warn : Boolean := False)
712 Stat : constant Boolean := Is_Static_Expression (N);
713 R_Stat : constant Node_Id :=
714 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
715 Rtyp : Entity_Id;
717 begin
718 if No (Typ) then
719 Rtyp := Etype (N);
720 else
721 Rtyp := Typ;
722 end if;
724 Discard_Node
725 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
727 if not Rep then
728 return;
729 end if;
731 -- Now we replace the node by an N_Raise_Constraint_Error node
732 -- This does not need reanalyzing, so set it as analyzed now.
734 Rewrite (N, R_Stat);
735 Set_Analyzed (N, True);
737 Set_Etype (N, Rtyp);
738 Set_Raises_Constraint_Error (N);
740 -- Now deal with possible local raise handling
742 Possible_Local_Raise (N, Standard_Constraint_Error);
744 -- If the original expression was marked as static, the result is
745 -- still marked as static, but the Raises_Constraint_Error flag is
746 -- always set so that further static evaluation is not attempted.
748 if Stat then
749 Set_Is_Static_Expression (N);
750 end if;
751 end Apply_Compile_Time_Constraint_Error;
753 ---------------------------
754 -- Async_Readers_Enabled --
755 ---------------------------
757 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
758 begin
759 return Has_Enabled_Property (Id, Name_Async_Readers);
760 end Async_Readers_Enabled;
762 ---------------------------
763 -- Async_Writers_Enabled --
764 ---------------------------
766 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
767 begin
768 return Has_Enabled_Property (Id, Name_Async_Writers);
769 end Async_Writers_Enabled;
771 --------------------------------------
772 -- Available_Full_View_Of_Component --
773 --------------------------------------
775 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
776 ST : constant Entity_Id := Scope (T);
777 SCT : constant Entity_Id := Scope (Component_Type (T));
778 begin
779 return In_Open_Scopes (ST)
780 and then In_Open_Scopes (SCT)
781 and then Scope_Depth (ST) >= Scope_Depth (SCT);
782 end Available_Full_View_Of_Component;
784 -------------------
785 -- Bad_Attribute --
786 -------------------
788 procedure Bad_Attribute
789 (N : Node_Id;
790 Nam : Name_Id;
791 Warn : Boolean := False)
793 begin
794 Error_Msg_Warn := Warn;
795 Error_Msg_N ("unrecognized attribute&<<", N);
797 -- Check for possible misspelling
799 Error_Msg_Name_1 := First_Attribute_Name;
800 while Error_Msg_Name_1 <= Last_Attribute_Name loop
801 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
802 Error_Msg_N -- CODEFIX
803 ("\possible misspelling of %<<", N);
804 exit;
805 end if;
807 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
808 end loop;
809 end Bad_Attribute;
811 --------------------------------
812 -- Bad_Predicated_Subtype_Use --
813 --------------------------------
815 procedure Bad_Predicated_Subtype_Use
816 (Msg : String;
817 N : Node_Id;
818 Typ : Entity_Id;
819 Suggest_Static : Boolean := False)
821 Gen : Entity_Id;
823 begin
824 -- Avoid cascaded errors
826 if Error_Posted (N) then
827 return;
828 end if;
830 if Inside_A_Generic then
831 Gen := Current_Scope;
832 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
833 Gen := Scope (Gen);
834 end loop;
836 if No (Gen) then
837 return;
838 end if;
840 if Is_Generic_Formal (Typ) and then Is_Discrete_Type (Typ) then
841 Set_No_Predicate_On_Actual (Typ);
842 end if;
844 elsif Has_Predicates (Typ) then
845 if Is_Generic_Actual_Type (Typ) then
847 -- The restriction on loop parameters is only that the type
848 -- should have no dynamic predicates.
850 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
851 and then not Has_Dynamic_Predicate_Aspect (Typ)
852 and then Is_OK_Static_Subtype (Typ)
853 then
854 return;
855 end if;
857 Gen := Current_Scope;
858 while not Is_Generic_Instance (Gen) loop
859 Gen := Scope (Gen);
860 end loop;
862 pragma Assert (Present (Gen));
864 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
865 Error_Msg_Warn := SPARK_Mode /= On;
866 Error_Msg_FE (Msg & "<<", N, Typ);
867 Error_Msg_F ("\Program_Error [<<", N);
869 Insert_Action (N,
870 Make_Raise_Program_Error (Sloc (N),
871 Reason => PE_Bad_Predicated_Generic_Type));
873 else
874 Error_Msg_FE (Msg & "<<", N, Typ);
875 end if;
877 else
878 Error_Msg_FE (Msg, N, Typ);
879 end if;
881 -- Emit an optional suggestion on how to remedy the error if the
882 -- context warrants it.
884 if Suggest_Static and then Has_Static_Predicate (Typ) then
885 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
886 end if;
887 end if;
888 end Bad_Predicated_Subtype_Use;
890 -----------------------------------------
891 -- Bad_Unordered_Enumeration_Reference --
892 -----------------------------------------
894 function Bad_Unordered_Enumeration_Reference
895 (N : Node_Id;
896 T : Entity_Id) return Boolean
898 begin
899 return Is_Enumeration_Type (T)
900 and then 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 Formal := First_Formal (Id);
2137 Actual := First_Actual (Call);
2138 while Present (Actual) and then Present (Formal) loop
2139 if Actual = N then
2140 if Ekind_In (Formal, E_Out_Parameter,
2141 E_In_Out_Parameter)
2142 then
2143 Is_Writable_Actual := True;
2144 end if;
2146 exit;
2147 end if;
2149 Next_Formal (Formal);
2150 Next_Actual (Actual);
2151 end loop;
2152 end;
2153 end if;
2155 if Is_Writable_Actual then
2156 if Contains (Writable_Actuals_List, N) then
2157 Error_Msg_NE
2158 ("value may be affected by call to& "
2159 & "because order of evaluation is arbitrary", N, Id);
2160 Error_Node := N;
2161 return Abandon;
2162 end if;
2164 Append_New_Elmt (N, To => Writable_Actuals_List);
2166 else
2167 if Identifiers_List = No_Elist then
2168 Identifiers_List := New_Elmt_List;
2169 end if;
2171 Append_Unique_Elmt (N, Identifiers_List);
2172 end if;
2173 end if;
2175 return OK;
2176 end Check_Node;
2178 --------------
2179 -- Contains --
2180 --------------
2182 function Contains
2183 (List : Elist_Id;
2184 N : Node_Id) return Boolean
2186 pragma Assert (Nkind (N) in N_Has_Entity);
2188 Elmt : Elmt_Id;
2190 begin
2191 if List = No_Elist then
2192 return False;
2193 end if;
2195 Elmt := First_Elmt (List);
2196 while Present (Elmt) loop
2197 if Entity (Node (Elmt)) = Entity (N) then
2198 return True;
2199 else
2200 Next_Elmt (Elmt);
2201 end if;
2202 end loop;
2204 return False;
2205 end Contains;
2207 ------------------
2208 -- Do_Traversal --
2209 ------------------
2211 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2212 -- The traversal procedure
2214 -- Start of processing for Collect_Identifiers
2216 begin
2217 if Present (Error_Node) then
2218 return;
2219 end if;
2221 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2222 return;
2223 end if;
2225 Do_Traversal (N);
2226 end Collect_Identifiers;
2228 ---------------------
2229 -- Get_Function_Id --
2230 ---------------------
2232 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2233 Nam : constant Node_Id := Name (Call);
2234 Id : Entity_Id;
2236 begin
2237 if Nkind (Nam) = N_Explicit_Dereference then
2238 Id := Etype (Nam);
2239 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2241 elsif Nkind (Nam) = N_Selected_Component then
2242 Id := Entity (Selector_Name (Nam));
2244 elsif Nkind (Nam) = N_Indexed_Component then
2245 Id := Entity (Selector_Name (Prefix (Nam)));
2247 else
2248 Id := Entity (Nam);
2249 end if;
2251 return Id;
2252 end Get_Function_Id;
2254 ---------------------------
2255 -- Preanalyze_Expression --
2256 ---------------------------
2258 procedure Preanalyze_Without_Errors (N : Node_Id) is
2259 Status : constant Boolean := Get_Ignore_Errors;
2260 begin
2261 Set_Ignore_Errors (True);
2262 Preanalyze (N);
2263 Set_Ignore_Errors (Status);
2264 end Preanalyze_Without_Errors;
2266 -- Start of processing for Check_Function_Writable_Actuals
2268 begin
2269 -- The check only applies to Ada 2012 code, and only to constructs that
2270 -- have multiple constituents whose order of evaluation is not specified
2271 -- by the language.
2273 if Ada_Version < Ada_2012
2274 or else (not (Nkind (N) in N_Op)
2275 and then not (Nkind (N) in N_Membership_Test)
2276 and then not Nkind_In (N, N_Range,
2277 N_Aggregate,
2278 N_Extension_Aggregate,
2279 N_Full_Type_Declaration,
2280 N_Function_Call,
2281 N_Procedure_Call_Statement,
2282 N_Entry_Call_Statement))
2283 or else (Nkind (N) = N_Full_Type_Declaration
2284 and then not Is_Record_Type (Defining_Identifier (N)))
2286 -- In addition, this check only applies to source code, not to code
2287 -- generated by constraint checks.
2289 or else not Comes_From_Source (N)
2290 then
2291 return;
2292 end if;
2294 -- If a construct C has two or more direct constituents that are names
2295 -- or expressions whose evaluation may occur in an arbitrary order, at
2296 -- least one of which contains a function call with an in out or out
2297 -- parameter, then the construct is legal only if: for each name N that
2298 -- is passed as a parameter of mode in out or out to some inner function
2299 -- call C2 (not including the construct C itself), there is no other
2300 -- name anywhere within a direct constituent of the construct C other
2301 -- than the one containing C2, that is known to refer to the same
2302 -- object (RM 6.4.1(6.17/3)).
2304 case Nkind (N) is
2305 when N_Range =>
2306 Collect_Identifiers (Low_Bound (N));
2307 Collect_Identifiers (High_Bound (N));
2309 when N_Op | N_Membership_Test =>
2310 declare
2311 Expr : Node_Id;
2313 begin
2314 Collect_Identifiers (Left_Opnd (N));
2316 if Present (Right_Opnd (N)) then
2317 Collect_Identifiers (Right_Opnd (N));
2318 end if;
2320 if Nkind_In (N, N_In, N_Not_In)
2321 and then Present (Alternatives (N))
2322 then
2323 Expr := First (Alternatives (N));
2324 while Present (Expr) loop
2325 Collect_Identifiers (Expr);
2327 Next (Expr);
2328 end loop;
2329 end if;
2330 end;
2332 when N_Full_Type_Declaration =>
2333 declare
2334 function Get_Record_Part (N : Node_Id) return Node_Id;
2335 -- Return the record part of this record type definition
2337 function Get_Record_Part (N : Node_Id) return Node_Id is
2338 Type_Def : constant Node_Id := Type_Definition (N);
2339 begin
2340 if Nkind (Type_Def) = N_Derived_Type_Definition then
2341 return Record_Extension_Part (Type_Def);
2342 else
2343 return Type_Def;
2344 end if;
2345 end Get_Record_Part;
2347 Comp : Node_Id;
2348 Def_Id : Entity_Id := Defining_Identifier (N);
2349 Rec : Node_Id := Get_Record_Part (N);
2351 begin
2352 -- No need to perform any analysis if the record has no
2353 -- components
2355 if No (Rec) or else No (Component_List (Rec)) then
2356 return;
2357 end if;
2359 -- Collect the identifiers starting from the deepest
2360 -- derivation. Done to report the error in the deepest
2361 -- derivation.
2363 loop
2364 if Present (Component_List (Rec)) then
2365 Comp := First (Component_Items (Component_List (Rec)));
2366 while Present (Comp) loop
2367 if Nkind (Comp) = N_Component_Declaration
2368 and then Present (Expression (Comp))
2369 then
2370 Collect_Identifiers (Expression (Comp));
2371 end if;
2373 Next (Comp);
2374 end loop;
2375 end if;
2377 exit when No (Underlying_Type (Etype (Def_Id)))
2378 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2379 = Def_Id;
2381 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2382 Rec := Get_Record_Part (Parent (Def_Id));
2383 end loop;
2384 end;
2386 when N_Subprogram_Call |
2387 N_Entry_Call_Statement =>
2388 declare
2389 Id : constant Entity_Id := Get_Function_Id (N);
2390 Formal : Node_Id;
2391 Actual : Node_Id;
2393 begin
2394 Formal := First_Formal (Id);
2395 Actual := First_Actual (N);
2396 while Present (Actual) and then Present (Formal) loop
2397 if Ekind_In (Formal, E_Out_Parameter,
2398 E_In_Out_Parameter)
2399 then
2400 Collect_Identifiers (Actual);
2401 end if;
2403 Next_Formal (Formal);
2404 Next_Actual (Actual);
2405 end loop;
2406 end;
2408 when N_Aggregate |
2409 N_Extension_Aggregate =>
2410 declare
2411 Assoc : Node_Id;
2412 Choice : Node_Id;
2413 Comp_Expr : Node_Id;
2415 begin
2416 -- Handle the N_Others_Choice of array aggregates with static
2417 -- bounds. There is no need to perform this analysis in
2418 -- aggregates without static bounds since we cannot evaluate
2419 -- if the N_Others_Choice covers several elements. There is
2420 -- no need to handle the N_Others choice of record aggregates
2421 -- since at this stage it has been already expanded by
2422 -- Resolve_Record_Aggregate.
2424 if Is_Array_Type (Etype (N))
2425 and then Nkind (N) = N_Aggregate
2426 and then Present (Aggregate_Bounds (N))
2427 and then Compile_Time_Known_Bounds (Etype (N))
2428 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2430 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2431 then
2432 declare
2433 Count_Components : Uint := Uint_0;
2434 Num_Components : Uint;
2435 Others_Assoc : Node_Id;
2436 Others_Choice : Node_Id := Empty;
2437 Others_Box_Present : Boolean := False;
2439 begin
2440 -- Count positional associations
2442 if Present (Expressions (N)) then
2443 Comp_Expr := First (Expressions (N));
2444 while Present (Comp_Expr) loop
2445 Count_Components := Count_Components + 1;
2446 Next (Comp_Expr);
2447 end loop;
2448 end if;
2450 -- Count the rest of elements and locate the N_Others
2451 -- choice (if any)
2453 Assoc := First (Component_Associations (N));
2454 while Present (Assoc) loop
2455 Choice := First (Choices (Assoc));
2456 while Present (Choice) loop
2457 if Nkind (Choice) = N_Others_Choice then
2458 Others_Assoc := Assoc;
2459 Others_Choice := Choice;
2460 Others_Box_Present := Box_Present (Assoc);
2462 -- Count several components
2464 elsif Nkind_In (Choice, N_Range,
2465 N_Subtype_Indication)
2466 or else (Is_Entity_Name (Choice)
2467 and then Is_Type (Entity (Choice)))
2468 then
2469 declare
2470 L, H : Node_Id;
2471 begin
2472 Get_Index_Bounds (Choice, L, H);
2473 pragma Assert
2474 (Compile_Time_Known_Value (L)
2475 and then Compile_Time_Known_Value (H));
2476 Count_Components :=
2477 Count_Components
2478 + Expr_Value (H) - Expr_Value (L) + 1;
2479 end;
2481 -- Count single component. No other case available
2482 -- since we are handling an aggregate with static
2483 -- bounds.
2485 else
2486 pragma Assert (Is_OK_Static_Expression (Choice)
2487 or else Nkind (Choice) = N_Identifier
2488 or else Nkind (Choice) = N_Integer_Literal);
2490 Count_Components := Count_Components + 1;
2491 end if;
2493 Next (Choice);
2494 end loop;
2496 Next (Assoc);
2497 end loop;
2499 Num_Components :=
2500 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2501 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2503 pragma Assert (Count_Components <= Num_Components);
2505 -- Handle the N_Others choice if it covers several
2506 -- components
2508 if Present (Others_Choice)
2509 and then (Num_Components - Count_Components) > 1
2510 then
2511 if not Others_Box_Present then
2513 -- At this stage, if expansion is active, the
2514 -- expression of the others choice has not been
2515 -- analyzed. Hence we generate a duplicate and
2516 -- we analyze it silently to have available the
2517 -- minimum decoration required to collect the
2518 -- identifiers.
2520 if not Expander_Active then
2521 Comp_Expr := Expression (Others_Assoc);
2522 else
2523 Comp_Expr :=
2524 New_Copy_Tree (Expression (Others_Assoc));
2525 Preanalyze_Without_Errors (Comp_Expr);
2526 end if;
2528 Collect_Identifiers (Comp_Expr);
2530 if Writable_Actuals_List /= No_Elist then
2532 -- As suggested by Robert, at current stage we
2533 -- report occurrences of this case as warnings.
2535 Error_Msg_N
2536 ("writable function parameter may affect "
2537 & "value in other component because order "
2538 & "of evaluation is unspecified??",
2539 Node (First_Elmt (Writable_Actuals_List)));
2540 end if;
2541 end if;
2542 end if;
2543 end;
2544 end if;
2546 -- Handle ancestor part of extension aggregates
2548 if Nkind (N) = N_Extension_Aggregate then
2549 Collect_Identifiers (Ancestor_Part (N));
2550 end if;
2552 -- Handle positional associations
2554 if Present (Expressions (N)) then
2555 Comp_Expr := First (Expressions (N));
2556 while Present (Comp_Expr) loop
2557 if not Is_OK_Static_Expression (Comp_Expr) then
2558 Collect_Identifiers (Comp_Expr);
2559 end if;
2561 Next (Comp_Expr);
2562 end loop;
2563 end if;
2565 -- Handle discrete associations
2567 if Present (Component_Associations (N)) then
2568 Assoc := First (Component_Associations (N));
2569 while Present (Assoc) loop
2571 if not Box_Present (Assoc) then
2572 Choice := First (Choices (Assoc));
2573 while Present (Choice) loop
2575 -- For now we skip discriminants since it requires
2576 -- performing the analysis in two phases: first one
2577 -- analyzing discriminants and second one analyzing
2578 -- the rest of components since discriminants are
2579 -- evaluated prior to components: too much extra
2580 -- work to detect a corner case???
2582 if Nkind (Choice) in N_Has_Entity
2583 and then Present (Entity (Choice))
2584 and then Ekind (Entity (Choice)) = E_Discriminant
2585 then
2586 null;
2588 elsif Box_Present (Assoc) then
2589 null;
2591 else
2592 if not Analyzed (Expression (Assoc)) then
2593 Comp_Expr :=
2594 New_Copy_Tree (Expression (Assoc));
2595 Set_Parent (Comp_Expr, Parent (N));
2596 Preanalyze_Without_Errors (Comp_Expr);
2597 else
2598 Comp_Expr := Expression (Assoc);
2599 end if;
2601 Collect_Identifiers (Comp_Expr);
2602 end if;
2604 Next (Choice);
2605 end loop;
2606 end if;
2608 Next (Assoc);
2609 end loop;
2610 end if;
2611 end;
2613 when others =>
2614 return;
2615 end case;
2617 -- No further action needed if we already reported an error
2619 if Present (Error_Node) then
2620 return;
2621 end if;
2623 -- Check if some writable argument of a function is referenced
2625 if Writable_Actuals_List /= No_Elist
2626 and then Identifiers_List /= No_Elist
2627 then
2628 declare
2629 Elmt_1 : Elmt_Id;
2630 Elmt_2 : Elmt_Id;
2632 begin
2633 Elmt_1 := First_Elmt (Writable_Actuals_List);
2634 while Present (Elmt_1) loop
2635 Elmt_2 := First_Elmt (Identifiers_List);
2636 while Present (Elmt_2) loop
2637 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2638 case Nkind (Parent (Node (Elmt_2))) is
2639 when N_Aggregate |
2640 N_Component_Association |
2641 N_Component_Declaration =>
2642 Error_Msg_N
2643 ("value may be affected by call in other "
2644 & "component because they are evaluated "
2645 & "in unspecified order",
2646 Node (Elmt_2));
2648 when N_In | N_Not_In =>
2649 Error_Msg_N
2650 ("value may be affected by call in other "
2651 & "alternative because they are evaluated "
2652 & "in unspecified order",
2653 Node (Elmt_2));
2655 when others =>
2656 Error_Msg_N
2657 ("value of actual may be affected by call in "
2658 & "other actual because they are evaluated "
2659 & "in unspecified order",
2660 Node (Elmt_2));
2661 end case;
2662 end if;
2664 Next_Elmt (Elmt_2);
2665 end loop;
2667 Next_Elmt (Elmt_1);
2668 end loop;
2669 end;
2670 end if;
2671 end Check_Function_Writable_Actuals;
2673 ----------------------------
2674 -- Check_Ghost_Completion --
2675 ----------------------------
2677 procedure Check_Ghost_Completion
2678 (Partial_View : Entity_Id;
2679 Full_View : Entity_Id)
2681 Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
2683 begin
2684 -- The Ghost policy in effect at the point of declaration and at the
2685 -- point of completion must match (SPARK RM 6.9(15)).
2687 if Is_Checked_Ghost_Entity (Partial_View)
2688 and then Policy = Name_Ignore
2689 then
2690 Error_Msg_Sloc := Sloc (Full_View);
2692 Error_Msg_N ("incompatible ghost policies in effect", Partial_View);
2693 Error_Msg_N ("\& declared with ghost policy Check", Partial_View);
2694 Error_Msg_N ("\& completed # with ghost policy Ignore", Partial_View);
2696 elsif Is_Ignored_Ghost_Entity (Partial_View)
2697 and then Policy = Name_Check
2698 then
2699 Error_Msg_Sloc := Sloc (Full_View);
2701 Error_Msg_N ("incompatible ghost policies in effect", Partial_View);
2702 Error_Msg_N ("\& declared with ghost policy Ignore", Partial_View);
2703 Error_Msg_N ("\& completed # with ghost policy Check", Partial_View);
2704 end if;
2705 end Check_Ghost_Completion;
2707 ----------------------------
2708 -- Check_Ghost_Derivation --
2709 ----------------------------
2711 procedure Check_Ghost_Derivation (Typ : Entity_Id) is
2712 Parent_Typ : constant Entity_Id := Etype (Typ);
2713 Iface : Entity_Id;
2714 Iface_Elmt : Elmt_Id;
2716 begin
2717 -- Allow untagged derivations from predefined types such as Integer as
2718 -- those are not Ghost by definition.
2720 if Is_Scalar_Type (Typ) and then Parent_Typ = Base_Type (Typ) then
2721 null;
2723 -- The parent type of a Ghost type extension must be Ghost
2725 elsif not Is_Ghost_Entity (Parent_Typ) then
2726 Error_Msg_N ("type extension & cannot be ghost", Typ);
2727 Error_Msg_NE ("\parent type & is not ghost", Typ, Parent_Typ);
2728 return;
2729 end if;
2731 -- All progenitors (if any) must be Ghost as well
2733 if Is_Tagged_Type (Typ) and then Present (Interfaces (Typ)) then
2734 Iface_Elmt := First_Elmt (Interfaces (Typ));
2735 while Present (Iface_Elmt) loop
2736 Iface := Node (Iface_Elmt);
2738 if not Is_Ghost_Entity (Iface) then
2739 Error_Msg_N ("type extension & cannot be ghost", Typ);
2740 Error_Msg_NE ("\interface type & is not ghost", Typ, Iface);
2741 return;
2742 end if;
2744 Next_Elmt (Iface_Elmt);
2745 end loop;
2746 end if;
2747 end Check_Ghost_Derivation;
2749 --------------------------------
2750 -- Check_Implicit_Dereference --
2751 --------------------------------
2753 procedure Check_Implicit_Dereference (N : Node_Id; Typ : Entity_Id) is
2754 Disc : Entity_Id;
2755 Desig : Entity_Id;
2756 Nam : Node_Id;
2758 begin
2759 if Nkind (N) = N_Indexed_Component
2760 and then Present (Generalized_Indexing (N))
2761 then
2762 Nam := Generalized_Indexing (N);
2763 else
2764 Nam := N;
2765 end if;
2767 if Ada_Version < Ada_2012
2768 or else not Has_Implicit_Dereference (Base_Type (Typ))
2769 then
2770 return;
2772 elsif not Comes_From_Source (N)
2773 and then Nkind (N) /= N_Indexed_Component
2774 then
2775 return;
2777 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2778 null;
2780 else
2781 Disc := First_Discriminant (Typ);
2782 while Present (Disc) loop
2783 if Has_Implicit_Dereference (Disc) then
2784 Desig := Designated_Type (Etype (Disc));
2785 Add_One_Interp (Nam, Disc, Desig);
2787 -- If the node is a generalized indexing, add interpretation
2788 -- to that node as well, for subsequent resolution.
2790 if Nkind (N) = N_Indexed_Component then
2791 Add_One_Interp (N, Disc, Desig);
2792 end if;
2794 -- If the operation comes from a generic unit and the context
2795 -- is a selected component, the selector name may be global
2796 -- and set in the instance already. Remove the entity to
2797 -- force resolution of the selected component, and the
2798 -- generation of an explicit dereference if needed.
2800 if In_Instance
2801 and then Nkind (Parent (Nam)) = N_Selected_Component
2802 then
2803 Set_Entity (Selector_Name (Parent (Nam)), Empty);
2804 end if;
2806 exit;
2807 end if;
2809 Next_Discriminant (Disc);
2810 end loop;
2811 end if;
2812 end Check_Implicit_Dereference;
2814 ----------------------------------
2815 -- Check_Internal_Protected_Use --
2816 ----------------------------------
2818 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2819 S : Entity_Id;
2820 Prot : Entity_Id;
2822 begin
2823 S := Current_Scope;
2824 while Present (S) loop
2825 if S = Standard_Standard then
2826 return;
2828 elsif Ekind (S) = E_Function
2829 and then Ekind (Scope (S)) = E_Protected_Type
2830 then
2831 Prot := Scope (S);
2832 exit;
2833 end if;
2835 S := Scope (S);
2836 end loop;
2838 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2840 -- An indirect function call (e.g. a callback within a protected
2841 -- function body) is not statically illegal. If the access type is
2842 -- anonymous and is the type of an access parameter, the scope of Nam
2843 -- will be the protected type, but it is not a protected operation.
2845 if Ekind (Nam) = E_Subprogram_Type
2846 and then
2847 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2848 then
2849 null;
2851 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2852 Error_Msg_N
2853 ("within protected function cannot use protected "
2854 & "procedure in renaming or as generic actual", N);
2856 elsif Nkind (N) = N_Attribute_Reference then
2857 Error_Msg_N
2858 ("within protected function cannot take access of "
2859 & " protected procedure", N);
2861 else
2862 Error_Msg_N
2863 ("within protected function, protected object is constant", N);
2864 Error_Msg_N
2865 ("\cannot call operation that may modify it", N);
2866 end if;
2867 end if;
2868 end Check_Internal_Protected_Use;
2870 ---------------------------------------
2871 -- Check_Later_Vs_Basic_Declarations --
2872 ---------------------------------------
2874 procedure Check_Later_Vs_Basic_Declarations
2875 (Decls : List_Id;
2876 During_Parsing : Boolean)
2878 Body_Sloc : Source_Ptr;
2879 Decl : Node_Id;
2881 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2882 -- Return whether Decl is considered as a declarative item.
2883 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2884 -- When During_Parsing is False, the semantics of SPARK is followed.
2886 -------------------------------
2887 -- Is_Later_Declarative_Item --
2888 -------------------------------
2890 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2891 begin
2892 if Nkind (Decl) in N_Later_Decl_Item then
2893 return True;
2895 elsif Nkind (Decl) = N_Pragma then
2896 return True;
2898 elsif During_Parsing then
2899 return False;
2901 -- In SPARK, a package declaration is not considered as a later
2902 -- declarative item.
2904 elsif Nkind (Decl) = N_Package_Declaration then
2905 return False;
2907 -- In SPARK, a renaming is considered as a later declarative item
2909 elsif Nkind (Decl) in N_Renaming_Declaration then
2910 return True;
2912 else
2913 return False;
2914 end if;
2915 end Is_Later_Declarative_Item;
2917 -- Start of Check_Later_Vs_Basic_Declarations
2919 begin
2920 Decl := First (Decls);
2922 -- Loop through sequence of basic declarative items
2924 Outer : while Present (Decl) loop
2925 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2926 and then Nkind (Decl) not in N_Body_Stub
2927 then
2928 Next (Decl);
2930 -- Once a body is encountered, we only allow later declarative
2931 -- items. The inner loop checks the rest of the list.
2933 else
2934 Body_Sloc := Sloc (Decl);
2936 Inner : while Present (Decl) loop
2937 if not Is_Later_Declarative_Item (Decl) then
2938 if During_Parsing then
2939 if Ada_Version = Ada_83 then
2940 Error_Msg_Sloc := Body_Sloc;
2941 Error_Msg_N
2942 ("(Ada 83) decl cannot appear after body#", Decl);
2943 end if;
2944 else
2945 Error_Msg_Sloc := Body_Sloc;
2946 Check_SPARK_05_Restriction
2947 ("decl cannot appear after body#", Decl);
2948 end if;
2949 end if;
2951 Next (Decl);
2952 end loop Inner;
2953 end if;
2954 end loop Outer;
2955 end Check_Later_Vs_Basic_Declarations;
2957 -------------------------
2958 -- Check_Nested_Access --
2959 -------------------------
2961 procedure Check_Nested_Access (Ent : Entity_Id) is
2962 Scop : constant Entity_Id := Current_Scope;
2963 Current_Subp : Entity_Id;
2964 Enclosing : Entity_Id;
2966 begin
2967 -- Currently only enabled for VM back-ends for efficiency, should we
2968 -- enable it more systematically ???
2970 -- Check for Is_Imported needs commenting below ???
2972 if VM_Target /= No_VM
2973 and then Ekind_In (Ent, E_Variable, E_Constant, E_Loop_Parameter)
2974 and then Scope (Ent) /= Empty
2975 and then not Is_Library_Level_Entity (Ent)
2976 and then not Is_Imported (Ent)
2977 then
2978 if Is_Subprogram (Scop)
2979 or else Is_Generic_Subprogram (Scop)
2980 or else Is_Entry (Scop)
2981 then
2982 Current_Subp := Scop;
2983 else
2984 Current_Subp := Current_Subprogram;
2985 end if;
2987 Enclosing := Enclosing_Subprogram (Ent);
2989 if Enclosing /= Empty and then Enclosing /= Current_Subp then
2990 Set_Has_Up_Level_Access (Ent, True);
2991 end if;
2992 end if;
2993 end Check_Nested_Access;
2995 ---------------------------
2996 -- Check_No_Hidden_State --
2997 ---------------------------
2999 procedure Check_No_Hidden_State (Id : Entity_Id) is
3000 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
3001 -- Determine whether the entity of a package denoted by Pkg has a null
3002 -- abstract state.
3004 -----------------------------
3005 -- Has_Null_Abstract_State --
3006 -----------------------------
3008 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
3009 States : constant Elist_Id := Abstract_States (Pkg);
3011 begin
3012 -- Check first available state of related package. A null abstract
3013 -- state always appears as the sole element of the state list.
3015 return
3016 Present (States)
3017 and then Is_Null_State (Node (First_Elmt (States)));
3018 end Has_Null_Abstract_State;
3020 -- Local variables
3022 Context : Entity_Id := Empty;
3023 Not_Visible : Boolean := False;
3024 Scop : Entity_Id;
3026 -- Start of processing for Check_No_Hidden_State
3028 begin
3029 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
3031 -- Find the proper context where the object or state appears
3033 Scop := Scope (Id);
3034 while Present (Scop) loop
3035 Context := Scop;
3037 -- Keep track of the context's visibility
3039 Not_Visible := Not_Visible or else In_Private_Part (Context);
3041 -- Prevent the search from going too far
3043 if Context = Standard_Standard then
3044 return;
3046 -- Objects and states that appear immediately within a subprogram or
3047 -- inside a construct nested within a subprogram do not introduce a
3048 -- hidden state. They behave as local variable declarations.
3050 elsif Is_Subprogram (Context) then
3051 return;
3053 -- When examining a package body, use the entity of the spec as it
3054 -- carries the abstract state declarations.
3056 elsif Ekind (Context) = E_Package_Body then
3057 Context := Spec_Entity (Context);
3058 end if;
3060 -- Stop the traversal when a package subject to a null abstract state
3061 -- has been found.
3063 if Ekind_In (Context, E_Generic_Package, E_Package)
3064 and then Has_Null_Abstract_State (Context)
3065 then
3066 exit;
3067 end if;
3069 Scop := Scope (Scop);
3070 end loop;
3072 -- At this point we know that there is at least one package with a null
3073 -- abstract state in visibility. Emit an error message unconditionally
3074 -- if the entity being processed is a state because the placement of the
3075 -- related package is irrelevant. This is not the case for objects as
3076 -- the intermediate context matters.
3078 if Present (Context)
3079 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
3080 then
3081 Error_Msg_N ("cannot introduce hidden state &", Id);
3082 Error_Msg_NE ("\package & has null abstract state", Id, Context);
3083 end if;
3084 end Check_No_Hidden_State;
3086 ------------------------------------------
3087 -- Check_Potentially_Blocking_Operation --
3088 ------------------------------------------
3090 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
3091 S : Entity_Id;
3093 begin
3094 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3095 -- When pragma Detect_Blocking is active, the run time will raise
3096 -- Program_Error. Here we only issue a warning, since we generally
3097 -- support the use of potentially blocking operations in the absence
3098 -- of the pragma.
3100 -- Indirect blocking through a subprogram call cannot be diagnosed
3101 -- statically without interprocedural analysis, so we do not attempt
3102 -- to do it here.
3104 S := Scope (Current_Scope);
3105 while Present (S) and then S /= Standard_Standard loop
3106 if Is_Protected_Type (S) then
3107 Error_Msg_N
3108 ("potentially blocking operation in protected operation??", N);
3109 return;
3110 end if;
3112 S := Scope (S);
3113 end loop;
3114 end Check_Potentially_Blocking_Operation;
3116 ---------------------------------
3117 -- Check_Result_And_Post_State --
3118 ---------------------------------
3120 procedure Check_Result_And_Post_State
3121 (Prag : Node_Id;
3122 Result_Seen : in out Boolean)
3124 procedure Check_Expression (Expr : Node_Id);
3125 -- Perform the 'Result and post-state checks on a given expression
3127 function Is_Function_Result (N : Node_Id) return Traverse_Result;
3128 -- Attempt to find attribute 'Result in a subtree denoted by N
3130 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
3131 -- Determine whether source node N denotes "True" or "False"
3133 function Mentions_Post_State (N : Node_Id) return Boolean;
3134 -- Determine whether a subtree denoted by N mentions any construct that
3135 -- denotes a post-state.
3137 procedure Check_Function_Result is
3138 new Traverse_Proc (Is_Function_Result);
3140 ----------------------
3141 -- Check_Expression --
3142 ----------------------
3144 procedure Check_Expression (Expr : Node_Id) is
3145 begin
3146 if not Is_Trivial_Boolean (Expr) then
3147 Check_Function_Result (Expr);
3149 if not Mentions_Post_State (Expr) then
3150 if Pragma_Name (Prag) = Name_Contract_Cases then
3151 Error_Msg_N
3152 ("contract case refers only to pre-state?T?", Expr);
3154 elsif Pragma_Name (Prag) = Name_Refined_Post then
3155 Error_Msg_N
3156 ("refined postcondition refers only to pre-state?T?",
3157 Prag);
3159 else
3160 Error_Msg_N
3161 ("postcondition refers only to pre-state?T?", Prag);
3162 end if;
3163 end if;
3164 end if;
3165 end Check_Expression;
3167 ------------------------
3168 -- Is_Function_Result --
3169 ------------------------
3171 function Is_Function_Result (N : Node_Id) return Traverse_Result is
3172 begin
3173 if Is_Attribute_Result (N) then
3174 Result_Seen := True;
3175 return Abandon;
3177 -- Continue the traversal
3179 else
3180 return OK;
3181 end if;
3182 end Is_Function_Result;
3184 ------------------------
3185 -- Is_Trivial_Boolean --
3186 ------------------------
3188 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
3189 begin
3190 return
3191 Comes_From_Source (N)
3192 and then Is_Entity_Name (N)
3193 and then (Entity (N) = Standard_True
3194 or else
3195 Entity (N) = Standard_False);
3196 end Is_Trivial_Boolean;
3198 -------------------------
3199 -- Mentions_Post_State --
3200 -------------------------
3202 function Mentions_Post_State (N : Node_Id) return Boolean is
3203 Post_State_Seen : Boolean := False;
3205 function Is_Post_State (N : Node_Id) return Traverse_Result;
3206 -- Attempt to find a construct that denotes a post-state. If this is
3207 -- the case, set flag Post_State_Seen.
3209 -------------------
3210 -- Is_Post_State --
3211 -------------------
3213 function Is_Post_State (N : Node_Id) return Traverse_Result is
3214 Ent : Entity_Id;
3216 begin
3217 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3218 Post_State_Seen := True;
3219 return Abandon;
3221 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3222 Ent := Entity (N);
3224 -- The entity may be modifiable through an implicit dereference
3226 if No (Ent)
3227 or else Ekind (Ent) in Assignable_Kind
3228 or else (Is_Access_Type (Etype (Ent))
3229 and then Nkind (Parent (N)) = N_Selected_Component)
3230 then
3231 Post_State_Seen := True;
3232 return Abandon;
3233 end if;
3235 elsif Nkind (N) = N_Attribute_Reference then
3236 if Attribute_Name (N) = Name_Old then
3237 return Skip;
3239 elsif Attribute_Name (N) = Name_Result then
3240 Post_State_Seen := True;
3241 return Abandon;
3242 end if;
3243 end if;
3245 return OK;
3246 end Is_Post_State;
3248 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3250 -- Start of processing for Mentions_Post_State
3252 begin
3253 Find_Post_State (N);
3255 return Post_State_Seen;
3256 end Mentions_Post_State;
3258 -- Local variables
3260 Expr : constant Node_Id :=
3261 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
3262 Nam : constant Name_Id := Pragma_Name (Prag);
3263 CCase : Node_Id;
3265 -- Start of processing for Check_Result_And_Post_State
3267 begin
3268 -- Examine all consequences
3270 if Nam = Name_Contract_Cases then
3271 CCase := First (Component_Associations (Expr));
3272 while Present (CCase) loop
3273 Check_Expression (Expression (CCase));
3275 Next (CCase);
3276 end loop;
3278 -- Examine the expression of a postcondition
3280 else pragma Assert (Nam_In (Nam, Name_Postcondition, Name_Refined_Post));
3281 Check_Expression (Expr);
3282 end if;
3283 end Check_Result_And_Post_State;
3285 ------------------------------
3286 -- Check_Unprotected_Access --
3287 ------------------------------
3289 procedure Check_Unprotected_Access
3290 (Context : Node_Id;
3291 Expr : Node_Id)
3293 Cont_Encl_Typ : Entity_Id;
3294 Pref_Encl_Typ : Entity_Id;
3296 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3297 -- Check whether Obj is a private component of a protected object.
3298 -- Return the protected type where the component resides, Empty
3299 -- otherwise.
3301 function Is_Public_Operation return Boolean;
3302 -- Verify that the enclosing operation is callable from outside the
3303 -- protected object, to minimize false positives.
3305 ------------------------------
3306 -- Enclosing_Protected_Type --
3307 ------------------------------
3309 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3310 begin
3311 if Is_Entity_Name (Obj) then
3312 declare
3313 Ent : Entity_Id := Entity (Obj);
3315 begin
3316 -- The object can be a renaming of a private component, use
3317 -- the original record component.
3319 if Is_Prival (Ent) then
3320 Ent := Prival_Link (Ent);
3321 end if;
3323 if Is_Protected_Type (Scope (Ent)) then
3324 return Scope (Ent);
3325 end if;
3326 end;
3327 end if;
3329 -- For indexed and selected components, recursively check the prefix
3331 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3332 return Enclosing_Protected_Type (Prefix (Obj));
3334 -- The object does not denote a protected component
3336 else
3337 return Empty;
3338 end if;
3339 end Enclosing_Protected_Type;
3341 -------------------------
3342 -- Is_Public_Operation --
3343 -------------------------
3345 function Is_Public_Operation return Boolean is
3346 S : Entity_Id;
3347 E : Entity_Id;
3349 begin
3350 S := Current_Scope;
3351 while Present (S) and then S /= Pref_Encl_Typ loop
3352 if Scope (S) = Pref_Encl_Typ then
3353 E := First_Entity (Pref_Encl_Typ);
3354 while Present (E)
3355 and then E /= First_Private_Entity (Pref_Encl_Typ)
3356 loop
3357 if E = S then
3358 return True;
3359 end if;
3361 Next_Entity (E);
3362 end loop;
3363 end if;
3365 S := Scope (S);
3366 end loop;
3368 return False;
3369 end Is_Public_Operation;
3371 -- Start of processing for Check_Unprotected_Access
3373 begin
3374 if Nkind (Expr) = N_Attribute_Reference
3375 and then Attribute_Name (Expr) = Name_Unchecked_Access
3376 then
3377 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3378 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3380 -- Check whether we are trying to export a protected component to a
3381 -- context with an equal or lower access level.
3383 if Present (Pref_Encl_Typ)
3384 and then No (Cont_Encl_Typ)
3385 and then Is_Public_Operation
3386 and then Scope_Depth (Pref_Encl_Typ) >=
3387 Object_Access_Level (Context)
3388 then
3389 Error_Msg_N
3390 ("??possible unprotected access to protected data", Expr);
3391 end if;
3392 end if;
3393 end Check_Unprotected_Access;
3395 ------------------------
3396 -- Collect_Interfaces --
3397 ------------------------
3399 procedure Collect_Interfaces
3400 (T : Entity_Id;
3401 Ifaces_List : out Elist_Id;
3402 Exclude_Parents : Boolean := False;
3403 Use_Full_View : Boolean := True)
3405 procedure Collect (Typ : Entity_Id);
3406 -- Subsidiary subprogram used to traverse the whole list
3407 -- of directly and indirectly implemented interfaces
3409 -------------
3410 -- Collect --
3411 -------------
3413 procedure Collect (Typ : Entity_Id) is
3414 Ancestor : Entity_Id;
3415 Full_T : Entity_Id;
3416 Id : Node_Id;
3417 Iface : Entity_Id;
3419 begin
3420 Full_T := Typ;
3422 -- Handle private types
3424 if Use_Full_View
3425 and then Is_Private_Type (Typ)
3426 and then Present (Full_View (Typ))
3427 then
3428 Full_T := Full_View (Typ);
3429 end if;
3431 -- Include the ancestor if we are generating the whole list of
3432 -- abstract interfaces.
3434 if Etype (Full_T) /= Typ
3436 -- Protect the frontend against wrong sources. For example:
3438 -- package P is
3439 -- type A is tagged null record;
3440 -- type B is new A with private;
3441 -- type C is new A with private;
3442 -- private
3443 -- type B is new C with null record;
3444 -- type C is new B with null record;
3445 -- end P;
3447 and then Etype (Full_T) /= T
3448 then
3449 Ancestor := Etype (Full_T);
3450 Collect (Ancestor);
3452 if Is_Interface (Ancestor) and then not Exclude_Parents then
3453 Append_Unique_Elmt (Ancestor, Ifaces_List);
3454 end if;
3455 end if;
3457 -- Traverse the graph of ancestor interfaces
3459 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3460 Id := First (Abstract_Interface_List (Full_T));
3461 while Present (Id) loop
3462 Iface := Etype (Id);
3464 -- Protect against wrong uses. For example:
3465 -- type I is interface;
3466 -- type O is tagged null record;
3467 -- type Wrong is new I and O with null record; -- ERROR
3469 if Is_Interface (Iface) then
3470 if Exclude_Parents
3471 and then Etype (T) /= T
3472 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3473 then
3474 null;
3475 else
3476 Collect (Iface);
3477 Append_Unique_Elmt (Iface, Ifaces_List);
3478 end if;
3479 end if;
3481 Next (Id);
3482 end loop;
3483 end if;
3484 end Collect;
3486 -- Start of processing for Collect_Interfaces
3488 begin
3489 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3490 Ifaces_List := New_Elmt_List;
3491 Collect (T);
3492 end Collect_Interfaces;
3494 ----------------------------------
3495 -- Collect_Interface_Components --
3496 ----------------------------------
3498 procedure Collect_Interface_Components
3499 (Tagged_Type : Entity_Id;
3500 Components_List : out Elist_Id)
3502 procedure Collect (Typ : Entity_Id);
3503 -- Subsidiary subprogram used to climb to the parents
3505 -------------
3506 -- Collect --
3507 -------------
3509 procedure Collect (Typ : Entity_Id) is
3510 Tag_Comp : Entity_Id;
3511 Parent_Typ : Entity_Id;
3513 begin
3514 -- Handle private types
3516 if Present (Full_View (Etype (Typ))) then
3517 Parent_Typ := Full_View (Etype (Typ));
3518 else
3519 Parent_Typ := Etype (Typ);
3520 end if;
3522 if Parent_Typ /= Typ
3524 -- Protect the frontend against wrong sources. For example:
3526 -- package P is
3527 -- type A is tagged null record;
3528 -- type B is new A with private;
3529 -- type C is new A with private;
3530 -- private
3531 -- type B is new C with null record;
3532 -- type C is new B with null record;
3533 -- end P;
3535 and then Parent_Typ /= Tagged_Type
3536 then
3537 Collect (Parent_Typ);
3538 end if;
3540 -- Collect the components containing tags of secondary dispatch
3541 -- tables.
3543 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3544 while Present (Tag_Comp) loop
3545 pragma Assert (Present (Related_Type (Tag_Comp)));
3546 Append_Elmt (Tag_Comp, Components_List);
3548 Tag_Comp := Next_Tag_Component (Tag_Comp);
3549 end loop;
3550 end Collect;
3552 -- Start of processing for Collect_Interface_Components
3554 begin
3555 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3556 and then Is_Tagged_Type (Tagged_Type));
3558 Components_List := New_Elmt_List;
3559 Collect (Tagged_Type);
3560 end Collect_Interface_Components;
3562 -----------------------------
3563 -- Collect_Interfaces_Info --
3564 -----------------------------
3566 procedure Collect_Interfaces_Info
3567 (T : Entity_Id;
3568 Ifaces_List : out Elist_Id;
3569 Components_List : out Elist_Id;
3570 Tags_List : out Elist_Id)
3572 Comps_List : Elist_Id;
3573 Comp_Elmt : Elmt_Id;
3574 Comp_Iface : Entity_Id;
3575 Iface_Elmt : Elmt_Id;
3576 Iface : Entity_Id;
3578 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3579 -- Search for the secondary tag associated with the interface type
3580 -- Iface that is implemented by T.
3582 ----------------
3583 -- Search_Tag --
3584 ----------------
3586 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3587 ADT : Elmt_Id;
3588 begin
3589 if not Is_CPP_Class (T) then
3590 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3591 else
3592 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3593 end if;
3595 while Present (ADT)
3596 and then Is_Tag (Node (ADT))
3597 and then Related_Type (Node (ADT)) /= Iface
3598 loop
3599 -- Skip secondary dispatch table referencing thunks to user
3600 -- defined primitives covered by this interface.
3602 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3603 Next_Elmt (ADT);
3605 -- Skip secondary dispatch tables of Ada types
3607 if not Is_CPP_Class (T) then
3609 -- Skip secondary dispatch table referencing thunks to
3610 -- predefined primitives.
3612 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3613 Next_Elmt (ADT);
3615 -- Skip secondary dispatch table referencing user-defined
3616 -- primitives covered by this interface.
3618 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3619 Next_Elmt (ADT);
3621 -- Skip secondary dispatch table referencing predefined
3622 -- primitives.
3624 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3625 Next_Elmt (ADT);
3626 end if;
3627 end loop;
3629 pragma Assert (Is_Tag (Node (ADT)));
3630 return Node (ADT);
3631 end Search_Tag;
3633 -- Start of processing for Collect_Interfaces_Info
3635 begin
3636 Collect_Interfaces (T, Ifaces_List);
3637 Collect_Interface_Components (T, Comps_List);
3639 -- Search for the record component and tag associated with each
3640 -- interface type of T.
3642 Components_List := New_Elmt_List;
3643 Tags_List := New_Elmt_List;
3645 Iface_Elmt := First_Elmt (Ifaces_List);
3646 while Present (Iface_Elmt) loop
3647 Iface := Node (Iface_Elmt);
3649 -- Associate the primary tag component and the primary dispatch table
3650 -- with all the interfaces that are parents of T
3652 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3653 Append_Elmt (First_Tag_Component (T), Components_List);
3654 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3656 -- Otherwise search for the tag component and secondary dispatch
3657 -- table of Iface
3659 else
3660 Comp_Elmt := First_Elmt (Comps_List);
3661 while Present (Comp_Elmt) loop
3662 Comp_Iface := Related_Type (Node (Comp_Elmt));
3664 if Comp_Iface = Iface
3665 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3666 then
3667 Append_Elmt (Node (Comp_Elmt), Components_List);
3668 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3669 exit;
3670 end if;
3672 Next_Elmt (Comp_Elmt);
3673 end loop;
3674 pragma Assert (Present (Comp_Elmt));
3675 end if;
3677 Next_Elmt (Iface_Elmt);
3678 end loop;
3679 end Collect_Interfaces_Info;
3681 ---------------------
3682 -- Collect_Parents --
3683 ---------------------
3685 procedure Collect_Parents
3686 (T : Entity_Id;
3687 List : out Elist_Id;
3688 Use_Full_View : Boolean := True)
3690 Current_Typ : Entity_Id := T;
3691 Parent_Typ : Entity_Id;
3693 begin
3694 List := New_Elmt_List;
3696 -- No action if the if the type has no parents
3698 if T = Etype (T) then
3699 return;
3700 end if;
3702 loop
3703 Parent_Typ := Etype (Current_Typ);
3705 if Is_Private_Type (Parent_Typ)
3706 and then Present (Full_View (Parent_Typ))
3707 and then Use_Full_View
3708 then
3709 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3710 end if;
3712 Append_Elmt (Parent_Typ, List);
3714 exit when Parent_Typ = Current_Typ;
3715 Current_Typ := Parent_Typ;
3716 end loop;
3717 end Collect_Parents;
3719 ----------------------------------
3720 -- Collect_Primitive_Operations --
3721 ----------------------------------
3723 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
3724 B_Type : constant Entity_Id := Base_Type (T);
3725 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
3726 B_Scope : Entity_Id := Scope (B_Type);
3727 Op_List : Elist_Id;
3728 Formal : Entity_Id;
3729 Is_Prim : Boolean;
3730 Is_Type_In_Pkg : Boolean;
3731 Formal_Derived : Boolean := False;
3732 Id : Entity_Id;
3734 function Match (E : Entity_Id) return Boolean;
3735 -- True if E's base type is B_Type, or E is of an anonymous access type
3736 -- and the base type of its designated type is B_Type.
3738 -----------
3739 -- Match --
3740 -----------
3742 function Match (E : Entity_Id) return Boolean is
3743 Etyp : Entity_Id := Etype (E);
3745 begin
3746 if Ekind (Etyp) = E_Anonymous_Access_Type then
3747 Etyp := Designated_Type (Etyp);
3748 end if;
3750 -- In Ada 2012 a primitive operation may have a formal of an
3751 -- incomplete view of the parent type.
3753 return Base_Type (Etyp) = B_Type
3754 or else
3755 (Ada_Version >= Ada_2012
3756 and then Ekind (Etyp) = E_Incomplete_Type
3757 and then Full_View (Etyp) = B_Type);
3758 end Match;
3760 -- Start of processing for Collect_Primitive_Operations
3762 begin
3763 -- For tagged types, the primitive operations are collected as they
3764 -- are declared, and held in an explicit list which is simply returned.
3766 if Is_Tagged_Type (B_Type) then
3767 return Primitive_Operations (B_Type);
3769 -- An untagged generic type that is a derived type inherits the
3770 -- primitive operations of its parent type. Other formal types only
3771 -- have predefined operators, which are not explicitly represented.
3773 elsif Is_Generic_Type (B_Type) then
3774 if Nkind (B_Decl) = N_Formal_Type_Declaration
3775 and then Nkind (Formal_Type_Definition (B_Decl)) =
3776 N_Formal_Derived_Type_Definition
3777 then
3778 Formal_Derived := True;
3779 else
3780 return New_Elmt_List;
3781 end if;
3782 end if;
3784 Op_List := New_Elmt_List;
3786 if B_Scope = Standard_Standard then
3787 if B_Type = Standard_String then
3788 Append_Elmt (Standard_Op_Concat, Op_List);
3790 elsif B_Type = Standard_Wide_String then
3791 Append_Elmt (Standard_Op_Concatw, Op_List);
3793 else
3794 null;
3795 end if;
3797 -- Locate the primitive subprograms of the type
3799 else
3800 -- The primitive operations appear after the base type, except
3801 -- if the derivation happens within the private part of B_Scope
3802 -- and the type is a private type, in which case both the type
3803 -- and some primitive operations may appear before the base
3804 -- type, and the list of candidates starts after the type.
3806 if In_Open_Scopes (B_Scope)
3807 and then Scope (T) = B_Scope
3808 and then In_Private_Part (B_Scope)
3809 then
3810 Id := Next_Entity (T);
3812 -- In Ada 2012, If the type has an incomplete partial view, there
3813 -- may be primitive operations declared before the full view, so
3814 -- we need to start scanning from the incomplete view, which is
3815 -- earlier on the entity chain.
3817 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
3818 and then Present (Incomplete_View (Parent (B_Type)))
3819 then
3820 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
3822 else
3823 Id := Next_Entity (B_Type);
3824 end if;
3826 -- Set flag if this is a type in a package spec
3828 Is_Type_In_Pkg :=
3829 Is_Package_Or_Generic_Package (B_Scope)
3830 and then
3831 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
3832 N_Package_Body;
3834 while Present (Id) loop
3836 -- Test whether the result type or any of the parameter types of
3837 -- each subprogram following the type match that type when the
3838 -- type is declared in a package spec, is a derived type, or the
3839 -- subprogram is marked as primitive. (The Is_Primitive test is
3840 -- needed to find primitives of nonderived types in declarative
3841 -- parts that happen to override the predefined "=" operator.)
3843 -- Note that generic formal subprograms are not considered to be
3844 -- primitive operations and thus are never inherited.
3846 if Is_Overloadable (Id)
3847 and then (Is_Type_In_Pkg
3848 or else Is_Derived_Type (B_Type)
3849 or else Is_Primitive (Id))
3850 and then Nkind (Parent (Parent (Id)))
3851 not in N_Formal_Subprogram_Declaration
3852 then
3853 Is_Prim := False;
3855 if Match (Id) then
3856 Is_Prim := True;
3858 else
3859 Formal := First_Formal (Id);
3860 while Present (Formal) loop
3861 if Match (Formal) then
3862 Is_Prim := True;
3863 exit;
3864 end if;
3866 Next_Formal (Formal);
3867 end loop;
3868 end if;
3870 -- For a formal derived type, the only primitives are the ones
3871 -- inherited from the parent type. Operations appearing in the
3872 -- package declaration are not primitive for it.
3874 if Is_Prim
3875 and then (not Formal_Derived or else Present (Alias (Id)))
3876 then
3877 -- In the special case of an equality operator aliased to
3878 -- an overriding dispatching equality belonging to the same
3879 -- type, we don't include it in the list of primitives.
3880 -- This avoids inheriting multiple equality operators when
3881 -- deriving from untagged private types whose full type is
3882 -- tagged, which can otherwise cause ambiguities. Note that
3883 -- this should only happen for this kind of untagged parent
3884 -- type, since normally dispatching operations are inherited
3885 -- using the type's Primitive_Operations list.
3887 if Chars (Id) = Name_Op_Eq
3888 and then Is_Dispatching_Operation (Id)
3889 and then Present (Alias (Id))
3890 and then Present (Overridden_Operation (Alias (Id)))
3891 and then Base_Type (Etype (First_Entity (Id))) =
3892 Base_Type (Etype (First_Entity (Alias (Id))))
3893 then
3894 null;
3896 -- Include the subprogram in the list of primitives
3898 else
3899 Append_Elmt (Id, Op_List);
3900 end if;
3901 end if;
3902 end if;
3904 Next_Entity (Id);
3906 -- For a type declared in System, some of its operations may
3907 -- appear in the target-specific extension to System.
3909 if No (Id)
3910 and then B_Scope = RTU_Entity (System)
3911 and then Present_System_Aux
3912 then
3913 B_Scope := System_Aux_Id;
3914 Id := First_Entity (System_Aux_Id);
3915 end if;
3916 end loop;
3917 end if;
3919 return Op_List;
3920 end Collect_Primitive_Operations;
3922 -----------------------------------
3923 -- Compile_Time_Constraint_Error --
3924 -----------------------------------
3926 function Compile_Time_Constraint_Error
3927 (N : Node_Id;
3928 Msg : String;
3929 Ent : Entity_Id := Empty;
3930 Loc : Source_Ptr := No_Location;
3931 Warn : Boolean := False) return Node_Id
3933 Msgc : String (1 .. Msg'Length + 3);
3934 -- Copy of message, with room for possible ?? or << and ! at end
3936 Msgl : Natural;
3937 Wmsg : Boolean;
3938 Eloc : Source_Ptr;
3940 -- Start of processing for Compile_Time_Constraint_Error
3942 begin
3943 -- If this is a warning, convert it into an error if we are in code
3944 -- subject to SPARK_Mode being set ON.
3946 Error_Msg_Warn := SPARK_Mode /= On;
3948 -- A static constraint error in an instance body is not a fatal error.
3949 -- we choose to inhibit the message altogether, because there is no
3950 -- obvious node (for now) on which to post it. On the other hand the
3951 -- offending node must be replaced with a constraint_error in any case.
3953 -- No messages are generated if we already posted an error on this node
3955 if not Error_Posted (N) then
3956 if Loc /= No_Location then
3957 Eloc := Loc;
3958 else
3959 Eloc := Sloc (N);
3960 end if;
3962 -- Copy message to Msgc, converting any ? in the message into
3963 -- < instead, so that we have an error in GNATprove mode.
3965 Msgl := Msg'Length;
3967 for J in 1 .. Msgl loop
3968 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
3969 Msgc (J) := '<';
3970 else
3971 Msgc (J) := Msg (J);
3972 end if;
3973 end loop;
3975 -- Message is a warning, even in Ada 95 case
3977 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
3978 Wmsg := True;
3980 -- In Ada 83, all messages are warnings. In the private part and
3981 -- the body of an instance, constraint_checks are only warnings.
3982 -- We also make this a warning if the Warn parameter is set.
3984 elsif Warn
3985 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
3986 then
3987 Msgl := Msgl + 1;
3988 Msgc (Msgl) := '<';
3989 Msgl := Msgl + 1;
3990 Msgc (Msgl) := '<';
3991 Wmsg := True;
3993 elsif In_Instance_Not_Visible then
3994 Msgl := Msgl + 1;
3995 Msgc (Msgl) := '<';
3996 Msgl := Msgl + 1;
3997 Msgc (Msgl) := '<';
3998 Wmsg := True;
4000 -- Otherwise we have a real error message (Ada 95 static case)
4001 -- and we make this an unconditional message. Note that in the
4002 -- warning case we do not make the message unconditional, it seems
4003 -- quite reasonable to delete messages like this (about exceptions
4004 -- that will be raised) in dead code.
4006 else
4007 Wmsg := False;
4008 Msgl := Msgl + 1;
4009 Msgc (Msgl) := '!';
4010 end if;
4012 -- One more test, skip the warning if the related expression is
4013 -- statically unevaluated, since we don't want to warn about what
4014 -- will happen when something is evaluated if it never will be
4015 -- evaluated.
4017 if not Is_Statically_Unevaluated (N) then
4018 Error_Msg_Warn := SPARK_Mode /= On;
4020 if Present (Ent) then
4021 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
4022 else
4023 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
4024 end if;
4026 if Wmsg then
4028 -- Check whether the context is an Init_Proc
4030 if Inside_Init_Proc then
4031 declare
4032 Conc_Typ : constant Entity_Id :=
4033 Corresponding_Concurrent_Type
4034 (Entity (Parameter_Type (First
4035 (Parameter_Specifications
4036 (Parent (Current_Scope))))));
4038 begin
4039 -- Don't complain if the corresponding concurrent type
4040 -- doesn't come from source (i.e. a single task/protected
4041 -- object).
4043 if Present (Conc_Typ)
4044 and then not Comes_From_Source (Conc_Typ)
4045 then
4046 Error_Msg_NEL
4047 ("\& [<<", N, Standard_Constraint_Error, Eloc);
4049 else
4050 if GNATprove_Mode then
4051 Error_Msg_NEL
4052 ("\& would have been raised for objects of this "
4053 & "type", N, Standard_Constraint_Error, Eloc);
4054 else
4055 Error_Msg_NEL
4056 ("\& will be raised for objects of this type??",
4057 N, Standard_Constraint_Error, Eloc);
4058 end if;
4059 end if;
4060 end;
4062 else
4063 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
4064 end if;
4066 else
4067 Error_Msg ("\static expression fails Constraint_Check", Eloc);
4068 Set_Error_Posted (N);
4069 end if;
4070 end if;
4071 end if;
4073 return N;
4074 end Compile_Time_Constraint_Error;
4076 -----------------------
4077 -- Conditional_Delay --
4078 -----------------------
4080 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
4081 begin
4082 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
4083 Set_Has_Delayed_Freeze (New_Ent);
4084 end if;
4085 end Conditional_Delay;
4087 ----------------------------
4088 -- Contains_Refined_State --
4089 ----------------------------
4091 function Contains_Refined_State (Prag : Node_Id) return Boolean is
4092 function Has_State_In_Dependency (List : Node_Id) return Boolean;
4093 -- Determine whether a dependency list mentions a state with a visible
4094 -- refinement.
4096 function Has_State_In_Global (List : Node_Id) return Boolean;
4097 -- Determine whether a global list mentions a state with a visible
4098 -- refinement.
4100 function Is_Refined_State (Item : Node_Id) return Boolean;
4101 -- Determine whether Item is a reference to an abstract state with a
4102 -- visible refinement.
4104 -----------------------------
4105 -- Has_State_In_Dependency --
4106 -----------------------------
4108 function Has_State_In_Dependency (List : Node_Id) return Boolean is
4109 Clause : Node_Id;
4110 Output : Node_Id;
4112 begin
4113 -- A null dependency list does not mention any states
4115 if Nkind (List) = N_Null then
4116 return False;
4118 -- Dependency clauses appear as component associations of an
4119 -- aggregate.
4121 elsif Nkind (List) = N_Aggregate
4122 and then Present (Component_Associations (List))
4123 then
4124 Clause := First (Component_Associations (List));
4125 while Present (Clause) loop
4127 -- Inspect the outputs of a dependency clause
4129 Output := First (Choices (Clause));
4130 while Present (Output) loop
4131 if Is_Refined_State (Output) then
4132 return True;
4133 end if;
4135 Next (Output);
4136 end loop;
4138 -- Inspect the outputs of a dependency clause
4140 if Is_Refined_State (Expression (Clause)) then
4141 return True;
4142 end if;
4144 Next (Clause);
4145 end loop;
4147 -- If we get here, then none of the dependency clauses mention a
4148 -- state with visible refinement.
4150 return False;
4152 -- An illegal pragma managed to sneak in
4154 else
4155 raise Program_Error;
4156 end if;
4157 end Has_State_In_Dependency;
4159 -------------------------
4160 -- Has_State_In_Global --
4161 -------------------------
4163 function Has_State_In_Global (List : Node_Id) return Boolean is
4164 Item : Node_Id;
4166 begin
4167 -- A null global list does not mention any states
4169 if Nkind (List) = N_Null then
4170 return False;
4172 -- Simple global list or moded global list declaration
4174 elsif Nkind (List) = N_Aggregate then
4176 -- The declaration of a simple global list appear as a collection
4177 -- of expressions.
4179 if Present (Expressions (List)) then
4180 Item := First (Expressions (List));
4181 while Present (Item) loop
4182 if Is_Refined_State (Item) then
4183 return True;
4184 end if;
4186 Next (Item);
4187 end loop;
4189 -- The declaration of a moded global list appears as a collection
4190 -- of component associations where individual choices denote
4191 -- modes.
4193 else
4194 Item := First (Component_Associations (List));
4195 while Present (Item) loop
4196 if Has_State_In_Global (Expression (Item)) then
4197 return True;
4198 end if;
4200 Next (Item);
4201 end loop;
4202 end if;
4204 -- If we get here, then the simple/moded global list did not
4205 -- mention any states with a visible refinement.
4207 return False;
4209 -- Single global item declaration
4211 elsif Is_Entity_Name (List) then
4212 return Is_Refined_State (List);
4214 -- An illegal pragma managed to sneak in
4216 else
4217 raise Program_Error;
4218 end if;
4219 end Has_State_In_Global;
4221 ----------------------
4222 -- Is_Refined_State --
4223 ----------------------
4225 function Is_Refined_State (Item : Node_Id) return Boolean is
4226 Elmt : Node_Id;
4227 Item_Id : Entity_Id;
4229 begin
4230 if Nkind (Item) = N_Null then
4231 return False;
4233 -- States cannot be subject to attribute 'Result. This case arises
4234 -- in dependency relations.
4236 elsif Nkind (Item) = N_Attribute_Reference
4237 and then Attribute_Name (Item) = Name_Result
4238 then
4239 return False;
4241 -- Multiple items appear as an aggregate. This case arises in
4242 -- dependency relations.
4244 elsif Nkind (Item) = N_Aggregate
4245 and then Present (Expressions (Item))
4246 then
4247 Elmt := First (Expressions (Item));
4248 while Present (Elmt) loop
4249 if Is_Refined_State (Elmt) then
4250 return True;
4251 end if;
4253 Next (Elmt);
4254 end loop;
4256 -- If we get here, then none of the inputs or outputs reference a
4257 -- state with visible refinement.
4259 return False;
4261 -- Single item
4263 else
4264 Item_Id := Entity_Of (Item);
4266 return
4267 Present (Item_Id)
4268 and then Ekind (Item_Id) = E_Abstract_State
4269 and then Has_Visible_Refinement (Item_Id);
4270 end if;
4271 end Is_Refined_State;
4273 -- Local variables
4275 Arg : constant Node_Id :=
4276 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4277 Nam : constant Name_Id := Pragma_Name (Prag);
4279 -- Start of processing for Contains_Refined_State
4281 begin
4282 if Nam = Name_Depends then
4283 return Has_State_In_Dependency (Arg);
4285 else pragma Assert (Nam = Name_Global);
4286 return Has_State_In_Global (Arg);
4287 end if;
4288 end Contains_Refined_State;
4290 -------------------------
4291 -- Copy_Component_List --
4292 -------------------------
4294 function Copy_Component_List
4295 (R_Typ : Entity_Id;
4296 Loc : Source_Ptr) return List_Id
4298 Comp : Node_Id;
4299 Comps : constant List_Id := New_List;
4301 begin
4302 Comp := First_Component (Underlying_Type (R_Typ));
4303 while Present (Comp) loop
4304 if Comes_From_Source (Comp) then
4305 declare
4306 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4307 begin
4308 Append_To (Comps,
4309 Make_Component_Declaration (Loc,
4310 Defining_Identifier =>
4311 Make_Defining_Identifier (Loc, Chars (Comp)),
4312 Component_Definition =>
4313 New_Copy_Tree
4314 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4315 end;
4316 end if;
4318 Next_Component (Comp);
4319 end loop;
4321 return Comps;
4322 end Copy_Component_List;
4324 -------------------------
4325 -- Copy_Parameter_List --
4326 -------------------------
4328 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4329 Loc : constant Source_Ptr := Sloc (Subp_Id);
4330 Plist : List_Id;
4331 Formal : Entity_Id;
4333 begin
4334 if No (First_Formal (Subp_Id)) then
4335 return No_List;
4336 else
4337 Plist := New_List;
4338 Formal := First_Formal (Subp_Id);
4339 while Present (Formal) loop
4340 Append
4341 (Make_Parameter_Specification (Loc,
4342 Defining_Identifier =>
4343 Make_Defining_Identifier (Sloc (Formal),
4344 Chars => Chars (Formal)),
4345 In_Present => In_Present (Parent (Formal)),
4346 Out_Present => Out_Present (Parent (Formal)),
4347 Parameter_Type =>
4348 New_Occurrence_Of (Etype (Formal), Loc),
4349 Expression =>
4350 New_Copy_Tree (Expression (Parent (Formal)))),
4351 Plist);
4353 Next_Formal (Formal);
4354 end loop;
4355 end if;
4357 return Plist;
4358 end Copy_Parameter_List;
4360 --------------------------------
4361 -- Corresponding_Generic_Type --
4362 --------------------------------
4364 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4365 Inst : Entity_Id;
4366 Gen : Entity_Id;
4367 Typ : Entity_Id;
4369 begin
4370 if not Is_Generic_Actual_Type (T) then
4371 return Any_Type;
4373 -- If the actual is the actual of an enclosing instance, resolution
4374 -- was correct in the generic.
4376 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4377 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4378 and then
4379 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4380 then
4381 return Any_Type;
4383 else
4384 Inst := Scope (T);
4386 if Is_Wrapper_Package (Inst) then
4387 Inst := Related_Instance (Inst);
4388 end if;
4390 Gen :=
4391 Generic_Parent
4392 (Specification (Unit_Declaration_Node (Inst)));
4394 -- Generic actual has the same name as the corresponding formal
4396 Typ := First_Entity (Gen);
4397 while Present (Typ) loop
4398 if Chars (Typ) = Chars (T) then
4399 return Typ;
4400 end if;
4402 Next_Entity (Typ);
4403 end loop;
4405 return Any_Type;
4406 end if;
4407 end Corresponding_Generic_Type;
4409 --------------------
4410 -- Current_Entity --
4411 --------------------
4413 -- The currently visible definition for a given identifier is the
4414 -- one most chained at the start of the visibility chain, i.e. the
4415 -- one that is referenced by the Node_Id value of the name of the
4416 -- given identifier.
4418 function Current_Entity (N : Node_Id) return Entity_Id is
4419 begin
4420 return Get_Name_Entity_Id (Chars (N));
4421 end Current_Entity;
4423 -----------------------------
4424 -- Current_Entity_In_Scope --
4425 -----------------------------
4427 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4428 E : Entity_Id;
4429 CS : constant Entity_Id := Current_Scope;
4431 Transient_Case : constant Boolean := Scope_Is_Transient;
4433 begin
4434 E := Get_Name_Entity_Id (Chars (N));
4435 while Present (E)
4436 and then Scope (E) /= CS
4437 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4438 loop
4439 E := Homonym (E);
4440 end loop;
4442 return E;
4443 end Current_Entity_In_Scope;
4445 -------------------
4446 -- Current_Scope --
4447 -------------------
4449 function Current_Scope return Entity_Id is
4450 begin
4451 if Scope_Stack.Last = -1 then
4452 return Standard_Standard;
4453 else
4454 declare
4455 C : constant Entity_Id :=
4456 Scope_Stack.Table (Scope_Stack.Last).Entity;
4457 begin
4458 if Present (C) then
4459 return C;
4460 else
4461 return Standard_Standard;
4462 end if;
4463 end;
4464 end if;
4465 end Current_Scope;
4467 ------------------------
4468 -- Current_Subprogram --
4469 ------------------------
4471 function Current_Subprogram return Entity_Id is
4472 Scop : constant Entity_Id := Current_Scope;
4473 begin
4474 if Is_Subprogram_Or_Generic_Subprogram (Scop) then
4475 return Scop;
4476 else
4477 return Enclosing_Subprogram (Scop);
4478 end if;
4479 end Current_Subprogram;
4481 ----------------------------------
4482 -- Deepest_Type_Access_Level --
4483 ----------------------------------
4485 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4486 begin
4487 if Ekind (Typ) = E_Anonymous_Access_Type
4488 and then not Is_Local_Anonymous_Access (Typ)
4489 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4490 then
4491 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4492 -- access type.
4494 return
4495 Scope_Depth (Enclosing_Dynamic_Scope
4496 (Defining_Identifier
4497 (Associated_Node_For_Itype (Typ))));
4499 -- For generic formal type, return Int'Last (infinite).
4500 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4502 elsif Is_Generic_Type (Root_Type (Typ)) then
4503 return UI_From_Int (Int'Last);
4505 else
4506 return Type_Access_Level (Typ);
4507 end if;
4508 end Deepest_Type_Access_Level;
4510 ---------------------
4511 -- Defining_Entity --
4512 ---------------------
4514 function Defining_Entity (N : Node_Id) return Entity_Id is
4515 K : constant Node_Kind := Nkind (N);
4516 Err : Entity_Id := Empty;
4518 begin
4519 case K is
4520 when
4521 N_Subprogram_Declaration |
4522 N_Abstract_Subprogram_Declaration |
4523 N_Subprogram_Body |
4524 N_Package_Declaration |
4525 N_Subprogram_Renaming_Declaration |
4526 N_Subprogram_Body_Stub |
4527 N_Generic_Subprogram_Declaration |
4528 N_Generic_Package_Declaration |
4529 N_Formal_Subprogram_Declaration |
4530 N_Expression_Function
4532 return Defining_Entity (Specification (N));
4534 when
4535 N_Component_Declaration |
4536 N_Defining_Program_Unit_Name |
4537 N_Discriminant_Specification |
4538 N_Entry_Body |
4539 N_Entry_Declaration |
4540 N_Entry_Index_Specification |
4541 N_Exception_Declaration |
4542 N_Exception_Renaming_Declaration |
4543 N_Formal_Object_Declaration |
4544 N_Formal_Package_Declaration |
4545 N_Formal_Type_Declaration |
4546 N_Full_Type_Declaration |
4547 N_Implicit_Label_Declaration |
4548 N_Incomplete_Type_Declaration |
4549 N_Loop_Parameter_Specification |
4550 N_Number_Declaration |
4551 N_Object_Declaration |
4552 N_Object_Renaming_Declaration |
4553 N_Package_Body_Stub |
4554 N_Parameter_Specification |
4555 N_Private_Extension_Declaration |
4556 N_Private_Type_Declaration |
4557 N_Protected_Body |
4558 N_Protected_Body_Stub |
4559 N_Protected_Type_Declaration |
4560 N_Single_Protected_Declaration |
4561 N_Single_Task_Declaration |
4562 N_Subtype_Declaration |
4563 N_Task_Body |
4564 N_Task_Body_Stub |
4565 N_Task_Type_Declaration
4567 return Defining_Identifier (N);
4569 when N_Subunit =>
4570 return Defining_Entity (Proper_Body (N));
4572 when
4573 N_Function_Instantiation |
4574 N_Function_Specification |
4575 N_Generic_Function_Renaming_Declaration |
4576 N_Generic_Package_Renaming_Declaration |
4577 N_Generic_Procedure_Renaming_Declaration |
4578 N_Package_Body |
4579 N_Package_Instantiation |
4580 N_Package_Renaming_Declaration |
4581 N_Package_Specification |
4582 N_Procedure_Instantiation |
4583 N_Procedure_Specification
4585 declare
4586 Nam : constant Node_Id := Defining_Unit_Name (N);
4588 begin
4589 if Nkind (Nam) in N_Entity then
4590 return Nam;
4592 -- For Error, make up a name and attach to declaration
4593 -- so we can continue semantic analysis
4595 elsif Nam = Error then
4596 Err := Make_Temporary (Sloc (N), 'T');
4597 Set_Defining_Unit_Name (N, Err);
4599 return Err;
4601 -- If not an entity, get defining identifier
4603 else
4604 return Defining_Identifier (Nam);
4605 end if;
4606 end;
4608 when
4609 N_Block_Statement |
4610 N_Loop_Statement
4612 return Entity (Identifier (N));
4614 when others =>
4615 raise Program_Error;
4617 end case;
4618 end Defining_Entity;
4620 --------------------------
4621 -- Denotes_Discriminant --
4622 --------------------------
4624 function Denotes_Discriminant
4625 (N : Node_Id;
4626 Check_Concurrent : Boolean := False) return Boolean
4628 E : Entity_Id;
4630 begin
4631 if not Is_Entity_Name (N) or else No (Entity (N)) then
4632 return False;
4633 else
4634 E := Entity (N);
4635 end if;
4637 -- If we are checking for a protected type, the discriminant may have
4638 -- been rewritten as the corresponding discriminal of the original type
4639 -- or of the corresponding concurrent record, depending on whether we
4640 -- are in the spec or body of the protected type.
4642 return Ekind (E) = E_Discriminant
4643 or else
4644 (Check_Concurrent
4645 and then Ekind (E) = E_In_Parameter
4646 and then Present (Discriminal_Link (E))
4647 and then
4648 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
4649 or else
4650 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
4652 end Denotes_Discriminant;
4654 -------------------------
4655 -- Denotes_Same_Object --
4656 -------------------------
4658 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
4659 Obj1 : Node_Id := A1;
4660 Obj2 : Node_Id := A2;
4662 function Has_Prefix (N : Node_Id) return Boolean;
4663 -- Return True if N has attribute Prefix
4665 function Is_Renaming (N : Node_Id) return Boolean;
4666 -- Return true if N names a renaming entity
4668 function Is_Valid_Renaming (N : Node_Id) return Boolean;
4669 -- For renamings, return False if the prefix of any dereference within
4670 -- the renamed object_name is a variable, or any expression within the
4671 -- renamed object_name contains references to variables or calls on
4672 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4674 ----------------
4675 -- Has_Prefix --
4676 ----------------
4678 function Has_Prefix (N : Node_Id) return Boolean is
4679 begin
4680 return
4681 Nkind_In (N,
4682 N_Attribute_Reference,
4683 N_Expanded_Name,
4684 N_Explicit_Dereference,
4685 N_Indexed_Component,
4686 N_Reference,
4687 N_Selected_Component,
4688 N_Slice);
4689 end Has_Prefix;
4691 -----------------
4692 -- Is_Renaming --
4693 -----------------
4695 function Is_Renaming (N : Node_Id) return Boolean is
4696 begin
4697 return Is_Entity_Name (N)
4698 and then Present (Renamed_Entity (Entity (N)));
4699 end Is_Renaming;
4701 -----------------------
4702 -- Is_Valid_Renaming --
4703 -----------------------
4705 function Is_Valid_Renaming (N : Node_Id) return Boolean is
4707 function Check_Renaming (N : Node_Id) return Boolean;
4708 -- Recursive function used to traverse all the prefixes of N
4710 function Check_Renaming (N : Node_Id) return Boolean is
4711 begin
4712 if Is_Renaming (N)
4713 and then not Check_Renaming (Renamed_Entity (Entity (N)))
4714 then
4715 return False;
4716 end if;
4718 if Nkind (N) = N_Indexed_Component then
4719 declare
4720 Indx : Node_Id;
4722 begin
4723 Indx := First (Expressions (N));
4724 while Present (Indx) loop
4725 if not Is_OK_Static_Expression (Indx) then
4726 return False;
4727 end if;
4729 Next_Index (Indx);
4730 end loop;
4731 end;
4732 end if;
4734 if Has_Prefix (N) then
4735 declare
4736 P : constant Node_Id := Prefix (N);
4738 begin
4739 if Nkind (N) = N_Explicit_Dereference
4740 and then Is_Variable (P)
4741 then
4742 return False;
4744 elsif Is_Entity_Name (P)
4745 and then Ekind (Entity (P)) = E_Function
4746 then
4747 return False;
4749 elsif Nkind (P) = N_Function_Call then
4750 return False;
4751 end if;
4753 -- Recursion to continue traversing the prefix of the
4754 -- renaming expression
4756 return Check_Renaming (P);
4757 end;
4758 end if;
4760 return True;
4761 end Check_Renaming;
4763 -- Start of processing for Is_Valid_Renaming
4765 begin
4766 return Check_Renaming (N);
4767 end Is_Valid_Renaming;
4769 -- Start of processing for Denotes_Same_Object
4771 begin
4772 -- Both names statically denote the same stand-alone object or parameter
4773 -- (RM 6.4.1(6.5/3))
4775 if Is_Entity_Name (Obj1)
4776 and then Is_Entity_Name (Obj2)
4777 and then Entity (Obj1) = Entity (Obj2)
4778 then
4779 return True;
4780 end if;
4782 -- For renamings, the prefix of any dereference within the renamed
4783 -- object_name is not a variable, and any expression within the
4784 -- renamed object_name contains no references to variables nor
4785 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4787 if Is_Renaming (Obj1) then
4788 if Is_Valid_Renaming (Obj1) then
4789 Obj1 := Renamed_Entity (Entity (Obj1));
4790 else
4791 return False;
4792 end if;
4793 end if;
4795 if Is_Renaming (Obj2) then
4796 if Is_Valid_Renaming (Obj2) then
4797 Obj2 := Renamed_Entity (Entity (Obj2));
4798 else
4799 return False;
4800 end if;
4801 end if;
4803 -- No match if not same node kind (such cases are handled by
4804 -- Denotes_Same_Prefix)
4806 if Nkind (Obj1) /= Nkind (Obj2) then
4807 return False;
4809 -- After handling valid renamings, one of the two names statically
4810 -- denoted a renaming declaration whose renamed object_name is known
4811 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4813 elsif Is_Entity_Name (Obj1) then
4814 if Is_Entity_Name (Obj2) then
4815 return Entity (Obj1) = Entity (Obj2);
4816 else
4817 return False;
4818 end if;
4820 -- Both names are selected_components, their prefixes are known to
4821 -- denote the same object, and their selector_names denote the same
4822 -- component (RM 6.4.1(6.6/3)
4824 elsif Nkind (Obj1) = N_Selected_Component then
4825 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4826 and then
4827 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
4829 -- Both names are dereferences and the dereferenced names are known to
4830 -- denote the same object (RM 6.4.1(6.7/3))
4832 elsif Nkind (Obj1) = N_Explicit_Dereference then
4833 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
4835 -- Both names are indexed_components, their prefixes are known to denote
4836 -- the same object, and each of the pairs of corresponding index values
4837 -- are either both static expressions with the same static value or both
4838 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4840 elsif Nkind (Obj1) = N_Indexed_Component then
4841 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
4842 return False;
4843 else
4844 declare
4845 Indx1 : Node_Id;
4846 Indx2 : Node_Id;
4848 begin
4849 Indx1 := First (Expressions (Obj1));
4850 Indx2 := First (Expressions (Obj2));
4851 while Present (Indx1) loop
4853 -- Indexes must denote the same static value or same object
4855 if Is_OK_Static_Expression (Indx1) then
4856 if not Is_OK_Static_Expression (Indx2) then
4857 return False;
4859 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
4860 return False;
4861 end if;
4863 elsif not Denotes_Same_Object (Indx1, Indx2) then
4864 return False;
4865 end if;
4867 Next (Indx1);
4868 Next (Indx2);
4869 end loop;
4871 return True;
4872 end;
4873 end if;
4875 -- Both names are slices, their prefixes are known to denote the same
4876 -- object, and the two slices have statically matching index constraints
4877 -- (RM 6.4.1(6.9/3))
4879 elsif Nkind (Obj1) = N_Slice
4880 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4881 then
4882 declare
4883 Lo1, Lo2, Hi1, Hi2 : Node_Id;
4885 begin
4886 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
4887 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
4889 -- Check whether bounds are statically identical. There is no
4890 -- attempt to detect partial overlap of slices.
4892 return Denotes_Same_Object (Lo1, Lo2)
4893 and then
4894 Denotes_Same_Object (Hi1, Hi2);
4895 end;
4897 -- In the recursion, literals appear as indexes
4899 elsif Nkind (Obj1) = N_Integer_Literal
4900 and then
4901 Nkind (Obj2) = N_Integer_Literal
4902 then
4903 return Intval (Obj1) = Intval (Obj2);
4905 else
4906 return False;
4907 end if;
4908 end Denotes_Same_Object;
4910 -------------------------
4911 -- Denotes_Same_Prefix --
4912 -------------------------
4914 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
4916 begin
4917 if Is_Entity_Name (A1) then
4918 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
4919 and then not Is_Access_Type (Etype (A1))
4920 then
4921 return Denotes_Same_Object (A1, Prefix (A2))
4922 or else Denotes_Same_Prefix (A1, Prefix (A2));
4923 else
4924 return False;
4925 end if;
4927 elsif Is_Entity_Name (A2) then
4928 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
4930 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
4931 and then
4932 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
4933 then
4934 declare
4935 Root1, Root2 : Node_Id;
4936 Depth1, Depth2 : Int := 0;
4938 begin
4939 Root1 := Prefix (A1);
4940 while not Is_Entity_Name (Root1) loop
4941 if not Nkind_In
4942 (Root1, N_Selected_Component, N_Indexed_Component)
4943 then
4944 return False;
4945 else
4946 Root1 := Prefix (Root1);
4947 end if;
4949 Depth1 := Depth1 + 1;
4950 end loop;
4952 Root2 := Prefix (A2);
4953 while not Is_Entity_Name (Root2) loop
4954 if not Nkind_In (Root2, N_Selected_Component,
4955 N_Indexed_Component)
4956 then
4957 return False;
4958 else
4959 Root2 := Prefix (Root2);
4960 end if;
4962 Depth2 := Depth2 + 1;
4963 end loop;
4965 -- If both have the same depth and they do not denote the same
4966 -- object, they are disjoint and no warning is needed.
4968 if Depth1 = Depth2 then
4969 return False;
4971 elsif Depth1 > Depth2 then
4972 Root1 := Prefix (A1);
4973 for J in 1 .. Depth1 - Depth2 - 1 loop
4974 Root1 := Prefix (Root1);
4975 end loop;
4977 return Denotes_Same_Object (Root1, A2);
4979 else
4980 Root2 := Prefix (A2);
4981 for J in 1 .. Depth2 - Depth1 - 1 loop
4982 Root2 := Prefix (Root2);
4983 end loop;
4985 return Denotes_Same_Object (A1, Root2);
4986 end if;
4987 end;
4989 else
4990 return False;
4991 end if;
4992 end Denotes_Same_Prefix;
4994 ----------------------
4995 -- Denotes_Variable --
4996 ----------------------
4998 function Denotes_Variable (N : Node_Id) return Boolean is
4999 begin
5000 return Is_Variable (N) and then Paren_Count (N) = 0;
5001 end Denotes_Variable;
5003 -----------------------------
5004 -- Depends_On_Discriminant --
5005 -----------------------------
5007 function Depends_On_Discriminant (N : Node_Id) return Boolean is
5008 L : Node_Id;
5009 H : Node_Id;
5011 begin
5012 Get_Index_Bounds (N, L, H);
5013 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
5014 end Depends_On_Discriminant;
5016 -------------------------
5017 -- Designate_Same_Unit --
5018 -------------------------
5020 function Designate_Same_Unit
5021 (Name1 : Node_Id;
5022 Name2 : Node_Id) return Boolean
5024 K1 : constant Node_Kind := Nkind (Name1);
5025 K2 : constant Node_Kind := Nkind (Name2);
5027 function Prefix_Node (N : Node_Id) return Node_Id;
5028 -- Returns the parent unit name node of a defining program unit name
5029 -- or the prefix if N is a selected component or an expanded name.
5031 function Select_Node (N : Node_Id) return Node_Id;
5032 -- Returns the defining identifier node of a defining program unit
5033 -- name or the selector node if N is a selected component or an
5034 -- expanded name.
5036 -----------------
5037 -- Prefix_Node --
5038 -----------------
5040 function Prefix_Node (N : Node_Id) return Node_Id is
5041 begin
5042 if Nkind (N) = N_Defining_Program_Unit_Name then
5043 return Name (N);
5044 else
5045 return Prefix (N);
5046 end if;
5047 end Prefix_Node;
5049 -----------------
5050 -- Select_Node --
5051 -----------------
5053 function Select_Node (N : Node_Id) return Node_Id is
5054 begin
5055 if Nkind (N) = N_Defining_Program_Unit_Name then
5056 return Defining_Identifier (N);
5057 else
5058 return Selector_Name (N);
5059 end if;
5060 end Select_Node;
5062 -- Start of processing for Designate_Next_Unit
5064 begin
5065 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
5066 and then
5067 (K2 = N_Identifier or else K2 = N_Defining_Identifier)
5068 then
5069 return Chars (Name1) = Chars (Name2);
5071 elsif
5072 (K1 = N_Expanded_Name or else
5073 K1 = N_Selected_Component or else
5074 K1 = N_Defining_Program_Unit_Name)
5075 and then
5076 (K2 = N_Expanded_Name or else
5077 K2 = N_Selected_Component or else
5078 K2 = N_Defining_Program_Unit_Name)
5079 then
5080 return
5081 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
5082 and then
5083 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
5085 else
5086 return False;
5087 end if;
5088 end Designate_Same_Unit;
5090 ------------------------------------------
5091 -- function Dynamic_Accessibility_Level --
5092 ------------------------------------------
5094 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
5095 E : Entity_Id;
5096 Loc : constant Source_Ptr := Sloc (Expr);
5098 function Make_Level_Literal (Level : Uint) return Node_Id;
5099 -- Construct an integer literal representing an accessibility level
5100 -- with its type set to Natural.
5102 ------------------------
5103 -- Make_Level_Literal --
5104 ------------------------
5106 function Make_Level_Literal (Level : Uint) return Node_Id is
5107 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
5108 begin
5109 Set_Etype (Result, Standard_Natural);
5110 return Result;
5111 end Make_Level_Literal;
5113 -- Start of processing for Dynamic_Accessibility_Level
5115 begin
5116 if Is_Entity_Name (Expr) then
5117 E := Entity (Expr);
5119 if Present (Renamed_Object (E)) then
5120 return Dynamic_Accessibility_Level (Renamed_Object (E));
5121 end if;
5123 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
5124 if Present (Extra_Accessibility (E)) then
5125 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
5126 end if;
5127 end if;
5128 end if;
5130 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5132 case Nkind (Expr) is
5134 -- For access discriminant, the level of the enclosing object
5136 when N_Selected_Component =>
5137 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
5138 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
5139 E_Anonymous_Access_Type
5140 then
5141 return Make_Level_Literal (Object_Access_Level (Expr));
5142 end if;
5144 when N_Attribute_Reference =>
5145 case Get_Attribute_Id (Attribute_Name (Expr)) is
5147 -- For X'Access, the level of the prefix X
5149 when Attribute_Access =>
5150 return Make_Level_Literal
5151 (Object_Access_Level (Prefix (Expr)));
5153 -- Treat the unchecked attributes as library-level
5155 when Attribute_Unchecked_Access |
5156 Attribute_Unrestricted_Access =>
5157 return Make_Level_Literal (Scope_Depth (Standard_Standard));
5159 -- No other access-valued attributes
5161 when others =>
5162 raise Program_Error;
5163 end case;
5165 when N_Allocator =>
5167 -- Unimplemented: depends on context. As an actual parameter where
5168 -- formal type is anonymous, use
5169 -- Scope_Depth (Current_Scope) + 1.
5170 -- For other cases, see 3.10.2(14/3) and following. ???
5172 null;
5174 when N_Type_Conversion =>
5175 if not Is_Local_Anonymous_Access (Etype (Expr)) then
5177 -- Handle type conversions introduced for a rename of an
5178 -- Ada 2012 stand-alone object of an anonymous access type.
5180 return Dynamic_Accessibility_Level (Expression (Expr));
5181 end if;
5183 when others =>
5184 null;
5185 end case;
5187 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5188 end Dynamic_Accessibility_Level;
5190 -----------------------------------
5191 -- Effective_Extra_Accessibility --
5192 -----------------------------------
5194 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5195 begin
5196 if Present (Renamed_Object (Id))
5197 and then Is_Entity_Name (Renamed_Object (Id))
5198 then
5199 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5200 else
5201 return Extra_Accessibility (Id);
5202 end if;
5203 end Effective_Extra_Accessibility;
5205 -----------------------------
5206 -- Effective_Reads_Enabled --
5207 -----------------------------
5209 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5210 begin
5211 return Has_Enabled_Property (Id, Name_Effective_Reads);
5212 end Effective_Reads_Enabled;
5214 ------------------------------
5215 -- Effective_Writes_Enabled --
5216 ------------------------------
5218 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5219 begin
5220 return Has_Enabled_Property (Id, Name_Effective_Writes);
5221 end Effective_Writes_Enabled;
5223 ------------------------------
5224 -- Enclosing_Comp_Unit_Node --
5225 ------------------------------
5227 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5228 Current_Node : Node_Id;
5230 begin
5231 Current_Node := N;
5232 while Present (Current_Node)
5233 and then Nkind (Current_Node) /= N_Compilation_Unit
5234 loop
5235 Current_Node := Parent (Current_Node);
5236 end loop;
5238 if Nkind (Current_Node) /= N_Compilation_Unit then
5239 return Empty;
5240 else
5241 return Current_Node;
5242 end if;
5243 end Enclosing_Comp_Unit_Node;
5245 --------------------------
5246 -- Enclosing_CPP_Parent --
5247 --------------------------
5249 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5250 Parent_Typ : Entity_Id := Typ;
5252 begin
5253 while not Is_CPP_Class (Parent_Typ)
5254 and then Etype (Parent_Typ) /= Parent_Typ
5255 loop
5256 Parent_Typ := Etype (Parent_Typ);
5258 if Is_Private_Type (Parent_Typ) then
5259 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5260 end if;
5261 end loop;
5263 pragma Assert (Is_CPP_Class (Parent_Typ));
5264 return Parent_Typ;
5265 end Enclosing_CPP_Parent;
5267 ----------------------------
5268 -- Enclosing_Generic_Body --
5269 ----------------------------
5271 function Enclosing_Generic_Body
5272 (N : Node_Id) return Node_Id
5274 P : Node_Id;
5275 Decl : Node_Id;
5276 Spec : Node_Id;
5278 begin
5279 P := Parent (N);
5280 while Present (P) loop
5281 if Nkind (P) = N_Package_Body
5282 or else Nkind (P) = N_Subprogram_Body
5283 then
5284 Spec := Corresponding_Spec (P);
5286 if Present (Spec) then
5287 Decl := Unit_Declaration_Node (Spec);
5289 if Nkind (Decl) = N_Generic_Package_Declaration
5290 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5291 then
5292 return P;
5293 end if;
5294 end if;
5295 end if;
5297 P := Parent (P);
5298 end loop;
5300 return Empty;
5301 end Enclosing_Generic_Body;
5303 ----------------------------
5304 -- Enclosing_Generic_Unit --
5305 ----------------------------
5307 function Enclosing_Generic_Unit
5308 (N : Node_Id) return Node_Id
5310 P : Node_Id;
5311 Decl : Node_Id;
5312 Spec : Node_Id;
5314 begin
5315 P := Parent (N);
5316 while Present (P) loop
5317 if Nkind (P) = N_Generic_Package_Declaration
5318 or else Nkind (P) = N_Generic_Subprogram_Declaration
5319 then
5320 return P;
5322 elsif Nkind (P) = N_Package_Body
5323 or else Nkind (P) = N_Subprogram_Body
5324 then
5325 Spec := Corresponding_Spec (P);
5327 if Present (Spec) then
5328 Decl := Unit_Declaration_Node (Spec);
5330 if Nkind (Decl) = N_Generic_Package_Declaration
5331 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5332 then
5333 return Decl;
5334 end if;
5335 end if;
5336 end if;
5338 P := Parent (P);
5339 end loop;
5341 return Empty;
5342 end Enclosing_Generic_Unit;
5344 -------------------------------
5345 -- Enclosing_Lib_Unit_Entity --
5346 -------------------------------
5348 function Enclosing_Lib_Unit_Entity
5349 (E : Entity_Id := Current_Scope) return Entity_Id
5351 Unit_Entity : Entity_Id;
5353 begin
5354 -- Look for enclosing library unit entity by following scope links.
5355 -- Equivalent to, but faster than indexing through the scope stack.
5357 Unit_Entity := E;
5358 while (Present (Scope (Unit_Entity))
5359 and then Scope (Unit_Entity) /= Standard_Standard)
5360 and not Is_Child_Unit (Unit_Entity)
5361 loop
5362 Unit_Entity := Scope (Unit_Entity);
5363 end loop;
5365 return Unit_Entity;
5366 end Enclosing_Lib_Unit_Entity;
5368 -----------------------
5369 -- Enclosing_Package --
5370 -----------------------
5372 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5373 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5375 begin
5376 if Dynamic_Scope = Standard_Standard then
5377 return Standard_Standard;
5379 elsif Dynamic_Scope = Empty then
5380 return Empty;
5382 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5383 E_Generic_Package)
5384 then
5385 return Dynamic_Scope;
5387 else
5388 return Enclosing_Package (Dynamic_Scope);
5389 end if;
5390 end Enclosing_Package;
5392 --------------------------
5393 -- Enclosing_Subprogram --
5394 --------------------------
5396 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5397 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5399 begin
5400 if Dynamic_Scope = Standard_Standard then
5401 return Empty;
5403 elsif Dynamic_Scope = Empty then
5404 return Empty;
5406 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5407 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5409 elsif Ekind (Dynamic_Scope) = E_Block
5410 or else Ekind (Dynamic_Scope) = E_Return_Statement
5411 then
5412 return Enclosing_Subprogram (Dynamic_Scope);
5414 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5415 return Get_Task_Body_Procedure (Dynamic_Scope);
5417 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5418 and then Present (Full_View (Dynamic_Scope))
5419 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5420 then
5421 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5423 -- No body is generated if the protected operation is eliminated
5425 elsif Convention (Dynamic_Scope) = Convention_Protected
5426 and then not Is_Eliminated (Dynamic_Scope)
5427 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5428 then
5429 return Protected_Body_Subprogram (Dynamic_Scope);
5431 else
5432 return Dynamic_Scope;
5433 end if;
5434 end Enclosing_Subprogram;
5436 ------------------------
5437 -- Ensure_Freeze_Node --
5438 ------------------------
5440 procedure Ensure_Freeze_Node (E : Entity_Id) is
5441 FN : Node_Id;
5442 begin
5443 if No (Freeze_Node (E)) then
5444 FN := Make_Freeze_Entity (Sloc (E));
5445 Set_Has_Delayed_Freeze (E);
5446 Set_Freeze_Node (E, FN);
5447 Set_Access_Types_To_Process (FN, No_Elist);
5448 Set_TSS_Elist (FN, No_Elist);
5449 Set_Entity (FN, E);
5450 end if;
5451 end Ensure_Freeze_Node;
5453 ----------------
5454 -- Enter_Name --
5455 ----------------
5457 procedure Enter_Name (Def_Id : Entity_Id) is
5458 C : constant Entity_Id := Current_Entity (Def_Id);
5459 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5460 S : constant Entity_Id := Current_Scope;
5462 begin
5463 Generate_Definition (Def_Id);
5465 -- Add new name to current scope declarations. Check for duplicate
5466 -- declaration, which may or may not be a genuine error.
5468 if Present (E) then
5470 -- Case of previous entity entered because of a missing declaration
5471 -- or else a bad subtype indication. Best is to use the new entity,
5472 -- and make the previous one invisible.
5474 if Etype (E) = Any_Type then
5475 Set_Is_Immediately_Visible (E, False);
5477 -- Case of renaming declaration constructed for package instances.
5478 -- if there is an explicit declaration with the same identifier,
5479 -- the renaming is not immediately visible any longer, but remains
5480 -- visible through selected component notation.
5482 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5483 and then not Comes_From_Source (E)
5484 then
5485 Set_Is_Immediately_Visible (E, False);
5487 -- The new entity may be the package renaming, which has the same
5488 -- same name as a generic formal which has been seen already.
5490 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5491 and then not Comes_From_Source (Def_Id)
5492 then
5493 Set_Is_Immediately_Visible (E, False);
5495 -- For a fat pointer corresponding to a remote access to subprogram,
5496 -- we use the same identifier as the RAS type, so that the proper
5497 -- name appears in the stub. This type is only retrieved through
5498 -- the RAS type and never by visibility, and is not added to the
5499 -- visibility list (see below).
5501 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5502 and then Ekind (Def_Id) = E_Record_Type
5503 and then Present (Corresponding_Remote_Type (Def_Id))
5504 then
5505 null;
5507 -- Case of an implicit operation or derived literal. The new entity
5508 -- hides the implicit one, which is removed from all visibility,
5509 -- i.e. the entity list of its scope, and homonym chain of its name.
5511 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5512 or else Is_Internal (E)
5513 then
5514 declare
5515 Prev : Entity_Id;
5516 Prev_Vis : Entity_Id;
5517 Decl : constant Node_Id := Parent (E);
5519 begin
5520 -- If E is an implicit declaration, it cannot be the first
5521 -- entity in the scope.
5523 Prev := First_Entity (Current_Scope);
5524 while Present (Prev) and then Next_Entity (Prev) /= E loop
5525 Next_Entity (Prev);
5526 end loop;
5528 if No (Prev) then
5530 -- If E is not on the entity chain of the current scope,
5531 -- it is an implicit declaration in the generic formal
5532 -- part of a generic subprogram. When analyzing the body,
5533 -- the generic formals are visible but not on the entity
5534 -- chain of the subprogram. The new entity will become
5535 -- the visible one in the body.
5537 pragma Assert
5538 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5539 null;
5541 else
5542 Set_Next_Entity (Prev, Next_Entity (E));
5544 if No (Next_Entity (Prev)) then
5545 Set_Last_Entity (Current_Scope, Prev);
5546 end if;
5548 if E = Current_Entity (E) then
5549 Prev_Vis := Empty;
5551 else
5552 Prev_Vis := Current_Entity (E);
5553 while Homonym (Prev_Vis) /= E loop
5554 Prev_Vis := Homonym (Prev_Vis);
5555 end loop;
5556 end if;
5558 if Present (Prev_Vis) then
5560 -- Skip E in the visibility chain
5562 Set_Homonym (Prev_Vis, Homonym (E));
5564 else
5565 Set_Name_Entity_Id (Chars (E), Homonym (E));
5566 end if;
5567 end if;
5568 end;
5570 -- This section of code could use a comment ???
5572 elsif Present (Etype (E))
5573 and then Is_Concurrent_Type (Etype (E))
5574 and then E = Def_Id
5575 then
5576 return;
5578 -- If the homograph is a protected component renaming, it should not
5579 -- be hiding the current entity. Such renamings are treated as weak
5580 -- declarations.
5582 elsif Is_Prival (E) then
5583 Set_Is_Immediately_Visible (E, False);
5585 -- In this case the current entity is a protected component renaming.
5586 -- Perform minimal decoration by setting the scope and return since
5587 -- the prival should not be hiding other visible entities.
5589 elsif Is_Prival (Def_Id) then
5590 Set_Scope (Def_Id, Current_Scope);
5591 return;
5593 -- Analogous to privals, the discriminal generated for an entry index
5594 -- parameter acts as a weak declaration. Perform minimal decoration
5595 -- to avoid bogus errors.
5597 elsif Is_Discriminal (Def_Id)
5598 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
5599 then
5600 Set_Scope (Def_Id, Current_Scope);
5601 return;
5603 -- In the body or private part of an instance, a type extension may
5604 -- introduce a component with the same name as that of an actual. The
5605 -- legality rule is not enforced, but the semantics of the full type
5606 -- with two components of same name are not clear at this point???
5608 elsif In_Instance_Not_Visible then
5609 null;
5611 -- When compiling a package body, some child units may have become
5612 -- visible. They cannot conflict with local entities that hide them.
5614 elsif Is_Child_Unit (E)
5615 and then In_Open_Scopes (Scope (E))
5616 and then not Is_Immediately_Visible (E)
5617 then
5618 null;
5620 -- Conversely, with front-end inlining we may compile the parent body
5621 -- first, and a child unit subsequently. The context is now the
5622 -- parent spec, and body entities are not visible.
5624 elsif Is_Child_Unit (Def_Id)
5625 and then Is_Package_Body_Entity (E)
5626 and then not In_Package_Body (Current_Scope)
5627 then
5628 null;
5630 -- Case of genuine duplicate declaration
5632 else
5633 Error_Msg_Sloc := Sloc (E);
5635 -- If the previous declaration is an incomplete type declaration
5636 -- this may be an attempt to complete it with a private type. The
5637 -- following avoids confusing cascaded errors.
5639 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
5640 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
5641 then
5642 Error_Msg_N
5643 ("incomplete type cannot be completed with a private " &
5644 "declaration", Parent (Def_Id));
5645 Set_Is_Immediately_Visible (E, False);
5646 Set_Full_View (E, Def_Id);
5648 -- An inherited component of a record conflicts with a new
5649 -- discriminant. The discriminant is inserted first in the scope,
5650 -- but the error should be posted on it, not on the component.
5652 elsif Ekind (E) = E_Discriminant
5653 and then Present (Scope (Def_Id))
5654 and then Scope (Def_Id) /= Current_Scope
5655 then
5656 Error_Msg_Sloc := Sloc (Def_Id);
5657 Error_Msg_N ("& conflicts with declaration#", E);
5658 return;
5660 -- If the name of the unit appears in its own context clause, a
5661 -- dummy package with the name has already been created, and the
5662 -- error emitted. Try to continue quietly.
5664 elsif Error_Posted (E)
5665 and then Sloc (E) = No_Location
5666 and then Nkind (Parent (E)) = N_Package_Specification
5667 and then Current_Scope = Standard_Standard
5668 then
5669 Set_Scope (Def_Id, Current_Scope);
5670 return;
5672 else
5673 Error_Msg_N ("& conflicts with declaration#", Def_Id);
5675 -- Avoid cascaded messages with duplicate components in
5676 -- derived types.
5678 if Ekind_In (E, E_Component, E_Discriminant) then
5679 return;
5680 end if;
5681 end if;
5683 if Nkind (Parent (Parent (Def_Id))) =
5684 N_Generic_Subprogram_Declaration
5685 and then Def_Id =
5686 Defining_Entity (Specification (Parent (Parent (Def_Id))))
5687 then
5688 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
5689 end if;
5691 -- If entity is in standard, then we are in trouble, because it
5692 -- means that we have a library package with a duplicated name.
5693 -- That's hard to recover from, so abort.
5695 if S = Standard_Standard then
5696 raise Unrecoverable_Error;
5698 -- Otherwise we continue with the declaration. Having two
5699 -- identical declarations should not cause us too much trouble.
5701 else
5702 null;
5703 end if;
5704 end if;
5705 end if;
5707 -- If we fall through, declaration is OK, at least OK enough to continue
5709 -- If Def_Id is a discriminant or a record component we are in the midst
5710 -- of inheriting components in a derived record definition. Preserve
5711 -- their Ekind and Etype.
5713 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
5714 null;
5716 -- If a type is already set, leave it alone (happens when a type
5717 -- declaration is reanalyzed following a call to the optimizer).
5719 elsif Present (Etype (Def_Id)) then
5720 null;
5722 -- Otherwise, the kind E_Void insures that premature uses of the entity
5723 -- will be detected. Any_Type insures that no cascaded errors will occur
5725 else
5726 Set_Ekind (Def_Id, E_Void);
5727 Set_Etype (Def_Id, Any_Type);
5728 end if;
5730 -- Inherited discriminants and components in derived record types are
5731 -- immediately visible. Itypes are not.
5733 -- Unless the Itype is for a record type with a corresponding remote
5734 -- type (what is that about, it was not commented ???)
5736 if Ekind_In (Def_Id, E_Discriminant, E_Component)
5737 or else
5738 ((not Is_Record_Type (Def_Id)
5739 or else No (Corresponding_Remote_Type (Def_Id)))
5740 and then not Is_Itype (Def_Id))
5741 then
5742 Set_Is_Immediately_Visible (Def_Id);
5743 Set_Current_Entity (Def_Id);
5744 end if;
5746 Set_Homonym (Def_Id, C);
5747 Append_Entity (Def_Id, S);
5748 Set_Public_Status (Def_Id);
5750 -- Declaring a homonym is not allowed in SPARK ...
5752 if Present (C) and then Restriction_Check_Required (SPARK_05) then
5753 declare
5754 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
5755 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
5756 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
5758 begin
5759 -- ... unless the new declaration is in a subprogram, and the
5760 -- visible declaration is a variable declaration or a parameter
5761 -- specification outside that subprogram.
5763 if Present (Enclosing_Subp)
5764 and then Nkind_In (Parent (C), N_Object_Declaration,
5765 N_Parameter_Specification)
5766 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
5767 then
5768 null;
5770 -- ... or the new declaration is in a package, and the visible
5771 -- declaration occurs outside that package.
5773 elsif Present (Enclosing_Pack)
5774 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
5775 then
5776 null;
5778 -- ... or the new declaration is a component declaration in a
5779 -- record type definition.
5781 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
5782 null;
5784 -- Don't issue error for non-source entities
5786 elsif Comes_From_Source (Def_Id)
5787 and then Comes_From_Source (C)
5788 then
5789 Error_Msg_Sloc := Sloc (C);
5790 Check_SPARK_05_Restriction
5791 ("redeclaration of identifier &#", Def_Id);
5792 end if;
5793 end;
5794 end if;
5796 -- Warn if new entity hides an old one
5798 if Warn_On_Hiding and then Present (C)
5800 -- Don't warn for record components since they always have a well
5801 -- defined scope which does not confuse other uses. Note that in
5802 -- some cases, Ekind has not been set yet.
5804 and then Ekind (C) /= E_Component
5805 and then Ekind (C) /= E_Discriminant
5806 and then Nkind (Parent (C)) /= N_Component_Declaration
5807 and then Ekind (Def_Id) /= E_Component
5808 and then Ekind (Def_Id) /= E_Discriminant
5809 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
5811 -- Don't warn for one character variables. It is too common to use
5812 -- such variables as locals and will just cause too many false hits.
5814 and then Length_Of_Name (Chars (C)) /= 1
5816 -- Don't warn for non-source entities
5818 and then Comes_From_Source (C)
5819 and then Comes_From_Source (Def_Id)
5821 -- Don't warn unless entity in question is in extended main source
5823 and then In_Extended_Main_Source_Unit (Def_Id)
5825 -- Finally, the hidden entity must be either immediately visible or
5826 -- use visible (i.e. from a used package).
5828 and then
5829 (Is_Immediately_Visible (C)
5830 or else
5831 Is_Potentially_Use_Visible (C))
5832 then
5833 Error_Msg_Sloc := Sloc (C);
5834 Error_Msg_N ("declaration hides &#?h?", Def_Id);
5835 end if;
5836 end Enter_Name;
5838 ---------------
5839 -- Entity_Of --
5840 ---------------
5842 function Entity_Of (N : Node_Id) return Entity_Id is
5843 Id : Entity_Id;
5845 begin
5846 Id := Empty;
5848 if Is_Entity_Name (N) then
5849 Id := Entity (N);
5851 -- Follow a possible chain of renamings to reach the root renamed
5852 -- object.
5854 while Present (Id) and then Present (Renamed_Object (Id)) loop
5855 if Is_Entity_Name (Renamed_Object (Id)) then
5856 Id := Entity (Renamed_Object (Id));
5857 else
5858 Id := Empty;
5859 exit;
5860 end if;
5861 end loop;
5862 end if;
5864 return Id;
5865 end Entity_Of;
5867 --------------------------
5868 -- Explain_Limited_Type --
5869 --------------------------
5871 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
5872 C : Entity_Id;
5874 begin
5875 -- For array, component type must be limited
5877 if Is_Array_Type (T) then
5878 Error_Msg_Node_2 := T;
5879 Error_Msg_NE
5880 ("\component type& of type& is limited", N, Component_Type (T));
5881 Explain_Limited_Type (Component_Type (T), N);
5883 elsif Is_Record_Type (T) then
5885 -- No need for extra messages if explicit limited record
5887 if Is_Limited_Record (Base_Type (T)) then
5888 return;
5889 end if;
5891 -- Otherwise find a limited component. Check only components that
5892 -- come from source, or inherited components that appear in the
5893 -- source of the ancestor.
5895 C := First_Component (T);
5896 while Present (C) loop
5897 if Is_Limited_Type (Etype (C))
5898 and then
5899 (Comes_From_Source (C)
5900 or else
5901 (Present (Original_Record_Component (C))
5902 and then
5903 Comes_From_Source (Original_Record_Component (C))))
5904 then
5905 Error_Msg_Node_2 := T;
5906 Error_Msg_NE ("\component& of type& has limited type", N, C);
5907 Explain_Limited_Type (Etype (C), N);
5908 return;
5909 end if;
5911 Next_Component (C);
5912 end loop;
5914 -- The type may be declared explicitly limited, even if no component
5915 -- of it is limited, in which case we fall out of the loop.
5916 return;
5917 end if;
5918 end Explain_Limited_Type;
5920 -------------------------------
5921 -- Extensions_Visible_Status --
5922 -------------------------------
5924 function Extensions_Visible_Status
5925 (Id : Entity_Id) return Extensions_Visible_Mode
5927 Arg : Node_Id;
5928 Decl : Node_Id;
5929 Expr : Node_Id;
5930 Prag : Node_Id;
5931 Subp : Entity_Id;
5933 begin
5934 -- When a formal parameter is subject to Extensions_Visible, the pragma
5935 -- is stored in the contract of related subprogram.
5937 if Is_Formal (Id) then
5938 Subp := Scope (Id);
5940 elsif Is_Subprogram_Or_Generic_Subprogram (Id) then
5941 Subp := Id;
5943 -- No other construct carries this pragma
5945 else
5946 return Extensions_Visible_None;
5947 end if;
5949 Prag := Get_Pragma (Subp, Pragma_Extensions_Visible);
5951 -- In certain cases analysis may request the Extensions_Visible status
5952 -- of an expression function before the pragma has been analyzed yet.
5953 -- Inspect the declarative items after the expression function looking
5954 -- for the pragma (if any).
5956 if No (Prag) and then Is_Expression_Function (Subp) then
5957 Decl := Next (Unit_Declaration_Node (Subp));
5958 while Present (Decl) loop
5959 if Nkind (Decl) = N_Pragma
5960 and then Pragma_Name (Decl) = Name_Extensions_Visible
5961 then
5962 Prag := Decl;
5963 exit;
5965 -- A source construct ends the region where Extensions_Visible may
5966 -- appear, stop the traversal. An expanded expression function is
5967 -- no longer a source construct, but it must still be recognized.
5969 elsif Comes_From_Source (Decl)
5970 or else
5971 (Nkind_In (Decl, N_Subprogram_Body,
5972 N_Subprogram_Declaration)
5973 and then Is_Expression_Function (Defining_Entity (Decl)))
5974 then
5975 exit;
5976 end if;
5978 Next (Decl);
5979 end loop;
5980 end if;
5982 -- Extract the value from the Boolean expression (if any)
5984 if Present (Prag) then
5985 Arg := First (Pragma_Argument_Associations (Prag));
5987 if Present (Arg) then
5988 Expr := Get_Pragma_Arg (Arg);
5990 -- When the associated subprogram is an expression function, the
5991 -- argument of the pragma may not have been analyzed.
5993 if not Analyzed (Expr) then
5994 Preanalyze_And_Resolve (Expr, Standard_Boolean);
5995 end if;
5997 -- Guard against cascading errors when the argument of pragma
5998 -- Extensions_Visible is not a valid static Boolean expression.
6000 if Error_Posted (Expr) then
6001 return Extensions_Visible_None;
6003 elsif Is_True (Expr_Value (Expr)) then
6004 return Extensions_Visible_True;
6006 else
6007 return Extensions_Visible_False;
6008 end if;
6010 -- Otherwise the aspect or pragma defaults to True
6012 else
6013 return Extensions_Visible_True;
6014 end if;
6016 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6017 -- directly specified. In SPARK code, its value defaults to "False".
6019 elsif SPARK_Mode = On then
6020 return Extensions_Visible_False;
6022 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6023 -- "True".
6025 else
6026 return Extensions_Visible_True;
6027 end if;
6028 end Extensions_Visible_Status;
6030 -----------------
6031 -- Find_Actual --
6032 -----------------
6034 procedure Find_Actual
6035 (N : Node_Id;
6036 Formal : out Entity_Id;
6037 Call : out Node_Id)
6039 Parnt : constant Node_Id := Parent (N);
6040 Actual : Node_Id;
6042 begin
6043 if Nkind_In (Parnt, N_Indexed_Component, N_Selected_Component)
6044 and then N = Prefix (Parnt)
6045 then
6046 Find_Actual (Parnt, Formal, Call);
6047 return;
6049 elsif Nkind (Parnt) = N_Parameter_Association
6050 and then N = Explicit_Actual_Parameter (Parnt)
6051 then
6052 Call := Parent (Parnt);
6054 elsif Nkind (Parnt) in N_Subprogram_Call then
6055 Call := Parnt;
6057 else
6058 Formal := Empty;
6059 Call := Empty;
6060 return;
6061 end if;
6063 -- If we have a call to a subprogram look for the parameter. Note that
6064 -- we exclude overloaded calls, since we don't know enough to be sure
6065 -- of giving the right answer in this case.
6067 if Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
6068 and then Is_Entity_Name (Name (Call))
6069 and then Present (Entity (Name (Call)))
6070 and then Is_Overloadable (Entity (Name (Call)))
6071 and then not Is_Overloaded (Name (Call))
6072 then
6073 -- Fall here if we are definitely a parameter
6075 Actual := First_Actual (Call);
6076 Formal := First_Formal (Entity (Name (Call)));
6077 while Present (Formal) and then Present (Actual) loop
6078 if Actual = N then
6079 return;
6081 -- An actual that is the prefix in a prefixed call may have
6082 -- been rewritten in the call, after the deferred reference
6083 -- was collected. Check if sloc and kinds and names match.
6085 elsif Sloc (Actual) = Sloc (N)
6086 and then Nkind (Actual) = N_Identifier
6087 and then Nkind (Actual) = Nkind (N)
6088 and then Chars (Actual) = Chars (N)
6089 then
6090 return;
6092 else
6093 Actual := Next_Actual (Actual);
6094 Formal := Next_Formal (Formal);
6095 end if;
6096 end loop;
6097 end if;
6099 -- Fall through here if we did not find matching actual
6101 Formal := Empty;
6102 Call := Empty;
6103 end Find_Actual;
6105 ---------------------------
6106 -- Find_Body_Discriminal --
6107 ---------------------------
6109 function Find_Body_Discriminal
6110 (Spec_Discriminant : Entity_Id) return Entity_Id
6112 Tsk : Entity_Id;
6113 Disc : Entity_Id;
6115 begin
6116 -- If expansion is suppressed, then the scope can be the concurrent type
6117 -- itself rather than a corresponding concurrent record type.
6119 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
6120 Tsk := Scope (Spec_Discriminant);
6122 else
6123 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
6125 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
6126 end if;
6128 -- Find discriminant of original concurrent type, and use its current
6129 -- discriminal, which is the renaming within the task/protected body.
6131 Disc := First_Discriminant (Tsk);
6132 while Present (Disc) loop
6133 if Chars (Disc) = Chars (Spec_Discriminant) then
6134 return Discriminal (Disc);
6135 end if;
6137 Next_Discriminant (Disc);
6138 end loop;
6140 -- That loop should always succeed in finding a matching entry and
6141 -- returning. Fatal error if not.
6143 raise Program_Error;
6144 end Find_Body_Discriminal;
6146 -------------------------------------
6147 -- Find_Corresponding_Discriminant --
6148 -------------------------------------
6150 function Find_Corresponding_Discriminant
6151 (Id : Node_Id;
6152 Typ : Entity_Id) return Entity_Id
6154 Par_Disc : Entity_Id;
6155 Old_Disc : Entity_Id;
6156 New_Disc : Entity_Id;
6158 begin
6159 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
6161 -- The original type may currently be private, and the discriminant
6162 -- only appear on its full view.
6164 if Is_Private_Type (Scope (Par_Disc))
6165 and then not Has_Discriminants (Scope (Par_Disc))
6166 and then Present (Full_View (Scope (Par_Disc)))
6167 then
6168 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
6169 else
6170 Old_Disc := First_Discriminant (Scope (Par_Disc));
6171 end if;
6173 if Is_Class_Wide_Type (Typ) then
6174 New_Disc := First_Discriminant (Root_Type (Typ));
6175 else
6176 New_Disc := First_Discriminant (Typ);
6177 end if;
6179 while Present (Old_Disc) and then Present (New_Disc) loop
6180 if Old_Disc = Par_Disc then
6181 return New_Disc;
6182 end if;
6184 Next_Discriminant (Old_Disc);
6185 Next_Discriminant (New_Disc);
6186 end loop;
6188 -- Should always find it
6190 raise Program_Error;
6191 end Find_Corresponding_Discriminant;
6193 ----------------------------------
6194 -- Find_Enclosing_Iterator_Loop --
6195 ----------------------------------
6197 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
6198 Constr : Node_Id;
6199 S : Entity_Id;
6201 begin
6202 -- Traverse the scope chain looking for an iterator loop. Such loops are
6203 -- usually transformed into blocks, hence the use of Original_Node.
6205 S := Id;
6206 while Present (S) and then S /= Standard_Standard loop
6207 if Ekind (S) = E_Loop
6208 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
6209 then
6210 Constr := Original_Node (Label_Construct (Parent (S)));
6212 if Nkind (Constr) = N_Loop_Statement
6213 and then Present (Iteration_Scheme (Constr))
6214 and then Nkind (Iterator_Specification
6215 (Iteration_Scheme (Constr))) =
6216 N_Iterator_Specification
6217 then
6218 return S;
6219 end if;
6220 end if;
6222 S := Scope (S);
6223 end loop;
6225 return Empty;
6226 end Find_Enclosing_Iterator_Loop;
6228 ------------------------------------
6229 -- Find_Loop_In_Conditional_Block --
6230 ------------------------------------
6232 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
6233 Stmt : Node_Id;
6235 begin
6236 Stmt := N;
6238 if Nkind (Stmt) = N_If_Statement then
6239 Stmt := First (Then_Statements (Stmt));
6240 end if;
6242 pragma Assert (Nkind (Stmt) = N_Block_Statement);
6244 -- Inspect the statements of the conditional block. In general the loop
6245 -- should be the first statement in the statement sequence of the block,
6246 -- but the finalization machinery may have introduced extra object
6247 -- declarations.
6249 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
6250 while Present (Stmt) loop
6251 if Nkind (Stmt) = N_Loop_Statement then
6252 return Stmt;
6253 end if;
6255 Next (Stmt);
6256 end loop;
6258 -- The expansion of attribute 'Loop_Entry produced a malformed block
6260 raise Program_Error;
6261 end Find_Loop_In_Conditional_Block;
6263 --------------------------
6264 -- Find_Overlaid_Entity --
6265 --------------------------
6267 procedure Find_Overlaid_Entity
6268 (N : Node_Id;
6269 Ent : out Entity_Id;
6270 Off : out Boolean)
6272 Expr : Node_Id;
6274 begin
6275 -- We are looking for one of the two following forms:
6277 -- for X'Address use Y'Address
6279 -- or
6281 -- Const : constant Address := expr;
6282 -- ...
6283 -- for X'Address use Const;
6285 -- In the second case, the expr is either Y'Address, or recursively a
6286 -- constant that eventually references Y'Address.
6288 Ent := Empty;
6289 Off := False;
6291 if Nkind (N) = N_Attribute_Definition_Clause
6292 and then Chars (N) = Name_Address
6293 then
6294 Expr := Expression (N);
6296 -- This loop checks the form of the expression for Y'Address,
6297 -- using recursion to deal with intermediate constants.
6299 loop
6300 -- Check for Y'Address
6302 if Nkind (Expr) = N_Attribute_Reference
6303 and then Attribute_Name (Expr) = Name_Address
6304 then
6305 Expr := Prefix (Expr);
6306 exit;
6308 -- Check for Const where Const is a constant entity
6310 elsif Is_Entity_Name (Expr)
6311 and then Ekind (Entity (Expr)) = E_Constant
6312 then
6313 Expr := Constant_Value (Entity (Expr));
6315 -- Anything else does not need checking
6317 else
6318 return;
6319 end if;
6320 end loop;
6322 -- This loop checks the form of the prefix for an entity, using
6323 -- recursion to deal with intermediate components.
6325 loop
6326 -- Check for Y where Y is an entity
6328 if Is_Entity_Name (Expr) then
6329 Ent := Entity (Expr);
6330 return;
6332 -- Check for components
6334 elsif
6335 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6336 then
6337 Expr := Prefix (Expr);
6338 Off := True;
6340 -- Anything else does not need checking
6342 else
6343 return;
6344 end if;
6345 end loop;
6346 end if;
6347 end Find_Overlaid_Entity;
6349 -------------------------
6350 -- Find_Parameter_Type --
6351 -------------------------
6353 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6354 begin
6355 if Nkind (Param) /= N_Parameter_Specification then
6356 return Empty;
6358 -- For an access parameter, obtain the type from the formal entity
6359 -- itself, because access to subprogram nodes do not carry a type.
6360 -- Shouldn't we always use the formal entity ???
6362 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6363 return Etype (Defining_Identifier (Param));
6365 else
6366 return Etype (Parameter_Type (Param));
6367 end if;
6368 end Find_Parameter_Type;
6370 -----------------------------------
6371 -- Find_Placement_In_State_Space --
6372 -----------------------------------
6374 procedure Find_Placement_In_State_Space
6375 (Item_Id : Entity_Id;
6376 Placement : out State_Space_Kind;
6377 Pack_Id : out Entity_Id)
6379 Context : Entity_Id;
6381 begin
6382 -- Assume that the item does not appear in the state space of a package
6384 Placement := Not_In_Package;
6385 Pack_Id := Empty;
6387 -- Climb the scope stack and examine the enclosing context
6389 Context := Scope (Item_Id);
6390 while Present (Context) and then Context /= Standard_Standard loop
6391 if Ekind (Context) = E_Package then
6392 Pack_Id := Context;
6394 -- A package body is a cut off point for the traversal as the item
6395 -- cannot be visible to the outside from this point on. Note that
6396 -- this test must be done first as a body is also classified as a
6397 -- private part.
6399 if In_Package_Body (Context) then
6400 Placement := Body_State_Space;
6401 return;
6403 -- The private part of a package is a cut off point for the
6404 -- traversal as the item cannot be visible to the outside from
6405 -- this point on.
6407 elsif In_Private_Part (Context) then
6408 Placement := Private_State_Space;
6409 return;
6411 -- When the item appears in the visible state space of a package,
6412 -- continue to climb the scope stack as this may not be the final
6413 -- state space.
6415 else
6416 Placement := Visible_State_Space;
6418 -- The visible state space of a child unit acts as the proper
6419 -- placement of an item.
6421 if Is_Child_Unit (Context) then
6422 return;
6423 end if;
6424 end if;
6426 -- The item or its enclosing package appear in a construct that has
6427 -- no state space.
6429 else
6430 Placement := Not_In_Package;
6431 return;
6432 end if;
6434 Context := Scope (Context);
6435 end loop;
6436 end Find_Placement_In_State_Space;
6438 ------------------------
6439 -- Find_Specific_Type --
6440 ------------------------
6442 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6443 Typ : Entity_Id := Root_Type (CW);
6445 begin
6446 if Ekind (Typ) = E_Incomplete_Type then
6447 if From_Limited_With (Typ) then
6448 Typ := Non_Limited_View (Typ);
6449 else
6450 Typ := Full_View (Typ);
6451 end if;
6452 end if;
6454 if Is_Private_Type (Typ)
6455 and then not Is_Tagged_Type (Typ)
6456 and then Present (Full_View (Typ))
6457 then
6458 return Full_View (Typ);
6459 else
6460 return Typ;
6461 end if;
6462 end Find_Specific_Type;
6464 -----------------------------
6465 -- Find_Static_Alternative --
6466 -----------------------------
6468 function Find_Static_Alternative (N : Node_Id) return Node_Id is
6469 Expr : constant Node_Id := Expression (N);
6470 Val : constant Uint := Expr_Value (Expr);
6471 Alt : Node_Id;
6472 Choice : Node_Id;
6474 begin
6475 Alt := First (Alternatives (N));
6477 Search : loop
6478 if Nkind (Alt) /= N_Pragma then
6479 Choice := First (Discrete_Choices (Alt));
6480 while Present (Choice) loop
6482 -- Others choice, always matches
6484 if Nkind (Choice) = N_Others_Choice then
6485 exit Search;
6487 -- Range, check if value is in the range
6489 elsif Nkind (Choice) = N_Range then
6490 exit Search when
6491 Val >= Expr_Value (Low_Bound (Choice))
6492 and then
6493 Val <= Expr_Value (High_Bound (Choice));
6495 -- Choice is a subtype name. Note that we know it must
6496 -- be a static subtype, since otherwise it would have
6497 -- been diagnosed as illegal.
6499 elsif Is_Entity_Name (Choice)
6500 and then Is_Type (Entity (Choice))
6501 then
6502 exit Search when Is_In_Range (Expr, Etype (Choice),
6503 Assume_Valid => False);
6505 -- Choice is a subtype indication
6507 elsif Nkind (Choice) = N_Subtype_Indication then
6508 declare
6509 C : constant Node_Id := Constraint (Choice);
6510 R : constant Node_Id := Range_Expression (C);
6512 begin
6513 exit Search when
6514 Val >= Expr_Value (Low_Bound (R))
6515 and then
6516 Val <= Expr_Value (High_Bound (R));
6517 end;
6519 -- Choice is a simple expression
6521 else
6522 exit Search when Val = Expr_Value (Choice);
6523 end if;
6525 Next (Choice);
6526 end loop;
6527 end if;
6529 Next (Alt);
6530 pragma Assert (Present (Alt));
6531 end loop Search;
6533 -- The above loop *must* terminate by finding a match, since
6534 -- we know the case statement is valid, and the value of the
6535 -- expression is known at compile time. When we fall out of
6536 -- the loop, Alt points to the alternative that we know will
6537 -- be selected at run time.
6539 return Alt;
6540 end Find_Static_Alternative;
6542 ------------------
6543 -- First_Actual --
6544 ------------------
6546 function First_Actual (Node : Node_Id) return Node_Id is
6547 N : Node_Id;
6549 begin
6550 if No (Parameter_Associations (Node)) then
6551 return Empty;
6552 end if;
6554 N := First (Parameter_Associations (Node));
6556 if Nkind (N) = N_Parameter_Association then
6557 return First_Named_Actual (Node);
6558 else
6559 return N;
6560 end if;
6561 end First_Actual;
6563 -----------------------
6564 -- Gather_Components --
6565 -----------------------
6567 procedure Gather_Components
6568 (Typ : Entity_Id;
6569 Comp_List : Node_Id;
6570 Governed_By : List_Id;
6571 Into : Elist_Id;
6572 Report_Errors : out Boolean)
6574 Assoc : Node_Id;
6575 Variant : Node_Id;
6576 Discrete_Choice : Node_Id;
6577 Comp_Item : Node_Id;
6579 Discrim : Entity_Id;
6580 Discrim_Name : Node_Id;
6581 Discrim_Value : Node_Id;
6583 begin
6584 Report_Errors := False;
6586 if No (Comp_List) or else Null_Present (Comp_List) then
6587 return;
6589 elsif Present (Component_Items (Comp_List)) then
6590 Comp_Item := First (Component_Items (Comp_List));
6592 else
6593 Comp_Item := Empty;
6594 end if;
6596 while Present (Comp_Item) loop
6598 -- Skip the tag of a tagged record, the interface tags, as well
6599 -- as all items that are not user components (anonymous types,
6600 -- rep clauses, Parent field, controller field).
6602 if Nkind (Comp_Item) = N_Component_Declaration then
6603 declare
6604 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
6605 begin
6606 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
6607 Append_Elmt (Comp, Into);
6608 end if;
6609 end;
6610 end if;
6612 Next (Comp_Item);
6613 end loop;
6615 if No (Variant_Part (Comp_List)) then
6616 return;
6617 else
6618 Discrim_Name := Name (Variant_Part (Comp_List));
6619 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
6620 end if;
6622 -- Look for the discriminant that governs this variant part.
6623 -- The discriminant *must* be in the Governed_By List
6625 Assoc := First (Governed_By);
6626 Find_Constraint : loop
6627 Discrim := First (Choices (Assoc));
6628 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
6629 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
6630 and then
6631 Chars (Corresponding_Discriminant (Entity (Discrim))) =
6632 Chars (Discrim_Name))
6633 or else Chars (Original_Record_Component (Entity (Discrim)))
6634 = Chars (Discrim_Name);
6636 if No (Next (Assoc)) then
6637 if not Is_Constrained (Typ)
6638 and then Is_Derived_Type (Typ)
6639 and then Present (Stored_Constraint (Typ))
6640 then
6641 -- If the type is a tagged type with inherited discriminants,
6642 -- use the stored constraint on the parent in order to find
6643 -- the values of discriminants that are otherwise hidden by an
6644 -- explicit constraint. Renamed discriminants are handled in
6645 -- the code above.
6647 -- If several parent discriminants are renamed by a single
6648 -- discriminant of the derived type, the call to obtain the
6649 -- Corresponding_Discriminant field only retrieves the last
6650 -- of them. We recover the constraint on the others from the
6651 -- Stored_Constraint as well.
6653 declare
6654 D : Entity_Id;
6655 C : Elmt_Id;
6657 begin
6658 D := First_Discriminant (Etype (Typ));
6659 C := First_Elmt (Stored_Constraint (Typ));
6660 while Present (D) and then Present (C) loop
6661 if Chars (Discrim_Name) = Chars (D) then
6662 if Is_Entity_Name (Node (C))
6663 and then Entity (Node (C)) = Entity (Discrim)
6664 then
6665 -- D is renamed by Discrim, whose value is given in
6666 -- Assoc.
6668 null;
6670 else
6671 Assoc :=
6672 Make_Component_Association (Sloc (Typ),
6673 New_List
6674 (New_Occurrence_Of (D, Sloc (Typ))),
6675 Duplicate_Subexpr_No_Checks (Node (C)));
6676 end if;
6677 exit Find_Constraint;
6678 end if;
6680 Next_Discriminant (D);
6681 Next_Elmt (C);
6682 end loop;
6683 end;
6684 end if;
6685 end if;
6687 if No (Next (Assoc)) then
6688 Error_Msg_NE (" missing value for discriminant&",
6689 First (Governed_By), Discrim_Name);
6690 Report_Errors := True;
6691 return;
6692 end if;
6694 Next (Assoc);
6695 end loop Find_Constraint;
6697 Discrim_Value := Expression (Assoc);
6699 if not Is_OK_Static_Expression (Discrim_Value) then
6700 Error_Msg_FE
6701 ("value for discriminant & must be static!",
6702 Discrim_Value, Discrim);
6703 Why_Not_Static (Discrim_Value);
6704 Report_Errors := True;
6705 return;
6706 end if;
6708 Search_For_Discriminant_Value : declare
6709 Low : Node_Id;
6710 High : Node_Id;
6712 UI_High : Uint;
6713 UI_Low : Uint;
6714 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
6716 begin
6717 Find_Discrete_Value : while Present (Variant) loop
6718 Discrete_Choice := First (Discrete_Choices (Variant));
6719 while Present (Discrete_Choice) loop
6720 exit Find_Discrete_Value when
6721 Nkind (Discrete_Choice) = N_Others_Choice;
6723 Get_Index_Bounds (Discrete_Choice, Low, High);
6725 UI_Low := Expr_Value (Low);
6726 UI_High := Expr_Value (High);
6728 exit Find_Discrete_Value when
6729 UI_Low <= UI_Discrim_Value
6730 and then
6731 UI_High >= UI_Discrim_Value;
6733 Next (Discrete_Choice);
6734 end loop;
6736 Next_Non_Pragma (Variant);
6737 end loop Find_Discrete_Value;
6738 end Search_For_Discriminant_Value;
6740 if No (Variant) then
6741 Error_Msg_NE
6742 ("value of discriminant & is out of range", Discrim_Value, Discrim);
6743 Report_Errors := True;
6744 return;
6745 end if;
6747 -- If we have found the corresponding choice, recursively add its
6748 -- components to the Into list.
6750 Gather_Components
6751 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
6752 end Gather_Components;
6754 ------------------------
6755 -- Get_Actual_Subtype --
6756 ------------------------
6758 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
6759 Typ : constant Entity_Id := Etype (N);
6760 Utyp : Entity_Id := Underlying_Type (Typ);
6761 Decl : Node_Id;
6762 Atyp : Entity_Id;
6764 begin
6765 if No (Utyp) then
6766 Utyp := Typ;
6767 end if;
6769 -- If what we have is an identifier that references a subprogram
6770 -- formal, or a variable or constant object, then we get the actual
6771 -- subtype from the referenced entity if one has been built.
6773 if Nkind (N) = N_Identifier
6774 and then
6775 (Is_Formal (Entity (N))
6776 or else Ekind (Entity (N)) = E_Constant
6777 or else Ekind (Entity (N)) = E_Variable)
6778 and then Present (Actual_Subtype (Entity (N)))
6779 then
6780 return Actual_Subtype (Entity (N));
6782 -- Actual subtype of unchecked union is always itself. We never need
6783 -- the "real" actual subtype. If we did, we couldn't get it anyway
6784 -- because the discriminant is not available. The restrictions on
6785 -- Unchecked_Union are designed to make sure that this is OK.
6787 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
6788 return Typ;
6790 -- Here for the unconstrained case, we must find actual subtype
6791 -- No actual subtype is available, so we must build it on the fly.
6793 -- Checking the type, not the underlying type, for constrainedness
6794 -- seems to be necessary. Maybe all the tests should be on the type???
6796 elsif (not Is_Constrained (Typ))
6797 and then (Is_Array_Type (Utyp)
6798 or else (Is_Record_Type (Utyp)
6799 and then Has_Discriminants (Utyp)))
6800 and then not Has_Unknown_Discriminants (Utyp)
6801 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
6802 then
6803 -- Nothing to do if in spec expression (why not???)
6805 if In_Spec_Expression then
6806 return Typ;
6808 elsif Is_Private_Type (Typ) and then not Has_Discriminants (Typ) then
6810 -- If the type has no discriminants, there is no subtype to
6811 -- build, even if the underlying type is discriminated.
6813 return Typ;
6815 -- Else build the actual subtype
6817 else
6818 Decl := Build_Actual_Subtype (Typ, N);
6819 Atyp := Defining_Identifier (Decl);
6821 -- If Build_Actual_Subtype generated a new declaration then use it
6823 if Atyp /= Typ then
6825 -- The actual subtype is an Itype, so analyze the declaration,
6826 -- but do not attach it to the tree, to get the type defined.
6828 Set_Parent (Decl, N);
6829 Set_Is_Itype (Atyp);
6830 Analyze (Decl, Suppress => All_Checks);
6831 Set_Associated_Node_For_Itype (Atyp, N);
6832 Set_Has_Delayed_Freeze (Atyp, False);
6834 -- We need to freeze the actual subtype immediately. This is
6835 -- needed, because otherwise this Itype will not get frozen
6836 -- at all, and it is always safe to freeze on creation because
6837 -- any associated types must be frozen at this point.
6839 Freeze_Itype (Atyp, N);
6840 return Atyp;
6842 -- Otherwise we did not build a declaration, so return original
6844 else
6845 return Typ;
6846 end if;
6847 end if;
6849 -- For all remaining cases, the actual subtype is the same as
6850 -- the nominal type.
6852 else
6853 return Typ;
6854 end if;
6855 end Get_Actual_Subtype;
6857 -------------------------------------
6858 -- Get_Actual_Subtype_If_Available --
6859 -------------------------------------
6861 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
6862 Typ : constant Entity_Id := Etype (N);
6864 begin
6865 -- If what we have is an identifier that references a subprogram
6866 -- formal, or a variable or constant object, then we get the actual
6867 -- subtype from the referenced entity if one has been built.
6869 if Nkind (N) = N_Identifier
6870 and then
6871 (Is_Formal (Entity (N))
6872 or else Ekind (Entity (N)) = E_Constant
6873 or else Ekind (Entity (N)) = E_Variable)
6874 and then Present (Actual_Subtype (Entity (N)))
6875 then
6876 return Actual_Subtype (Entity (N));
6878 -- Otherwise the Etype of N is returned unchanged
6880 else
6881 return Typ;
6882 end if;
6883 end Get_Actual_Subtype_If_Available;
6885 ------------------------
6886 -- Get_Body_From_Stub --
6887 ------------------------
6889 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
6890 begin
6891 return Proper_Body (Unit (Library_Unit (N)));
6892 end Get_Body_From_Stub;
6894 ---------------------
6895 -- Get_Cursor_Type --
6896 ---------------------
6898 function Get_Cursor_Type
6899 (Aspect : Node_Id;
6900 Typ : Entity_Id) return Entity_Id
6902 Assoc : Node_Id;
6903 Func : Entity_Id;
6904 First_Op : Entity_Id;
6905 Cursor : Entity_Id;
6907 begin
6908 -- If error already detected, return
6910 if Error_Posted (Aspect) then
6911 return Any_Type;
6912 end if;
6914 -- The cursor type for an Iterable aspect is the return type of a
6915 -- non-overloaded First primitive operation. Locate association for
6916 -- First.
6918 Assoc := First (Component_Associations (Expression (Aspect)));
6919 First_Op := Any_Id;
6920 while Present (Assoc) loop
6921 if Chars (First (Choices (Assoc))) = Name_First then
6922 First_Op := Expression (Assoc);
6923 exit;
6924 end if;
6926 Next (Assoc);
6927 end loop;
6929 if First_Op = Any_Id then
6930 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
6931 return Any_Type;
6932 end if;
6934 Cursor := Any_Type;
6936 -- Locate function with desired name and profile in scope of type
6938 Func := First_Entity (Scope (Typ));
6939 while Present (Func) loop
6940 if Chars (Func) = Chars (First_Op)
6941 and then Ekind (Func) = E_Function
6942 and then Present (First_Formal (Func))
6943 and then Etype (First_Formal (Func)) = Typ
6944 and then No (Next_Formal (First_Formal (Func)))
6945 then
6946 if Cursor /= Any_Type then
6947 Error_Msg_N
6948 ("Operation First for iterable type must be unique", Aspect);
6949 return Any_Type;
6950 else
6951 Cursor := Etype (Func);
6952 end if;
6953 end if;
6955 Next_Entity (Func);
6956 end loop;
6958 -- If not found, no way to resolve remaining primitives.
6960 if Cursor = Any_Type then
6961 Error_Msg_N
6962 ("No legal primitive operation First for Iterable type", Aspect);
6963 end if;
6965 return Cursor;
6966 end Get_Cursor_Type;
6968 -------------------------------
6969 -- Get_Default_External_Name --
6970 -------------------------------
6972 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
6973 begin
6974 Get_Decoded_Name_String (Chars (E));
6976 if Opt.External_Name_Imp_Casing = Uppercase then
6977 Set_Casing (All_Upper_Case);
6978 else
6979 Set_Casing (All_Lower_Case);
6980 end if;
6982 return
6983 Make_String_Literal (Sloc (E),
6984 Strval => String_From_Name_Buffer);
6985 end Get_Default_External_Name;
6987 --------------------------
6988 -- Get_Enclosing_Object --
6989 --------------------------
6991 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
6992 begin
6993 if Is_Entity_Name (N) then
6994 return Entity (N);
6995 else
6996 case Nkind (N) is
6997 when N_Indexed_Component |
6998 N_Slice |
6999 N_Selected_Component =>
7001 -- If not generating code, a dereference may be left implicit.
7002 -- In thoses cases, return Empty.
7004 if Is_Access_Type (Etype (Prefix (N))) then
7005 return Empty;
7006 else
7007 return Get_Enclosing_Object (Prefix (N));
7008 end if;
7010 when N_Type_Conversion =>
7011 return Get_Enclosing_Object (Expression (N));
7013 when others =>
7014 return Empty;
7015 end case;
7016 end if;
7017 end Get_Enclosing_Object;
7019 ---------------------------
7020 -- Get_Enum_Lit_From_Pos --
7021 ---------------------------
7023 function Get_Enum_Lit_From_Pos
7024 (T : Entity_Id;
7025 Pos : Uint;
7026 Loc : Source_Ptr) return Node_Id
7028 Btyp : Entity_Id := Base_Type (T);
7029 Lit : Node_Id;
7031 begin
7032 -- In the case where the literal is of type Character, Wide_Character
7033 -- or Wide_Wide_Character or of a type derived from them, there needs
7034 -- to be some special handling since there is no explicit chain of
7035 -- literals to search. Instead, an N_Character_Literal node is created
7036 -- with the appropriate Char_Code and Chars fields.
7038 if Is_Standard_Character_Type (T) then
7039 Set_Character_Literal_Name (UI_To_CC (Pos));
7040 return
7041 Make_Character_Literal (Loc,
7042 Chars => Name_Find,
7043 Char_Literal_Value => Pos);
7045 -- For all other cases, we have a complete table of literals, and
7046 -- we simply iterate through the chain of literal until the one
7047 -- with the desired position value is found.
7049 else
7050 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
7051 Btyp := Full_View (Btyp);
7052 end if;
7054 Lit := First_Literal (Btyp);
7055 for J in 1 .. UI_To_Int (Pos) loop
7056 Next_Literal (Lit);
7057 end loop;
7059 return New_Occurrence_Of (Lit, Loc);
7060 end if;
7061 end Get_Enum_Lit_From_Pos;
7063 ---------------------------------
7064 -- Get_Ensures_From_CTC_Pragma --
7065 ---------------------------------
7067 function Get_Ensures_From_CTC_Pragma (N : Node_Id) return Node_Id is
7068 Args : constant List_Id := Pragma_Argument_Associations (N);
7069 Res : Node_Id;
7071 begin
7072 if List_Length (Args) = 4 then
7073 Res := Pick (Args, 4);
7075 elsif List_Length (Args) = 3 then
7076 Res := Pick (Args, 3);
7078 if Chars (Res) /= Name_Ensures then
7079 Res := Empty;
7080 end if;
7082 else
7083 Res := Empty;
7084 end if;
7086 return Res;
7087 end Get_Ensures_From_CTC_Pragma;
7089 ------------------------
7090 -- Get_Generic_Entity --
7091 ------------------------
7093 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
7094 Ent : constant Entity_Id := Entity (Name (N));
7095 begin
7096 if Present (Renamed_Object (Ent)) then
7097 return Renamed_Object (Ent);
7098 else
7099 return Ent;
7100 end if;
7101 end Get_Generic_Entity;
7103 -------------------------------------
7104 -- Get_Incomplete_View_Of_Ancestor --
7105 -------------------------------------
7107 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
7108 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
7109 Par_Scope : Entity_Id;
7110 Par_Type : Entity_Id;
7112 begin
7113 -- The incomplete view of an ancestor is only relevant for private
7114 -- derived types in child units.
7116 if not Is_Derived_Type (E)
7117 or else not Is_Child_Unit (Cur_Unit)
7118 then
7119 return Empty;
7121 else
7122 Par_Scope := Scope (Cur_Unit);
7123 if No (Par_Scope) then
7124 return Empty;
7125 end if;
7127 Par_Type := Etype (Base_Type (E));
7129 -- Traverse list of ancestor types until we find one declared in
7130 -- a parent or grandparent unit (two levels seem sufficient).
7132 while Present (Par_Type) loop
7133 if Scope (Par_Type) = Par_Scope
7134 or else Scope (Par_Type) = Scope (Par_Scope)
7135 then
7136 return Par_Type;
7138 elsif not Is_Derived_Type (Par_Type) then
7139 return Empty;
7141 else
7142 Par_Type := Etype (Base_Type (Par_Type));
7143 end if;
7144 end loop;
7146 -- If none found, there is no relevant ancestor type.
7148 return Empty;
7149 end if;
7150 end Get_Incomplete_View_Of_Ancestor;
7152 ----------------------
7153 -- Get_Index_Bounds --
7154 ----------------------
7156 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
7157 Kind : constant Node_Kind := Nkind (N);
7158 R : Node_Id;
7160 begin
7161 if Kind = N_Range then
7162 L := Low_Bound (N);
7163 H := High_Bound (N);
7165 elsif Kind = N_Subtype_Indication then
7166 R := Range_Expression (Constraint (N));
7168 if R = Error then
7169 L := Error;
7170 H := Error;
7171 return;
7173 else
7174 L := Low_Bound (Range_Expression (Constraint (N)));
7175 H := High_Bound (Range_Expression (Constraint (N)));
7176 end if;
7178 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
7179 if Error_Posted (Scalar_Range (Entity (N))) then
7180 L := Error;
7181 H := Error;
7183 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
7184 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
7186 else
7187 L := Low_Bound (Scalar_Range (Entity (N)));
7188 H := High_Bound (Scalar_Range (Entity (N)));
7189 end if;
7191 else
7192 -- N is an expression, indicating a range with one value
7194 L := N;
7195 H := N;
7196 end if;
7197 end Get_Index_Bounds;
7199 ---------------------------------
7200 -- Get_Iterable_Type_Primitive --
7201 ---------------------------------
7203 function Get_Iterable_Type_Primitive
7204 (Typ : Entity_Id;
7205 Nam : Name_Id) return Entity_Id
7207 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
7208 Assoc : Node_Id;
7210 begin
7211 if No (Funcs) then
7212 return Empty;
7214 else
7215 Assoc := First (Component_Associations (Funcs));
7216 while Present (Assoc) loop
7217 if Chars (First (Choices (Assoc))) = Nam then
7218 return Entity (Expression (Assoc));
7219 end if;
7221 Assoc := Next (Assoc);
7222 end loop;
7224 return Empty;
7225 end if;
7226 end Get_Iterable_Type_Primitive;
7228 ----------------------------------
7229 -- Get_Library_Unit_Name_string --
7230 ----------------------------------
7232 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
7233 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
7235 begin
7236 Get_Unit_Name_String (Unit_Name_Id);
7238 -- Remove seven last character (" (spec)" or " (body)")
7240 Name_Len := Name_Len - 7;
7241 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
7242 end Get_Library_Unit_Name_String;
7244 ------------------------
7245 -- Get_Name_Entity_Id --
7246 ------------------------
7248 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
7249 begin
7250 return Entity_Id (Get_Name_Table_Info (Id));
7251 end Get_Name_Entity_Id;
7253 ------------------------------
7254 -- Get_Name_From_CTC_Pragma --
7255 ------------------------------
7257 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
7258 Arg : constant Node_Id :=
7259 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
7260 begin
7261 return Strval (Expr_Value_S (Arg));
7262 end Get_Name_From_CTC_Pragma;
7264 -----------------------
7265 -- Get_Parent_Entity --
7266 -----------------------
7268 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
7269 begin
7270 if Nkind (Unit) = N_Package_Body
7271 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
7272 then
7273 return Defining_Entity
7274 (Specification (Instance_Spec (Original_Node (Unit))));
7275 elsif Nkind (Unit) = N_Package_Instantiation then
7276 return Defining_Entity (Specification (Instance_Spec (Unit)));
7277 else
7278 return Defining_Entity (Unit);
7279 end if;
7280 end Get_Parent_Entity;
7281 -------------------
7282 -- Get_Pragma_Id --
7283 -------------------
7285 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
7286 begin
7287 return Get_Pragma_Id (Pragma_Name (N));
7288 end Get_Pragma_Id;
7290 -----------------------
7291 -- Get_Reason_String --
7292 -----------------------
7294 procedure Get_Reason_String (N : Node_Id) is
7295 begin
7296 if Nkind (N) = N_String_Literal then
7297 Store_String_Chars (Strval (N));
7299 elsif Nkind (N) = N_Op_Concat then
7300 Get_Reason_String (Left_Opnd (N));
7301 Get_Reason_String (Right_Opnd (N));
7303 -- If not of required form, error
7305 else
7306 Error_Msg_N
7307 ("Reason for pragma Warnings has wrong form", N);
7308 Error_Msg_N
7309 ("\must be string literal or concatenation of string literals", N);
7310 return;
7311 end if;
7312 end Get_Reason_String;
7314 ---------------------------
7315 -- Get_Referenced_Object --
7316 ---------------------------
7318 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7319 R : Node_Id;
7321 begin
7322 R := N;
7323 while Is_Entity_Name (R)
7324 and then Present (Renamed_Object (Entity (R)))
7325 loop
7326 R := Renamed_Object (Entity (R));
7327 end loop;
7329 return R;
7330 end Get_Referenced_Object;
7332 ------------------------
7333 -- Get_Renamed_Entity --
7334 ------------------------
7336 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7337 R : Entity_Id;
7339 begin
7340 R := E;
7341 while Present (Renamed_Entity (R)) loop
7342 R := Renamed_Entity (R);
7343 end loop;
7345 return R;
7346 end Get_Renamed_Entity;
7348 ----------------------------------
7349 -- Get_Requires_From_CTC_Pragma --
7350 ----------------------------------
7352 function Get_Requires_From_CTC_Pragma (N : Node_Id) return Node_Id is
7353 Args : constant List_Id := Pragma_Argument_Associations (N);
7354 Res : Node_Id;
7356 begin
7357 if List_Length (Args) >= 3 then
7358 Res := Pick (Args, 3);
7360 if Chars (Res) /= Name_Requires then
7361 Res := Empty;
7362 end if;
7364 else
7365 Res := Empty;
7366 end if;
7368 return Res;
7369 end Get_Requires_From_CTC_Pragma;
7371 -------------------------
7372 -- Get_Subprogram_Body --
7373 -------------------------
7375 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
7376 Decl : Node_Id;
7378 begin
7379 Decl := Unit_Declaration_Node (E);
7381 if Nkind (Decl) = N_Subprogram_Body then
7382 return Decl;
7384 -- The below comment is bad, because it is possible for
7385 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7387 else -- Nkind (Decl) = N_Subprogram_Declaration
7389 if Present (Corresponding_Body (Decl)) then
7390 return Unit_Declaration_Node (Corresponding_Body (Decl));
7392 -- Imported subprogram case
7394 else
7395 return Empty;
7396 end if;
7397 end if;
7398 end Get_Subprogram_Body;
7400 ---------------------------
7401 -- Get_Subprogram_Entity --
7402 ---------------------------
7404 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7405 Subp : Node_Id;
7406 Subp_Id : Entity_Id;
7408 begin
7409 if Nkind (Nod) = N_Accept_Statement then
7410 Subp := Entry_Direct_Name (Nod);
7412 elsif Nkind (Nod) = N_Slice then
7413 Subp := Prefix (Nod);
7415 else
7416 Subp := Name (Nod);
7417 end if;
7419 -- Strip the subprogram call
7421 loop
7422 if Nkind_In (Subp, N_Explicit_Dereference,
7423 N_Indexed_Component,
7424 N_Selected_Component)
7425 then
7426 Subp := Prefix (Subp);
7428 elsif Nkind_In (Subp, N_Type_Conversion,
7429 N_Unchecked_Type_Conversion)
7430 then
7431 Subp := Expression (Subp);
7433 else
7434 exit;
7435 end if;
7436 end loop;
7438 -- Extract the entity of the subprogram call
7440 if Is_Entity_Name (Subp) then
7441 Subp_Id := Entity (Subp);
7443 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
7444 Subp_Id := Directly_Designated_Type (Subp_Id);
7445 end if;
7447 if Is_Subprogram (Subp_Id) then
7448 return Subp_Id;
7449 else
7450 return Empty;
7451 end if;
7453 -- The search did not find a construct that denotes a subprogram
7455 else
7456 return Empty;
7457 end if;
7458 end Get_Subprogram_Entity;
7460 -----------------------------
7461 -- Get_Task_Body_Procedure --
7462 -----------------------------
7464 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
7465 begin
7466 -- Note: A task type may be the completion of a private type with
7467 -- discriminants. When performing elaboration checks on a task
7468 -- declaration, the current view of the type may be the private one,
7469 -- and the procedure that holds the body of the task is held in its
7470 -- underlying type.
7472 -- This is an odd function, why not have Task_Body_Procedure do
7473 -- the following digging???
7475 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
7476 end Get_Task_Body_Procedure;
7478 -----------------------
7479 -- Has_Access_Values --
7480 -----------------------
7482 function Has_Access_Values (T : Entity_Id) return Boolean is
7483 Typ : constant Entity_Id := Underlying_Type (T);
7485 begin
7486 -- Case of a private type which is not completed yet. This can only
7487 -- happen in the case of a generic format type appearing directly, or
7488 -- as a component of the type to which this function is being applied
7489 -- at the top level. Return False in this case, since we certainly do
7490 -- not know that the type contains access types.
7492 if No (Typ) then
7493 return False;
7495 elsif Is_Access_Type (Typ) then
7496 return True;
7498 elsif Is_Array_Type (Typ) then
7499 return Has_Access_Values (Component_Type (Typ));
7501 elsif Is_Record_Type (Typ) then
7502 declare
7503 Comp : Entity_Id;
7505 begin
7506 -- Loop to Check components
7508 Comp := First_Component_Or_Discriminant (Typ);
7509 while Present (Comp) loop
7511 -- Check for access component, tag field does not count, even
7512 -- though it is implemented internally using an access type.
7514 if Has_Access_Values (Etype (Comp))
7515 and then Chars (Comp) /= Name_uTag
7516 then
7517 return True;
7518 end if;
7520 Next_Component_Or_Discriminant (Comp);
7521 end loop;
7522 end;
7524 return False;
7526 else
7527 return False;
7528 end if;
7529 end Has_Access_Values;
7531 ------------------------------
7532 -- Has_Compatible_Alignment --
7533 ------------------------------
7535 function Has_Compatible_Alignment
7536 (Obj : Entity_Id;
7537 Expr : Node_Id) return Alignment_Result
7539 function Has_Compatible_Alignment_Internal
7540 (Obj : Entity_Id;
7541 Expr : Node_Id;
7542 Default : Alignment_Result) return Alignment_Result;
7543 -- This is the internal recursive function that actually does the work.
7544 -- There is one additional parameter, which says what the result should
7545 -- be if no alignment information is found, and there is no definite
7546 -- indication of compatible alignments. At the outer level, this is set
7547 -- to Unknown, but for internal recursive calls in the case where types
7548 -- are known to be correct, it is set to Known_Compatible.
7550 ---------------------------------------
7551 -- Has_Compatible_Alignment_Internal --
7552 ---------------------------------------
7554 function Has_Compatible_Alignment_Internal
7555 (Obj : Entity_Id;
7556 Expr : Node_Id;
7557 Default : Alignment_Result) return Alignment_Result
7559 Result : Alignment_Result := Known_Compatible;
7560 -- Holds the current status of the result. Note that once a value of
7561 -- Known_Incompatible is set, it is sticky and does not get changed
7562 -- to Unknown (the value in Result only gets worse as we go along,
7563 -- never better).
7565 Offs : Uint := No_Uint;
7566 -- Set to a factor of the offset from the base object when Expr is a
7567 -- selected or indexed component, based on Component_Bit_Offset and
7568 -- Component_Size respectively. A negative value is used to represent
7569 -- a value which is not known at compile time.
7571 procedure Check_Prefix;
7572 -- Checks the prefix recursively in the case where the expression
7573 -- is an indexed or selected component.
7575 procedure Set_Result (R : Alignment_Result);
7576 -- If R represents a worse outcome (unknown instead of known
7577 -- compatible, or known incompatible), then set Result to R.
7579 ------------------
7580 -- Check_Prefix --
7581 ------------------
7583 procedure Check_Prefix is
7584 begin
7585 -- The subtlety here is that in doing a recursive call to check
7586 -- the prefix, we have to decide what to do in the case where we
7587 -- don't find any specific indication of an alignment problem.
7589 -- At the outer level, we normally set Unknown as the result in
7590 -- this case, since we can only set Known_Compatible if we really
7591 -- know that the alignment value is OK, but for the recursive
7592 -- call, in the case where the types match, and we have not
7593 -- specified a peculiar alignment for the object, we are only
7594 -- concerned about suspicious rep clauses, the default case does
7595 -- not affect us, since the compiler will, in the absence of such
7596 -- rep clauses, ensure that the alignment is correct.
7598 if Default = Known_Compatible
7599 or else
7600 (Etype (Obj) = Etype (Expr)
7601 and then (Unknown_Alignment (Obj)
7602 or else
7603 Alignment (Obj) = Alignment (Etype (Obj))))
7604 then
7605 Set_Result
7606 (Has_Compatible_Alignment_Internal
7607 (Obj, Prefix (Expr), Known_Compatible));
7609 -- In all other cases, we need a full check on the prefix
7611 else
7612 Set_Result
7613 (Has_Compatible_Alignment_Internal
7614 (Obj, Prefix (Expr), Unknown));
7615 end if;
7616 end Check_Prefix;
7618 ----------------
7619 -- Set_Result --
7620 ----------------
7622 procedure Set_Result (R : Alignment_Result) is
7623 begin
7624 if R > Result then
7625 Result := R;
7626 end if;
7627 end Set_Result;
7629 -- Start of processing for Has_Compatible_Alignment_Internal
7631 begin
7632 -- If Expr is a selected component, we must make sure there is no
7633 -- potentially troublesome component clause, and that the record is
7634 -- not packed.
7636 if Nkind (Expr) = N_Selected_Component then
7638 -- Packed record always generate unknown alignment
7640 if Is_Packed (Etype (Prefix (Expr))) then
7641 Set_Result (Unknown);
7642 end if;
7644 -- Check prefix and component offset
7646 Check_Prefix;
7647 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
7649 -- If Expr is an indexed component, we must make sure there is no
7650 -- potentially troublesome Component_Size clause and that the array
7651 -- is not bit-packed.
7653 elsif Nkind (Expr) = N_Indexed_Component then
7654 declare
7655 Typ : constant Entity_Id := Etype (Prefix (Expr));
7656 Ind : constant Node_Id := First_Index (Typ);
7658 begin
7659 -- Bit packed array always generates unknown alignment
7661 if Is_Bit_Packed_Array (Typ) then
7662 Set_Result (Unknown);
7663 end if;
7665 -- Check prefix and component offset
7667 Check_Prefix;
7668 Offs := Component_Size (Typ);
7670 -- Small optimization: compute the full offset when possible
7672 if Offs /= No_Uint
7673 and then Offs > Uint_0
7674 and then Present (Ind)
7675 and then Nkind (Ind) = N_Range
7676 and then Compile_Time_Known_Value (Low_Bound (Ind))
7677 and then Compile_Time_Known_Value (First (Expressions (Expr)))
7678 then
7679 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
7680 - Expr_Value (Low_Bound ((Ind))));
7681 end if;
7682 end;
7683 end if;
7685 -- If we have a null offset, the result is entirely determined by
7686 -- the base object and has already been computed recursively.
7688 if Offs = Uint_0 then
7689 null;
7691 -- Case where we know the alignment of the object
7693 elsif Known_Alignment (Obj) then
7694 declare
7695 ObjA : constant Uint := Alignment (Obj);
7696 ExpA : Uint := No_Uint;
7697 SizA : Uint := No_Uint;
7699 begin
7700 -- If alignment of Obj is 1, then we are always OK
7702 if ObjA = 1 then
7703 Set_Result (Known_Compatible);
7705 -- Alignment of Obj is greater than 1, so we need to check
7707 else
7708 -- If we have an offset, see if it is compatible
7710 if Offs /= No_Uint and Offs > Uint_0 then
7711 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
7712 Set_Result (Known_Incompatible);
7713 end if;
7715 -- See if Expr is an object with known alignment
7717 elsif Is_Entity_Name (Expr)
7718 and then Known_Alignment (Entity (Expr))
7719 then
7720 ExpA := Alignment (Entity (Expr));
7722 -- Otherwise, we can use the alignment of the type of
7723 -- Expr given that we already checked for
7724 -- discombobulating rep clauses for the cases of indexed
7725 -- and selected components above.
7727 elsif Known_Alignment (Etype (Expr)) then
7728 ExpA := Alignment (Etype (Expr));
7730 -- Otherwise the alignment is unknown
7732 else
7733 Set_Result (Default);
7734 end if;
7736 -- If we got an alignment, see if it is acceptable
7738 if ExpA /= No_Uint and then ExpA < ObjA then
7739 Set_Result (Known_Incompatible);
7740 end if;
7742 -- If Expr is not a piece of a larger object, see if size
7743 -- is given. If so, check that it is not too small for the
7744 -- required alignment.
7746 if Offs /= No_Uint then
7747 null;
7749 -- See if Expr is an object with known size
7751 elsif Is_Entity_Name (Expr)
7752 and then Known_Static_Esize (Entity (Expr))
7753 then
7754 SizA := Esize (Entity (Expr));
7756 -- Otherwise, we check the object size of the Expr type
7758 elsif Known_Static_Esize (Etype (Expr)) then
7759 SizA := Esize (Etype (Expr));
7760 end if;
7762 -- If we got a size, see if it is a multiple of the Obj
7763 -- alignment, if not, then the alignment cannot be
7764 -- acceptable, since the size is always a multiple of the
7765 -- alignment.
7767 if SizA /= No_Uint then
7768 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
7769 Set_Result (Known_Incompatible);
7770 end if;
7771 end if;
7772 end if;
7773 end;
7775 -- If we do not know required alignment, any non-zero offset is a
7776 -- potential problem (but certainly may be OK, so result is unknown).
7778 elsif Offs /= No_Uint then
7779 Set_Result (Unknown);
7781 -- If we can't find the result by direct comparison of alignment
7782 -- values, then there is still one case that we can determine known
7783 -- result, and that is when we can determine that the types are the
7784 -- same, and no alignments are specified. Then we known that the
7785 -- alignments are compatible, even if we don't know the alignment
7786 -- value in the front end.
7788 elsif Etype (Obj) = Etype (Expr) then
7790 -- Types are the same, but we have to check for possible size
7791 -- and alignments on the Expr object that may make the alignment
7792 -- different, even though the types are the same.
7794 if Is_Entity_Name (Expr) then
7796 -- First check alignment of the Expr object. Any alignment less
7797 -- than Maximum_Alignment is worrisome since this is the case
7798 -- where we do not know the alignment of Obj.
7800 if Known_Alignment (Entity (Expr))
7801 and then UI_To_Int (Alignment (Entity (Expr))) <
7802 Ttypes.Maximum_Alignment
7803 then
7804 Set_Result (Unknown);
7806 -- Now check size of Expr object. Any size that is not an
7807 -- even multiple of Maximum_Alignment is also worrisome
7808 -- since it may cause the alignment of the object to be less
7809 -- than the alignment of the type.
7811 elsif Known_Static_Esize (Entity (Expr))
7812 and then
7813 (UI_To_Int (Esize (Entity (Expr))) mod
7814 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
7815 /= 0
7816 then
7817 Set_Result (Unknown);
7819 -- Otherwise same type is decisive
7821 else
7822 Set_Result (Known_Compatible);
7823 end if;
7824 end if;
7826 -- Another case to deal with is when there is an explicit size or
7827 -- alignment clause when the types are not the same. If so, then the
7828 -- result is Unknown. We don't need to do this test if the Default is
7829 -- Unknown, since that result will be set in any case.
7831 elsif Default /= Unknown
7832 and then (Has_Size_Clause (Etype (Expr))
7833 or else
7834 Has_Alignment_Clause (Etype (Expr)))
7835 then
7836 Set_Result (Unknown);
7838 -- If no indication found, set default
7840 else
7841 Set_Result (Default);
7842 end if;
7844 -- Return worst result found
7846 return Result;
7847 end Has_Compatible_Alignment_Internal;
7849 -- Start of processing for Has_Compatible_Alignment
7851 begin
7852 -- If Obj has no specified alignment, then set alignment from the type
7853 -- alignment. Perhaps we should always do this, but for sure we should
7854 -- do it when there is an address clause since we can do more if the
7855 -- alignment is known.
7857 if Unknown_Alignment (Obj) then
7858 Set_Alignment (Obj, Alignment (Etype (Obj)));
7859 end if;
7861 -- Now do the internal call that does all the work
7863 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
7864 end Has_Compatible_Alignment;
7866 ----------------------
7867 -- Has_Declarations --
7868 ----------------------
7870 function Has_Declarations (N : Node_Id) return Boolean is
7871 begin
7872 return Nkind_In (Nkind (N), N_Accept_Statement,
7873 N_Block_Statement,
7874 N_Compilation_Unit_Aux,
7875 N_Entry_Body,
7876 N_Package_Body,
7877 N_Protected_Body,
7878 N_Subprogram_Body,
7879 N_Task_Body,
7880 N_Package_Specification);
7881 end Has_Declarations;
7883 ---------------------------------
7884 -- Has_Defaulted_Discriminants --
7885 ---------------------------------
7887 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
7888 begin
7889 return Has_Discriminants (Typ)
7890 and then Present (First_Discriminant (Typ))
7891 and then Present (Discriminant_Default_Value
7892 (First_Discriminant (Typ)));
7893 end Has_Defaulted_Discriminants;
7895 -------------------
7896 -- Has_Denormals --
7897 -------------------
7899 function Has_Denormals (E : Entity_Id) return Boolean is
7900 begin
7901 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
7902 end Has_Denormals;
7904 -------------------------------------------
7905 -- Has_Discriminant_Dependent_Constraint --
7906 -------------------------------------------
7908 function Has_Discriminant_Dependent_Constraint
7909 (Comp : Entity_Id) return Boolean
7911 Comp_Decl : constant Node_Id := Parent (Comp);
7912 Subt_Indic : Node_Id;
7913 Constr : Node_Id;
7914 Assn : Node_Id;
7916 begin
7917 -- Discriminants can't depend on discriminants
7919 if Ekind (Comp) = E_Discriminant then
7920 return False;
7922 else
7923 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
7925 if Nkind (Subt_Indic) = N_Subtype_Indication then
7926 Constr := Constraint (Subt_Indic);
7928 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
7929 Assn := First (Constraints (Constr));
7930 while Present (Assn) loop
7931 case Nkind (Assn) is
7932 when N_Subtype_Indication |
7933 N_Range |
7934 N_Identifier
7936 if Depends_On_Discriminant (Assn) then
7937 return True;
7938 end if;
7940 when N_Discriminant_Association =>
7941 if Depends_On_Discriminant (Expression (Assn)) then
7942 return True;
7943 end if;
7945 when others =>
7946 null;
7947 end case;
7949 Next (Assn);
7950 end loop;
7951 end if;
7952 end if;
7953 end if;
7955 return False;
7956 end Has_Discriminant_Dependent_Constraint;
7958 --------------------------
7959 -- Has_Enabled_Property --
7960 --------------------------
7962 function Has_Enabled_Property
7963 (Item_Id : Entity_Id;
7964 Property : Name_Id) return Boolean
7966 function State_Has_Enabled_Property return Boolean;
7967 -- Determine whether a state denoted by Item_Id has the property enabled
7969 function Variable_Has_Enabled_Property return Boolean;
7970 -- Determine whether a variable denoted by Item_Id has the property
7971 -- enabled.
7973 --------------------------------
7974 -- State_Has_Enabled_Property --
7975 --------------------------------
7977 function State_Has_Enabled_Property return Boolean is
7978 Decl : constant Node_Id := Parent (Item_Id);
7979 Opt : Node_Id;
7980 Opt_Nam : Node_Id;
7981 Prop : Node_Id;
7982 Prop_Nam : Node_Id;
7983 Props : Node_Id;
7985 begin
7986 -- The declaration of an external abstract state appears as an
7987 -- extension aggregate. If this is not the case, properties can never
7988 -- be set.
7990 if Nkind (Decl) /= N_Extension_Aggregate then
7991 return False;
7992 end if;
7994 -- When External appears as a simple option, it automatically enables
7995 -- all properties.
7997 Opt := First (Expressions (Decl));
7998 while Present (Opt) loop
7999 if Nkind (Opt) = N_Identifier
8000 and then Chars (Opt) = Name_External
8001 then
8002 return True;
8003 end if;
8005 Next (Opt);
8006 end loop;
8008 -- When External specifies particular properties, inspect those and
8009 -- find the desired one (if any).
8011 Opt := First (Component_Associations (Decl));
8012 while Present (Opt) loop
8013 Opt_Nam := First (Choices (Opt));
8015 if Nkind (Opt_Nam) = N_Identifier
8016 and then Chars (Opt_Nam) = Name_External
8017 then
8018 Props := Expression (Opt);
8020 -- Multiple properties appear as an aggregate
8022 if Nkind (Props) = N_Aggregate then
8024 -- Simple property form
8026 Prop := First (Expressions (Props));
8027 while Present (Prop) loop
8028 if Chars (Prop) = Property then
8029 return True;
8030 end if;
8032 Next (Prop);
8033 end loop;
8035 -- Property with expression form
8037 Prop := First (Component_Associations (Props));
8038 while Present (Prop) loop
8039 Prop_Nam := First (Choices (Prop));
8041 -- The property can be represented in two ways:
8042 -- others => <value>
8043 -- <property> => <value>
8045 if Nkind (Prop_Nam) = N_Others_Choice
8046 or else (Nkind (Prop_Nam) = N_Identifier
8047 and then Chars (Prop_Nam) = Property)
8048 then
8049 return Is_True (Expr_Value (Expression (Prop)));
8050 end if;
8052 Next (Prop);
8053 end loop;
8055 -- Single property
8057 else
8058 return Chars (Props) = Property;
8059 end if;
8060 end if;
8062 Next (Opt);
8063 end loop;
8065 return False;
8066 end State_Has_Enabled_Property;
8068 -----------------------------------
8069 -- Variable_Has_Enabled_Property --
8070 -----------------------------------
8072 function Variable_Has_Enabled_Property return Boolean is
8073 function Is_Enabled (Prag : Node_Id) return Boolean;
8074 -- Determine whether property pragma Prag (if present) denotes an
8075 -- enabled property.
8077 ----------------
8078 -- Is_Enabled --
8079 ----------------
8081 function Is_Enabled (Prag : Node_Id) return Boolean is
8082 Arg2 : Node_Id;
8084 begin
8085 if Present (Prag) then
8086 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
8088 -- The pragma has an optional Boolean expression, the related
8089 -- property is enabled only when the expression evaluates to
8090 -- True.
8092 if Present (Arg2) then
8093 return Is_True (Expr_Value (Get_Pragma_Arg (Arg2)));
8095 -- Otherwise the lack of expression enables the property by
8096 -- default.
8098 else
8099 return True;
8100 end if;
8102 -- The property was never set in the first place
8104 else
8105 return False;
8106 end if;
8107 end Is_Enabled;
8109 -- Local variables
8111 AR : constant Node_Id :=
8112 Get_Pragma (Item_Id, Pragma_Async_Readers);
8113 AW : constant Node_Id :=
8114 Get_Pragma (Item_Id, Pragma_Async_Writers);
8115 ER : constant Node_Id :=
8116 Get_Pragma (Item_Id, Pragma_Effective_Reads);
8117 EW : constant Node_Id :=
8118 Get_Pragma (Item_Id, Pragma_Effective_Writes);
8120 -- Start of processing for Variable_Has_Enabled_Property
8122 begin
8123 -- A non-effectively volatile object can never possess external
8124 -- properties.
8126 if not Is_Effectively_Volatile (Item_Id) then
8127 return False;
8129 -- External properties related to variables come in two flavors -
8130 -- explicit and implicit. The explicit case is characterized by the
8131 -- presence of a property pragma with an optional Boolean flag. The
8132 -- property is enabled when the flag evaluates to True or the flag is
8133 -- missing altogether.
8135 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
8136 return True;
8138 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
8139 return True;
8141 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
8142 return True;
8144 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
8145 return True;
8147 -- The implicit case lacks all property pragmas
8149 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
8150 return True;
8152 else
8153 return False;
8154 end if;
8155 end Variable_Has_Enabled_Property;
8157 -- Start of processing for Has_Enabled_Property
8159 begin
8160 -- Abstract states and variables have a flexible scheme of specifying
8161 -- external properties.
8163 if Ekind (Item_Id) = E_Abstract_State then
8164 return State_Has_Enabled_Property;
8166 elsif Ekind (Item_Id) = E_Variable then
8167 return Variable_Has_Enabled_Property;
8169 -- Otherwise a property is enabled when the related item is effectively
8170 -- volatile.
8172 else
8173 return Is_Effectively_Volatile (Item_Id);
8174 end if;
8175 end Has_Enabled_Property;
8177 --------------------
8178 -- Has_Infinities --
8179 --------------------
8181 function Has_Infinities (E : Entity_Id) return Boolean is
8182 begin
8183 return
8184 Is_Floating_Point_Type (E)
8185 and then Nkind (Scalar_Range (E)) = N_Range
8186 and then Includes_Infinities (Scalar_Range (E));
8187 end Has_Infinities;
8189 --------------------
8190 -- Has_Interfaces --
8191 --------------------
8193 function Has_Interfaces
8194 (T : Entity_Id;
8195 Use_Full_View : Boolean := True) return Boolean
8197 Typ : Entity_Id := Base_Type (T);
8199 begin
8200 -- Handle concurrent types
8202 if Is_Concurrent_Type (Typ) then
8203 Typ := Corresponding_Record_Type (Typ);
8204 end if;
8206 if not Present (Typ)
8207 or else not Is_Record_Type (Typ)
8208 or else not Is_Tagged_Type (Typ)
8209 then
8210 return False;
8211 end if;
8213 -- Handle private types
8215 if Use_Full_View and then Present (Full_View (Typ)) then
8216 Typ := Full_View (Typ);
8217 end if;
8219 -- Handle concurrent record types
8221 if Is_Concurrent_Record_Type (Typ)
8222 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
8223 then
8224 return True;
8225 end if;
8227 loop
8228 if Is_Interface (Typ)
8229 or else
8230 (Is_Record_Type (Typ)
8231 and then Present (Interfaces (Typ))
8232 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
8233 then
8234 return True;
8235 end if;
8237 exit when Etype (Typ) = Typ
8239 -- Handle private types
8241 or else (Present (Full_View (Etype (Typ)))
8242 and then Full_View (Etype (Typ)) = Typ)
8244 -- Protect frontend against wrong sources with cyclic derivations
8246 or else Etype (Typ) = T;
8248 -- Climb to the ancestor type handling private types
8250 if Present (Full_View (Etype (Typ))) then
8251 Typ := Full_View (Etype (Typ));
8252 else
8253 Typ := Etype (Typ);
8254 end if;
8255 end loop;
8257 return False;
8258 end Has_Interfaces;
8260 ---------------------------------
8261 -- Has_No_Obvious_Side_Effects --
8262 ---------------------------------
8264 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
8265 begin
8266 -- For now, just handle literals, constants, and non-volatile
8267 -- variables and expressions combining these with operators or
8268 -- short circuit forms.
8270 if Nkind (N) in N_Numeric_Or_String_Literal then
8271 return True;
8273 elsif Nkind (N) = N_Character_Literal then
8274 return True;
8276 elsif Nkind (N) in N_Unary_Op then
8277 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
8279 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
8280 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
8281 and then
8282 Has_No_Obvious_Side_Effects (Right_Opnd (N));
8284 elsif Nkind (N) = N_Expression_With_Actions
8285 and then Is_Empty_List (Actions (N))
8286 then
8287 return Has_No_Obvious_Side_Effects (Expression (N));
8289 elsif Nkind (N) in N_Has_Entity then
8290 return Present (Entity (N))
8291 and then Ekind_In (Entity (N), E_Variable,
8292 E_Constant,
8293 E_Enumeration_Literal,
8294 E_In_Parameter,
8295 E_Out_Parameter,
8296 E_In_Out_Parameter)
8297 and then not Is_Volatile (Entity (N));
8299 else
8300 return False;
8301 end if;
8302 end Has_No_Obvious_Side_Effects;
8304 ------------------------
8305 -- Has_Null_Exclusion --
8306 ------------------------
8308 function Has_Null_Exclusion (N : Node_Id) return Boolean is
8309 begin
8310 case Nkind (N) is
8311 when N_Access_Definition |
8312 N_Access_Function_Definition |
8313 N_Access_Procedure_Definition |
8314 N_Access_To_Object_Definition |
8315 N_Allocator |
8316 N_Derived_Type_Definition |
8317 N_Function_Specification |
8318 N_Subtype_Declaration =>
8319 return Null_Exclusion_Present (N);
8321 when N_Component_Definition |
8322 N_Formal_Object_Declaration |
8323 N_Object_Renaming_Declaration =>
8324 if Present (Subtype_Mark (N)) then
8325 return Null_Exclusion_Present (N);
8326 else pragma Assert (Present (Access_Definition (N)));
8327 return Null_Exclusion_Present (Access_Definition (N));
8328 end if;
8330 when N_Discriminant_Specification =>
8331 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
8332 return Null_Exclusion_Present (Discriminant_Type (N));
8333 else
8334 return Null_Exclusion_Present (N);
8335 end if;
8337 when N_Object_Declaration =>
8338 if Nkind (Object_Definition (N)) = N_Access_Definition then
8339 return Null_Exclusion_Present (Object_Definition (N));
8340 else
8341 return Null_Exclusion_Present (N);
8342 end if;
8344 when N_Parameter_Specification =>
8345 if Nkind (Parameter_Type (N)) = N_Access_Definition then
8346 return Null_Exclusion_Present (Parameter_Type (N));
8347 else
8348 return Null_Exclusion_Present (N);
8349 end if;
8351 when others =>
8352 return False;
8354 end case;
8355 end Has_Null_Exclusion;
8357 ------------------------
8358 -- Has_Null_Extension --
8359 ------------------------
8361 function Has_Null_Extension (T : Entity_Id) return Boolean is
8362 B : constant Entity_Id := Base_Type (T);
8363 Comps : Node_Id;
8364 Ext : Node_Id;
8366 begin
8367 if Nkind (Parent (B)) = N_Full_Type_Declaration
8368 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
8369 then
8370 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
8372 if Present (Ext) then
8373 if Null_Present (Ext) then
8374 return True;
8375 else
8376 Comps := Component_List (Ext);
8378 -- The null component list is rewritten during analysis to
8379 -- include the parent component. Any other component indicates
8380 -- that the extension was not originally null.
8382 return Null_Present (Comps)
8383 or else No (Next (First (Component_Items (Comps))));
8384 end if;
8385 else
8386 return False;
8387 end if;
8389 else
8390 return False;
8391 end if;
8392 end Has_Null_Extension;
8394 -------------------------------
8395 -- Has_Overriding_Initialize --
8396 -------------------------------
8398 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
8399 BT : constant Entity_Id := Base_Type (T);
8400 P : Elmt_Id;
8402 begin
8403 if Is_Controlled (BT) then
8404 if Is_RTU (Scope (BT), Ada_Finalization) then
8405 return False;
8407 elsif Present (Primitive_Operations (BT)) then
8408 P := First_Elmt (Primitive_Operations (BT));
8409 while Present (P) loop
8410 declare
8411 Init : constant Entity_Id := Node (P);
8412 Formal : constant Entity_Id := First_Formal (Init);
8413 begin
8414 if Ekind (Init) = E_Procedure
8415 and then Chars (Init) = Name_Initialize
8416 and then Comes_From_Source (Init)
8417 and then Present (Formal)
8418 and then Etype (Formal) = BT
8419 and then No (Next_Formal (Formal))
8420 and then (Ada_Version < Ada_2012
8421 or else not Null_Present (Parent (Init)))
8422 then
8423 return True;
8424 end if;
8425 end;
8427 Next_Elmt (P);
8428 end loop;
8429 end if;
8431 -- Here if type itself does not have a non-null Initialize operation:
8432 -- check immediate ancestor.
8434 if Is_Derived_Type (BT)
8435 and then Has_Overriding_Initialize (Etype (BT))
8436 then
8437 return True;
8438 end if;
8439 end if;
8441 return False;
8442 end Has_Overriding_Initialize;
8444 --------------------------------------
8445 -- Has_Preelaborable_Initialization --
8446 --------------------------------------
8448 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
8449 Has_PE : Boolean;
8451 procedure Check_Components (E : Entity_Id);
8452 -- Check component/discriminant chain, sets Has_PE False if a component
8453 -- or discriminant does not meet the preelaborable initialization rules.
8455 ----------------------
8456 -- Check_Components --
8457 ----------------------
8459 procedure Check_Components (E : Entity_Id) is
8460 Ent : Entity_Id;
8461 Exp : Node_Id;
8463 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
8464 -- Returns True if and only if the expression denoted by N does not
8465 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8467 ---------------------------------
8468 -- Is_Preelaborable_Expression --
8469 ---------------------------------
8471 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
8472 Exp : Node_Id;
8473 Assn : Node_Id;
8474 Choice : Node_Id;
8475 Comp_Type : Entity_Id;
8476 Is_Array_Aggr : Boolean;
8478 begin
8479 if Is_OK_Static_Expression (N) then
8480 return True;
8482 elsif Nkind (N) = N_Null then
8483 return True;
8485 -- Attributes are allowed in general, even if their prefix is a
8486 -- formal type. (It seems that certain attributes known not to be
8487 -- static might not be allowed, but there are no rules to prevent
8488 -- them.)
8490 elsif Nkind (N) = N_Attribute_Reference then
8491 return True;
8493 -- The name of a discriminant evaluated within its parent type is
8494 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8495 -- names that denote discriminals as well as discriminants to
8496 -- catch references occurring within init procs.
8498 elsif Is_Entity_Name (N)
8499 and then
8500 (Ekind (Entity (N)) = E_Discriminant
8501 or else (Ekind_In (Entity (N), E_Constant, E_In_Parameter)
8502 and then Present (Discriminal_Link (Entity (N)))))
8503 then
8504 return True;
8506 elsif Nkind (N) = N_Qualified_Expression then
8507 return Is_Preelaborable_Expression (Expression (N));
8509 -- For aggregates we have to check that each of the associations
8510 -- is preelaborable.
8512 elsif Nkind_In (N, N_Aggregate, N_Extension_Aggregate) then
8513 Is_Array_Aggr := Is_Array_Type (Etype (N));
8515 if Is_Array_Aggr then
8516 Comp_Type := Component_Type (Etype (N));
8517 end if;
8519 -- Check the ancestor part of extension aggregates, which must
8520 -- be either the name of a type that has preelaborable init or
8521 -- an expression that is preelaborable.
8523 if Nkind (N) = N_Extension_Aggregate then
8524 declare
8525 Anc_Part : constant Node_Id := Ancestor_Part (N);
8527 begin
8528 if Is_Entity_Name (Anc_Part)
8529 and then Is_Type (Entity (Anc_Part))
8530 then
8531 if not Has_Preelaborable_Initialization
8532 (Entity (Anc_Part))
8533 then
8534 return False;
8535 end if;
8537 elsif not Is_Preelaborable_Expression (Anc_Part) then
8538 return False;
8539 end if;
8540 end;
8541 end if;
8543 -- Check positional associations
8545 Exp := First (Expressions (N));
8546 while Present (Exp) loop
8547 if not Is_Preelaborable_Expression (Exp) then
8548 return False;
8549 end if;
8551 Next (Exp);
8552 end loop;
8554 -- Check named associations
8556 Assn := First (Component_Associations (N));
8557 while Present (Assn) loop
8558 Choice := First (Choices (Assn));
8559 while Present (Choice) loop
8560 if Is_Array_Aggr then
8561 if Nkind (Choice) = N_Others_Choice then
8562 null;
8564 elsif Nkind (Choice) = N_Range then
8565 if not Is_OK_Static_Range (Choice) then
8566 return False;
8567 end if;
8569 elsif not Is_OK_Static_Expression (Choice) then
8570 return False;
8571 end if;
8573 else
8574 Comp_Type := Etype (Choice);
8575 end if;
8577 Next (Choice);
8578 end loop;
8580 -- If the association has a <> at this point, then we have
8581 -- to check whether the component's type has preelaborable
8582 -- initialization. Note that this only occurs when the
8583 -- association's corresponding component does not have a
8584 -- default expression, the latter case having already been
8585 -- expanded as an expression for the association.
8587 if Box_Present (Assn) then
8588 if not Has_Preelaborable_Initialization (Comp_Type) then
8589 return False;
8590 end if;
8592 -- In the expression case we check whether the expression
8593 -- is preelaborable.
8595 elsif
8596 not Is_Preelaborable_Expression (Expression (Assn))
8597 then
8598 return False;
8599 end if;
8601 Next (Assn);
8602 end loop;
8604 -- If we get here then aggregate as a whole is preelaborable
8606 return True;
8608 -- All other cases are not preelaborable
8610 else
8611 return False;
8612 end if;
8613 end Is_Preelaborable_Expression;
8615 -- Start of processing for Check_Components
8617 begin
8618 -- Loop through entities of record or protected type
8620 Ent := E;
8621 while Present (Ent) loop
8623 -- We are interested only in components and discriminants
8625 Exp := Empty;
8627 case Ekind (Ent) is
8628 when E_Component =>
8630 -- Get default expression if any. If there is no declaration
8631 -- node, it means we have an internal entity. The parent and
8632 -- tag fields are examples of such entities. For such cases,
8633 -- we just test the type of the entity.
8635 if Present (Declaration_Node (Ent)) then
8636 Exp := Expression (Declaration_Node (Ent));
8637 end if;
8639 when E_Discriminant =>
8641 -- Note: for a renamed discriminant, the Declaration_Node
8642 -- may point to the one from the ancestor, and have a
8643 -- different expression, so use the proper attribute to
8644 -- retrieve the expression from the derived constraint.
8646 Exp := Discriminant_Default_Value (Ent);
8648 when others =>
8649 goto Check_Next_Entity;
8650 end case;
8652 -- A component has PI if it has no default expression and the
8653 -- component type has PI.
8655 if No (Exp) then
8656 if not Has_Preelaborable_Initialization (Etype (Ent)) then
8657 Has_PE := False;
8658 exit;
8659 end if;
8661 -- Require the default expression to be preelaborable
8663 elsif not Is_Preelaborable_Expression (Exp) then
8664 Has_PE := False;
8665 exit;
8666 end if;
8668 <<Check_Next_Entity>>
8669 Next_Entity (Ent);
8670 end loop;
8671 end Check_Components;
8673 -- Start of processing for Has_Preelaborable_Initialization
8675 begin
8676 -- Immediate return if already marked as known preelaborable init. This
8677 -- covers types for which this function has already been called once
8678 -- and returned True (in which case the result is cached), and also
8679 -- types to which a pragma Preelaborable_Initialization applies.
8681 if Known_To_Have_Preelab_Init (E) then
8682 return True;
8683 end if;
8685 -- If the type is a subtype representing a generic actual type, then
8686 -- test whether its base type has preelaborable initialization since
8687 -- the subtype representing the actual does not inherit this attribute
8688 -- from the actual or formal. (but maybe it should???)
8690 if Is_Generic_Actual_Type (E) then
8691 return Has_Preelaborable_Initialization (Base_Type (E));
8692 end if;
8694 -- All elementary types have preelaborable initialization
8696 if Is_Elementary_Type (E) then
8697 Has_PE := True;
8699 -- Array types have PI if the component type has PI
8701 elsif Is_Array_Type (E) then
8702 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
8704 -- A derived type has preelaborable initialization if its parent type
8705 -- has preelaborable initialization and (in the case of a derived record
8706 -- extension) if the non-inherited components all have preelaborable
8707 -- initialization. However, a user-defined controlled type with an
8708 -- overriding Initialize procedure does not have preelaborable
8709 -- initialization.
8711 elsif Is_Derived_Type (E) then
8713 -- If the derived type is a private extension then it doesn't have
8714 -- preelaborable initialization.
8716 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
8717 return False;
8718 end if;
8720 -- First check whether ancestor type has preelaborable initialization
8722 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
8724 -- If OK, check extension components (if any)
8726 if Has_PE and then Is_Record_Type (E) then
8727 Check_Components (First_Entity (E));
8728 end if;
8730 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8731 -- with a user defined Initialize procedure does not have PI. If
8732 -- the type is untagged, the control primitives come from a component
8733 -- that has already been checked.
8735 if Has_PE
8736 and then Is_Controlled (E)
8737 and then Is_Tagged_Type (E)
8738 and then Has_Overriding_Initialize (E)
8739 then
8740 Has_PE := False;
8741 end if;
8743 -- Private types not derived from a type having preelaborable init and
8744 -- that are not marked with pragma Preelaborable_Initialization do not
8745 -- have preelaborable initialization.
8747 elsif Is_Private_Type (E) then
8748 return False;
8750 -- Record type has PI if it is non private and all components have PI
8752 elsif Is_Record_Type (E) then
8753 Has_PE := True;
8754 Check_Components (First_Entity (E));
8756 -- Protected types must not have entries, and components must meet
8757 -- same set of rules as for record components.
8759 elsif Is_Protected_Type (E) then
8760 if Has_Entries (E) then
8761 Has_PE := False;
8762 else
8763 Has_PE := True;
8764 Check_Components (First_Entity (E));
8765 Check_Components (First_Private_Entity (E));
8766 end if;
8768 -- Type System.Address always has preelaborable initialization
8770 elsif Is_RTE (E, RE_Address) then
8771 Has_PE := True;
8773 -- In all other cases, type does not have preelaborable initialization
8775 else
8776 return False;
8777 end if;
8779 -- If type has preelaborable initialization, cache result
8781 if Has_PE then
8782 Set_Known_To_Have_Preelab_Init (E);
8783 end if;
8785 return Has_PE;
8786 end Has_Preelaborable_Initialization;
8788 ---------------------------
8789 -- Has_Private_Component --
8790 ---------------------------
8792 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
8793 Btype : Entity_Id := Base_Type (Type_Id);
8794 Component : Entity_Id;
8796 begin
8797 if Error_Posted (Type_Id)
8798 or else Error_Posted (Btype)
8799 then
8800 return False;
8801 end if;
8803 if Is_Class_Wide_Type (Btype) then
8804 Btype := Root_Type (Btype);
8805 end if;
8807 if Is_Private_Type (Btype) then
8808 declare
8809 UT : constant Entity_Id := Underlying_Type (Btype);
8810 begin
8811 if No (UT) then
8812 if No (Full_View (Btype)) then
8813 return not Is_Generic_Type (Btype)
8814 and then
8815 not Is_Generic_Type (Root_Type (Btype));
8816 else
8817 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
8818 end if;
8819 else
8820 return not Is_Frozen (UT) and then Has_Private_Component (UT);
8821 end if;
8822 end;
8824 elsif Is_Array_Type (Btype) then
8825 return Has_Private_Component (Component_Type (Btype));
8827 elsif Is_Record_Type (Btype) then
8828 Component := First_Component (Btype);
8829 while Present (Component) loop
8830 if Has_Private_Component (Etype (Component)) then
8831 return True;
8832 end if;
8834 Next_Component (Component);
8835 end loop;
8837 return False;
8839 elsif Is_Protected_Type (Btype)
8840 and then Present (Corresponding_Record_Type (Btype))
8841 then
8842 return Has_Private_Component (Corresponding_Record_Type (Btype));
8844 else
8845 return False;
8846 end if;
8847 end Has_Private_Component;
8849 ----------------------
8850 -- Has_Signed_Zeros --
8851 ----------------------
8853 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
8854 begin
8855 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
8856 end Has_Signed_Zeros;
8858 -----------------------------
8859 -- Has_Static_Array_Bounds --
8860 -----------------------------
8862 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
8863 Ndims : constant Nat := Number_Dimensions (Typ);
8865 Index : Node_Id;
8866 Low : Node_Id;
8867 High : Node_Id;
8869 begin
8870 -- Unconstrained types do not have static bounds
8872 if not Is_Constrained (Typ) then
8873 return False;
8874 end if;
8876 -- First treat string literals specially, as the lower bound and length
8877 -- of string literals are not stored like those of arrays.
8879 -- A string literal always has static bounds
8881 if Ekind (Typ) = E_String_Literal_Subtype then
8882 return True;
8883 end if;
8885 -- Treat all dimensions in turn
8887 Index := First_Index (Typ);
8888 for Indx in 1 .. Ndims loop
8890 -- In case of an illegal index which is not a discrete type, return
8891 -- that the type is not static.
8893 if not Is_Discrete_Type (Etype (Index))
8894 or else Etype (Index) = Any_Type
8895 then
8896 return False;
8897 end if;
8899 Get_Index_Bounds (Index, Low, High);
8901 if Error_Posted (Low) or else Error_Posted (High) then
8902 return False;
8903 end if;
8905 if Is_OK_Static_Expression (Low)
8906 and then
8907 Is_OK_Static_Expression (High)
8908 then
8909 null;
8910 else
8911 return False;
8912 end if;
8914 Next (Index);
8915 end loop;
8917 -- If we fall through the loop, all indexes matched
8919 return True;
8920 end Has_Static_Array_Bounds;
8922 ----------------
8923 -- Has_Stream --
8924 ----------------
8926 function Has_Stream (T : Entity_Id) return Boolean is
8927 E : Entity_Id;
8929 begin
8930 if No (T) then
8931 return False;
8933 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
8934 return True;
8936 elsif Is_Array_Type (T) then
8937 return Has_Stream (Component_Type (T));
8939 elsif Is_Record_Type (T) then
8940 E := First_Component (T);
8941 while Present (E) loop
8942 if Has_Stream (Etype (E)) then
8943 return True;
8944 else
8945 Next_Component (E);
8946 end if;
8947 end loop;
8949 return False;
8951 elsif Is_Private_Type (T) then
8952 return Has_Stream (Underlying_Type (T));
8954 else
8955 return False;
8956 end if;
8957 end Has_Stream;
8959 ----------------
8960 -- Has_Suffix --
8961 ----------------
8963 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
8964 begin
8965 Get_Name_String (Chars (E));
8966 return Name_Buffer (Name_Len) = Suffix;
8967 end Has_Suffix;
8969 ----------------
8970 -- Add_Suffix --
8971 ----------------
8973 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8974 begin
8975 Get_Name_String (Chars (E));
8976 Add_Char_To_Name_Buffer (Suffix);
8977 return Name_Find;
8978 end Add_Suffix;
8980 -------------------
8981 -- Remove_Suffix --
8982 -------------------
8984 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8985 begin
8986 pragma Assert (Has_Suffix (E, Suffix));
8987 Get_Name_String (Chars (E));
8988 Name_Len := Name_Len - 1;
8989 return Name_Find;
8990 end Remove_Suffix;
8992 --------------------------
8993 -- Has_Tagged_Component --
8994 --------------------------
8996 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
8997 Comp : Entity_Id;
8999 begin
9000 if Is_Private_Type (Typ) and then Present (Underlying_Type (Typ)) then
9001 return Has_Tagged_Component (Underlying_Type (Typ));
9003 elsif Is_Array_Type (Typ) then
9004 return Has_Tagged_Component (Component_Type (Typ));
9006 elsif Is_Tagged_Type (Typ) then
9007 return True;
9009 elsif Is_Record_Type (Typ) then
9010 Comp := First_Component (Typ);
9011 while Present (Comp) loop
9012 if Has_Tagged_Component (Etype (Comp)) then
9013 return True;
9014 end if;
9016 Next_Component (Comp);
9017 end loop;
9019 return False;
9021 else
9022 return False;
9023 end if;
9024 end Has_Tagged_Component;
9026 ----------------------------
9027 -- Has_Volatile_Component --
9028 ----------------------------
9030 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
9031 Comp : Entity_Id;
9033 begin
9034 if Has_Volatile_Components (Typ) then
9035 return True;
9037 elsif Is_Array_Type (Typ) then
9038 return Is_Volatile (Component_Type (Typ));
9040 elsif Is_Record_Type (Typ) then
9041 Comp := First_Component (Typ);
9042 while Present (Comp) loop
9043 if Is_Volatile_Object (Comp) then
9044 return True;
9045 end if;
9047 Comp := Next_Component (Comp);
9048 end loop;
9049 end if;
9051 return False;
9052 end Has_Volatile_Component;
9054 -------------------------
9055 -- Implementation_Kind --
9056 -------------------------
9058 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
9059 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
9060 Arg : Node_Id;
9061 begin
9062 pragma Assert (Present (Impl_Prag));
9063 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
9064 return Chars (Get_Pragma_Arg (Arg));
9065 end Implementation_Kind;
9067 --------------------------
9068 -- Implements_Interface --
9069 --------------------------
9071 function Implements_Interface
9072 (Typ_Ent : Entity_Id;
9073 Iface_Ent : Entity_Id;
9074 Exclude_Parents : Boolean := False) return Boolean
9076 Ifaces_List : Elist_Id;
9077 Elmt : Elmt_Id;
9078 Iface : Entity_Id := Base_Type (Iface_Ent);
9079 Typ : Entity_Id := Base_Type (Typ_Ent);
9081 begin
9082 if Is_Class_Wide_Type (Typ) then
9083 Typ := Root_Type (Typ);
9084 end if;
9086 if not Has_Interfaces (Typ) then
9087 return False;
9088 end if;
9090 if Is_Class_Wide_Type (Iface) then
9091 Iface := Root_Type (Iface);
9092 end if;
9094 Collect_Interfaces (Typ, Ifaces_List);
9096 Elmt := First_Elmt (Ifaces_List);
9097 while Present (Elmt) loop
9098 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
9099 and then Exclude_Parents
9100 then
9101 null;
9103 elsif Node (Elmt) = Iface then
9104 return True;
9105 end if;
9107 Next_Elmt (Elmt);
9108 end loop;
9110 return False;
9111 end Implements_Interface;
9113 ------------------------------------
9114 -- In_Assertion_Expression_Pragma --
9115 ------------------------------------
9117 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
9118 Par : Node_Id;
9119 Prag : Node_Id := Empty;
9121 begin
9122 -- Climb the parent chain looking for an enclosing pragma
9124 Par := N;
9125 while Present (Par) loop
9126 if Nkind (Par) = N_Pragma then
9127 Prag := Par;
9128 exit;
9130 -- Precondition-like pragmas are expanded into if statements, check
9131 -- the original node instead.
9133 elsif Nkind (Original_Node (Par)) = N_Pragma then
9134 Prag := Original_Node (Par);
9135 exit;
9137 -- The expansion of attribute 'Old generates a constant to capture
9138 -- the result of the prefix. If the parent traversal reaches
9139 -- one of these constants, then the node technically came from a
9140 -- postcondition-like pragma. Note that the Ekind is not tested here
9141 -- because N may be the expression of an object declaration which is
9142 -- currently being analyzed. Such objects carry Ekind of E_Void.
9144 elsif Nkind (Par) = N_Object_Declaration
9145 and then Constant_Present (Par)
9146 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
9147 then
9148 return True;
9150 -- Prevent the search from going too far
9152 elsif Is_Body_Or_Package_Declaration (Par) then
9153 return False;
9154 end if;
9156 Par := Parent (Par);
9157 end loop;
9159 return
9160 Present (Prag)
9161 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
9162 end In_Assertion_Expression_Pragma;
9164 -----------------
9165 -- In_Instance --
9166 -----------------
9168 function In_Instance return Boolean is
9169 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
9170 S : Entity_Id;
9172 begin
9173 S := Current_Scope;
9174 while Present (S) and then S /= Standard_Standard loop
9175 if Ekind_In (S, E_Function, E_Package, E_Procedure)
9176 and then Is_Generic_Instance (S)
9177 then
9178 -- A child instance is always compiled in the context of a parent
9179 -- instance. Nevertheless, the actuals are not analyzed in an
9180 -- instance context. We detect this case by examining the current
9181 -- compilation unit, which must be a child instance, and checking
9182 -- that it is not currently on the scope stack.
9184 if Is_Child_Unit (Curr_Unit)
9185 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
9186 N_Package_Instantiation
9187 and then not In_Open_Scopes (Curr_Unit)
9188 then
9189 return False;
9190 else
9191 return True;
9192 end if;
9193 end if;
9195 S := Scope (S);
9196 end loop;
9198 return False;
9199 end In_Instance;
9201 ----------------------
9202 -- In_Instance_Body --
9203 ----------------------
9205 function In_Instance_Body return Boolean is
9206 S : Entity_Id;
9208 begin
9209 S := Current_Scope;
9210 while Present (S) and then S /= Standard_Standard loop
9211 if Ekind_In (S, E_Function, E_Procedure)
9212 and then Is_Generic_Instance (S)
9213 then
9214 return True;
9216 elsif Ekind (S) = E_Package
9217 and then In_Package_Body (S)
9218 and then Is_Generic_Instance (S)
9219 then
9220 return True;
9221 end if;
9223 S := Scope (S);
9224 end loop;
9226 return False;
9227 end In_Instance_Body;
9229 -----------------------------
9230 -- In_Instance_Not_Visible --
9231 -----------------------------
9233 function In_Instance_Not_Visible return Boolean is
9234 S : Entity_Id;
9236 begin
9237 S := Current_Scope;
9238 while Present (S) and then S /= Standard_Standard loop
9239 if Ekind_In (S, E_Function, E_Procedure)
9240 and then Is_Generic_Instance (S)
9241 then
9242 return True;
9244 elsif Ekind (S) = E_Package
9245 and then (In_Package_Body (S) or else In_Private_Part (S))
9246 and then Is_Generic_Instance (S)
9247 then
9248 return True;
9249 end if;
9251 S := Scope (S);
9252 end loop;
9254 return False;
9255 end In_Instance_Not_Visible;
9257 ------------------------------
9258 -- In_Instance_Visible_Part --
9259 ------------------------------
9261 function In_Instance_Visible_Part return Boolean is
9262 S : Entity_Id;
9264 begin
9265 S := Current_Scope;
9266 while Present (S) and then S /= Standard_Standard loop
9267 if Ekind (S) = E_Package
9268 and then Is_Generic_Instance (S)
9269 and then not In_Package_Body (S)
9270 and then not In_Private_Part (S)
9271 then
9272 return True;
9273 end if;
9275 S := Scope (S);
9276 end loop;
9278 return False;
9279 end In_Instance_Visible_Part;
9281 ---------------------
9282 -- In_Package_Body --
9283 ---------------------
9285 function In_Package_Body return Boolean is
9286 S : Entity_Id;
9288 begin
9289 S := Current_Scope;
9290 while Present (S) and then S /= Standard_Standard loop
9291 if Ekind (S) = E_Package and then In_Package_Body (S) then
9292 return True;
9293 else
9294 S := Scope (S);
9295 end if;
9296 end loop;
9298 return False;
9299 end In_Package_Body;
9301 --------------------------------
9302 -- In_Parameter_Specification --
9303 --------------------------------
9305 function In_Parameter_Specification (N : Node_Id) return Boolean is
9306 PN : Node_Id;
9308 begin
9309 PN := Parent (N);
9310 while Present (PN) loop
9311 if Nkind (PN) = N_Parameter_Specification then
9312 return True;
9313 end if;
9315 PN := Parent (PN);
9316 end loop;
9318 return False;
9319 end In_Parameter_Specification;
9321 --------------------------
9322 -- In_Pragma_Expression --
9323 --------------------------
9325 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
9326 P : Node_Id;
9327 begin
9328 P := Parent (N);
9329 loop
9330 if No (P) then
9331 return False;
9332 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
9333 return True;
9334 else
9335 P := Parent (P);
9336 end if;
9337 end loop;
9338 end In_Pragma_Expression;
9340 -------------------------------------
9341 -- In_Reverse_Storage_Order_Object --
9342 -------------------------------------
9344 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
9345 Pref : Node_Id;
9346 Btyp : Entity_Id := Empty;
9348 begin
9349 -- Climb up indexed components
9351 Pref := N;
9352 loop
9353 case Nkind (Pref) is
9354 when N_Selected_Component =>
9355 Pref := Prefix (Pref);
9356 exit;
9358 when N_Indexed_Component =>
9359 Pref := Prefix (Pref);
9361 when others =>
9362 Pref := Empty;
9363 exit;
9364 end case;
9365 end loop;
9367 if Present (Pref) then
9368 Btyp := Base_Type (Etype (Pref));
9369 end if;
9371 return Present (Btyp)
9372 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
9373 and then Reverse_Storage_Order (Btyp);
9374 end In_Reverse_Storage_Order_Object;
9376 --------------------------------------
9377 -- In_Subprogram_Or_Concurrent_Unit --
9378 --------------------------------------
9380 function In_Subprogram_Or_Concurrent_Unit return Boolean is
9381 E : Entity_Id;
9382 K : Entity_Kind;
9384 begin
9385 -- Use scope chain to check successively outer scopes
9387 E := Current_Scope;
9388 loop
9389 K := Ekind (E);
9391 if K in Subprogram_Kind
9392 or else K in Concurrent_Kind
9393 or else K in Generic_Subprogram_Kind
9394 then
9395 return True;
9397 elsif E = Standard_Standard then
9398 return False;
9399 end if;
9401 E := Scope (E);
9402 end loop;
9403 end In_Subprogram_Or_Concurrent_Unit;
9405 ---------------------
9406 -- In_Visible_Part --
9407 ---------------------
9409 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
9410 begin
9411 return Is_Package_Or_Generic_Package (Scope_Id)
9412 and then In_Open_Scopes (Scope_Id)
9413 and then not In_Package_Body (Scope_Id)
9414 and then not In_Private_Part (Scope_Id);
9415 end In_Visible_Part;
9417 --------------------------------
9418 -- Incomplete_Or_Partial_View --
9419 --------------------------------
9421 function Incomplete_Or_Partial_View (Id : Entity_Id) return Entity_Id is
9422 function Inspect_Decls
9423 (Decls : List_Id;
9424 Taft : Boolean := False) return Entity_Id;
9425 -- Check whether a declarative region contains the incomplete or partial
9426 -- view of Id.
9428 -------------------
9429 -- Inspect_Decls --
9430 -------------------
9432 function Inspect_Decls
9433 (Decls : List_Id;
9434 Taft : Boolean := False) return Entity_Id
9436 Decl : Node_Id;
9437 Match : Node_Id;
9439 begin
9440 Decl := First (Decls);
9441 while Present (Decl) loop
9442 Match := Empty;
9444 if Taft then
9445 if Nkind (Decl) = N_Incomplete_Type_Declaration then
9446 Match := Defining_Identifier (Decl);
9447 end if;
9449 else
9450 if Nkind_In (Decl, N_Private_Extension_Declaration,
9451 N_Private_Type_Declaration)
9452 then
9453 Match := Defining_Identifier (Decl);
9454 end if;
9455 end if;
9457 if Present (Match)
9458 and then Present (Full_View (Match))
9459 and then Full_View (Match) = Id
9460 then
9461 return Match;
9462 end if;
9464 Next (Decl);
9465 end loop;
9467 return Empty;
9468 end Inspect_Decls;
9470 -- Local variables
9472 Prev : Entity_Id;
9474 -- Start of processing for Incomplete_Or_Partial_View
9476 begin
9477 -- Deferred constant or incomplete type case
9479 Prev := Current_Entity_In_Scope (Id);
9481 if Present (Prev)
9482 and then (Is_Incomplete_Type (Prev) or else Ekind (Prev) = E_Constant)
9483 and then Present (Full_View (Prev))
9484 and then Full_View (Prev) = Id
9485 then
9486 return Prev;
9487 end if;
9489 -- Private or Taft amendment type case
9491 declare
9492 Pkg : constant Entity_Id := Scope (Id);
9493 Pkg_Decl : Node_Id := Pkg;
9495 begin
9496 if Ekind (Pkg) = E_Package then
9497 while Nkind (Pkg_Decl) /= N_Package_Specification loop
9498 Pkg_Decl := Parent (Pkg_Decl);
9499 end loop;
9501 -- It is knows that Typ has a private view, look for it in the
9502 -- visible declarations of the enclosing scope. A special case
9503 -- of this is when the two views have been exchanged - the full
9504 -- appears earlier than the private.
9506 if Has_Private_Declaration (Id) then
9507 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
9509 -- Exchanged view case, look in the private declarations
9511 if No (Prev) then
9512 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
9513 end if;
9515 return Prev;
9517 -- Otherwise if this is the package body, then Typ is a potential
9518 -- Taft amendment type. The incomplete view should be located in
9519 -- the private declarations of the enclosing scope.
9521 elsif In_Package_Body (Pkg) then
9522 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
9523 end if;
9524 end if;
9525 end;
9527 -- The type has no incomplete or private view
9529 return Empty;
9530 end Incomplete_Or_Partial_View;
9532 -----------------------------------------
9533 -- Inherit_Default_Init_Cond_Procedure --
9534 -----------------------------------------
9536 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
9537 Par_Typ : constant Entity_Id := Etype (Typ);
9539 begin
9540 -- A derived type inherits the default initial condition procedure of
9541 -- its parent type.
9543 if No (Default_Init_Cond_Procedure (Typ)) then
9544 Set_Default_Init_Cond_Procedure
9545 (Typ, Default_Init_Cond_Procedure (Par_Typ));
9546 end if;
9547 end Inherit_Default_Init_Cond_Procedure;
9549 ----------------------------
9550 -- Inherit_Rep_Item_Chain --
9551 ----------------------------
9553 procedure Inherit_Rep_Item_Chain (Typ : Entity_Id; From_Typ : Entity_Id) is
9554 From_Item : constant Node_Id := First_Rep_Item (From_Typ);
9555 Item : Node_Id := Empty;
9556 Last_Item : Node_Id := Empty;
9558 begin
9559 -- Reach the end of the destination type's chain (if any) and capture
9560 -- the last item.
9562 Item := First_Rep_Item (Typ);
9563 while Present (Item) loop
9565 -- Do not inherit a chain that has been inherited already
9567 if Item = From_Item then
9568 return;
9569 end if;
9571 Last_Item := Item;
9572 Item := Next_Rep_Item (Item);
9573 end loop;
9575 -- When the destination type has a rep item chain, the chain of the
9576 -- source type is appended to it.
9578 if Present (Last_Item) then
9579 Set_Next_Rep_Item (Last_Item, From_Item);
9581 -- Otherwise the destination type directly inherits the rep item chain
9582 -- of the source type (if any).
9584 else
9585 Set_First_Rep_Item (Typ, From_Item);
9586 end if;
9587 end Inherit_Rep_Item_Chain;
9589 ---------------------------------
9590 -- Inherit_Subprogram_Contract --
9591 ---------------------------------
9593 procedure Inherit_Subprogram_Contract
9594 (Subp : Entity_Id;
9595 From_Subp : Entity_Id)
9597 procedure Inherit_Pragma (Prag_Id : Pragma_Id);
9598 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
9599 -- Subp's contract.
9601 --------------------
9602 -- Inherit_Pragma --
9603 --------------------
9605 procedure Inherit_Pragma (Prag_Id : Pragma_Id) is
9606 Prag : constant Node_Id := Get_Pragma (From_Subp, Prag_Id);
9607 New_Prag : Node_Id;
9609 begin
9610 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
9611 -- chains, therefore the node must be replicated. The new pragma is
9612 -- flagged is inherited for distrinction purposes.
9614 if Present (Prag) then
9615 New_Prag := New_Copy_Tree (Prag);
9616 Set_Is_Inherited (New_Prag);
9618 Add_Contract_Item (New_Prag, Subp);
9619 end if;
9620 end Inherit_Pragma;
9622 -- Start of processing for Inherit_Subprogram_Contract
9624 begin
9625 -- Inheritance is carried out only when both entities are subprograms
9626 -- with contracts.
9628 if Is_Subprogram_Or_Generic_Subprogram (Subp)
9629 and then Is_Subprogram_Or_Generic_Subprogram (From_Subp)
9630 and then Present (Contract (Subp))
9631 and then Present (Contract (From_Subp))
9632 then
9633 Inherit_Pragma (Pragma_Extensions_Visible);
9634 end if;
9635 end Inherit_Subprogram_Contract;
9637 ---------------------------------
9638 -- Insert_Explicit_Dereference --
9639 ---------------------------------
9641 procedure Insert_Explicit_Dereference (N : Node_Id) is
9642 New_Prefix : constant Node_Id := Relocate_Node (N);
9643 Ent : Entity_Id := Empty;
9644 Pref : Node_Id;
9645 I : Interp_Index;
9646 It : Interp;
9647 T : Entity_Id;
9649 begin
9650 Save_Interps (N, New_Prefix);
9652 Rewrite (N,
9653 Make_Explicit_Dereference (Sloc (Parent (N)),
9654 Prefix => New_Prefix));
9656 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
9658 if Is_Overloaded (New_Prefix) then
9660 -- The dereference is also overloaded, and its interpretations are
9661 -- the designated types of the interpretations of the original node.
9663 Set_Etype (N, Any_Type);
9665 Get_First_Interp (New_Prefix, I, It);
9666 while Present (It.Nam) loop
9667 T := It.Typ;
9669 if Is_Access_Type (T) then
9670 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
9671 end if;
9673 Get_Next_Interp (I, It);
9674 end loop;
9676 End_Interp_List;
9678 else
9679 -- Prefix is unambiguous: mark the original prefix (which might
9680 -- Come_From_Source) as a reference, since the new (relocated) one
9681 -- won't be taken into account.
9683 if Is_Entity_Name (New_Prefix) then
9684 Ent := Entity (New_Prefix);
9685 Pref := New_Prefix;
9687 -- For a retrieval of a subcomponent of some composite object,
9688 -- retrieve the ultimate entity if there is one.
9690 elsif Nkind_In (New_Prefix, N_Selected_Component,
9691 N_Indexed_Component)
9692 then
9693 Pref := Prefix (New_Prefix);
9694 while Present (Pref)
9695 and then Nkind_In (Pref, N_Selected_Component,
9696 N_Indexed_Component)
9697 loop
9698 Pref := Prefix (Pref);
9699 end loop;
9701 if Present (Pref) and then Is_Entity_Name (Pref) then
9702 Ent := Entity (Pref);
9703 end if;
9704 end if;
9706 -- Place the reference on the entity node
9708 if Present (Ent) then
9709 Generate_Reference (Ent, Pref);
9710 end if;
9711 end if;
9712 end Insert_Explicit_Dereference;
9714 ------------------------------------------
9715 -- Inspect_Deferred_Constant_Completion --
9716 ------------------------------------------
9718 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
9719 Decl : Node_Id;
9721 begin
9722 Decl := First (Decls);
9723 while Present (Decl) loop
9725 -- Deferred constant signature
9727 if Nkind (Decl) = N_Object_Declaration
9728 and then Constant_Present (Decl)
9729 and then No (Expression (Decl))
9731 -- No need to check internally generated constants
9733 and then Comes_From_Source (Decl)
9735 -- The constant is not completed. A full object declaration or a
9736 -- pragma Import complete a deferred constant.
9738 and then not Has_Completion (Defining_Identifier (Decl))
9739 then
9740 Error_Msg_N
9741 ("constant declaration requires initialization expression",
9742 Defining_Identifier (Decl));
9743 end if;
9745 Decl := Next (Decl);
9746 end loop;
9747 end Inspect_Deferred_Constant_Completion;
9749 -----------------------------
9750 -- Is_Actual_Out_Parameter --
9751 -----------------------------
9753 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
9754 Formal : Entity_Id;
9755 Call : Node_Id;
9756 begin
9757 Find_Actual (N, Formal, Call);
9758 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
9759 end Is_Actual_Out_Parameter;
9761 -------------------------
9762 -- Is_Actual_Parameter --
9763 -------------------------
9765 function Is_Actual_Parameter (N : Node_Id) return Boolean is
9766 PK : constant Node_Kind := Nkind (Parent (N));
9768 begin
9769 case PK is
9770 when N_Parameter_Association =>
9771 return N = Explicit_Actual_Parameter (Parent (N));
9773 when N_Subprogram_Call =>
9774 return Is_List_Member (N)
9775 and then
9776 List_Containing (N) = Parameter_Associations (Parent (N));
9778 when others =>
9779 return False;
9780 end case;
9781 end Is_Actual_Parameter;
9783 --------------------------------
9784 -- Is_Actual_Tagged_Parameter --
9785 --------------------------------
9787 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
9788 Formal : Entity_Id;
9789 Call : Node_Id;
9790 begin
9791 Find_Actual (N, Formal, Call);
9792 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
9793 end Is_Actual_Tagged_Parameter;
9795 ---------------------
9796 -- Is_Aliased_View --
9797 ---------------------
9799 function Is_Aliased_View (Obj : Node_Id) return Boolean is
9800 E : Entity_Id;
9802 begin
9803 if Is_Entity_Name (Obj) then
9804 E := Entity (Obj);
9806 return
9807 (Is_Object (E)
9808 and then
9809 (Is_Aliased (E)
9810 or else (Present (Renamed_Object (E))
9811 and then Is_Aliased_View (Renamed_Object (E)))))
9813 or else ((Is_Formal (E)
9814 or else Ekind_In (E, E_Generic_In_Out_Parameter,
9815 E_Generic_In_Parameter))
9816 and then Is_Tagged_Type (Etype (E)))
9818 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
9820 -- Current instance of type, either directly or as rewritten
9821 -- reference to the current object.
9823 or else (Is_Entity_Name (Original_Node (Obj))
9824 and then Present (Entity (Original_Node (Obj)))
9825 and then Is_Type (Entity (Original_Node (Obj))))
9827 or else (Is_Type (E) and then E = Current_Scope)
9829 or else (Is_Incomplete_Or_Private_Type (E)
9830 and then Full_View (E) = Current_Scope)
9832 -- Ada 2012 AI05-0053: the return object of an extended return
9833 -- statement is aliased if its type is immutably limited.
9835 or else (Is_Return_Object (E)
9836 and then Is_Limited_View (Etype (E)));
9838 elsif Nkind (Obj) = N_Selected_Component then
9839 return Is_Aliased (Entity (Selector_Name (Obj)));
9841 elsif Nkind (Obj) = N_Indexed_Component then
9842 return Has_Aliased_Components (Etype (Prefix (Obj)))
9843 or else
9844 (Is_Access_Type (Etype (Prefix (Obj)))
9845 and then Has_Aliased_Components
9846 (Designated_Type (Etype (Prefix (Obj)))));
9848 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
9849 return Is_Tagged_Type (Etype (Obj))
9850 and then Is_Aliased_View (Expression (Obj));
9852 elsif Nkind (Obj) = N_Explicit_Dereference then
9853 return Nkind (Original_Node (Obj)) /= N_Function_Call;
9855 else
9856 return False;
9857 end if;
9858 end Is_Aliased_View;
9860 -------------------------
9861 -- Is_Ancestor_Package --
9862 -------------------------
9864 function Is_Ancestor_Package
9865 (E1 : Entity_Id;
9866 E2 : Entity_Id) return Boolean
9868 Par : Entity_Id;
9870 begin
9871 Par := E2;
9872 while Present (Par) and then Par /= Standard_Standard loop
9873 if Par = E1 then
9874 return True;
9875 end if;
9877 Par := Scope (Par);
9878 end loop;
9880 return False;
9881 end Is_Ancestor_Package;
9883 ----------------------
9884 -- Is_Atomic_Object --
9885 ----------------------
9887 function Is_Atomic_Object (N : Node_Id) return Boolean is
9889 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
9890 -- Determines if given object has atomic components
9892 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
9893 -- If prefix is an implicit dereference, examine designated type
9895 ----------------------
9896 -- Is_Atomic_Prefix --
9897 ----------------------
9899 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
9900 begin
9901 if Is_Access_Type (Etype (N)) then
9902 return
9903 Has_Atomic_Components (Designated_Type (Etype (N)));
9904 else
9905 return Object_Has_Atomic_Components (N);
9906 end if;
9907 end Is_Atomic_Prefix;
9909 ----------------------------------
9910 -- Object_Has_Atomic_Components --
9911 ----------------------------------
9913 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
9914 begin
9915 if Has_Atomic_Components (Etype (N))
9916 or else Is_Atomic (Etype (N))
9917 then
9918 return True;
9920 elsif Is_Entity_Name (N)
9921 and then (Has_Atomic_Components (Entity (N))
9922 or else Is_Atomic (Entity (N)))
9923 then
9924 return True;
9926 elsif Nkind (N) = N_Selected_Component
9927 and then Is_Atomic (Entity (Selector_Name (N)))
9928 then
9929 return True;
9931 elsif Nkind (N) = N_Indexed_Component
9932 or else Nkind (N) = N_Selected_Component
9933 then
9934 return Is_Atomic_Prefix (Prefix (N));
9936 else
9937 return False;
9938 end if;
9939 end Object_Has_Atomic_Components;
9941 -- Start of processing for Is_Atomic_Object
9943 begin
9944 -- Predicate is not relevant to subprograms
9946 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
9947 return False;
9949 elsif Is_Atomic (Etype (N))
9950 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
9951 then
9952 return True;
9954 elsif Nkind (N) = N_Selected_Component
9955 and then Is_Atomic (Entity (Selector_Name (N)))
9956 then
9957 return True;
9959 elsif Nkind (N) = N_Indexed_Component
9960 or else Nkind (N) = N_Selected_Component
9961 then
9962 return Is_Atomic_Prefix (Prefix (N));
9964 else
9965 return False;
9966 end if;
9967 end Is_Atomic_Object;
9969 -------------------------
9970 -- Is_Attribute_Result --
9971 -------------------------
9973 function Is_Attribute_Result (N : Node_Id) return Boolean is
9974 begin
9975 return Nkind (N) = N_Attribute_Reference
9976 and then Attribute_Name (N) = Name_Result;
9977 end Is_Attribute_Result;
9979 ------------------------------------
9980 -- Is_Body_Or_Package_Declaration --
9981 ------------------------------------
9983 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
9984 begin
9985 return Nkind_In (N, N_Entry_Body,
9986 N_Package_Body,
9987 N_Package_Declaration,
9988 N_Protected_Body,
9989 N_Subprogram_Body,
9990 N_Task_Body);
9991 end Is_Body_Or_Package_Declaration;
9993 -----------------------
9994 -- Is_Bounded_String --
9995 -----------------------
9997 function Is_Bounded_String (T : Entity_Id) return Boolean is
9998 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
10000 begin
10001 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10002 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10003 -- be True for all the Bounded_String types in instances of the
10004 -- Generic_Bounded_Length generics, and for types derived from those.
10006 return Present (Under)
10007 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
10008 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
10009 Is_RTE (Root_Type (Under), RO_WW_Super_String));
10010 end Is_Bounded_String;
10012 -------------------------
10013 -- Is_Child_Or_Sibling --
10014 -------------------------
10016 function Is_Child_Or_Sibling
10017 (Pack_1 : Entity_Id;
10018 Pack_2 : Entity_Id) return Boolean
10020 function Distance_From_Standard (Pack : Entity_Id) return Nat;
10021 -- Given an arbitrary package, return the number of "climbs" necessary
10022 -- to reach scope Standard_Standard.
10024 procedure Equalize_Depths
10025 (Pack : in out Entity_Id;
10026 Depth : in out Nat;
10027 Depth_To_Reach : Nat);
10028 -- Given an arbitrary package, its depth and a target depth to reach,
10029 -- climb the scope chain until the said depth is reached. The pointer
10030 -- to the package and its depth a modified during the climb.
10032 ----------------------------
10033 -- Distance_From_Standard --
10034 ----------------------------
10036 function Distance_From_Standard (Pack : Entity_Id) return Nat is
10037 Dist : Nat;
10038 Scop : Entity_Id;
10040 begin
10041 Dist := 0;
10042 Scop := Pack;
10043 while Present (Scop) and then Scop /= Standard_Standard loop
10044 Dist := Dist + 1;
10045 Scop := Scope (Scop);
10046 end loop;
10048 return Dist;
10049 end Distance_From_Standard;
10051 ---------------------
10052 -- Equalize_Depths --
10053 ---------------------
10055 procedure Equalize_Depths
10056 (Pack : in out Entity_Id;
10057 Depth : in out Nat;
10058 Depth_To_Reach : Nat)
10060 begin
10061 -- The package must be at a greater or equal depth
10063 if Depth < Depth_To_Reach then
10064 raise Program_Error;
10065 end if;
10067 -- Climb the scope chain until the desired depth is reached
10069 while Present (Pack) and then Depth /= Depth_To_Reach loop
10070 Pack := Scope (Pack);
10071 Depth := Depth - 1;
10072 end loop;
10073 end Equalize_Depths;
10075 -- Local variables
10077 P_1 : Entity_Id := Pack_1;
10078 P_1_Child : Boolean := False;
10079 P_1_Depth : Nat := Distance_From_Standard (P_1);
10080 P_2 : Entity_Id := Pack_2;
10081 P_2_Child : Boolean := False;
10082 P_2_Depth : Nat := Distance_From_Standard (P_2);
10084 -- Start of processing for Is_Child_Or_Sibling
10086 begin
10087 pragma Assert
10088 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
10090 -- Both packages denote the same entity, therefore they cannot be
10091 -- children or siblings.
10093 if P_1 = P_2 then
10094 return False;
10096 -- One of the packages is at a deeper level than the other. Note that
10097 -- both may still come from differen hierarchies.
10099 -- (root) P_2
10100 -- / \ :
10101 -- X P_2 or X
10102 -- : :
10103 -- P_1 P_1
10105 elsif P_1_Depth > P_2_Depth then
10106 Equalize_Depths
10107 (Pack => P_1,
10108 Depth => P_1_Depth,
10109 Depth_To_Reach => P_2_Depth);
10110 P_1_Child := True;
10112 -- (root) P_1
10113 -- / \ :
10114 -- P_1 X or X
10115 -- : :
10116 -- P_2 P_2
10118 elsif P_2_Depth > P_1_Depth then
10119 Equalize_Depths
10120 (Pack => P_2,
10121 Depth => P_2_Depth,
10122 Depth_To_Reach => P_1_Depth);
10123 P_2_Child := True;
10124 end if;
10126 -- At this stage the package pointers have been elevated to the same
10127 -- depth. If the related entities are the same, then one package is a
10128 -- potential child of the other:
10130 -- P_1
10131 -- :
10132 -- X became P_1 P_2 or vica versa
10133 -- :
10134 -- P_2
10136 if P_1 = P_2 then
10137 if P_1_Child then
10138 return Is_Child_Unit (Pack_1);
10140 else pragma Assert (P_2_Child);
10141 return Is_Child_Unit (Pack_2);
10142 end if;
10144 -- The packages may come from the same package chain or from entirely
10145 -- different hierarcies. To determine this, climb the scope stack until
10146 -- a common root is found.
10148 -- (root) (root 1) (root 2)
10149 -- / \ | |
10150 -- P_1 P_2 P_1 P_2
10152 else
10153 while Present (P_1) and then Present (P_2) loop
10155 -- The two packages may be siblings
10157 if P_1 = P_2 then
10158 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
10159 end if;
10161 P_1 := Scope (P_1);
10162 P_2 := Scope (P_2);
10163 end loop;
10164 end if;
10166 return False;
10167 end Is_Child_Or_Sibling;
10169 -----------------------------
10170 -- Is_Concurrent_Interface --
10171 -----------------------------
10173 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
10174 begin
10175 return Is_Interface (T)
10176 and then
10177 (Is_Protected_Interface (T)
10178 or else Is_Synchronized_Interface (T)
10179 or else Is_Task_Interface (T));
10180 end Is_Concurrent_Interface;
10182 ---------------------------
10183 -- Is_Container_Element --
10184 ---------------------------
10186 function Is_Container_Element (Exp : Node_Id) return Boolean is
10187 Loc : constant Source_Ptr := Sloc (Exp);
10188 Pref : constant Node_Id := Prefix (Exp);
10190 Call : Node_Id;
10191 -- Call to an indexing aspect
10193 Cont_Typ : Entity_Id;
10194 -- The type of the container being accessed
10196 Elem_Typ : Entity_Id;
10197 -- Its element type
10199 Indexing : Entity_Id;
10200 Is_Const : Boolean;
10201 -- Indicates that constant indexing is used, and the element is thus
10202 -- a constant.
10204 Ref_Typ : Entity_Id;
10205 -- The reference type returned by the indexing operation
10207 begin
10208 -- If C is a container, in a context that imposes the element type of
10209 -- that container, the indexing notation C (X) is rewritten as:
10211 -- Indexing (C, X).Discr.all
10213 -- where Indexing is one of the indexing aspects of the container.
10214 -- If the context does not require a reference, the construct can be
10215 -- rewritten as
10217 -- Element (C, X)
10219 -- First, verify that the construct has the proper form
10221 if not Expander_Active then
10222 return False;
10224 elsif Nkind (Pref) /= N_Selected_Component then
10225 return False;
10227 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
10228 return False;
10230 else
10231 Call := Prefix (Pref);
10232 Ref_Typ := Etype (Call);
10233 end if;
10235 if not Has_Implicit_Dereference (Ref_Typ)
10236 or else No (First (Parameter_Associations (Call)))
10237 or else not Is_Entity_Name (Name (Call))
10238 then
10239 return False;
10240 end if;
10242 -- Retrieve type of container object, and its iterator aspects
10244 Cont_Typ := Etype (First (Parameter_Associations (Call)));
10245 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
10246 Is_Const := False;
10248 if No (Indexing) then
10250 -- Container should have at least one indexing operation
10252 return False;
10254 elsif Entity (Name (Call)) /= Entity (Indexing) then
10256 -- This may be a variable indexing operation
10258 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
10260 if No (Indexing)
10261 or else Entity (Name (Call)) /= Entity (Indexing)
10262 then
10263 return False;
10264 end if;
10266 else
10267 Is_Const := True;
10268 end if;
10270 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
10272 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
10273 return False;
10274 end if;
10276 -- Check that the expression is not the target of an assignment, in
10277 -- which case the rewriting is not possible.
10279 if not Is_Const then
10280 declare
10281 Par : Node_Id;
10283 begin
10284 Par := Exp;
10285 while Present (Par)
10286 loop
10287 if Nkind (Parent (Par)) = N_Assignment_Statement
10288 and then Par = Name (Parent (Par))
10289 then
10290 return False;
10292 -- A renaming produces a reference, and the transformation
10293 -- does not apply.
10295 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
10296 return False;
10298 elsif Nkind_In
10299 (Nkind (Parent (Par)), N_Function_Call,
10300 N_Procedure_Call_Statement,
10301 N_Entry_Call_Statement)
10302 then
10303 -- Check that the element is not part of an actual for an
10304 -- in-out parameter.
10306 declare
10307 F : Entity_Id;
10308 A : Node_Id;
10310 begin
10311 F := First_Formal (Entity (Name (Parent (Par))));
10312 A := First (Parameter_Associations (Parent (Par)));
10313 while Present (F) loop
10314 if A = Par and then Ekind (F) /= E_In_Parameter then
10315 return False;
10316 end if;
10318 Next_Formal (F);
10319 Next (A);
10320 end loop;
10321 end;
10323 -- E_In_Parameter in a call: element is not modified.
10325 exit;
10326 end if;
10328 Par := Parent (Par);
10329 end loop;
10330 end;
10331 end if;
10333 -- The expression has the proper form and the context requires the
10334 -- element type. Retrieve the Element function of the container and
10335 -- rewrite the construct as a call to it.
10337 declare
10338 Op : Elmt_Id;
10340 begin
10341 Op := First_Elmt (Primitive_Operations (Cont_Typ));
10342 while Present (Op) loop
10343 exit when Chars (Node (Op)) = Name_Element;
10344 Next_Elmt (Op);
10345 end loop;
10347 if No (Op) then
10348 return False;
10350 else
10351 Rewrite (Exp,
10352 Make_Function_Call (Loc,
10353 Name => New_Occurrence_Of (Node (Op), Loc),
10354 Parameter_Associations => Parameter_Associations (Call)));
10355 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
10356 return True;
10357 end if;
10358 end;
10359 end Is_Container_Element;
10361 -----------------------
10362 -- Is_Constant_Bound --
10363 -----------------------
10365 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
10366 begin
10367 if Compile_Time_Known_Value (Exp) then
10368 return True;
10370 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10371 return Is_Constant_Object (Entity (Exp))
10372 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10374 elsif Nkind (Exp) in N_Binary_Op then
10375 return Is_Constant_Bound (Left_Opnd (Exp))
10376 and then Is_Constant_Bound (Right_Opnd (Exp))
10377 and then Scope (Entity (Exp)) = Standard_Standard;
10379 else
10380 return False;
10381 end if;
10382 end Is_Constant_Bound;
10384 --------------------------------------
10385 -- Is_Controlling_Limited_Procedure --
10386 --------------------------------------
10388 function Is_Controlling_Limited_Procedure
10389 (Proc_Nam : Entity_Id) return Boolean
10391 Param_Typ : Entity_Id := Empty;
10393 begin
10394 if Ekind (Proc_Nam) = E_Procedure
10395 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
10396 then
10397 Param_Typ := Etype (Parameter_Type (First (
10398 Parameter_Specifications (Parent (Proc_Nam)))));
10400 -- In this case where an Itype was created, the procedure call has been
10401 -- rewritten.
10403 elsif Present (Associated_Node_For_Itype (Proc_Nam))
10404 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
10405 and then
10406 Present (Parameter_Associations
10407 (Associated_Node_For_Itype (Proc_Nam)))
10408 then
10409 Param_Typ :=
10410 Etype (First (Parameter_Associations
10411 (Associated_Node_For_Itype (Proc_Nam))));
10412 end if;
10414 if Present (Param_Typ) then
10415 return
10416 Is_Interface (Param_Typ)
10417 and then Is_Limited_Record (Param_Typ);
10418 end if;
10420 return False;
10421 end Is_Controlling_Limited_Procedure;
10423 -----------------------------
10424 -- Is_CPP_Constructor_Call --
10425 -----------------------------
10427 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
10428 begin
10429 return Nkind (N) = N_Function_Call
10430 and then Is_CPP_Class (Etype (Etype (N)))
10431 and then Is_Constructor (Entity (Name (N)))
10432 and then Is_Imported (Entity (Name (N)));
10433 end Is_CPP_Constructor_Call;
10435 -----------------
10436 -- Is_Delegate --
10437 -----------------
10439 function Is_Delegate (T : Entity_Id) return Boolean is
10440 Desig_Type : Entity_Id;
10442 begin
10443 if VM_Target /= CLI_Target then
10444 return False;
10445 end if;
10447 -- Access-to-subprograms are delegates in CIL
10449 if Ekind (T) = E_Access_Subprogram_Type then
10450 return True;
10451 end if;
10453 if not Is_Access_Type (T) then
10455 -- A delegate is a managed pointer. If no designated type is defined
10456 -- it means that it's not a delegate.
10458 return False;
10459 end if;
10461 Desig_Type := Etype (Directly_Designated_Type (T));
10463 if not Is_Tagged_Type (Desig_Type) then
10464 return False;
10465 end if;
10467 -- Test if the type is inherited from [mscorlib]System.Delegate
10469 while Etype (Desig_Type) /= Desig_Type loop
10470 if Chars (Scope (Desig_Type)) /= No_Name
10471 and then Is_Imported (Scope (Desig_Type))
10472 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
10473 then
10474 return True;
10475 end if;
10477 Desig_Type := Etype (Desig_Type);
10478 end loop;
10480 return False;
10481 end Is_Delegate;
10483 ----------------------------------------------
10484 -- Is_Dependent_Component_Of_Mutable_Object --
10485 ----------------------------------------------
10487 function Is_Dependent_Component_Of_Mutable_Object
10488 (Object : Node_Id) return Boolean
10490 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
10491 -- Returns True if and only if Comp is declared within a variant part
10493 --------------------------------
10494 -- Is_Declared_Within_Variant --
10495 --------------------------------
10497 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
10498 Comp_Decl : constant Node_Id := Parent (Comp);
10499 Comp_List : constant Node_Id := Parent (Comp_Decl);
10500 begin
10501 return Nkind (Parent (Comp_List)) = N_Variant;
10502 end Is_Declared_Within_Variant;
10504 P : Node_Id;
10505 Prefix_Type : Entity_Id;
10506 P_Aliased : Boolean := False;
10507 Comp : Entity_Id;
10509 Deref : Node_Id := Object;
10510 -- Dereference node, in something like X.all.Y(2)
10512 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10514 begin
10515 -- Find the dereference node if any
10517 while Nkind_In (Deref, N_Indexed_Component,
10518 N_Selected_Component,
10519 N_Slice)
10520 loop
10521 Deref := Prefix (Deref);
10522 end loop;
10524 -- Ada 2005: If we have a component or slice of a dereference,
10525 -- something like X.all.Y (2), and the type of X is access-to-constant,
10526 -- Is_Variable will return False, because it is indeed a constant
10527 -- view. But it might be a view of a variable object, so we want the
10528 -- following condition to be True in that case.
10530 if Is_Variable (Object)
10531 or else (Ada_Version >= Ada_2005
10532 and then Nkind (Deref) = N_Explicit_Dereference)
10533 then
10534 if Nkind (Object) = N_Selected_Component then
10535 P := Prefix (Object);
10536 Prefix_Type := Etype (P);
10538 if Is_Entity_Name (P) then
10539 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
10540 Prefix_Type := Base_Type (Prefix_Type);
10541 end if;
10543 if Is_Aliased (Entity (P)) then
10544 P_Aliased := True;
10545 end if;
10547 -- A discriminant check on a selected component may be expanded
10548 -- into a dereference when removing side-effects. Recover the
10549 -- original node and its type, which may be unconstrained.
10551 elsif Nkind (P) = N_Explicit_Dereference
10552 and then not (Comes_From_Source (P))
10553 then
10554 P := Original_Node (P);
10555 Prefix_Type := Etype (P);
10557 else
10558 -- Check for prefix being an aliased component???
10560 null;
10562 end if;
10564 -- A heap object is constrained by its initial value
10566 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10567 -- the dereferenced case, since the access value might denote an
10568 -- unconstrained aliased object, whereas in Ada 95 the designated
10569 -- object is guaranteed to be constrained. A worst-case assumption
10570 -- has to apply in Ada 2005 because we can't tell at compile
10571 -- time whether the object is "constrained by its initial value"
10572 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10573 -- rules (these rules are acknowledged to need fixing).
10575 if Ada_Version < Ada_2005 then
10576 if Is_Access_Type (Prefix_Type)
10577 or else Nkind (P) = N_Explicit_Dereference
10578 then
10579 return False;
10580 end if;
10582 else pragma Assert (Ada_Version >= Ada_2005);
10583 if Is_Access_Type (Prefix_Type) then
10585 -- If the access type is pool-specific, and there is no
10586 -- constrained partial view of the designated type, then the
10587 -- designated object is known to be constrained.
10589 if Ekind (Prefix_Type) = E_Access_Type
10590 and then not Object_Type_Has_Constrained_Partial_View
10591 (Typ => Designated_Type (Prefix_Type),
10592 Scop => Current_Scope)
10593 then
10594 return False;
10596 -- Otherwise (general access type, or there is a constrained
10597 -- partial view of the designated type), we need to check
10598 -- based on the designated type.
10600 else
10601 Prefix_Type := Designated_Type (Prefix_Type);
10602 end if;
10603 end if;
10604 end if;
10606 Comp :=
10607 Original_Record_Component (Entity (Selector_Name (Object)));
10609 -- As per AI-0017, the renaming is illegal in a generic body, even
10610 -- if the subtype is indefinite.
10612 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10614 if not Is_Constrained (Prefix_Type)
10615 and then (not Is_Indefinite_Subtype (Prefix_Type)
10616 or else
10617 (Is_Generic_Type (Prefix_Type)
10618 and then Ekind (Current_Scope) = E_Generic_Package
10619 and then In_Package_Body (Current_Scope)))
10621 and then (Is_Declared_Within_Variant (Comp)
10622 or else Has_Discriminant_Dependent_Constraint (Comp))
10623 and then (not P_Aliased or else Ada_Version >= Ada_2005)
10624 then
10625 return True;
10627 -- If the prefix is of an access type at this point, then we want
10628 -- to return False, rather than calling this function recursively
10629 -- on the access object (which itself might be a discriminant-
10630 -- dependent component of some other object, but that isn't
10631 -- relevant to checking the object passed to us). This avoids
10632 -- issuing wrong errors when compiling with -gnatc, where there
10633 -- can be implicit dereferences that have not been expanded.
10635 elsif Is_Access_Type (Etype (Prefix (Object))) then
10636 return False;
10638 else
10639 return
10640 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10641 end if;
10643 elsif Nkind (Object) = N_Indexed_Component
10644 or else Nkind (Object) = N_Slice
10645 then
10646 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10648 -- A type conversion that Is_Variable is a view conversion:
10649 -- go back to the denoted object.
10651 elsif Nkind (Object) = N_Type_Conversion then
10652 return
10653 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
10654 end if;
10655 end if;
10657 return False;
10658 end Is_Dependent_Component_Of_Mutable_Object;
10660 ---------------------
10661 -- Is_Dereferenced --
10662 ---------------------
10664 function Is_Dereferenced (N : Node_Id) return Boolean is
10665 P : constant Node_Id := Parent (N);
10666 begin
10667 return Nkind_In (P, N_Selected_Component,
10668 N_Explicit_Dereference,
10669 N_Indexed_Component,
10670 N_Slice)
10671 and then Prefix (P) = N;
10672 end Is_Dereferenced;
10674 ----------------------
10675 -- Is_Descendent_Of --
10676 ----------------------
10678 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
10679 T : Entity_Id;
10680 Etyp : Entity_Id;
10682 begin
10683 pragma Assert (Nkind (T1) in N_Entity);
10684 pragma Assert (Nkind (T2) in N_Entity);
10686 T := Base_Type (T1);
10688 -- Immediate return if the types match
10690 if T = T2 then
10691 return True;
10693 -- Comment needed here ???
10695 elsif Ekind (T) = E_Class_Wide_Type then
10696 return Etype (T) = T2;
10698 -- All other cases
10700 else
10701 loop
10702 Etyp := Etype (T);
10704 -- Done if we found the type we are looking for
10706 if Etyp = T2 then
10707 return True;
10709 -- Done if no more derivations to check
10711 elsif T = T1
10712 or else T = Etyp
10713 then
10714 return False;
10716 -- Following test catches error cases resulting from prev errors
10718 elsif No (Etyp) then
10719 return False;
10721 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
10722 return False;
10724 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
10725 return False;
10726 end if;
10728 T := Base_Type (Etyp);
10729 end loop;
10730 end if;
10731 end Is_Descendent_Of;
10733 -----------------------------
10734 -- Is_Effectively_Volatile --
10735 -----------------------------
10737 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
10738 begin
10739 if Is_Type (Id) then
10741 -- An arbitrary type is effectively volatile when it is subject to
10742 -- pragma Atomic or Volatile.
10744 if Is_Volatile (Id) then
10745 return True;
10747 -- An array type is effectively volatile when it is subject to pragma
10748 -- Atomic_Components or Volatile_Components or its compolent type is
10749 -- effectively volatile.
10751 elsif Is_Array_Type (Id) then
10752 return
10753 Has_Volatile_Components (Id)
10754 or else
10755 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
10757 else
10758 return False;
10759 end if;
10761 -- Otherwise Id denotes an object
10763 else
10764 return
10765 Is_Volatile (Id)
10766 or else Has_Volatile_Components (Id)
10767 or else Is_Effectively_Volatile (Etype (Id));
10768 end if;
10769 end Is_Effectively_Volatile;
10771 ------------------------------------
10772 -- Is_Effectively_Volatile_Object --
10773 ------------------------------------
10775 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
10776 begin
10777 if Is_Entity_Name (N) then
10778 return Is_Effectively_Volatile (Entity (N));
10780 elsif Nkind (N) = N_Expanded_Name then
10781 return Is_Effectively_Volatile (Entity (N));
10783 elsif Nkind (N) = N_Indexed_Component then
10784 return Is_Effectively_Volatile_Object (Prefix (N));
10786 elsif Nkind (N) = N_Selected_Component then
10787 return
10788 Is_Effectively_Volatile_Object (Prefix (N))
10789 or else
10790 Is_Effectively_Volatile_Object (Selector_Name (N));
10792 else
10793 return False;
10794 end if;
10795 end Is_Effectively_Volatile_Object;
10797 ----------------------------
10798 -- Is_Expression_Function --
10799 ----------------------------
10801 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
10802 Decl : Node_Id;
10804 begin
10805 if Ekind (Subp) /= E_Function then
10806 return False;
10808 else
10809 Decl := Unit_Declaration_Node (Subp);
10810 return Nkind (Decl) = N_Subprogram_Declaration
10811 and then
10812 (Nkind (Original_Node (Decl)) = N_Expression_Function
10813 or else
10814 (Present (Corresponding_Body (Decl))
10815 and then
10816 Nkind (Original_Node
10817 (Unit_Declaration_Node
10818 (Corresponding_Body (Decl)))) =
10819 N_Expression_Function));
10820 end if;
10821 end Is_Expression_Function;
10823 -----------------------
10824 -- Is_EVF_Expression --
10825 -----------------------
10827 function Is_EVF_Expression (N : Node_Id) return Boolean is
10828 Orig_N : constant Node_Id := Original_Node (N);
10829 Alt : Node_Id;
10830 Expr : Node_Id;
10831 Id : Entity_Id;
10833 begin
10834 -- Detect a reference to a formal parameter of a specific tagged type
10835 -- whose related subprogram is subject to pragma Expresions_Visible with
10836 -- value "False".
10838 if Is_Entity_Name (N) and then Present (Entity (N)) then
10839 Id := Entity (N);
10841 return
10842 Is_Formal (Id)
10843 and then Is_Specific_Tagged_Type (Etype (Id))
10844 and then Extensions_Visible_Status (Id) =
10845 Extensions_Visible_False;
10847 -- A case expression is an EVF expression when it contains at least one
10848 -- EVF dependent_expression. Note that a case expression may have been
10849 -- expanded, hence the use of Original_Node.
10851 elsif Nkind (Orig_N) = N_Case_Expression then
10852 Alt := First (Alternatives (Orig_N));
10853 while Present (Alt) loop
10854 if Is_EVF_Expression (Expression (Alt)) then
10855 return True;
10856 end if;
10858 Next (Alt);
10859 end loop;
10861 -- An if expression is an EVF expression when it contains at least one
10862 -- EVF dependent_expression. Note that an if expression may have been
10863 -- expanded, hence the use of Original_Node.
10865 elsif Nkind (Orig_N) = N_If_Expression then
10866 Expr := Next (First (Expressions (Orig_N)));
10867 while Present (Expr) loop
10868 if Is_EVF_Expression (Expr) then
10869 return True;
10870 end if;
10872 Next (Expr);
10873 end loop;
10875 -- A qualified expression or a type conversion is an EVF expression when
10876 -- its operand is an EVF expression.
10878 elsif Nkind_In (N, N_Qualified_Expression,
10879 N_Unchecked_Type_Conversion,
10880 N_Type_Conversion)
10881 then
10882 return Is_EVF_Expression (Expression (N));
10884 -- Attributes 'Loop_Entry, 'Old and 'Update are an EVF expression when
10885 -- their prefix denotes an EVF expression.
10887 elsif Nkind (N) = N_Attribute_Reference
10888 and then Nam_In (Attribute_Name (N), Name_Loop_Entry,
10889 Name_Old,
10890 Name_Update)
10891 then
10892 return Is_EVF_Expression (Prefix (N));
10893 end if;
10895 return False;
10896 end Is_EVF_Expression;
10898 --------------
10899 -- Is_False --
10900 --------------
10902 function Is_False (U : Uint) return Boolean is
10903 begin
10904 return (U = 0);
10905 end Is_False;
10907 ---------------------------
10908 -- Is_Fixed_Model_Number --
10909 ---------------------------
10911 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
10912 S : constant Ureal := Small_Value (T);
10913 M : Urealp.Save_Mark;
10914 R : Boolean;
10915 begin
10916 M := Urealp.Mark;
10917 R := (U = UR_Trunc (U / S) * S);
10918 Urealp.Release (M);
10919 return R;
10920 end Is_Fixed_Model_Number;
10922 -------------------------------
10923 -- Is_Fully_Initialized_Type --
10924 -------------------------------
10926 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
10927 begin
10928 -- Scalar types
10930 if Is_Scalar_Type (Typ) then
10932 -- A scalar type with an aspect Default_Value is fully initialized
10934 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
10935 -- of a scalar type, but we don't take that into account here, since
10936 -- we don't want these to affect warnings.
10938 return Has_Default_Aspect (Typ);
10940 elsif Is_Access_Type (Typ) then
10941 return True;
10943 elsif Is_Array_Type (Typ) then
10944 if Is_Fully_Initialized_Type (Component_Type (Typ))
10945 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
10946 then
10947 return True;
10948 end if;
10950 -- An interesting case, if we have a constrained type one of whose
10951 -- bounds is known to be null, then there are no elements to be
10952 -- initialized, so all the elements are initialized.
10954 if Is_Constrained (Typ) then
10955 declare
10956 Indx : Node_Id;
10957 Indx_Typ : Entity_Id;
10958 Lbd, Hbd : Node_Id;
10960 begin
10961 Indx := First_Index (Typ);
10962 while Present (Indx) loop
10963 if Etype (Indx) = Any_Type then
10964 return False;
10966 -- If index is a range, use directly
10968 elsif Nkind (Indx) = N_Range then
10969 Lbd := Low_Bound (Indx);
10970 Hbd := High_Bound (Indx);
10972 else
10973 Indx_Typ := Etype (Indx);
10975 if Is_Private_Type (Indx_Typ) then
10976 Indx_Typ := Full_View (Indx_Typ);
10977 end if;
10979 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
10980 return False;
10981 else
10982 Lbd := Type_Low_Bound (Indx_Typ);
10983 Hbd := Type_High_Bound (Indx_Typ);
10984 end if;
10985 end if;
10987 if Compile_Time_Known_Value (Lbd)
10988 and then
10989 Compile_Time_Known_Value (Hbd)
10990 then
10991 if Expr_Value (Hbd) < Expr_Value (Lbd) then
10992 return True;
10993 end if;
10994 end if;
10996 Next_Index (Indx);
10997 end loop;
10998 end;
10999 end if;
11001 -- If no null indexes, then type is not fully initialized
11003 return False;
11005 -- Record types
11007 elsif Is_Record_Type (Typ) then
11008 if Has_Discriminants (Typ)
11009 and then
11010 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
11011 and then Is_Fully_Initialized_Variant (Typ)
11012 then
11013 return True;
11014 end if;
11016 -- We consider bounded string types to be fully initialized, because
11017 -- otherwise we get false alarms when the Data component is not
11018 -- default-initialized.
11020 if Is_Bounded_String (Typ) then
11021 return True;
11022 end if;
11024 -- Controlled records are considered to be fully initialized if
11025 -- there is a user defined Initialize routine. This may not be
11026 -- entirely correct, but as the spec notes, we are guessing here
11027 -- what is best from the point of view of issuing warnings.
11029 if Is_Controlled (Typ) then
11030 declare
11031 Utyp : constant Entity_Id := Underlying_Type (Typ);
11033 begin
11034 if Present (Utyp) then
11035 declare
11036 Init : constant Entity_Id :=
11037 (Find_Prim_Op
11038 (Underlying_Type (Typ), Name_Initialize));
11040 begin
11041 if Present (Init)
11042 and then Comes_From_Source (Init)
11043 and then not
11044 Is_Predefined_File_Name
11045 (File_Name (Get_Source_File_Index (Sloc (Init))))
11046 then
11047 return True;
11049 elsif Has_Null_Extension (Typ)
11050 and then
11051 Is_Fully_Initialized_Type
11052 (Etype (Base_Type (Typ)))
11053 then
11054 return True;
11055 end if;
11056 end;
11057 end if;
11058 end;
11059 end if;
11061 -- Otherwise see if all record components are initialized
11063 declare
11064 Ent : Entity_Id;
11066 begin
11067 Ent := First_Entity (Typ);
11068 while Present (Ent) loop
11069 if Ekind (Ent) = E_Component
11070 and then (No (Parent (Ent))
11071 or else No (Expression (Parent (Ent))))
11072 and then not Is_Fully_Initialized_Type (Etype (Ent))
11074 -- Special VM case for tag components, which need to be
11075 -- defined in this case, but are never initialized as VMs
11076 -- are using other dispatching mechanisms. Ignore this
11077 -- uninitialized case. Note that this applies both to the
11078 -- uTag entry and the main vtable pointer (CPP_Class case).
11080 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
11081 then
11082 return False;
11083 end if;
11085 Next_Entity (Ent);
11086 end loop;
11087 end;
11089 -- No uninitialized components, so type is fully initialized.
11090 -- Note that this catches the case of no components as well.
11092 return True;
11094 elsif Is_Concurrent_Type (Typ) then
11095 return True;
11097 elsif Is_Private_Type (Typ) then
11098 declare
11099 U : constant Entity_Id := Underlying_Type (Typ);
11101 begin
11102 if No (U) then
11103 return False;
11104 else
11105 return Is_Fully_Initialized_Type (U);
11106 end if;
11107 end;
11109 else
11110 return False;
11111 end if;
11112 end Is_Fully_Initialized_Type;
11114 ----------------------------------
11115 -- Is_Fully_Initialized_Variant --
11116 ----------------------------------
11118 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
11119 Loc : constant Source_Ptr := Sloc (Typ);
11120 Constraints : constant List_Id := New_List;
11121 Components : constant Elist_Id := New_Elmt_List;
11122 Comp_Elmt : Elmt_Id;
11123 Comp_Id : Node_Id;
11124 Comp_List : Node_Id;
11125 Discr : Entity_Id;
11126 Discr_Val : Node_Id;
11128 Report_Errors : Boolean;
11129 pragma Warnings (Off, Report_Errors);
11131 begin
11132 if Serious_Errors_Detected > 0 then
11133 return False;
11134 end if;
11136 if Is_Record_Type (Typ)
11137 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
11138 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
11139 then
11140 Comp_List := Component_List (Type_Definition (Parent (Typ)));
11142 Discr := First_Discriminant (Typ);
11143 while Present (Discr) loop
11144 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
11145 Discr_Val := Expression (Parent (Discr));
11147 if Present (Discr_Val)
11148 and then Is_OK_Static_Expression (Discr_Val)
11149 then
11150 Append_To (Constraints,
11151 Make_Component_Association (Loc,
11152 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
11153 Expression => New_Copy (Discr_Val)));
11154 else
11155 return False;
11156 end if;
11157 else
11158 return False;
11159 end if;
11161 Next_Discriminant (Discr);
11162 end loop;
11164 Gather_Components
11165 (Typ => Typ,
11166 Comp_List => Comp_List,
11167 Governed_By => Constraints,
11168 Into => Components,
11169 Report_Errors => Report_Errors);
11171 -- Check that each component present is fully initialized
11173 Comp_Elmt := First_Elmt (Components);
11174 while Present (Comp_Elmt) loop
11175 Comp_Id := Node (Comp_Elmt);
11177 if Ekind (Comp_Id) = E_Component
11178 and then (No (Parent (Comp_Id))
11179 or else No (Expression (Parent (Comp_Id))))
11180 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
11181 then
11182 return False;
11183 end if;
11185 Next_Elmt (Comp_Elmt);
11186 end loop;
11188 return True;
11190 elsif Is_Private_Type (Typ) then
11191 declare
11192 U : constant Entity_Id := Underlying_Type (Typ);
11194 begin
11195 if No (U) then
11196 return False;
11197 else
11198 return Is_Fully_Initialized_Variant (U);
11199 end if;
11200 end;
11202 else
11203 return False;
11204 end if;
11205 end Is_Fully_Initialized_Variant;
11207 ---------------------
11208 -- Is_Ghost_Entity --
11209 ---------------------
11211 function Is_Ghost_Entity (Id : Entity_Id) return Boolean is
11212 begin
11213 return Is_Checked_Ghost_Entity (Id) or else Is_Ignored_Ghost_Entity (Id);
11214 end Is_Ghost_Entity;
11216 ----------------------------------
11217 -- Is_Ghost_Statement_Or_Pragma --
11218 ----------------------------------
11220 function Is_Ghost_Statement_Or_Pragma (N : Node_Id) return Boolean is
11221 function Is_Ghost_Entity_Reference (N : Node_Id) return Boolean;
11222 -- Determine whether an arbitrary node denotes a reference to a Ghost
11223 -- entity.
11225 -------------------------------
11226 -- Is_Ghost_Entity_Reference --
11227 -------------------------------
11229 function Is_Ghost_Entity_Reference (N : Node_Id) return Boolean is
11230 Ref : Node_Id;
11232 begin
11233 Ref := N;
11235 -- When the reference extracts a subcomponent, recover the related
11236 -- object (SPARK RM 6.9(1)).
11238 while Nkind_In (Ref, N_Explicit_Dereference,
11239 N_Indexed_Component,
11240 N_Selected_Component,
11241 N_Slice)
11242 loop
11243 Ref := Prefix (Ref);
11244 end loop;
11246 return
11247 Is_Entity_Name (Ref)
11248 and then Present (Entity (Ref))
11249 and then Is_Ghost_Entity (Entity (Ref));
11250 end Is_Ghost_Entity_Reference;
11252 -- Local variables
11254 Arg : Node_Id;
11255 Stmt : Node_Id;
11257 -- Start of processing for Is_Ghost_Statement_Or_Pragma
11259 begin
11260 if Nkind (N) = N_Pragma then
11262 -- A pragma is Ghost when it appears within a Ghost package or
11263 -- subprogram.
11265 if Within_Ghost_Scope then
11266 return True;
11267 end if;
11269 -- A pragma is Ghost when it mentions a Ghost entity
11271 Arg := First (Pragma_Argument_Associations (N));
11272 while Present (Arg) loop
11273 if Is_Ghost_Entity_Reference (Get_Pragma_Arg (Arg)) then
11274 return True;
11275 end if;
11277 Next (Arg);
11278 end loop;
11279 end if;
11281 Stmt := N;
11282 while Present (Stmt) loop
11284 -- A statement is Ghost when it appears within a Ghost package or
11285 -- subprogram.
11287 if Is_Statement (Stmt) and then Within_Ghost_Scope then
11288 return True;
11290 -- An assignment statement is Ghost when the target is a Ghost
11291 -- variable. A procedure call is Ghost when the invoked procedure
11292 -- is Ghost.
11294 elsif Nkind_In (Stmt, N_Assignment_Statement,
11295 N_Procedure_Call_Statement)
11296 then
11297 return Is_Ghost_Entity_Reference (Name (Stmt));
11299 -- Prevent the search from going too far
11301 elsif Is_Body_Or_Package_Declaration (Stmt) then
11302 return False;
11303 end if;
11305 Stmt := Parent (Stmt);
11306 end loop;
11308 return False;
11309 end Is_Ghost_Statement_Or_Pragma;
11311 ----------------------------
11312 -- Is_Inherited_Operation --
11313 ----------------------------
11315 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
11316 pragma Assert (Is_Overloadable (E));
11317 Kind : constant Node_Kind := Nkind (Parent (E));
11318 begin
11319 return Kind = N_Full_Type_Declaration
11320 or else Kind = N_Private_Extension_Declaration
11321 or else Kind = N_Subtype_Declaration
11322 or else (Ekind (E) = E_Enumeration_Literal
11323 and then Is_Derived_Type (Etype (E)));
11324 end Is_Inherited_Operation;
11326 -------------------------------------
11327 -- Is_Inherited_Operation_For_Type --
11328 -------------------------------------
11330 function Is_Inherited_Operation_For_Type
11331 (E : Entity_Id;
11332 Typ : Entity_Id) return Boolean
11334 begin
11335 -- Check that the operation has been created by the type declaration
11337 return Is_Inherited_Operation (E)
11338 and then Defining_Identifier (Parent (E)) = Typ;
11339 end Is_Inherited_Operation_For_Type;
11341 -----------------
11342 -- Is_Iterator --
11343 -----------------
11345 function Is_Iterator (Typ : Entity_Id) return Boolean is
11346 Ifaces_List : Elist_Id;
11347 Iface_Elmt : Elmt_Id;
11348 Iface : Entity_Id;
11350 begin
11351 if Is_Class_Wide_Type (Typ)
11352 and then Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
11353 Name_Reversible_Iterator)
11354 and then
11355 Is_Predefined_File_Name
11356 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
11357 then
11358 return True;
11360 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11361 return False;
11363 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
11364 return True;
11366 else
11367 Collect_Interfaces (Typ, Ifaces_List);
11369 Iface_Elmt := First_Elmt (Ifaces_List);
11370 while Present (Iface_Elmt) loop
11371 Iface := Node (Iface_Elmt);
11372 if Chars (Iface) = Name_Forward_Iterator
11373 and then
11374 Is_Predefined_File_Name
11375 (Unit_File_Name (Get_Source_Unit (Iface)))
11376 then
11377 return True;
11378 end if;
11380 Next_Elmt (Iface_Elmt);
11381 end loop;
11383 return False;
11384 end if;
11385 end Is_Iterator;
11387 ------------
11388 -- Is_LHS --
11389 ------------
11391 -- We seem to have a lot of overlapping functions that do similar things
11392 -- (testing for left hand sides or lvalues???).
11394 function Is_LHS (N : Node_Id) return Is_LHS_Result is
11395 P : constant Node_Id := Parent (N);
11397 begin
11398 -- Return True if we are the left hand side of an assignment statement
11400 if Nkind (P) = N_Assignment_Statement then
11401 if Name (P) = N then
11402 return Yes;
11403 else
11404 return No;
11405 end if;
11407 -- Case of prefix of indexed or selected component or slice
11409 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
11410 and then N = Prefix (P)
11411 then
11412 -- Here we have the case where the parent P is N.Q or N(Q .. R).
11413 -- If P is an LHS, then N is also effectively an LHS, but there
11414 -- is an important exception. If N is of an access type, then
11415 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
11416 -- case this makes N.all a left hand side but not N itself.
11418 -- If we don't know the type yet, this is the case where we return
11419 -- Unknown, since the answer depends on the type which is unknown.
11421 if No (Etype (N)) then
11422 return Unknown;
11424 -- We have an Etype set, so we can check it
11426 elsif Is_Access_Type (Etype (N)) then
11427 return No;
11429 -- OK, not access type case, so just test whole expression
11431 else
11432 return Is_LHS (P);
11433 end if;
11435 -- All other cases are not left hand sides
11437 else
11438 return No;
11439 end if;
11440 end Is_LHS;
11442 -----------------------------
11443 -- Is_Library_Level_Entity --
11444 -----------------------------
11446 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
11447 begin
11448 -- The following is a small optimization, and it also properly handles
11449 -- discriminals, which in task bodies might appear in expressions before
11450 -- the corresponding procedure has been created, and which therefore do
11451 -- not have an assigned scope.
11453 if Is_Formal (E) then
11454 return False;
11455 end if;
11457 -- Normal test is simply that the enclosing dynamic scope is Standard
11459 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
11460 end Is_Library_Level_Entity;
11462 --------------------------------
11463 -- Is_Limited_Class_Wide_Type --
11464 --------------------------------
11466 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
11467 begin
11468 return
11469 Is_Class_Wide_Type (Typ)
11470 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
11471 end Is_Limited_Class_Wide_Type;
11473 ---------------------------------
11474 -- Is_Local_Variable_Reference --
11475 ---------------------------------
11477 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
11478 begin
11479 if not Is_Entity_Name (Expr) then
11480 return False;
11482 else
11483 declare
11484 Ent : constant Entity_Id := Entity (Expr);
11485 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
11486 begin
11487 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
11488 return False;
11489 else
11490 return Present (Sub) and then Sub = Current_Subprogram;
11491 end if;
11492 end;
11493 end if;
11494 end Is_Local_Variable_Reference;
11496 -------------------------
11497 -- Is_Object_Reference --
11498 -------------------------
11500 function Is_Object_Reference (N : Node_Id) return Boolean is
11502 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
11503 -- Determine whether N is the name of an internally-generated renaming
11505 --------------------------------------
11506 -- Is_Internally_Generated_Renaming --
11507 --------------------------------------
11509 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
11510 P : Node_Id;
11512 begin
11513 P := N;
11514 while Present (P) loop
11515 if Nkind (P) = N_Object_Renaming_Declaration then
11516 return not Comes_From_Source (P);
11517 elsif Is_List_Member (P) then
11518 return False;
11519 end if;
11521 P := Parent (P);
11522 end loop;
11524 return False;
11525 end Is_Internally_Generated_Renaming;
11527 -- Start of processing for Is_Object_Reference
11529 begin
11530 if Is_Entity_Name (N) then
11531 return Present (Entity (N)) and then Is_Object (Entity (N));
11533 else
11534 case Nkind (N) is
11535 when N_Indexed_Component | N_Slice =>
11536 return
11537 Is_Object_Reference (Prefix (N))
11538 or else Is_Access_Type (Etype (Prefix (N)));
11540 -- In Ada 95, a function call is a constant object; a procedure
11541 -- call is not.
11543 when N_Function_Call =>
11544 return Etype (N) /= Standard_Void_Type;
11546 -- Attributes 'Input, 'Old and 'Result produce objects
11548 when N_Attribute_Reference =>
11549 return
11550 Nam_In
11551 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
11553 when N_Selected_Component =>
11554 return
11555 Is_Object_Reference (Selector_Name (N))
11556 and then
11557 (Is_Object_Reference (Prefix (N))
11558 or else Is_Access_Type (Etype (Prefix (N))));
11560 when N_Explicit_Dereference =>
11561 return True;
11563 -- A view conversion of a tagged object is an object reference
11565 when N_Type_Conversion =>
11566 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
11567 and then Is_Tagged_Type (Etype (Expression (N)))
11568 and then Is_Object_Reference (Expression (N));
11570 -- An unchecked type conversion is considered to be an object if
11571 -- the operand is an object (this construction arises only as a
11572 -- result of expansion activities).
11574 when N_Unchecked_Type_Conversion =>
11575 return True;
11577 -- Allow string literals to act as objects as long as they appear
11578 -- in internally-generated renamings. The expansion of iterators
11579 -- may generate such renamings when the range involves a string
11580 -- literal.
11582 when N_String_Literal =>
11583 return Is_Internally_Generated_Renaming (Parent (N));
11585 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11586 -- This allows disambiguation of function calls and the use
11587 -- of aggregates in more contexts.
11589 when N_Qualified_Expression =>
11590 if Ada_Version < Ada_2012 then
11591 return False;
11592 else
11593 return Is_Object_Reference (Expression (N))
11594 or else Nkind (Expression (N)) = N_Aggregate;
11595 end if;
11597 when others =>
11598 return False;
11599 end case;
11600 end if;
11601 end Is_Object_Reference;
11603 -----------------------------------
11604 -- Is_OK_Variable_For_Out_Formal --
11605 -----------------------------------
11607 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
11608 begin
11609 Note_Possible_Modification (AV, Sure => True);
11611 -- We must reject parenthesized variable names. Comes_From_Source is
11612 -- checked because there are currently cases where the compiler violates
11613 -- this rule (e.g. passing a task object to its controlled Initialize
11614 -- routine). This should be properly documented in sinfo???
11616 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
11617 return False;
11619 -- A variable is always allowed
11621 elsif Is_Variable (AV) then
11622 return True;
11624 -- Unchecked conversions are allowed only if they come from the
11625 -- generated code, which sometimes uses unchecked conversions for out
11626 -- parameters in cases where code generation is unaffected. We tell
11627 -- source unchecked conversions by seeing if they are rewrites of
11628 -- an original Unchecked_Conversion function call, or of an explicit
11629 -- conversion of a function call or an aggregate (as may happen in the
11630 -- expansion of a packed array aggregate).
11632 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
11633 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
11634 return False;
11636 elsif Comes_From_Source (AV)
11637 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
11638 then
11639 return False;
11641 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
11642 return Is_OK_Variable_For_Out_Formal (Expression (AV));
11644 else
11645 return True;
11646 end if;
11648 -- Normal type conversions are allowed if argument is a variable
11650 elsif Nkind (AV) = N_Type_Conversion then
11651 if Is_Variable (Expression (AV))
11652 and then Paren_Count (Expression (AV)) = 0
11653 then
11654 Note_Possible_Modification (Expression (AV), Sure => True);
11655 return True;
11657 -- We also allow a non-parenthesized expression that raises
11658 -- constraint error if it rewrites what used to be a variable
11660 elsif Raises_Constraint_Error (Expression (AV))
11661 and then Paren_Count (Expression (AV)) = 0
11662 and then Is_Variable (Original_Node (Expression (AV)))
11663 then
11664 return True;
11666 -- Type conversion of something other than a variable
11668 else
11669 return False;
11670 end if;
11672 -- If this node is rewritten, then test the original form, if that is
11673 -- OK, then we consider the rewritten node OK (for example, if the
11674 -- original node is a conversion, then Is_Variable will not be true
11675 -- but we still want to allow the conversion if it converts a variable).
11677 elsif Original_Node (AV) /= AV then
11679 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11680 -- Reference function.
11682 if Ada_Version >= Ada_2012
11683 and then Nkind (Original_Node (AV)) = N_Function_Call
11684 and then
11685 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
11686 then
11687 return True;
11689 else
11690 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
11691 end if;
11693 -- All other non-variables are rejected
11695 else
11696 return False;
11697 end if;
11698 end Is_OK_Variable_For_Out_Formal;
11700 -----------------------------------
11701 -- Is_Partially_Initialized_Type --
11702 -----------------------------------
11704 function Is_Partially_Initialized_Type
11705 (Typ : Entity_Id;
11706 Include_Implicit : Boolean := True) return Boolean
11708 begin
11709 if Is_Scalar_Type (Typ) then
11710 return False;
11712 elsif Is_Access_Type (Typ) then
11713 return Include_Implicit;
11715 elsif Is_Array_Type (Typ) then
11717 -- If component type is partially initialized, so is array type
11719 if Is_Partially_Initialized_Type
11720 (Component_Type (Typ), Include_Implicit)
11721 then
11722 return True;
11724 -- Otherwise we are only partially initialized if we are fully
11725 -- initialized (this is the empty array case, no point in us
11726 -- duplicating that code here).
11728 else
11729 return Is_Fully_Initialized_Type (Typ);
11730 end if;
11732 elsif Is_Record_Type (Typ) then
11734 -- A discriminated type is always partially initialized if in
11735 -- all mode
11737 if Has_Discriminants (Typ) and then Include_Implicit then
11738 return True;
11740 -- A tagged type is always partially initialized
11742 elsif Is_Tagged_Type (Typ) then
11743 return True;
11745 -- Case of non-discriminated record
11747 else
11748 declare
11749 Ent : Entity_Id;
11751 Component_Present : Boolean := False;
11752 -- Set True if at least one component is present. If no
11753 -- components are present, then record type is fully
11754 -- initialized (another odd case, like the null array).
11756 begin
11757 -- Loop through components
11759 Ent := First_Entity (Typ);
11760 while Present (Ent) loop
11761 if Ekind (Ent) = E_Component then
11762 Component_Present := True;
11764 -- If a component has an initialization expression then
11765 -- the enclosing record type is partially initialized
11767 if Present (Parent (Ent))
11768 and then Present (Expression (Parent (Ent)))
11769 then
11770 return True;
11772 -- If a component is of a type which is itself partially
11773 -- initialized, then the enclosing record type is also.
11775 elsif Is_Partially_Initialized_Type
11776 (Etype (Ent), Include_Implicit)
11777 then
11778 return True;
11779 end if;
11780 end if;
11782 Next_Entity (Ent);
11783 end loop;
11785 -- No initialized components found. If we found any components
11786 -- they were all uninitialized so the result is false.
11788 if Component_Present then
11789 return False;
11791 -- But if we found no components, then all the components are
11792 -- initialized so we consider the type to be initialized.
11794 else
11795 return True;
11796 end if;
11797 end;
11798 end if;
11800 -- Concurrent types are always fully initialized
11802 elsif Is_Concurrent_Type (Typ) then
11803 return True;
11805 -- For a private type, go to underlying type. If there is no underlying
11806 -- type then just assume this partially initialized. Not clear if this
11807 -- can happen in a non-error case, but no harm in testing for this.
11809 elsif Is_Private_Type (Typ) then
11810 declare
11811 U : constant Entity_Id := Underlying_Type (Typ);
11812 begin
11813 if No (U) then
11814 return True;
11815 else
11816 return Is_Partially_Initialized_Type (U, Include_Implicit);
11817 end if;
11818 end;
11820 -- For any other type (are there any?) assume partially initialized
11822 else
11823 return True;
11824 end if;
11825 end Is_Partially_Initialized_Type;
11827 ------------------------------------
11828 -- Is_Potentially_Persistent_Type --
11829 ------------------------------------
11831 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
11832 Comp : Entity_Id;
11833 Indx : Node_Id;
11835 begin
11836 -- For private type, test corresponding full type
11838 if Is_Private_Type (T) then
11839 return Is_Potentially_Persistent_Type (Full_View (T));
11841 -- Scalar types are potentially persistent
11843 elsif Is_Scalar_Type (T) then
11844 return True;
11846 -- Record type is potentially persistent if not tagged and the types of
11847 -- all it components are potentially persistent, and no component has
11848 -- an initialization expression.
11850 elsif Is_Record_Type (T)
11851 and then not Is_Tagged_Type (T)
11852 and then not Is_Partially_Initialized_Type (T)
11853 then
11854 Comp := First_Component (T);
11855 while Present (Comp) loop
11856 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
11857 return False;
11858 else
11859 Next_Entity (Comp);
11860 end if;
11861 end loop;
11863 return True;
11865 -- Array type is potentially persistent if its component type is
11866 -- potentially persistent and if all its constraints are static.
11868 elsif Is_Array_Type (T) then
11869 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
11870 return False;
11871 end if;
11873 Indx := First_Index (T);
11874 while Present (Indx) loop
11875 if not Is_OK_Static_Subtype (Etype (Indx)) then
11876 return False;
11877 else
11878 Next_Index (Indx);
11879 end if;
11880 end loop;
11882 return True;
11884 -- All other types are not potentially persistent
11886 else
11887 return False;
11888 end if;
11889 end Is_Potentially_Persistent_Type;
11891 --------------------------------
11892 -- Is_Potentially_Unevaluated --
11893 --------------------------------
11895 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
11896 Par : Node_Id;
11897 Expr : Node_Id;
11899 begin
11900 Expr := N;
11901 Par := Parent (N);
11903 -- A postcondition whose expression is a short-circuit is broken down
11904 -- into individual aspects for better exception reporting. The original
11905 -- short-circuit expression is rewritten as the second operand, and an
11906 -- occurrence of 'Old in that operand is potentially unevaluated.
11907 -- See Sem_ch13.adb for details of this transformation.
11909 if Nkind (Original_Node (Par)) = N_And_Then then
11910 return True;
11911 end if;
11913 while not Nkind_In (Par, N_If_Expression,
11914 N_Case_Expression,
11915 N_And_Then,
11916 N_Or_Else,
11917 N_In,
11918 N_Not_In)
11919 loop
11920 Expr := Par;
11921 Par := Parent (Par);
11923 -- If the context is not an expression, or if is the result of
11924 -- expansion of an enclosing construct (such as another attribute)
11925 -- the predicate does not apply.
11927 if Nkind (Par) not in N_Subexpr
11928 or else not Comes_From_Source (Par)
11929 then
11930 return False;
11931 end if;
11932 end loop;
11934 if Nkind (Par) = N_If_Expression then
11935 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
11937 elsif Nkind (Par) = N_Case_Expression then
11938 return Expr /= Expression (Par);
11940 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
11941 return Expr = Right_Opnd (Par);
11943 elsif Nkind_In (Par, N_In, N_Not_In) then
11944 return Expr /= Left_Opnd (Par);
11946 else
11947 return False;
11948 end if;
11949 end Is_Potentially_Unevaluated;
11951 ---------------------------------
11952 -- Is_Protected_Self_Reference --
11953 ---------------------------------
11955 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
11957 function In_Access_Definition (N : Node_Id) return Boolean;
11958 -- Returns true if N belongs to an access definition
11960 --------------------------
11961 -- In_Access_Definition --
11962 --------------------------
11964 function In_Access_Definition (N : Node_Id) return Boolean is
11965 P : Node_Id;
11967 begin
11968 P := Parent (N);
11969 while Present (P) loop
11970 if Nkind (P) = N_Access_Definition then
11971 return True;
11972 end if;
11974 P := Parent (P);
11975 end loop;
11977 return False;
11978 end In_Access_Definition;
11980 -- Start of processing for Is_Protected_Self_Reference
11982 begin
11983 -- Verify that prefix is analyzed and has the proper form. Note that
11984 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11985 -- which also produce the address of an entity, do not analyze their
11986 -- prefix because they denote entities that are not necessarily visible.
11987 -- Neither of them can apply to a protected type.
11989 return Ada_Version >= Ada_2005
11990 and then Is_Entity_Name (N)
11991 and then Present (Entity (N))
11992 and then Is_Protected_Type (Entity (N))
11993 and then In_Open_Scopes (Entity (N))
11994 and then not In_Access_Definition (N);
11995 end Is_Protected_Self_Reference;
11997 -----------------------------
11998 -- Is_RCI_Pkg_Spec_Or_Body --
11999 -----------------------------
12001 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
12003 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
12004 -- Return True if the unit of Cunit is an RCI package declaration
12006 ---------------------------
12007 -- Is_RCI_Pkg_Decl_Cunit --
12008 ---------------------------
12010 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
12011 The_Unit : constant Node_Id := Unit (Cunit);
12013 begin
12014 if Nkind (The_Unit) /= N_Package_Declaration then
12015 return False;
12016 end if;
12018 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
12019 end Is_RCI_Pkg_Decl_Cunit;
12021 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12023 begin
12024 return Is_RCI_Pkg_Decl_Cunit (Cunit)
12025 or else
12026 (Nkind (Unit (Cunit)) = N_Package_Body
12027 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
12028 end Is_RCI_Pkg_Spec_Or_Body;
12030 -----------------------------------------
12031 -- Is_Remote_Access_To_Class_Wide_Type --
12032 -----------------------------------------
12034 function Is_Remote_Access_To_Class_Wide_Type
12035 (E : Entity_Id) return Boolean
12037 begin
12038 -- A remote access to class-wide type is a general access to object type
12039 -- declared in the visible part of a Remote_Types or Remote_Call_
12040 -- Interface unit.
12042 return Ekind (E) = E_General_Access_Type
12043 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12044 end Is_Remote_Access_To_Class_Wide_Type;
12046 -----------------------------------------
12047 -- Is_Remote_Access_To_Subprogram_Type --
12048 -----------------------------------------
12050 function Is_Remote_Access_To_Subprogram_Type
12051 (E : Entity_Id) return Boolean
12053 begin
12054 return (Ekind (E) = E_Access_Subprogram_Type
12055 or else (Ekind (E) = E_Record_Type
12056 and then Present (Corresponding_Remote_Type (E))))
12057 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
12058 end Is_Remote_Access_To_Subprogram_Type;
12060 --------------------
12061 -- Is_Remote_Call --
12062 --------------------
12064 function Is_Remote_Call (N : Node_Id) return Boolean is
12065 begin
12066 if Nkind (N) not in N_Subprogram_Call then
12068 -- An entry call cannot be remote
12070 return False;
12072 elsif Nkind (Name (N)) in N_Has_Entity
12073 and then Is_Remote_Call_Interface (Entity (Name (N)))
12074 then
12075 -- A subprogram declared in the spec of a RCI package is remote
12077 return True;
12079 elsif Nkind (Name (N)) = N_Explicit_Dereference
12080 and then Is_Remote_Access_To_Subprogram_Type
12081 (Etype (Prefix (Name (N))))
12082 then
12083 -- The dereference of a RAS is a remote call
12085 return True;
12087 elsif Present (Controlling_Argument (N))
12088 and then Is_Remote_Access_To_Class_Wide_Type
12089 (Etype (Controlling_Argument (N)))
12090 then
12091 -- Any primitive operation call with a controlling argument of
12092 -- a RACW type is a remote call.
12094 return True;
12095 end if;
12097 -- All other calls are local calls
12099 return False;
12100 end Is_Remote_Call;
12102 ----------------------
12103 -- Is_Renamed_Entry --
12104 ----------------------
12106 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
12107 Orig_Node : Node_Id := Empty;
12108 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
12110 function Is_Entry (Nam : Node_Id) return Boolean;
12111 -- Determine whether Nam is an entry. Traverse selectors if there are
12112 -- nested selected components.
12114 --------------
12115 -- Is_Entry --
12116 --------------
12118 function Is_Entry (Nam : Node_Id) return Boolean is
12119 begin
12120 if Nkind (Nam) = N_Selected_Component then
12121 return Is_Entry (Selector_Name (Nam));
12122 end if;
12124 return Ekind (Entity (Nam)) = E_Entry;
12125 end Is_Entry;
12127 -- Start of processing for Is_Renamed_Entry
12129 begin
12130 if Present (Alias (Proc_Nam)) then
12131 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
12132 end if;
12134 -- Look for a rewritten subprogram renaming declaration
12136 if Nkind (Subp_Decl) = N_Subprogram_Declaration
12137 and then Present (Original_Node (Subp_Decl))
12138 then
12139 Orig_Node := Original_Node (Subp_Decl);
12140 end if;
12142 -- The rewritten subprogram is actually an entry
12144 if Present (Orig_Node)
12145 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
12146 and then Is_Entry (Name (Orig_Node))
12147 then
12148 return True;
12149 end if;
12151 return False;
12152 end Is_Renamed_Entry;
12154 ----------------------------
12155 -- Is_Reversible_Iterator --
12156 ----------------------------
12158 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
12159 Ifaces_List : Elist_Id;
12160 Iface_Elmt : Elmt_Id;
12161 Iface : Entity_Id;
12163 begin
12164 if Is_Class_Wide_Type (Typ)
12165 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
12166 and then Is_Predefined_File_Name
12167 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
12168 then
12169 return True;
12171 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
12172 return False;
12174 else
12175 Collect_Interfaces (Typ, Ifaces_List);
12177 Iface_Elmt := First_Elmt (Ifaces_List);
12178 while Present (Iface_Elmt) loop
12179 Iface := Node (Iface_Elmt);
12180 if Chars (Iface) = Name_Reversible_Iterator
12181 and then
12182 Is_Predefined_File_Name
12183 (Unit_File_Name (Get_Source_Unit (Iface)))
12184 then
12185 return True;
12186 end if;
12188 Next_Elmt (Iface_Elmt);
12189 end loop;
12190 end if;
12192 return False;
12193 end Is_Reversible_Iterator;
12195 ----------------------
12196 -- Is_Selector_Name --
12197 ----------------------
12199 function Is_Selector_Name (N : Node_Id) return Boolean is
12200 begin
12201 if not Is_List_Member (N) then
12202 declare
12203 P : constant Node_Id := Parent (N);
12204 begin
12205 return Nkind_In (P, N_Expanded_Name,
12206 N_Generic_Association,
12207 N_Parameter_Association,
12208 N_Selected_Component)
12209 and then Selector_Name (P) = N;
12210 end;
12212 else
12213 declare
12214 L : constant List_Id := List_Containing (N);
12215 P : constant Node_Id := Parent (L);
12216 begin
12217 return (Nkind (P) = N_Discriminant_Association
12218 and then Selector_Names (P) = L)
12219 or else
12220 (Nkind (P) = N_Component_Association
12221 and then Choices (P) = L);
12222 end;
12223 end if;
12224 end Is_Selector_Name;
12226 -------------------------------------
12227 -- Is_SPARK_05_Initialization_Expr --
12228 -------------------------------------
12230 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
12231 Is_Ok : Boolean;
12232 Expr : Node_Id;
12233 Comp_Assn : Node_Id;
12234 Orig_N : constant Node_Id := Original_Node (N);
12236 begin
12237 Is_Ok := True;
12239 if not Comes_From_Source (Orig_N) then
12240 goto Done;
12241 end if;
12243 pragma Assert (Nkind (Orig_N) in N_Subexpr);
12245 case Nkind (Orig_N) is
12246 when N_Character_Literal |
12247 N_Integer_Literal |
12248 N_Real_Literal |
12249 N_String_Literal =>
12250 null;
12252 when N_Identifier |
12253 N_Expanded_Name =>
12254 if Is_Entity_Name (Orig_N)
12255 and then Present (Entity (Orig_N)) -- needed in some cases
12256 then
12257 case Ekind (Entity (Orig_N)) is
12258 when E_Constant |
12259 E_Enumeration_Literal |
12260 E_Named_Integer |
12261 E_Named_Real =>
12262 null;
12263 when others =>
12264 if Is_Type (Entity (Orig_N)) then
12265 null;
12266 else
12267 Is_Ok := False;
12268 end if;
12269 end case;
12270 end if;
12272 when N_Qualified_Expression |
12273 N_Type_Conversion =>
12274 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
12276 when N_Unary_Op =>
12277 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12279 when N_Binary_Op |
12280 N_Short_Circuit |
12281 N_Membership_Test =>
12282 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
12283 and then
12284 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
12286 when N_Aggregate |
12287 N_Extension_Aggregate =>
12288 if Nkind (Orig_N) = N_Extension_Aggregate then
12289 Is_Ok :=
12290 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
12291 end if;
12293 Expr := First (Expressions (Orig_N));
12294 while Present (Expr) loop
12295 if not Is_SPARK_05_Initialization_Expr (Expr) then
12296 Is_Ok := False;
12297 goto Done;
12298 end if;
12300 Next (Expr);
12301 end loop;
12303 Comp_Assn := First (Component_Associations (Orig_N));
12304 while Present (Comp_Assn) loop
12305 Expr := Expression (Comp_Assn);
12307 -- Note: test for Present here needed for box assocation
12309 if Present (Expr)
12310 and then not Is_SPARK_05_Initialization_Expr (Expr)
12311 then
12312 Is_Ok := False;
12313 goto Done;
12314 end if;
12316 Next (Comp_Assn);
12317 end loop;
12319 when N_Attribute_Reference =>
12320 if Nkind (Prefix (Orig_N)) in N_Subexpr then
12321 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
12322 end if;
12324 Expr := First (Expressions (Orig_N));
12325 while Present (Expr) loop
12326 if not Is_SPARK_05_Initialization_Expr (Expr) then
12327 Is_Ok := False;
12328 goto Done;
12329 end if;
12331 Next (Expr);
12332 end loop;
12334 -- Selected components might be expanded named not yet resolved, so
12335 -- default on the safe side. (Eg on sparklex.ads)
12337 when N_Selected_Component =>
12338 null;
12340 when others =>
12341 Is_Ok := False;
12342 end case;
12344 <<Done>>
12345 return Is_Ok;
12346 end Is_SPARK_05_Initialization_Expr;
12348 ----------------------------------
12349 -- Is_SPARK_05_Object_Reference --
12350 ----------------------------------
12352 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
12353 begin
12354 if Is_Entity_Name (N) then
12355 return Present (Entity (N))
12356 and then
12357 (Ekind_In (Entity (N), E_Constant, E_Variable)
12358 or else Ekind (Entity (N)) in Formal_Kind);
12360 else
12361 case Nkind (N) is
12362 when N_Selected_Component =>
12363 return Is_SPARK_05_Object_Reference (Prefix (N));
12365 when others =>
12366 return False;
12367 end case;
12368 end if;
12369 end Is_SPARK_05_Object_Reference;
12371 -----------------------------
12372 -- Is_Specific_Tagged_Type --
12373 -----------------------------
12375 function Is_Specific_Tagged_Type (Typ : Entity_Id) return Boolean is
12376 Full_Typ : Entity_Id;
12378 begin
12379 -- Handle private types
12381 if Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
12382 Full_Typ := Full_View (Typ);
12383 else
12384 Full_Typ := Typ;
12385 end if;
12387 -- A specific tagged type is a non-class-wide tagged type
12389 return Is_Tagged_Type (Full_Typ) and not Is_Class_Wide_Type (Full_Typ);
12390 end Is_Specific_Tagged_Type;
12392 ------------------
12393 -- Is_Statement --
12394 ------------------
12396 function Is_Statement (N : Node_Id) return Boolean is
12397 begin
12398 return
12399 Nkind (N) in N_Statement_Other_Than_Procedure_Call
12400 or else Nkind (N) = N_Procedure_Call_Statement;
12401 end Is_Statement;
12403 -------------------------
12404 -- Is_Subject_To_Ghost --
12405 -------------------------
12407 function Is_Subject_To_Ghost (N : Node_Id) return Boolean is
12408 function Enables_Ghostness (Arg : Node_Id) return Boolean;
12409 -- Determine whether aspect or pragma argument Arg enables "ghostness"
12411 -----------------------
12412 -- Enables_Ghostness --
12413 -----------------------
12415 function Enables_Ghostness (Arg : Node_Id) return Boolean is
12416 Expr : Node_Id;
12418 begin
12419 Expr := Arg;
12421 if Nkind (Expr) = N_Pragma_Argument_Association then
12422 Expr := Get_Pragma_Arg (Expr);
12423 end if;
12425 -- Determine whether the expression of the aspect is static and
12426 -- denotes True.
12428 if Present (Expr) then
12429 Preanalyze_And_Resolve (Expr);
12431 return
12432 Is_OK_Static_Expression (Expr)
12433 and then Is_True (Expr_Value (Expr));
12435 -- Otherwise Ghost defaults to True
12437 else
12438 return True;
12439 end if;
12440 end Enables_Ghostness;
12442 -- Local variables
12444 Id : constant Entity_Id := Defining_Entity (N);
12445 Asp : Node_Id;
12446 Decl : Node_Id;
12447 Prev_Id : Entity_Id;
12449 -- Start of processing for Is_Subject_To_Ghost
12451 begin
12452 if Is_Ghost_Entity (Id) then
12453 return True;
12455 -- The completion of a type or a constant is not fully analyzed when the
12456 -- reference to the Ghost entity is resolved. Because the completion is
12457 -- not marked as Ghost yet, inspect the partial view.
12459 elsif Is_Record_Type (Id)
12460 or else Ekind (Id) = E_Constant
12461 or else (Nkind (N) = N_Object_Declaration
12462 and then Constant_Present (N))
12463 then
12464 Prev_Id := Incomplete_Or_Partial_View (Id);
12466 if Present (Prev_Id) and then Is_Ghost_Entity (Prev_Id) then
12467 return True;
12468 end if;
12469 end if;
12471 -- Examine the aspect specifications (if any) looking for aspect Ghost
12473 if Permits_Aspect_Specifications (N) then
12474 Asp := First (Aspect_Specifications (N));
12475 while Present (Asp) loop
12476 if Chars (Identifier (Asp)) = Name_Ghost then
12477 return Enables_Ghostness (Expression (Asp));
12478 end if;
12480 Next (Asp);
12481 end loop;
12482 end if;
12484 Decl := Empty;
12486 -- When the context is a [generic] package declaration, pragma Ghost
12487 -- resides in the visible declarations.
12489 if Nkind_In (N, N_Generic_Package_Declaration,
12490 N_Package_Declaration)
12491 then
12492 Decl := First (Visible_Declarations (Specification (N)));
12494 -- Otherwise pragma Ghost appears in the declarations following N
12496 elsif Is_List_Member (N) then
12497 Decl := Next (N);
12498 end if;
12500 while Present (Decl) loop
12501 if Nkind (Decl) = N_Pragma
12502 and then Pragma_Name (Decl) = Name_Ghost
12503 then
12504 return
12505 Enables_Ghostness (First (Pragma_Argument_Associations (Decl)));
12507 -- A source construct ends the region where pragma Ghost may appear,
12508 -- stop the traversal.
12510 elsif Comes_From_Source (Decl) then
12511 exit;
12512 end if;
12514 Next (Decl);
12515 end loop;
12517 return False;
12518 end Is_Subject_To_Ghost;
12520 --------------------------------------------------
12521 -- Is_Subprogram_Stub_Without_Prior_Declaration --
12522 --------------------------------------------------
12524 function Is_Subprogram_Stub_Without_Prior_Declaration
12525 (N : Node_Id) return Boolean
12527 begin
12528 -- A subprogram stub without prior declaration serves as declaration for
12529 -- the actual subprogram body. As such, it has an attached defining
12530 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
12532 return Nkind (N) = N_Subprogram_Body_Stub
12533 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
12534 end Is_Subprogram_Stub_Without_Prior_Declaration;
12536 ---------------------------------
12537 -- Is_Synchronized_Tagged_Type --
12538 ---------------------------------
12540 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
12541 Kind : constant Entity_Kind := Ekind (Base_Type (E));
12543 begin
12544 -- A task or protected type derived from an interface is a tagged type.
12545 -- Such a tagged type is called a synchronized tagged type, as are
12546 -- synchronized interfaces and private extensions whose declaration
12547 -- includes the reserved word synchronized.
12549 return (Is_Tagged_Type (E)
12550 and then (Kind = E_Task_Type
12551 or else
12552 Kind = E_Protected_Type))
12553 or else
12554 (Is_Interface (E)
12555 and then Is_Synchronized_Interface (E))
12556 or else
12557 (Ekind (E) = E_Record_Type_With_Private
12558 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
12559 and then (Synchronized_Present (Parent (E))
12560 or else Is_Synchronized_Interface (Etype (E))));
12561 end Is_Synchronized_Tagged_Type;
12563 -----------------
12564 -- Is_Transfer --
12565 -----------------
12567 function Is_Transfer (N : Node_Id) return Boolean is
12568 Kind : constant Node_Kind := Nkind (N);
12570 begin
12571 if Kind = N_Simple_Return_Statement
12572 or else
12573 Kind = N_Extended_Return_Statement
12574 or else
12575 Kind = N_Goto_Statement
12576 or else
12577 Kind = N_Raise_Statement
12578 or else
12579 Kind = N_Requeue_Statement
12580 then
12581 return True;
12583 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
12584 and then No (Condition (N))
12585 then
12586 return True;
12588 elsif Kind = N_Procedure_Call_Statement
12589 and then Is_Entity_Name (Name (N))
12590 and then Present (Entity (Name (N)))
12591 and then No_Return (Entity (Name (N)))
12592 then
12593 return True;
12595 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
12596 return True;
12598 else
12599 return False;
12600 end if;
12601 end Is_Transfer;
12603 -------------
12604 -- Is_True --
12605 -------------
12607 function Is_True (U : Uint) return Boolean is
12608 begin
12609 return (U /= 0);
12610 end Is_True;
12612 --------------------------------------
12613 -- Is_Unchecked_Conversion_Instance --
12614 --------------------------------------
12616 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
12617 Gen_Par : Entity_Id;
12619 begin
12620 -- Look for a function whose generic parent is the predefined intrinsic
12621 -- function Unchecked_Conversion.
12623 if Ekind (Id) = E_Function then
12624 Gen_Par := Generic_Parent (Parent (Id));
12626 return
12627 Present (Gen_Par)
12628 and then Chars (Gen_Par) = Name_Unchecked_Conversion
12629 and then Is_Intrinsic_Subprogram (Gen_Par)
12630 and then Is_Predefined_File_Name
12631 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
12632 end if;
12634 return False;
12635 end Is_Unchecked_Conversion_Instance;
12637 -------------------------------
12638 -- Is_Universal_Numeric_Type --
12639 -------------------------------
12641 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
12642 begin
12643 return T = Universal_Integer or else T = Universal_Real;
12644 end Is_Universal_Numeric_Type;
12646 -------------------
12647 -- Is_Value_Type --
12648 -------------------
12650 function Is_Value_Type (T : Entity_Id) return Boolean is
12651 begin
12652 return VM_Target = CLI_Target
12653 and then Nkind (T) in N_Has_Chars
12654 and then Chars (T) /= No_Name
12655 and then Get_Name_String (Chars (T)) = "valuetype";
12656 end Is_Value_Type;
12658 ----------------------------
12659 -- Is_Variable_Size_Array --
12660 ----------------------------
12662 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
12663 Idx : Node_Id;
12665 begin
12666 pragma Assert (Is_Array_Type (E));
12668 -- Check if some index is initialized with a non-constant value
12670 Idx := First_Index (E);
12671 while Present (Idx) loop
12672 if Nkind (Idx) = N_Range then
12673 if not Is_Constant_Bound (Low_Bound (Idx))
12674 or else not Is_Constant_Bound (High_Bound (Idx))
12675 then
12676 return True;
12677 end if;
12678 end if;
12680 Idx := Next_Index (Idx);
12681 end loop;
12683 return False;
12684 end Is_Variable_Size_Array;
12686 -----------------------------
12687 -- Is_Variable_Size_Record --
12688 -----------------------------
12690 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
12691 Comp : Entity_Id;
12692 Comp_Typ : Entity_Id;
12694 begin
12695 pragma Assert (Is_Record_Type (E));
12697 Comp := First_Entity (E);
12698 while Present (Comp) loop
12699 Comp_Typ := Etype (Comp);
12701 -- Recursive call if the record type has discriminants
12703 if Is_Record_Type (Comp_Typ)
12704 and then Has_Discriminants (Comp_Typ)
12705 and then Is_Variable_Size_Record (Comp_Typ)
12706 then
12707 return True;
12709 elsif Is_Array_Type (Comp_Typ)
12710 and then Is_Variable_Size_Array (Comp_Typ)
12711 then
12712 return True;
12713 end if;
12715 Next_Entity (Comp);
12716 end loop;
12718 return False;
12719 end Is_Variable_Size_Record;
12721 -----------------
12722 -- Is_Variable --
12723 -----------------
12725 function Is_Variable
12726 (N : Node_Id;
12727 Use_Original_Node : Boolean := True) return Boolean
12729 Orig_Node : Node_Id;
12731 function In_Protected_Function (E : Entity_Id) return Boolean;
12732 -- Within a protected function, the private components of the enclosing
12733 -- protected type are constants. A function nested within a (protected)
12734 -- procedure is not itself protected. Within the body of a protected
12735 -- function the current instance of the protected type is a constant.
12737 function Is_Variable_Prefix (P : Node_Id) return Boolean;
12738 -- Prefixes can involve implicit dereferences, in which case we must
12739 -- test for the case of a reference of a constant access type, which can
12740 -- can never be a variable.
12742 ---------------------------
12743 -- In_Protected_Function --
12744 ---------------------------
12746 function In_Protected_Function (E : Entity_Id) return Boolean is
12747 Prot : Entity_Id;
12748 S : Entity_Id;
12750 begin
12751 -- E is the current instance of a type
12753 if Is_Type (E) then
12754 Prot := E;
12756 -- E is an object
12758 else
12759 Prot := Scope (E);
12760 end if;
12762 if not Is_Protected_Type (Prot) then
12763 return False;
12765 else
12766 S := Current_Scope;
12767 while Present (S) and then S /= Prot loop
12768 if Ekind (S) = E_Function and then Scope (S) = Prot then
12769 return True;
12770 end if;
12772 S := Scope (S);
12773 end loop;
12775 return False;
12776 end if;
12777 end In_Protected_Function;
12779 ------------------------
12780 -- Is_Variable_Prefix --
12781 ------------------------
12783 function Is_Variable_Prefix (P : Node_Id) return Boolean is
12784 begin
12785 if Is_Access_Type (Etype (P)) then
12786 return not Is_Access_Constant (Root_Type (Etype (P)));
12788 -- For the case of an indexed component whose prefix has a packed
12789 -- array type, the prefix has been rewritten into a type conversion.
12790 -- Determine variable-ness from the converted expression.
12792 elsif Nkind (P) = N_Type_Conversion
12793 and then not Comes_From_Source (P)
12794 and then Is_Array_Type (Etype (P))
12795 and then Is_Packed (Etype (P))
12796 then
12797 return Is_Variable (Expression (P));
12799 else
12800 return Is_Variable (P);
12801 end if;
12802 end Is_Variable_Prefix;
12804 -- Start of processing for Is_Variable
12806 begin
12807 -- Check if we perform the test on the original node since this may be a
12808 -- test of syntactic categories which must not be disturbed by whatever
12809 -- rewriting might have occurred. For example, an aggregate, which is
12810 -- certainly NOT a variable, could be turned into a variable by
12811 -- expansion.
12813 if Use_Original_Node then
12814 Orig_Node := Original_Node (N);
12815 else
12816 Orig_Node := N;
12817 end if;
12819 -- Definitely OK if Assignment_OK is set. Since this is something that
12820 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12822 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
12823 return True;
12825 -- Normally we go to the original node, but there is one exception where
12826 -- we use the rewritten node, namely when it is an explicit dereference.
12827 -- The generated code may rewrite a prefix which is an access type with
12828 -- an explicit dereference. The dereference is a variable, even though
12829 -- the original node may not be (since it could be a constant of the
12830 -- access type).
12832 -- In Ada 2005 we have a further case to consider: the prefix may be a
12833 -- function call given in prefix notation. The original node appears to
12834 -- be a selected component, but we need to examine the call.
12836 elsif Nkind (N) = N_Explicit_Dereference
12837 and then Nkind (Orig_Node) /= N_Explicit_Dereference
12838 and then Present (Etype (Orig_Node))
12839 and then Is_Access_Type (Etype (Orig_Node))
12840 then
12841 -- Note that if the prefix is an explicit dereference that does not
12842 -- come from source, we must check for a rewritten function call in
12843 -- prefixed notation before other forms of rewriting, to prevent a
12844 -- compiler crash.
12846 return
12847 (Nkind (Orig_Node) = N_Function_Call
12848 and then not Is_Access_Constant (Etype (Prefix (N))))
12849 or else
12850 Is_Variable_Prefix (Original_Node (Prefix (N)));
12852 -- in Ada 2012, the dereference may have been added for a type with
12853 -- a declared implicit dereference aspect. Check that it is not an
12854 -- access to constant.
12856 elsif Nkind (N) = N_Explicit_Dereference
12857 and then Present (Etype (Orig_Node))
12858 and then Ada_Version >= Ada_2012
12859 and then Has_Implicit_Dereference (Etype (Orig_Node))
12860 and then not Is_Access_Constant (Etype (Prefix (N)))
12861 then
12862 return True;
12864 -- A function call is never a variable
12866 elsif Nkind (N) = N_Function_Call then
12867 return False;
12869 -- All remaining checks use the original node
12871 elsif Is_Entity_Name (Orig_Node)
12872 and then Present (Entity (Orig_Node))
12873 then
12874 declare
12875 E : constant Entity_Id := Entity (Orig_Node);
12876 K : constant Entity_Kind := Ekind (E);
12878 begin
12879 return (K = E_Variable
12880 and then Nkind (Parent (E)) /= N_Exception_Handler)
12881 or else (K = E_Component
12882 and then not In_Protected_Function (E))
12883 or else K = E_Out_Parameter
12884 or else K = E_In_Out_Parameter
12885 or else K = E_Generic_In_Out_Parameter
12887 -- Current instance of type. If this is a protected type, check
12888 -- we are not within the body of one of its protected functions.
12890 or else (Is_Type (E)
12891 and then In_Open_Scopes (E)
12892 and then not In_Protected_Function (E))
12894 or else (Is_Incomplete_Or_Private_Type (E)
12895 and then In_Open_Scopes (Full_View (E)));
12896 end;
12898 else
12899 case Nkind (Orig_Node) is
12900 when N_Indexed_Component | N_Slice =>
12901 return Is_Variable_Prefix (Prefix (Orig_Node));
12903 when N_Selected_Component =>
12904 return (Is_Variable (Selector_Name (Orig_Node))
12905 and then Is_Variable_Prefix (Prefix (Orig_Node)))
12906 or else
12907 (Nkind (N) = N_Expanded_Name
12908 and then Scope (Entity (N)) = Entity (Prefix (N)));
12910 -- For an explicit dereference, the type of the prefix cannot
12911 -- be an access to constant or an access to subprogram.
12913 when N_Explicit_Dereference =>
12914 declare
12915 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
12916 begin
12917 return Is_Access_Type (Typ)
12918 and then not Is_Access_Constant (Root_Type (Typ))
12919 and then Ekind (Typ) /= E_Access_Subprogram_Type;
12920 end;
12922 -- The type conversion is the case where we do not deal with the
12923 -- context dependent special case of an actual parameter. Thus
12924 -- the type conversion is only considered a variable for the
12925 -- purposes of this routine if the target type is tagged. However,
12926 -- a type conversion is considered to be a variable if it does not
12927 -- come from source (this deals for example with the conversions
12928 -- of expressions to their actual subtypes).
12930 when N_Type_Conversion =>
12931 return Is_Variable (Expression (Orig_Node))
12932 and then
12933 (not Comes_From_Source (Orig_Node)
12934 or else
12935 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
12936 and then
12937 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
12939 -- GNAT allows an unchecked type conversion as a variable. This
12940 -- only affects the generation of internal expanded code, since
12941 -- calls to instantiations of Unchecked_Conversion are never
12942 -- considered variables (since they are function calls).
12944 when N_Unchecked_Type_Conversion =>
12945 return Is_Variable (Expression (Orig_Node));
12947 when others =>
12948 return False;
12949 end case;
12950 end if;
12951 end Is_Variable;
12953 ---------------------------
12954 -- Is_Visibly_Controlled --
12955 ---------------------------
12957 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
12958 Root : constant Entity_Id := Root_Type (T);
12959 begin
12960 return Chars (Scope (Root)) = Name_Finalization
12961 and then Chars (Scope (Scope (Root))) = Name_Ada
12962 and then Scope (Scope (Scope (Root))) = Standard_Standard;
12963 end Is_Visibly_Controlled;
12965 ------------------------
12966 -- Is_Volatile_Object --
12967 ------------------------
12969 function Is_Volatile_Object (N : Node_Id) return Boolean is
12971 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
12972 -- If prefix is an implicit dereference, examine designated type
12974 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
12975 -- Determines if given object has volatile components
12977 ------------------------
12978 -- Is_Volatile_Prefix --
12979 ------------------------
12981 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
12982 Typ : constant Entity_Id := Etype (N);
12984 begin
12985 if Is_Access_Type (Typ) then
12986 declare
12987 Dtyp : constant Entity_Id := Designated_Type (Typ);
12989 begin
12990 return Is_Volatile (Dtyp)
12991 or else Has_Volatile_Components (Dtyp);
12992 end;
12994 else
12995 return Object_Has_Volatile_Components (N);
12996 end if;
12997 end Is_Volatile_Prefix;
12999 ------------------------------------
13000 -- Object_Has_Volatile_Components --
13001 ------------------------------------
13003 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
13004 Typ : constant Entity_Id := Etype (N);
13006 begin
13007 if Is_Volatile (Typ)
13008 or else Has_Volatile_Components (Typ)
13009 then
13010 return True;
13012 elsif Is_Entity_Name (N)
13013 and then (Has_Volatile_Components (Entity (N))
13014 or else Is_Volatile (Entity (N)))
13015 then
13016 return True;
13018 elsif Nkind (N) = N_Indexed_Component
13019 or else Nkind (N) = N_Selected_Component
13020 then
13021 return Is_Volatile_Prefix (Prefix (N));
13023 else
13024 return False;
13025 end if;
13026 end Object_Has_Volatile_Components;
13028 -- Start of processing for Is_Volatile_Object
13030 begin
13031 if Nkind (N) = N_Defining_Identifier then
13032 return Is_Volatile (N) or else Is_Volatile (Etype (N));
13034 elsif Nkind (N) = N_Expanded_Name then
13035 return Is_Volatile_Object (Entity (N));
13037 elsif Is_Volatile (Etype (N))
13038 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
13039 then
13040 return True;
13042 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
13043 and then Is_Volatile_Prefix (Prefix (N))
13044 then
13045 return True;
13047 elsif Nkind (N) = N_Selected_Component
13048 and then Is_Volatile (Entity (Selector_Name (N)))
13049 then
13050 return True;
13052 else
13053 return False;
13054 end if;
13055 end Is_Volatile_Object;
13057 ---------------------------
13058 -- Itype_Has_Declaration --
13059 ---------------------------
13061 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
13062 begin
13063 pragma Assert (Is_Itype (Id));
13064 return Present (Parent (Id))
13065 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
13066 N_Subtype_Declaration)
13067 and then Defining_Entity (Parent (Id)) = Id;
13068 end Itype_Has_Declaration;
13070 -------------------------
13071 -- Kill_Current_Values --
13072 -------------------------
13074 procedure Kill_Current_Values
13075 (Ent : Entity_Id;
13076 Last_Assignment_Only : Boolean := False)
13078 begin
13079 if Is_Assignable (Ent) then
13080 Set_Last_Assignment (Ent, Empty);
13081 end if;
13083 if Is_Object (Ent) then
13084 if not Last_Assignment_Only then
13085 Kill_Checks (Ent);
13086 Set_Current_Value (Ent, Empty);
13088 if not Can_Never_Be_Null (Ent) then
13089 Set_Is_Known_Non_Null (Ent, False);
13090 end if;
13092 Set_Is_Known_Null (Ent, False);
13094 -- Reset Is_Known_Valid unless type is always valid, or if we have
13095 -- a loop parameter (loop parameters are always valid, since their
13096 -- bounds are defined by the bounds given in the loop header).
13098 if not Is_Known_Valid (Etype (Ent))
13099 and then Ekind (Ent) /= E_Loop_Parameter
13100 then
13101 Set_Is_Known_Valid (Ent, False);
13102 end if;
13103 end if;
13104 end if;
13105 end Kill_Current_Values;
13107 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
13108 S : Entity_Id;
13110 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
13111 -- Clear current value for entity E and all entities chained to E
13113 ------------------------------------------
13114 -- Kill_Current_Values_For_Entity_Chain --
13115 ------------------------------------------
13117 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
13118 Ent : Entity_Id;
13119 begin
13120 Ent := E;
13121 while Present (Ent) loop
13122 Kill_Current_Values (Ent, Last_Assignment_Only);
13123 Next_Entity (Ent);
13124 end loop;
13125 end Kill_Current_Values_For_Entity_Chain;
13127 -- Start of processing for Kill_Current_Values
13129 begin
13130 -- Kill all saved checks, a special case of killing saved values
13132 if not Last_Assignment_Only then
13133 Kill_All_Checks;
13134 end if;
13136 -- Loop through relevant scopes, which includes the current scope and
13137 -- any parent scopes if the current scope is a block or a package.
13139 S := Current_Scope;
13140 Scope_Loop : loop
13142 -- Clear current values of all entities in current scope
13144 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
13146 -- If scope is a package, also clear current values of all private
13147 -- entities in the scope.
13149 if Is_Package_Or_Generic_Package (S)
13150 or else Is_Concurrent_Type (S)
13151 then
13152 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
13153 end if;
13155 -- If this is a not a subprogram, deal with parents
13157 if not Is_Subprogram (S) then
13158 S := Scope (S);
13159 exit Scope_Loop when S = Standard_Standard;
13160 else
13161 exit Scope_Loop;
13162 end if;
13163 end loop Scope_Loop;
13164 end Kill_Current_Values;
13166 --------------------------
13167 -- Kill_Size_Check_Code --
13168 --------------------------
13170 procedure Kill_Size_Check_Code (E : Entity_Id) is
13171 begin
13172 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
13173 and then Present (Size_Check_Code (E))
13174 then
13175 Remove (Size_Check_Code (E));
13176 Set_Size_Check_Code (E, Empty);
13177 end if;
13178 end Kill_Size_Check_Code;
13180 --------------------------
13181 -- Known_To_Be_Assigned --
13182 --------------------------
13184 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
13185 P : constant Node_Id := Parent (N);
13187 begin
13188 case Nkind (P) is
13190 -- Test left side of assignment
13192 when N_Assignment_Statement =>
13193 return N = Name (P);
13195 -- Function call arguments are never lvalues
13197 when N_Function_Call =>
13198 return False;
13200 -- Positional parameter for procedure or accept call
13202 when N_Procedure_Call_Statement |
13203 N_Accept_Statement
13205 declare
13206 Proc : Entity_Id;
13207 Form : Entity_Id;
13208 Act : Node_Id;
13210 begin
13211 Proc := Get_Subprogram_Entity (P);
13213 if No (Proc) then
13214 return False;
13215 end if;
13217 -- If we are not a list member, something is strange, so
13218 -- be conservative and return False.
13220 if not Is_List_Member (N) then
13221 return False;
13222 end if;
13224 -- We are going to find the right formal by stepping forward
13225 -- through the formals, as we step backwards in the actuals.
13227 Form := First_Formal (Proc);
13228 Act := N;
13229 loop
13230 -- If no formal, something is weird, so be conservative
13231 -- and return False.
13233 if No (Form) then
13234 return False;
13235 end if;
13237 Prev (Act);
13238 exit when No (Act);
13239 Next_Formal (Form);
13240 end loop;
13242 return Ekind (Form) /= E_In_Parameter;
13243 end;
13245 -- Named parameter for procedure or accept call
13247 when N_Parameter_Association =>
13248 declare
13249 Proc : Entity_Id;
13250 Form : Entity_Id;
13252 begin
13253 Proc := Get_Subprogram_Entity (Parent (P));
13255 if No (Proc) then
13256 return False;
13257 end if;
13259 -- Loop through formals to find the one that matches
13261 Form := First_Formal (Proc);
13262 loop
13263 -- If no matching formal, that's peculiar, some kind of
13264 -- previous error, so return False to be conservative.
13265 -- Actually this also happens in legal code in the case
13266 -- where P is a parameter association for an Extra_Formal???
13268 if No (Form) then
13269 return False;
13270 end if;
13272 -- Else test for match
13274 if Chars (Form) = Chars (Selector_Name (P)) then
13275 return Ekind (Form) /= E_In_Parameter;
13276 end if;
13278 Next_Formal (Form);
13279 end loop;
13280 end;
13282 -- Test for appearing in a conversion that itself appears
13283 -- in an lvalue context, since this should be an lvalue.
13285 when N_Type_Conversion =>
13286 return Known_To_Be_Assigned (P);
13288 -- All other references are definitely not known to be modifications
13290 when others =>
13291 return False;
13293 end case;
13294 end Known_To_Be_Assigned;
13296 ---------------------------
13297 -- Last_Source_Statement --
13298 ---------------------------
13300 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
13301 N : Node_Id;
13303 begin
13304 N := Last (Statements (HSS));
13305 while Present (N) loop
13306 exit when Comes_From_Source (N);
13307 Prev (N);
13308 end loop;
13310 return N;
13311 end Last_Source_Statement;
13313 ----------------------------------
13314 -- Matching_Static_Array_Bounds --
13315 ----------------------------------
13317 function Matching_Static_Array_Bounds
13318 (L_Typ : Node_Id;
13319 R_Typ : Node_Id) return Boolean
13321 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
13322 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
13324 L_Index : Node_Id;
13325 R_Index : Node_Id;
13326 L_Low : Node_Id;
13327 L_High : Node_Id;
13328 L_Len : Uint;
13329 R_Low : Node_Id;
13330 R_High : Node_Id;
13331 R_Len : Uint;
13333 begin
13334 if L_Ndims /= R_Ndims then
13335 return False;
13336 end if;
13338 -- Unconstrained types do not have static bounds
13340 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
13341 return False;
13342 end if;
13344 -- First treat specially the first dimension, as the lower bound and
13345 -- length of string literals are not stored like those of arrays.
13347 if Ekind (L_Typ) = E_String_Literal_Subtype then
13348 L_Low := String_Literal_Low_Bound (L_Typ);
13349 L_Len := String_Literal_Length (L_Typ);
13350 else
13351 L_Index := First_Index (L_Typ);
13352 Get_Index_Bounds (L_Index, L_Low, L_High);
13354 if Is_OK_Static_Expression (L_Low)
13355 and then
13356 Is_OK_Static_Expression (L_High)
13357 then
13358 if Expr_Value (L_High) < Expr_Value (L_Low) then
13359 L_Len := Uint_0;
13360 else
13361 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
13362 end if;
13363 else
13364 return False;
13365 end if;
13366 end if;
13368 if Ekind (R_Typ) = E_String_Literal_Subtype then
13369 R_Low := String_Literal_Low_Bound (R_Typ);
13370 R_Len := String_Literal_Length (R_Typ);
13371 else
13372 R_Index := First_Index (R_Typ);
13373 Get_Index_Bounds (R_Index, R_Low, R_High);
13375 if Is_OK_Static_Expression (R_Low)
13376 and then
13377 Is_OK_Static_Expression (R_High)
13378 then
13379 if Expr_Value (R_High) < Expr_Value (R_Low) then
13380 R_Len := Uint_0;
13381 else
13382 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
13383 end if;
13384 else
13385 return False;
13386 end if;
13387 end if;
13389 if (Is_OK_Static_Expression (L_Low)
13390 and then
13391 Is_OK_Static_Expression (R_Low))
13392 and then Expr_Value (L_Low) = Expr_Value (R_Low)
13393 and then L_Len = R_Len
13394 then
13395 null;
13396 else
13397 return False;
13398 end if;
13400 -- Then treat all other dimensions
13402 for Indx in 2 .. L_Ndims loop
13403 Next (L_Index);
13404 Next (R_Index);
13406 Get_Index_Bounds (L_Index, L_Low, L_High);
13407 Get_Index_Bounds (R_Index, R_Low, R_High);
13409 if (Is_OK_Static_Expression (L_Low) and then
13410 Is_OK_Static_Expression (L_High) and then
13411 Is_OK_Static_Expression (R_Low) and then
13412 Is_OK_Static_Expression (R_High))
13413 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
13414 and then
13415 Expr_Value (L_High) = Expr_Value (R_High))
13416 then
13417 null;
13418 else
13419 return False;
13420 end if;
13421 end loop;
13423 -- If we fall through the loop, all indexes matched
13425 return True;
13426 end Matching_Static_Array_Bounds;
13428 -------------------
13429 -- May_Be_Lvalue --
13430 -------------------
13432 function May_Be_Lvalue (N : Node_Id) return Boolean is
13433 P : constant Node_Id := Parent (N);
13435 begin
13436 case Nkind (P) is
13438 -- Test left side of assignment
13440 when N_Assignment_Statement =>
13441 return N = Name (P);
13443 -- Test prefix of component or attribute. Note that the prefix of an
13444 -- explicit or implicit dereference cannot be an l-value.
13446 when N_Attribute_Reference =>
13447 return N = Prefix (P)
13448 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
13450 -- For an expanded name, the name is an lvalue if the expanded name
13451 -- is an lvalue, but the prefix is never an lvalue, since it is just
13452 -- the scope where the name is found.
13454 when N_Expanded_Name =>
13455 if N = Prefix (P) then
13456 return May_Be_Lvalue (P);
13457 else
13458 return False;
13459 end if;
13461 -- For a selected component A.B, A is certainly an lvalue if A.B is.
13462 -- B is a little interesting, if we have A.B := 3, there is some
13463 -- discussion as to whether B is an lvalue or not, we choose to say
13464 -- it is. Note however that A is not an lvalue if it is of an access
13465 -- type since this is an implicit dereference.
13467 when N_Selected_Component =>
13468 if N = Prefix (P)
13469 and then Present (Etype (N))
13470 and then Is_Access_Type (Etype (N))
13471 then
13472 return False;
13473 else
13474 return May_Be_Lvalue (P);
13475 end if;
13477 -- For an indexed component or slice, the index or slice bounds is
13478 -- never an lvalue. The prefix is an lvalue if the indexed component
13479 -- or slice is an lvalue, except if it is an access type, where we
13480 -- have an implicit dereference.
13482 when N_Indexed_Component | N_Slice =>
13483 if N /= Prefix (P)
13484 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
13485 then
13486 return False;
13487 else
13488 return May_Be_Lvalue (P);
13489 end if;
13491 -- Prefix of a reference is an lvalue if the reference is an lvalue
13493 when N_Reference =>
13494 return May_Be_Lvalue (P);
13496 -- Prefix of explicit dereference is never an lvalue
13498 when N_Explicit_Dereference =>
13499 return False;
13501 -- Positional parameter for subprogram, entry, or accept call.
13502 -- In older versions of Ada function call arguments are never
13503 -- lvalues. In Ada 2012 functions can have in-out parameters.
13505 when N_Subprogram_Call |
13506 N_Entry_Call_Statement |
13507 N_Accept_Statement
13509 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
13510 return False;
13511 end if;
13513 -- The following mechanism is clumsy and fragile. A single flag
13514 -- set in Resolve_Actuals would be preferable ???
13516 declare
13517 Proc : Entity_Id;
13518 Form : Entity_Id;
13519 Act : Node_Id;
13521 begin
13522 Proc := Get_Subprogram_Entity (P);
13524 if No (Proc) then
13525 return True;
13526 end if;
13528 -- If we are not a list member, something is strange, so be
13529 -- conservative and return True.
13531 if not Is_List_Member (N) then
13532 return True;
13533 end if;
13535 -- We are going to find the right formal by stepping forward
13536 -- through the formals, as we step backwards in the actuals.
13538 Form := First_Formal (Proc);
13539 Act := N;
13540 loop
13541 -- If no formal, something is weird, so be conservative and
13542 -- return True.
13544 if No (Form) then
13545 return True;
13546 end if;
13548 Prev (Act);
13549 exit when No (Act);
13550 Next_Formal (Form);
13551 end loop;
13553 return Ekind (Form) /= E_In_Parameter;
13554 end;
13556 -- Named parameter for procedure or accept call
13558 when N_Parameter_Association =>
13559 declare
13560 Proc : Entity_Id;
13561 Form : Entity_Id;
13563 begin
13564 Proc := Get_Subprogram_Entity (Parent (P));
13566 if No (Proc) then
13567 return True;
13568 end if;
13570 -- Loop through formals to find the one that matches
13572 Form := First_Formal (Proc);
13573 loop
13574 -- If no matching formal, that's peculiar, some kind of
13575 -- previous error, so return True to be conservative.
13576 -- Actually happens with legal code for an unresolved call
13577 -- where we may get the wrong homonym???
13579 if No (Form) then
13580 return True;
13581 end if;
13583 -- Else test for match
13585 if Chars (Form) = Chars (Selector_Name (P)) then
13586 return Ekind (Form) /= E_In_Parameter;
13587 end if;
13589 Next_Formal (Form);
13590 end loop;
13591 end;
13593 -- Test for appearing in a conversion that itself appears in an
13594 -- lvalue context, since this should be an lvalue.
13596 when N_Type_Conversion =>
13597 return May_Be_Lvalue (P);
13599 -- Test for appearance in object renaming declaration
13601 when N_Object_Renaming_Declaration =>
13602 return True;
13604 -- All other references are definitely not lvalues
13606 when others =>
13607 return False;
13609 end case;
13610 end May_Be_Lvalue;
13612 -----------------------
13613 -- Mark_Coextensions --
13614 -----------------------
13616 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
13617 Is_Dynamic : Boolean;
13618 -- Indicates whether the context causes nested coextensions to be
13619 -- dynamic or static
13621 function Mark_Allocator (N : Node_Id) return Traverse_Result;
13622 -- Recognize an allocator node and label it as a dynamic coextension
13624 --------------------
13625 -- Mark_Allocator --
13626 --------------------
13628 function Mark_Allocator (N : Node_Id) return Traverse_Result is
13629 begin
13630 if Nkind (N) = N_Allocator then
13631 if Is_Dynamic then
13632 Set_Is_Dynamic_Coextension (N);
13634 -- If the allocator expression is potentially dynamic, it may
13635 -- be expanded out of order and require dynamic allocation
13636 -- anyway, so we treat the coextension itself as dynamic.
13637 -- Potential optimization ???
13639 elsif Nkind (Expression (N)) = N_Qualified_Expression
13640 and then Nkind (Expression (Expression (N))) = N_Op_Concat
13641 then
13642 Set_Is_Dynamic_Coextension (N);
13643 else
13644 Set_Is_Static_Coextension (N);
13645 end if;
13646 end if;
13648 return OK;
13649 end Mark_Allocator;
13651 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
13653 -- Start of processing Mark_Coextensions
13655 begin
13656 case Nkind (Context_Nod) is
13658 -- Comment here ???
13660 when N_Assignment_Statement =>
13661 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
13663 -- An allocator that is a component of a returned aggregate
13664 -- must be dynamic.
13666 when N_Simple_Return_Statement =>
13667 declare
13668 Expr : constant Node_Id := Expression (Context_Nod);
13669 begin
13670 Is_Dynamic :=
13671 Nkind (Expr) = N_Allocator
13672 or else
13673 (Nkind (Expr) = N_Qualified_Expression
13674 and then Nkind (Expression (Expr)) = N_Aggregate);
13675 end;
13677 -- An alloctor within an object declaration in an extended return
13678 -- statement is of necessity dynamic.
13680 when N_Object_Declaration =>
13681 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
13682 or else
13683 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
13685 -- This routine should not be called for constructs which may not
13686 -- contain coextensions.
13688 when others =>
13689 raise Program_Error;
13690 end case;
13692 Mark_Allocators (Root_Nod);
13693 end Mark_Coextensions;
13695 ----------------------
13696 -- Needs_One_Actual --
13697 ----------------------
13699 function Needs_One_Actual (E : Entity_Id) return Boolean is
13700 Formal : Entity_Id;
13702 begin
13703 -- Ada 2005 or later, and formals present
13705 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
13706 Formal := Next_Formal (First_Formal (E));
13707 while Present (Formal) loop
13708 if No (Default_Value (Formal)) then
13709 return False;
13710 end if;
13712 Next_Formal (Formal);
13713 end loop;
13715 return True;
13717 -- Ada 83/95 or no formals
13719 else
13720 return False;
13721 end if;
13722 end Needs_One_Actual;
13724 ------------------------
13725 -- New_Copy_List_Tree --
13726 ------------------------
13728 function New_Copy_List_Tree (List : List_Id) return List_Id is
13729 NL : List_Id;
13730 E : Node_Id;
13732 begin
13733 if List = No_List then
13734 return No_List;
13736 else
13737 NL := New_List;
13738 E := First (List);
13740 while Present (E) loop
13741 Append (New_Copy_Tree (E), NL);
13742 E := Next (E);
13743 end loop;
13745 return NL;
13746 end if;
13747 end New_Copy_List_Tree;
13749 --------------------------------------------------
13750 -- New_Copy_Tree Auxiliary Data and Subprograms --
13751 --------------------------------------------------
13753 use Atree.Unchecked_Access;
13754 use Atree_Private_Part;
13756 -- Our approach here requires a two pass traversal of the tree. The
13757 -- first pass visits all nodes that eventually will be copied looking
13758 -- for defining Itypes. If any defining Itypes are found, then they are
13759 -- copied, and an entry is added to the replacement map. In the second
13760 -- phase, the tree is copied, using the replacement map to replace any
13761 -- Itype references within the copied tree.
13763 -- The following hash tables are used if the Map supplied has more
13764 -- than hash threshold entries to speed up access to the map. If
13765 -- there are fewer entries, then the map is searched sequentially
13766 -- (because setting up a hash table for only a few entries takes
13767 -- more time than it saves.
13769 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
13770 -- Hash function used for hash operations
13772 -------------------
13773 -- New_Copy_Hash --
13774 -------------------
13776 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
13777 begin
13778 return Nat (E) mod (NCT_Header_Num'Last + 1);
13779 end New_Copy_Hash;
13781 ---------------
13782 -- NCT_Assoc --
13783 ---------------
13785 -- The hash table NCT_Assoc associates old entities in the table
13786 -- with their corresponding new entities (i.e. the pairs of entries
13787 -- presented in the original Map argument are Key-Element pairs).
13789 package NCT_Assoc is new Simple_HTable (
13790 Header_Num => NCT_Header_Num,
13791 Element => Entity_Id,
13792 No_Element => Empty,
13793 Key => Entity_Id,
13794 Hash => New_Copy_Hash,
13795 Equal => Types."=");
13797 ---------------------
13798 -- NCT_Itype_Assoc --
13799 ---------------------
13801 -- The hash table NCT_Itype_Assoc contains entries only for those
13802 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13803 -- The key is the associated node, and the element is the new node
13804 -- itself (NOT the associated node for the new node).
13806 package NCT_Itype_Assoc is new Simple_HTable (
13807 Header_Num => NCT_Header_Num,
13808 Element => Entity_Id,
13809 No_Element => Empty,
13810 Key => Entity_Id,
13811 Hash => New_Copy_Hash,
13812 Equal => Types."=");
13814 -------------------
13815 -- New_Copy_Tree --
13816 -------------------
13818 function New_Copy_Tree
13819 (Source : Node_Id;
13820 Map : Elist_Id := No_Elist;
13821 New_Sloc : Source_Ptr := No_Location;
13822 New_Scope : Entity_Id := Empty) return Node_Id
13824 Actual_Map : Elist_Id := Map;
13825 -- This is the actual map for the copy. It is initialized with the
13826 -- given elements, and then enlarged as required for Itypes that are
13827 -- copied during the first phase of the copy operation. The visit
13828 -- procedures add elements to this map as Itypes are encountered.
13829 -- The reason we cannot use Map directly, is that it may well be
13830 -- (and normally is) initialized to No_Elist, and if we have mapped
13831 -- entities, we have to reset it to point to a real Elist.
13833 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
13834 -- Called during second phase to map entities into their corresponding
13835 -- copies using Actual_Map. If the argument is not an entity, or is not
13836 -- in Actual_Map, then it is returned unchanged.
13838 procedure Build_NCT_Hash_Tables;
13839 -- Builds hash tables (number of elements >= threshold value)
13841 function Copy_Elist_With_Replacement
13842 (Old_Elist : Elist_Id) return Elist_Id;
13843 -- Called during second phase to copy element list doing replacements
13845 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
13846 -- Called during the second phase to process a copied Itype. The actual
13847 -- copy happened during the first phase (so that we could make the entry
13848 -- in the mapping), but we still have to deal with the descendents of
13849 -- the copied Itype and copy them where necessary.
13851 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
13852 -- Called during second phase to copy list doing replacements
13854 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
13855 -- Called during second phase to copy node doing replacements
13857 procedure Visit_Elist (E : Elist_Id);
13858 -- Called during first phase to visit all elements of an Elist
13860 procedure Visit_Field (F : Union_Id; N : Node_Id);
13861 -- Visit a single field, recursing to call Visit_Node or Visit_List
13862 -- if the field is a syntactic descendent of the current node (i.e.
13863 -- its parent is Node N).
13865 procedure Visit_Itype (Old_Itype : Entity_Id);
13866 -- Called during first phase to visit subsidiary fields of a defining
13867 -- Itype, and also create a copy and make an entry in the replacement
13868 -- map for the new copy.
13870 procedure Visit_List (L : List_Id);
13871 -- Called during first phase to visit all elements of a List
13873 procedure Visit_Node (N : Node_Or_Entity_Id);
13874 -- Called during first phase to visit a node and all its subtrees
13876 -----------
13877 -- Assoc --
13878 -----------
13880 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
13881 E : Elmt_Id;
13882 Ent : Entity_Id;
13884 begin
13885 if not Has_Extension (N) or else No (Actual_Map) then
13886 return N;
13888 elsif NCT_Hash_Tables_Used then
13889 Ent := NCT_Assoc.Get (Entity_Id (N));
13891 if Present (Ent) then
13892 return Ent;
13893 else
13894 return N;
13895 end if;
13897 -- No hash table used, do serial search
13899 else
13900 E := First_Elmt (Actual_Map);
13901 while Present (E) loop
13902 if Node (E) = N then
13903 return Node (Next_Elmt (E));
13904 else
13905 E := Next_Elmt (Next_Elmt (E));
13906 end if;
13907 end loop;
13908 end if;
13910 return N;
13911 end Assoc;
13913 ---------------------------
13914 -- Build_NCT_Hash_Tables --
13915 ---------------------------
13917 procedure Build_NCT_Hash_Tables is
13918 Elmt : Elmt_Id;
13919 Ent : Entity_Id;
13920 begin
13921 if NCT_Hash_Table_Setup then
13922 NCT_Assoc.Reset;
13923 NCT_Itype_Assoc.Reset;
13924 end if;
13926 Elmt := First_Elmt (Actual_Map);
13927 while Present (Elmt) loop
13928 Ent := Node (Elmt);
13930 -- Get new entity, and associate old and new
13932 Next_Elmt (Elmt);
13933 NCT_Assoc.Set (Ent, Node (Elmt));
13935 if Is_Type (Ent) then
13936 declare
13937 Anode : constant Entity_Id :=
13938 Associated_Node_For_Itype (Ent);
13940 begin
13941 if Present (Anode) then
13943 -- Enter a link between the associated node of the
13944 -- old Itype and the new Itype, for updating later
13945 -- when node is copied.
13947 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
13948 end if;
13949 end;
13950 end if;
13952 Next_Elmt (Elmt);
13953 end loop;
13955 NCT_Hash_Tables_Used := True;
13956 NCT_Hash_Table_Setup := True;
13957 end Build_NCT_Hash_Tables;
13959 ---------------------------------
13960 -- Copy_Elist_With_Replacement --
13961 ---------------------------------
13963 function Copy_Elist_With_Replacement
13964 (Old_Elist : Elist_Id) return Elist_Id
13966 M : Elmt_Id;
13967 New_Elist : Elist_Id;
13969 begin
13970 if No (Old_Elist) then
13971 return No_Elist;
13973 else
13974 New_Elist := New_Elmt_List;
13976 M := First_Elmt (Old_Elist);
13977 while Present (M) loop
13978 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
13979 Next_Elmt (M);
13980 end loop;
13981 end if;
13983 return New_Elist;
13984 end Copy_Elist_With_Replacement;
13986 ---------------------------------
13987 -- Copy_Itype_With_Replacement --
13988 ---------------------------------
13990 -- This routine exactly parallels its phase one analog Visit_Itype,
13992 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
13993 begin
13994 -- Translate Next_Entity, Scope and Etype fields, in case they
13995 -- reference entities that have been mapped into copies.
13997 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
13998 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
14000 if Present (New_Scope) then
14001 Set_Scope (New_Itype, New_Scope);
14002 else
14003 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
14004 end if;
14006 -- Copy referenced fields
14008 if Is_Discrete_Type (New_Itype) then
14009 Set_Scalar_Range (New_Itype,
14010 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
14012 elsif Has_Discriminants (Base_Type (New_Itype)) then
14013 Set_Discriminant_Constraint (New_Itype,
14014 Copy_Elist_With_Replacement
14015 (Discriminant_Constraint (New_Itype)));
14017 elsif Is_Array_Type (New_Itype) then
14018 if Present (First_Index (New_Itype)) then
14019 Set_First_Index (New_Itype,
14020 First (Copy_List_With_Replacement
14021 (List_Containing (First_Index (New_Itype)))));
14022 end if;
14024 if Is_Packed (New_Itype) then
14025 Set_Packed_Array_Impl_Type (New_Itype,
14026 Copy_Node_With_Replacement
14027 (Packed_Array_Impl_Type (New_Itype)));
14028 end if;
14029 end if;
14030 end Copy_Itype_With_Replacement;
14032 --------------------------------
14033 -- Copy_List_With_Replacement --
14034 --------------------------------
14036 function Copy_List_With_Replacement
14037 (Old_List : List_Id) return List_Id
14039 New_List : List_Id;
14040 E : Node_Id;
14042 begin
14043 if Old_List = No_List then
14044 return No_List;
14046 else
14047 New_List := Empty_List;
14049 E := First (Old_List);
14050 while Present (E) loop
14051 Append (Copy_Node_With_Replacement (E), New_List);
14052 Next (E);
14053 end loop;
14055 return New_List;
14056 end if;
14057 end Copy_List_With_Replacement;
14059 --------------------------------
14060 -- Copy_Node_With_Replacement --
14061 --------------------------------
14063 function Copy_Node_With_Replacement
14064 (Old_Node : Node_Id) return Node_Id
14066 New_Node : Node_Id;
14068 procedure Adjust_Named_Associations
14069 (Old_Node : Node_Id;
14070 New_Node : Node_Id);
14071 -- If a call node has named associations, these are chained through
14072 -- the First_Named_Actual, Next_Named_Actual links. These must be
14073 -- propagated separately to the new parameter list, because these
14074 -- are not syntactic fields.
14076 function Copy_Field_With_Replacement
14077 (Field : Union_Id) return Union_Id;
14078 -- Given Field, which is a field of Old_Node, return a copy of it
14079 -- if it is a syntactic field (i.e. its parent is Node), setting
14080 -- the parent of the copy to poit to New_Node. Otherwise returns
14081 -- the field (possibly mapped if it is an entity).
14083 -------------------------------
14084 -- Adjust_Named_Associations --
14085 -------------------------------
14087 procedure Adjust_Named_Associations
14088 (Old_Node : Node_Id;
14089 New_Node : Node_Id)
14091 Old_E : Node_Id;
14092 New_E : Node_Id;
14094 Old_Next : Node_Id;
14095 New_Next : Node_Id;
14097 begin
14098 Old_E := First (Parameter_Associations (Old_Node));
14099 New_E := First (Parameter_Associations (New_Node));
14100 while Present (Old_E) loop
14101 if Nkind (Old_E) = N_Parameter_Association
14102 and then Present (Next_Named_Actual (Old_E))
14103 then
14104 if First_Named_Actual (Old_Node)
14105 = Explicit_Actual_Parameter (Old_E)
14106 then
14107 Set_First_Named_Actual
14108 (New_Node, Explicit_Actual_Parameter (New_E));
14109 end if;
14111 -- Now scan parameter list from the beginning,to locate
14112 -- next named actual, which can be out of order.
14114 Old_Next := First (Parameter_Associations (Old_Node));
14115 New_Next := First (Parameter_Associations (New_Node));
14117 while Nkind (Old_Next) /= N_Parameter_Association
14118 or else Explicit_Actual_Parameter (Old_Next)
14119 /= Next_Named_Actual (Old_E)
14120 loop
14121 Next (Old_Next);
14122 Next (New_Next);
14123 end loop;
14125 Set_Next_Named_Actual
14126 (New_E, Explicit_Actual_Parameter (New_Next));
14127 end if;
14129 Next (Old_E);
14130 Next (New_E);
14131 end loop;
14132 end Adjust_Named_Associations;
14134 ---------------------------------
14135 -- Copy_Field_With_Replacement --
14136 ---------------------------------
14138 function Copy_Field_With_Replacement
14139 (Field : Union_Id) return Union_Id
14141 begin
14142 if Field = Union_Id (Empty) then
14143 return Field;
14145 elsif Field in Node_Range then
14146 declare
14147 Old_N : constant Node_Id := Node_Id (Field);
14148 New_N : Node_Id;
14150 begin
14151 -- If syntactic field, as indicated by the parent pointer
14152 -- being set, then copy the referenced node recursively.
14154 if Parent (Old_N) = Old_Node then
14155 New_N := Copy_Node_With_Replacement (Old_N);
14157 if New_N /= Old_N then
14158 Set_Parent (New_N, New_Node);
14159 end if;
14161 -- For semantic fields, update possible entity reference
14162 -- from the replacement map.
14164 else
14165 New_N := Assoc (Old_N);
14166 end if;
14168 return Union_Id (New_N);
14169 end;
14171 elsif Field in List_Range then
14172 declare
14173 Old_L : constant List_Id := List_Id (Field);
14174 New_L : List_Id;
14176 begin
14177 -- If syntactic field, as indicated by the parent pointer,
14178 -- then recursively copy the entire referenced list.
14180 if Parent (Old_L) = Old_Node then
14181 New_L := Copy_List_With_Replacement (Old_L);
14182 Set_Parent (New_L, New_Node);
14184 -- For semantic list, just returned unchanged
14186 else
14187 New_L := Old_L;
14188 end if;
14190 return Union_Id (New_L);
14191 end;
14193 -- Anything other than a list or a node is returned unchanged
14195 else
14196 return Field;
14197 end if;
14198 end Copy_Field_With_Replacement;
14200 -- Start of processing for Copy_Node_With_Replacement
14202 begin
14203 if Old_Node <= Empty_Or_Error then
14204 return Old_Node;
14206 elsif Has_Extension (Old_Node) then
14207 return Assoc (Old_Node);
14209 else
14210 New_Node := New_Copy (Old_Node);
14212 -- If the node we are copying is the associated node of a
14213 -- previously copied Itype, then adjust the associated node
14214 -- of the copy of that Itype accordingly.
14216 if Present (Actual_Map) then
14217 declare
14218 E : Elmt_Id;
14219 Ent : Entity_Id;
14221 begin
14222 -- Case of hash table used
14224 if NCT_Hash_Tables_Used then
14225 Ent := NCT_Itype_Assoc.Get (Old_Node);
14227 if Present (Ent) then
14228 Set_Associated_Node_For_Itype (Ent, New_Node);
14229 end if;
14231 -- Case of no hash table used
14233 else
14234 E := First_Elmt (Actual_Map);
14235 while Present (E) loop
14236 if Is_Itype (Node (E))
14237 and then
14238 Old_Node = Associated_Node_For_Itype (Node (E))
14239 then
14240 Set_Associated_Node_For_Itype
14241 (Node (Next_Elmt (E)), New_Node);
14242 end if;
14244 E := Next_Elmt (Next_Elmt (E));
14245 end loop;
14246 end if;
14247 end;
14248 end if;
14250 -- Recursively copy descendents
14252 Set_Field1
14253 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
14254 Set_Field2
14255 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
14256 Set_Field3
14257 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
14258 Set_Field4
14259 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
14260 Set_Field5
14261 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
14263 -- Adjust Sloc of new node if necessary
14265 if New_Sloc /= No_Location then
14266 Set_Sloc (New_Node, New_Sloc);
14268 -- If we adjust the Sloc, then we are essentially making
14269 -- a completely new node, so the Comes_From_Source flag
14270 -- should be reset to the proper default value.
14272 Nodes.Table (New_Node).Comes_From_Source :=
14273 Default_Node.Comes_From_Source;
14274 end if;
14276 -- If the node is call and has named associations,
14277 -- set the corresponding links in the copy.
14279 if (Nkind (Old_Node) = N_Function_Call
14280 or else Nkind (Old_Node) = N_Entry_Call_Statement
14281 or else
14282 Nkind (Old_Node) = N_Procedure_Call_Statement)
14283 and then Present (First_Named_Actual (Old_Node))
14284 then
14285 Adjust_Named_Associations (Old_Node, New_Node);
14286 end if;
14288 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14289 -- The replacement mechanism applies to entities, and is not used
14290 -- here. Eventually we may need a more general graph-copying
14291 -- routine. For now, do a sequential search to find desired node.
14293 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
14294 and then Present (First_Real_Statement (Old_Node))
14295 then
14296 declare
14297 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
14298 N1, N2 : Node_Id;
14300 begin
14301 N1 := First (Statements (Old_Node));
14302 N2 := First (Statements (New_Node));
14304 while N1 /= Old_F loop
14305 Next (N1);
14306 Next (N2);
14307 end loop;
14309 Set_First_Real_Statement (New_Node, N2);
14310 end;
14311 end if;
14312 end if;
14314 -- All done, return copied node
14316 return New_Node;
14317 end Copy_Node_With_Replacement;
14319 -----------------
14320 -- Visit_Elist --
14321 -----------------
14323 procedure Visit_Elist (E : Elist_Id) is
14324 Elmt : Elmt_Id;
14325 begin
14326 if Present (E) then
14327 Elmt := First_Elmt (E);
14329 while Elmt /= No_Elmt loop
14330 Visit_Node (Node (Elmt));
14331 Next_Elmt (Elmt);
14332 end loop;
14333 end if;
14334 end Visit_Elist;
14336 -----------------
14337 -- Visit_Field --
14338 -----------------
14340 procedure Visit_Field (F : Union_Id; N : Node_Id) is
14341 begin
14342 if F = Union_Id (Empty) then
14343 return;
14345 elsif F in Node_Range then
14347 -- Copy node if it is syntactic, i.e. its parent pointer is
14348 -- set to point to the field that referenced it (certain
14349 -- Itypes will also meet this criterion, which is fine, since
14350 -- these are clearly Itypes that do need to be copied, since
14351 -- we are copying their parent.)
14353 if Parent (Node_Id (F)) = N then
14354 Visit_Node (Node_Id (F));
14355 return;
14357 -- Another case, if we are pointing to an Itype, then we want
14358 -- to copy it if its associated node is somewhere in the tree
14359 -- being copied.
14361 -- Note: the exclusion of self-referential copies is just an
14362 -- optimization, since the search of the already copied list
14363 -- would catch it, but it is a common case (Etype pointing
14364 -- to itself for an Itype that is a base type).
14366 elsif Has_Extension (Node_Id (F))
14367 and then Is_Itype (Entity_Id (F))
14368 and then Node_Id (F) /= N
14369 then
14370 declare
14371 P : Node_Id;
14373 begin
14374 P := Associated_Node_For_Itype (Node_Id (F));
14375 while Present (P) loop
14376 if P = Source then
14377 Visit_Node (Node_Id (F));
14378 return;
14379 else
14380 P := Parent (P);
14381 end if;
14382 end loop;
14384 -- An Itype whose parent is not being copied definitely
14385 -- should NOT be copied, since it does not belong in any
14386 -- sense to the copied subtree.
14388 return;
14389 end;
14390 end if;
14392 elsif F in List_Range and then Parent (List_Id (F)) = N then
14393 Visit_List (List_Id (F));
14394 return;
14395 end if;
14396 end Visit_Field;
14398 -----------------
14399 -- Visit_Itype --
14400 -----------------
14402 procedure Visit_Itype (Old_Itype : Entity_Id) is
14403 New_Itype : Entity_Id;
14404 E : Elmt_Id;
14405 Ent : Entity_Id;
14407 begin
14408 -- Itypes that describe the designated type of access to subprograms
14409 -- have the structure of subprogram declarations, with signatures,
14410 -- etc. Either we duplicate the signatures completely, or choose to
14411 -- share such itypes, which is fine because their elaboration will
14412 -- have no side effects.
14414 if Ekind (Old_Itype) = E_Subprogram_Type then
14415 return;
14416 end if;
14418 New_Itype := New_Copy (Old_Itype);
14420 -- The new Itype has all the attributes of the old one, and
14421 -- we just copy the contents of the entity. However, the back-end
14422 -- needs different names for debugging purposes, so we create a
14423 -- new internal name for it in all cases.
14425 Set_Chars (New_Itype, New_Internal_Name ('T'));
14427 -- If our associated node is an entity that has already been copied,
14428 -- then set the associated node of the copy to point to the right
14429 -- copy. If we have copied an Itype that is itself the associated
14430 -- node of some previously copied Itype, then we set the right
14431 -- pointer in the other direction.
14433 if Present (Actual_Map) then
14435 -- Case of hash tables used
14437 if NCT_Hash_Tables_Used then
14439 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
14441 if Present (Ent) then
14442 Set_Associated_Node_For_Itype (New_Itype, Ent);
14443 end if;
14445 Ent := NCT_Itype_Assoc.Get (Old_Itype);
14446 if Present (Ent) then
14447 Set_Associated_Node_For_Itype (Ent, New_Itype);
14449 -- If the hash table has no association for this Itype and
14450 -- its associated node, enter one now.
14452 else
14453 NCT_Itype_Assoc.Set
14454 (Associated_Node_For_Itype (Old_Itype), New_Itype);
14455 end if;
14457 -- Case of hash tables not used
14459 else
14460 E := First_Elmt (Actual_Map);
14461 while Present (E) loop
14462 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
14463 Set_Associated_Node_For_Itype
14464 (New_Itype, Node (Next_Elmt (E)));
14465 end if;
14467 if Is_Type (Node (E))
14468 and then Old_Itype = Associated_Node_For_Itype (Node (E))
14469 then
14470 Set_Associated_Node_For_Itype
14471 (Node (Next_Elmt (E)), New_Itype);
14472 end if;
14474 E := Next_Elmt (Next_Elmt (E));
14475 end loop;
14476 end if;
14477 end if;
14479 if Present (Freeze_Node (New_Itype)) then
14480 Set_Is_Frozen (New_Itype, False);
14481 Set_Freeze_Node (New_Itype, Empty);
14482 end if;
14484 -- Add new association to map
14486 if No (Actual_Map) then
14487 Actual_Map := New_Elmt_List;
14488 end if;
14490 Append_Elmt (Old_Itype, Actual_Map);
14491 Append_Elmt (New_Itype, Actual_Map);
14493 if NCT_Hash_Tables_Used then
14494 NCT_Assoc.Set (Old_Itype, New_Itype);
14496 else
14497 NCT_Table_Entries := NCT_Table_Entries + 1;
14499 if NCT_Table_Entries > NCT_Hash_Threshold then
14500 Build_NCT_Hash_Tables;
14501 end if;
14502 end if;
14504 -- If a record subtype is simply copied, the entity list will be
14505 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
14507 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
14508 Set_Cloned_Subtype (New_Itype, Old_Itype);
14509 end if;
14511 -- Visit descendents that eventually get copied
14513 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
14515 if Is_Discrete_Type (Old_Itype) then
14516 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
14518 elsif Has_Discriminants (Base_Type (Old_Itype)) then
14519 -- ??? This should involve call to Visit_Field
14520 Visit_Elist (Discriminant_Constraint (Old_Itype));
14522 elsif Is_Array_Type (Old_Itype) then
14523 if Present (First_Index (Old_Itype)) then
14524 Visit_Field (Union_Id (List_Containing
14525 (First_Index (Old_Itype))),
14526 Old_Itype);
14527 end if;
14529 if Is_Packed (Old_Itype) then
14530 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
14531 Old_Itype);
14532 end if;
14533 end if;
14534 end Visit_Itype;
14536 ----------------
14537 -- Visit_List --
14538 ----------------
14540 procedure Visit_List (L : List_Id) is
14541 N : Node_Id;
14542 begin
14543 if L /= No_List then
14544 N := First (L);
14546 while Present (N) loop
14547 Visit_Node (N);
14548 Next (N);
14549 end loop;
14550 end if;
14551 end Visit_List;
14553 ----------------
14554 -- Visit_Node --
14555 ----------------
14557 procedure Visit_Node (N : Node_Or_Entity_Id) is
14559 -- Start of processing for Visit_Node
14561 begin
14562 -- Handle case of an Itype, which must be copied
14564 if Has_Extension (N) and then Is_Itype (N) then
14566 -- Nothing to do if already in the list. This can happen with an
14567 -- Itype entity that appears more than once in the tree.
14568 -- Note that we do not want to visit descendents in this case.
14570 -- Test for already in list when hash table is used
14572 if NCT_Hash_Tables_Used then
14573 if Present (NCT_Assoc.Get (Entity_Id (N))) then
14574 return;
14575 end if;
14577 -- Test for already in list when hash table not used
14579 else
14580 declare
14581 E : Elmt_Id;
14582 begin
14583 if Present (Actual_Map) then
14584 E := First_Elmt (Actual_Map);
14585 while Present (E) loop
14586 if Node (E) = N then
14587 return;
14588 else
14589 E := Next_Elmt (Next_Elmt (E));
14590 end if;
14591 end loop;
14592 end if;
14593 end;
14594 end if;
14596 Visit_Itype (N);
14597 end if;
14599 -- Visit descendents
14601 Visit_Field (Field1 (N), N);
14602 Visit_Field (Field2 (N), N);
14603 Visit_Field (Field3 (N), N);
14604 Visit_Field (Field4 (N), N);
14605 Visit_Field (Field5 (N), N);
14606 end Visit_Node;
14608 -- Start of processing for New_Copy_Tree
14610 begin
14611 Actual_Map := Map;
14613 -- See if we should use hash table
14615 if No (Actual_Map) then
14616 NCT_Hash_Tables_Used := False;
14618 else
14619 declare
14620 Elmt : Elmt_Id;
14622 begin
14623 NCT_Table_Entries := 0;
14625 Elmt := First_Elmt (Actual_Map);
14626 while Present (Elmt) loop
14627 NCT_Table_Entries := NCT_Table_Entries + 1;
14628 Next_Elmt (Elmt);
14629 Next_Elmt (Elmt);
14630 end loop;
14632 if NCT_Table_Entries > NCT_Hash_Threshold then
14633 Build_NCT_Hash_Tables;
14634 else
14635 NCT_Hash_Tables_Used := False;
14636 end if;
14637 end;
14638 end if;
14640 -- Hash table set up if required, now start phase one by visiting
14641 -- top node (we will recursively visit the descendents).
14643 Visit_Node (Source);
14645 -- Now the second phase of the copy can start. First we process
14646 -- all the mapped entities, copying their descendents.
14648 if Present (Actual_Map) then
14649 declare
14650 Elmt : Elmt_Id;
14651 New_Itype : Entity_Id;
14652 begin
14653 Elmt := First_Elmt (Actual_Map);
14654 while Present (Elmt) loop
14655 Next_Elmt (Elmt);
14656 New_Itype := Node (Elmt);
14657 Copy_Itype_With_Replacement (New_Itype);
14658 Next_Elmt (Elmt);
14659 end loop;
14660 end;
14661 end if;
14663 -- Now we can copy the actual tree
14665 return Copy_Node_With_Replacement (Source);
14666 end New_Copy_Tree;
14668 -------------------------
14669 -- New_External_Entity --
14670 -------------------------
14672 function New_External_Entity
14673 (Kind : Entity_Kind;
14674 Scope_Id : Entity_Id;
14675 Sloc_Value : Source_Ptr;
14676 Related_Id : Entity_Id;
14677 Suffix : Character;
14678 Suffix_Index : Nat := 0;
14679 Prefix : Character := ' ') return Entity_Id
14681 N : constant Entity_Id :=
14682 Make_Defining_Identifier (Sloc_Value,
14683 New_External_Name
14684 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
14686 begin
14687 Set_Ekind (N, Kind);
14688 Set_Is_Internal (N, True);
14689 Append_Entity (N, Scope_Id);
14690 Set_Public_Status (N);
14692 if Kind in Type_Kind then
14693 Init_Size_Align (N);
14694 end if;
14696 return N;
14697 end New_External_Entity;
14699 -------------------------
14700 -- New_Internal_Entity --
14701 -------------------------
14703 function New_Internal_Entity
14704 (Kind : Entity_Kind;
14705 Scope_Id : Entity_Id;
14706 Sloc_Value : Source_Ptr;
14707 Id_Char : Character) return Entity_Id
14709 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
14711 begin
14712 Set_Ekind (N, Kind);
14713 Set_Is_Internal (N, True);
14714 Append_Entity (N, Scope_Id);
14716 if Kind in Type_Kind then
14717 Init_Size_Align (N);
14718 end if;
14720 return N;
14721 end New_Internal_Entity;
14723 -----------------
14724 -- Next_Actual --
14725 -----------------
14727 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
14728 N : Node_Id;
14730 begin
14731 -- If we are pointing at a positional parameter, it is a member of a
14732 -- node list (the list of parameters), and the next parameter is the
14733 -- next node on the list, unless we hit a parameter association, then
14734 -- we shift to using the chain whose head is the First_Named_Actual in
14735 -- the parent, and then is threaded using the Next_Named_Actual of the
14736 -- Parameter_Association. All this fiddling is because the original node
14737 -- list is in the textual call order, and what we need is the
14738 -- declaration order.
14740 if Is_List_Member (Actual_Id) then
14741 N := Next (Actual_Id);
14743 if Nkind (N) = N_Parameter_Association then
14744 return First_Named_Actual (Parent (Actual_Id));
14745 else
14746 return N;
14747 end if;
14749 else
14750 return Next_Named_Actual (Parent (Actual_Id));
14751 end if;
14752 end Next_Actual;
14754 procedure Next_Actual (Actual_Id : in out Node_Id) is
14755 begin
14756 Actual_Id := Next_Actual (Actual_Id);
14757 end Next_Actual;
14759 -----------------------
14760 -- Normalize_Actuals --
14761 -----------------------
14763 -- Chain actuals according to formals of subprogram. If there are no named
14764 -- associations, the chain is simply the list of Parameter Associations,
14765 -- since the order is the same as the declaration order. If there are named
14766 -- associations, then the First_Named_Actual field in the N_Function_Call
14767 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14768 -- node for the parameter that comes first in declaration order. The
14769 -- remaining named parameters are then chained in declaration order using
14770 -- Next_Named_Actual.
14772 -- This routine also verifies that the number of actuals is compatible with
14773 -- the number and default values of formals, but performs no type checking
14774 -- (type checking is done by the caller).
14776 -- If the matching succeeds, Success is set to True and the caller proceeds
14777 -- with type-checking. If the match is unsuccessful, then Success is set to
14778 -- False, and the caller attempts a different interpretation, if there is
14779 -- one.
14781 -- If the flag Report is on, the call is not overloaded, and a failure to
14782 -- match can be reported here, rather than in the caller.
14784 procedure Normalize_Actuals
14785 (N : Node_Id;
14786 S : Entity_Id;
14787 Report : Boolean;
14788 Success : out Boolean)
14790 Actuals : constant List_Id := Parameter_Associations (N);
14791 Actual : Node_Id := Empty;
14792 Formal : Entity_Id;
14793 Last : Node_Id := Empty;
14794 First_Named : Node_Id := Empty;
14795 Found : Boolean;
14797 Formals_To_Match : Integer := 0;
14798 Actuals_To_Match : Integer := 0;
14800 procedure Chain (A : Node_Id);
14801 -- Add named actual at the proper place in the list, using the
14802 -- Next_Named_Actual link.
14804 function Reporting return Boolean;
14805 -- Determines if an error is to be reported. To report an error, we
14806 -- need Report to be True, and also we do not report errors caused
14807 -- by calls to init procs that occur within other init procs. Such
14808 -- errors must always be cascaded errors, since if all the types are
14809 -- declared correctly, the compiler will certainly build decent calls.
14811 -----------
14812 -- Chain --
14813 -----------
14815 procedure Chain (A : Node_Id) is
14816 begin
14817 if No (Last) then
14819 -- Call node points to first actual in list
14821 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
14823 else
14824 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
14825 end if;
14827 Last := A;
14828 Set_Next_Named_Actual (Last, Empty);
14829 end Chain;
14831 ---------------
14832 -- Reporting --
14833 ---------------
14835 function Reporting return Boolean is
14836 begin
14837 if not Report then
14838 return False;
14840 elsif not Within_Init_Proc then
14841 return True;
14843 elsif Is_Init_Proc (Entity (Name (N))) then
14844 return False;
14846 else
14847 return True;
14848 end if;
14849 end Reporting;
14851 -- Start of processing for Normalize_Actuals
14853 begin
14854 if Is_Access_Type (S) then
14856 -- The name in the call is a function call that returns an access
14857 -- to subprogram. The designated type has the list of formals.
14859 Formal := First_Formal (Designated_Type (S));
14860 else
14861 Formal := First_Formal (S);
14862 end if;
14864 while Present (Formal) loop
14865 Formals_To_Match := Formals_To_Match + 1;
14866 Next_Formal (Formal);
14867 end loop;
14869 -- Find if there is a named association, and verify that no positional
14870 -- associations appear after named ones.
14872 if Present (Actuals) then
14873 Actual := First (Actuals);
14874 end if;
14876 while Present (Actual)
14877 and then Nkind (Actual) /= N_Parameter_Association
14878 loop
14879 Actuals_To_Match := Actuals_To_Match + 1;
14880 Next (Actual);
14881 end loop;
14883 if No (Actual) and Actuals_To_Match = Formals_To_Match then
14885 -- Most common case: positional notation, no defaults
14887 Success := True;
14888 return;
14890 elsif Actuals_To_Match > Formals_To_Match then
14892 -- Too many actuals: will not work
14894 if Reporting then
14895 if Is_Entity_Name (Name (N)) then
14896 Error_Msg_N ("too many arguments in call to&", Name (N));
14897 else
14898 Error_Msg_N ("too many arguments in call", N);
14899 end if;
14900 end if;
14902 Success := False;
14903 return;
14904 end if;
14906 First_Named := Actual;
14908 while Present (Actual) loop
14909 if Nkind (Actual) /= N_Parameter_Association then
14910 Error_Msg_N
14911 ("positional parameters not allowed after named ones", Actual);
14912 Success := False;
14913 return;
14915 else
14916 Actuals_To_Match := Actuals_To_Match + 1;
14917 end if;
14919 Next (Actual);
14920 end loop;
14922 if Present (Actuals) then
14923 Actual := First (Actuals);
14924 end if;
14926 Formal := First_Formal (S);
14927 while Present (Formal) loop
14929 -- Match the formals in order. If the corresponding actual is
14930 -- positional, nothing to do. Else scan the list of named actuals
14931 -- to find the one with the right name.
14933 if Present (Actual)
14934 and then Nkind (Actual) /= N_Parameter_Association
14935 then
14936 Next (Actual);
14937 Actuals_To_Match := Actuals_To_Match - 1;
14938 Formals_To_Match := Formals_To_Match - 1;
14940 else
14941 -- For named parameters, search the list of actuals to find
14942 -- one that matches the next formal name.
14944 Actual := First_Named;
14945 Found := False;
14946 while Present (Actual) loop
14947 if Chars (Selector_Name (Actual)) = Chars (Formal) then
14948 Found := True;
14949 Chain (Actual);
14950 Actuals_To_Match := Actuals_To_Match - 1;
14951 Formals_To_Match := Formals_To_Match - 1;
14952 exit;
14953 end if;
14955 Next (Actual);
14956 end loop;
14958 if not Found then
14959 if Ekind (Formal) /= E_In_Parameter
14960 or else No (Default_Value (Formal))
14961 then
14962 if Reporting then
14963 if (Comes_From_Source (S)
14964 or else Sloc (S) = Standard_Location)
14965 and then Is_Overloadable (S)
14966 then
14967 if No (Actuals)
14968 and then
14969 Nkind_In (Parent (N), N_Procedure_Call_Statement,
14970 N_Function_Call,
14971 N_Parameter_Association)
14972 and then Ekind (S) /= E_Function
14973 then
14974 Set_Etype (N, Etype (S));
14976 else
14977 Error_Msg_Name_1 := Chars (S);
14978 Error_Msg_Sloc := Sloc (S);
14979 Error_Msg_NE
14980 ("missing argument for parameter & "
14981 & "in call to % declared #", N, Formal);
14982 end if;
14984 elsif Is_Overloadable (S) then
14985 Error_Msg_Name_1 := Chars (S);
14987 -- Point to type derivation that generated the
14988 -- operation.
14990 Error_Msg_Sloc := Sloc (Parent (S));
14992 Error_Msg_NE
14993 ("missing argument for parameter & "
14994 & "in call to % (inherited) #", N, Formal);
14996 else
14997 Error_Msg_NE
14998 ("missing argument for parameter &", N, Formal);
14999 end if;
15000 end if;
15002 Success := False;
15003 return;
15005 else
15006 Formals_To_Match := Formals_To_Match - 1;
15007 end if;
15008 end if;
15009 end if;
15011 Next_Formal (Formal);
15012 end loop;
15014 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
15015 Success := True;
15016 return;
15018 else
15019 if Reporting then
15021 -- Find some superfluous named actual that did not get
15022 -- attached to the list of associations.
15024 Actual := First (Actuals);
15025 while Present (Actual) loop
15026 if Nkind (Actual) = N_Parameter_Association
15027 and then Actual /= Last
15028 and then No (Next_Named_Actual (Actual))
15029 then
15030 Error_Msg_N ("unmatched actual & in call",
15031 Selector_Name (Actual));
15032 exit;
15033 end if;
15035 Next (Actual);
15036 end loop;
15037 end if;
15039 Success := False;
15040 return;
15041 end if;
15042 end Normalize_Actuals;
15044 --------------------------------
15045 -- Note_Possible_Modification --
15046 --------------------------------
15048 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
15049 Modification_Comes_From_Source : constant Boolean :=
15050 Comes_From_Source (Parent (N));
15052 Ent : Entity_Id;
15053 Exp : Node_Id;
15055 begin
15056 -- Loop to find referenced entity, if there is one
15058 Exp := N;
15059 loop
15060 Ent := Empty;
15062 if Is_Entity_Name (Exp) then
15063 Ent := Entity (Exp);
15065 -- If the entity is missing, it is an undeclared identifier,
15066 -- and there is nothing to annotate.
15068 if No (Ent) then
15069 return;
15070 end if;
15072 elsif Nkind (Exp) = N_Explicit_Dereference then
15073 declare
15074 P : constant Node_Id := Prefix (Exp);
15076 begin
15077 -- In formal verification mode, keep track of all reads and
15078 -- writes through explicit dereferences.
15080 if GNATprove_Mode then
15081 SPARK_Specific.Generate_Dereference (N, 'm');
15082 end if;
15084 if Nkind (P) = N_Selected_Component
15085 and then Present (Entry_Formal (Entity (Selector_Name (P))))
15086 then
15087 -- Case of a reference to an entry formal
15089 Ent := Entry_Formal (Entity (Selector_Name (P)));
15091 elsif Nkind (P) = N_Identifier
15092 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
15093 and then Present (Expression (Parent (Entity (P))))
15094 and then Nkind (Expression (Parent (Entity (P)))) =
15095 N_Reference
15096 then
15097 -- Case of a reference to a value on which side effects have
15098 -- been removed.
15100 Exp := Prefix (Expression (Parent (Entity (P))));
15101 goto Continue;
15103 else
15104 return;
15105 end if;
15106 end;
15108 elsif Nkind_In (Exp, N_Type_Conversion,
15109 N_Unchecked_Type_Conversion)
15110 then
15111 Exp := Expression (Exp);
15112 goto Continue;
15114 elsif Nkind_In (Exp, N_Slice,
15115 N_Indexed_Component,
15116 N_Selected_Component)
15117 then
15118 -- Special check, if the prefix is an access type, then return
15119 -- since we are modifying the thing pointed to, not the prefix.
15120 -- When we are expanding, most usually the prefix is replaced
15121 -- by an explicit dereference, and this test is not needed, but
15122 -- in some cases (notably -gnatc mode and generics) when we do
15123 -- not do full expansion, we need this special test.
15125 if Is_Access_Type (Etype (Prefix (Exp))) then
15126 return;
15128 -- Otherwise go to prefix and keep going
15130 else
15131 Exp := Prefix (Exp);
15132 goto Continue;
15133 end if;
15135 -- All other cases, not a modification
15137 else
15138 return;
15139 end if;
15141 -- Now look for entity being referenced
15143 if Present (Ent) then
15144 if Is_Object (Ent) then
15145 if Comes_From_Source (Exp)
15146 or else Modification_Comes_From_Source
15147 then
15148 -- Give warning if pragma unmodified given and we are
15149 -- sure this is a modification.
15151 if Has_Pragma_Unmodified (Ent) and then Sure then
15152 Error_Msg_NE ("??pragma Unmodified given for &!", N, Ent);
15153 end if;
15155 Set_Never_Set_In_Source (Ent, False);
15156 end if;
15158 Set_Is_True_Constant (Ent, False);
15159 Set_Current_Value (Ent, Empty);
15160 Set_Is_Known_Null (Ent, False);
15162 if not Can_Never_Be_Null (Ent) then
15163 Set_Is_Known_Non_Null (Ent, False);
15164 end if;
15166 -- Follow renaming chain
15168 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
15169 and then Present (Renamed_Object (Ent))
15170 then
15171 Exp := Renamed_Object (Ent);
15173 -- If the entity is the loop variable in an iteration over
15174 -- a container, retrieve container expression to indicate
15175 -- possible modificastion.
15177 if Present (Related_Expression (Ent))
15178 and then Nkind (Parent (Related_Expression (Ent))) =
15179 N_Iterator_Specification
15180 then
15181 Exp := Original_Node (Related_Expression (Ent));
15182 end if;
15184 goto Continue;
15186 -- The expression may be the renaming of a subcomponent of an
15187 -- array or container. The assignment to the subcomponent is
15188 -- a modification of the container.
15190 elsif Comes_From_Source (Original_Node (Exp))
15191 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
15192 N_Indexed_Component)
15193 then
15194 Exp := Prefix (Original_Node (Exp));
15195 goto Continue;
15196 end if;
15198 -- Generate a reference only if the assignment comes from
15199 -- source. This excludes, for example, calls to a dispatching
15200 -- assignment operation when the left-hand side is tagged. In
15201 -- GNATprove mode, we need those references also on generated
15202 -- code, as these are used to compute the local effects of
15203 -- subprograms.
15205 if Modification_Comes_From_Source or GNATprove_Mode then
15206 Generate_Reference (Ent, Exp, 'm');
15208 -- If the target of the assignment is the bound variable
15209 -- in an iterator, indicate that the corresponding array
15210 -- or container is also modified.
15212 if Ada_Version >= Ada_2012
15213 and then Nkind (Parent (Ent)) = N_Iterator_Specification
15214 then
15215 declare
15216 Domain : constant Node_Id := Name (Parent (Ent));
15218 begin
15219 -- TBD : in the full version of the construct, the
15220 -- domain of iteration can be given by an expression.
15222 if Is_Entity_Name (Domain) then
15223 Generate_Reference (Entity (Domain), Exp, 'm');
15224 Set_Is_True_Constant (Entity (Domain), False);
15225 Set_Never_Set_In_Source (Entity (Domain), False);
15226 end if;
15227 end;
15228 end if;
15229 end if;
15231 Check_Nested_Access (Ent);
15232 end if;
15234 Kill_Checks (Ent);
15236 -- If we are sure this is a modification from source, and we know
15237 -- this modifies a constant, then give an appropriate warning.
15239 if Overlays_Constant (Ent)
15240 and then (Modification_Comes_From_Source and Sure)
15241 then
15242 declare
15243 A : constant Node_Id := Address_Clause (Ent);
15244 begin
15245 if Present (A) then
15246 declare
15247 Exp : constant Node_Id := Expression (A);
15248 begin
15249 if Nkind (Exp) = N_Attribute_Reference
15250 and then Attribute_Name (Exp) = Name_Address
15251 and then Is_Entity_Name (Prefix (Exp))
15252 then
15253 Error_Msg_Sloc := Sloc (A);
15254 Error_Msg_NE
15255 ("constant& may be modified via address "
15256 & "clause#??", N, Entity (Prefix (Exp)));
15257 end if;
15258 end;
15259 end if;
15260 end;
15261 end if;
15263 return;
15264 end if;
15266 <<Continue>>
15267 null;
15268 end loop;
15269 end Note_Possible_Modification;
15271 -------------------------
15272 -- Object_Access_Level --
15273 -------------------------
15275 -- Returns the static accessibility level of the view denoted by Obj. Note
15276 -- that the value returned is the result of a call to Scope_Depth. Only
15277 -- scope depths associated with dynamic scopes can actually be returned.
15278 -- Since only relative levels matter for accessibility checking, the fact
15279 -- that the distance between successive levels of accessibility is not
15280 -- always one is immaterial (invariant: if level(E2) is deeper than
15281 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15283 function Object_Access_Level (Obj : Node_Id) return Uint is
15284 function Is_Interface_Conversion (N : Node_Id) return Boolean;
15285 -- Determine whether N is a construct of the form
15286 -- Some_Type (Operand._tag'Address)
15287 -- This construct appears in the context of dispatching calls.
15289 function Reference_To (Obj : Node_Id) return Node_Id;
15290 -- An explicit dereference is created when removing side-effects from
15291 -- expressions for constraint checking purposes. In this case a local
15292 -- access type is created for it. The correct access level is that of
15293 -- the original source node. We detect this case by noting that the
15294 -- prefix of the dereference is created by an object declaration whose
15295 -- initial expression is a reference.
15297 -----------------------------
15298 -- Is_Interface_Conversion --
15299 -----------------------------
15301 function Is_Interface_Conversion (N : Node_Id) return Boolean is
15302 begin
15303 return Nkind (N) = N_Unchecked_Type_Conversion
15304 and then Nkind (Expression (N)) = N_Attribute_Reference
15305 and then Attribute_Name (Expression (N)) = Name_Address;
15306 end Is_Interface_Conversion;
15308 ------------------
15309 -- Reference_To --
15310 ------------------
15312 function Reference_To (Obj : Node_Id) return Node_Id is
15313 Pref : constant Node_Id := Prefix (Obj);
15314 begin
15315 if Is_Entity_Name (Pref)
15316 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
15317 and then Present (Expression (Parent (Entity (Pref))))
15318 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
15319 then
15320 return (Prefix (Expression (Parent (Entity (Pref)))));
15321 else
15322 return Empty;
15323 end if;
15324 end Reference_To;
15326 -- Local variables
15328 E : Entity_Id;
15330 -- Start of processing for Object_Access_Level
15332 begin
15333 if Nkind (Obj) = N_Defining_Identifier
15334 or else Is_Entity_Name (Obj)
15335 then
15336 if Nkind (Obj) = N_Defining_Identifier then
15337 E := Obj;
15338 else
15339 E := Entity (Obj);
15340 end if;
15342 if Is_Prival (E) then
15343 E := Prival_Link (E);
15344 end if;
15346 -- If E is a type then it denotes a current instance. For this case
15347 -- we add one to the normal accessibility level of the type to ensure
15348 -- that current instances are treated as always being deeper than
15349 -- than the level of any visible named access type (see 3.10.2(21)).
15351 if Is_Type (E) then
15352 return Type_Access_Level (E) + 1;
15354 elsif Present (Renamed_Object (E)) then
15355 return Object_Access_Level (Renamed_Object (E));
15357 -- Similarly, if E is a component of the current instance of a
15358 -- protected type, any instance of it is assumed to be at a deeper
15359 -- level than the type. For a protected object (whose type is an
15360 -- anonymous protected type) its components are at the same level
15361 -- as the type itself.
15363 elsif not Is_Overloadable (E)
15364 and then Ekind (Scope (E)) = E_Protected_Type
15365 and then Comes_From_Source (Scope (E))
15366 then
15367 return Type_Access_Level (Scope (E)) + 1;
15369 else
15370 -- Aliased formals take their access level from the point of call.
15371 -- This is smaller than the level of the subprogram itself.
15373 if Is_Formal (E) and then Is_Aliased (E) then
15374 return Type_Access_Level (Etype (E));
15376 else
15377 return Scope_Depth (Enclosing_Dynamic_Scope (E));
15378 end if;
15379 end if;
15381 elsif Nkind (Obj) = N_Selected_Component then
15382 if Is_Access_Type (Etype (Prefix (Obj))) then
15383 return Type_Access_Level (Etype (Prefix (Obj)));
15384 else
15385 return Object_Access_Level (Prefix (Obj));
15386 end if;
15388 elsif Nkind (Obj) = N_Indexed_Component then
15389 if Is_Access_Type (Etype (Prefix (Obj))) then
15390 return Type_Access_Level (Etype (Prefix (Obj)));
15391 else
15392 return Object_Access_Level (Prefix (Obj));
15393 end if;
15395 elsif Nkind (Obj) = N_Explicit_Dereference then
15397 -- If the prefix is a selected access discriminant then we make a
15398 -- recursive call on the prefix, which will in turn check the level
15399 -- of the prefix object of the selected discriminant.
15401 -- In Ada 2012, if the discriminant has implicit dereference and
15402 -- the context is a selected component, treat this as an object of
15403 -- unknown scope (see below). This is necessary in compile-only mode;
15404 -- otherwise expansion will already have transformed the prefix into
15405 -- a temporary.
15407 if Nkind (Prefix (Obj)) = N_Selected_Component
15408 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
15409 and then
15410 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
15411 and then
15412 (not Has_Implicit_Dereference
15413 (Entity (Selector_Name (Prefix (Obj))))
15414 or else Nkind (Parent (Obj)) /= N_Selected_Component)
15415 then
15416 return Object_Access_Level (Prefix (Obj));
15418 -- Detect an interface conversion in the context of a dispatching
15419 -- call. Use the original form of the conversion to find the access
15420 -- level of the operand.
15422 elsif Is_Interface (Etype (Obj))
15423 and then Is_Interface_Conversion (Prefix (Obj))
15424 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
15425 then
15426 return Object_Access_Level (Original_Node (Obj));
15428 elsif not Comes_From_Source (Obj) then
15429 declare
15430 Ref : constant Node_Id := Reference_To (Obj);
15431 begin
15432 if Present (Ref) then
15433 return Object_Access_Level (Ref);
15434 else
15435 return Type_Access_Level (Etype (Prefix (Obj)));
15436 end if;
15437 end;
15439 else
15440 return Type_Access_Level (Etype (Prefix (Obj)));
15441 end if;
15443 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
15444 return Object_Access_Level (Expression (Obj));
15446 elsif Nkind (Obj) = N_Function_Call then
15448 -- Function results are objects, so we get either the access level of
15449 -- the function or, in the case of an indirect call, the level of the
15450 -- access-to-subprogram type. (This code is used for Ada 95, but it
15451 -- looks wrong, because it seems that we should be checking the level
15452 -- of the call itself, even for Ada 95. However, using the Ada 2005
15453 -- version of the code causes regressions in several tests that are
15454 -- compiled with -gnat95. ???)
15456 if Ada_Version < Ada_2005 then
15457 if Is_Entity_Name (Name (Obj)) then
15458 return Subprogram_Access_Level (Entity (Name (Obj)));
15459 else
15460 return Type_Access_Level (Etype (Prefix (Name (Obj))));
15461 end if;
15463 -- For Ada 2005, the level of the result object of a function call is
15464 -- defined to be the level of the call's innermost enclosing master.
15465 -- We determine that by querying the depth of the innermost enclosing
15466 -- dynamic scope.
15468 else
15469 Return_Master_Scope_Depth_Of_Call : declare
15471 function Innermost_Master_Scope_Depth
15472 (N : Node_Id) return Uint;
15473 -- Returns the scope depth of the given node's innermost
15474 -- enclosing dynamic scope (effectively the accessibility
15475 -- level of the innermost enclosing master).
15477 ----------------------------------
15478 -- Innermost_Master_Scope_Depth --
15479 ----------------------------------
15481 function Innermost_Master_Scope_Depth
15482 (N : Node_Id) return Uint
15484 Node_Par : Node_Id := Parent (N);
15486 begin
15487 -- Locate the nearest enclosing node (by traversing Parents)
15488 -- that Defining_Entity can be applied to, and return the
15489 -- depth of that entity's nearest enclosing dynamic scope.
15491 while Present (Node_Par) loop
15492 case Nkind (Node_Par) is
15493 when N_Component_Declaration |
15494 N_Entry_Declaration |
15495 N_Formal_Object_Declaration |
15496 N_Formal_Type_Declaration |
15497 N_Full_Type_Declaration |
15498 N_Incomplete_Type_Declaration |
15499 N_Loop_Parameter_Specification |
15500 N_Object_Declaration |
15501 N_Protected_Type_Declaration |
15502 N_Private_Extension_Declaration |
15503 N_Private_Type_Declaration |
15504 N_Subtype_Declaration |
15505 N_Function_Specification |
15506 N_Procedure_Specification |
15507 N_Task_Type_Declaration |
15508 N_Body_Stub |
15509 N_Generic_Instantiation |
15510 N_Proper_Body |
15511 N_Implicit_Label_Declaration |
15512 N_Package_Declaration |
15513 N_Single_Task_Declaration |
15514 N_Subprogram_Declaration |
15515 N_Generic_Declaration |
15516 N_Renaming_Declaration |
15517 N_Block_Statement |
15518 N_Formal_Subprogram_Declaration |
15519 N_Abstract_Subprogram_Declaration |
15520 N_Entry_Body |
15521 N_Exception_Declaration |
15522 N_Formal_Package_Declaration |
15523 N_Number_Declaration |
15524 N_Package_Specification |
15525 N_Parameter_Specification |
15526 N_Single_Protected_Declaration |
15527 N_Subunit =>
15529 return Scope_Depth
15530 (Nearest_Dynamic_Scope
15531 (Defining_Entity (Node_Par)));
15533 when others =>
15534 null;
15535 end case;
15537 Node_Par := Parent (Node_Par);
15538 end loop;
15540 pragma Assert (False);
15542 -- Should never reach the following return
15544 return Scope_Depth (Current_Scope) + 1;
15545 end Innermost_Master_Scope_Depth;
15547 -- Start of processing for Return_Master_Scope_Depth_Of_Call
15549 begin
15550 return Innermost_Master_Scope_Depth (Obj);
15551 end Return_Master_Scope_Depth_Of_Call;
15552 end if;
15554 -- For convenience we handle qualified expressions, even though they
15555 -- aren't technically object names.
15557 elsif Nkind (Obj) = N_Qualified_Expression then
15558 return Object_Access_Level (Expression (Obj));
15560 -- Ditto for aggregates. They have the level of the temporary that
15561 -- will hold their value.
15563 elsif Nkind (Obj) = N_Aggregate then
15564 return Object_Access_Level (Current_Scope);
15566 -- Otherwise return the scope level of Standard. (If there are cases
15567 -- that fall through to this point they will be treated as having
15568 -- global accessibility for now. ???)
15570 else
15571 return Scope_Depth (Standard_Standard);
15572 end if;
15573 end Object_Access_Level;
15575 --------------------------
15576 -- Original_Aspect_Name --
15577 --------------------------
15579 function Original_Aspect_Name (N : Node_Id) return Name_Id is
15580 Pras : Node_Id;
15581 Name : Name_Id;
15583 begin
15584 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
15585 Pras := N;
15587 if Is_Rewrite_Substitution (Pras)
15588 and then Nkind (Original_Node (Pras)) = N_Pragma
15589 then
15590 Pras := Original_Node (Pras);
15591 end if;
15593 -- Case where we came from aspect specication
15595 if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
15596 Pras := Corresponding_Aspect (Pras);
15597 end if;
15599 -- Get name from aspect or pragma
15601 if Nkind (Pras) = N_Pragma then
15602 Name := Pragma_Name (Pras);
15603 else
15604 Name := Chars (Identifier (Pras));
15605 end if;
15607 -- Deal with 'Class
15609 if Class_Present (Pras) then
15610 case Name is
15612 -- Names that need converting to special _xxx form
15614 when Name_Pre |
15615 Name_Pre_Class =>
15616 Name := Name_uPre;
15618 when Name_Post |
15619 Name_Post_Class =>
15620 Name := Name_uPost;
15622 when Name_Invariant =>
15623 Name := Name_uInvariant;
15625 when Name_Type_Invariant |
15626 Name_Type_Invariant_Class =>
15627 Name := Name_uType_Invariant;
15629 -- Nothing to do for other cases (e.g. a Check that derived
15630 -- from Pre_Class and has the flag set). Also we do nothing
15631 -- if the name is already in special _xxx form.
15633 when others =>
15634 null;
15635 end case;
15636 end if;
15638 return Name;
15639 end Original_Aspect_Name;
15641 --------------------------------------
15642 -- Original_Corresponding_Operation --
15643 --------------------------------------
15645 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
15647 Typ : constant Entity_Id := Find_Dispatching_Type (S);
15649 begin
15650 -- If S is an inherited primitive S2 the original corresponding
15651 -- operation of S is the original corresponding operation of S2
15653 if Present (Alias (S))
15654 and then Find_Dispatching_Type (Alias (S)) /= Typ
15655 then
15656 return Original_Corresponding_Operation (Alias (S));
15658 -- If S overrides an inherited subprogram S2 the original corresponding
15659 -- operation of S is the original corresponding operation of S2
15661 elsif Present (Overridden_Operation (S)) then
15662 return Original_Corresponding_Operation (Overridden_Operation (S));
15664 -- otherwise it is S itself
15666 else
15667 return S;
15668 end if;
15669 end Original_Corresponding_Operation;
15671 ----------------------
15672 -- Policy_In_Effect --
15673 ----------------------
15675 function Policy_In_Effect (Policy : Name_Id) return Name_Id is
15676 function Policy_In_List (List : Node_Id) return Name_Id;
15677 -- Determine the the mode of a policy in a N_Pragma list
15679 --------------------
15680 -- Policy_In_List --
15681 --------------------
15683 function Policy_In_List (List : Node_Id) return Name_Id is
15684 Arg : Node_Id;
15685 Expr : Node_Id;
15686 Prag : Node_Id;
15688 begin
15689 Prag := List;
15690 while Present (Prag) loop
15691 Arg := First (Pragma_Argument_Associations (Prag));
15692 Expr := Get_Pragma_Arg (Arg);
15694 -- The current Check_Policy pragma matches the requested policy,
15695 -- return the second argument which denotes the policy identifier.
15697 if Chars (Expr) = Policy then
15698 return Chars (Get_Pragma_Arg (Next (Arg)));
15699 end if;
15701 Prag := Next_Pragma (Prag);
15702 end loop;
15704 return No_Name;
15705 end Policy_In_List;
15707 -- Local variables
15709 Kind : Name_Id;
15711 -- Start of processing for Policy_In_Effect
15713 begin
15714 if not Is_Valid_Assertion_Kind (Policy) then
15715 raise Program_Error;
15716 end if;
15718 -- Inspect all policy pragmas that appear within scopes (if any)
15720 Kind := Policy_In_List (Check_Policy_List);
15722 -- Inspect all configuration policy pragmas (if any)
15724 if Kind = No_Name then
15725 Kind := Policy_In_List (Check_Policy_List_Config);
15726 end if;
15728 -- The context lacks policy pragmas, determine the mode based on whether
15729 -- assertions are enabled at the configuration level. This ensures that
15730 -- the policy is preserved when analyzing generics.
15732 if Kind = No_Name then
15733 if Assertions_Enabled_Config then
15734 Kind := Name_Check;
15735 else
15736 Kind := Name_Ignore;
15737 end if;
15738 end if;
15740 return Kind;
15741 end Policy_In_Effect;
15743 ----------------------------------
15744 -- Predicate_Tests_On_Arguments --
15745 ----------------------------------
15747 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
15748 begin
15749 -- Always test predicates on indirect call
15751 if Ekind (Subp) = E_Subprogram_Type then
15752 return True;
15754 -- Do not test predicates on call to generated default Finalize, since
15755 -- we are not interested in whether something we are finalizing (and
15756 -- typically destroying) satisfies its predicates.
15758 elsif Chars (Subp) = Name_Finalize
15759 and then not Comes_From_Source (Subp)
15760 then
15761 return False;
15763 -- Do not test predicates on any internally generated routines
15765 elsif Is_Internal_Name (Chars (Subp)) then
15766 return False;
15768 -- Do not test predicates on call to Init_Proc, since if needed the
15769 -- predicate test will occur at some other point.
15771 elsif Is_Init_Proc (Subp) then
15772 return False;
15774 -- Do not test predicates on call to predicate function, since this
15775 -- would cause infinite recursion.
15777 elsif Ekind (Subp) = E_Function
15778 and then (Is_Predicate_Function (Subp)
15779 or else
15780 Is_Predicate_Function_M (Subp))
15781 then
15782 return False;
15784 -- For now, no other exceptions
15786 else
15787 return True;
15788 end if;
15789 end Predicate_Tests_On_Arguments;
15791 -----------------------
15792 -- Private_Component --
15793 -----------------------
15795 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
15796 Ancestor : constant Entity_Id := Base_Type (Type_Id);
15798 function Trace_Components
15799 (T : Entity_Id;
15800 Check : Boolean) return Entity_Id;
15801 -- Recursive function that does the work, and checks against circular
15802 -- definition for each subcomponent type.
15804 ----------------------
15805 -- Trace_Components --
15806 ----------------------
15808 function Trace_Components
15809 (T : Entity_Id;
15810 Check : Boolean) return Entity_Id
15812 Btype : constant Entity_Id := Base_Type (T);
15813 Component : Entity_Id;
15814 P : Entity_Id;
15815 Candidate : Entity_Id := Empty;
15817 begin
15818 if Check and then Btype = Ancestor then
15819 Error_Msg_N ("circular type definition", Type_Id);
15820 return Any_Type;
15821 end if;
15823 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
15824 if Present (Full_View (Btype))
15825 and then Is_Record_Type (Full_View (Btype))
15826 and then not Is_Frozen (Btype)
15827 then
15828 -- To indicate that the ancestor depends on a private type, the
15829 -- current Btype is sufficient. However, to check for circular
15830 -- definition we must recurse on the full view.
15832 Candidate := Trace_Components (Full_View (Btype), True);
15834 if Candidate = Any_Type then
15835 return Any_Type;
15836 else
15837 return Btype;
15838 end if;
15840 else
15841 return Btype;
15842 end if;
15844 elsif Is_Array_Type (Btype) then
15845 return Trace_Components (Component_Type (Btype), True);
15847 elsif Is_Record_Type (Btype) then
15848 Component := First_Entity (Btype);
15849 while Present (Component)
15850 and then Comes_From_Source (Component)
15851 loop
15852 -- Skip anonymous types generated by constrained components
15854 if not Is_Type (Component) then
15855 P := Trace_Components (Etype (Component), True);
15857 if Present (P) then
15858 if P = Any_Type then
15859 return P;
15860 else
15861 Candidate := P;
15862 end if;
15863 end if;
15864 end if;
15866 Next_Entity (Component);
15867 end loop;
15869 return Candidate;
15871 else
15872 return Empty;
15873 end if;
15874 end Trace_Components;
15876 -- Start of processing for Private_Component
15878 begin
15879 return Trace_Components (Type_Id, False);
15880 end Private_Component;
15882 ---------------------------
15883 -- Primitive_Names_Match --
15884 ---------------------------
15886 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
15888 function Non_Internal_Name (E : Entity_Id) return Name_Id;
15889 -- Given an internal name, returns the corresponding non-internal name
15891 ------------------------
15892 -- Non_Internal_Name --
15893 ------------------------
15895 function Non_Internal_Name (E : Entity_Id) return Name_Id is
15896 begin
15897 Get_Name_String (Chars (E));
15898 Name_Len := Name_Len - 1;
15899 return Name_Find;
15900 end Non_Internal_Name;
15902 -- Start of processing for Primitive_Names_Match
15904 begin
15905 pragma Assert (Present (E1) and then Present (E2));
15907 return Chars (E1) = Chars (E2)
15908 or else
15909 (not Is_Internal_Name (Chars (E1))
15910 and then Is_Internal_Name (Chars (E2))
15911 and then Non_Internal_Name (E2) = Chars (E1))
15912 or else
15913 (not Is_Internal_Name (Chars (E2))
15914 and then Is_Internal_Name (Chars (E1))
15915 and then Non_Internal_Name (E1) = Chars (E2))
15916 or else
15917 (Is_Predefined_Dispatching_Operation (E1)
15918 and then Is_Predefined_Dispatching_Operation (E2)
15919 and then Same_TSS (E1, E2))
15920 or else
15921 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
15922 end Primitive_Names_Match;
15924 -----------------------
15925 -- Process_End_Label --
15926 -----------------------
15928 procedure Process_End_Label
15929 (N : Node_Id;
15930 Typ : Character;
15931 Ent : Entity_Id)
15933 Loc : Source_Ptr;
15934 Nam : Node_Id;
15935 Scop : Entity_Id;
15937 Label_Ref : Boolean;
15938 -- Set True if reference to end label itself is required
15940 Endl : Node_Id;
15941 -- Gets set to the operator symbol or identifier that references the
15942 -- entity Ent. For the child unit case, this is the identifier from the
15943 -- designator. For other cases, this is simply Endl.
15945 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
15946 -- N is an identifier node that appears as a parent unit reference in
15947 -- the case where Ent is a child unit. This procedure generates an
15948 -- appropriate cross-reference entry. E is the corresponding entity.
15950 -------------------------
15951 -- Generate_Parent_Ref --
15952 -------------------------
15954 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
15955 begin
15956 -- If names do not match, something weird, skip reference
15958 if Chars (E) = Chars (N) then
15960 -- Generate the reference. We do NOT consider this as a reference
15961 -- for unreferenced symbol purposes.
15963 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
15965 if Style_Check then
15966 Style.Check_Identifier (N, E);
15967 end if;
15968 end if;
15969 end Generate_Parent_Ref;
15971 -- Start of processing for Process_End_Label
15973 begin
15974 -- If no node, ignore. This happens in some error situations, and
15975 -- also for some internally generated structures where no end label
15976 -- references are required in any case.
15978 if No (N) then
15979 return;
15980 end if;
15982 -- Nothing to do if no End_Label, happens for internally generated
15983 -- constructs where we don't want an end label reference anyway. Also
15984 -- nothing to do if Endl is a string literal, which means there was
15985 -- some prior error (bad operator symbol)
15987 Endl := End_Label (N);
15989 if No (Endl) or else Nkind (Endl) = N_String_Literal then
15990 return;
15991 end if;
15993 -- Reference node is not in extended main source unit
15995 if not In_Extended_Main_Source_Unit (N) then
15997 -- Generally we do not collect references except for the extended
15998 -- main source unit. The one exception is the 'e' entry for a
15999 -- package spec, where it is useful for a client to have the
16000 -- ending information to define scopes.
16002 if Typ /= 'e' then
16003 return;
16005 else
16006 Label_Ref := False;
16008 -- For this case, we can ignore any parent references, but we
16009 -- need the package name itself for the 'e' entry.
16011 if Nkind (Endl) = N_Designator then
16012 Endl := Identifier (Endl);
16013 end if;
16014 end if;
16016 -- Reference is in extended main source unit
16018 else
16019 Label_Ref := True;
16021 -- For designator, generate references for the parent entries
16023 if Nkind (Endl) = N_Designator then
16025 -- Generate references for the prefix if the END line comes from
16026 -- source (otherwise we do not need these references) We climb the
16027 -- scope stack to find the expected entities.
16029 if Comes_From_Source (Endl) then
16030 Nam := Name (Endl);
16031 Scop := Current_Scope;
16032 while Nkind (Nam) = N_Selected_Component loop
16033 Scop := Scope (Scop);
16034 exit when No (Scop);
16035 Generate_Parent_Ref (Selector_Name (Nam), Scop);
16036 Nam := Prefix (Nam);
16037 end loop;
16039 if Present (Scop) then
16040 Generate_Parent_Ref (Nam, Scope (Scop));
16041 end if;
16042 end if;
16044 Endl := Identifier (Endl);
16045 end if;
16046 end if;
16048 -- If the end label is not for the given entity, then either we have
16049 -- some previous error, or this is a generic instantiation for which
16050 -- we do not need to make a cross-reference in this case anyway. In
16051 -- either case we simply ignore the call.
16053 if Chars (Ent) /= Chars (Endl) then
16054 return;
16055 end if;
16057 -- If label was really there, then generate a normal reference and then
16058 -- adjust the location in the end label to point past the name (which
16059 -- should almost always be the semicolon).
16061 Loc := Sloc (Endl);
16063 if Comes_From_Source (Endl) then
16065 -- If a label reference is required, then do the style check and
16066 -- generate an l-type cross-reference entry for the label
16068 if Label_Ref then
16069 if Style_Check then
16070 Style.Check_Identifier (Endl, Ent);
16071 end if;
16073 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
16074 end if;
16076 -- Set the location to point past the label (normally this will
16077 -- mean the semicolon immediately following the label). This is
16078 -- done for the sake of the 'e' or 't' entry generated below.
16080 Get_Decoded_Name_String (Chars (Endl));
16081 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
16083 else
16084 -- In SPARK mode, no missing label is allowed for packages and
16085 -- subprogram bodies. Detect those cases by testing whether
16086 -- Process_End_Label was called for a body (Typ = 't') or a package.
16088 if Restriction_Check_Required (SPARK_05)
16089 and then (Typ = 't' or else Ekind (Ent) = E_Package)
16090 then
16091 Error_Msg_Node_1 := Endl;
16092 Check_SPARK_05_Restriction
16093 ("`END &` required", Endl, Force => True);
16094 end if;
16095 end if;
16097 -- Now generate the e/t reference
16099 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
16101 -- Restore Sloc, in case modified above, since we have an identifier
16102 -- and the normal Sloc should be left set in the tree.
16104 Set_Sloc (Endl, Loc);
16105 end Process_End_Label;
16107 ----------------
16108 -- Referenced --
16109 ----------------
16111 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
16112 Seen : Boolean := False;
16114 function Is_Reference (N : Node_Id) return Traverse_Result;
16115 -- Determine whether node N denotes a reference to Id. If this is the
16116 -- case, set global flag Seen to True and stop the traversal.
16118 ------------------
16119 -- Is_Reference --
16120 ------------------
16122 function Is_Reference (N : Node_Id) return Traverse_Result is
16123 begin
16124 if Is_Entity_Name (N)
16125 and then Present (Entity (N))
16126 and then Entity (N) = Id
16127 then
16128 Seen := True;
16129 return Abandon;
16130 else
16131 return OK;
16132 end if;
16133 end Is_Reference;
16135 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
16137 -- Start of processing for Referenced
16139 begin
16140 Inspect_Expression (Expr);
16141 return Seen;
16142 end Referenced;
16144 ------------------------------------
16145 -- References_Generic_Formal_Type --
16146 ------------------------------------
16148 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
16150 function Process (N : Node_Id) return Traverse_Result;
16151 -- Process one node in search for generic formal type
16153 -------------
16154 -- Process --
16155 -------------
16157 function Process (N : Node_Id) return Traverse_Result is
16158 begin
16159 if Nkind (N) in N_Has_Entity then
16160 declare
16161 E : constant Entity_Id := Entity (N);
16162 begin
16163 if Present (E) then
16164 if Is_Generic_Type (E) then
16165 return Abandon;
16166 elsif Present (Etype (E))
16167 and then Is_Generic_Type (Etype (E))
16168 then
16169 return Abandon;
16170 end if;
16171 end if;
16172 end;
16173 end if;
16175 return Atree.OK;
16176 end Process;
16178 function Traverse is new Traverse_Func (Process);
16179 -- Traverse tree to look for generic type
16181 begin
16182 if Inside_A_Generic then
16183 return Traverse (N) = Abandon;
16184 else
16185 return False;
16186 end if;
16187 end References_Generic_Formal_Type;
16189 --------------------
16190 -- Remove_Homonym --
16191 --------------------
16193 procedure Remove_Homonym (E : Entity_Id) is
16194 Prev : Entity_Id := Empty;
16195 H : Entity_Id;
16197 begin
16198 if E = Current_Entity (E) then
16199 if Present (Homonym (E)) then
16200 Set_Current_Entity (Homonym (E));
16201 else
16202 Set_Name_Entity_Id (Chars (E), Empty);
16203 end if;
16205 else
16206 H := Current_Entity (E);
16207 while Present (H) and then H /= E loop
16208 Prev := H;
16209 H := Homonym (H);
16210 end loop;
16212 -- If E is not on the homonym chain, nothing to do
16214 if Present (H) then
16215 Set_Homonym (Prev, Homonym (E));
16216 end if;
16217 end if;
16218 end Remove_Homonym;
16220 ---------------------
16221 -- Rep_To_Pos_Flag --
16222 ---------------------
16224 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
16225 begin
16226 return New_Occurrence_Of
16227 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
16228 end Rep_To_Pos_Flag;
16230 --------------------
16231 -- Require_Entity --
16232 --------------------
16234 procedure Require_Entity (N : Node_Id) is
16235 begin
16236 if Is_Entity_Name (N) and then No (Entity (N)) then
16237 if Total_Errors_Detected /= 0 then
16238 Set_Entity (N, Any_Id);
16239 else
16240 raise Program_Error;
16241 end if;
16242 end if;
16243 end Require_Entity;
16245 -------------------------------
16246 -- Requires_State_Refinement --
16247 -------------------------------
16249 function Requires_State_Refinement
16250 (Spec_Id : Entity_Id;
16251 Body_Id : Entity_Id) return Boolean
16253 function Mode_Is_Off (Prag : Node_Id) return Boolean;
16254 -- Given pragma SPARK_Mode, determine whether the mode is Off
16256 -----------------
16257 -- Mode_Is_Off --
16258 -----------------
16260 function Mode_Is_Off (Prag : Node_Id) return Boolean is
16261 Mode : Node_Id;
16263 begin
16264 -- The default SPARK mode is On
16266 if No (Prag) then
16267 return False;
16268 end if;
16270 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
16272 -- Then the pragma lacks an argument, the default mode is On
16274 if No (Mode) then
16275 return False;
16276 else
16277 return Chars (Mode) = Name_Off;
16278 end if;
16279 end Mode_Is_Off;
16281 -- Start of processing for Requires_State_Refinement
16283 begin
16284 -- A package that does not define at least one abstract state cannot
16285 -- possibly require refinement.
16287 if No (Abstract_States (Spec_Id)) then
16288 return False;
16290 -- The package instroduces a single null state which does not merit
16291 -- refinement.
16293 elsif Has_Null_Abstract_State (Spec_Id) then
16294 return False;
16296 -- Check whether the package body is subject to pragma SPARK_Mode. If
16297 -- it is and the mode is Off, the package body is considered to be in
16298 -- regular Ada and does not require refinement.
16300 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
16301 return False;
16303 -- The body's SPARK_Mode may be inherited from a similar pragma that
16304 -- appears in the private declarations of the spec. The pragma we are
16305 -- interested appears as the second entry in SPARK_Pragma.
16307 elsif Present (SPARK_Pragma (Spec_Id))
16308 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
16309 then
16310 return False;
16312 -- The spec defines at least one abstract state and the body has no way
16313 -- of circumventing the refinement.
16315 else
16316 return True;
16317 end if;
16318 end Requires_State_Refinement;
16320 ------------------------------
16321 -- Requires_Transient_Scope --
16322 ------------------------------
16324 -- A transient scope is required when variable-sized temporaries are
16325 -- allocated in the primary or secondary stack, or when finalization
16326 -- actions must be generated before the next instruction.
16328 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
16329 Typ : constant Entity_Id := Underlying_Type (Id);
16331 -- Start of processing for Requires_Transient_Scope
16333 begin
16334 -- This is a private type which is not completed yet. This can only
16335 -- happen in a default expression (of a formal parameter or of a
16336 -- record component). Do not expand transient scope in this case
16338 if No (Typ) then
16339 return False;
16341 -- Do not expand transient scope for non-existent procedure return
16343 elsif Typ = Standard_Void_Type then
16344 return False;
16346 -- Elementary types do not require a transient scope
16348 elsif Is_Elementary_Type (Typ) then
16349 return False;
16351 -- Generally, indefinite subtypes require a transient scope, since the
16352 -- back end cannot generate temporaries, since this is not a valid type
16353 -- for declaring an object. It might be possible to relax this in the
16354 -- future, e.g. by declaring the maximum possible space for the type.
16356 elsif Is_Indefinite_Subtype (Typ) then
16357 return True;
16359 -- Functions returning tagged types may dispatch on result so their
16360 -- returned value is allocated on the secondary stack. Controlled
16361 -- type temporaries need finalization.
16363 elsif Is_Tagged_Type (Typ)
16364 or else Has_Controlled_Component (Typ)
16365 then
16366 return not Is_Value_Type (Typ);
16368 -- Record type
16370 elsif Is_Record_Type (Typ) then
16371 declare
16372 Comp : Entity_Id;
16373 begin
16374 Comp := First_Entity (Typ);
16375 while Present (Comp) loop
16376 if Ekind (Comp) = E_Component
16377 and then Requires_Transient_Scope (Etype (Comp))
16378 then
16379 return True;
16380 else
16381 Next_Entity (Comp);
16382 end if;
16383 end loop;
16384 end;
16386 return False;
16388 -- String literal types never require transient scope
16390 elsif Ekind (Typ) = E_String_Literal_Subtype then
16391 return False;
16393 -- Array type. Note that we already know that this is a constrained
16394 -- array, since unconstrained arrays will fail the indefinite test.
16396 elsif Is_Array_Type (Typ) then
16398 -- If component type requires a transient scope, the array does too
16400 if Requires_Transient_Scope (Component_Type (Typ)) then
16401 return True;
16403 -- Otherwise, we only need a transient scope if the size depends on
16404 -- the value of one or more discriminants.
16406 else
16407 return Size_Depends_On_Discriminant (Typ);
16408 end if;
16410 -- All other cases do not require a transient scope
16412 else
16413 return False;
16414 end if;
16415 end Requires_Transient_Scope;
16417 --------------------------
16418 -- Reset_Analyzed_Flags --
16419 --------------------------
16421 procedure Reset_Analyzed_Flags (N : Node_Id) is
16423 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
16424 -- Function used to reset Analyzed flags in tree. Note that we do
16425 -- not reset Analyzed flags in entities, since there is no need to
16426 -- reanalyze entities, and indeed, it is wrong to do so, since it
16427 -- can result in generating auxiliary stuff more than once.
16429 --------------------
16430 -- Clear_Analyzed --
16431 --------------------
16433 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
16434 begin
16435 if not Has_Extension (N) then
16436 Set_Analyzed (N, False);
16437 end if;
16439 return OK;
16440 end Clear_Analyzed;
16442 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
16444 -- Start of processing for Reset_Analyzed_Flags
16446 begin
16447 Reset_Analyzed (N);
16448 end Reset_Analyzed_Flags;
16450 ------------------------
16451 -- Restore_SPARK_Mode --
16452 ------------------------
16454 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
16455 begin
16456 SPARK_Mode := Mode;
16457 end Restore_SPARK_Mode;
16459 --------------------------------
16460 -- Returns_Unconstrained_Type --
16461 --------------------------------
16463 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
16464 begin
16465 return Ekind (Subp) = E_Function
16466 and then not Is_Scalar_Type (Etype (Subp))
16467 and then not Is_Access_Type (Etype (Subp))
16468 and then not Is_Constrained (Etype (Subp));
16469 end Returns_Unconstrained_Type;
16471 ----------------------------
16472 -- Root_Type_Of_Full_View --
16473 ----------------------------
16475 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
16476 Rtyp : constant Entity_Id := Root_Type (T);
16478 begin
16479 -- The root type of the full view may itself be a private type. Keep
16480 -- looking for the ultimate derivation parent.
16482 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
16483 return Root_Type_Of_Full_View (Full_View (Rtyp));
16484 else
16485 return Rtyp;
16486 end if;
16487 end Root_Type_Of_Full_View;
16489 ---------------------------
16490 -- Safe_To_Capture_Value --
16491 ---------------------------
16493 function Safe_To_Capture_Value
16494 (N : Node_Id;
16495 Ent : Entity_Id;
16496 Cond : Boolean := False) return Boolean
16498 begin
16499 -- The only entities for which we track constant values are variables
16500 -- which are not renamings, constants, out parameters, and in out
16501 -- parameters, so check if we have this case.
16503 -- Note: it may seem odd to track constant values for constants, but in
16504 -- fact this routine is used for other purposes than simply capturing
16505 -- the value. In particular, the setting of Known[_Non]_Null.
16507 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
16508 or else
16509 Ekind_In (Ent, E_Constant, E_Out_Parameter, E_In_Out_Parameter)
16510 then
16511 null;
16513 -- For conditionals, we also allow loop parameters and all formals,
16514 -- including in parameters.
16516 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
16517 null;
16519 -- For all other cases, not just unsafe, but impossible to capture
16520 -- Current_Value, since the above are the only entities which have
16521 -- Current_Value fields.
16523 else
16524 return False;
16525 end if;
16527 -- Skip if volatile or aliased, since funny things might be going on in
16528 -- these cases which we cannot necessarily track. Also skip any variable
16529 -- for which an address clause is given, or whose address is taken. Also
16530 -- never capture value of library level variables (an attempt to do so
16531 -- can occur in the case of package elaboration code).
16533 if Treat_As_Volatile (Ent)
16534 or else Is_Aliased (Ent)
16535 or else Present (Address_Clause (Ent))
16536 or else Address_Taken (Ent)
16537 or else (Is_Library_Level_Entity (Ent)
16538 and then Ekind (Ent) = E_Variable)
16539 then
16540 return False;
16541 end if;
16543 -- OK, all above conditions are met. We also require that the scope of
16544 -- the reference be the same as the scope of the entity, not counting
16545 -- packages and blocks and loops.
16547 declare
16548 E_Scope : constant Entity_Id := Scope (Ent);
16549 R_Scope : Entity_Id;
16551 begin
16552 R_Scope := Current_Scope;
16553 while R_Scope /= Standard_Standard loop
16554 exit when R_Scope = E_Scope;
16556 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
16557 return False;
16558 else
16559 R_Scope := Scope (R_Scope);
16560 end if;
16561 end loop;
16562 end;
16564 -- We also require that the reference does not appear in a context
16565 -- where it is not sure to be executed (i.e. a conditional context
16566 -- or an exception handler). We skip this if Cond is True, since the
16567 -- capturing of values from conditional tests handles this ok.
16569 if Cond then
16570 return True;
16571 end if;
16573 declare
16574 Desc : Node_Id;
16575 P : Node_Id;
16577 begin
16578 Desc := N;
16580 -- Seems dubious that case expressions are not handled here ???
16582 P := Parent (N);
16583 while Present (P) loop
16584 if Nkind (P) = N_If_Statement
16585 or else Nkind (P) = N_Case_Statement
16586 or else (Nkind (P) in N_Short_Circuit
16587 and then Desc = Right_Opnd (P))
16588 or else (Nkind (P) = N_If_Expression
16589 and then Desc /= First (Expressions (P)))
16590 or else Nkind (P) = N_Exception_Handler
16591 or else Nkind (P) = N_Selective_Accept
16592 or else Nkind (P) = N_Conditional_Entry_Call
16593 or else Nkind (P) = N_Timed_Entry_Call
16594 or else Nkind (P) = N_Asynchronous_Select
16595 then
16596 return False;
16598 else
16599 Desc := P;
16600 P := Parent (P);
16602 -- A special Ada 2012 case: the original node may be part
16603 -- of the else_actions of a conditional expression, in which
16604 -- case it might not have been expanded yet, and appears in
16605 -- a non-syntactic list of actions. In that case it is clearly
16606 -- not safe to save a value.
16608 if No (P)
16609 and then Is_List_Member (Desc)
16610 and then No (Parent (List_Containing (Desc)))
16611 then
16612 return False;
16613 end if;
16614 end if;
16615 end loop;
16616 end;
16618 -- OK, looks safe to set value
16620 return True;
16621 end Safe_To_Capture_Value;
16623 ---------------
16624 -- Same_Name --
16625 ---------------
16627 function Same_Name (N1, N2 : Node_Id) return Boolean is
16628 K1 : constant Node_Kind := Nkind (N1);
16629 K2 : constant Node_Kind := Nkind (N2);
16631 begin
16632 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
16633 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
16634 then
16635 return Chars (N1) = Chars (N2);
16637 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
16638 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
16639 then
16640 return Same_Name (Selector_Name (N1), Selector_Name (N2))
16641 and then Same_Name (Prefix (N1), Prefix (N2));
16643 else
16644 return False;
16645 end if;
16646 end Same_Name;
16648 -----------------
16649 -- Same_Object --
16650 -----------------
16652 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
16653 N1 : constant Node_Id := Original_Node (Node1);
16654 N2 : constant Node_Id := Original_Node (Node2);
16655 -- We do the tests on original nodes, since we are most interested
16656 -- in the original source, not any expansion that got in the way.
16658 K1 : constant Node_Kind := Nkind (N1);
16659 K2 : constant Node_Kind := Nkind (N2);
16661 begin
16662 -- First case, both are entities with same entity
16664 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
16665 declare
16666 EN1 : constant Entity_Id := Entity (N1);
16667 EN2 : constant Entity_Id := Entity (N2);
16668 begin
16669 if Present (EN1) and then Present (EN2)
16670 and then (Ekind_In (EN1, E_Variable, E_Constant)
16671 or else Is_Formal (EN1))
16672 and then EN1 = EN2
16673 then
16674 return True;
16675 end if;
16676 end;
16677 end if;
16679 -- Second case, selected component with same selector, same record
16681 if K1 = N_Selected_Component
16682 and then K2 = N_Selected_Component
16683 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
16684 then
16685 return Same_Object (Prefix (N1), Prefix (N2));
16687 -- Third case, indexed component with same subscripts, same array
16689 elsif K1 = N_Indexed_Component
16690 and then K2 = N_Indexed_Component
16691 and then Same_Object (Prefix (N1), Prefix (N2))
16692 then
16693 declare
16694 E1, E2 : Node_Id;
16695 begin
16696 E1 := First (Expressions (N1));
16697 E2 := First (Expressions (N2));
16698 while Present (E1) loop
16699 if not Same_Value (E1, E2) then
16700 return False;
16701 else
16702 Next (E1);
16703 Next (E2);
16704 end if;
16705 end loop;
16707 return True;
16708 end;
16710 -- Fourth case, slice of same array with same bounds
16712 elsif K1 = N_Slice
16713 and then K2 = N_Slice
16714 and then Nkind (Discrete_Range (N1)) = N_Range
16715 and then Nkind (Discrete_Range (N2)) = N_Range
16716 and then Same_Value (Low_Bound (Discrete_Range (N1)),
16717 Low_Bound (Discrete_Range (N2)))
16718 and then Same_Value (High_Bound (Discrete_Range (N1)),
16719 High_Bound (Discrete_Range (N2)))
16720 then
16721 return Same_Name (Prefix (N1), Prefix (N2));
16723 -- All other cases, not clearly the same object
16725 else
16726 return False;
16727 end if;
16728 end Same_Object;
16730 ---------------
16731 -- Same_Type --
16732 ---------------
16734 function Same_Type (T1, T2 : Entity_Id) return Boolean is
16735 begin
16736 if T1 = T2 then
16737 return True;
16739 elsif not Is_Constrained (T1)
16740 and then not Is_Constrained (T2)
16741 and then Base_Type (T1) = Base_Type (T2)
16742 then
16743 return True;
16745 -- For now don't bother with case of identical constraints, to be
16746 -- fiddled with later on perhaps (this is only used for optimization
16747 -- purposes, so it is not critical to do a best possible job)
16749 else
16750 return False;
16751 end if;
16752 end Same_Type;
16754 ----------------
16755 -- Same_Value --
16756 ----------------
16758 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
16759 begin
16760 if Compile_Time_Known_Value (Node1)
16761 and then Compile_Time_Known_Value (Node2)
16762 and then Expr_Value (Node1) = Expr_Value (Node2)
16763 then
16764 return True;
16765 elsif Same_Object (Node1, Node2) then
16766 return True;
16767 else
16768 return False;
16769 end if;
16770 end Same_Value;
16772 -----------------------------
16773 -- Save_SPARK_Mode_And_Set --
16774 -----------------------------
16776 procedure Save_SPARK_Mode_And_Set
16777 (Context : Entity_Id;
16778 Mode : out SPARK_Mode_Type)
16780 begin
16781 -- Save the current mode in effect
16783 Mode := SPARK_Mode;
16785 -- Do not consider illegal or partially decorated constructs
16787 if Ekind (Context) = E_Void or else Error_Posted (Context) then
16788 null;
16790 elsif Present (SPARK_Pragma (Context)) then
16791 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
16792 end if;
16793 end Save_SPARK_Mode_And_Set;
16795 -------------------------
16796 -- Scalar_Part_Present --
16797 -------------------------
16799 function Scalar_Part_Present (T : Entity_Id) return Boolean is
16800 C : Entity_Id;
16802 begin
16803 if Is_Scalar_Type (T) then
16804 return True;
16806 elsif Is_Array_Type (T) then
16807 return Scalar_Part_Present (Component_Type (T));
16809 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
16810 C := First_Component_Or_Discriminant (T);
16811 while Present (C) loop
16812 if Scalar_Part_Present (Etype (C)) then
16813 return True;
16814 else
16815 Next_Component_Or_Discriminant (C);
16816 end if;
16817 end loop;
16818 end if;
16820 return False;
16821 end Scalar_Part_Present;
16823 ------------------------
16824 -- Scope_Is_Transient --
16825 ------------------------
16827 function Scope_Is_Transient return Boolean is
16828 begin
16829 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
16830 end Scope_Is_Transient;
16832 ------------------
16833 -- Scope_Within --
16834 ------------------
16836 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
16837 Scop : Entity_Id;
16839 begin
16840 Scop := Scope1;
16841 while Scop /= Standard_Standard loop
16842 Scop := Scope (Scop);
16844 if Scop = Scope2 then
16845 return True;
16846 end if;
16847 end loop;
16849 return False;
16850 end Scope_Within;
16852 --------------------------
16853 -- Scope_Within_Or_Same --
16854 --------------------------
16856 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
16857 Scop : Entity_Id;
16859 begin
16860 Scop := Scope1;
16861 while Scop /= Standard_Standard loop
16862 if Scop = Scope2 then
16863 return True;
16864 else
16865 Scop := Scope (Scop);
16866 end if;
16867 end loop;
16869 return False;
16870 end Scope_Within_Or_Same;
16872 --------------------
16873 -- Set_Convention --
16874 --------------------
16876 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
16877 begin
16878 Basic_Set_Convention (E, Val);
16880 if Is_Type (E)
16881 and then Is_Access_Subprogram_Type (Base_Type (E))
16882 and then Has_Foreign_Convention (E)
16883 then
16884 Set_Can_Use_Internal_Rep (E, False);
16885 end if;
16887 -- If E is an object or component, and the type of E is an anonymous
16888 -- access type with no convention set, then also set the convention of
16889 -- the anonymous access type. We do not do this for anonymous protected
16890 -- types, since protected types always have the default convention.
16892 if Present (Etype (E))
16893 and then (Is_Object (E)
16894 or else Ekind (E) = E_Component
16896 -- Allow E_Void (happens for pragma Convention appearing
16897 -- in the middle of a record applying to a component)
16899 or else Ekind (E) = E_Void)
16900 then
16901 declare
16902 Typ : constant Entity_Id := Etype (E);
16904 begin
16905 if Ekind_In (Typ, E_Anonymous_Access_Type,
16906 E_Anonymous_Access_Subprogram_Type)
16907 and then not Has_Convention_Pragma (Typ)
16908 then
16909 Basic_Set_Convention (Typ, Val);
16910 Set_Has_Convention_Pragma (Typ);
16912 -- And for the access subprogram type, deal similarly with the
16913 -- designated E_Subprogram_Type if it is also internal (which
16914 -- it always is?)
16916 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
16917 declare
16918 Dtype : constant Entity_Id := Designated_Type (Typ);
16919 begin
16920 if Ekind (Dtype) = E_Subprogram_Type
16921 and then Is_Itype (Dtype)
16922 and then not Has_Convention_Pragma (Dtype)
16923 then
16924 Basic_Set_Convention (Dtype, Val);
16925 Set_Has_Convention_Pragma (Dtype);
16926 end if;
16927 end;
16928 end if;
16929 end if;
16930 end;
16931 end if;
16932 end Set_Convention;
16934 ------------------------
16935 -- Set_Current_Entity --
16936 ------------------------
16938 -- The given entity is to be set as the currently visible definition of its
16939 -- associated name (i.e. the Node_Id associated with its name). All we have
16940 -- to do is to get the name from the identifier, and then set the
16941 -- associated Node_Id to point to the given entity.
16943 procedure Set_Current_Entity (E : Entity_Id) is
16944 begin
16945 Set_Name_Entity_Id (Chars (E), E);
16946 end Set_Current_Entity;
16948 ---------------------------
16949 -- Set_Debug_Info_Needed --
16950 ---------------------------
16952 procedure Set_Debug_Info_Needed (T : Entity_Id) is
16954 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
16955 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
16956 -- Used to set debug info in a related node if not set already
16958 --------------------------------------
16959 -- Set_Debug_Info_Needed_If_Not_Set --
16960 --------------------------------------
16962 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
16963 begin
16964 if Present (E) and then not Needs_Debug_Info (E) then
16965 Set_Debug_Info_Needed (E);
16967 -- For a private type, indicate that the full view also needs
16968 -- debug information.
16970 if Is_Type (E)
16971 and then Is_Private_Type (E)
16972 and then Present (Full_View (E))
16973 then
16974 Set_Debug_Info_Needed (Full_View (E));
16975 end if;
16976 end if;
16977 end Set_Debug_Info_Needed_If_Not_Set;
16979 -- Start of processing for Set_Debug_Info_Needed
16981 begin
16982 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16983 -- indicates that Debug_Info_Needed is never required for the entity.
16984 -- Nothing to do if entity comes from a predefined file. Library files
16985 -- are compiled without debug information, but inlined bodies of these
16986 -- routines may appear in user code, and debug information on them ends
16987 -- up complicating debugging the user code.
16989 if No (T)
16990 or else Debug_Info_Off (T)
16991 then
16992 return;
16994 elsif In_Inlined_Body
16995 and then Is_Predefined_File_Name
16996 (Unit_File_Name (Get_Source_Unit (Sloc (T))))
16997 then
16998 Set_Needs_Debug_Info (T, False);
16999 end if;
17001 -- Set flag in entity itself. Note that we will go through the following
17002 -- circuitry even if the flag is already set on T. That's intentional,
17003 -- it makes sure that the flag will be set in subsidiary entities.
17005 Set_Needs_Debug_Info (T);
17007 -- Set flag on subsidiary entities if not set already
17009 if Is_Object (T) then
17010 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
17012 elsif Is_Type (T) then
17013 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
17015 if Is_Record_Type (T) then
17016 declare
17017 Ent : Entity_Id := First_Entity (T);
17018 begin
17019 while Present (Ent) loop
17020 Set_Debug_Info_Needed_If_Not_Set (Ent);
17021 Next_Entity (Ent);
17022 end loop;
17023 end;
17025 -- For a class wide subtype, we also need debug information
17026 -- for the equivalent type.
17028 if Ekind (T) = E_Class_Wide_Subtype then
17029 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
17030 end if;
17032 elsif Is_Array_Type (T) then
17033 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
17035 declare
17036 Indx : Node_Id := First_Index (T);
17037 begin
17038 while Present (Indx) loop
17039 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
17040 Indx := Next_Index (Indx);
17041 end loop;
17042 end;
17044 -- For a packed array type, we also need debug information for
17045 -- the type used to represent the packed array. Conversely, we
17046 -- also need it for the former if we need it for the latter.
17048 if Is_Packed (T) then
17049 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
17050 end if;
17052 if Is_Packed_Array_Impl_Type (T) then
17053 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
17054 end if;
17056 elsif Is_Access_Type (T) then
17057 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
17059 elsif Is_Private_Type (T) then
17060 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
17062 elsif Is_Protected_Type (T) then
17063 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
17065 elsif Is_Scalar_Type (T) then
17067 -- If the subrange bounds are materialized by dedicated constant
17068 -- objects, also include them in the debug info to make sure the
17069 -- debugger can properly use them.
17071 if Present (Scalar_Range (T))
17072 and then Nkind (Scalar_Range (T)) = N_Range
17073 then
17074 declare
17075 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
17076 High_Bnd : constant Node_Id := Type_High_Bound (T);
17078 begin
17079 if Is_Entity_Name (Low_Bnd) then
17080 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
17081 end if;
17083 if Is_Entity_Name (High_Bnd) then
17084 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
17085 end if;
17086 end;
17087 end if;
17088 end if;
17089 end if;
17090 end Set_Debug_Info_Needed;
17092 ----------------------------
17093 -- Set_Entity_With_Checks --
17094 ----------------------------
17096 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
17097 Val_Actual : Entity_Id;
17098 Nod : Node_Id;
17099 Post_Node : Node_Id;
17101 begin
17102 -- Unconditionally set the entity
17104 Set_Entity (N, Val);
17106 -- The node to post on is the selector in the case of an expanded name,
17107 -- and otherwise the node itself.
17109 if Nkind (N) = N_Expanded_Name then
17110 Post_Node := Selector_Name (N);
17111 else
17112 Post_Node := N;
17113 end if;
17115 -- Check for violation of No_Fixed_IO
17117 if Restriction_Check_Required (No_Fixed_IO)
17118 and then
17119 ((RTU_Loaded (Ada_Text_IO)
17120 and then (Is_RTE (Val, RE_Decimal_IO)
17121 or else
17122 Is_RTE (Val, RE_Fixed_IO)))
17124 or else
17125 (RTU_Loaded (Ada_Wide_Text_IO)
17126 and then (Is_RTE (Val, RO_WT_Decimal_IO)
17127 or else
17128 Is_RTE (Val, RO_WT_Fixed_IO)))
17130 or else
17131 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
17132 and then (Is_RTE (Val, RO_WW_Decimal_IO)
17133 or else
17134 Is_RTE (Val, RO_WW_Fixed_IO))))
17136 -- A special extra check, don't complain about a reference from within
17137 -- the Ada.Interrupts package itself!
17139 and then not In_Same_Extended_Unit (N, Val)
17140 then
17141 Check_Restriction (No_Fixed_IO, Post_Node);
17142 end if;
17144 -- Remaining checks are only done on source nodes. Note that we test
17145 -- for violation of No_Fixed_IO even on non-source nodes, because the
17146 -- cases for checking violations of this restriction are instantiations
17147 -- where the reference in the instance has Comes_From_Source False.
17149 if not Comes_From_Source (N) then
17150 return;
17151 end if;
17153 -- Check for violation of No_Abort_Statements, which is triggered by
17154 -- call to Ada.Task_Identification.Abort_Task.
17156 if Restriction_Check_Required (No_Abort_Statements)
17157 and then (Is_RTE (Val, RE_Abort_Task))
17159 -- A special extra check, don't complain about a reference from within
17160 -- the Ada.Task_Identification package itself!
17162 and then not In_Same_Extended_Unit (N, Val)
17163 then
17164 Check_Restriction (No_Abort_Statements, Post_Node);
17165 end if;
17167 if Val = Standard_Long_Long_Integer then
17168 Check_Restriction (No_Long_Long_Integers, Post_Node);
17169 end if;
17171 -- Check for violation of No_Dynamic_Attachment
17173 if Restriction_Check_Required (No_Dynamic_Attachment)
17174 and then RTU_Loaded (Ada_Interrupts)
17175 and then (Is_RTE (Val, RE_Is_Reserved) or else
17176 Is_RTE (Val, RE_Is_Attached) or else
17177 Is_RTE (Val, RE_Current_Handler) or else
17178 Is_RTE (Val, RE_Attach_Handler) or else
17179 Is_RTE (Val, RE_Exchange_Handler) or else
17180 Is_RTE (Val, RE_Detach_Handler) or else
17181 Is_RTE (Val, RE_Reference))
17183 -- A special extra check, don't complain about a reference from within
17184 -- the Ada.Interrupts package itself!
17186 and then not In_Same_Extended_Unit (N, Val)
17187 then
17188 Check_Restriction (No_Dynamic_Attachment, Post_Node);
17189 end if;
17191 -- Check for No_Implementation_Identifiers
17193 if Restriction_Check_Required (No_Implementation_Identifiers) then
17195 -- We have an implementation defined entity if it is marked as
17196 -- implementation defined, or is defined in a package marked as
17197 -- implementation defined. However, library packages themselves
17198 -- are excluded (we don't want to flag Interfaces itself, just
17199 -- the entities within it).
17201 if (Is_Implementation_Defined (Val)
17202 or else
17203 (Present (Scope (Val))
17204 and then Is_Implementation_Defined (Scope (Val))))
17205 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
17206 and then Is_Library_Level_Entity (Val))
17207 then
17208 Check_Restriction (No_Implementation_Identifiers, Post_Node);
17209 end if;
17210 end if;
17212 -- Do the style check
17214 if Style_Check
17215 and then not Suppress_Style_Checks (Val)
17216 and then not In_Instance
17217 then
17218 if Nkind (N) = N_Identifier then
17219 Nod := N;
17220 elsif Nkind (N) = N_Expanded_Name then
17221 Nod := Selector_Name (N);
17222 else
17223 return;
17224 end if;
17226 -- A special situation arises for derived operations, where we want
17227 -- to do the check against the parent (since the Sloc of the derived
17228 -- operation points to the derived type declaration itself).
17230 Val_Actual := Val;
17231 while not Comes_From_Source (Val_Actual)
17232 and then Nkind (Val_Actual) in N_Entity
17233 and then (Ekind (Val_Actual) = E_Enumeration_Literal
17234 or else Is_Subprogram_Or_Generic_Subprogram (Val_Actual))
17235 and then Present (Alias (Val_Actual))
17236 loop
17237 Val_Actual := Alias (Val_Actual);
17238 end loop;
17240 -- Renaming declarations for generic actuals do not come from source,
17241 -- and have a different name from that of the entity they rename, so
17242 -- there is no style check to perform here.
17244 if Chars (Nod) = Chars (Val_Actual) then
17245 Style.Check_Identifier (Nod, Val_Actual);
17246 end if;
17247 end if;
17249 Set_Entity (N, Val);
17250 end Set_Entity_With_Checks;
17252 -------------------------
17253 -- Set_Is_Ghost_Entity --
17254 -------------------------
17256 procedure Set_Is_Ghost_Entity (Id : Entity_Id) is
17257 Policy : constant Name_Id := Policy_In_Effect (Name_Ghost);
17259 begin
17260 if Policy = Name_Check then
17261 Set_Is_Checked_Ghost_Entity (Id);
17263 elsif Policy = Name_Ignore then
17264 Set_Is_Ignored_Ghost_Entity (Id);
17265 end if;
17266 end Set_Is_Ghost_Entity;
17268 ------------------------
17269 -- Set_Name_Entity_Id --
17270 ------------------------
17272 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
17273 begin
17274 Set_Name_Table_Info (Id, Int (Val));
17275 end Set_Name_Entity_Id;
17277 ---------------------
17278 -- Set_Next_Actual --
17279 ---------------------
17281 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
17282 begin
17283 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
17284 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
17285 end if;
17286 end Set_Next_Actual;
17288 ----------------------------------
17289 -- Set_Optimize_Alignment_Flags --
17290 ----------------------------------
17292 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
17293 begin
17294 if Optimize_Alignment = 'S' then
17295 Set_Optimize_Alignment_Space (E);
17296 elsif Optimize_Alignment = 'T' then
17297 Set_Optimize_Alignment_Time (E);
17298 end if;
17299 end Set_Optimize_Alignment_Flags;
17301 -----------------------
17302 -- Set_Public_Status --
17303 -----------------------
17305 procedure Set_Public_Status (Id : Entity_Id) is
17306 S : constant Entity_Id := Current_Scope;
17308 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
17309 -- Determines if E is defined within handled statement sequence or
17310 -- an if statement, returns True if so, False otherwise.
17312 ----------------------
17313 -- Within_HSS_Or_If --
17314 ----------------------
17316 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
17317 N : Node_Id;
17318 begin
17319 N := Declaration_Node (E);
17320 loop
17321 N := Parent (N);
17323 if No (N) then
17324 return False;
17326 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
17327 N_If_Statement)
17328 then
17329 return True;
17330 end if;
17331 end loop;
17332 end Within_HSS_Or_If;
17334 -- Start of processing for Set_Public_Status
17336 begin
17337 -- Everything in the scope of Standard is public
17339 if S = Standard_Standard then
17340 Set_Is_Public (Id);
17342 -- Entity is definitely not public if enclosing scope is not public
17344 elsif not Is_Public (S) then
17345 return;
17347 -- An object or function declaration that occurs in a handled sequence
17348 -- of statements or within an if statement is the declaration for a
17349 -- temporary object or local subprogram generated by the expander. It
17350 -- never needs to be made public and furthermore, making it public can
17351 -- cause back end problems.
17353 elsif Nkind_In (Parent (Id), N_Object_Declaration,
17354 N_Function_Specification)
17355 and then Within_HSS_Or_If (Id)
17356 then
17357 return;
17359 -- Entities in public packages or records are public
17361 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
17362 Set_Is_Public (Id);
17364 -- The bounds of an entry family declaration can generate object
17365 -- declarations that are visible to the back-end, e.g. in the
17366 -- the declaration of a composite type that contains tasks.
17368 elsif Is_Concurrent_Type (S)
17369 and then not Has_Completion (S)
17370 and then Nkind (Parent (Id)) = N_Object_Declaration
17371 then
17372 Set_Is_Public (Id);
17373 end if;
17374 end Set_Public_Status;
17376 -----------------------------
17377 -- Set_Referenced_Modified --
17378 -----------------------------
17380 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
17381 Pref : Node_Id;
17383 begin
17384 -- Deal with indexed or selected component where prefix is modified
17386 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
17387 Pref := Prefix (N);
17389 -- If prefix is access type, then it is the designated object that is
17390 -- being modified, which means we have no entity to set the flag on.
17392 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
17393 return;
17395 -- Otherwise chase the prefix
17397 else
17398 Set_Referenced_Modified (Pref, Out_Param);
17399 end if;
17401 -- Otherwise see if we have an entity name (only other case to process)
17403 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
17404 Set_Referenced_As_LHS (Entity (N), not Out_Param);
17405 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
17406 end if;
17407 end Set_Referenced_Modified;
17409 ----------------------------
17410 -- Set_Scope_Is_Transient --
17411 ----------------------------
17413 procedure Set_Scope_Is_Transient (V : Boolean := True) is
17414 begin
17415 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
17416 end Set_Scope_Is_Transient;
17418 -------------------
17419 -- Set_Size_Info --
17420 -------------------
17422 procedure Set_Size_Info (T1, T2 : Entity_Id) is
17423 begin
17424 -- We copy Esize, but not RM_Size, since in general RM_Size is
17425 -- subtype specific and does not get inherited by all subtypes.
17427 Set_Esize (T1, Esize (T2));
17428 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
17430 if Is_Discrete_Or_Fixed_Point_Type (T1)
17431 and then
17432 Is_Discrete_Or_Fixed_Point_Type (T2)
17433 then
17434 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
17435 end if;
17437 Set_Alignment (T1, Alignment (T2));
17438 end Set_Size_Info;
17440 --------------------
17441 -- Static_Boolean --
17442 --------------------
17444 function Static_Boolean (N : Node_Id) return Uint is
17445 begin
17446 Analyze_And_Resolve (N, Standard_Boolean);
17448 if N = Error
17449 or else Error_Posted (N)
17450 or else Etype (N) = Any_Type
17451 then
17452 return No_Uint;
17453 end if;
17455 if Is_OK_Static_Expression (N) then
17456 if not Raises_Constraint_Error (N) then
17457 return Expr_Value (N);
17458 else
17459 return No_Uint;
17460 end if;
17462 elsif Etype (N) = Any_Type then
17463 return No_Uint;
17465 else
17466 Flag_Non_Static_Expr
17467 ("static boolean expression required here", N);
17468 return No_Uint;
17469 end if;
17470 end Static_Boolean;
17472 --------------------
17473 -- Static_Integer --
17474 --------------------
17476 function Static_Integer (N : Node_Id) return Uint is
17477 begin
17478 Analyze_And_Resolve (N, Any_Integer);
17480 if N = Error
17481 or else Error_Posted (N)
17482 or else Etype (N) = Any_Type
17483 then
17484 return No_Uint;
17485 end if;
17487 if Is_OK_Static_Expression (N) then
17488 if not Raises_Constraint_Error (N) then
17489 return Expr_Value (N);
17490 else
17491 return No_Uint;
17492 end if;
17494 elsif Etype (N) = Any_Type then
17495 return No_Uint;
17497 else
17498 Flag_Non_Static_Expr
17499 ("static integer expression required here", N);
17500 return No_Uint;
17501 end if;
17502 end Static_Integer;
17504 --------------------------
17505 -- Statically_Different --
17506 --------------------------
17508 function Statically_Different (E1, E2 : Node_Id) return Boolean is
17509 R1 : constant Node_Id := Get_Referenced_Object (E1);
17510 R2 : constant Node_Id := Get_Referenced_Object (E2);
17511 begin
17512 return Is_Entity_Name (R1)
17513 and then Is_Entity_Name (R2)
17514 and then Entity (R1) /= Entity (R2)
17515 and then not Is_Formal (Entity (R1))
17516 and then not Is_Formal (Entity (R2));
17517 end Statically_Different;
17519 --------------------------------------
17520 -- Subject_To_Loop_Entry_Attributes --
17521 --------------------------------------
17523 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
17524 Stmt : Node_Id;
17526 begin
17527 Stmt := N;
17529 -- The expansion mechanism transform a loop subject to at least one
17530 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
17531 -- the conditional part.
17533 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
17534 and then Nkind (Original_Node (N)) = N_Loop_Statement
17535 then
17536 Stmt := Original_Node (N);
17537 end if;
17539 return
17540 Nkind (Stmt) = N_Loop_Statement
17541 and then Present (Identifier (Stmt))
17542 and then Present (Entity (Identifier (Stmt)))
17543 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
17544 end Subject_To_Loop_Entry_Attributes;
17546 -----------------------------
17547 -- Subprogram_Access_Level --
17548 -----------------------------
17550 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
17551 begin
17552 if Present (Alias (Subp)) then
17553 return Subprogram_Access_Level (Alias (Subp));
17554 else
17555 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
17556 end if;
17557 end Subprogram_Access_Level;
17559 -------------------------------
17560 -- Support_Atomic_Primitives --
17561 -------------------------------
17563 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
17564 Size : Int;
17566 begin
17567 -- Verify the alignment of Typ is known
17569 if not Known_Alignment (Typ) then
17570 return False;
17571 end if;
17573 if Known_Static_Esize (Typ) then
17574 Size := UI_To_Int (Esize (Typ));
17576 -- If the Esize (Object_Size) is unknown at compile time, look at the
17577 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
17579 elsif Known_Static_RM_Size (Typ) then
17580 Size := UI_To_Int (RM_Size (Typ));
17582 -- Otherwise, the size is considered to be unknown.
17584 else
17585 return False;
17586 end if;
17588 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
17589 -- Typ is properly aligned.
17591 case Size is
17592 when 8 | 16 | 32 | 64 =>
17593 return Size = UI_To_Int (Alignment (Typ)) * 8;
17594 when others =>
17595 return False;
17596 end case;
17597 end Support_Atomic_Primitives;
17599 -----------------
17600 -- Trace_Scope --
17601 -----------------
17603 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
17604 begin
17605 if Debug_Flag_W then
17606 for J in 0 .. Scope_Stack.Last loop
17607 Write_Str (" ");
17608 end loop;
17610 Write_Str (Msg);
17611 Write_Name (Chars (E));
17612 Write_Str (" from ");
17613 Write_Location (Sloc (N));
17614 Write_Eol;
17615 end if;
17616 end Trace_Scope;
17618 -----------------------
17619 -- Transfer_Entities --
17620 -----------------------
17622 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
17623 procedure Set_Public_Status_Of (Id : Entity_Id);
17624 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
17625 -- Set_Public_Status. If successfull and Id denotes a record type, set
17626 -- the Is_Public attribute of its fields.
17628 --------------------------
17629 -- Set_Public_Status_Of --
17630 --------------------------
17632 procedure Set_Public_Status_Of (Id : Entity_Id) is
17633 Field : Entity_Id;
17635 begin
17636 if not Is_Public (Id) then
17637 Set_Public_Status (Id);
17639 -- When the input entity is a public record type, ensure that all
17640 -- its internal fields are also exposed to the linker. The fields
17641 -- of a class-wide type are never made public.
17643 if Is_Public (Id)
17644 and then Is_Record_Type (Id)
17645 and then not Is_Class_Wide_Type (Id)
17646 then
17647 Field := First_Entity (Id);
17648 while Present (Field) loop
17649 Set_Is_Public (Field);
17650 Next_Entity (Field);
17651 end loop;
17652 end if;
17653 end if;
17654 end Set_Public_Status_Of;
17656 -- Local variables
17658 Full_Id : Entity_Id;
17659 Id : Entity_Id;
17661 -- Start of processing for Transfer_Entities
17663 begin
17664 Id := First_Entity (From);
17666 if Present (Id) then
17668 -- Merge the entity chain of the source scope with that of the
17669 -- destination scope.
17671 if Present (Last_Entity (To)) then
17672 Set_Next_Entity (Last_Entity (To), Id);
17673 else
17674 Set_First_Entity (To, Id);
17675 end if;
17677 Set_Last_Entity (To, Last_Entity (From));
17679 -- Inspect the entities of the source scope and update their Scope
17680 -- attribute.
17682 while Present (Id) loop
17683 Set_Scope (Id, To);
17684 Set_Public_Status_Of (Id);
17686 -- Handle an internally generated full view for a private type
17688 if Is_Private_Type (Id)
17689 and then Present (Full_View (Id))
17690 and then Is_Itype (Full_View (Id))
17691 then
17692 Full_Id := Full_View (Id);
17694 Set_Scope (Full_Id, To);
17695 Set_Public_Status_Of (Full_Id);
17696 end if;
17698 Next_Entity (Id);
17699 end loop;
17701 Set_First_Entity (From, Empty);
17702 Set_Last_Entity (From, Empty);
17703 end if;
17704 end Transfer_Entities;
17706 -----------------------
17707 -- Type_Access_Level --
17708 -----------------------
17710 function Type_Access_Level (Typ : Entity_Id) return Uint is
17711 Btyp : Entity_Id;
17713 begin
17714 Btyp := Base_Type (Typ);
17716 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
17717 -- simply use the level where the type is declared. This is true for
17718 -- stand-alone object declarations, and for anonymous access types
17719 -- associated with components the level is the same as that of the
17720 -- enclosing composite type. However, special treatment is needed for
17721 -- the cases of access parameters, return objects of an anonymous access
17722 -- type, and, in Ada 95, access discriminants of limited types.
17724 if Is_Access_Type (Btyp) then
17725 if Ekind (Btyp) = E_Anonymous_Access_Type then
17727 -- If the type is a nonlocal anonymous access type (such as for
17728 -- an access parameter) we treat it as being declared at the
17729 -- library level to ensure that names such as X.all'access don't
17730 -- fail static accessibility checks.
17732 if not Is_Local_Anonymous_Access (Typ) then
17733 return Scope_Depth (Standard_Standard);
17735 -- If this is a return object, the accessibility level is that of
17736 -- the result subtype of the enclosing function. The test here is
17737 -- little complicated, because we have to account for extended
17738 -- return statements that have been rewritten as blocks, in which
17739 -- case we have to find and the Is_Return_Object attribute of the
17740 -- itype's associated object. It would be nice to find a way to
17741 -- simplify this test, but it doesn't seem worthwhile to add a new
17742 -- flag just for purposes of this test. ???
17744 elsif Ekind (Scope (Btyp)) = E_Return_Statement
17745 or else
17746 (Is_Itype (Btyp)
17747 and then Nkind (Associated_Node_For_Itype (Btyp)) =
17748 N_Object_Declaration
17749 and then Is_Return_Object
17750 (Defining_Identifier
17751 (Associated_Node_For_Itype (Btyp))))
17752 then
17753 declare
17754 Scop : Entity_Id;
17756 begin
17757 Scop := Scope (Scope (Btyp));
17758 while Present (Scop) loop
17759 exit when Ekind (Scop) = E_Function;
17760 Scop := Scope (Scop);
17761 end loop;
17763 -- Treat the return object's type as having the level of the
17764 -- function's result subtype (as per RM05-6.5(5.3/2)).
17766 return Type_Access_Level (Etype (Scop));
17767 end;
17768 end if;
17769 end if;
17771 Btyp := Root_Type (Btyp);
17773 -- The accessibility level of anonymous access types associated with
17774 -- discriminants is that of the current instance of the type, and
17775 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
17777 -- AI-402: access discriminants have accessibility based on the
17778 -- object rather than the type in Ada 2005, so the above paragraph
17779 -- doesn't apply.
17781 -- ??? Needs completion with rules from AI-416
17783 if Ada_Version <= Ada_95
17784 and then Ekind (Typ) = E_Anonymous_Access_Type
17785 and then Present (Associated_Node_For_Itype (Typ))
17786 and then Nkind (Associated_Node_For_Itype (Typ)) =
17787 N_Discriminant_Specification
17788 then
17789 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
17790 end if;
17791 end if;
17793 -- Return library level for a generic formal type. This is done because
17794 -- RM(10.3.2) says that "The statically deeper relationship does not
17795 -- apply to ... a descendant of a generic formal type". Rather than
17796 -- checking at each point where a static accessibility check is
17797 -- performed to see if we are dealing with a formal type, this rule is
17798 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17799 -- return extreme values for a formal type; Deepest_Type_Access_Level
17800 -- returns Int'Last. By calling the appropriate function from among the
17801 -- two, we ensure that the static accessibility check will pass if we
17802 -- happen to run into a formal type. More specifically, we should call
17803 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17804 -- call occurs as part of a static accessibility check and the error
17805 -- case is the case where the type's level is too shallow (as opposed
17806 -- to too deep).
17808 if Is_Generic_Type (Root_Type (Btyp)) then
17809 return Scope_Depth (Standard_Standard);
17810 end if;
17812 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
17813 end Type_Access_Level;
17815 ------------------------------------
17816 -- Type_Without_Stream_Operation --
17817 ------------------------------------
17819 function Type_Without_Stream_Operation
17820 (T : Entity_Id;
17821 Op : TSS_Name_Type := TSS_Null) return Entity_Id
17823 BT : constant Entity_Id := Base_Type (T);
17824 Op_Missing : Boolean;
17826 begin
17827 if not Restriction_Active (No_Default_Stream_Attributes) then
17828 return Empty;
17829 end if;
17831 if Is_Elementary_Type (T) then
17832 if Op = TSS_Null then
17833 Op_Missing :=
17834 No (TSS (BT, TSS_Stream_Read))
17835 or else No (TSS (BT, TSS_Stream_Write));
17837 else
17838 Op_Missing := No (TSS (BT, Op));
17839 end if;
17841 if Op_Missing then
17842 return T;
17843 else
17844 return Empty;
17845 end if;
17847 elsif Is_Array_Type (T) then
17848 return Type_Without_Stream_Operation (Component_Type (T), Op);
17850 elsif Is_Record_Type (T) then
17851 declare
17852 Comp : Entity_Id;
17853 C_Typ : Entity_Id;
17855 begin
17856 Comp := First_Component (T);
17857 while Present (Comp) loop
17858 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
17860 if Present (C_Typ) then
17861 return C_Typ;
17862 end if;
17864 Next_Component (Comp);
17865 end loop;
17867 return Empty;
17868 end;
17870 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
17871 return Type_Without_Stream_Operation (Full_View (T), Op);
17872 else
17873 return Empty;
17874 end if;
17875 end Type_Without_Stream_Operation;
17877 ----------------------------
17878 -- Unique_Defining_Entity --
17879 ----------------------------
17881 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
17882 begin
17883 return Unique_Entity (Defining_Entity (N));
17884 end Unique_Defining_Entity;
17886 -------------------
17887 -- Unique_Entity --
17888 -------------------
17890 function Unique_Entity (E : Entity_Id) return Entity_Id is
17891 U : Entity_Id := E;
17892 P : Node_Id;
17894 begin
17895 case Ekind (E) is
17896 when E_Constant =>
17897 if Present (Full_View (E)) then
17898 U := Full_View (E);
17899 end if;
17901 when Type_Kind =>
17902 if Present (Full_View (E)) then
17903 U := Full_View (E);
17904 end if;
17906 when E_Package_Body =>
17907 P := Parent (E);
17909 if Nkind (P) = N_Defining_Program_Unit_Name then
17910 P := Parent (P);
17911 end if;
17913 U := Corresponding_Spec (P);
17915 when E_Subprogram_Body =>
17916 P := Parent (E);
17918 if Nkind (P) = N_Defining_Program_Unit_Name then
17919 P := Parent (P);
17920 end if;
17922 P := Parent (P);
17924 if Nkind (P) = N_Subprogram_Body_Stub then
17925 if Present (Library_Unit (P)) then
17927 -- Get to the function or procedure (generic) entity through
17928 -- the body entity.
17930 U :=
17931 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
17932 end if;
17933 else
17934 U := Corresponding_Spec (P);
17935 end if;
17937 when Formal_Kind =>
17938 if Present (Spec_Entity (E)) then
17939 U := Spec_Entity (E);
17940 end if;
17942 when others =>
17943 null;
17944 end case;
17946 return U;
17947 end Unique_Entity;
17949 -----------------
17950 -- Unique_Name --
17951 -----------------
17953 function Unique_Name (E : Entity_Id) return String is
17955 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17956 -- reliable, as they may not include the overloading suffix. Instead,
17957 -- when looking for the name of E or one of its enclosing scope, we get
17958 -- the name of the corresponding Unique_Entity.
17960 function Get_Scoped_Name (E : Entity_Id) return String;
17961 -- Return the name of E prefixed by all the names of the scopes to which
17962 -- E belongs, except for Standard.
17964 ---------------------
17965 -- Get_Scoped_Name --
17966 ---------------------
17968 function Get_Scoped_Name (E : Entity_Id) return String is
17969 Name : constant String := Get_Name_String (Chars (E));
17970 begin
17971 if Has_Fully_Qualified_Name (E)
17972 or else Scope (E) = Standard_Standard
17973 then
17974 return Name;
17975 else
17976 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
17977 end if;
17978 end Get_Scoped_Name;
17980 -- Start of processing for Unique_Name
17982 begin
17983 if E = Standard_Standard then
17984 return Get_Name_String (Name_Standard);
17986 elsif Scope (E) = Standard_Standard
17987 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
17988 then
17989 return Get_Name_String (Name_Standard) & "__" &
17990 Get_Name_String (Chars (E));
17992 elsif Ekind (E) = E_Enumeration_Literal then
17993 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
17995 else
17996 return Get_Scoped_Name (Unique_Entity (E));
17997 end if;
17998 end Unique_Name;
18000 ---------------------
18001 -- Unit_Is_Visible --
18002 ---------------------
18004 function Unit_Is_Visible (U : Entity_Id) return Boolean is
18005 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
18006 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
18008 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
18009 -- For a child unit, check whether unit appears in a with_clause
18010 -- of a parent.
18012 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
18013 -- Scan the context clause of one compilation unit looking for a
18014 -- with_clause for the unit in question.
18016 ----------------------------
18017 -- Unit_In_Parent_Context --
18018 ----------------------------
18020 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
18021 begin
18022 if Unit_In_Context (Par_Unit) then
18023 return True;
18025 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
18026 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
18028 else
18029 return False;
18030 end if;
18031 end Unit_In_Parent_Context;
18033 ---------------------
18034 -- Unit_In_Context --
18035 ---------------------
18037 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
18038 Clause : Node_Id;
18040 begin
18041 Clause := First (Context_Items (Comp_Unit));
18042 while Present (Clause) loop
18043 if Nkind (Clause) = N_With_Clause then
18044 if Library_Unit (Clause) = U then
18045 return True;
18047 -- The with_clause may denote a renaming of the unit we are
18048 -- looking for, eg. Text_IO which renames Ada.Text_IO.
18050 elsif
18051 Renamed_Entity (Entity (Name (Clause))) =
18052 Defining_Entity (Unit (U))
18053 then
18054 return True;
18055 end if;
18056 end if;
18058 Next (Clause);
18059 end loop;
18061 return False;
18062 end Unit_In_Context;
18064 -- Start of processing for Unit_Is_Visible
18066 begin
18067 -- The currrent unit is directly visible
18069 if Curr = U then
18070 return True;
18072 elsif Unit_In_Context (Curr) then
18073 return True;
18075 -- If the current unit is a body, check the context of the spec
18077 elsif Nkind (Unit (Curr)) = N_Package_Body
18078 or else
18079 (Nkind (Unit (Curr)) = N_Subprogram_Body
18080 and then not Acts_As_Spec (Unit (Curr)))
18081 then
18082 if Unit_In_Context (Library_Unit (Curr)) then
18083 return True;
18084 end if;
18085 end if;
18087 -- If the spec is a child unit, examine the parents
18089 if Is_Child_Unit (Curr_Entity) then
18090 if Nkind (Unit (Curr)) in N_Unit_Body then
18091 return
18092 Unit_In_Parent_Context
18093 (Parent_Spec (Unit (Library_Unit (Curr))));
18094 else
18095 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
18096 end if;
18098 else
18099 return False;
18100 end if;
18101 end Unit_Is_Visible;
18103 ------------------------------
18104 -- Universal_Interpretation --
18105 ------------------------------
18107 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
18108 Index : Interp_Index;
18109 It : Interp;
18111 begin
18112 -- The argument may be a formal parameter of an operator or subprogram
18113 -- with multiple interpretations, or else an expression for an actual.
18115 if Nkind (Opnd) = N_Defining_Identifier
18116 or else not Is_Overloaded (Opnd)
18117 then
18118 if Etype (Opnd) = Universal_Integer
18119 or else Etype (Opnd) = Universal_Real
18120 then
18121 return Etype (Opnd);
18122 else
18123 return Empty;
18124 end if;
18126 else
18127 Get_First_Interp (Opnd, Index, It);
18128 while Present (It.Typ) loop
18129 if It.Typ = Universal_Integer
18130 or else It.Typ = Universal_Real
18131 then
18132 return It.Typ;
18133 end if;
18135 Get_Next_Interp (Index, It);
18136 end loop;
18138 return Empty;
18139 end if;
18140 end Universal_Interpretation;
18142 ---------------
18143 -- Unqualify --
18144 ---------------
18146 function Unqualify (Expr : Node_Id) return Node_Id is
18147 begin
18148 -- Recurse to handle unlikely case of multiple levels of qualification
18150 if Nkind (Expr) = N_Qualified_Expression then
18151 return Unqualify (Expression (Expr));
18153 -- Normal case, not a qualified expression
18155 else
18156 return Expr;
18157 end if;
18158 end Unqualify;
18160 -----------------------
18161 -- Visible_Ancestors --
18162 -----------------------
18164 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
18165 List_1 : Elist_Id;
18166 List_2 : Elist_Id;
18167 Elmt : Elmt_Id;
18169 begin
18170 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
18172 -- Collect all the parents and progenitors of Typ. If the full-view of
18173 -- private parents and progenitors is available then it is used to
18174 -- generate the list of visible ancestors; otherwise their partial
18175 -- view is added to the resulting list.
18177 Collect_Parents
18178 (T => Typ,
18179 List => List_1,
18180 Use_Full_View => True);
18182 Collect_Interfaces
18183 (T => Typ,
18184 Ifaces_List => List_2,
18185 Exclude_Parents => True,
18186 Use_Full_View => True);
18188 -- Join the two lists. Avoid duplications because an interface may
18189 -- simultaneously be parent and progenitor of a type.
18191 Elmt := First_Elmt (List_2);
18192 while Present (Elmt) loop
18193 Append_Unique_Elmt (Node (Elmt), List_1);
18194 Next_Elmt (Elmt);
18195 end loop;
18197 return List_1;
18198 end Visible_Ancestors;
18200 ------------------------
18201 -- Within_Ghost_Scope --
18202 ------------------------
18204 function Within_Ghost_Scope
18205 (Id : Entity_Id := Current_Scope) return Boolean
18207 S : Entity_Id;
18209 begin
18210 -- Climb the scope stack looking for a Ghost scope
18212 S := Id;
18213 while Present (S) and then S /= Standard_Standard loop
18214 if Is_Ghost_Entity (S) then
18215 return True;
18216 end if;
18218 S := Scope (S);
18219 end loop;
18221 return False;
18222 end Within_Ghost_Scope;
18224 ----------------------
18225 -- Within_Init_Proc --
18226 ----------------------
18228 function Within_Init_Proc return Boolean is
18229 S : Entity_Id;
18231 begin
18232 S := Current_Scope;
18233 while not Is_Overloadable (S) loop
18234 if S = Standard_Standard then
18235 return False;
18236 else
18237 S := Scope (S);
18238 end if;
18239 end loop;
18241 return Is_Init_Proc (S);
18242 end Within_Init_Proc;
18244 ------------------
18245 -- Within_Scope --
18246 ------------------
18248 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
18249 SE : Entity_Id;
18250 begin
18251 SE := Scope (E);
18252 loop
18253 if SE = S then
18254 return True;
18255 elsif SE = Standard_Standard then
18256 return False;
18257 else
18258 SE := Scope (SE);
18259 end if;
18260 end loop;
18261 end Within_Scope;
18263 ----------------
18264 -- Wrong_Type --
18265 ----------------
18267 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
18268 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
18269 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
18271 Matching_Field : Entity_Id;
18272 -- Entity to give a more precise suggestion on how to write a one-
18273 -- element positional aggregate.
18275 function Has_One_Matching_Field return Boolean;
18276 -- Determines if Expec_Type is a record type with a single component or
18277 -- discriminant whose type matches the found type or is one dimensional
18278 -- array whose component type matches the found type. In the case of
18279 -- one discriminant, we ignore the variant parts. That's not accurate,
18280 -- but good enough for the warning.
18282 ----------------------------
18283 -- Has_One_Matching_Field --
18284 ----------------------------
18286 function Has_One_Matching_Field return Boolean is
18287 E : Entity_Id;
18289 begin
18290 Matching_Field := Empty;
18292 if Is_Array_Type (Expec_Type)
18293 and then Number_Dimensions (Expec_Type) = 1
18294 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
18295 then
18296 -- Use type name if available. This excludes multidimensional
18297 -- arrays and anonymous arrays.
18299 if Comes_From_Source (Expec_Type) then
18300 Matching_Field := Expec_Type;
18302 -- For an assignment, use name of target
18304 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
18305 and then Is_Entity_Name (Name (Parent (Expr)))
18306 then
18307 Matching_Field := Entity (Name (Parent (Expr)));
18308 end if;
18310 return True;
18312 elsif not Is_Record_Type (Expec_Type) then
18313 return False;
18315 else
18316 E := First_Entity (Expec_Type);
18317 loop
18318 if No (E) then
18319 return False;
18321 elsif not Ekind_In (E, E_Discriminant, E_Component)
18322 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
18323 then
18324 Next_Entity (E);
18326 else
18327 exit;
18328 end if;
18329 end loop;
18331 if not Covers (Etype (E), Found_Type) then
18332 return False;
18334 elsif Present (Next_Entity (E))
18335 and then (Ekind (E) = E_Component
18336 or else Ekind (Next_Entity (E)) = E_Discriminant)
18337 then
18338 return False;
18340 else
18341 Matching_Field := E;
18342 return True;
18343 end if;
18344 end if;
18345 end Has_One_Matching_Field;
18347 -- Start of processing for Wrong_Type
18349 begin
18350 -- Don't output message if either type is Any_Type, or if a message
18351 -- has already been posted for this node. We need to do the latter
18352 -- check explicitly (it is ordinarily done in Errout), because we
18353 -- are using ! to force the output of the error messages.
18355 if Expec_Type = Any_Type
18356 or else Found_Type = Any_Type
18357 or else Error_Posted (Expr)
18358 then
18359 return;
18361 -- If one of the types is a Taft-Amendment type and the other it its
18362 -- completion, it must be an illegal use of a TAT in the spec, for
18363 -- which an error was already emitted. Avoid cascaded errors.
18365 elsif Is_Incomplete_Type (Expec_Type)
18366 and then Has_Completion_In_Body (Expec_Type)
18367 and then Full_View (Expec_Type) = Etype (Expr)
18368 then
18369 return;
18371 elsif Is_Incomplete_Type (Etype (Expr))
18372 and then Has_Completion_In_Body (Etype (Expr))
18373 and then Full_View (Etype (Expr)) = Expec_Type
18374 then
18375 return;
18377 -- In an instance, there is an ongoing problem with completion of
18378 -- type derived from private types. Their structure is what Gigi
18379 -- expects, but the Etype is the parent type rather than the
18380 -- derived private type itself. Do not flag error in this case. The
18381 -- private completion is an entity without a parent, like an Itype.
18382 -- Similarly, full and partial views may be incorrect in the instance.
18383 -- There is no simple way to insure that it is consistent ???
18385 -- A similar view discrepancy can happen in an inlined body, for the
18386 -- same reason: inserted body may be outside of the original package
18387 -- and only partial views are visible at the point of insertion.
18389 elsif In_Instance or else In_Inlined_Body then
18390 if Etype (Etype (Expr)) = Etype (Expected_Type)
18391 and then
18392 (Has_Private_Declaration (Expected_Type)
18393 or else Has_Private_Declaration (Etype (Expr)))
18394 and then No (Parent (Expected_Type))
18395 then
18396 return;
18398 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
18399 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
18400 then
18401 return;
18403 elsif Is_Private_Type (Expected_Type)
18404 and then Present (Full_View (Expected_Type))
18405 and then Covers (Full_View (Expected_Type), Etype (Expr))
18406 then
18407 return;
18408 end if;
18409 end if;
18411 -- An interesting special check. If the expression is parenthesized
18412 -- and its type corresponds to the type of the sole component of the
18413 -- expected record type, or to the component type of the expected one
18414 -- dimensional array type, then assume we have a bad aggregate attempt.
18416 if Nkind (Expr) in N_Subexpr
18417 and then Paren_Count (Expr) /= 0
18418 and then Has_One_Matching_Field
18419 then
18420 Error_Msg_N ("positional aggregate cannot have one component", Expr);
18421 if Present (Matching_Field) then
18422 if Is_Array_Type (Expec_Type) then
18423 Error_Msg_NE
18424 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
18426 else
18427 Error_Msg_NE
18428 ("\write instead `& ='> ...`", Expr, Matching_Field);
18429 end if;
18430 end if;
18432 -- Another special check, if we are looking for a pool-specific access
18433 -- type and we found an E_Access_Attribute_Type, then we have the case
18434 -- of an Access attribute being used in a context which needs a pool-
18435 -- specific type, which is never allowed. The one extra check we make
18436 -- is that the expected designated type covers the Found_Type.
18438 elsif Is_Access_Type (Expec_Type)
18439 and then Ekind (Found_Type) = E_Access_Attribute_Type
18440 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
18441 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
18442 and then Covers
18443 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
18444 then
18445 Error_Msg_N -- CODEFIX
18446 ("result must be general access type!", Expr);
18447 Error_Msg_NE -- CODEFIX
18448 ("add ALL to }!", Expr, Expec_Type);
18450 -- Another special check, if the expected type is an integer type,
18451 -- but the expression is of type System.Address, and the parent is
18452 -- an addition or subtraction operation whose left operand is the
18453 -- expression in question and whose right operand is of an integral
18454 -- type, then this is an attempt at address arithmetic, so give
18455 -- appropriate message.
18457 elsif Is_Integer_Type (Expec_Type)
18458 and then Is_RTE (Found_Type, RE_Address)
18459 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
18460 and then Expr = Left_Opnd (Parent (Expr))
18461 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
18462 then
18463 Error_Msg_N
18464 ("address arithmetic not predefined in package System",
18465 Parent (Expr));
18466 Error_Msg_N
18467 ("\possible missing with/use of System.Storage_Elements",
18468 Parent (Expr));
18469 return;
18471 -- If the expected type is an anonymous access type, as for access
18472 -- parameters and discriminants, the error is on the designated types.
18474 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
18475 if Comes_From_Source (Expec_Type) then
18476 Error_Msg_NE ("expected}!", Expr, Expec_Type);
18477 else
18478 Error_Msg_NE
18479 ("expected an access type with designated}",
18480 Expr, Designated_Type (Expec_Type));
18481 end if;
18483 if Is_Access_Type (Found_Type)
18484 and then not Comes_From_Source (Found_Type)
18485 then
18486 Error_Msg_NE
18487 ("\\found an access type with designated}!",
18488 Expr, Designated_Type (Found_Type));
18489 else
18490 if From_Limited_With (Found_Type) then
18491 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
18492 Error_Msg_Qual_Level := 99;
18493 Error_Msg_NE -- CODEFIX
18494 ("\\missing `WITH &;", Expr, Scope (Found_Type));
18495 Error_Msg_Qual_Level := 0;
18496 else
18497 Error_Msg_NE ("found}!", Expr, Found_Type);
18498 end if;
18499 end if;
18501 -- Normal case of one type found, some other type expected
18503 else
18504 -- If the names of the two types are the same, see if some number
18505 -- of levels of qualification will help. Don't try more than three
18506 -- levels, and if we get to standard, it's no use (and probably
18507 -- represents an error in the compiler) Also do not bother with
18508 -- internal scope names.
18510 declare
18511 Expec_Scope : Entity_Id;
18512 Found_Scope : Entity_Id;
18514 begin
18515 Expec_Scope := Expec_Type;
18516 Found_Scope := Found_Type;
18518 for Levels in Int range 0 .. 3 loop
18519 if Chars (Expec_Scope) /= Chars (Found_Scope) then
18520 Error_Msg_Qual_Level := Levels;
18521 exit;
18522 end if;
18524 Expec_Scope := Scope (Expec_Scope);
18525 Found_Scope := Scope (Found_Scope);
18527 exit when Expec_Scope = Standard_Standard
18528 or else Found_Scope = Standard_Standard
18529 or else not Comes_From_Source (Expec_Scope)
18530 or else not Comes_From_Source (Found_Scope);
18531 end loop;
18532 end;
18534 if Is_Record_Type (Expec_Type)
18535 and then Present (Corresponding_Remote_Type (Expec_Type))
18536 then
18537 Error_Msg_NE ("expected}!", Expr,
18538 Corresponding_Remote_Type (Expec_Type));
18539 else
18540 Error_Msg_NE ("expected}!", Expr, Expec_Type);
18541 end if;
18543 if Is_Entity_Name (Expr)
18544 and then Is_Package_Or_Generic_Package (Entity (Expr))
18545 then
18546 Error_Msg_N ("\\found package name!", Expr);
18548 elsif Is_Entity_Name (Expr)
18549 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
18550 then
18551 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
18552 Error_Msg_N
18553 ("found procedure name, possibly missing Access attribute!",
18554 Expr);
18555 else
18556 Error_Msg_N
18557 ("\\found procedure name instead of function!", Expr);
18558 end if;
18560 elsif Nkind (Expr) = N_Function_Call
18561 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
18562 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
18563 and then No (Parameter_Associations (Expr))
18564 then
18565 Error_Msg_N
18566 ("found function name, possibly missing Access attribute!",
18567 Expr);
18569 -- Catch common error: a prefix or infix operator which is not
18570 -- directly visible because the type isn't.
18572 elsif Nkind (Expr) in N_Op
18573 and then Is_Overloaded (Expr)
18574 and then not Is_Immediately_Visible (Expec_Type)
18575 and then not Is_Potentially_Use_Visible (Expec_Type)
18576 and then not In_Use (Expec_Type)
18577 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
18578 then
18579 Error_Msg_N
18580 ("operator of the type is not directly visible!", Expr);
18582 elsif Ekind (Found_Type) = E_Void
18583 and then Present (Parent (Found_Type))
18584 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
18585 then
18586 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
18588 else
18589 Error_Msg_NE ("\\found}!", Expr, Found_Type);
18590 end if;
18592 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
18593 -- of the same modular type, and (M1 and M2) = 0 was intended.
18595 if Expec_Type = Standard_Boolean
18596 and then Is_Modular_Integer_Type (Found_Type)
18597 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
18598 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
18599 then
18600 declare
18601 Op : constant Node_Id := Right_Opnd (Parent (Expr));
18602 L : constant Node_Id := Left_Opnd (Op);
18603 R : constant Node_Id := Right_Opnd (Op);
18605 begin
18606 -- The case for the message is when the left operand of the
18607 -- comparison is the same modular type, or when it is an
18608 -- integer literal (or other universal integer expression),
18609 -- which would have been typed as the modular type if the
18610 -- parens had been there.
18612 if (Etype (L) = Found_Type
18613 or else
18614 Etype (L) = Universal_Integer)
18615 and then Is_Integer_Type (Etype (R))
18616 then
18617 Error_Msg_N
18618 ("\\possible missing parens for modular operation", Expr);
18619 end if;
18620 end;
18621 end if;
18623 -- Reset error message qualification indication
18625 Error_Msg_Qual_Level := 0;
18626 end if;
18627 end Wrong_Type;
18629 end Sem_Util;