2014-08-04 Robert Dewar <dewar@adacore.com>
[official-gcc.git] / gcc / ada / sem_util.adb
blobdd6206dc265b4a09e6f9e966ec2e4e78077f8f01
1 ------------------------------------------------------------------------------
2 -- --
3 -- GNAT COMPILER COMPONENTS --
4 -- --
5 -- S E M _ U T I L --
6 -- --
7 -- B o d y --
8 -- --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
10 -- --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
20 -- --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
23 -- --
24 ------------------------------------------------------------------------------
26 with Aspects; use Aspects;
27 with Atree; use Atree;
28 with Casing; use Casing;
29 with Checks; use Checks;
30 with Debug; use Debug;
31 with Elists; use Elists;
32 with Errout; use Errout;
33 with Exp_Ch11; use Exp_Ch11;
34 with Exp_Disp; use Exp_Disp;
35 with Exp_Util; use Exp_Util;
36 with Fname; use Fname;
37 with Freeze; use Freeze;
38 with Lib; use Lib;
39 with Lib.Xref; use Lib.Xref;
40 with Namet.Sp; use Namet.Sp;
41 with Nlists; use Nlists;
42 with Nmake; use Nmake;
43 with Output; use Output;
44 with Restrict; use Restrict;
45 with Rident; use Rident;
46 with Rtsfind; use Rtsfind;
47 with Sem; use Sem;
48 with Sem_Aux; use Sem_Aux;
49 with Sem_Attr; use Sem_Attr;
50 with Sem_Ch8; use Sem_Ch8;
51 with Sem_Ch13; use Sem_Ch13;
52 with Sem_Disp; use Sem_Disp;
53 with Sem_Eval; use Sem_Eval;
54 with Sem_Prag; use Sem_Prag;
55 with Sem_Res; use Sem_Res;
56 with Sem_Warn; use Sem_Warn;
57 with Sem_Type; use Sem_Type;
58 with Sinfo; use Sinfo;
59 with Sinput; use Sinput;
60 with Stand; use Stand;
61 with Style;
62 with Stringt; use Stringt;
63 with Targparm; use Targparm;
64 with Tbuild; use Tbuild;
65 with Ttypes; use Ttypes;
66 with Uname; use Uname;
68 with GNAT.HTable; use GNAT.HTable;
70 package body Sem_Util is
72 ----------------------------------------
73 -- Global_Variables for New_Copy_Tree --
74 ----------------------------------------
76 -- These global variables are used by New_Copy_Tree. See description of the
77 -- body of this subprogram for details. Global variables can be safely used
78 -- by New_Copy_Tree, since there is no case of a recursive call from the
79 -- processing inside New_Copy_Tree.
81 NCT_Hash_Threshold : constant := 20;
82 -- If there are more than this number of pairs of entries in the map, then
83 -- Hash_Tables_Used will be set, and the hash tables will be initialized
84 -- and used for the searches.
86 NCT_Hash_Tables_Used : Boolean := False;
87 -- Set to True if hash tables are in use
89 NCT_Table_Entries : Nat := 0;
90 -- Count entries in table to see if threshold is reached
92 NCT_Hash_Table_Setup : Boolean := False;
93 -- Set to True if hash table contains data. We set this True if we setup
94 -- the hash table with data, and leave it set permanently from then on,
95 -- this is a signal that second and subsequent users of the hash table
96 -- must clear the old entries before reuse.
98 subtype NCT_Header_Num is Int range 0 .. 511;
99 -- Defines range of headers in hash tables (512 headers)
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 function Build_Component_Subtype
106 (C : List_Id;
107 Loc : Source_Ptr;
108 T : Entity_Id) return Node_Id;
109 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
110 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
111 -- Loc is the source location, T is the original subtype.
113 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
114 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
115 -- with discriminants whose default values are static, examine only the
116 -- components in the selected variant to determine whether all of them
117 -- have a default.
119 function Has_Enabled_Property
120 (Item_Id : Entity_Id;
121 Property : Name_Id) return Boolean;
122 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
123 -- Determine whether an abstract state or a variable denoted by entity
124 -- Item_Id has enabled property Property.
126 function Has_Null_Extension (T : Entity_Id) return Boolean;
127 -- T is a derived tagged type. Check whether the type extension is null.
128 -- If the parent type is fully initialized, T can be treated as such.
130 ------------------------------
131 -- Abstract_Interface_List --
132 ------------------------------
134 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
135 Nod : Node_Id;
137 begin
138 if Is_Concurrent_Type (Typ) then
140 -- If we are dealing with a synchronized subtype, go to the base
141 -- type, whose declaration has the interface list.
143 -- Shouldn't this be Declaration_Node???
145 Nod := Parent (Base_Type (Typ));
147 if Nkind (Nod) = N_Full_Type_Declaration then
148 return Empty_List;
149 end if;
151 elsif Ekind (Typ) = E_Record_Type_With_Private then
152 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
153 Nod := Type_Definition (Parent (Typ));
155 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
156 if Present (Full_View (Typ))
157 and then
158 Nkind (Parent (Full_View (Typ))) = N_Full_Type_Declaration
159 then
160 Nod := Type_Definition (Parent (Full_View (Typ)));
162 -- If the full-view is not available we cannot do anything else
163 -- here (the source has errors).
165 else
166 return Empty_List;
167 end if;
169 -- Support for generic formals with interfaces is still missing ???
171 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
172 return Empty_List;
174 else
175 pragma Assert
176 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
177 Nod := Parent (Typ);
178 end if;
180 elsif Ekind (Typ) = E_Record_Subtype then
181 Nod := Type_Definition (Parent (Etype (Typ)));
183 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
185 -- Recurse, because parent may still be a private extension. Also
186 -- note that the full view of the subtype or the full view of its
187 -- base type may (both) be unavailable.
189 return Abstract_Interface_List (Etype (Typ));
191 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
192 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
193 Nod := Formal_Type_Definition (Parent (Typ));
194 else
195 Nod := Type_Definition (Parent (Typ));
196 end if;
197 end if;
199 return Interface_List (Nod);
200 end Abstract_Interface_List;
202 --------------------------------
203 -- Add_Access_Type_To_Process --
204 --------------------------------
206 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
207 L : Elist_Id;
209 begin
210 Ensure_Freeze_Node (E);
211 L := Access_Types_To_Process (Freeze_Node (E));
213 if No (L) then
214 L := New_Elmt_List;
215 Set_Access_Types_To_Process (Freeze_Node (E), L);
216 end if;
218 Append_Elmt (A, L);
219 end Add_Access_Type_To_Process;
221 --------------------------
222 -- Add_Block_Identifier --
223 --------------------------
225 procedure Add_Block_Identifier (N : Node_Id; Id : out Entity_Id) is
226 Loc : constant Source_Ptr := Sloc (N);
228 begin
229 pragma Assert (Nkind (N) = N_Block_Statement);
231 -- The block already has a label, return its entity
233 if Present (Identifier (N)) then
234 Id := Entity (Identifier (N));
236 -- Create a new block label and set its attributes
238 else
239 Id := New_Internal_Entity (E_Block, Current_Scope, Loc, 'B');
240 Set_Etype (Id, Standard_Void_Type);
241 Set_Parent (Id, N);
243 Set_Identifier (N, New_Occurrence_Of (Id, Loc));
244 Set_Block_Node (Id, Identifier (N));
245 end if;
246 end Add_Block_Identifier;
248 -----------------------
249 -- Add_Contract_Item --
250 -----------------------
252 procedure Add_Contract_Item (Prag : Node_Id; Id : Entity_Id) is
253 Items : constant Node_Id := Contract (Id);
254 Nam : Name_Id;
255 N : Node_Id;
257 begin
258 -- The related context must have a contract and the item to be added
259 -- must be a pragma.
261 pragma Assert (Present (Items));
262 pragma Assert (Nkind (Prag) = N_Pragma);
264 Nam := Original_Aspect_Name (Prag);
266 -- Contract items related to [generic] packages or instantiations. The
267 -- applicable pragmas are:
268 -- Abstract_States
269 -- Initial_Condition
270 -- Initializes
271 -- Part_Of (instantiation only)
273 if Ekind_In (Id, E_Generic_Package, E_Package) then
274 if Nam_In (Nam, Name_Abstract_State,
275 Name_Initial_Condition,
276 Name_Initializes)
277 then
278 Set_Next_Pragma (Prag, Classifications (Items));
279 Set_Classifications (Items, Prag);
281 -- Indicator Part_Of must be associated with a package instantiation
283 elsif Nam = Name_Part_Of and then Is_Generic_Instance (Id) then
284 Set_Next_Pragma (Prag, Classifications (Items));
285 Set_Classifications (Items, Prag);
287 -- The pragma is not a proper contract item
289 else
290 raise Program_Error;
291 end if;
293 -- Contract items related to package bodies. The applicable pragmas are:
294 -- Refined_States
296 elsif Ekind (Id) = E_Package_Body then
297 if Nam = Name_Refined_State then
298 Set_Next_Pragma (Prag, Classifications (Items));
299 Set_Classifications (Items, Prag);
301 -- The pragma is not a proper contract item
303 else
304 raise Program_Error;
305 end if;
307 -- Contract items related to subprogram or entry declarations. The
308 -- applicable pragmas are:
309 -- Contract_Cases
310 -- Depends
311 -- Global
312 -- Post
313 -- Postcondition
314 -- Pre
315 -- Precondition
316 -- Test_Case
318 elsif Ekind_In (Id, E_Entry, E_Entry_Family)
319 or else Is_Generic_Subprogram (Id)
320 or else Is_Subprogram (Id)
321 then
322 if Nam_In (Nam, Name_Precondition,
323 Name_Postcondition,
324 Name_Pre,
325 Name_Post,
326 Name_uPre,
327 Name_uPost)
328 then
329 -- Before we add a precondition or postcondition to the list,
330 -- make sure we do not have a disallowed duplicate, which can
331 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
332 -- instead of the corresponding aspect.
334 if not From_Aspect_Specification (Prag)
335 and then Nam_In (Nam, Name_Pre_Class,
336 Name_Pre,
337 Name_uPre,
338 Name_Post_Class,
339 Name_Post,
340 Name_uPost)
341 then
342 N := Pre_Post_Conditions (Items);
343 while Present (N) loop
344 if not Split_PPC (N)
345 and then Original_Aspect_Name (N) = Nam
346 then
347 Error_Msg_Sloc := Sloc (N);
348 Error_Msg_NE
349 ("duplication of aspect for & given#", Prag, Id);
350 return;
351 else
352 N := Next_Pragma (N);
353 end if;
354 end loop;
355 end if;
357 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
358 Set_Pre_Post_Conditions (Items, Prag);
360 elsif Nam_In (Nam, Name_Contract_Cases, Name_Test_Case) then
361 Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
362 Set_Contract_Test_Cases (Items, Prag);
364 elsif Nam_In (Nam, Name_Depends, Name_Global) then
365 Set_Next_Pragma (Prag, Classifications (Items));
366 Set_Classifications (Items, Prag);
368 -- The pragma is not a proper contract item
370 else
371 raise Program_Error;
372 end if;
374 -- Contract items related to subprogram bodies. The applicable pragmas
375 -- are:
376 -- Refined_Depends
377 -- Refined_Global
378 -- Refined_Post
380 elsif Ekind (Id) = E_Subprogram_Body then
381 if Nam = Name_Refined_Post then
382 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
383 Set_Pre_Post_Conditions (Items, Prag);
385 elsif Nam_In (Nam, Name_Refined_Depends, Name_Refined_Global) then
386 Set_Next_Pragma (Prag, Classifications (Items));
387 Set_Classifications (Items, Prag);
389 -- The pragma is not a proper contract item
391 else
392 raise Program_Error;
393 end if;
395 -- Contract items related to variables. The applicable pragmas are:
396 -- Async_Readers
397 -- Async_Writers
398 -- Effective_Reads
399 -- Effective_Writes
400 -- Part_Of
402 elsif Ekind (Id) = E_Variable then
403 if Nam_In (Nam, Name_Async_Readers,
404 Name_Async_Writers,
405 Name_Effective_Reads,
406 Name_Effective_Writes,
407 Name_Part_Of)
408 then
409 Set_Next_Pragma (Prag, Classifications (Items));
410 Set_Classifications (Items, Prag);
412 -- The pragma is not a proper contract item
414 else
415 raise Program_Error;
416 end if;
417 end if;
418 end Add_Contract_Item;
420 ----------------------------
421 -- Add_Global_Declaration --
422 ----------------------------
424 procedure Add_Global_Declaration (N : Node_Id) is
425 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
427 begin
428 if No (Declarations (Aux_Node)) then
429 Set_Declarations (Aux_Node, New_List);
430 end if;
432 Append_To (Declarations (Aux_Node), N);
433 Analyze (N);
434 end Add_Global_Declaration;
436 --------------------------------
437 -- Address_Integer_Convert_OK --
438 --------------------------------
440 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
441 begin
442 if Allow_Integer_Address
443 and then ((Is_Descendent_Of_Address (T1)
444 and then Is_Private_Type (T1)
445 and then Is_Integer_Type (T2))
446 or else
447 (Is_Descendent_Of_Address (T2)
448 and then Is_Private_Type (T2)
449 and then Is_Integer_Type (T1)))
450 then
451 return True;
452 else
453 return False;
454 end if;
455 end Address_Integer_Convert_OK;
457 -----------------
458 -- Addressable --
459 -----------------
461 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
463 function Addressable (V : Uint) return Boolean is
464 begin
465 return V = Uint_8 or else
466 V = Uint_16 or else
467 V = Uint_32 or else
468 V = Uint_64;
469 end Addressable;
471 function Addressable (V : Int) return Boolean is
472 begin
473 return V = 8 or else
474 V = 16 or else
475 V = 32 or else
476 V = 64;
477 end Addressable;
479 ---------------------------------
480 -- Aggregate_Constraint_Checks --
481 ---------------------------------
483 procedure Aggregate_Constraint_Checks
484 (Exp : Node_Id;
485 Check_Typ : Entity_Id)
487 Exp_Typ : constant Entity_Id := Etype (Exp);
489 begin
490 if Raises_Constraint_Error (Exp) then
491 return;
492 end if;
494 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
495 -- component's type to force the appropriate accessibility checks.
497 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
498 -- type to force the corresponding run-time check
500 if Is_Access_Type (Check_Typ)
501 and then ((Is_Local_Anonymous_Access (Check_Typ))
502 or else (Can_Never_Be_Null (Check_Typ)
503 and then not Can_Never_Be_Null (Exp_Typ)))
504 then
505 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
506 Analyze_And_Resolve (Exp, Check_Typ);
507 Check_Unset_Reference (Exp);
508 end if;
510 -- This is really expansion activity, so make sure that expansion is
511 -- on and is allowed. In GNATprove mode, we also want check flags to
512 -- be added in the tree, so that the formal verification can rely on
513 -- those to be present. In GNATprove mode for formal verification, some
514 -- treatment typically only done during expansion needs to be performed
515 -- on the tree, but it should not be applied inside generics. Otherwise,
516 -- this breaks the name resolution mechanism for generic instances.
518 if not Expander_Active
519 and (Inside_A_Generic or not Full_Analysis or not GNATprove_Mode)
520 then
521 return;
522 end if;
524 -- First check if we have to insert discriminant checks
526 if Has_Discriminants (Exp_Typ) then
527 Apply_Discriminant_Check (Exp, Check_Typ);
529 -- Next emit length checks for array aggregates
531 elsif Is_Array_Type (Exp_Typ) then
532 Apply_Length_Check (Exp, Check_Typ);
534 -- Finally emit scalar and string checks. If we are dealing with a
535 -- scalar literal we need to check by hand because the Etype of
536 -- literals is not necessarily correct.
538 elsif Is_Scalar_Type (Exp_Typ)
539 and then Compile_Time_Known_Value (Exp)
540 then
541 if Is_Out_Of_Range (Exp, Base_Type (Check_Typ)) then
542 Apply_Compile_Time_Constraint_Error
543 (Exp, "value not in range of}??", CE_Range_Check_Failed,
544 Ent => Base_Type (Check_Typ),
545 Typ => Base_Type (Check_Typ));
547 elsif Is_Out_Of_Range (Exp, Check_Typ) then
548 Apply_Compile_Time_Constraint_Error
549 (Exp, "value not in range of}??", CE_Range_Check_Failed,
550 Ent => Check_Typ,
551 Typ => Check_Typ);
553 elsif not Range_Checks_Suppressed (Check_Typ) then
554 Apply_Scalar_Range_Check (Exp, Check_Typ);
555 end if;
557 -- Verify that target type is also scalar, to prevent view anomalies
558 -- in instantiations.
560 elsif (Is_Scalar_Type (Exp_Typ)
561 or else Nkind (Exp) = N_String_Literal)
562 and then Is_Scalar_Type (Check_Typ)
563 and then Exp_Typ /= Check_Typ
564 then
565 if Is_Entity_Name (Exp)
566 and then Ekind (Entity (Exp)) = E_Constant
567 then
568 -- If expression is a constant, it is worthwhile checking whether
569 -- it is a bound of the type.
571 if (Is_Entity_Name (Type_Low_Bound (Check_Typ))
572 and then Entity (Exp) = Entity (Type_Low_Bound (Check_Typ)))
573 or else
574 (Is_Entity_Name (Type_High_Bound (Check_Typ))
575 and then Entity (Exp) = Entity (Type_High_Bound (Check_Typ)))
576 then
577 return;
579 else
580 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
581 Analyze_And_Resolve (Exp, Check_Typ);
582 Check_Unset_Reference (Exp);
583 end if;
585 -- Could use a comment on this case ???
587 else
588 Rewrite (Exp, Convert_To (Check_Typ, Relocate_Node (Exp)));
589 Analyze_And_Resolve (Exp, Check_Typ);
590 Check_Unset_Reference (Exp);
591 end if;
593 end if;
594 end Aggregate_Constraint_Checks;
596 -----------------------
597 -- Alignment_In_Bits --
598 -----------------------
600 function Alignment_In_Bits (E : Entity_Id) return Uint is
601 begin
602 return Alignment (E) * System_Storage_Unit;
603 end Alignment_In_Bits;
605 ---------------------------------
606 -- Append_Inherited_Subprogram --
607 ---------------------------------
609 procedure Append_Inherited_Subprogram (S : Entity_Id) is
610 Par : constant Entity_Id := Alias (S);
611 -- The parent subprogram
613 Scop : constant Entity_Id := Scope (Par);
614 -- The scope of definition of the parent subprogram
616 Typ : constant Entity_Id := Defining_Entity (Parent (S));
617 -- The derived type of which S is a primitive operation
619 Decl : Node_Id;
620 Next_E : Entity_Id;
622 begin
623 if Ekind (Current_Scope) = E_Package
624 and then In_Private_Part (Current_Scope)
625 and then Has_Private_Declaration (Typ)
626 and then Is_Tagged_Type (Typ)
627 and then Scop = Current_Scope
628 then
629 -- The inherited operation is available at the earliest place after
630 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
631 -- relevant for type extensions. If the parent operation appears
632 -- after the type extension, the operation is not visible.
634 Decl := First
635 (Visible_Declarations
636 (Package_Specification (Current_Scope)));
637 while Present (Decl) loop
638 if Nkind (Decl) = N_Private_Extension_Declaration
639 and then Defining_Entity (Decl) = Typ
640 then
641 if Sloc (Decl) > Sloc (Par) then
642 Next_E := Next_Entity (Par);
643 Set_Next_Entity (Par, S);
644 Set_Next_Entity (S, Next_E);
645 return;
647 else
648 exit;
649 end if;
650 end if;
652 Next (Decl);
653 end loop;
654 end if;
656 -- If partial view is not a type extension, or it appears before the
657 -- subprogram declaration, insert normally at end of entity list.
659 Append_Entity (S, Current_Scope);
660 end Append_Inherited_Subprogram;
662 -----------------------------------------
663 -- Apply_Compile_Time_Constraint_Error --
664 -----------------------------------------
666 procedure Apply_Compile_Time_Constraint_Error
667 (N : Node_Id;
668 Msg : String;
669 Reason : RT_Exception_Code;
670 Ent : Entity_Id := Empty;
671 Typ : Entity_Id := Empty;
672 Loc : Source_Ptr := No_Location;
673 Rep : Boolean := True;
674 Warn : Boolean := False)
676 Stat : constant Boolean := Is_Static_Expression (N);
677 R_Stat : constant Node_Id :=
678 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
679 Rtyp : Entity_Id;
681 begin
682 if No (Typ) then
683 Rtyp := Etype (N);
684 else
685 Rtyp := Typ;
686 end if;
688 Discard_Node
689 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
691 if not Rep then
692 return;
693 end if;
695 -- Now we replace the node by an N_Raise_Constraint_Error node
696 -- This does not need reanalyzing, so set it as analyzed now.
698 Rewrite (N, R_Stat);
699 Set_Analyzed (N, True);
701 Set_Etype (N, Rtyp);
702 Set_Raises_Constraint_Error (N);
704 -- Now deal with possible local raise handling
706 Possible_Local_Raise (N, Standard_Constraint_Error);
708 -- If the original expression was marked as static, the result is
709 -- still marked as static, but the Raises_Constraint_Error flag is
710 -- always set so that further static evaluation is not attempted.
712 if Stat then
713 Set_Is_Static_Expression (N);
714 end if;
715 end Apply_Compile_Time_Constraint_Error;
717 ---------------------------
718 -- Async_Readers_Enabled --
719 ---------------------------
721 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
722 begin
723 return Has_Enabled_Property (Id, Name_Async_Readers);
724 end Async_Readers_Enabled;
726 ---------------------------
727 -- Async_Writers_Enabled --
728 ---------------------------
730 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
731 begin
732 return Has_Enabled_Property (Id, Name_Async_Writers);
733 end Async_Writers_Enabled;
735 --------------------------------------
736 -- Available_Full_View_Of_Component --
737 --------------------------------------
739 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
740 ST : constant Entity_Id := Scope (T);
741 SCT : constant Entity_Id := Scope (Component_Type (T));
742 begin
743 return In_Open_Scopes (ST)
744 and then In_Open_Scopes (SCT)
745 and then Scope_Depth (ST) >= Scope_Depth (SCT);
746 end Available_Full_View_Of_Component;
748 -------------------
749 -- Bad_Attribute --
750 -------------------
752 procedure Bad_Attribute
753 (N : Node_Id;
754 Nam : Name_Id;
755 Warn : Boolean := False)
757 begin
758 Error_Msg_Warn := Warn;
759 Error_Msg_N ("unrecognized attribute&<<", N);
761 -- Check for possible misspelling
763 Error_Msg_Name_1 := First_Attribute_Name;
764 while Error_Msg_Name_1 <= Last_Attribute_Name loop
765 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
766 Error_Msg_N -- CODEFIX
767 ("\possible misspelling of %<<", N);
768 exit;
769 end if;
771 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
772 end loop;
773 end Bad_Attribute;
775 --------------------------------
776 -- Bad_Predicated_Subtype_Use --
777 --------------------------------
779 procedure Bad_Predicated_Subtype_Use
780 (Msg : String;
781 N : Node_Id;
782 Typ : Entity_Id;
783 Suggest_Static : Boolean := False)
785 Gen : Entity_Id;
787 begin
788 -- Avoid cascaded errors
790 if Error_Posted (N) then
791 return;
792 end if;
794 if Inside_A_Generic then
795 Gen := Current_Scope;
796 while Present (Gen) and then Ekind (Gen) /= E_Generic_Package loop
797 Gen := Scope (Gen);
798 end loop;
800 if No (Gen) then
801 return;
802 end if;
804 if Is_Generic_Formal (Typ)
805 and then Is_Discrete_Type (Typ)
806 then
807 Set_No_Predicate_On_Actual (Typ);
808 end if;
810 elsif Has_Predicates (Typ) then
811 if Is_Generic_Actual_Type (Typ) then
813 -- The restriction on loop parameters is only that the type
814 -- should have no dynamic predicates.
816 if Nkind (Parent (N)) = N_Loop_Parameter_Specification
817 and then not Has_Dynamic_Predicate_Aspect (Typ)
818 and then Is_OK_Static_Subtype (Typ)
819 then
820 return;
821 end if;
823 Gen := Current_Scope;
824 while not Is_Generic_Instance (Gen) loop
825 Gen := Scope (Gen);
826 end loop;
828 pragma Assert (Present (Gen));
830 if Ekind (Gen) = E_Package and then In_Package_Body (Gen) then
831 Error_Msg_Warn := SPARK_Mode /= On;
832 Error_Msg_FE (Msg & "<<", N, Typ);
833 Error_Msg_F ("\Program_Error [<<", N);
835 Insert_Action (N,
836 Make_Raise_Program_Error (Sloc (N),
837 Reason => PE_Bad_Predicated_Generic_Type));
839 else
840 Error_Msg_FE (Msg & "<<", N, Typ);
841 end if;
843 else
844 Error_Msg_FE (Msg, N, Typ);
845 end if;
847 -- Emit an optional suggestion on how to remedy the error if the
848 -- context warrants it.
850 if Suggest_Static and then Has_Static_Predicate (Typ) then
851 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
852 end if;
853 end if;
854 end Bad_Predicated_Subtype_Use;
856 -----------------------------------------
857 -- Bad_Unordered_Enumeration_Reference --
858 -----------------------------------------
860 function Bad_Unordered_Enumeration_Reference
861 (N : Node_Id;
862 T : Entity_Id) return Boolean
864 begin
865 return Is_Enumeration_Type (T)
866 and then Comes_From_Source (N)
867 and then Warn_On_Unordered_Enumeration_Type
868 and then not Has_Pragma_Ordered (T)
869 and then not In_Same_Extended_Unit (N, T);
870 end Bad_Unordered_Enumeration_Reference;
872 --------------------------
873 -- Build_Actual_Subtype --
874 --------------------------
876 function Build_Actual_Subtype
877 (T : Entity_Id;
878 N : Node_Or_Entity_Id) return Node_Id
880 Loc : Source_Ptr;
881 -- Normally Sloc (N), but may point to corresponding body in some cases
883 Constraints : List_Id;
884 Decl : Node_Id;
885 Discr : Entity_Id;
886 Hi : Node_Id;
887 Lo : Node_Id;
888 Subt : Entity_Id;
889 Disc_Type : Entity_Id;
890 Obj : Node_Id;
892 begin
893 Loc := Sloc (N);
895 if Nkind (N) = N_Defining_Identifier then
896 Obj := New_Occurrence_Of (N, Loc);
898 -- If this is a formal parameter of a subprogram declaration, and
899 -- we are compiling the body, we want the declaration for the
900 -- actual subtype to carry the source position of the body, to
901 -- prevent anomalies in gdb when stepping through the code.
903 if Is_Formal (N) then
904 declare
905 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
906 begin
907 if Nkind (Decl) = N_Subprogram_Declaration
908 and then Present (Corresponding_Body (Decl))
909 then
910 Loc := Sloc (Corresponding_Body (Decl));
911 end if;
912 end;
913 end if;
915 else
916 Obj := N;
917 end if;
919 if Is_Array_Type (T) then
920 Constraints := New_List;
921 for J in 1 .. Number_Dimensions (T) loop
923 -- Build an array subtype declaration with the nominal subtype and
924 -- the bounds of the actual. Add the declaration in front of the
925 -- local declarations for the subprogram, for analysis before any
926 -- reference to the formal in the body.
928 Lo :=
929 Make_Attribute_Reference (Loc,
930 Prefix =>
931 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
932 Attribute_Name => Name_First,
933 Expressions => New_List (
934 Make_Integer_Literal (Loc, J)));
936 Hi :=
937 Make_Attribute_Reference (Loc,
938 Prefix =>
939 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
940 Attribute_Name => Name_Last,
941 Expressions => New_List (
942 Make_Integer_Literal (Loc, J)));
944 Append (Make_Range (Loc, Lo, Hi), Constraints);
945 end loop;
947 -- If the type has unknown discriminants there is no constrained
948 -- subtype to build. This is never called for a formal or for a
949 -- lhs, so returning the type is ok ???
951 elsif Has_Unknown_Discriminants (T) then
952 return T;
954 else
955 Constraints := New_List;
957 -- Type T is a generic derived type, inherit the discriminants from
958 -- the parent type.
960 if Is_Private_Type (T)
961 and then No (Full_View (T))
963 -- T was flagged as an error if it was declared as a formal
964 -- derived type with known discriminants. In this case there
965 -- is no need to look at the parent type since T already carries
966 -- its own discriminants.
968 and then not Error_Posted (T)
969 then
970 Disc_Type := Etype (Base_Type (T));
971 else
972 Disc_Type := T;
973 end if;
975 Discr := First_Discriminant (Disc_Type);
976 while Present (Discr) loop
977 Append_To (Constraints,
978 Make_Selected_Component (Loc,
979 Prefix =>
980 Duplicate_Subexpr_No_Checks (Obj),
981 Selector_Name => New_Occurrence_Of (Discr, Loc)));
982 Next_Discriminant (Discr);
983 end loop;
984 end if;
986 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
987 Set_Is_Internal (Subt);
989 Decl :=
990 Make_Subtype_Declaration (Loc,
991 Defining_Identifier => Subt,
992 Subtype_Indication =>
993 Make_Subtype_Indication (Loc,
994 Subtype_Mark => New_Occurrence_Of (T, Loc),
995 Constraint =>
996 Make_Index_Or_Discriminant_Constraint (Loc,
997 Constraints => Constraints)));
999 Mark_Rewrite_Insertion (Decl);
1000 return Decl;
1001 end Build_Actual_Subtype;
1003 ---------------------------------------
1004 -- Build_Actual_Subtype_Of_Component --
1005 ---------------------------------------
1007 function Build_Actual_Subtype_Of_Component
1008 (T : Entity_Id;
1009 N : Node_Id) return Node_Id
1011 Loc : constant Source_Ptr := Sloc (N);
1012 P : constant Node_Id := Prefix (N);
1013 D : Elmt_Id;
1014 Id : Node_Id;
1015 Index_Typ : Entity_Id;
1017 Desig_Typ : Entity_Id;
1018 -- This is either a copy of T, or if T is an access type, then it is
1019 -- the directly designated type of this access type.
1021 function Build_Actual_Array_Constraint return List_Id;
1022 -- If one or more of the bounds of the component depends on
1023 -- discriminants, build actual constraint using the discriminants
1024 -- of the prefix.
1026 function Build_Actual_Record_Constraint return List_Id;
1027 -- Similar to previous one, for discriminated components constrained
1028 -- by the discriminant of the enclosing object.
1030 -----------------------------------
1031 -- Build_Actual_Array_Constraint --
1032 -----------------------------------
1034 function Build_Actual_Array_Constraint return List_Id is
1035 Constraints : constant List_Id := New_List;
1036 Indx : Node_Id;
1037 Hi : Node_Id;
1038 Lo : Node_Id;
1039 Old_Hi : Node_Id;
1040 Old_Lo : Node_Id;
1042 begin
1043 Indx := First_Index (Desig_Typ);
1044 while Present (Indx) loop
1045 Old_Lo := Type_Low_Bound (Etype (Indx));
1046 Old_Hi := Type_High_Bound (Etype (Indx));
1048 if Denotes_Discriminant (Old_Lo) then
1049 Lo :=
1050 Make_Selected_Component (Loc,
1051 Prefix => New_Copy_Tree (P),
1052 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
1054 else
1055 Lo := New_Copy_Tree (Old_Lo);
1057 -- The new bound will be reanalyzed in the enclosing
1058 -- declaration. For literal bounds that come from a type
1059 -- declaration, the type of the context must be imposed, so
1060 -- insure that analysis will take place. For non-universal
1061 -- types this is not strictly necessary.
1063 Set_Analyzed (Lo, False);
1064 end if;
1066 if Denotes_Discriminant (Old_Hi) then
1067 Hi :=
1068 Make_Selected_Component (Loc,
1069 Prefix => New_Copy_Tree (P),
1070 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
1072 else
1073 Hi := New_Copy_Tree (Old_Hi);
1074 Set_Analyzed (Hi, False);
1075 end if;
1077 Append (Make_Range (Loc, Lo, Hi), Constraints);
1078 Next_Index (Indx);
1079 end loop;
1081 return Constraints;
1082 end Build_Actual_Array_Constraint;
1084 ------------------------------------
1085 -- Build_Actual_Record_Constraint --
1086 ------------------------------------
1088 function Build_Actual_Record_Constraint return List_Id is
1089 Constraints : constant List_Id := New_List;
1090 D : Elmt_Id;
1091 D_Val : Node_Id;
1093 begin
1094 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1095 while Present (D) loop
1096 if Denotes_Discriminant (Node (D)) then
1097 D_Val := Make_Selected_Component (Loc,
1098 Prefix => New_Copy_Tree (P),
1099 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
1101 else
1102 D_Val := New_Copy_Tree (Node (D));
1103 end if;
1105 Append (D_Val, Constraints);
1106 Next_Elmt (D);
1107 end loop;
1109 return Constraints;
1110 end Build_Actual_Record_Constraint;
1112 -- Start of processing for Build_Actual_Subtype_Of_Component
1114 begin
1115 -- Why the test for Spec_Expression mode here???
1117 if In_Spec_Expression then
1118 return Empty;
1120 -- More comments for the rest of this body would be good ???
1122 elsif Nkind (N) = N_Explicit_Dereference then
1123 if Is_Composite_Type (T)
1124 and then not Is_Constrained (T)
1125 and then not (Is_Class_Wide_Type (T)
1126 and then Is_Constrained (Root_Type (T)))
1127 and then not Has_Unknown_Discriminants (T)
1128 then
1129 -- If the type of the dereference is already constrained, it is an
1130 -- actual subtype.
1132 if Is_Array_Type (Etype (N))
1133 and then Is_Constrained (Etype (N))
1134 then
1135 return Empty;
1136 else
1137 Remove_Side_Effects (P);
1138 return Build_Actual_Subtype (T, N);
1139 end if;
1140 else
1141 return Empty;
1142 end if;
1143 end if;
1145 if Ekind (T) = E_Access_Subtype then
1146 Desig_Typ := Designated_Type (T);
1147 else
1148 Desig_Typ := T;
1149 end if;
1151 if Ekind (Desig_Typ) = E_Array_Subtype then
1152 Id := First_Index (Desig_Typ);
1153 while Present (Id) loop
1154 Index_Typ := Underlying_Type (Etype (Id));
1156 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
1157 or else
1158 Denotes_Discriminant (Type_High_Bound (Index_Typ))
1159 then
1160 Remove_Side_Effects (P);
1161 return
1162 Build_Component_Subtype
1163 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
1164 end if;
1166 Next_Index (Id);
1167 end loop;
1169 elsif Is_Composite_Type (Desig_Typ)
1170 and then Has_Discriminants (Desig_Typ)
1171 and then not Has_Unknown_Discriminants (Desig_Typ)
1172 then
1173 if Is_Private_Type (Desig_Typ)
1174 and then No (Discriminant_Constraint (Desig_Typ))
1175 then
1176 Desig_Typ := Full_View (Desig_Typ);
1177 end if;
1179 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
1180 while Present (D) loop
1181 if Denotes_Discriminant (Node (D)) then
1182 Remove_Side_Effects (P);
1183 return
1184 Build_Component_Subtype (
1185 Build_Actual_Record_Constraint, Loc, Base_Type (T));
1186 end if;
1188 Next_Elmt (D);
1189 end loop;
1190 end if;
1192 -- If none of the above, the actual and nominal subtypes are the same
1194 return Empty;
1195 end Build_Actual_Subtype_Of_Component;
1197 -----------------------------
1198 -- Build_Component_Subtype --
1199 -----------------------------
1201 function Build_Component_Subtype
1202 (C : List_Id;
1203 Loc : Source_Ptr;
1204 T : Entity_Id) return Node_Id
1206 Subt : Entity_Id;
1207 Decl : Node_Id;
1209 begin
1210 -- Unchecked_Union components do not require component subtypes
1212 if Is_Unchecked_Union (T) then
1213 return Empty;
1214 end if;
1216 Subt := Make_Temporary (Loc, 'S');
1217 Set_Is_Internal (Subt);
1219 Decl :=
1220 Make_Subtype_Declaration (Loc,
1221 Defining_Identifier => Subt,
1222 Subtype_Indication =>
1223 Make_Subtype_Indication (Loc,
1224 Subtype_Mark => New_Occurrence_Of (Base_Type (T), Loc),
1225 Constraint =>
1226 Make_Index_Or_Discriminant_Constraint (Loc,
1227 Constraints => C)));
1229 Mark_Rewrite_Insertion (Decl);
1230 return Decl;
1231 end Build_Component_Subtype;
1233 ----------------------------------
1234 -- Build_Default_Init_Cond_Call --
1235 ----------------------------------
1237 function Build_Default_Init_Cond_Call
1238 (Loc : Source_Ptr;
1239 Obj_Id : Entity_Id;
1240 Typ : Entity_Id) return Node_Id
1242 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1243 Formal_Typ : constant Entity_Id := Etype (First_Formal (Proc_Id));
1245 begin
1246 return
1247 Make_Procedure_Call_Statement (Loc,
1248 Name => New_Occurrence_Of (Proc_Id, Loc),
1249 Parameter_Associations => New_List (
1250 Make_Type_Conversion (Loc,
1251 Subtype_Mark => New_Occurrence_Of (Formal_Typ, Loc),
1252 Expression => New_Occurrence_Of (Obj_Id, Loc))));
1253 end Build_Default_Init_Cond_Call;
1255 --------------------------------------------
1256 -- Build_Default_Init_Cond_Procedure_Body --
1257 --------------------------------------------
1259 procedure Build_Default_Init_Cond_Procedure_Body (Typ : Entity_Id) is
1260 Param_Id : Entity_Id;
1261 -- The entity of the formal parameter of the default initial condition
1262 -- procedure.
1264 procedure Replace_Type_Reference (N : Node_Id);
1265 -- Replace a single reference to type Typ with a reference to Param_Id
1267 ----------------------------
1268 -- Replace_Type_Reference --
1269 ----------------------------
1271 procedure Replace_Type_Reference (N : Node_Id) is
1272 begin
1273 Rewrite (N, New_Occurrence_Of (Param_Id, Sloc (N)));
1274 end Replace_Type_Reference;
1276 procedure Replace_Type_References is
1277 new Replace_Type_References_Generic (Replace_Type_Reference);
1279 -- Local variables
1281 Loc : constant Source_Ptr := Sloc (Typ);
1282 Prag : constant Node_Id :=
1283 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1284 Proc_Id : constant Entity_Id := Default_Init_Cond_Procedure (Typ);
1285 Spec_Decl : constant Node_Id := Unit_Declaration_Node (Proc_Id);
1286 Body_Decl : Node_Id;
1287 Expr : Node_Id;
1288 Stmt : Node_Id;
1290 -- Start of processing for Build_Default_Init_Cond_Procedure
1292 begin
1293 -- The procedure should be generated only for types subject to pragma
1294 -- Default_Initial_Condition. Types that inherit the pragma do not get
1295 -- this specialized procedure.
1297 pragma Assert (Has_Default_Init_Cond (Typ));
1298 pragma Assert (Present (Prag));
1299 pragma Assert (Present (Proc_Id));
1301 -- Nothing to do if the body was already built
1303 if Present (Corresponding_Body (Spec_Decl)) then
1304 return;
1305 end if;
1307 Param_Id := First_Formal (Proc_Id);
1309 -- The pragma has an argument. Note that the argument is analyzed after
1310 -- all references to the current instance of the type are replaced.
1312 if Present (Pragma_Argument_Associations (Prag)) then
1313 Expr := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
1315 if Nkind (Expr) = N_Null then
1316 Stmt := Make_Null_Statement (Loc);
1318 -- Preserve the original argument of the pragma by replicating it.
1319 -- Replace all references to the current instance of the type with
1320 -- references to the formal parameter.
1322 else
1323 Expr := New_Copy_Tree (Expr);
1324 Replace_Type_References (Expr, Typ);
1326 -- Generate:
1327 -- pragma Check (Default_Initial_Condition, <Expr>);
1329 Stmt :=
1330 Make_Pragma (Loc,
1331 Pragma_Identifier =>
1332 Make_Identifier (Loc, Name_Check),
1334 Pragma_Argument_Associations => New_List (
1335 Make_Pragma_Argument_Association (Loc,
1336 Expression =>
1337 Make_Identifier (Loc, Name_Default_Initial_Condition)),
1338 Make_Pragma_Argument_Association (Loc,
1339 Expression => Expr)));
1340 end if;
1342 -- Otherwise the pragma appears without an argument
1344 else
1345 Stmt := Make_Null_Statement (Loc);
1346 end if;
1348 -- Generate:
1349 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1350 -- begin
1351 -- <Stmt>;
1352 -- end <Typ>Default_Init_Cond;
1354 Body_Decl :=
1355 Make_Subprogram_Body (Loc,
1356 Specification =>
1357 Copy_Separate_Tree (Specification (Spec_Decl)),
1358 Declarations => Empty_List,
1359 Handled_Statement_Sequence =>
1360 Make_Handled_Sequence_Of_Statements (Loc,
1361 Statements => New_List (Stmt)));
1363 -- Link the spec and body of the default initial condition procedure
1364 -- to prevent the generation of a duplicate body in case there is an
1365 -- attempt to freeze the related type again.
1367 Set_Corresponding_Body (Spec_Decl, Defining_Entity (Body_Decl));
1368 Set_Corresponding_Spec (Body_Decl, Proc_Id);
1370 Append_Freeze_Action (Typ, Body_Decl);
1371 end Build_Default_Init_Cond_Procedure_Body;
1373 ---------------------------------------------------
1374 -- Build_Default_Init_Cond_Procedure_Declaration --
1375 ---------------------------------------------------
1377 procedure Build_Default_Init_Cond_Procedure_Declaration (Typ : Entity_Id) is
1378 Loc : constant Source_Ptr := Sloc (Typ);
1379 Prag : constant Node_Id :=
1380 Get_Pragma (Typ, Pragma_Default_Initial_Condition);
1381 Proc_Id : Entity_Id;
1383 begin
1384 -- The procedure should be generated only for types subject to pragma
1385 -- Default_Initial_Condition. Types that inherit the pragma do not get
1386 -- this specialized procedure.
1388 pragma Assert (Has_Default_Init_Cond (Typ));
1389 pragma Assert (Present (Prag));
1391 Proc_Id :=
1392 Make_Defining_Identifier (Loc,
1393 Chars => New_External_Name (Chars (Typ), "Default_Init_Cond"));
1395 -- Associate default initial condition procedure with the private type
1397 Set_Ekind (Proc_Id, E_Procedure);
1398 Set_Is_Default_Init_Cond_Procedure (Proc_Id);
1399 Set_Default_Init_Cond_Procedure (Typ, Proc_Id);
1401 -- Generate:
1402 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1404 Insert_After_And_Analyze (Prag,
1405 Make_Subprogram_Declaration (Loc,
1406 Specification =>
1407 Make_Procedure_Specification (Loc,
1408 Defining_Unit_Name => Proc_Id,
1409 Parameter_Specifications => New_List (
1410 Make_Parameter_Specification (Loc,
1411 Defining_Identifier => Make_Temporary (Loc, 'I'),
1412 Parameter_Type => New_Occurrence_Of (Typ, Loc))))));
1413 end Build_Default_Init_Cond_Procedure_Declaration;
1415 ---------------------------
1416 -- Build_Default_Subtype --
1417 ---------------------------
1419 function Build_Default_Subtype
1420 (T : Entity_Id;
1421 N : Node_Id) return Entity_Id
1423 Loc : constant Source_Ptr := Sloc (N);
1424 Disc : Entity_Id;
1426 Bas : Entity_Id;
1427 -- The base type that is to be constrained by the defaults
1429 begin
1430 if not Has_Discriminants (T) or else Is_Constrained (T) then
1431 return T;
1432 end if;
1434 Bas := Base_Type (T);
1436 -- If T is non-private but its base type is private, this is the
1437 -- completion of a subtype declaration whose parent type is private
1438 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1439 -- are to be found in the full view of the base. Check that the private
1440 -- status of T and its base differ.
1442 if Is_Private_Type (Bas)
1443 and then not Is_Private_Type (T)
1444 and then Present (Full_View (Bas))
1445 then
1446 Bas := Full_View (Bas);
1447 end if;
1449 Disc := First_Discriminant (T);
1451 if No (Discriminant_Default_Value (Disc)) then
1452 return T;
1453 end if;
1455 declare
1456 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1457 Constraints : constant List_Id := New_List;
1458 Decl : Node_Id;
1460 begin
1461 while Present (Disc) loop
1462 Append_To (Constraints,
1463 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1464 Next_Discriminant (Disc);
1465 end loop;
1467 Decl :=
1468 Make_Subtype_Declaration (Loc,
1469 Defining_Identifier => Act,
1470 Subtype_Indication =>
1471 Make_Subtype_Indication (Loc,
1472 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1473 Constraint =>
1474 Make_Index_Or_Discriminant_Constraint (Loc,
1475 Constraints => Constraints)));
1477 Insert_Action (N, Decl);
1478 Analyze (Decl);
1479 return Act;
1480 end;
1481 end Build_Default_Subtype;
1483 --------------------------------------------
1484 -- Build_Discriminal_Subtype_Of_Component --
1485 --------------------------------------------
1487 function Build_Discriminal_Subtype_Of_Component
1488 (T : Entity_Id) return Node_Id
1490 Loc : constant Source_Ptr := Sloc (T);
1491 D : Elmt_Id;
1492 Id : Node_Id;
1494 function Build_Discriminal_Array_Constraint return List_Id;
1495 -- If one or more of the bounds of the component depends on
1496 -- discriminants, build actual constraint using the discriminants
1497 -- of the prefix.
1499 function Build_Discriminal_Record_Constraint return List_Id;
1500 -- Similar to previous one, for discriminated components constrained by
1501 -- the discriminant of the enclosing object.
1503 ----------------------------------------
1504 -- Build_Discriminal_Array_Constraint --
1505 ----------------------------------------
1507 function Build_Discriminal_Array_Constraint return List_Id is
1508 Constraints : constant List_Id := New_List;
1509 Indx : Node_Id;
1510 Hi : Node_Id;
1511 Lo : Node_Id;
1512 Old_Hi : Node_Id;
1513 Old_Lo : Node_Id;
1515 begin
1516 Indx := First_Index (T);
1517 while Present (Indx) loop
1518 Old_Lo := Type_Low_Bound (Etype (Indx));
1519 Old_Hi := Type_High_Bound (Etype (Indx));
1521 if Denotes_Discriminant (Old_Lo) then
1522 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1524 else
1525 Lo := New_Copy_Tree (Old_Lo);
1526 end if;
1528 if Denotes_Discriminant (Old_Hi) then
1529 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1531 else
1532 Hi := New_Copy_Tree (Old_Hi);
1533 end if;
1535 Append (Make_Range (Loc, Lo, Hi), Constraints);
1536 Next_Index (Indx);
1537 end loop;
1539 return Constraints;
1540 end Build_Discriminal_Array_Constraint;
1542 -----------------------------------------
1543 -- Build_Discriminal_Record_Constraint --
1544 -----------------------------------------
1546 function Build_Discriminal_Record_Constraint return List_Id is
1547 Constraints : constant List_Id := New_List;
1548 D : Elmt_Id;
1549 D_Val : Node_Id;
1551 begin
1552 D := First_Elmt (Discriminant_Constraint (T));
1553 while Present (D) loop
1554 if Denotes_Discriminant (Node (D)) then
1555 D_Val :=
1556 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1557 else
1558 D_Val := New_Copy_Tree (Node (D));
1559 end if;
1561 Append (D_Val, Constraints);
1562 Next_Elmt (D);
1563 end loop;
1565 return Constraints;
1566 end Build_Discriminal_Record_Constraint;
1568 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1570 begin
1571 if Ekind (T) = E_Array_Subtype then
1572 Id := First_Index (T);
1573 while Present (Id) loop
1574 if Denotes_Discriminant (Type_Low_Bound (Etype (Id)))
1575 or else
1576 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1577 then
1578 return Build_Component_Subtype
1579 (Build_Discriminal_Array_Constraint, Loc, T);
1580 end if;
1582 Next_Index (Id);
1583 end loop;
1585 elsif Ekind (T) = E_Record_Subtype
1586 and then Has_Discriminants (T)
1587 and then not Has_Unknown_Discriminants (T)
1588 then
1589 D := First_Elmt (Discriminant_Constraint (T));
1590 while Present (D) loop
1591 if Denotes_Discriminant (Node (D)) then
1592 return Build_Component_Subtype
1593 (Build_Discriminal_Record_Constraint, Loc, T);
1594 end if;
1596 Next_Elmt (D);
1597 end loop;
1598 end if;
1600 -- If none of the above, the actual and nominal subtypes are the same
1602 return Empty;
1603 end Build_Discriminal_Subtype_Of_Component;
1605 ------------------------------
1606 -- Build_Elaboration_Entity --
1607 ------------------------------
1609 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1610 Loc : constant Source_Ptr := Sloc (N);
1611 Decl : Node_Id;
1612 Elab_Ent : Entity_Id;
1614 procedure Set_Package_Name (Ent : Entity_Id);
1615 -- Given an entity, sets the fully qualified name of the entity in
1616 -- Name_Buffer, with components separated by double underscores. This
1617 -- is a recursive routine that climbs the scope chain to Standard.
1619 ----------------------
1620 -- Set_Package_Name --
1621 ----------------------
1623 procedure Set_Package_Name (Ent : Entity_Id) is
1624 begin
1625 if Scope (Ent) /= Standard_Standard then
1626 Set_Package_Name (Scope (Ent));
1628 declare
1629 Nam : constant String := Get_Name_String (Chars (Ent));
1630 begin
1631 Name_Buffer (Name_Len + 1) := '_';
1632 Name_Buffer (Name_Len + 2) := '_';
1633 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1634 Name_Len := Name_Len + Nam'Length + 2;
1635 end;
1637 else
1638 Get_Name_String (Chars (Ent));
1639 end if;
1640 end Set_Package_Name;
1642 -- Start of processing for Build_Elaboration_Entity
1644 begin
1645 -- Ignore call if already constructed
1647 if Present (Elaboration_Entity (Spec_Id)) then
1648 return;
1650 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1651 -- no role in analysis.
1653 elsif ASIS_Mode then
1654 return;
1656 -- See if we need elaboration entity. We always need it for the dynamic
1657 -- elaboration model, since it is needed to properly generate the PE
1658 -- exception for access before elaboration.
1660 elsif Dynamic_Elaboration_Checks then
1661 null;
1663 -- For the static model, we don't need the elaboration counter if this
1664 -- unit is sure to have no elaboration code, since that means there
1665 -- is no elaboration unit to be called. Note that we can't just decide
1666 -- after the fact by looking to see whether there was elaboration code,
1667 -- because that's too late to make this decision.
1669 elsif Restriction_Active (No_Elaboration_Code) then
1670 return;
1672 -- Similarly, for the static model, we can skip the elaboration counter
1673 -- if we have the No_Multiple_Elaboration restriction, since for the
1674 -- static model, that's the only purpose of the counter (to avoid
1675 -- multiple elaboration).
1677 elsif Restriction_Active (No_Multiple_Elaboration) then
1678 return;
1679 end if;
1681 -- Here we need the elaboration entity
1683 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1684 -- name with dots replaced by double underscore. We have to manually
1685 -- construct this name, since it will be elaborated in the outer scope,
1686 -- and thus will not have the unit name automatically prepended.
1688 Set_Package_Name (Spec_Id);
1689 Add_Str_To_Name_Buffer ("_E");
1691 -- Create elaboration counter
1693 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1694 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1696 Decl :=
1697 Make_Object_Declaration (Loc,
1698 Defining_Identifier => Elab_Ent,
1699 Object_Definition =>
1700 New_Occurrence_Of (Standard_Short_Integer, Loc),
1701 Expression => Make_Integer_Literal (Loc, Uint_0));
1703 Push_Scope (Standard_Standard);
1704 Add_Global_Declaration (Decl);
1705 Pop_Scope;
1707 -- Reset True_Constant indication, since we will indeed assign a value
1708 -- to the variable in the binder main. We also kill the Current_Value
1709 -- and Last_Assignment fields for the same reason.
1711 Set_Is_True_Constant (Elab_Ent, False);
1712 Set_Current_Value (Elab_Ent, Empty);
1713 Set_Last_Assignment (Elab_Ent, Empty);
1715 -- We do not want any further qualification of the name (if we did not
1716 -- do this, we would pick up the name of the generic package in the case
1717 -- of a library level generic instantiation).
1719 Set_Has_Qualified_Name (Elab_Ent);
1720 Set_Has_Fully_Qualified_Name (Elab_Ent);
1721 end Build_Elaboration_Entity;
1723 --------------------------------
1724 -- Build_Explicit_Dereference --
1725 --------------------------------
1727 procedure Build_Explicit_Dereference
1728 (Expr : Node_Id;
1729 Disc : Entity_Id)
1731 Loc : constant Source_Ptr := Sloc (Expr);
1733 begin
1734 -- An entity of a type with a reference aspect is overloaded with
1735 -- both interpretations: with and without the dereference. Now that
1736 -- the dereference is made explicit, set the type of the node properly,
1737 -- to prevent anomalies in the backend. Same if the expression is an
1738 -- overloaded function call whose return type has a reference aspect.
1740 if Is_Entity_Name (Expr) then
1741 Set_Etype (Expr, Etype (Entity (Expr)));
1743 elsif Nkind (Expr) = N_Function_Call then
1744 Set_Etype (Expr, Etype (Name (Expr)));
1745 end if;
1747 Set_Is_Overloaded (Expr, False);
1749 -- The expression will often be a generalized indexing that yields a
1750 -- container element that is then dereferenced, in which case the
1751 -- generalized indexing call is also non-overloaded.
1753 if Nkind (Expr) = N_Indexed_Component
1754 and then Present (Generalized_Indexing (Expr))
1755 then
1756 Set_Is_Overloaded (Generalized_Indexing (Expr), False);
1757 end if;
1759 Rewrite (Expr,
1760 Make_Explicit_Dereference (Loc,
1761 Prefix =>
1762 Make_Selected_Component (Loc,
1763 Prefix => Relocate_Node (Expr),
1764 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1765 Set_Etype (Prefix (Expr), Etype (Disc));
1766 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1767 end Build_Explicit_Dereference;
1769 -----------------------------------
1770 -- Cannot_Raise_Constraint_Error --
1771 -----------------------------------
1773 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1774 begin
1775 if Compile_Time_Known_Value (Expr) then
1776 return True;
1778 elsif Do_Range_Check (Expr) then
1779 return False;
1781 elsif Raises_Constraint_Error (Expr) then
1782 return False;
1784 else
1785 case Nkind (Expr) is
1786 when N_Identifier =>
1787 return True;
1789 when N_Expanded_Name =>
1790 return True;
1792 when N_Selected_Component =>
1793 return not Do_Discriminant_Check (Expr);
1795 when N_Attribute_Reference =>
1796 if Do_Overflow_Check (Expr) then
1797 return False;
1799 elsif No (Expressions (Expr)) then
1800 return True;
1802 else
1803 declare
1804 N : Node_Id;
1806 begin
1807 N := First (Expressions (Expr));
1808 while Present (N) loop
1809 if Cannot_Raise_Constraint_Error (N) then
1810 Next (N);
1811 else
1812 return False;
1813 end if;
1814 end loop;
1816 return True;
1817 end;
1818 end if;
1820 when N_Type_Conversion =>
1821 if Do_Overflow_Check (Expr)
1822 or else Do_Length_Check (Expr)
1823 or else Do_Tag_Check (Expr)
1824 then
1825 return False;
1826 else
1827 return Cannot_Raise_Constraint_Error (Expression (Expr));
1828 end if;
1830 when N_Unchecked_Type_Conversion =>
1831 return Cannot_Raise_Constraint_Error (Expression (Expr));
1833 when N_Unary_Op =>
1834 if Do_Overflow_Check (Expr) then
1835 return False;
1836 else
1837 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1838 end if;
1840 when N_Op_Divide |
1841 N_Op_Mod |
1842 N_Op_Rem
1844 if Do_Division_Check (Expr)
1845 or else
1846 Do_Overflow_Check (Expr)
1847 then
1848 return False;
1849 else
1850 return
1851 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1852 and then
1853 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1854 end if;
1856 when N_Op_Add |
1857 N_Op_And |
1858 N_Op_Concat |
1859 N_Op_Eq |
1860 N_Op_Expon |
1861 N_Op_Ge |
1862 N_Op_Gt |
1863 N_Op_Le |
1864 N_Op_Lt |
1865 N_Op_Multiply |
1866 N_Op_Ne |
1867 N_Op_Or |
1868 N_Op_Rotate_Left |
1869 N_Op_Rotate_Right |
1870 N_Op_Shift_Left |
1871 N_Op_Shift_Right |
1872 N_Op_Shift_Right_Arithmetic |
1873 N_Op_Subtract |
1874 N_Op_Xor
1876 if Do_Overflow_Check (Expr) then
1877 return False;
1878 else
1879 return
1880 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1881 and then
1882 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1883 end if;
1885 when others =>
1886 return False;
1887 end case;
1888 end if;
1889 end Cannot_Raise_Constraint_Error;
1891 -----------------------------------------
1892 -- Check_Dynamically_Tagged_Expression --
1893 -----------------------------------------
1895 procedure Check_Dynamically_Tagged_Expression
1896 (Expr : Node_Id;
1897 Typ : Entity_Id;
1898 Related_Nod : Node_Id)
1900 begin
1901 pragma Assert (Is_Tagged_Type (Typ));
1903 -- In order to avoid spurious errors when analyzing the expanded code,
1904 -- this check is done only for nodes that come from source and for
1905 -- actuals of generic instantiations.
1907 if (Comes_From_Source (Related_Nod)
1908 or else In_Generic_Actual (Expr))
1909 and then (Is_Class_Wide_Type (Etype (Expr))
1910 or else Is_Dynamically_Tagged (Expr))
1911 and then Is_Tagged_Type (Typ)
1912 and then not Is_Class_Wide_Type (Typ)
1913 then
1914 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1915 end if;
1916 end Check_Dynamically_Tagged_Expression;
1918 --------------------------
1919 -- Check_Fully_Declared --
1920 --------------------------
1922 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1923 begin
1924 if Ekind (T) = E_Incomplete_Type then
1926 -- Ada 2005 (AI-50217): If the type is available through a limited
1927 -- with_clause, verify that its full view has been analyzed.
1929 if From_Limited_With (T)
1930 and then Present (Non_Limited_View (T))
1931 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1932 then
1933 -- The non-limited view is fully declared
1934 null;
1936 else
1937 Error_Msg_NE
1938 ("premature usage of incomplete}", N, First_Subtype (T));
1939 end if;
1941 -- Need comments for these tests ???
1943 elsif Has_Private_Component (T)
1944 and then not Is_Generic_Type (Root_Type (T))
1945 and then not In_Spec_Expression
1946 then
1947 -- Special case: if T is the anonymous type created for a single
1948 -- task or protected object, use the name of the source object.
1950 if Is_Concurrent_Type (T)
1951 and then not Comes_From_Source (T)
1952 and then Nkind (N) = N_Object_Declaration
1953 then
1954 Error_Msg_NE
1955 ("type of& has incomplete component",
1956 N, Defining_Identifier (N));
1957 else
1958 Error_Msg_NE
1959 ("premature usage of incomplete}",
1960 N, First_Subtype (T));
1961 end if;
1962 end if;
1963 end Check_Fully_Declared;
1965 -------------------------------------
1966 -- Check_Function_Writable_Actuals --
1967 -------------------------------------
1969 procedure Check_Function_Writable_Actuals (N : Node_Id) is
1970 Writable_Actuals_List : Elist_Id := No_Elist;
1971 Identifiers_List : Elist_Id := No_Elist;
1972 Error_Node : Node_Id := Empty;
1974 procedure Collect_Identifiers (N : Node_Id);
1975 -- In a single traversal of subtree N collect in Writable_Actuals_List
1976 -- all the actuals of functions with writable actuals, and in the list
1977 -- Identifiers_List collect all the identifiers that are not actuals of
1978 -- functions with writable actuals. If a writable actual is referenced
1979 -- twice as writable actual then Error_Node is set to reference its
1980 -- second occurrence, the error is reported, and the tree traversal
1981 -- is abandoned.
1983 function Get_Function_Id (Call : Node_Id) return Entity_Id;
1984 -- Return the entity associated with the function call
1986 procedure Preanalyze_Without_Errors (N : Node_Id);
1987 -- Preanalyze N without reporting errors. Very dubious, you can't just
1988 -- go analyzing things more than once???
1990 -------------------------
1991 -- Collect_Identifiers --
1992 -------------------------
1994 procedure Collect_Identifiers (N : Node_Id) is
1996 function Check_Node (N : Node_Id) return Traverse_Result;
1997 -- Process a single node during the tree traversal to collect the
1998 -- writable actuals of functions and all the identifiers which are
1999 -- not writable actuals of functions.
2001 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
2002 -- Returns True if List has a node whose Entity is Entity (N)
2004 -------------------------
2005 -- Check_Function_Call --
2006 -------------------------
2008 function Check_Node (N : Node_Id) return Traverse_Result is
2009 Is_Writable_Actual : Boolean := False;
2010 Id : Entity_Id;
2012 begin
2013 if Nkind (N) = N_Identifier then
2015 -- No analysis possible if the entity is not decorated
2017 if No (Entity (N)) then
2018 return Skip;
2020 -- Don't collect identifiers of packages, called functions, etc
2022 elsif Ekind_In (Entity (N), E_Package,
2023 E_Function,
2024 E_Procedure,
2025 E_Entry)
2026 then
2027 return Skip;
2029 -- Analyze if N is a writable actual of a function
2031 elsif Nkind (Parent (N)) = N_Function_Call then
2032 declare
2033 Call : constant Node_Id := Parent (N);
2034 Actual : Node_Id;
2035 Formal : Node_Id;
2037 begin
2038 Id := Get_Function_Id (Call);
2040 Formal := First_Formal (Id);
2041 Actual := First_Actual (Call);
2042 while Present (Actual) and then Present (Formal) loop
2043 if Actual = N then
2044 if Ekind_In (Formal, E_Out_Parameter,
2045 E_In_Out_Parameter)
2046 then
2047 Is_Writable_Actual := True;
2048 end if;
2050 exit;
2051 end if;
2053 Next_Formal (Formal);
2054 Next_Actual (Actual);
2055 end loop;
2056 end;
2057 end if;
2059 if Is_Writable_Actual then
2060 if Contains (Writable_Actuals_List, N) then
2061 Error_Msg_NE
2062 ("value may be affected by call to& "
2063 & "because order of evaluation is arbitrary", N, Id);
2064 Error_Node := N;
2065 return Abandon;
2066 end if;
2068 Append_New_Elmt (N, To => Writable_Actuals_List);
2070 else
2071 if Identifiers_List = No_Elist then
2072 Identifiers_List := New_Elmt_List;
2073 end if;
2075 Append_Unique_Elmt (N, Identifiers_List);
2076 end if;
2077 end if;
2079 return OK;
2080 end Check_Node;
2082 --------------
2083 -- Contains --
2084 --------------
2086 function Contains
2087 (List : Elist_Id;
2088 N : Node_Id) return Boolean
2090 pragma Assert (Nkind (N) in N_Has_Entity);
2092 Elmt : Elmt_Id;
2094 begin
2095 if List = No_Elist then
2096 return False;
2097 end if;
2099 Elmt := First_Elmt (List);
2100 while Present (Elmt) loop
2101 if Entity (Node (Elmt)) = Entity (N) then
2102 return True;
2103 else
2104 Next_Elmt (Elmt);
2105 end if;
2106 end loop;
2108 return False;
2109 end Contains;
2111 ------------------
2112 -- Do_Traversal --
2113 ------------------
2115 procedure Do_Traversal is new Traverse_Proc (Check_Node);
2116 -- The traversal procedure
2118 -- Start of processing for Collect_Identifiers
2120 begin
2121 if Present (Error_Node) then
2122 return;
2123 end if;
2125 if Nkind (N) in N_Subexpr and then Is_OK_Static_Expression (N) then
2126 return;
2127 end if;
2129 Do_Traversal (N);
2130 end Collect_Identifiers;
2132 ---------------------
2133 -- Get_Function_Id --
2134 ---------------------
2136 function Get_Function_Id (Call : Node_Id) return Entity_Id is
2137 Nam : constant Node_Id := Name (Call);
2138 Id : Entity_Id;
2140 begin
2141 if Nkind (Nam) = N_Explicit_Dereference then
2142 Id := Etype (Nam);
2143 pragma Assert (Ekind (Id) = E_Subprogram_Type);
2145 elsif Nkind (Nam) = N_Selected_Component then
2146 Id := Entity (Selector_Name (Nam));
2148 elsif Nkind (Nam) = N_Indexed_Component then
2149 Id := Entity (Selector_Name (Prefix (Nam)));
2151 else
2152 Id := Entity (Nam);
2153 end if;
2155 return Id;
2156 end Get_Function_Id;
2158 ---------------------------
2159 -- Preanalyze_Expression --
2160 ---------------------------
2162 procedure Preanalyze_Without_Errors (N : Node_Id) is
2163 Status : constant Boolean := Get_Ignore_Errors;
2164 begin
2165 Set_Ignore_Errors (True);
2166 Preanalyze (N);
2167 Set_Ignore_Errors (Status);
2168 end Preanalyze_Without_Errors;
2170 -- Start of processing for Check_Function_Writable_Actuals
2172 begin
2173 -- The check only applies to Ada 2012 code, and only to constructs that
2174 -- have multiple constituents whose order of evaluation is not specified
2175 -- by the language.
2177 if Ada_Version < Ada_2012
2178 or else (not (Nkind (N) in N_Op)
2179 and then not (Nkind (N) in N_Membership_Test)
2180 and then not Nkind_In (N, N_Range,
2181 N_Aggregate,
2182 N_Extension_Aggregate,
2183 N_Full_Type_Declaration,
2184 N_Function_Call,
2185 N_Procedure_Call_Statement,
2186 N_Entry_Call_Statement))
2187 or else (Nkind (N) = N_Full_Type_Declaration
2188 and then not Is_Record_Type (Defining_Identifier (N)))
2190 -- In addition, this check only applies to source code, not to code
2191 -- generated by constraint checks.
2193 or else not Comes_From_Source (N)
2194 then
2195 return;
2196 end if;
2198 -- If a construct C has two or more direct constituents that are names
2199 -- or expressions whose evaluation may occur in an arbitrary order, at
2200 -- least one of which contains a function call with an in out or out
2201 -- parameter, then the construct is legal only if: for each name N that
2202 -- is passed as a parameter of mode in out or out to some inner function
2203 -- call C2 (not including the construct C itself), there is no other
2204 -- name anywhere within a direct constituent of the construct C other
2205 -- than the one containing C2, that is known to refer to the same
2206 -- object (RM 6.4.1(6.17/3)).
2208 case Nkind (N) is
2209 when N_Range =>
2210 Collect_Identifiers (Low_Bound (N));
2211 Collect_Identifiers (High_Bound (N));
2213 when N_Op | N_Membership_Test =>
2214 declare
2215 Expr : Node_Id;
2217 begin
2218 Collect_Identifiers (Left_Opnd (N));
2220 if Present (Right_Opnd (N)) then
2221 Collect_Identifiers (Right_Opnd (N));
2222 end if;
2224 if Nkind_In (N, N_In, N_Not_In)
2225 and then Present (Alternatives (N))
2226 then
2227 Expr := First (Alternatives (N));
2228 while Present (Expr) loop
2229 Collect_Identifiers (Expr);
2231 Next (Expr);
2232 end loop;
2233 end if;
2234 end;
2236 when N_Full_Type_Declaration =>
2237 declare
2238 function Get_Record_Part (N : Node_Id) return Node_Id;
2239 -- Return the record part of this record type definition
2241 function Get_Record_Part (N : Node_Id) return Node_Id is
2242 Type_Def : constant Node_Id := Type_Definition (N);
2243 begin
2244 if Nkind (Type_Def) = N_Derived_Type_Definition then
2245 return Record_Extension_Part (Type_Def);
2246 else
2247 return Type_Def;
2248 end if;
2249 end Get_Record_Part;
2251 Comp : Node_Id;
2252 Def_Id : Entity_Id := Defining_Identifier (N);
2253 Rec : Node_Id := Get_Record_Part (N);
2255 begin
2256 -- No need to perform any analysis if the record has no
2257 -- components
2259 if No (Rec) or else No (Component_List (Rec)) then
2260 return;
2261 end if;
2263 -- Collect the identifiers starting from the deepest
2264 -- derivation. Done to report the error in the deepest
2265 -- derivation.
2267 loop
2268 if Present (Component_List (Rec)) then
2269 Comp := First (Component_Items (Component_List (Rec)));
2270 while Present (Comp) loop
2271 if Nkind (Comp) = N_Component_Declaration
2272 and then Present (Expression (Comp))
2273 then
2274 Collect_Identifiers (Expression (Comp));
2275 end if;
2277 Next (Comp);
2278 end loop;
2279 end if;
2281 exit when No (Underlying_Type (Etype (Def_Id)))
2282 or else Base_Type (Underlying_Type (Etype (Def_Id)))
2283 = Def_Id;
2285 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
2286 Rec := Get_Record_Part (Parent (Def_Id));
2287 end loop;
2288 end;
2290 when N_Subprogram_Call |
2291 N_Entry_Call_Statement =>
2292 declare
2293 Id : constant Entity_Id := Get_Function_Id (N);
2294 Formal : Node_Id;
2295 Actual : Node_Id;
2297 begin
2298 Formal := First_Formal (Id);
2299 Actual := First_Actual (N);
2300 while Present (Actual) and then Present (Formal) loop
2301 if Ekind_In (Formal, E_Out_Parameter,
2302 E_In_Out_Parameter)
2303 then
2304 Collect_Identifiers (Actual);
2305 end if;
2307 Next_Formal (Formal);
2308 Next_Actual (Actual);
2309 end loop;
2310 end;
2312 when N_Aggregate |
2313 N_Extension_Aggregate =>
2314 declare
2315 Assoc : Node_Id;
2316 Choice : Node_Id;
2317 Comp_Expr : Node_Id;
2319 begin
2320 -- Handle the N_Others_Choice of array aggregates with static
2321 -- bounds. There is no need to perform this analysis in
2322 -- aggregates without static bounds since we cannot evaluate
2323 -- if the N_Others_Choice covers several elements. There is
2324 -- no need to handle the N_Others choice of record aggregates
2325 -- since at this stage it has been already expanded by
2326 -- Resolve_Record_Aggregate.
2328 if Is_Array_Type (Etype (N))
2329 and then Nkind (N) = N_Aggregate
2330 and then Present (Aggregate_Bounds (N))
2331 and then Compile_Time_Known_Bounds (Etype (N))
2332 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
2334 Expr_Value (Low_Bound (Aggregate_Bounds (N)))
2335 then
2336 declare
2337 Count_Components : Uint := Uint_0;
2338 Num_Components : Uint;
2339 Others_Assoc : Node_Id;
2340 Others_Choice : Node_Id := Empty;
2341 Others_Box_Present : Boolean := False;
2343 begin
2344 -- Count positional associations
2346 if Present (Expressions (N)) then
2347 Comp_Expr := First (Expressions (N));
2348 while Present (Comp_Expr) loop
2349 Count_Components := Count_Components + 1;
2350 Next (Comp_Expr);
2351 end loop;
2352 end if;
2354 -- Count the rest of elements and locate the N_Others
2355 -- choice (if any)
2357 Assoc := First (Component_Associations (N));
2358 while Present (Assoc) loop
2359 Choice := First (Choices (Assoc));
2360 while Present (Choice) loop
2361 if Nkind (Choice) = N_Others_Choice then
2362 Others_Assoc := Assoc;
2363 Others_Choice := Choice;
2364 Others_Box_Present := Box_Present (Assoc);
2366 -- Count several components
2368 elsif Nkind_In (Choice, N_Range,
2369 N_Subtype_Indication)
2370 or else (Is_Entity_Name (Choice)
2371 and then Is_Type (Entity (Choice)))
2372 then
2373 declare
2374 L, H : Node_Id;
2375 begin
2376 Get_Index_Bounds (Choice, L, H);
2377 pragma Assert
2378 (Compile_Time_Known_Value (L)
2379 and then Compile_Time_Known_Value (H));
2380 Count_Components :=
2381 Count_Components
2382 + Expr_Value (H) - Expr_Value (L) + 1;
2383 end;
2385 -- Count single component. No other case available
2386 -- since we are handling an aggregate with static
2387 -- bounds.
2389 else
2390 pragma Assert (Is_OK_Static_Expression (Choice)
2391 or else Nkind (Choice) = N_Identifier
2392 or else Nkind (Choice) = N_Integer_Literal);
2394 Count_Components := Count_Components + 1;
2395 end if;
2397 Next (Choice);
2398 end loop;
2400 Next (Assoc);
2401 end loop;
2403 Num_Components :=
2404 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2405 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2407 pragma Assert (Count_Components <= Num_Components);
2409 -- Handle the N_Others choice if it covers several
2410 -- components
2412 if Present (Others_Choice)
2413 and then (Num_Components - Count_Components) > 1
2414 then
2415 if not Others_Box_Present then
2417 -- At this stage, if expansion is active, the
2418 -- expression of the others choice has not been
2419 -- analyzed. Hence we generate a duplicate and
2420 -- we analyze it silently to have available the
2421 -- minimum decoration required to collect the
2422 -- identifiers.
2424 if not Expander_Active then
2425 Comp_Expr := Expression (Others_Assoc);
2426 else
2427 Comp_Expr :=
2428 New_Copy_Tree (Expression (Others_Assoc));
2429 Preanalyze_Without_Errors (Comp_Expr);
2430 end if;
2432 Collect_Identifiers (Comp_Expr);
2434 if Writable_Actuals_List /= No_Elist then
2436 -- As suggested by Robert, at current stage we
2437 -- report occurrences of this case as warnings.
2439 Error_Msg_N
2440 ("writable function parameter may affect "
2441 & "value in other component because order "
2442 & "of evaluation is unspecified??",
2443 Node (First_Elmt (Writable_Actuals_List)));
2444 end if;
2445 end if;
2446 end if;
2447 end;
2448 end if;
2450 -- Handle ancestor part of extension aggregates
2452 if Nkind (N) = N_Extension_Aggregate then
2453 Collect_Identifiers (Ancestor_Part (N));
2454 end if;
2456 -- Handle positional associations
2458 if Present (Expressions (N)) then
2459 Comp_Expr := First (Expressions (N));
2460 while Present (Comp_Expr) loop
2461 if not Is_OK_Static_Expression (Comp_Expr) then
2462 Collect_Identifiers (Comp_Expr);
2463 end if;
2465 Next (Comp_Expr);
2466 end loop;
2467 end if;
2469 -- Handle discrete associations
2471 if Present (Component_Associations (N)) then
2472 Assoc := First (Component_Associations (N));
2473 while Present (Assoc) loop
2475 if not Box_Present (Assoc) then
2476 Choice := First (Choices (Assoc));
2477 while Present (Choice) loop
2479 -- For now we skip discriminants since it requires
2480 -- performing the analysis in two phases: first one
2481 -- analyzing discriminants and second one analyzing
2482 -- the rest of components since discriminants are
2483 -- evaluated prior to components: too much extra
2484 -- work to detect a corner case???
2486 if Nkind (Choice) in N_Has_Entity
2487 and then Present (Entity (Choice))
2488 and then Ekind (Entity (Choice)) = E_Discriminant
2489 then
2490 null;
2492 elsif Box_Present (Assoc) then
2493 null;
2495 else
2496 if not Analyzed (Expression (Assoc)) then
2497 Comp_Expr :=
2498 New_Copy_Tree (Expression (Assoc));
2499 Set_Parent (Comp_Expr, Parent (N));
2500 Preanalyze_Without_Errors (Comp_Expr);
2501 else
2502 Comp_Expr := Expression (Assoc);
2503 end if;
2505 Collect_Identifiers (Comp_Expr);
2506 end if;
2508 Next (Choice);
2509 end loop;
2510 end if;
2512 Next (Assoc);
2513 end loop;
2514 end if;
2515 end;
2517 when others =>
2518 return;
2519 end case;
2521 -- No further action needed if we already reported an error
2523 if Present (Error_Node) then
2524 return;
2525 end if;
2527 -- Check if some writable argument of a function is referenced
2529 if Writable_Actuals_List /= No_Elist
2530 and then Identifiers_List /= No_Elist
2531 then
2532 declare
2533 Elmt_1 : Elmt_Id;
2534 Elmt_2 : Elmt_Id;
2536 begin
2537 Elmt_1 := First_Elmt (Writable_Actuals_List);
2538 while Present (Elmt_1) loop
2539 Elmt_2 := First_Elmt (Identifiers_List);
2540 while Present (Elmt_2) loop
2541 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2542 case Nkind (Parent (Node (Elmt_2))) is
2543 when N_Aggregate |
2544 N_Component_Association |
2545 N_Component_Declaration =>
2546 Error_Msg_N
2547 ("value may be affected by call in other "
2548 & "component because they are evaluated "
2549 & "in unspecified order",
2550 Node (Elmt_2));
2552 when N_In | N_Not_In =>
2553 Error_Msg_N
2554 ("value may be affected by call in other "
2555 & "alternative because they are evaluated "
2556 & "in unspecified order",
2557 Node (Elmt_2));
2559 when others =>
2560 Error_Msg_N
2561 ("value of actual may be affected by call in "
2562 & "other actual because they are evaluated "
2563 & "in unspecified order",
2564 Node (Elmt_2));
2565 end case;
2566 end if;
2568 Next_Elmt (Elmt_2);
2569 end loop;
2571 Next_Elmt (Elmt_1);
2572 end loop;
2573 end;
2574 end if;
2575 end Check_Function_Writable_Actuals;
2577 --------------------------------
2578 -- Check_Implicit_Dereference --
2579 --------------------------------
2581 procedure Check_Implicit_Dereference (Nam : Node_Id; Typ : Entity_Id) is
2582 Disc : Entity_Id;
2583 Desig : Entity_Id;
2585 begin
2586 if Ada_Version < Ada_2012
2587 or else not Has_Implicit_Dereference (Base_Type (Typ))
2588 then
2589 return;
2591 elsif not Comes_From_Source (Nam) then
2592 return;
2594 elsif Is_Entity_Name (Nam) and then Is_Type (Entity (Nam)) then
2595 null;
2597 else
2598 Disc := First_Discriminant (Typ);
2599 while Present (Disc) loop
2600 if Has_Implicit_Dereference (Disc) then
2601 Desig := Designated_Type (Etype (Disc));
2602 Add_One_Interp (Nam, Disc, Desig);
2603 exit;
2604 end if;
2606 Next_Discriminant (Disc);
2607 end loop;
2608 end if;
2609 end Check_Implicit_Dereference;
2611 ----------------------------------
2612 -- Check_Internal_Protected_Use --
2613 ----------------------------------
2615 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2616 S : Entity_Id;
2617 Prot : Entity_Id;
2619 begin
2620 S := Current_Scope;
2621 while Present (S) loop
2622 if S = Standard_Standard then
2623 return;
2625 elsif Ekind (S) = E_Function
2626 and then Ekind (Scope (S)) = E_Protected_Type
2627 then
2628 Prot := Scope (S);
2629 exit;
2630 end if;
2632 S := Scope (S);
2633 end loop;
2635 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2637 -- An indirect function call (e.g. a callback within a protected
2638 -- function body) is not statically illegal. If the access type is
2639 -- anonymous and is the type of an access parameter, the scope of Nam
2640 -- will be the protected type, but it is not a protected operation.
2642 if Ekind (Nam) = E_Subprogram_Type
2643 and then
2644 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2645 then
2646 null;
2648 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2649 Error_Msg_N
2650 ("within protected function cannot use protected "
2651 & "procedure in renaming or as generic actual", N);
2653 elsif Nkind (N) = N_Attribute_Reference then
2654 Error_Msg_N
2655 ("within protected function cannot take access of "
2656 & " protected procedure", N);
2658 else
2659 Error_Msg_N
2660 ("within protected function, protected object is constant", N);
2661 Error_Msg_N
2662 ("\cannot call operation that may modify it", N);
2663 end if;
2664 end if;
2665 end Check_Internal_Protected_Use;
2667 ---------------------------------------
2668 -- Check_Later_Vs_Basic_Declarations --
2669 ---------------------------------------
2671 procedure Check_Later_Vs_Basic_Declarations
2672 (Decls : List_Id;
2673 During_Parsing : Boolean)
2675 Body_Sloc : Source_Ptr;
2676 Decl : Node_Id;
2678 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2679 -- Return whether Decl is considered as a declarative item.
2680 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2681 -- When During_Parsing is False, the semantics of SPARK is followed.
2683 -------------------------------
2684 -- Is_Later_Declarative_Item --
2685 -------------------------------
2687 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2688 begin
2689 if Nkind (Decl) in N_Later_Decl_Item then
2690 return True;
2692 elsif Nkind (Decl) = N_Pragma then
2693 return True;
2695 elsif During_Parsing then
2696 return False;
2698 -- In SPARK, a package declaration is not considered as a later
2699 -- declarative item.
2701 elsif Nkind (Decl) = N_Package_Declaration then
2702 return False;
2704 -- In SPARK, a renaming is considered as a later declarative item
2706 elsif Nkind (Decl) in N_Renaming_Declaration then
2707 return True;
2709 else
2710 return False;
2711 end if;
2712 end Is_Later_Declarative_Item;
2714 -- Start of Check_Later_Vs_Basic_Declarations
2716 begin
2717 Decl := First (Decls);
2719 -- Loop through sequence of basic declarative items
2721 Outer : while Present (Decl) loop
2722 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2723 and then Nkind (Decl) not in N_Body_Stub
2724 then
2725 Next (Decl);
2727 -- Once a body is encountered, we only allow later declarative
2728 -- items. The inner loop checks the rest of the list.
2730 else
2731 Body_Sloc := Sloc (Decl);
2733 Inner : while Present (Decl) loop
2734 if not Is_Later_Declarative_Item (Decl) then
2735 if During_Parsing then
2736 if Ada_Version = Ada_83 then
2737 Error_Msg_Sloc := Body_Sloc;
2738 Error_Msg_N
2739 ("(Ada 83) decl cannot appear after body#", Decl);
2740 end if;
2741 else
2742 Error_Msg_Sloc := Body_Sloc;
2743 Check_SPARK_05_Restriction
2744 ("decl cannot appear after body#", Decl);
2745 end if;
2746 end if;
2748 Next (Decl);
2749 end loop Inner;
2750 end if;
2751 end loop Outer;
2752 end Check_Later_Vs_Basic_Declarations;
2754 -------------------------
2755 -- Check_Nested_Access --
2756 -------------------------
2758 procedure Check_Nested_Access (Ent : Entity_Id) is
2759 Scop : constant Entity_Id := Current_Scope;
2760 Current_Subp : Entity_Id;
2761 Enclosing : Entity_Id;
2763 begin
2764 -- Currently only enabled for VM back-ends for efficiency, should we
2765 -- enable it more systematically ???
2767 -- Check for Is_Imported needs commenting below ???
2769 if VM_Target /= No_VM
2770 and then Ekind_In (Ent, E_Variable, E_Constant, E_Loop_Parameter)
2771 and then Scope (Ent) /= Empty
2772 and then not Is_Library_Level_Entity (Ent)
2773 and then not Is_Imported (Ent)
2774 then
2775 if Is_Subprogram (Scop)
2776 or else Is_Generic_Subprogram (Scop)
2777 or else Is_Entry (Scop)
2778 then
2779 Current_Subp := Scop;
2780 else
2781 Current_Subp := Current_Subprogram;
2782 end if;
2784 Enclosing := Enclosing_Subprogram (Ent);
2786 if Enclosing /= Empty and then Enclosing /= Current_Subp then
2787 Set_Has_Up_Level_Access (Ent, True);
2788 end if;
2789 end if;
2790 end Check_Nested_Access;
2792 ---------------------------
2793 -- Check_No_Hidden_State --
2794 ---------------------------
2796 procedure Check_No_Hidden_State (Id : Entity_Id) is
2797 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2798 -- Determine whether the entity of a package denoted by Pkg has a null
2799 -- abstract state.
2801 -----------------------------
2802 -- Has_Null_Abstract_State --
2803 -----------------------------
2805 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2806 States : constant Elist_Id := Abstract_States (Pkg);
2808 begin
2809 -- Check first available state of related package. A null abstract
2810 -- state always appears as the sole element of the state list.
2812 return
2813 Present (States)
2814 and then Is_Null_State (Node (First_Elmt (States)));
2815 end Has_Null_Abstract_State;
2817 -- Local variables
2819 Context : Entity_Id := Empty;
2820 Not_Visible : Boolean := False;
2821 Scop : Entity_Id;
2823 -- Start of processing for Check_No_Hidden_State
2825 begin
2826 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2828 -- Find the proper context where the object or state appears
2830 Scop := Scope (Id);
2831 while Present (Scop) loop
2832 Context := Scop;
2834 -- Keep track of the context's visibility
2836 Not_Visible := Not_Visible or else In_Private_Part (Context);
2838 -- Prevent the search from going too far
2840 if Context = Standard_Standard then
2841 return;
2843 -- Objects and states that appear immediately within a subprogram or
2844 -- inside a construct nested within a subprogram do not introduce a
2845 -- hidden state. They behave as local variable declarations.
2847 elsif Is_Subprogram (Context) then
2848 return;
2850 -- When examining a package body, use the entity of the spec as it
2851 -- carries the abstract state declarations.
2853 elsif Ekind (Context) = E_Package_Body then
2854 Context := Spec_Entity (Context);
2855 end if;
2857 -- Stop the traversal when a package subject to a null abstract state
2858 -- has been found.
2860 if Ekind_In (Context, E_Generic_Package, E_Package)
2861 and then Has_Null_Abstract_State (Context)
2862 then
2863 exit;
2864 end if;
2866 Scop := Scope (Scop);
2867 end loop;
2869 -- At this point we know that there is at least one package with a null
2870 -- abstract state in visibility. Emit an error message unconditionally
2871 -- if the entity being processed is a state because the placement of the
2872 -- related package is irrelevant. This is not the case for objects as
2873 -- the intermediate context matters.
2875 if Present (Context)
2876 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
2877 then
2878 Error_Msg_N ("cannot introduce hidden state &", Id);
2879 Error_Msg_NE ("\package & has null abstract state", Id, Context);
2880 end if;
2881 end Check_No_Hidden_State;
2883 ------------------------------------------
2884 -- Check_Potentially_Blocking_Operation --
2885 ------------------------------------------
2887 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
2888 S : Entity_Id;
2890 begin
2891 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2892 -- When pragma Detect_Blocking is active, the run time will raise
2893 -- Program_Error. Here we only issue a warning, since we generally
2894 -- support the use of potentially blocking operations in the absence
2895 -- of the pragma.
2897 -- Indirect blocking through a subprogram call cannot be diagnosed
2898 -- statically without interprocedural analysis, so we do not attempt
2899 -- to do it here.
2901 S := Scope (Current_Scope);
2902 while Present (S) and then S /= Standard_Standard loop
2903 if Is_Protected_Type (S) then
2904 Error_Msg_N
2905 ("potentially blocking operation in protected operation??", N);
2906 return;
2907 end if;
2909 S := Scope (S);
2910 end loop;
2911 end Check_Potentially_Blocking_Operation;
2913 ---------------------------------
2914 -- Check_Result_And_Post_State --
2915 ---------------------------------
2917 procedure Check_Result_And_Post_State
2918 (Prag : Node_Id;
2919 Result_Seen : in out Boolean)
2921 procedure Check_Expression (Expr : Node_Id);
2922 -- Perform the 'Result and post-state checks on a given expression
2924 function Is_Function_Result (N : Node_Id) return Traverse_Result;
2925 -- Attempt to find attribute 'Result in a subtree denoted by N
2927 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
2928 -- Determine whether source node N denotes "True" or "False"
2930 function Mentions_Post_State (N : Node_Id) return Boolean;
2931 -- Determine whether a subtree denoted by N mentions any construct that
2932 -- denotes a post-state.
2934 procedure Check_Function_Result is
2935 new Traverse_Proc (Is_Function_Result);
2937 ----------------------
2938 -- Check_Expression --
2939 ----------------------
2941 procedure Check_Expression (Expr : Node_Id) is
2942 begin
2943 if not Is_Trivial_Boolean (Expr) then
2944 Check_Function_Result (Expr);
2946 if not Mentions_Post_State (Expr) then
2947 if Pragma_Name (Prag) = Name_Contract_Cases then
2948 Error_Msg_N
2949 ("contract case refers only to pre-state?T?", Expr);
2951 elsif Pragma_Name (Prag) = Name_Refined_Post then
2952 Error_Msg_N
2953 ("refined postcondition refers only to pre-state?T?",
2954 Prag);
2956 else
2957 Error_Msg_N
2958 ("postcondition refers only to pre-state?T?", Prag);
2959 end if;
2960 end if;
2961 end if;
2962 end Check_Expression;
2964 ------------------------
2965 -- Is_Function_Result --
2966 ------------------------
2968 function Is_Function_Result (N : Node_Id) return Traverse_Result is
2969 begin
2970 if Is_Attribute_Result (N) then
2971 Result_Seen := True;
2972 return Abandon;
2974 -- Continue the traversal
2976 else
2977 return OK;
2978 end if;
2979 end Is_Function_Result;
2981 ------------------------
2982 -- Is_Trivial_Boolean --
2983 ------------------------
2985 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
2986 begin
2987 return
2988 Comes_From_Source (N)
2989 and then Is_Entity_Name (N)
2990 and then (Entity (N) = Standard_True
2991 or else Entity (N) = Standard_False);
2992 end Is_Trivial_Boolean;
2994 -------------------------
2995 -- Mentions_Post_State --
2996 -------------------------
2998 function Mentions_Post_State (N : Node_Id) return Boolean is
2999 Post_State_Seen : Boolean := False;
3001 function Is_Post_State (N : Node_Id) return Traverse_Result;
3002 -- Attempt to find a construct that denotes a post-state. If this is
3003 -- the case, set flag Post_State_Seen.
3005 -------------------
3006 -- Is_Post_State --
3007 -------------------
3009 function Is_Post_State (N : Node_Id) return Traverse_Result is
3010 Ent : Entity_Id;
3012 begin
3013 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
3014 Post_State_Seen := True;
3015 return Abandon;
3017 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
3018 Ent := Entity (N);
3020 -- The entity may be modifiable through an implicit dereference
3022 if No (Ent)
3023 or else Ekind (Ent) in Assignable_Kind
3024 or else (Is_Access_Type (Etype (Ent))
3025 and then Nkind (Parent (N)) = N_Selected_Component)
3026 then
3027 Post_State_Seen := True;
3028 return Abandon;
3029 end if;
3031 elsif Nkind (N) = N_Attribute_Reference then
3032 if Attribute_Name (N) = Name_Old then
3033 return Skip;
3035 elsif Attribute_Name (N) = Name_Result then
3036 Post_State_Seen := True;
3037 return Abandon;
3038 end if;
3039 end if;
3041 return OK;
3042 end Is_Post_State;
3044 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
3046 -- Start of processing for Mentions_Post_State
3048 begin
3049 Find_Post_State (N);
3051 return Post_State_Seen;
3052 end Mentions_Post_State;
3054 -- Local variables
3056 Expr : constant Node_Id :=
3057 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
3058 Nam : constant Name_Id := Pragma_Name (Prag);
3059 CCase : Node_Id;
3061 -- Start of processing for Check_Result_And_Post_State
3063 begin
3064 -- Examine all consequences
3066 if Nam = Name_Contract_Cases then
3067 CCase := First (Component_Associations (Expr));
3068 while Present (CCase) loop
3069 Check_Expression (Expression (CCase));
3071 Next (CCase);
3072 end loop;
3074 -- Examine the expression of a postcondition
3076 else pragma Assert (Nam_In (Nam, Name_Postcondition, Name_Refined_Post));
3077 Check_Expression (Expr);
3078 end if;
3079 end Check_Result_And_Post_State;
3081 ---------------------------------
3082 -- Check_SPARK_Mode_In_Generic --
3083 ---------------------------------
3085 procedure Check_SPARK_Mode_In_Generic (N : Node_Id) is
3086 Aspect : Node_Id;
3088 begin
3089 -- Try to find aspect SPARK_Mode and flag it as illegal
3091 if Has_Aspects (N) then
3092 Aspect := First (Aspect_Specifications (N));
3093 while Present (Aspect) loop
3094 if Get_Aspect_Id (Aspect) = Aspect_SPARK_Mode then
3095 Error_Msg_Name_1 := Name_SPARK_Mode;
3096 Error_Msg_N
3097 ("incorrect placement of aspect % on a generic", Aspect);
3098 exit;
3099 end if;
3101 Next (Aspect);
3102 end loop;
3103 end if;
3104 end Check_SPARK_Mode_In_Generic;
3106 ------------------------------
3107 -- Check_Unprotected_Access --
3108 ------------------------------
3110 procedure Check_Unprotected_Access
3111 (Context : Node_Id;
3112 Expr : Node_Id)
3114 Cont_Encl_Typ : Entity_Id;
3115 Pref_Encl_Typ : Entity_Id;
3117 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
3118 -- Check whether Obj is a private component of a protected object.
3119 -- Return the protected type where the component resides, Empty
3120 -- otherwise.
3122 function Is_Public_Operation return Boolean;
3123 -- Verify that the enclosing operation is callable from outside the
3124 -- protected object, to minimize false positives.
3126 ------------------------------
3127 -- Enclosing_Protected_Type --
3128 ------------------------------
3130 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
3131 begin
3132 if Is_Entity_Name (Obj) then
3133 declare
3134 Ent : Entity_Id := Entity (Obj);
3136 begin
3137 -- The object can be a renaming of a private component, use
3138 -- the original record component.
3140 if Is_Prival (Ent) then
3141 Ent := Prival_Link (Ent);
3142 end if;
3144 if Is_Protected_Type (Scope (Ent)) then
3145 return Scope (Ent);
3146 end if;
3147 end;
3148 end if;
3150 -- For indexed and selected components, recursively check the prefix
3152 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
3153 return Enclosing_Protected_Type (Prefix (Obj));
3155 -- The object does not denote a protected component
3157 else
3158 return Empty;
3159 end if;
3160 end Enclosing_Protected_Type;
3162 -------------------------
3163 -- Is_Public_Operation --
3164 -------------------------
3166 function Is_Public_Operation return Boolean is
3167 S : Entity_Id;
3168 E : Entity_Id;
3170 begin
3171 S := Current_Scope;
3172 while Present (S) and then S /= Pref_Encl_Typ loop
3173 if Scope (S) = Pref_Encl_Typ then
3174 E := First_Entity (Pref_Encl_Typ);
3175 while Present (E)
3176 and then E /= First_Private_Entity (Pref_Encl_Typ)
3177 loop
3178 if E = S then
3179 return True;
3180 end if;
3182 Next_Entity (E);
3183 end loop;
3184 end if;
3186 S := Scope (S);
3187 end loop;
3189 return False;
3190 end Is_Public_Operation;
3192 -- Start of processing for Check_Unprotected_Access
3194 begin
3195 if Nkind (Expr) = N_Attribute_Reference
3196 and then Attribute_Name (Expr) = Name_Unchecked_Access
3197 then
3198 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
3199 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
3201 -- Check whether we are trying to export a protected component to a
3202 -- context with an equal or lower access level.
3204 if Present (Pref_Encl_Typ)
3205 and then No (Cont_Encl_Typ)
3206 and then Is_Public_Operation
3207 and then Scope_Depth (Pref_Encl_Typ) >=
3208 Object_Access_Level (Context)
3209 then
3210 Error_Msg_N
3211 ("??possible unprotected access to protected data", Expr);
3212 end if;
3213 end if;
3214 end Check_Unprotected_Access;
3216 ------------------------
3217 -- Collect_Interfaces --
3218 ------------------------
3220 procedure Collect_Interfaces
3221 (T : Entity_Id;
3222 Ifaces_List : out Elist_Id;
3223 Exclude_Parents : Boolean := False;
3224 Use_Full_View : Boolean := True)
3226 procedure Collect (Typ : Entity_Id);
3227 -- Subsidiary subprogram used to traverse the whole list
3228 -- of directly and indirectly implemented interfaces
3230 -------------
3231 -- Collect --
3232 -------------
3234 procedure Collect (Typ : Entity_Id) is
3235 Ancestor : Entity_Id;
3236 Full_T : Entity_Id;
3237 Id : Node_Id;
3238 Iface : Entity_Id;
3240 begin
3241 Full_T := Typ;
3243 -- Handle private types
3245 if Use_Full_View
3246 and then Is_Private_Type (Typ)
3247 and then Present (Full_View (Typ))
3248 then
3249 Full_T := Full_View (Typ);
3250 end if;
3252 -- Include the ancestor if we are generating the whole list of
3253 -- abstract interfaces.
3255 if Etype (Full_T) /= Typ
3257 -- Protect the frontend against wrong sources. For example:
3259 -- package P is
3260 -- type A is tagged null record;
3261 -- type B is new A with private;
3262 -- type C is new A with private;
3263 -- private
3264 -- type B is new C with null record;
3265 -- type C is new B with null record;
3266 -- end P;
3268 and then Etype (Full_T) /= T
3269 then
3270 Ancestor := Etype (Full_T);
3271 Collect (Ancestor);
3273 if Is_Interface (Ancestor) and then not Exclude_Parents then
3274 Append_Unique_Elmt (Ancestor, Ifaces_List);
3275 end if;
3276 end if;
3278 -- Traverse the graph of ancestor interfaces
3280 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
3281 Id := First (Abstract_Interface_List (Full_T));
3282 while Present (Id) loop
3283 Iface := Etype (Id);
3285 -- Protect against wrong uses. For example:
3286 -- type I is interface;
3287 -- type O is tagged null record;
3288 -- type Wrong is new I and O with null record; -- ERROR
3290 if Is_Interface (Iface) then
3291 if Exclude_Parents
3292 and then Etype (T) /= T
3293 and then Interface_Present_In_Ancestor (Etype (T), Iface)
3294 then
3295 null;
3296 else
3297 Collect (Iface);
3298 Append_Unique_Elmt (Iface, Ifaces_List);
3299 end if;
3300 end if;
3302 Next (Id);
3303 end loop;
3304 end if;
3305 end Collect;
3307 -- Start of processing for Collect_Interfaces
3309 begin
3310 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
3311 Ifaces_List := New_Elmt_List;
3312 Collect (T);
3313 end Collect_Interfaces;
3315 ----------------------------------
3316 -- Collect_Interface_Components --
3317 ----------------------------------
3319 procedure Collect_Interface_Components
3320 (Tagged_Type : Entity_Id;
3321 Components_List : out Elist_Id)
3323 procedure Collect (Typ : Entity_Id);
3324 -- Subsidiary subprogram used to climb to the parents
3326 -------------
3327 -- Collect --
3328 -------------
3330 procedure Collect (Typ : Entity_Id) is
3331 Tag_Comp : Entity_Id;
3332 Parent_Typ : Entity_Id;
3334 begin
3335 -- Handle private types
3337 if Present (Full_View (Etype (Typ))) then
3338 Parent_Typ := Full_View (Etype (Typ));
3339 else
3340 Parent_Typ := Etype (Typ);
3341 end if;
3343 if Parent_Typ /= Typ
3345 -- Protect the frontend against wrong sources. For example:
3347 -- package P is
3348 -- type A is tagged null record;
3349 -- type B is new A with private;
3350 -- type C is new A with private;
3351 -- private
3352 -- type B is new C with null record;
3353 -- type C is new B with null record;
3354 -- end P;
3356 and then Parent_Typ /= Tagged_Type
3357 then
3358 Collect (Parent_Typ);
3359 end if;
3361 -- Collect the components containing tags of secondary dispatch
3362 -- tables.
3364 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
3365 while Present (Tag_Comp) loop
3366 pragma Assert (Present (Related_Type (Tag_Comp)));
3367 Append_Elmt (Tag_Comp, Components_List);
3369 Tag_Comp := Next_Tag_Component (Tag_Comp);
3370 end loop;
3371 end Collect;
3373 -- Start of processing for Collect_Interface_Components
3375 begin
3376 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
3377 and then Is_Tagged_Type (Tagged_Type));
3379 Components_List := New_Elmt_List;
3380 Collect (Tagged_Type);
3381 end Collect_Interface_Components;
3383 -----------------------------
3384 -- Collect_Interfaces_Info --
3385 -----------------------------
3387 procedure Collect_Interfaces_Info
3388 (T : Entity_Id;
3389 Ifaces_List : out Elist_Id;
3390 Components_List : out Elist_Id;
3391 Tags_List : out Elist_Id)
3393 Comps_List : Elist_Id;
3394 Comp_Elmt : Elmt_Id;
3395 Comp_Iface : Entity_Id;
3396 Iface_Elmt : Elmt_Id;
3397 Iface : Entity_Id;
3399 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3400 -- Search for the secondary tag associated with the interface type
3401 -- Iface that is implemented by T.
3403 ----------------
3404 -- Search_Tag --
3405 ----------------
3407 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3408 ADT : Elmt_Id;
3409 begin
3410 if not Is_CPP_Class (T) then
3411 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3412 else
3413 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3414 end if;
3416 while Present (ADT)
3417 and then Is_Tag (Node (ADT))
3418 and then Related_Type (Node (ADT)) /= Iface
3419 loop
3420 -- Skip secondary dispatch table referencing thunks to user
3421 -- defined primitives covered by this interface.
3423 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3424 Next_Elmt (ADT);
3426 -- Skip secondary dispatch tables of Ada types
3428 if not Is_CPP_Class (T) then
3430 -- Skip secondary dispatch table referencing thunks to
3431 -- predefined primitives.
3433 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3434 Next_Elmt (ADT);
3436 -- Skip secondary dispatch table referencing user-defined
3437 -- primitives covered by this interface.
3439 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3440 Next_Elmt (ADT);
3442 -- Skip secondary dispatch table referencing predefined
3443 -- primitives.
3445 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3446 Next_Elmt (ADT);
3447 end if;
3448 end loop;
3450 pragma Assert (Is_Tag (Node (ADT)));
3451 return Node (ADT);
3452 end Search_Tag;
3454 -- Start of processing for Collect_Interfaces_Info
3456 begin
3457 Collect_Interfaces (T, Ifaces_List);
3458 Collect_Interface_Components (T, Comps_List);
3460 -- Search for the record component and tag associated with each
3461 -- interface type of T.
3463 Components_List := New_Elmt_List;
3464 Tags_List := New_Elmt_List;
3466 Iface_Elmt := First_Elmt (Ifaces_List);
3467 while Present (Iface_Elmt) loop
3468 Iface := Node (Iface_Elmt);
3470 -- Associate the primary tag component and the primary dispatch table
3471 -- with all the interfaces that are parents of T
3473 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3474 Append_Elmt (First_Tag_Component (T), Components_List);
3475 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3477 -- Otherwise search for the tag component and secondary dispatch
3478 -- table of Iface
3480 else
3481 Comp_Elmt := First_Elmt (Comps_List);
3482 while Present (Comp_Elmt) loop
3483 Comp_Iface := Related_Type (Node (Comp_Elmt));
3485 if Comp_Iface = Iface
3486 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3487 then
3488 Append_Elmt (Node (Comp_Elmt), Components_List);
3489 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3490 exit;
3491 end if;
3493 Next_Elmt (Comp_Elmt);
3494 end loop;
3495 pragma Assert (Present (Comp_Elmt));
3496 end if;
3498 Next_Elmt (Iface_Elmt);
3499 end loop;
3500 end Collect_Interfaces_Info;
3502 ---------------------
3503 -- Collect_Parents --
3504 ---------------------
3506 procedure Collect_Parents
3507 (T : Entity_Id;
3508 List : out Elist_Id;
3509 Use_Full_View : Boolean := True)
3511 Current_Typ : Entity_Id := T;
3512 Parent_Typ : Entity_Id;
3514 begin
3515 List := New_Elmt_List;
3517 -- No action if the if the type has no parents
3519 if T = Etype (T) then
3520 return;
3521 end if;
3523 loop
3524 Parent_Typ := Etype (Current_Typ);
3526 if Is_Private_Type (Parent_Typ)
3527 and then Present (Full_View (Parent_Typ))
3528 and then Use_Full_View
3529 then
3530 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3531 end if;
3533 Append_Elmt (Parent_Typ, List);
3535 exit when Parent_Typ = Current_Typ;
3536 Current_Typ := Parent_Typ;
3537 end loop;
3538 end Collect_Parents;
3540 ----------------------------------
3541 -- Collect_Primitive_Operations --
3542 ----------------------------------
3544 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
3545 B_Type : constant Entity_Id := Base_Type (T);
3546 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
3547 B_Scope : Entity_Id := Scope (B_Type);
3548 Op_List : Elist_Id;
3549 Formal : Entity_Id;
3550 Is_Prim : Boolean;
3551 Is_Type_In_Pkg : Boolean;
3552 Formal_Derived : Boolean := False;
3553 Id : Entity_Id;
3555 function Match (E : Entity_Id) return Boolean;
3556 -- True if E's base type is B_Type, or E is of an anonymous access type
3557 -- and the base type of its designated type is B_Type.
3559 -----------
3560 -- Match --
3561 -----------
3563 function Match (E : Entity_Id) return Boolean is
3564 Etyp : Entity_Id := Etype (E);
3566 begin
3567 if Ekind (Etyp) = E_Anonymous_Access_Type then
3568 Etyp := Designated_Type (Etyp);
3569 end if;
3571 -- In Ada 2012 a primitive operation may have a formal of an
3572 -- incomplete view of the parent type.
3574 return Base_Type (Etyp) = B_Type
3575 or else
3576 (Ada_Version >= Ada_2012
3577 and then Ekind (Etyp) = E_Incomplete_Type
3578 and then Full_View (Etyp) = B_Type);
3579 end Match;
3581 -- Start of processing for Collect_Primitive_Operations
3583 begin
3584 -- For tagged types, the primitive operations are collected as they
3585 -- are declared, and held in an explicit list which is simply returned.
3587 if Is_Tagged_Type (B_Type) then
3588 return Primitive_Operations (B_Type);
3590 -- An untagged generic type that is a derived type inherits the
3591 -- primitive operations of its parent type. Other formal types only
3592 -- have predefined operators, which are not explicitly represented.
3594 elsif Is_Generic_Type (B_Type) then
3595 if Nkind (B_Decl) = N_Formal_Type_Declaration
3596 and then Nkind (Formal_Type_Definition (B_Decl)) =
3597 N_Formal_Derived_Type_Definition
3598 then
3599 Formal_Derived := True;
3600 else
3601 return New_Elmt_List;
3602 end if;
3603 end if;
3605 Op_List := New_Elmt_List;
3607 if B_Scope = Standard_Standard then
3608 if B_Type = Standard_String then
3609 Append_Elmt (Standard_Op_Concat, Op_List);
3611 elsif B_Type = Standard_Wide_String then
3612 Append_Elmt (Standard_Op_Concatw, Op_List);
3614 else
3615 null;
3616 end if;
3618 -- Locate the primitive subprograms of the type
3620 else
3621 -- The primitive operations appear after the base type, except
3622 -- if the derivation happens within the private part of B_Scope
3623 -- and the type is a private type, in which case both the type
3624 -- and some primitive operations may appear before the base
3625 -- type, and the list of candidates starts after the type.
3627 if In_Open_Scopes (B_Scope)
3628 and then Scope (T) = B_Scope
3629 and then In_Private_Part (B_Scope)
3630 then
3631 Id := Next_Entity (T);
3633 -- In Ada 2012, If the type has an incomplete partial view, there
3634 -- may be primitive operations declared before the full view, so
3635 -- we need to start scanning from the incomplete view, which is
3636 -- earlier on the entity chain.
3638 elsif Nkind (Parent (B_Type)) = N_Full_Type_Declaration
3639 and then Present (Incomplete_View (Parent (B_Type)))
3640 then
3641 Id := Defining_Entity (Incomplete_View (Parent (B_Type)));
3643 else
3644 Id := Next_Entity (B_Type);
3645 end if;
3647 -- Set flag if this is a type in a package spec
3649 Is_Type_In_Pkg :=
3650 Is_Package_Or_Generic_Package (B_Scope)
3651 and then
3652 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
3653 N_Package_Body;
3655 while Present (Id) loop
3657 -- Test whether the result type or any of the parameter types of
3658 -- each subprogram following the type match that type when the
3659 -- type is declared in a package spec, is a derived type, or the
3660 -- subprogram is marked as primitive. (The Is_Primitive test is
3661 -- needed to find primitives of nonderived types in declarative
3662 -- parts that happen to override the predefined "=" operator.)
3664 -- Note that generic formal subprograms are not considered to be
3665 -- primitive operations and thus are never inherited.
3667 if Is_Overloadable (Id)
3668 and then (Is_Type_In_Pkg
3669 or else Is_Derived_Type (B_Type)
3670 or else Is_Primitive (Id))
3671 and then Nkind (Parent (Parent (Id)))
3672 not in N_Formal_Subprogram_Declaration
3673 then
3674 Is_Prim := False;
3676 if Match (Id) then
3677 Is_Prim := True;
3679 else
3680 Formal := First_Formal (Id);
3681 while Present (Formal) loop
3682 if Match (Formal) then
3683 Is_Prim := True;
3684 exit;
3685 end if;
3687 Next_Formal (Formal);
3688 end loop;
3689 end if;
3691 -- For a formal derived type, the only primitives are the ones
3692 -- inherited from the parent type. Operations appearing in the
3693 -- package declaration are not primitive for it.
3695 if Is_Prim
3696 and then (not Formal_Derived or else Present (Alias (Id)))
3697 then
3698 -- In the special case of an equality operator aliased to
3699 -- an overriding dispatching equality belonging to the same
3700 -- type, we don't include it in the list of primitives.
3701 -- This avoids inheriting multiple equality operators when
3702 -- deriving from untagged private types whose full type is
3703 -- tagged, which can otherwise cause ambiguities. Note that
3704 -- this should only happen for this kind of untagged parent
3705 -- type, since normally dispatching operations are inherited
3706 -- using the type's Primitive_Operations list.
3708 if Chars (Id) = Name_Op_Eq
3709 and then Is_Dispatching_Operation (Id)
3710 and then Present (Alias (Id))
3711 and then Present (Overridden_Operation (Alias (Id)))
3712 and then Base_Type (Etype (First_Entity (Id))) =
3713 Base_Type (Etype (First_Entity (Alias (Id))))
3714 then
3715 null;
3717 -- Include the subprogram in the list of primitives
3719 else
3720 Append_Elmt (Id, Op_List);
3721 end if;
3722 end if;
3723 end if;
3725 Next_Entity (Id);
3727 -- For a type declared in System, some of its operations may
3728 -- appear in the target-specific extension to System.
3730 if No (Id)
3731 and then B_Scope = RTU_Entity (System)
3732 and then Present_System_Aux
3733 then
3734 B_Scope := System_Aux_Id;
3735 Id := First_Entity (System_Aux_Id);
3736 end if;
3737 end loop;
3738 end if;
3740 return Op_List;
3741 end Collect_Primitive_Operations;
3743 -----------------------------------
3744 -- Compile_Time_Constraint_Error --
3745 -----------------------------------
3747 function Compile_Time_Constraint_Error
3748 (N : Node_Id;
3749 Msg : String;
3750 Ent : Entity_Id := Empty;
3751 Loc : Source_Ptr := No_Location;
3752 Warn : Boolean := False) return Node_Id
3754 Msgc : String (1 .. Msg'Length + 3);
3755 -- Copy of message, with room for possible ?? or << and ! at end
3757 Msgl : Natural;
3758 Wmsg : Boolean;
3759 Eloc : Source_Ptr;
3761 -- Start of processing for Compile_Time_Constraint_Error
3763 begin
3764 -- If this is a warning, convert it into an error if we are in code
3765 -- subject to SPARK_Mode being set ON.
3767 Error_Msg_Warn := SPARK_Mode /= On;
3769 -- A static constraint error in an instance body is not a fatal error.
3770 -- we choose to inhibit the message altogether, because there is no
3771 -- obvious node (for now) on which to post it. On the other hand the
3772 -- offending node must be replaced with a constraint_error in any case.
3774 -- No messages are generated if we already posted an error on this node
3776 if not Error_Posted (N) then
3777 if Loc /= No_Location then
3778 Eloc := Loc;
3779 else
3780 Eloc := Sloc (N);
3781 end if;
3783 -- Copy message to Msgc, converting any ? in the message into
3784 -- < instead, so that we have an error in GNATprove mode.
3786 Msgl := Msg'Length;
3788 for J in 1 .. Msgl loop
3789 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
3790 Msgc (J) := '<';
3791 else
3792 Msgc (J) := Msg (J);
3793 end if;
3794 end loop;
3796 -- Message is a warning, even in Ada 95 case
3798 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
3799 Wmsg := True;
3801 -- In Ada 83, all messages are warnings. In the private part and
3802 -- the body of an instance, constraint_checks are only warnings.
3803 -- We also make this a warning if the Warn parameter is set.
3805 elsif Warn
3806 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
3807 then
3808 Msgl := Msgl + 1;
3809 Msgc (Msgl) := '<';
3810 Msgl := Msgl + 1;
3811 Msgc (Msgl) := '<';
3812 Wmsg := True;
3814 elsif In_Instance_Not_Visible then
3815 Msgl := Msgl + 1;
3816 Msgc (Msgl) := '<';
3817 Msgl := Msgl + 1;
3818 Msgc (Msgl) := '<';
3819 Wmsg := True;
3821 -- Otherwise we have a real error message (Ada 95 static case)
3822 -- and we make this an unconditional message. Note that in the
3823 -- warning case we do not make the message unconditional, it seems
3824 -- quite reasonable to delete messages like this (about exceptions
3825 -- that will be raised) in dead code.
3827 else
3828 Wmsg := False;
3829 Msgl := Msgl + 1;
3830 Msgc (Msgl) := '!';
3831 end if;
3833 -- One more test, skip the warning if the related expression is
3834 -- statically unevaluated, since we don't want to warn about what
3835 -- will happen when something is evaluated if it never will be
3836 -- evaluated.
3838 if not Is_Statically_Unevaluated (N) then
3839 Error_Msg_Warn := SPARK_Mode /= On;
3841 if Present (Ent) then
3842 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
3843 else
3844 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
3845 end if;
3847 if Wmsg then
3849 -- Check whether the context is an Init_Proc
3851 if Inside_Init_Proc then
3852 declare
3853 Conc_Typ : constant Entity_Id :=
3854 Corresponding_Concurrent_Type
3855 (Entity (Parameter_Type (First
3856 (Parameter_Specifications
3857 (Parent (Current_Scope))))));
3859 begin
3860 -- Don't complain if the corresponding concurrent type
3861 -- doesn't come from source (i.e. a single task/protected
3862 -- object).
3864 if Present (Conc_Typ)
3865 and then not Comes_From_Source (Conc_Typ)
3866 then
3867 Error_Msg_NEL
3868 ("\& [<<", N, Standard_Constraint_Error, Eloc);
3870 else
3871 if GNATprove_Mode then
3872 Error_Msg_NEL
3873 ("\& would have been raised for objects of this "
3874 & "type", N, Standard_Constraint_Error, Eloc);
3875 else
3876 Error_Msg_NEL
3877 ("\& will be raised for objects of this type??",
3878 N, Standard_Constraint_Error, Eloc);
3879 end if;
3880 end if;
3881 end;
3883 else
3884 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
3885 end if;
3887 else
3888 Error_Msg ("\static expression fails Constraint_Check", Eloc);
3889 Set_Error_Posted (N);
3890 end if;
3891 end if;
3892 end if;
3894 return N;
3895 end Compile_Time_Constraint_Error;
3897 -----------------------
3898 -- Conditional_Delay --
3899 -----------------------
3901 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
3902 begin
3903 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
3904 Set_Has_Delayed_Freeze (New_Ent);
3905 end if;
3906 end Conditional_Delay;
3908 ----------------------------
3909 -- Contains_Refined_State --
3910 ----------------------------
3912 function Contains_Refined_State (Prag : Node_Id) return Boolean is
3913 function Has_State_In_Dependency (List : Node_Id) return Boolean;
3914 -- Determine whether a dependency list mentions a state with a visible
3915 -- refinement.
3917 function Has_State_In_Global (List : Node_Id) return Boolean;
3918 -- Determine whether a global list mentions a state with a visible
3919 -- refinement.
3921 function Is_Refined_State (Item : Node_Id) return Boolean;
3922 -- Determine whether Item is a reference to an abstract state with a
3923 -- visible refinement.
3925 -----------------------------
3926 -- Has_State_In_Dependency --
3927 -----------------------------
3929 function Has_State_In_Dependency (List : Node_Id) return Boolean is
3930 Clause : Node_Id;
3931 Output : Node_Id;
3933 begin
3934 -- A null dependency list does not mention any states
3936 if Nkind (List) = N_Null then
3937 return False;
3939 -- Dependency clauses appear as component associations of an
3940 -- aggregate.
3942 elsif Nkind (List) = N_Aggregate
3943 and then Present (Component_Associations (List))
3944 then
3945 Clause := First (Component_Associations (List));
3946 while Present (Clause) loop
3948 -- Inspect the outputs of a dependency clause
3950 Output := First (Choices (Clause));
3951 while Present (Output) loop
3952 if Is_Refined_State (Output) then
3953 return True;
3954 end if;
3956 Next (Output);
3957 end loop;
3959 -- Inspect the outputs of a dependency clause
3961 if Is_Refined_State (Expression (Clause)) then
3962 return True;
3963 end if;
3965 Next (Clause);
3966 end loop;
3968 -- If we get here, then none of the dependency clauses mention a
3969 -- state with visible refinement.
3971 return False;
3973 -- An illegal pragma managed to sneak in
3975 else
3976 raise Program_Error;
3977 end if;
3978 end Has_State_In_Dependency;
3980 -------------------------
3981 -- Has_State_In_Global --
3982 -------------------------
3984 function Has_State_In_Global (List : Node_Id) return Boolean is
3985 Item : Node_Id;
3987 begin
3988 -- A null global list does not mention any states
3990 if Nkind (List) = N_Null then
3991 return False;
3993 -- Simple global list or moded global list declaration
3995 elsif Nkind (List) = N_Aggregate then
3997 -- The declaration of a simple global list appear as a collection
3998 -- of expressions.
4000 if Present (Expressions (List)) then
4001 Item := First (Expressions (List));
4002 while Present (Item) loop
4003 if Is_Refined_State (Item) then
4004 return True;
4005 end if;
4007 Next (Item);
4008 end loop;
4010 -- The declaration of a moded global list appears as a collection
4011 -- of component associations where individual choices denote
4012 -- modes.
4014 else
4015 Item := First (Component_Associations (List));
4016 while Present (Item) loop
4017 if Has_State_In_Global (Expression (Item)) then
4018 return True;
4019 end if;
4021 Next (Item);
4022 end loop;
4023 end if;
4025 -- If we get here, then the simple/moded global list did not
4026 -- mention any states with a visible refinement.
4028 return False;
4030 -- Single global item declaration
4032 elsif Is_Entity_Name (List) then
4033 return Is_Refined_State (List);
4035 -- An illegal pragma managed to sneak in
4037 else
4038 raise Program_Error;
4039 end if;
4040 end Has_State_In_Global;
4042 ----------------------
4043 -- Is_Refined_State --
4044 ----------------------
4046 function Is_Refined_State (Item : Node_Id) return Boolean is
4047 Elmt : Node_Id;
4048 Item_Id : Entity_Id;
4050 begin
4051 if Nkind (Item) = N_Null then
4052 return False;
4054 -- States cannot be subject to attribute 'Result. This case arises
4055 -- in dependency relations.
4057 elsif Nkind (Item) = N_Attribute_Reference
4058 and then Attribute_Name (Item) = Name_Result
4059 then
4060 return False;
4062 -- Multiple items appear as an aggregate. This case arises in
4063 -- dependency relations.
4065 elsif Nkind (Item) = N_Aggregate
4066 and then Present (Expressions (Item))
4067 then
4068 Elmt := First (Expressions (Item));
4069 while Present (Elmt) loop
4070 if Is_Refined_State (Elmt) then
4071 return True;
4072 end if;
4074 Next (Elmt);
4075 end loop;
4077 -- If we get here, then none of the inputs or outputs reference a
4078 -- state with visible refinement.
4080 return False;
4082 -- Single item
4084 else
4085 Item_Id := Entity_Of (Item);
4087 return
4088 Present (Item_Id)
4089 and then Ekind (Item_Id) = E_Abstract_State
4090 and then Has_Visible_Refinement (Item_Id);
4091 end if;
4092 end Is_Refined_State;
4094 -- Local variables
4096 Arg : constant Node_Id :=
4097 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
4098 Nam : constant Name_Id := Pragma_Name (Prag);
4100 -- Start of processing for Contains_Refined_State
4102 begin
4103 if Nam = Name_Depends then
4104 return Has_State_In_Dependency (Arg);
4106 else pragma Assert (Nam = Name_Global);
4107 return Has_State_In_Global (Arg);
4108 end if;
4109 end Contains_Refined_State;
4111 -------------------------
4112 -- Copy_Component_List --
4113 -------------------------
4115 function Copy_Component_List
4116 (R_Typ : Entity_Id;
4117 Loc : Source_Ptr) return List_Id
4119 Comp : Node_Id;
4120 Comps : constant List_Id := New_List;
4122 begin
4123 Comp := First_Component (Underlying_Type (R_Typ));
4124 while Present (Comp) loop
4125 if Comes_From_Source (Comp) then
4126 declare
4127 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
4128 begin
4129 Append_To (Comps,
4130 Make_Component_Declaration (Loc,
4131 Defining_Identifier =>
4132 Make_Defining_Identifier (Loc, Chars (Comp)),
4133 Component_Definition =>
4134 New_Copy_Tree
4135 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
4136 end;
4137 end if;
4139 Next_Component (Comp);
4140 end loop;
4142 return Comps;
4143 end Copy_Component_List;
4145 -------------------------
4146 -- Copy_Parameter_List --
4147 -------------------------
4149 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
4150 Loc : constant Source_Ptr := Sloc (Subp_Id);
4151 Plist : List_Id;
4152 Formal : Entity_Id;
4154 begin
4155 if No (First_Formal (Subp_Id)) then
4156 return No_List;
4157 else
4158 Plist := New_List;
4159 Formal := First_Formal (Subp_Id);
4160 while Present (Formal) loop
4161 Append
4162 (Make_Parameter_Specification (Loc,
4163 Defining_Identifier =>
4164 Make_Defining_Identifier (Sloc (Formal),
4165 Chars => Chars (Formal)),
4166 In_Present => In_Present (Parent (Formal)),
4167 Out_Present => Out_Present (Parent (Formal)),
4168 Parameter_Type =>
4169 New_Occurrence_Of (Etype (Formal), Loc),
4170 Expression =>
4171 New_Copy_Tree (Expression (Parent (Formal)))),
4172 Plist);
4174 Next_Formal (Formal);
4175 end loop;
4176 end if;
4178 return Plist;
4179 end Copy_Parameter_List;
4181 --------------------------------
4182 -- Corresponding_Generic_Type --
4183 --------------------------------
4185 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
4186 Inst : Entity_Id;
4187 Gen : Entity_Id;
4188 Typ : Entity_Id;
4190 begin
4191 if not Is_Generic_Actual_Type (T) then
4192 return Any_Type;
4194 -- If the actual is the actual of an enclosing instance, resolution
4195 -- was correct in the generic.
4197 elsif Nkind (Parent (T)) = N_Subtype_Declaration
4198 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
4199 and then
4200 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
4201 then
4202 return Any_Type;
4204 else
4205 Inst := Scope (T);
4207 if Is_Wrapper_Package (Inst) then
4208 Inst := Related_Instance (Inst);
4209 end if;
4211 Gen :=
4212 Generic_Parent
4213 (Specification (Unit_Declaration_Node (Inst)));
4215 -- Generic actual has the same name as the corresponding formal
4217 Typ := First_Entity (Gen);
4218 while Present (Typ) loop
4219 if Chars (Typ) = Chars (T) then
4220 return Typ;
4221 end if;
4223 Next_Entity (Typ);
4224 end loop;
4226 return Any_Type;
4227 end if;
4228 end Corresponding_Generic_Type;
4230 --------------------
4231 -- Current_Entity --
4232 --------------------
4234 -- The currently visible definition for a given identifier is the
4235 -- one most chained at the start of the visibility chain, i.e. the
4236 -- one that is referenced by the Node_Id value of the name of the
4237 -- given identifier.
4239 function Current_Entity (N : Node_Id) return Entity_Id is
4240 begin
4241 return Get_Name_Entity_Id (Chars (N));
4242 end Current_Entity;
4244 -----------------------------
4245 -- Current_Entity_In_Scope --
4246 -----------------------------
4248 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
4249 E : Entity_Id;
4250 CS : constant Entity_Id := Current_Scope;
4252 Transient_Case : constant Boolean := Scope_Is_Transient;
4254 begin
4255 E := Get_Name_Entity_Id (Chars (N));
4256 while Present (E)
4257 and then Scope (E) /= CS
4258 and then (not Transient_Case or else Scope (E) /= Scope (CS))
4259 loop
4260 E := Homonym (E);
4261 end loop;
4263 return E;
4264 end Current_Entity_In_Scope;
4266 -------------------
4267 -- Current_Scope --
4268 -------------------
4270 function Current_Scope return Entity_Id is
4271 begin
4272 if Scope_Stack.Last = -1 then
4273 return Standard_Standard;
4274 else
4275 declare
4276 C : constant Entity_Id :=
4277 Scope_Stack.Table (Scope_Stack.Last).Entity;
4278 begin
4279 if Present (C) then
4280 return C;
4281 else
4282 return Standard_Standard;
4283 end if;
4284 end;
4285 end if;
4286 end Current_Scope;
4288 ------------------------
4289 -- Current_Subprogram --
4290 ------------------------
4292 function Current_Subprogram return Entity_Id is
4293 Scop : constant Entity_Id := Current_Scope;
4294 begin
4295 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
4296 return Scop;
4297 else
4298 return Enclosing_Subprogram (Scop);
4299 end if;
4300 end Current_Subprogram;
4302 ----------------------------------
4303 -- Deepest_Type_Access_Level --
4304 ----------------------------------
4306 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
4307 begin
4308 if Ekind (Typ) = E_Anonymous_Access_Type
4309 and then not Is_Local_Anonymous_Access (Typ)
4310 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
4311 then
4312 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4313 -- access type.
4315 return
4316 Scope_Depth (Enclosing_Dynamic_Scope
4317 (Defining_Identifier
4318 (Associated_Node_For_Itype (Typ))));
4320 -- For generic formal type, return Int'Last (infinite).
4321 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4323 elsif Is_Generic_Type (Root_Type (Typ)) then
4324 return UI_From_Int (Int'Last);
4326 else
4327 return Type_Access_Level (Typ);
4328 end if;
4329 end Deepest_Type_Access_Level;
4331 ---------------------
4332 -- Defining_Entity --
4333 ---------------------
4335 function Defining_Entity (N : Node_Id) return Entity_Id is
4336 K : constant Node_Kind := Nkind (N);
4337 Err : Entity_Id := Empty;
4339 begin
4340 case K is
4341 when
4342 N_Subprogram_Declaration |
4343 N_Abstract_Subprogram_Declaration |
4344 N_Subprogram_Body |
4345 N_Package_Declaration |
4346 N_Subprogram_Renaming_Declaration |
4347 N_Subprogram_Body_Stub |
4348 N_Generic_Subprogram_Declaration |
4349 N_Generic_Package_Declaration |
4350 N_Formal_Subprogram_Declaration |
4351 N_Expression_Function
4353 return Defining_Entity (Specification (N));
4355 when
4356 N_Component_Declaration |
4357 N_Defining_Program_Unit_Name |
4358 N_Discriminant_Specification |
4359 N_Entry_Body |
4360 N_Entry_Declaration |
4361 N_Entry_Index_Specification |
4362 N_Exception_Declaration |
4363 N_Exception_Renaming_Declaration |
4364 N_Formal_Object_Declaration |
4365 N_Formal_Package_Declaration |
4366 N_Formal_Type_Declaration |
4367 N_Full_Type_Declaration |
4368 N_Implicit_Label_Declaration |
4369 N_Incomplete_Type_Declaration |
4370 N_Loop_Parameter_Specification |
4371 N_Number_Declaration |
4372 N_Object_Declaration |
4373 N_Object_Renaming_Declaration |
4374 N_Package_Body_Stub |
4375 N_Parameter_Specification |
4376 N_Private_Extension_Declaration |
4377 N_Private_Type_Declaration |
4378 N_Protected_Body |
4379 N_Protected_Body_Stub |
4380 N_Protected_Type_Declaration |
4381 N_Single_Protected_Declaration |
4382 N_Single_Task_Declaration |
4383 N_Subtype_Declaration |
4384 N_Task_Body |
4385 N_Task_Body_Stub |
4386 N_Task_Type_Declaration
4388 return Defining_Identifier (N);
4390 when N_Subunit =>
4391 return Defining_Entity (Proper_Body (N));
4393 when
4394 N_Function_Instantiation |
4395 N_Function_Specification |
4396 N_Generic_Function_Renaming_Declaration |
4397 N_Generic_Package_Renaming_Declaration |
4398 N_Generic_Procedure_Renaming_Declaration |
4399 N_Package_Body |
4400 N_Package_Instantiation |
4401 N_Package_Renaming_Declaration |
4402 N_Package_Specification |
4403 N_Procedure_Instantiation |
4404 N_Procedure_Specification
4406 declare
4407 Nam : constant Node_Id := Defining_Unit_Name (N);
4409 begin
4410 if Nkind (Nam) in N_Entity then
4411 return Nam;
4413 -- For Error, make up a name and attach to declaration
4414 -- so we can continue semantic analysis
4416 elsif Nam = Error then
4417 Err := Make_Temporary (Sloc (N), 'T');
4418 Set_Defining_Unit_Name (N, Err);
4420 return Err;
4422 -- If not an entity, get defining identifier
4424 else
4425 return Defining_Identifier (Nam);
4426 end if;
4427 end;
4429 when
4430 N_Block_Statement |
4431 N_Loop_Statement
4433 return Entity (Identifier (N));
4435 when others =>
4436 raise Program_Error;
4438 end case;
4439 end Defining_Entity;
4441 --------------------------
4442 -- Denotes_Discriminant --
4443 --------------------------
4445 function Denotes_Discriminant
4446 (N : Node_Id;
4447 Check_Concurrent : Boolean := False) return Boolean
4449 E : Entity_Id;
4451 begin
4452 if not Is_Entity_Name (N) or else No (Entity (N)) then
4453 return False;
4454 else
4455 E := Entity (N);
4456 end if;
4458 -- If we are checking for a protected type, the discriminant may have
4459 -- been rewritten as the corresponding discriminal of the original type
4460 -- or of the corresponding concurrent record, depending on whether we
4461 -- are in the spec or body of the protected type.
4463 return Ekind (E) = E_Discriminant
4464 or else
4465 (Check_Concurrent
4466 and then Ekind (E) = E_In_Parameter
4467 and then Present (Discriminal_Link (E))
4468 and then
4469 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
4470 or else
4471 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
4473 end Denotes_Discriminant;
4475 -------------------------
4476 -- Denotes_Same_Object --
4477 -------------------------
4479 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
4480 Obj1 : Node_Id := A1;
4481 Obj2 : Node_Id := A2;
4483 function Has_Prefix (N : Node_Id) return Boolean;
4484 -- Return True if N has attribute Prefix
4486 function Is_Renaming (N : Node_Id) return Boolean;
4487 -- Return true if N names a renaming entity
4489 function Is_Valid_Renaming (N : Node_Id) return Boolean;
4490 -- For renamings, return False if the prefix of any dereference within
4491 -- the renamed object_name is a variable, or any expression within the
4492 -- renamed object_name contains references to variables or calls on
4493 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4495 ----------------
4496 -- Has_Prefix --
4497 ----------------
4499 function Has_Prefix (N : Node_Id) return Boolean is
4500 begin
4501 return
4502 Nkind_In (N,
4503 N_Attribute_Reference,
4504 N_Expanded_Name,
4505 N_Explicit_Dereference,
4506 N_Indexed_Component,
4507 N_Reference,
4508 N_Selected_Component,
4509 N_Slice);
4510 end Has_Prefix;
4512 -----------------
4513 -- Is_Renaming --
4514 -----------------
4516 function Is_Renaming (N : Node_Id) return Boolean is
4517 begin
4518 return Is_Entity_Name (N)
4519 and then Present (Renamed_Entity (Entity (N)));
4520 end Is_Renaming;
4522 -----------------------
4523 -- Is_Valid_Renaming --
4524 -----------------------
4526 function Is_Valid_Renaming (N : Node_Id) return Boolean is
4528 function Check_Renaming (N : Node_Id) return Boolean;
4529 -- Recursive function used to traverse all the prefixes of N
4531 function Check_Renaming (N : Node_Id) return Boolean is
4532 begin
4533 if Is_Renaming (N)
4534 and then not Check_Renaming (Renamed_Entity (Entity (N)))
4535 then
4536 return False;
4537 end if;
4539 if Nkind (N) = N_Indexed_Component then
4540 declare
4541 Indx : Node_Id;
4543 begin
4544 Indx := First (Expressions (N));
4545 while Present (Indx) loop
4546 if not Is_OK_Static_Expression (Indx) then
4547 return False;
4548 end if;
4550 Next_Index (Indx);
4551 end loop;
4552 end;
4553 end if;
4555 if Has_Prefix (N) then
4556 declare
4557 P : constant Node_Id := Prefix (N);
4559 begin
4560 if Nkind (N) = N_Explicit_Dereference
4561 and then Is_Variable (P)
4562 then
4563 return False;
4565 elsif Is_Entity_Name (P)
4566 and then Ekind (Entity (P)) = E_Function
4567 then
4568 return False;
4570 elsif Nkind (P) = N_Function_Call then
4571 return False;
4572 end if;
4574 -- Recursion to continue traversing the prefix of the
4575 -- renaming expression
4577 return Check_Renaming (P);
4578 end;
4579 end if;
4581 return True;
4582 end Check_Renaming;
4584 -- Start of processing for Is_Valid_Renaming
4586 begin
4587 return Check_Renaming (N);
4588 end Is_Valid_Renaming;
4590 -- Start of processing for Denotes_Same_Object
4592 begin
4593 -- Both names statically denote the same stand-alone object or parameter
4594 -- (RM 6.4.1(6.5/3))
4596 if Is_Entity_Name (Obj1)
4597 and then Is_Entity_Name (Obj2)
4598 and then Entity (Obj1) = Entity (Obj2)
4599 then
4600 return True;
4601 end if;
4603 -- For renamings, the prefix of any dereference within the renamed
4604 -- object_name is not a variable, and any expression within the
4605 -- renamed object_name contains no references to variables nor
4606 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4608 if Is_Renaming (Obj1) then
4609 if Is_Valid_Renaming (Obj1) then
4610 Obj1 := Renamed_Entity (Entity (Obj1));
4611 else
4612 return False;
4613 end if;
4614 end if;
4616 if Is_Renaming (Obj2) then
4617 if Is_Valid_Renaming (Obj2) then
4618 Obj2 := Renamed_Entity (Entity (Obj2));
4619 else
4620 return False;
4621 end if;
4622 end if;
4624 -- No match if not same node kind (such cases are handled by
4625 -- Denotes_Same_Prefix)
4627 if Nkind (Obj1) /= Nkind (Obj2) then
4628 return False;
4630 -- After handling valid renamings, one of the two names statically
4631 -- denoted a renaming declaration whose renamed object_name is known
4632 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4634 elsif Is_Entity_Name (Obj1) then
4635 if Is_Entity_Name (Obj2) then
4636 return Entity (Obj1) = Entity (Obj2);
4637 else
4638 return False;
4639 end if;
4641 -- Both names are selected_components, their prefixes are known to
4642 -- denote the same object, and their selector_names denote the same
4643 -- component (RM 6.4.1(6.6/3)
4645 elsif Nkind (Obj1) = N_Selected_Component then
4646 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4647 and then
4648 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
4650 -- Both names are dereferences and the dereferenced names are known to
4651 -- denote the same object (RM 6.4.1(6.7/3))
4653 elsif Nkind (Obj1) = N_Explicit_Dereference then
4654 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
4656 -- Both names are indexed_components, their prefixes are known to denote
4657 -- the same object, and each of the pairs of corresponding index values
4658 -- are either both static expressions with the same static value or both
4659 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4661 elsif Nkind (Obj1) = N_Indexed_Component then
4662 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
4663 return False;
4664 else
4665 declare
4666 Indx1 : Node_Id;
4667 Indx2 : Node_Id;
4669 begin
4670 Indx1 := First (Expressions (Obj1));
4671 Indx2 := First (Expressions (Obj2));
4672 while Present (Indx1) loop
4674 -- Indexes must denote the same static value or same object
4676 if Is_OK_Static_Expression (Indx1) then
4677 if not Is_OK_Static_Expression (Indx2) then
4678 return False;
4680 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
4681 return False;
4682 end if;
4684 elsif not Denotes_Same_Object (Indx1, Indx2) then
4685 return False;
4686 end if;
4688 Next (Indx1);
4689 Next (Indx2);
4690 end loop;
4692 return True;
4693 end;
4694 end if;
4696 -- Both names are slices, their prefixes are known to denote the same
4697 -- object, and the two slices have statically matching index constraints
4698 -- (RM 6.4.1(6.9/3))
4700 elsif Nkind (Obj1) = N_Slice
4701 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4702 then
4703 declare
4704 Lo1, Lo2, Hi1, Hi2 : Node_Id;
4706 begin
4707 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
4708 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
4710 -- Check whether bounds are statically identical. There is no
4711 -- attempt to detect partial overlap of slices.
4713 return Denotes_Same_Object (Lo1, Lo2)
4714 and then Denotes_Same_Object (Hi1, Hi2);
4715 end;
4717 -- In the recursion, literals appear as indexes
4719 elsif Nkind (Obj1) = N_Integer_Literal
4720 and then
4721 Nkind (Obj2) = N_Integer_Literal
4722 then
4723 return Intval (Obj1) = Intval (Obj2);
4725 else
4726 return False;
4727 end if;
4728 end Denotes_Same_Object;
4730 -------------------------
4731 -- Denotes_Same_Prefix --
4732 -------------------------
4734 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
4736 begin
4737 if Is_Entity_Name (A1) then
4738 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
4739 and then not Is_Access_Type (Etype (A1))
4740 then
4741 return Denotes_Same_Object (A1, Prefix (A2))
4742 or else Denotes_Same_Prefix (A1, Prefix (A2));
4743 else
4744 return False;
4745 end if;
4747 elsif Is_Entity_Name (A2) then
4748 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
4750 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
4751 and then
4752 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
4753 then
4754 declare
4755 Root1, Root2 : Node_Id;
4756 Depth1, Depth2 : Int := 0;
4758 begin
4759 Root1 := Prefix (A1);
4760 while not Is_Entity_Name (Root1) loop
4761 if not Nkind_In
4762 (Root1, N_Selected_Component, N_Indexed_Component)
4763 then
4764 return False;
4765 else
4766 Root1 := Prefix (Root1);
4767 end if;
4769 Depth1 := Depth1 + 1;
4770 end loop;
4772 Root2 := Prefix (A2);
4773 while not Is_Entity_Name (Root2) loop
4774 if not Nkind_In
4775 (Root2, N_Selected_Component, N_Indexed_Component)
4776 then
4777 return False;
4778 else
4779 Root2 := Prefix (Root2);
4780 end if;
4782 Depth2 := Depth2 + 1;
4783 end loop;
4785 -- If both have the same depth and they do not denote the same
4786 -- object, they are disjoint and no warning is needed.
4788 if Depth1 = Depth2 then
4789 return False;
4791 elsif Depth1 > Depth2 then
4792 Root1 := Prefix (A1);
4793 for I in 1 .. Depth1 - Depth2 - 1 loop
4794 Root1 := Prefix (Root1);
4795 end loop;
4797 return Denotes_Same_Object (Root1, A2);
4799 else
4800 Root2 := Prefix (A2);
4801 for I in 1 .. Depth2 - Depth1 - 1 loop
4802 Root2 := Prefix (Root2);
4803 end loop;
4805 return Denotes_Same_Object (A1, Root2);
4806 end if;
4807 end;
4809 else
4810 return False;
4811 end if;
4812 end Denotes_Same_Prefix;
4814 ----------------------
4815 -- Denotes_Variable --
4816 ----------------------
4818 function Denotes_Variable (N : Node_Id) return Boolean is
4819 begin
4820 return Is_Variable (N) and then Paren_Count (N) = 0;
4821 end Denotes_Variable;
4823 -----------------------------
4824 -- Depends_On_Discriminant --
4825 -----------------------------
4827 function Depends_On_Discriminant (N : Node_Id) return Boolean is
4828 L : Node_Id;
4829 H : Node_Id;
4831 begin
4832 Get_Index_Bounds (N, L, H);
4833 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
4834 end Depends_On_Discriminant;
4836 -------------------------
4837 -- Designate_Same_Unit --
4838 -------------------------
4840 function Designate_Same_Unit
4841 (Name1 : Node_Id;
4842 Name2 : Node_Id) return Boolean
4844 K1 : constant Node_Kind := Nkind (Name1);
4845 K2 : constant Node_Kind := Nkind (Name2);
4847 function Prefix_Node (N : Node_Id) return Node_Id;
4848 -- Returns the parent unit name node of a defining program unit name
4849 -- or the prefix if N is a selected component or an expanded name.
4851 function Select_Node (N : Node_Id) return Node_Id;
4852 -- Returns the defining identifier node of a defining program unit
4853 -- name or the selector node if N is a selected component or an
4854 -- expanded name.
4856 -----------------
4857 -- Prefix_Node --
4858 -----------------
4860 function Prefix_Node (N : Node_Id) return Node_Id is
4861 begin
4862 if Nkind (N) = N_Defining_Program_Unit_Name then
4863 return Name (N);
4865 else
4866 return Prefix (N);
4867 end if;
4868 end Prefix_Node;
4870 -----------------
4871 -- Select_Node --
4872 -----------------
4874 function Select_Node (N : Node_Id) return Node_Id is
4875 begin
4876 if Nkind (N) = N_Defining_Program_Unit_Name then
4877 return Defining_Identifier (N);
4879 else
4880 return Selector_Name (N);
4881 end if;
4882 end Select_Node;
4884 -- Start of processing for Designate_Next_Unit
4886 begin
4887 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
4888 and then
4889 (K2 = N_Identifier or else K2 = N_Defining_Identifier)
4890 then
4891 return Chars (Name1) = Chars (Name2);
4893 elsif
4894 (K1 = N_Expanded_Name or else
4895 K1 = N_Selected_Component or else
4896 K1 = N_Defining_Program_Unit_Name)
4897 and then
4898 (K2 = N_Expanded_Name or else
4899 K2 = N_Selected_Component or else
4900 K2 = N_Defining_Program_Unit_Name)
4901 then
4902 return
4903 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
4904 and then
4905 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
4907 else
4908 return False;
4909 end if;
4910 end Designate_Same_Unit;
4912 ------------------------------------------
4913 -- function Dynamic_Accessibility_Level --
4914 ------------------------------------------
4916 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
4917 E : Entity_Id;
4918 Loc : constant Source_Ptr := Sloc (Expr);
4920 function Make_Level_Literal (Level : Uint) return Node_Id;
4921 -- Construct an integer literal representing an accessibility level
4922 -- with its type set to Natural.
4924 ------------------------
4925 -- Make_Level_Literal --
4926 ------------------------
4928 function Make_Level_Literal (Level : Uint) return Node_Id is
4929 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
4930 begin
4931 Set_Etype (Result, Standard_Natural);
4932 return Result;
4933 end Make_Level_Literal;
4935 -- Start of processing for Dynamic_Accessibility_Level
4937 begin
4938 if Is_Entity_Name (Expr) then
4939 E := Entity (Expr);
4941 if Present (Renamed_Object (E)) then
4942 return Dynamic_Accessibility_Level (Renamed_Object (E));
4943 end if;
4945 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
4946 if Present (Extra_Accessibility (E)) then
4947 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
4948 end if;
4949 end if;
4950 end if;
4952 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4954 case Nkind (Expr) is
4956 -- For access discriminant, the level of the enclosing object
4958 when N_Selected_Component =>
4959 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
4960 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
4961 E_Anonymous_Access_Type
4962 then
4963 return Make_Level_Literal (Object_Access_Level (Expr));
4964 end if;
4966 when N_Attribute_Reference =>
4967 case Get_Attribute_Id (Attribute_Name (Expr)) is
4969 -- For X'Access, the level of the prefix X
4971 when Attribute_Access =>
4972 return Make_Level_Literal
4973 (Object_Access_Level (Prefix (Expr)));
4975 -- Treat the unchecked attributes as library-level
4977 when Attribute_Unchecked_Access |
4978 Attribute_Unrestricted_Access =>
4979 return Make_Level_Literal (Scope_Depth (Standard_Standard));
4981 -- No other access-valued attributes
4983 when others =>
4984 raise Program_Error;
4985 end case;
4987 when N_Allocator =>
4989 -- Unimplemented: depends on context. As an actual parameter where
4990 -- formal type is anonymous, use
4991 -- Scope_Depth (Current_Scope) + 1.
4992 -- For other cases, see 3.10.2(14/3) and following. ???
4994 null;
4996 when N_Type_Conversion =>
4997 if not Is_Local_Anonymous_Access (Etype (Expr)) then
4999 -- Handle type conversions introduced for a rename of an
5000 -- Ada 2012 stand-alone object of an anonymous access type.
5002 return Dynamic_Accessibility_Level (Expression (Expr));
5003 end if;
5005 when others =>
5006 null;
5007 end case;
5009 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
5010 end Dynamic_Accessibility_Level;
5012 -----------------------------------
5013 -- Effective_Extra_Accessibility --
5014 -----------------------------------
5016 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
5017 begin
5018 if Present (Renamed_Object (Id))
5019 and then Is_Entity_Name (Renamed_Object (Id))
5020 then
5021 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
5022 else
5023 return Extra_Accessibility (Id);
5024 end if;
5025 end Effective_Extra_Accessibility;
5027 -----------------------------
5028 -- Effective_Reads_Enabled --
5029 -----------------------------
5031 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
5032 begin
5033 return Has_Enabled_Property (Id, Name_Effective_Reads);
5034 end Effective_Reads_Enabled;
5036 ------------------------------
5037 -- Effective_Writes_Enabled --
5038 ------------------------------
5040 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
5041 begin
5042 return Has_Enabled_Property (Id, Name_Effective_Writes);
5043 end Effective_Writes_Enabled;
5045 ------------------------------
5046 -- Enclosing_Comp_Unit_Node --
5047 ------------------------------
5049 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
5050 Current_Node : Node_Id;
5052 begin
5053 Current_Node := N;
5054 while Present (Current_Node)
5055 and then Nkind (Current_Node) /= N_Compilation_Unit
5056 loop
5057 Current_Node := Parent (Current_Node);
5058 end loop;
5060 if Nkind (Current_Node) /= N_Compilation_Unit then
5061 return Empty;
5062 else
5063 return Current_Node;
5064 end if;
5065 end Enclosing_Comp_Unit_Node;
5067 --------------------------
5068 -- Enclosing_CPP_Parent --
5069 --------------------------
5071 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
5072 Parent_Typ : Entity_Id := Typ;
5074 begin
5075 while not Is_CPP_Class (Parent_Typ)
5076 and then Etype (Parent_Typ) /= Parent_Typ
5077 loop
5078 Parent_Typ := Etype (Parent_Typ);
5080 if Is_Private_Type (Parent_Typ) then
5081 Parent_Typ := Full_View (Base_Type (Parent_Typ));
5082 end if;
5083 end loop;
5085 pragma Assert (Is_CPP_Class (Parent_Typ));
5086 return Parent_Typ;
5087 end Enclosing_CPP_Parent;
5089 ----------------------------
5090 -- Enclosing_Generic_Body --
5091 ----------------------------
5093 function Enclosing_Generic_Body
5094 (N : Node_Id) return Node_Id
5096 P : Node_Id;
5097 Decl : Node_Id;
5098 Spec : Node_Id;
5100 begin
5101 P := Parent (N);
5102 while Present (P) loop
5103 if Nkind (P) = N_Package_Body
5104 or else Nkind (P) = N_Subprogram_Body
5105 then
5106 Spec := Corresponding_Spec (P);
5108 if Present (Spec) then
5109 Decl := Unit_Declaration_Node (Spec);
5111 if Nkind (Decl) = N_Generic_Package_Declaration
5112 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5113 then
5114 return P;
5115 end if;
5116 end if;
5117 end if;
5119 P := Parent (P);
5120 end loop;
5122 return Empty;
5123 end Enclosing_Generic_Body;
5125 ----------------------------
5126 -- Enclosing_Generic_Unit --
5127 ----------------------------
5129 function Enclosing_Generic_Unit
5130 (N : Node_Id) return Node_Id
5132 P : Node_Id;
5133 Decl : Node_Id;
5134 Spec : Node_Id;
5136 begin
5137 P := Parent (N);
5138 while Present (P) loop
5139 if Nkind (P) = N_Generic_Package_Declaration
5140 or else Nkind (P) = N_Generic_Subprogram_Declaration
5141 then
5142 return P;
5144 elsif Nkind (P) = N_Package_Body
5145 or else Nkind (P) = N_Subprogram_Body
5146 then
5147 Spec := Corresponding_Spec (P);
5149 if Present (Spec) then
5150 Decl := Unit_Declaration_Node (Spec);
5152 if Nkind (Decl) = N_Generic_Package_Declaration
5153 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
5154 then
5155 return Decl;
5156 end if;
5157 end if;
5158 end if;
5160 P := Parent (P);
5161 end loop;
5163 return Empty;
5164 end Enclosing_Generic_Unit;
5166 -------------------------------
5167 -- Enclosing_Lib_Unit_Entity --
5168 -------------------------------
5170 function Enclosing_Lib_Unit_Entity
5171 (E : Entity_Id := Current_Scope) return Entity_Id
5173 Unit_Entity : Entity_Id;
5175 begin
5176 -- Look for enclosing library unit entity by following scope links.
5177 -- Equivalent to, but faster than indexing through the scope stack.
5179 Unit_Entity := E;
5180 while (Present (Scope (Unit_Entity))
5181 and then Scope (Unit_Entity) /= Standard_Standard)
5182 and not Is_Child_Unit (Unit_Entity)
5183 loop
5184 Unit_Entity := Scope (Unit_Entity);
5185 end loop;
5187 return Unit_Entity;
5188 end Enclosing_Lib_Unit_Entity;
5190 -----------------------
5191 -- Enclosing_Package --
5192 -----------------------
5194 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5195 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5197 begin
5198 if Dynamic_Scope = Standard_Standard then
5199 return Standard_Standard;
5201 elsif Dynamic_Scope = Empty then
5202 return Empty;
5204 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5205 E_Generic_Package)
5206 then
5207 return Dynamic_Scope;
5209 else
5210 return Enclosing_Package (Dynamic_Scope);
5211 end if;
5212 end Enclosing_Package;
5214 --------------------------
5215 -- Enclosing_Subprogram --
5216 --------------------------
5218 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5219 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5221 begin
5222 if Dynamic_Scope = Standard_Standard then
5223 return Empty;
5225 elsif Dynamic_Scope = Empty then
5226 return Empty;
5228 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5229 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5231 elsif Ekind (Dynamic_Scope) = E_Block
5232 or else Ekind (Dynamic_Scope) = E_Return_Statement
5233 then
5234 return Enclosing_Subprogram (Dynamic_Scope);
5236 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5237 return Get_Task_Body_Procedure (Dynamic_Scope);
5239 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5240 and then Present (Full_View (Dynamic_Scope))
5241 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5242 then
5243 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5245 -- No body is generated if the protected operation is eliminated
5247 elsif Convention (Dynamic_Scope) = Convention_Protected
5248 and then not Is_Eliminated (Dynamic_Scope)
5249 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5250 then
5251 return Protected_Body_Subprogram (Dynamic_Scope);
5253 else
5254 return Dynamic_Scope;
5255 end if;
5256 end Enclosing_Subprogram;
5258 ------------------------
5259 -- Ensure_Freeze_Node --
5260 ------------------------
5262 procedure Ensure_Freeze_Node (E : Entity_Id) is
5263 FN : Node_Id;
5264 begin
5265 if No (Freeze_Node (E)) then
5266 FN := Make_Freeze_Entity (Sloc (E));
5267 Set_Has_Delayed_Freeze (E);
5268 Set_Freeze_Node (E, FN);
5269 Set_Access_Types_To_Process (FN, No_Elist);
5270 Set_TSS_Elist (FN, No_Elist);
5271 Set_Entity (FN, E);
5272 end if;
5273 end Ensure_Freeze_Node;
5275 ----------------
5276 -- Enter_Name --
5277 ----------------
5279 procedure Enter_Name (Def_Id : Entity_Id) is
5280 C : constant Entity_Id := Current_Entity (Def_Id);
5281 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5282 S : constant Entity_Id := Current_Scope;
5284 begin
5285 Generate_Definition (Def_Id);
5287 -- Add new name to current scope declarations. Check for duplicate
5288 -- declaration, which may or may not be a genuine error.
5290 if Present (E) then
5292 -- Case of previous entity entered because of a missing declaration
5293 -- or else a bad subtype indication. Best is to use the new entity,
5294 -- and make the previous one invisible.
5296 if Etype (E) = Any_Type then
5297 Set_Is_Immediately_Visible (E, False);
5299 -- Case of renaming declaration constructed for package instances.
5300 -- if there is an explicit declaration with the same identifier,
5301 -- the renaming is not immediately visible any longer, but remains
5302 -- visible through selected component notation.
5304 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5305 and then not Comes_From_Source (E)
5306 then
5307 Set_Is_Immediately_Visible (E, False);
5309 -- The new entity may be the package renaming, which has the same
5310 -- same name as a generic formal which has been seen already.
5312 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5313 and then not Comes_From_Source (Def_Id)
5314 then
5315 Set_Is_Immediately_Visible (E, False);
5317 -- For a fat pointer corresponding to a remote access to subprogram,
5318 -- we use the same identifier as the RAS type, so that the proper
5319 -- name appears in the stub. This type is only retrieved through
5320 -- the RAS type and never by visibility, and is not added to the
5321 -- visibility list (see below).
5323 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5324 and then Ekind (Def_Id) = E_Record_Type
5325 and then Present (Corresponding_Remote_Type (Def_Id))
5326 then
5327 null;
5329 -- Case of an implicit operation or derived literal. The new entity
5330 -- hides the implicit one, which is removed from all visibility,
5331 -- i.e. the entity list of its scope, and homonym chain of its name.
5333 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5334 or else Is_Internal (E)
5335 then
5336 declare
5337 Prev : Entity_Id;
5338 Prev_Vis : Entity_Id;
5339 Decl : constant Node_Id := Parent (E);
5341 begin
5342 -- If E is an implicit declaration, it cannot be the first
5343 -- entity in the scope.
5345 Prev := First_Entity (Current_Scope);
5346 while Present (Prev) and then Next_Entity (Prev) /= E loop
5347 Next_Entity (Prev);
5348 end loop;
5350 if No (Prev) then
5352 -- If E is not on the entity chain of the current scope,
5353 -- it is an implicit declaration in the generic formal
5354 -- part of a generic subprogram. When analyzing the body,
5355 -- the generic formals are visible but not on the entity
5356 -- chain of the subprogram. The new entity will become
5357 -- the visible one in the body.
5359 pragma Assert
5360 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5361 null;
5363 else
5364 Set_Next_Entity (Prev, Next_Entity (E));
5366 if No (Next_Entity (Prev)) then
5367 Set_Last_Entity (Current_Scope, Prev);
5368 end if;
5370 if E = Current_Entity (E) then
5371 Prev_Vis := Empty;
5373 else
5374 Prev_Vis := Current_Entity (E);
5375 while Homonym (Prev_Vis) /= E loop
5376 Prev_Vis := Homonym (Prev_Vis);
5377 end loop;
5378 end if;
5380 if Present (Prev_Vis) then
5382 -- Skip E in the visibility chain
5384 Set_Homonym (Prev_Vis, Homonym (E));
5386 else
5387 Set_Name_Entity_Id (Chars (E), Homonym (E));
5388 end if;
5389 end if;
5390 end;
5392 -- This section of code could use a comment ???
5394 elsif Present (Etype (E))
5395 and then Is_Concurrent_Type (Etype (E))
5396 and then E = Def_Id
5397 then
5398 return;
5400 -- If the homograph is a protected component renaming, it should not
5401 -- be hiding the current entity. Such renamings are treated as weak
5402 -- declarations.
5404 elsif Is_Prival (E) then
5405 Set_Is_Immediately_Visible (E, False);
5407 -- In this case the current entity is a protected component renaming.
5408 -- Perform minimal decoration by setting the scope and return since
5409 -- the prival should not be hiding other visible entities.
5411 elsif Is_Prival (Def_Id) then
5412 Set_Scope (Def_Id, Current_Scope);
5413 return;
5415 -- Analogous to privals, the discriminal generated for an entry index
5416 -- parameter acts as a weak declaration. Perform minimal decoration
5417 -- to avoid bogus errors.
5419 elsif Is_Discriminal (Def_Id)
5420 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
5421 then
5422 Set_Scope (Def_Id, Current_Scope);
5423 return;
5425 -- In the body or private part of an instance, a type extension may
5426 -- introduce a component with the same name as that of an actual. The
5427 -- legality rule is not enforced, but the semantics of the full type
5428 -- with two components of same name are not clear at this point???
5430 elsif In_Instance_Not_Visible then
5431 null;
5433 -- When compiling a package body, some child units may have become
5434 -- visible. They cannot conflict with local entities that hide them.
5436 elsif Is_Child_Unit (E)
5437 and then In_Open_Scopes (Scope (E))
5438 and then not Is_Immediately_Visible (E)
5439 then
5440 null;
5442 -- Conversely, with front-end inlining we may compile the parent body
5443 -- first, and a child unit subsequently. The context is now the
5444 -- parent spec, and body entities are not visible.
5446 elsif Is_Child_Unit (Def_Id)
5447 and then Is_Package_Body_Entity (E)
5448 and then not In_Package_Body (Current_Scope)
5449 then
5450 null;
5452 -- Case of genuine duplicate declaration
5454 else
5455 Error_Msg_Sloc := Sloc (E);
5457 -- If the previous declaration is an incomplete type declaration
5458 -- this may be an attempt to complete it with a private type. The
5459 -- following avoids confusing cascaded errors.
5461 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
5462 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
5463 then
5464 Error_Msg_N
5465 ("incomplete type cannot be completed with a private " &
5466 "declaration", Parent (Def_Id));
5467 Set_Is_Immediately_Visible (E, False);
5468 Set_Full_View (E, Def_Id);
5470 -- An inherited component of a record conflicts with a new
5471 -- discriminant. The discriminant is inserted first in the scope,
5472 -- but the error should be posted on it, not on the component.
5474 elsif Ekind (E) = E_Discriminant
5475 and then Present (Scope (Def_Id))
5476 and then Scope (Def_Id) /= Current_Scope
5477 then
5478 Error_Msg_Sloc := Sloc (Def_Id);
5479 Error_Msg_N ("& conflicts with declaration#", E);
5480 return;
5482 -- If the name of the unit appears in its own context clause, a
5483 -- dummy package with the name has already been created, and the
5484 -- error emitted. Try to continue quietly.
5486 elsif Error_Posted (E)
5487 and then Sloc (E) = No_Location
5488 and then Nkind (Parent (E)) = N_Package_Specification
5489 and then Current_Scope = Standard_Standard
5490 then
5491 Set_Scope (Def_Id, Current_Scope);
5492 return;
5494 else
5495 Error_Msg_N ("& conflicts with declaration#", Def_Id);
5497 -- Avoid cascaded messages with duplicate components in
5498 -- derived types.
5500 if Ekind_In (E, E_Component, E_Discriminant) then
5501 return;
5502 end if;
5503 end if;
5505 if Nkind (Parent (Parent (Def_Id))) =
5506 N_Generic_Subprogram_Declaration
5507 and then Def_Id =
5508 Defining_Entity (Specification (Parent (Parent (Def_Id))))
5509 then
5510 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
5511 end if;
5513 -- If entity is in standard, then we are in trouble, because it
5514 -- means that we have a library package with a duplicated name.
5515 -- That's hard to recover from, so abort.
5517 if S = Standard_Standard then
5518 raise Unrecoverable_Error;
5520 -- Otherwise we continue with the declaration. Having two
5521 -- identical declarations should not cause us too much trouble.
5523 else
5524 null;
5525 end if;
5526 end if;
5527 end if;
5529 -- If we fall through, declaration is OK, at least OK enough to continue
5531 -- If Def_Id is a discriminant or a record component we are in the midst
5532 -- of inheriting components in a derived record definition. Preserve
5533 -- their Ekind and Etype.
5535 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
5536 null;
5538 -- If a type is already set, leave it alone (happens when a type
5539 -- declaration is reanalyzed following a call to the optimizer).
5541 elsif Present (Etype (Def_Id)) then
5542 null;
5544 -- Otherwise, the kind E_Void insures that premature uses of the entity
5545 -- will be detected. Any_Type insures that no cascaded errors will occur
5547 else
5548 Set_Ekind (Def_Id, E_Void);
5549 Set_Etype (Def_Id, Any_Type);
5550 end if;
5552 -- Inherited discriminants and components in derived record types are
5553 -- immediately visible. Itypes are not.
5555 -- Unless the Itype is for a record type with a corresponding remote
5556 -- type (what is that about, it was not commented ???)
5558 if Ekind_In (Def_Id, E_Discriminant, E_Component)
5559 or else
5560 ((not Is_Record_Type (Def_Id)
5561 or else No (Corresponding_Remote_Type (Def_Id)))
5562 and then not Is_Itype (Def_Id))
5563 then
5564 Set_Is_Immediately_Visible (Def_Id);
5565 Set_Current_Entity (Def_Id);
5566 end if;
5568 Set_Homonym (Def_Id, C);
5569 Append_Entity (Def_Id, S);
5570 Set_Public_Status (Def_Id);
5572 -- Declaring a homonym is not allowed in SPARK ...
5574 if Present (C) and then Restriction_Check_Required (SPARK_05) then
5575 declare
5576 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
5577 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
5578 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
5580 begin
5581 -- ... unless the new declaration is in a subprogram, and the
5582 -- visible declaration is a variable declaration or a parameter
5583 -- specification outside that subprogram.
5585 if Present (Enclosing_Subp)
5586 and then Nkind_In (Parent (C), N_Object_Declaration,
5587 N_Parameter_Specification)
5588 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
5589 then
5590 null;
5592 -- ... or the new declaration is in a package, and the visible
5593 -- declaration occurs outside that package.
5595 elsif Present (Enclosing_Pack)
5596 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
5597 then
5598 null;
5600 -- ... or the new declaration is a component declaration in a
5601 -- record type definition.
5603 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
5604 null;
5606 -- Don't issue error for non-source entities
5608 elsif Comes_From_Source (Def_Id)
5609 and then Comes_From_Source (C)
5610 then
5611 Error_Msg_Sloc := Sloc (C);
5612 Check_SPARK_05_Restriction
5613 ("redeclaration of identifier &#", Def_Id);
5614 end if;
5615 end;
5616 end if;
5618 -- Warn if new entity hides an old one
5620 if Warn_On_Hiding and then Present (C)
5622 -- Don't warn for record components since they always have a well
5623 -- defined scope which does not confuse other uses. Note that in
5624 -- some cases, Ekind has not been set yet.
5626 and then Ekind (C) /= E_Component
5627 and then Ekind (C) /= E_Discriminant
5628 and then Nkind (Parent (C)) /= N_Component_Declaration
5629 and then Ekind (Def_Id) /= E_Component
5630 and then Ekind (Def_Id) /= E_Discriminant
5631 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
5633 -- Don't warn for one character variables. It is too common to use
5634 -- such variables as locals and will just cause too many false hits.
5636 and then Length_Of_Name (Chars (C)) /= 1
5638 -- Don't warn for non-source entities
5640 and then Comes_From_Source (C)
5641 and then Comes_From_Source (Def_Id)
5643 -- Don't warn unless entity in question is in extended main source
5645 and then In_Extended_Main_Source_Unit (Def_Id)
5647 -- Finally, the hidden entity must be either immediately visible or
5648 -- use visible (i.e. from a used package).
5650 and then
5651 (Is_Immediately_Visible (C)
5652 or else
5653 Is_Potentially_Use_Visible (C))
5654 then
5655 Error_Msg_Sloc := Sloc (C);
5656 Error_Msg_N ("declaration hides &#?h?", Def_Id);
5657 end if;
5658 end Enter_Name;
5660 ---------------
5661 -- Entity_Of --
5662 ---------------
5664 function Entity_Of (N : Node_Id) return Entity_Id is
5665 Id : Entity_Id;
5667 begin
5668 Id := Empty;
5670 if Is_Entity_Name (N) then
5671 Id := Entity (N);
5673 -- Follow a possible chain of renamings to reach the root renamed
5674 -- object.
5676 while Present (Id) and then Present (Renamed_Object (Id)) loop
5677 if Is_Entity_Name (Renamed_Object (Id)) then
5678 Id := Entity (Renamed_Object (Id));
5679 else
5680 Id := Empty;
5681 exit;
5682 end if;
5683 end loop;
5684 end if;
5686 return Id;
5687 end Entity_Of;
5689 --------------------------
5690 -- Explain_Limited_Type --
5691 --------------------------
5693 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
5694 C : Entity_Id;
5696 begin
5697 -- For array, component type must be limited
5699 if Is_Array_Type (T) then
5700 Error_Msg_Node_2 := T;
5701 Error_Msg_NE
5702 ("\component type& of type& is limited", N, Component_Type (T));
5703 Explain_Limited_Type (Component_Type (T), N);
5705 elsif Is_Record_Type (T) then
5707 -- No need for extra messages if explicit limited record
5709 if Is_Limited_Record (Base_Type (T)) then
5710 return;
5711 end if;
5713 -- Otherwise find a limited component. Check only components that
5714 -- come from source, or inherited components that appear in the
5715 -- source of the ancestor.
5717 C := First_Component (T);
5718 while Present (C) loop
5719 if Is_Limited_Type (Etype (C))
5720 and then
5721 (Comes_From_Source (C)
5722 or else
5723 (Present (Original_Record_Component (C))
5724 and then
5725 Comes_From_Source (Original_Record_Component (C))))
5726 then
5727 Error_Msg_Node_2 := T;
5728 Error_Msg_NE ("\component& of type& has limited type", N, C);
5729 Explain_Limited_Type (Etype (C), N);
5730 return;
5731 end if;
5733 Next_Component (C);
5734 end loop;
5736 -- The type may be declared explicitly limited, even if no component
5737 -- of it is limited, in which case we fall out of the loop.
5738 return;
5739 end if;
5740 end Explain_Limited_Type;
5742 -----------------
5743 -- Find_Actual --
5744 -----------------
5746 procedure Find_Actual
5747 (N : Node_Id;
5748 Formal : out Entity_Id;
5749 Call : out Node_Id)
5751 Parnt : constant Node_Id := Parent (N);
5752 Actual : Node_Id;
5754 begin
5755 if Nkind_In (Parnt, N_Indexed_Component, N_Selected_Component)
5756 and then N = Prefix (Parnt)
5757 then
5758 Find_Actual (Parnt, Formal, Call);
5759 return;
5761 elsif Nkind (Parnt) = N_Parameter_Association
5762 and then N = Explicit_Actual_Parameter (Parnt)
5763 then
5764 Call := Parent (Parnt);
5766 elsif Nkind (Parnt) in N_Subprogram_Call then
5767 Call := Parnt;
5769 else
5770 Formal := Empty;
5771 Call := Empty;
5772 return;
5773 end if;
5775 -- If we have a call to a subprogram look for the parameter. Note that
5776 -- we exclude overloaded calls, since we don't know enough to be sure
5777 -- of giving the right answer in this case.
5779 if Nkind_In (Call, N_Function_Call, N_Procedure_Call_Statement)
5780 and then Is_Entity_Name (Name (Call))
5781 and then Present (Entity (Name (Call)))
5782 and then Is_Overloadable (Entity (Name (Call)))
5783 and then not Is_Overloaded (Name (Call))
5784 then
5785 -- Fall here if we are definitely a parameter
5787 Actual := First_Actual (Call);
5788 Formal := First_Formal (Entity (Name (Call)));
5789 while Present (Formal) and then Present (Actual) loop
5790 if Actual = N then
5791 return;
5793 -- An actual that is the prefix in a prefixed call may have
5794 -- been rewritten in the call, after the deferred reference
5795 -- was collected. Check if sloc and kinds and names match.
5797 elsif Sloc (Actual) = Sloc (N)
5798 and then Nkind (Actual) = N_Identifier
5799 and then Nkind (Actual) = Nkind (N)
5800 and then Chars (Actual) = Chars (N)
5801 then
5802 return;
5804 else
5805 Actual := Next_Actual (Actual);
5806 Formal := Next_Formal (Formal);
5807 end if;
5808 end loop;
5809 end if;
5811 -- Fall through here if we did not find matching actual
5813 Formal := Empty;
5814 Call := Empty;
5815 end Find_Actual;
5817 ---------------------------
5818 -- Find_Body_Discriminal --
5819 ---------------------------
5821 function Find_Body_Discriminal
5822 (Spec_Discriminant : Entity_Id) return Entity_Id
5824 Tsk : Entity_Id;
5825 Disc : Entity_Id;
5827 begin
5828 -- If expansion is suppressed, then the scope can be the concurrent type
5829 -- itself rather than a corresponding concurrent record type.
5831 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
5832 Tsk := Scope (Spec_Discriminant);
5834 else
5835 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
5837 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
5838 end if;
5840 -- Find discriminant of original concurrent type, and use its current
5841 -- discriminal, which is the renaming within the task/protected body.
5843 Disc := First_Discriminant (Tsk);
5844 while Present (Disc) loop
5845 if Chars (Disc) = Chars (Spec_Discriminant) then
5846 return Discriminal (Disc);
5847 end if;
5849 Next_Discriminant (Disc);
5850 end loop;
5852 -- That loop should always succeed in finding a matching entry and
5853 -- returning. Fatal error if not.
5855 raise Program_Error;
5856 end Find_Body_Discriminal;
5858 -------------------------------------
5859 -- Find_Corresponding_Discriminant --
5860 -------------------------------------
5862 function Find_Corresponding_Discriminant
5863 (Id : Node_Id;
5864 Typ : Entity_Id) return Entity_Id
5866 Par_Disc : Entity_Id;
5867 Old_Disc : Entity_Id;
5868 New_Disc : Entity_Id;
5870 begin
5871 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
5873 -- The original type may currently be private, and the discriminant
5874 -- only appear on its full view.
5876 if Is_Private_Type (Scope (Par_Disc))
5877 and then not Has_Discriminants (Scope (Par_Disc))
5878 and then Present (Full_View (Scope (Par_Disc)))
5879 then
5880 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
5881 else
5882 Old_Disc := First_Discriminant (Scope (Par_Disc));
5883 end if;
5885 if Is_Class_Wide_Type (Typ) then
5886 New_Disc := First_Discriminant (Root_Type (Typ));
5887 else
5888 New_Disc := First_Discriminant (Typ);
5889 end if;
5891 while Present (Old_Disc) and then Present (New_Disc) loop
5892 if Old_Disc = Par_Disc then
5893 return New_Disc;
5894 end if;
5896 Next_Discriminant (Old_Disc);
5897 Next_Discriminant (New_Disc);
5898 end loop;
5900 -- Should always find it
5902 raise Program_Error;
5903 end Find_Corresponding_Discriminant;
5905 ----------------------------------
5906 -- Find_Enclosing_Iterator_Loop --
5907 ----------------------------------
5909 function Find_Enclosing_Iterator_Loop (Id : Entity_Id) return Entity_Id is
5910 Constr : Node_Id;
5911 S : Entity_Id;
5913 begin
5914 -- Traverse the scope chain looking for an iterator loop. Such loops are
5915 -- usually transformed into blocks, hence the use of Original_Node.
5917 S := Id;
5918 while Present (S) and then S /= Standard_Standard loop
5919 if Ekind (S) = E_Loop
5920 and then Nkind (Parent (S)) = N_Implicit_Label_Declaration
5921 then
5922 Constr := Original_Node (Label_Construct (Parent (S)));
5924 if Nkind (Constr) = N_Loop_Statement
5925 and then Present (Iteration_Scheme (Constr))
5926 and then Nkind (Iterator_Specification
5927 (Iteration_Scheme (Constr))) =
5928 N_Iterator_Specification
5929 then
5930 return S;
5931 end if;
5932 end if;
5934 S := Scope (S);
5935 end loop;
5937 return Empty;
5938 end Find_Enclosing_Iterator_Loop;
5940 ------------------------------------
5941 -- Find_Loop_In_Conditional_Block --
5942 ------------------------------------
5944 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
5945 Stmt : Node_Id;
5947 begin
5948 Stmt := N;
5950 if Nkind (Stmt) = N_If_Statement then
5951 Stmt := First (Then_Statements (Stmt));
5952 end if;
5954 pragma Assert (Nkind (Stmt) = N_Block_Statement);
5956 -- Inspect the statements of the conditional block. In general the loop
5957 -- should be the first statement in the statement sequence of the block,
5958 -- but the finalization machinery may have introduced extra object
5959 -- declarations.
5961 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
5962 while Present (Stmt) loop
5963 if Nkind (Stmt) = N_Loop_Statement then
5964 return Stmt;
5965 end if;
5967 Next (Stmt);
5968 end loop;
5970 -- The expansion of attribute 'Loop_Entry produced a malformed block
5972 raise Program_Error;
5973 end Find_Loop_In_Conditional_Block;
5975 --------------------------
5976 -- Find_Overlaid_Entity --
5977 --------------------------
5979 procedure Find_Overlaid_Entity
5980 (N : Node_Id;
5981 Ent : out Entity_Id;
5982 Off : out Boolean)
5984 Expr : Node_Id;
5986 begin
5987 -- We are looking for one of the two following forms:
5989 -- for X'Address use Y'Address
5991 -- or
5993 -- Const : constant Address := expr;
5994 -- ...
5995 -- for X'Address use Const;
5997 -- In the second case, the expr is either Y'Address, or recursively a
5998 -- constant that eventually references Y'Address.
6000 Ent := Empty;
6001 Off := False;
6003 if Nkind (N) = N_Attribute_Definition_Clause
6004 and then Chars (N) = Name_Address
6005 then
6006 Expr := Expression (N);
6008 -- This loop checks the form of the expression for Y'Address,
6009 -- using recursion to deal with intermediate constants.
6011 loop
6012 -- Check for Y'Address
6014 if Nkind (Expr) = N_Attribute_Reference
6015 and then Attribute_Name (Expr) = Name_Address
6016 then
6017 Expr := Prefix (Expr);
6018 exit;
6020 -- Check for Const where Const is a constant entity
6022 elsif Is_Entity_Name (Expr)
6023 and then Ekind (Entity (Expr)) = E_Constant
6024 then
6025 Expr := Constant_Value (Entity (Expr));
6027 -- Anything else does not need checking
6029 else
6030 return;
6031 end if;
6032 end loop;
6034 -- This loop checks the form of the prefix for an entity, using
6035 -- recursion to deal with intermediate components.
6037 loop
6038 -- Check for Y where Y is an entity
6040 if Is_Entity_Name (Expr) then
6041 Ent := Entity (Expr);
6042 return;
6044 -- Check for components
6046 elsif
6047 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
6048 then
6049 Expr := Prefix (Expr);
6050 Off := True;
6052 -- Anything else does not need checking
6054 else
6055 return;
6056 end if;
6057 end loop;
6058 end if;
6059 end Find_Overlaid_Entity;
6061 -------------------------
6062 -- Find_Parameter_Type --
6063 -------------------------
6065 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
6066 begin
6067 if Nkind (Param) /= N_Parameter_Specification then
6068 return Empty;
6070 -- For an access parameter, obtain the type from the formal entity
6071 -- itself, because access to subprogram nodes do not carry a type.
6072 -- Shouldn't we always use the formal entity ???
6074 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
6075 return Etype (Defining_Identifier (Param));
6077 else
6078 return Etype (Parameter_Type (Param));
6079 end if;
6080 end Find_Parameter_Type;
6082 -----------------------------------
6083 -- Find_Placement_In_State_Space --
6084 -----------------------------------
6086 procedure Find_Placement_In_State_Space
6087 (Item_Id : Entity_Id;
6088 Placement : out State_Space_Kind;
6089 Pack_Id : out Entity_Id)
6091 Context : Entity_Id;
6093 begin
6094 -- Assume that the item does not appear in the state space of a package
6096 Placement := Not_In_Package;
6097 Pack_Id := Empty;
6099 -- Climb the scope stack and examine the enclosing context
6101 Context := Scope (Item_Id);
6102 while Present (Context) and then Context /= Standard_Standard loop
6103 if Ekind (Context) = E_Package then
6104 Pack_Id := Context;
6106 -- A package body is a cut off point for the traversal as the item
6107 -- cannot be visible to the outside from this point on. Note that
6108 -- this test must be done first as a body is also classified as a
6109 -- private part.
6111 if In_Package_Body (Context) then
6112 Placement := Body_State_Space;
6113 return;
6115 -- The private part of a package is a cut off point for the
6116 -- traversal as the item cannot be visible to the outside from
6117 -- this point on.
6119 elsif In_Private_Part (Context) then
6120 Placement := Private_State_Space;
6121 return;
6123 -- When the item appears in the visible state space of a package,
6124 -- continue to climb the scope stack as this may not be the final
6125 -- state space.
6127 else
6128 Placement := Visible_State_Space;
6130 -- The visible state space of a child unit acts as the proper
6131 -- placement of an item.
6133 if Is_Child_Unit (Context) then
6134 return;
6135 end if;
6136 end if;
6138 -- The item or its enclosing package appear in a construct that has
6139 -- no state space.
6141 else
6142 Placement := Not_In_Package;
6143 return;
6144 end if;
6146 Context := Scope (Context);
6147 end loop;
6148 end Find_Placement_In_State_Space;
6150 ------------------------
6151 -- Find_Specific_Type --
6152 ------------------------
6154 function Find_Specific_Type (CW : Entity_Id) return Entity_Id is
6155 Typ : Entity_Id := Root_Type (CW);
6157 begin
6158 if Ekind (Typ) = E_Incomplete_Type then
6159 if From_Limited_With (Typ) then
6160 Typ := Non_Limited_View (Typ);
6161 else
6162 Typ := Full_View (Typ);
6163 end if;
6164 end if;
6166 if Is_Private_Type (Typ)
6167 and then not Is_Tagged_Type (Typ)
6168 and then Present (Full_View (Typ))
6169 then
6170 return Full_View (Typ);
6171 else
6172 return Typ;
6173 end if;
6174 end Find_Specific_Type;
6176 -----------------------------
6177 -- Find_Static_Alternative --
6178 -----------------------------
6180 function Find_Static_Alternative (N : Node_Id) return Node_Id is
6181 Expr : constant Node_Id := Expression (N);
6182 Val : constant Uint := Expr_Value (Expr);
6183 Alt : Node_Id;
6184 Choice : Node_Id;
6186 begin
6187 Alt := First (Alternatives (N));
6189 Search : loop
6190 if Nkind (Alt) /= N_Pragma then
6191 Choice := First (Discrete_Choices (Alt));
6192 while Present (Choice) loop
6194 -- Others choice, always matches
6196 if Nkind (Choice) = N_Others_Choice then
6197 exit Search;
6199 -- Range, check if value is in the range
6201 elsif Nkind (Choice) = N_Range then
6202 exit Search when
6203 Val >= Expr_Value (Low_Bound (Choice))
6204 and then
6205 Val <= Expr_Value (High_Bound (Choice));
6207 -- Choice is a subtype name. Note that we know it must
6208 -- be a static subtype, since otherwise it would have
6209 -- been diagnosed as illegal.
6211 elsif Is_Entity_Name (Choice) and then Is_Type (Entity (Choice))
6212 then
6213 exit Search when Is_In_Range (Expr, Etype (Choice),
6214 Assume_Valid => False);
6216 -- Choice is a subtype indication
6218 elsif Nkind (Choice) = N_Subtype_Indication then
6219 declare
6220 C : constant Node_Id := Constraint (Choice);
6221 R : constant Node_Id := Range_Expression (C);
6223 begin
6224 exit Search when
6225 Val >= Expr_Value (Low_Bound (R))
6226 and then
6227 Val <= Expr_Value (High_Bound (R));
6228 end;
6230 -- Choice is a simple expression
6232 else
6233 exit Search when Val = Expr_Value (Choice);
6234 end if;
6236 Next (Choice);
6237 end loop;
6238 end if;
6240 Next (Alt);
6241 pragma Assert (Present (Alt));
6242 end loop Search;
6244 -- The above loop *must* terminate by finding a match, since
6245 -- we know the case statement is valid, and the value of the
6246 -- expression is known at compile time. When we fall out of
6247 -- the loop, Alt points to the alternative that we know will
6248 -- be selected at run time.
6250 return Alt;
6251 end Find_Static_Alternative;
6253 ------------------
6254 -- First_Actual --
6255 ------------------
6257 function First_Actual (Node : Node_Id) return Node_Id is
6258 N : Node_Id;
6260 begin
6261 if No (Parameter_Associations (Node)) then
6262 return Empty;
6263 end if;
6265 N := First (Parameter_Associations (Node));
6267 if Nkind (N) = N_Parameter_Association then
6268 return First_Named_Actual (Node);
6269 else
6270 return N;
6271 end if;
6272 end First_Actual;
6274 -----------------------
6275 -- Gather_Components --
6276 -----------------------
6278 procedure Gather_Components
6279 (Typ : Entity_Id;
6280 Comp_List : Node_Id;
6281 Governed_By : List_Id;
6282 Into : Elist_Id;
6283 Report_Errors : out Boolean)
6285 Assoc : Node_Id;
6286 Variant : Node_Id;
6287 Discrete_Choice : Node_Id;
6288 Comp_Item : Node_Id;
6290 Discrim : Entity_Id;
6291 Discrim_Name : Node_Id;
6292 Discrim_Value : Node_Id;
6294 begin
6295 Report_Errors := False;
6297 if No (Comp_List) or else Null_Present (Comp_List) then
6298 return;
6300 elsif Present (Component_Items (Comp_List)) then
6301 Comp_Item := First (Component_Items (Comp_List));
6303 else
6304 Comp_Item := Empty;
6305 end if;
6307 while Present (Comp_Item) loop
6309 -- Skip the tag of a tagged record, the interface tags, as well
6310 -- as all items that are not user components (anonymous types,
6311 -- rep clauses, Parent field, controller field).
6313 if Nkind (Comp_Item) = N_Component_Declaration then
6314 declare
6315 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
6316 begin
6317 if not Is_Tag (Comp) and then Chars (Comp) /= Name_uParent then
6318 Append_Elmt (Comp, Into);
6319 end if;
6320 end;
6321 end if;
6323 Next (Comp_Item);
6324 end loop;
6326 if No (Variant_Part (Comp_List)) then
6327 return;
6328 else
6329 Discrim_Name := Name (Variant_Part (Comp_List));
6330 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
6331 end if;
6333 -- Look for the discriminant that governs this variant part.
6334 -- The discriminant *must* be in the Governed_By List
6336 Assoc := First (Governed_By);
6337 Find_Constraint : loop
6338 Discrim := First (Choices (Assoc));
6339 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
6340 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
6341 and then
6342 Chars (Corresponding_Discriminant (Entity (Discrim))) =
6343 Chars (Discrim_Name))
6344 or else Chars (Original_Record_Component (Entity (Discrim)))
6345 = Chars (Discrim_Name);
6347 if No (Next (Assoc)) then
6348 if not Is_Constrained (Typ)
6349 and then Is_Derived_Type (Typ)
6350 and then Present (Stored_Constraint (Typ))
6351 then
6352 -- If the type is a tagged type with inherited discriminants,
6353 -- use the stored constraint on the parent in order to find
6354 -- the values of discriminants that are otherwise hidden by an
6355 -- explicit constraint. Renamed discriminants are handled in
6356 -- the code above.
6358 -- If several parent discriminants are renamed by a single
6359 -- discriminant of the derived type, the call to obtain the
6360 -- Corresponding_Discriminant field only retrieves the last
6361 -- of them. We recover the constraint on the others from the
6362 -- Stored_Constraint as well.
6364 declare
6365 D : Entity_Id;
6366 C : Elmt_Id;
6368 begin
6369 D := First_Discriminant (Etype (Typ));
6370 C := First_Elmt (Stored_Constraint (Typ));
6371 while Present (D) and then Present (C) loop
6372 if Chars (Discrim_Name) = Chars (D) then
6373 if Is_Entity_Name (Node (C))
6374 and then Entity (Node (C)) = Entity (Discrim)
6375 then
6376 -- D is renamed by Discrim, whose value is given in
6377 -- Assoc.
6379 null;
6381 else
6382 Assoc :=
6383 Make_Component_Association (Sloc (Typ),
6384 New_List
6385 (New_Occurrence_Of (D, Sloc (Typ))),
6386 Duplicate_Subexpr_No_Checks (Node (C)));
6387 end if;
6388 exit Find_Constraint;
6389 end if;
6391 Next_Discriminant (D);
6392 Next_Elmt (C);
6393 end loop;
6394 end;
6395 end if;
6396 end if;
6398 if No (Next (Assoc)) then
6399 Error_Msg_NE (" missing value for discriminant&",
6400 First (Governed_By), Discrim_Name);
6401 Report_Errors := True;
6402 return;
6403 end if;
6405 Next (Assoc);
6406 end loop Find_Constraint;
6408 Discrim_Value := Expression (Assoc);
6410 if not Is_OK_Static_Expression (Discrim_Value) then
6411 Error_Msg_FE
6412 ("value for discriminant & must be static!",
6413 Discrim_Value, Discrim);
6414 Why_Not_Static (Discrim_Value);
6415 Report_Errors := True;
6416 return;
6417 end if;
6419 Search_For_Discriminant_Value : declare
6420 Low : Node_Id;
6421 High : Node_Id;
6423 UI_High : Uint;
6424 UI_Low : Uint;
6425 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
6427 begin
6428 Find_Discrete_Value : while Present (Variant) loop
6429 Discrete_Choice := First (Discrete_Choices (Variant));
6430 while Present (Discrete_Choice) loop
6431 exit Find_Discrete_Value when
6432 Nkind (Discrete_Choice) = N_Others_Choice;
6434 Get_Index_Bounds (Discrete_Choice, Low, High);
6436 UI_Low := Expr_Value (Low);
6437 UI_High := Expr_Value (High);
6439 exit Find_Discrete_Value when
6440 UI_Low <= UI_Discrim_Value
6441 and then
6442 UI_High >= UI_Discrim_Value;
6444 Next (Discrete_Choice);
6445 end loop;
6447 Next_Non_Pragma (Variant);
6448 end loop Find_Discrete_Value;
6449 end Search_For_Discriminant_Value;
6451 if No (Variant) then
6452 Error_Msg_NE
6453 ("value of discriminant & is out of range", Discrim_Value, Discrim);
6454 Report_Errors := True;
6455 return;
6456 end if;
6458 -- If we have found the corresponding choice, recursively add its
6459 -- components to the Into list.
6461 Gather_Components
6462 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
6463 end Gather_Components;
6465 ------------------------
6466 -- Get_Actual_Subtype --
6467 ------------------------
6469 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
6470 Typ : constant Entity_Id := Etype (N);
6471 Utyp : Entity_Id := Underlying_Type (Typ);
6472 Decl : Node_Id;
6473 Atyp : Entity_Id;
6475 begin
6476 if No (Utyp) then
6477 Utyp := Typ;
6478 end if;
6480 -- If what we have is an identifier that references a subprogram
6481 -- formal, or a variable or constant object, then we get the actual
6482 -- subtype from the referenced entity if one has been built.
6484 if Nkind (N) = N_Identifier
6485 and then
6486 (Is_Formal (Entity (N))
6487 or else Ekind (Entity (N)) = E_Constant
6488 or else Ekind (Entity (N)) = E_Variable)
6489 and then Present (Actual_Subtype (Entity (N)))
6490 then
6491 return Actual_Subtype (Entity (N));
6493 -- Actual subtype of unchecked union is always itself. We never need
6494 -- the "real" actual subtype. If we did, we couldn't get it anyway
6495 -- because the discriminant is not available. The restrictions on
6496 -- Unchecked_Union are designed to make sure that this is OK.
6498 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
6499 return Typ;
6501 -- Here for the unconstrained case, we must find actual subtype
6502 -- No actual subtype is available, so we must build it on the fly.
6504 -- Checking the type, not the underlying type, for constrainedness
6505 -- seems to be necessary. Maybe all the tests should be on the type???
6507 elsif (not Is_Constrained (Typ))
6508 and then (Is_Array_Type (Utyp)
6509 or else (Is_Record_Type (Utyp)
6510 and then Has_Discriminants (Utyp)))
6511 and then not Has_Unknown_Discriminants (Utyp)
6512 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
6513 then
6514 -- Nothing to do if in spec expression (why not???)
6516 if In_Spec_Expression then
6517 return Typ;
6519 elsif Is_Private_Type (Typ)
6520 and then not Has_Discriminants (Typ)
6521 then
6522 -- If the type has no discriminants, there is no subtype to
6523 -- build, even if the underlying type is discriminated.
6525 return Typ;
6527 -- Else build the actual subtype
6529 else
6530 Decl := Build_Actual_Subtype (Typ, N);
6531 Atyp := Defining_Identifier (Decl);
6533 -- If Build_Actual_Subtype generated a new declaration then use it
6535 if Atyp /= Typ then
6537 -- The actual subtype is an Itype, so analyze the declaration,
6538 -- but do not attach it to the tree, to get the type defined.
6540 Set_Parent (Decl, N);
6541 Set_Is_Itype (Atyp);
6542 Analyze (Decl, Suppress => All_Checks);
6543 Set_Associated_Node_For_Itype (Atyp, N);
6544 Set_Has_Delayed_Freeze (Atyp, False);
6546 -- We need to freeze the actual subtype immediately. This is
6547 -- needed, because otherwise this Itype will not get frozen
6548 -- at all, and it is always safe to freeze on creation because
6549 -- any associated types must be frozen at this point.
6551 Freeze_Itype (Atyp, N);
6552 return Atyp;
6554 -- Otherwise we did not build a declaration, so return original
6556 else
6557 return Typ;
6558 end if;
6559 end if;
6561 -- For all remaining cases, the actual subtype is the same as
6562 -- the nominal type.
6564 else
6565 return Typ;
6566 end if;
6567 end Get_Actual_Subtype;
6569 -------------------------------------
6570 -- Get_Actual_Subtype_If_Available --
6571 -------------------------------------
6573 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
6574 Typ : constant Entity_Id := Etype (N);
6576 begin
6577 -- If what we have is an identifier that references a subprogram
6578 -- formal, or a variable or constant object, then we get the actual
6579 -- subtype from the referenced entity if one has been built.
6581 if Nkind (N) = N_Identifier
6582 and then
6583 (Is_Formal (Entity (N))
6584 or else Ekind (Entity (N)) = E_Constant
6585 or else Ekind (Entity (N)) = E_Variable)
6586 and then Present (Actual_Subtype (Entity (N)))
6587 then
6588 return Actual_Subtype (Entity (N));
6590 -- Otherwise the Etype of N is returned unchanged
6592 else
6593 return Typ;
6594 end if;
6595 end Get_Actual_Subtype_If_Available;
6597 ------------------------
6598 -- Get_Body_From_Stub --
6599 ------------------------
6601 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
6602 begin
6603 return Proper_Body (Unit (Library_Unit (N)));
6604 end Get_Body_From_Stub;
6606 ---------------------
6607 -- Get_Cursor_Type --
6608 ---------------------
6610 function Get_Cursor_Type
6611 (Aspect : Node_Id;
6612 Typ : Entity_Id) return Entity_Id
6614 Assoc : Node_Id;
6615 Func : Entity_Id;
6616 First_Op : Entity_Id;
6617 Cursor : Entity_Id;
6619 begin
6620 -- If error already detected, return
6622 if Error_Posted (Aspect) then
6623 return Any_Type;
6624 end if;
6626 -- The cursor type for an Iterable aspect is the return type of a
6627 -- non-overloaded First primitive operation. Locate association for
6628 -- First.
6630 Assoc := First (Component_Associations (Expression (Aspect)));
6631 First_Op := Any_Id;
6632 while Present (Assoc) loop
6633 if Chars (First (Choices (Assoc))) = Name_First then
6634 First_Op := Expression (Assoc);
6635 exit;
6636 end if;
6638 Next (Assoc);
6639 end loop;
6641 if First_Op = Any_Id then
6642 Error_Msg_N ("aspect Iterable must specify First operation", Aspect);
6643 return Any_Type;
6644 end if;
6646 Cursor := Any_Type;
6648 -- Locate function with desired name and profile in scope of type
6650 Func := First_Entity (Scope (Typ));
6651 while Present (Func) loop
6652 if Chars (Func) = Chars (First_Op)
6653 and then Ekind (Func) = E_Function
6654 and then Present (First_Formal (Func))
6655 and then Etype (First_Formal (Func)) = Typ
6656 and then No (Next_Formal (First_Formal (Func)))
6657 then
6658 if Cursor /= Any_Type then
6659 Error_Msg_N
6660 ("Operation First for iterable type must be unique", Aspect);
6661 return Any_Type;
6662 else
6663 Cursor := Etype (Func);
6664 end if;
6665 end if;
6667 Next_Entity (Func);
6668 end loop;
6670 -- If not found, no way to resolve remaining primitives.
6672 if Cursor = Any_Type then
6673 Error_Msg_N
6674 ("No legal primitive operation First for Iterable type", Aspect);
6675 end if;
6677 return Cursor;
6678 end Get_Cursor_Type;
6680 -------------------------------
6681 -- Get_Default_External_Name --
6682 -------------------------------
6684 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
6685 begin
6686 Get_Decoded_Name_String (Chars (E));
6688 if Opt.External_Name_Imp_Casing = Uppercase then
6689 Set_Casing (All_Upper_Case);
6690 else
6691 Set_Casing (All_Lower_Case);
6692 end if;
6694 return
6695 Make_String_Literal (Sloc (E),
6696 Strval => String_From_Name_Buffer);
6697 end Get_Default_External_Name;
6699 --------------------------
6700 -- Get_Enclosing_Object --
6701 --------------------------
6703 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
6704 begin
6705 if Is_Entity_Name (N) then
6706 return Entity (N);
6707 else
6708 case Nkind (N) is
6709 when N_Indexed_Component |
6710 N_Slice |
6711 N_Selected_Component =>
6713 -- If not generating code, a dereference may be left implicit.
6714 -- In thoses cases, return Empty.
6716 if Is_Access_Type (Etype (Prefix (N))) then
6717 return Empty;
6718 else
6719 return Get_Enclosing_Object (Prefix (N));
6720 end if;
6722 when N_Type_Conversion =>
6723 return Get_Enclosing_Object (Expression (N));
6725 when others =>
6726 return Empty;
6727 end case;
6728 end if;
6729 end Get_Enclosing_Object;
6731 ---------------------------
6732 -- Get_Enum_Lit_From_Pos --
6733 ---------------------------
6735 function Get_Enum_Lit_From_Pos
6736 (T : Entity_Id;
6737 Pos : Uint;
6738 Loc : Source_Ptr) return Node_Id
6740 Btyp : Entity_Id := Base_Type (T);
6741 Lit : Node_Id;
6743 begin
6744 -- In the case where the literal is of type Character, Wide_Character
6745 -- or Wide_Wide_Character or of a type derived from them, there needs
6746 -- to be some special handling since there is no explicit chain of
6747 -- literals to search. Instead, an N_Character_Literal node is created
6748 -- with the appropriate Char_Code and Chars fields.
6750 if Is_Standard_Character_Type (T) then
6751 Set_Character_Literal_Name (UI_To_CC (Pos));
6752 return
6753 Make_Character_Literal (Loc,
6754 Chars => Name_Find,
6755 Char_Literal_Value => Pos);
6757 -- For all other cases, we have a complete table of literals, and
6758 -- we simply iterate through the chain of literal until the one
6759 -- with the desired position value is found.
6762 else
6763 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
6764 Btyp := Full_View (Btyp);
6765 end if;
6767 Lit := First_Literal (Btyp);
6768 for J in 1 .. UI_To_Int (Pos) loop
6769 Next_Literal (Lit);
6770 end loop;
6772 return New_Occurrence_Of (Lit, Loc);
6773 end if;
6774 end Get_Enum_Lit_From_Pos;
6776 ---------------------------------
6777 -- Get_Ensures_From_CTC_Pragma --
6778 ---------------------------------
6780 function Get_Ensures_From_CTC_Pragma (N : Node_Id) return Node_Id is
6781 Args : constant List_Id := Pragma_Argument_Associations (N);
6782 Res : Node_Id;
6784 begin
6785 if List_Length (Args) = 4 then
6786 Res := Pick (Args, 4);
6788 elsif List_Length (Args) = 3 then
6789 Res := Pick (Args, 3);
6791 if Chars (Res) /= Name_Ensures then
6792 Res := Empty;
6793 end if;
6795 else
6796 Res := Empty;
6797 end if;
6799 return Res;
6800 end Get_Ensures_From_CTC_Pragma;
6802 ------------------------
6803 -- Get_Generic_Entity --
6804 ------------------------
6806 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
6807 Ent : constant Entity_Id := Entity (Name (N));
6808 begin
6809 if Present (Renamed_Object (Ent)) then
6810 return Renamed_Object (Ent);
6811 else
6812 return Ent;
6813 end if;
6814 end Get_Generic_Entity;
6816 -------------------------------------
6817 -- Get_Incomplete_View_Of_Ancestor --
6818 -------------------------------------
6820 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
6821 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
6822 Par_Scope : Entity_Id;
6823 Par_Type : Entity_Id;
6825 begin
6826 -- The incomplete view of an ancestor is only relevant for private
6827 -- derived types in child units.
6829 if not Is_Derived_Type (E)
6830 or else not Is_Child_Unit (Cur_Unit)
6831 then
6832 return Empty;
6834 else
6835 Par_Scope := Scope (Cur_Unit);
6836 if No (Par_Scope) then
6837 return Empty;
6838 end if;
6840 Par_Type := Etype (Base_Type (E));
6842 -- Traverse list of ancestor types until we find one declared in
6843 -- a parent or grandparent unit (two levels seem sufficient).
6845 while Present (Par_Type) loop
6846 if Scope (Par_Type) = Par_Scope
6847 or else Scope (Par_Type) = Scope (Par_Scope)
6848 then
6849 return Par_Type;
6851 elsif not Is_Derived_Type (Par_Type) then
6852 return Empty;
6854 else
6855 Par_Type := Etype (Base_Type (Par_Type));
6856 end if;
6857 end loop;
6859 -- If none found, there is no relevant ancestor type.
6861 return Empty;
6862 end if;
6863 end Get_Incomplete_View_Of_Ancestor;
6865 ----------------------
6866 -- Get_Index_Bounds --
6867 ----------------------
6869 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
6870 Kind : constant Node_Kind := Nkind (N);
6871 R : Node_Id;
6873 begin
6874 if Kind = N_Range then
6875 L := Low_Bound (N);
6876 H := High_Bound (N);
6878 elsif Kind = N_Subtype_Indication then
6879 R := Range_Expression (Constraint (N));
6881 if R = Error then
6882 L := Error;
6883 H := Error;
6884 return;
6886 else
6887 L := Low_Bound (Range_Expression (Constraint (N)));
6888 H := High_Bound (Range_Expression (Constraint (N)));
6889 end if;
6891 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
6892 if Error_Posted (Scalar_Range (Entity (N))) then
6893 L := Error;
6894 H := Error;
6896 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
6897 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
6899 else
6900 L := Low_Bound (Scalar_Range (Entity (N)));
6901 H := High_Bound (Scalar_Range (Entity (N)));
6902 end if;
6904 else
6905 -- N is an expression, indicating a range with one value
6907 L := N;
6908 H := N;
6909 end if;
6910 end Get_Index_Bounds;
6912 ---------------------------------
6913 -- Get_Iterable_Type_Primitive --
6914 ---------------------------------
6916 function Get_Iterable_Type_Primitive
6917 (Typ : Entity_Id;
6918 Nam : Name_Id) return Entity_Id
6920 Funcs : constant Node_Id := Find_Value_Of_Aspect (Typ, Aspect_Iterable);
6921 Assoc : Node_Id;
6923 begin
6924 if No (Funcs) then
6925 return Empty;
6927 else
6928 Assoc := First (Component_Associations (Funcs));
6929 while Present (Assoc) loop
6930 if Chars (First (Choices (Assoc))) = Nam then
6931 return Entity (Expression (Assoc));
6932 end if;
6934 Assoc := Next (Assoc);
6935 end loop;
6937 return Empty;
6938 end if;
6939 end Get_Iterable_Type_Primitive;
6941 ----------------------------------
6942 -- Get_Library_Unit_Name_string --
6943 ----------------------------------
6945 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
6946 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
6948 begin
6949 Get_Unit_Name_String (Unit_Name_Id);
6951 -- Remove seven last character (" (spec)" or " (body)")
6953 Name_Len := Name_Len - 7;
6954 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
6955 end Get_Library_Unit_Name_String;
6957 ------------------------
6958 -- Get_Name_Entity_Id --
6959 ------------------------
6961 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
6962 begin
6963 return Entity_Id (Get_Name_Table_Info (Id));
6964 end Get_Name_Entity_Id;
6966 ------------------------------
6967 -- Get_Name_From_CTC_Pragma --
6968 ------------------------------
6970 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
6971 Arg : constant Node_Id :=
6972 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
6973 begin
6974 return Strval (Expr_Value_S (Arg));
6975 end Get_Name_From_CTC_Pragma;
6977 -----------------------
6978 -- Get_Parent_Entity --
6979 -----------------------
6981 function Get_Parent_Entity (Unit : Node_Id) return Entity_Id is
6982 begin
6983 if Nkind (Unit) = N_Package_Body
6984 and then Nkind (Original_Node (Unit)) = N_Package_Instantiation
6985 then
6986 return Defining_Entity
6987 (Specification (Instance_Spec (Original_Node (Unit))));
6988 elsif Nkind (Unit) = N_Package_Instantiation then
6989 return Defining_Entity (Specification (Instance_Spec (Unit)));
6990 else
6991 return Defining_Entity (Unit);
6992 end if;
6993 end Get_Parent_Entity;
6994 -------------------
6995 -- Get_Pragma_Id --
6996 -------------------
6998 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
6999 begin
7000 return Get_Pragma_Id (Pragma_Name (N));
7001 end Get_Pragma_Id;
7003 -----------------------
7004 -- Get_Reason_String --
7005 -----------------------
7007 procedure Get_Reason_String (N : Node_Id) is
7008 begin
7009 if Nkind (N) = N_String_Literal then
7010 Store_String_Chars (Strval (N));
7012 elsif Nkind (N) = N_Op_Concat then
7013 Get_Reason_String (Left_Opnd (N));
7014 Get_Reason_String (Right_Opnd (N));
7016 -- If not of required form, error
7018 else
7019 Error_Msg_N
7020 ("Reason for pragma Warnings has wrong form", N);
7021 Error_Msg_N
7022 ("\must be string literal or concatenation of string literals", N);
7023 return;
7024 end if;
7025 end Get_Reason_String;
7027 ---------------------------
7028 -- Get_Referenced_Object --
7029 ---------------------------
7031 function Get_Referenced_Object (N : Node_Id) return Node_Id is
7032 R : Node_Id;
7034 begin
7035 R := N;
7036 while Is_Entity_Name (R)
7037 and then Present (Renamed_Object (Entity (R)))
7038 loop
7039 R := Renamed_Object (Entity (R));
7040 end loop;
7042 return R;
7043 end Get_Referenced_Object;
7045 ------------------------
7046 -- Get_Renamed_Entity --
7047 ------------------------
7049 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
7050 R : Entity_Id;
7052 begin
7053 R := E;
7054 while Present (Renamed_Entity (R)) loop
7055 R := Renamed_Entity (R);
7056 end loop;
7058 return R;
7059 end Get_Renamed_Entity;
7061 ----------------------------------
7062 -- Get_Requires_From_CTC_Pragma --
7063 ----------------------------------
7065 function Get_Requires_From_CTC_Pragma (N : Node_Id) return Node_Id is
7066 Args : constant List_Id := Pragma_Argument_Associations (N);
7067 Res : Node_Id;
7069 begin
7070 if List_Length (Args) >= 3 then
7071 Res := Pick (Args, 3);
7073 if Chars (Res) /= Name_Requires then
7074 Res := Empty;
7075 end if;
7077 else
7078 Res := Empty;
7079 end if;
7081 return Res;
7082 end Get_Requires_From_CTC_Pragma;
7084 -------------------------
7085 -- Get_Subprogram_Body --
7086 -------------------------
7088 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
7089 Decl : Node_Id;
7091 begin
7092 Decl := Unit_Declaration_Node (E);
7094 if Nkind (Decl) = N_Subprogram_Body then
7095 return Decl;
7097 -- The below comment is bad, because it is possible for
7098 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7100 else -- Nkind (Decl) = N_Subprogram_Declaration
7102 if Present (Corresponding_Body (Decl)) then
7103 return Unit_Declaration_Node (Corresponding_Body (Decl));
7105 -- Imported subprogram case
7107 else
7108 return Empty;
7109 end if;
7110 end if;
7111 end Get_Subprogram_Body;
7113 ---------------------------
7114 -- Get_Subprogram_Entity --
7115 ---------------------------
7117 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
7118 Subp : Node_Id;
7119 Subp_Id : Entity_Id;
7121 begin
7122 if Nkind (Nod) = N_Accept_Statement then
7123 Subp := Entry_Direct_Name (Nod);
7125 elsif Nkind (Nod) = N_Slice then
7126 Subp := Prefix (Nod);
7128 else
7129 Subp := Name (Nod);
7130 end if;
7132 -- Strip the subprogram call
7134 loop
7135 if Nkind_In (Subp, N_Explicit_Dereference,
7136 N_Indexed_Component,
7137 N_Selected_Component)
7138 then
7139 Subp := Prefix (Subp);
7141 elsif Nkind_In (Subp, N_Type_Conversion,
7142 N_Unchecked_Type_Conversion)
7143 then
7144 Subp := Expression (Subp);
7146 else
7147 exit;
7148 end if;
7149 end loop;
7151 -- Extract the entity of the subprogram call
7153 if Is_Entity_Name (Subp) then
7154 Subp_Id := Entity (Subp);
7156 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
7157 Subp_Id := Directly_Designated_Type (Subp_Id);
7158 end if;
7160 if Is_Subprogram (Subp_Id) then
7161 return Subp_Id;
7162 else
7163 return Empty;
7164 end if;
7166 -- The search did not find a construct that denotes a subprogram
7168 else
7169 return Empty;
7170 end if;
7171 end Get_Subprogram_Entity;
7173 -----------------------------
7174 -- Get_Task_Body_Procedure --
7175 -----------------------------
7177 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
7178 begin
7179 -- Note: A task type may be the completion of a private type with
7180 -- discriminants. When performing elaboration checks on a task
7181 -- declaration, the current view of the type may be the private one,
7182 -- and the procedure that holds the body of the task is held in its
7183 -- underlying type.
7185 -- This is an odd function, why not have Task_Body_Procedure do
7186 -- the following digging???
7188 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
7189 end Get_Task_Body_Procedure;
7191 -----------------------
7192 -- Has_Access_Values --
7193 -----------------------
7195 function Has_Access_Values (T : Entity_Id) return Boolean is
7196 Typ : constant Entity_Id := Underlying_Type (T);
7198 begin
7199 -- Case of a private type which is not completed yet. This can only
7200 -- happen in the case of a generic format type appearing directly, or
7201 -- as a component of the type to which this function is being applied
7202 -- at the top level. Return False in this case, since we certainly do
7203 -- not know that the type contains access types.
7205 if No (Typ) then
7206 return False;
7208 elsif Is_Access_Type (Typ) then
7209 return True;
7211 elsif Is_Array_Type (Typ) then
7212 return Has_Access_Values (Component_Type (Typ));
7214 elsif Is_Record_Type (Typ) then
7215 declare
7216 Comp : Entity_Id;
7218 begin
7219 -- Loop to Check components
7221 Comp := First_Component_Or_Discriminant (Typ);
7222 while Present (Comp) loop
7224 -- Check for access component, tag field does not count, even
7225 -- though it is implemented internally using an access type.
7227 if Has_Access_Values (Etype (Comp))
7228 and then Chars (Comp) /= Name_uTag
7229 then
7230 return True;
7231 end if;
7233 Next_Component_Or_Discriminant (Comp);
7234 end loop;
7235 end;
7237 return False;
7239 else
7240 return False;
7241 end if;
7242 end Has_Access_Values;
7244 ------------------------------
7245 -- Has_Compatible_Alignment --
7246 ------------------------------
7248 function Has_Compatible_Alignment
7249 (Obj : Entity_Id;
7250 Expr : Node_Id) return Alignment_Result
7252 function Has_Compatible_Alignment_Internal
7253 (Obj : Entity_Id;
7254 Expr : Node_Id;
7255 Default : Alignment_Result) return Alignment_Result;
7256 -- This is the internal recursive function that actually does the work.
7257 -- There is one additional parameter, which says what the result should
7258 -- be if no alignment information is found, and there is no definite
7259 -- indication of compatible alignments. At the outer level, this is set
7260 -- to Unknown, but for internal recursive calls in the case where types
7261 -- are known to be correct, it is set to Known_Compatible.
7263 ---------------------------------------
7264 -- Has_Compatible_Alignment_Internal --
7265 ---------------------------------------
7267 function Has_Compatible_Alignment_Internal
7268 (Obj : Entity_Id;
7269 Expr : Node_Id;
7270 Default : Alignment_Result) return Alignment_Result
7272 Result : Alignment_Result := Known_Compatible;
7273 -- Holds the current status of the result. Note that once a value of
7274 -- Known_Incompatible is set, it is sticky and does not get changed
7275 -- to Unknown (the value in Result only gets worse as we go along,
7276 -- never better).
7278 Offs : Uint := No_Uint;
7279 -- Set to a factor of the offset from the base object when Expr is a
7280 -- selected or indexed component, based on Component_Bit_Offset and
7281 -- Component_Size respectively. A negative value is used to represent
7282 -- a value which is not known at compile time.
7284 procedure Check_Prefix;
7285 -- Checks the prefix recursively in the case where the expression
7286 -- is an indexed or selected component.
7288 procedure Set_Result (R : Alignment_Result);
7289 -- If R represents a worse outcome (unknown instead of known
7290 -- compatible, or known incompatible), then set Result to R.
7292 ------------------
7293 -- Check_Prefix --
7294 ------------------
7296 procedure Check_Prefix is
7297 begin
7298 -- The subtlety here is that in doing a recursive call to check
7299 -- the prefix, we have to decide what to do in the case where we
7300 -- don't find any specific indication of an alignment problem.
7302 -- At the outer level, we normally set Unknown as the result in
7303 -- this case, since we can only set Known_Compatible if we really
7304 -- know that the alignment value is OK, but for the recursive
7305 -- call, in the case where the types match, and we have not
7306 -- specified a peculiar alignment for the object, we are only
7307 -- concerned about suspicious rep clauses, the default case does
7308 -- not affect us, since the compiler will, in the absence of such
7309 -- rep clauses, ensure that the alignment is correct.
7311 if Default = Known_Compatible
7312 or else
7313 (Etype (Obj) = Etype (Expr)
7314 and then (Unknown_Alignment (Obj)
7315 or else
7316 Alignment (Obj) = Alignment (Etype (Obj))))
7317 then
7318 Set_Result
7319 (Has_Compatible_Alignment_Internal
7320 (Obj, Prefix (Expr), Known_Compatible));
7322 -- In all other cases, we need a full check on the prefix
7324 else
7325 Set_Result
7326 (Has_Compatible_Alignment_Internal
7327 (Obj, Prefix (Expr), Unknown));
7328 end if;
7329 end Check_Prefix;
7331 ----------------
7332 -- Set_Result --
7333 ----------------
7335 procedure Set_Result (R : Alignment_Result) is
7336 begin
7337 if R > Result then
7338 Result := R;
7339 end if;
7340 end Set_Result;
7342 -- Start of processing for Has_Compatible_Alignment_Internal
7344 begin
7345 -- If Expr is a selected component, we must make sure there is no
7346 -- potentially troublesome component clause, and that the record is
7347 -- not packed.
7349 if Nkind (Expr) = N_Selected_Component then
7351 -- Packed record always generate unknown alignment
7353 if Is_Packed (Etype (Prefix (Expr))) then
7354 Set_Result (Unknown);
7355 end if;
7357 -- Check prefix and component offset
7359 Check_Prefix;
7360 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
7362 -- If Expr is an indexed component, we must make sure there is no
7363 -- potentially troublesome Component_Size clause and that the array
7364 -- is not bit-packed.
7366 elsif Nkind (Expr) = N_Indexed_Component then
7367 declare
7368 Typ : constant Entity_Id := Etype (Prefix (Expr));
7369 Ind : constant Node_Id := First_Index (Typ);
7371 begin
7372 -- Bit packed array always generates unknown alignment
7374 if Is_Bit_Packed_Array (Typ) then
7375 Set_Result (Unknown);
7376 end if;
7378 -- Check prefix and component offset
7380 Check_Prefix;
7381 Offs := Component_Size (Typ);
7383 -- Small optimization: compute the full offset when possible
7385 if Offs /= No_Uint
7386 and then Offs > Uint_0
7387 and then Present (Ind)
7388 and then Nkind (Ind) = N_Range
7389 and then Compile_Time_Known_Value (Low_Bound (Ind))
7390 and then Compile_Time_Known_Value (First (Expressions (Expr)))
7391 then
7392 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
7393 - Expr_Value (Low_Bound ((Ind))));
7394 end if;
7395 end;
7396 end if;
7398 -- If we have a null offset, the result is entirely determined by
7399 -- the base object and has already been computed recursively.
7401 if Offs = Uint_0 then
7402 null;
7404 -- Case where we know the alignment of the object
7406 elsif Known_Alignment (Obj) then
7407 declare
7408 ObjA : constant Uint := Alignment (Obj);
7409 ExpA : Uint := No_Uint;
7410 SizA : Uint := No_Uint;
7412 begin
7413 -- If alignment of Obj is 1, then we are always OK
7415 if ObjA = 1 then
7416 Set_Result (Known_Compatible);
7418 -- Alignment of Obj is greater than 1, so we need to check
7420 else
7421 -- If we have an offset, see if it is compatible
7423 if Offs /= No_Uint and Offs > Uint_0 then
7424 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
7425 Set_Result (Known_Incompatible);
7426 end if;
7428 -- See if Expr is an object with known alignment
7430 elsif Is_Entity_Name (Expr)
7431 and then Known_Alignment (Entity (Expr))
7432 then
7433 ExpA := Alignment (Entity (Expr));
7435 -- Otherwise, we can use the alignment of the type of
7436 -- Expr given that we already checked for
7437 -- discombobulating rep clauses for the cases of indexed
7438 -- and selected components above.
7440 elsif Known_Alignment (Etype (Expr)) then
7441 ExpA := Alignment (Etype (Expr));
7443 -- Otherwise the alignment is unknown
7445 else
7446 Set_Result (Default);
7447 end if;
7449 -- If we got an alignment, see if it is acceptable
7451 if ExpA /= No_Uint and then ExpA < ObjA then
7452 Set_Result (Known_Incompatible);
7453 end if;
7455 -- If Expr is not a piece of a larger object, see if size
7456 -- is given. If so, check that it is not too small for the
7457 -- required alignment.
7459 if Offs /= No_Uint then
7460 null;
7462 -- See if Expr is an object with known size
7464 elsif Is_Entity_Name (Expr)
7465 and then Known_Static_Esize (Entity (Expr))
7466 then
7467 SizA := Esize (Entity (Expr));
7469 -- Otherwise, we check the object size of the Expr type
7471 elsif Known_Static_Esize (Etype (Expr)) then
7472 SizA := Esize (Etype (Expr));
7473 end if;
7475 -- If we got a size, see if it is a multiple of the Obj
7476 -- alignment, if not, then the alignment cannot be
7477 -- acceptable, since the size is always a multiple of the
7478 -- alignment.
7480 if SizA /= No_Uint then
7481 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
7482 Set_Result (Known_Incompatible);
7483 end if;
7484 end if;
7485 end if;
7486 end;
7488 -- If we do not know required alignment, any non-zero offset is a
7489 -- potential problem (but certainly may be OK, so result is unknown).
7491 elsif Offs /= No_Uint then
7492 Set_Result (Unknown);
7494 -- If we can't find the result by direct comparison of alignment
7495 -- values, then there is still one case that we can determine known
7496 -- result, and that is when we can determine that the types are the
7497 -- same, and no alignments are specified. Then we known that the
7498 -- alignments are compatible, even if we don't know the alignment
7499 -- value in the front end.
7501 elsif Etype (Obj) = Etype (Expr) then
7503 -- Types are the same, but we have to check for possible size
7504 -- and alignments on the Expr object that may make the alignment
7505 -- different, even though the types are the same.
7507 if Is_Entity_Name (Expr) then
7509 -- First check alignment of the Expr object. Any alignment less
7510 -- than Maximum_Alignment is worrisome since this is the case
7511 -- where we do not know the alignment of Obj.
7513 if Known_Alignment (Entity (Expr))
7514 and then UI_To_Int (Alignment (Entity (Expr))) <
7515 Ttypes.Maximum_Alignment
7516 then
7517 Set_Result (Unknown);
7519 -- Now check size of Expr object. Any size that is not an
7520 -- even multiple of Maximum_Alignment is also worrisome
7521 -- since it may cause the alignment of the object to be less
7522 -- than the alignment of the type.
7524 elsif Known_Static_Esize (Entity (Expr))
7525 and then
7526 (UI_To_Int (Esize (Entity (Expr))) mod
7527 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
7528 /= 0
7529 then
7530 Set_Result (Unknown);
7532 -- Otherwise same type is decisive
7534 else
7535 Set_Result (Known_Compatible);
7536 end if;
7537 end if;
7539 -- Another case to deal with is when there is an explicit size or
7540 -- alignment clause when the types are not the same. If so, then the
7541 -- result is Unknown. We don't need to do this test if the Default is
7542 -- Unknown, since that result will be set in any case.
7544 elsif Default /= Unknown
7545 and then (Has_Size_Clause (Etype (Expr))
7546 or else
7547 Has_Alignment_Clause (Etype (Expr)))
7548 then
7549 Set_Result (Unknown);
7551 -- If no indication found, set default
7553 else
7554 Set_Result (Default);
7555 end if;
7557 -- Return worst result found
7559 return Result;
7560 end Has_Compatible_Alignment_Internal;
7562 -- Start of processing for Has_Compatible_Alignment
7564 begin
7565 -- If Obj has no specified alignment, then set alignment from the type
7566 -- alignment. Perhaps we should always do this, but for sure we should
7567 -- do it when there is an address clause since we can do more if the
7568 -- alignment is known.
7570 if Unknown_Alignment (Obj) then
7571 Set_Alignment (Obj, Alignment (Etype (Obj)));
7572 end if;
7574 -- Now do the internal call that does all the work
7576 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
7577 end Has_Compatible_Alignment;
7579 ----------------------
7580 -- Has_Declarations --
7581 ----------------------
7583 function Has_Declarations (N : Node_Id) return Boolean is
7584 begin
7585 return Nkind_In (Nkind (N), N_Accept_Statement,
7586 N_Block_Statement,
7587 N_Compilation_Unit_Aux,
7588 N_Entry_Body,
7589 N_Package_Body,
7590 N_Protected_Body,
7591 N_Subprogram_Body,
7592 N_Task_Body,
7593 N_Package_Specification);
7594 end Has_Declarations;
7596 ---------------------------------
7597 -- Has_Defaulted_Discriminants --
7598 ---------------------------------
7600 function Has_Defaulted_Discriminants (Typ : Entity_Id) return Boolean is
7601 begin
7602 return Has_Discriminants (Typ)
7603 and then Present (First_Discriminant (Typ))
7604 and then Present (Discriminant_Default_Value
7605 (First_Discriminant (Typ)));
7606 end Has_Defaulted_Discriminants;
7608 -------------------
7609 -- Has_Denormals --
7610 -------------------
7612 function Has_Denormals (E : Entity_Id) return Boolean is
7613 begin
7614 return Is_Floating_Point_Type (E) and then Denorm_On_Target;
7615 end Has_Denormals;
7617 -------------------------------------------
7618 -- Has_Discriminant_Dependent_Constraint --
7619 -------------------------------------------
7621 function Has_Discriminant_Dependent_Constraint
7622 (Comp : Entity_Id) return Boolean
7624 Comp_Decl : constant Node_Id := Parent (Comp);
7625 Subt_Indic : Node_Id;
7626 Constr : Node_Id;
7627 Assn : Node_Id;
7629 begin
7630 -- Discriminants can't depend on discriminants
7632 if Ekind (Comp) = E_Discriminant then
7633 return False;
7635 else
7636 Subt_Indic := Subtype_Indication (Component_Definition (Comp_Decl));
7638 if Nkind (Subt_Indic) = N_Subtype_Indication then
7639 Constr := Constraint (Subt_Indic);
7641 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
7642 Assn := First (Constraints (Constr));
7643 while Present (Assn) loop
7644 case Nkind (Assn) is
7645 when N_Subtype_Indication |
7646 N_Range |
7647 N_Identifier
7649 if Depends_On_Discriminant (Assn) then
7650 return True;
7651 end if;
7653 when N_Discriminant_Association =>
7654 if Depends_On_Discriminant (Expression (Assn)) then
7655 return True;
7656 end if;
7658 when others =>
7659 null;
7660 end case;
7662 Next (Assn);
7663 end loop;
7664 end if;
7665 end if;
7666 end if;
7668 return False;
7669 end Has_Discriminant_Dependent_Constraint;
7671 --------------------------
7672 -- Has_Enabled_Property --
7673 --------------------------
7675 function Has_Enabled_Property
7676 (Item_Id : Entity_Id;
7677 Property : Name_Id) return Boolean
7679 function State_Has_Enabled_Property return Boolean;
7680 -- Determine whether a state denoted by Item_Id has the property enabled
7682 function Variable_Has_Enabled_Property return Boolean;
7683 -- Determine whether a variable denoted by Item_Id has the property
7684 -- enabled.
7686 --------------------------------
7687 -- State_Has_Enabled_Property --
7688 --------------------------------
7690 function State_Has_Enabled_Property return Boolean is
7691 Decl : constant Node_Id := Parent (Item_Id);
7692 Opt : Node_Id;
7693 Opt_Nam : Node_Id;
7694 Prop : Node_Id;
7695 Prop_Nam : Node_Id;
7696 Props : Node_Id;
7698 begin
7699 -- The declaration of an external abstract state appears as an
7700 -- extension aggregate. If this is not the case, properties can never
7701 -- be set.
7703 if Nkind (Decl) /= N_Extension_Aggregate then
7704 return False;
7705 end if;
7707 -- When External appears as a simple option, it automatically enables
7708 -- all properties.
7710 Opt := First (Expressions (Decl));
7711 while Present (Opt) loop
7712 if Nkind (Opt) = N_Identifier
7713 and then Chars (Opt) = Name_External
7714 then
7715 return True;
7716 end if;
7718 Next (Opt);
7719 end loop;
7721 -- When External specifies particular properties, inspect those and
7722 -- find the desired one (if any).
7724 Opt := First (Component_Associations (Decl));
7725 while Present (Opt) loop
7726 Opt_Nam := First (Choices (Opt));
7728 if Nkind (Opt_Nam) = N_Identifier
7729 and then Chars (Opt_Nam) = Name_External
7730 then
7731 Props := Expression (Opt);
7733 -- Multiple properties appear as an aggregate
7735 if Nkind (Props) = N_Aggregate then
7737 -- Simple property form
7739 Prop := First (Expressions (Props));
7740 while Present (Prop) loop
7741 if Chars (Prop) = Property then
7742 return True;
7743 end if;
7745 Next (Prop);
7746 end loop;
7748 -- Property with expression form
7750 Prop := First (Component_Associations (Props));
7751 while Present (Prop) loop
7752 Prop_Nam := First (Choices (Prop));
7754 -- The property can be represented in two ways:
7755 -- others => <value>
7756 -- <property> => <value>
7758 if Nkind (Prop_Nam) = N_Others_Choice
7759 or else (Nkind (Prop_Nam) = N_Identifier
7760 and then Chars (Prop_Nam) = Property)
7761 then
7762 return Is_True (Expr_Value (Expression (Prop)));
7763 end if;
7765 Next (Prop);
7766 end loop;
7768 -- Single property
7770 else
7771 return Chars (Props) = Property;
7772 end if;
7773 end if;
7775 Next (Opt);
7776 end loop;
7778 return False;
7779 end State_Has_Enabled_Property;
7781 -----------------------------------
7782 -- Variable_Has_Enabled_Property --
7783 -----------------------------------
7785 function Variable_Has_Enabled_Property return Boolean is
7786 function Is_Enabled (Prag : Node_Id) return Boolean;
7787 -- Determine whether property pragma Prag (if present) denotes an
7788 -- enabled property.
7790 ----------------
7791 -- Is_Enabled --
7792 ----------------
7794 function Is_Enabled (Prag : Node_Id) return Boolean is
7795 Arg2 : Node_Id;
7797 begin
7798 if Present (Prag) then
7799 Arg2 := Next (First (Pragma_Argument_Associations (Prag)));
7801 -- The pragma has an optional Boolean expression, the related
7802 -- property is enabled only when the expression evaluates to
7803 -- True.
7805 if Present (Arg2) then
7806 return Is_True (Expr_Value (Get_Pragma_Arg (Arg2)));
7808 -- Otherwise the lack of expression enables the property by
7809 -- default.
7811 else
7812 return True;
7813 end if;
7815 -- The property was never set in the first place
7817 else
7818 return False;
7819 end if;
7820 end Is_Enabled;
7822 -- Local variables
7824 AR : constant Node_Id :=
7825 Get_Pragma (Item_Id, Pragma_Async_Readers);
7826 AW : constant Node_Id :=
7827 Get_Pragma (Item_Id, Pragma_Async_Writers);
7828 ER : constant Node_Id :=
7829 Get_Pragma (Item_Id, Pragma_Effective_Reads);
7830 EW : constant Node_Id :=
7831 Get_Pragma (Item_Id, Pragma_Effective_Writes);
7833 -- Start of processing for Variable_Has_Enabled_Property
7835 begin
7836 -- A non-effectively volatile object can never possess external
7837 -- properties.
7839 if not Is_Effectively_Volatile (Item_Id) then
7840 return False;
7842 -- External properties related to variables come in two flavors -
7843 -- explicit and implicit. The explicit case is characterized by the
7844 -- presence of a property pragma with an optional Boolean flag. The
7845 -- property is enabled when the flag evaluates to True or the flag is
7846 -- missing altogether.
7848 elsif Property = Name_Async_Readers and then Is_Enabled (AR) then
7849 return True;
7851 elsif Property = Name_Async_Writers and then Is_Enabled (AW) then
7852 return True;
7854 elsif Property = Name_Effective_Reads and then Is_Enabled (ER) then
7855 return True;
7857 elsif Property = Name_Effective_Writes and then Is_Enabled (EW) then
7858 return True;
7860 -- The implicit case lacks all property pragmas
7862 elsif No (AR) and then No (AW) and then No (ER) and then No (EW) then
7863 return True;
7865 else
7866 return False;
7867 end if;
7868 end Variable_Has_Enabled_Property;
7870 -- Start of processing for Has_Enabled_Property
7872 begin
7873 -- Abstract states and variables have a flexible scheme of specifying
7874 -- external properties.
7876 if Ekind (Item_Id) = E_Abstract_State then
7877 return State_Has_Enabled_Property;
7879 elsif Ekind (Item_Id) = E_Variable then
7880 return Variable_Has_Enabled_Property;
7882 -- Otherwise a property is enabled when the related item is effectively
7883 -- volatile.
7885 else
7886 return Is_Effectively_Volatile (Item_Id);
7887 end if;
7888 end Has_Enabled_Property;
7890 --------------------
7891 -- Has_Infinities --
7892 --------------------
7894 function Has_Infinities (E : Entity_Id) return Boolean is
7895 begin
7896 return
7897 Is_Floating_Point_Type (E)
7898 and then Nkind (Scalar_Range (E)) = N_Range
7899 and then Includes_Infinities (Scalar_Range (E));
7900 end Has_Infinities;
7902 --------------------
7903 -- Has_Interfaces --
7904 --------------------
7906 function Has_Interfaces
7907 (T : Entity_Id;
7908 Use_Full_View : Boolean := True) return Boolean
7910 Typ : Entity_Id := Base_Type (T);
7912 begin
7913 -- Handle concurrent types
7915 if Is_Concurrent_Type (Typ) then
7916 Typ := Corresponding_Record_Type (Typ);
7917 end if;
7919 if not Present (Typ)
7920 or else not Is_Record_Type (Typ)
7921 or else not Is_Tagged_Type (Typ)
7922 then
7923 return False;
7924 end if;
7926 -- Handle private types
7928 if Use_Full_View and then Present (Full_View (Typ)) then
7929 Typ := Full_View (Typ);
7930 end if;
7932 -- Handle concurrent record types
7934 if Is_Concurrent_Record_Type (Typ)
7935 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
7936 then
7937 return True;
7938 end if;
7940 loop
7941 if Is_Interface (Typ)
7942 or else
7943 (Is_Record_Type (Typ)
7944 and then Present (Interfaces (Typ))
7945 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
7946 then
7947 return True;
7948 end if;
7950 exit when Etype (Typ) = Typ
7952 -- Handle private types
7954 or else (Present (Full_View (Etype (Typ)))
7955 and then Full_View (Etype (Typ)) = Typ)
7957 -- Protect frontend against wrong sources with cyclic derivations
7959 or else Etype (Typ) = T;
7961 -- Climb to the ancestor type handling private types
7963 if Present (Full_View (Etype (Typ))) then
7964 Typ := Full_View (Etype (Typ));
7965 else
7966 Typ := Etype (Typ);
7967 end if;
7968 end loop;
7970 return False;
7971 end Has_Interfaces;
7973 ---------------------------------
7974 -- Has_No_Obvious_Side_Effects --
7975 ---------------------------------
7977 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
7978 begin
7979 -- For now, just handle literals, constants, and non-volatile
7980 -- variables and expressions combining these with operators or
7981 -- short circuit forms.
7983 if Nkind (N) in N_Numeric_Or_String_Literal then
7984 return True;
7986 elsif Nkind (N) = N_Character_Literal then
7987 return True;
7989 elsif Nkind (N) in N_Unary_Op then
7990 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
7992 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
7993 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
7994 and then
7995 Has_No_Obvious_Side_Effects (Right_Opnd (N));
7997 elsif Nkind (N) = N_Expression_With_Actions
7998 and then Is_Empty_List (Actions (N))
7999 then
8000 return Has_No_Obvious_Side_Effects (Expression (N));
8002 elsif Nkind (N) in N_Has_Entity then
8003 return Present (Entity (N))
8004 and then Ekind_In (Entity (N), E_Variable,
8005 E_Constant,
8006 E_Enumeration_Literal,
8007 E_In_Parameter,
8008 E_Out_Parameter,
8009 E_In_Out_Parameter)
8010 and then not Is_Volatile (Entity (N));
8012 else
8013 return False;
8014 end if;
8015 end Has_No_Obvious_Side_Effects;
8017 ------------------------
8018 -- Has_Null_Exclusion --
8019 ------------------------
8021 function Has_Null_Exclusion (N : Node_Id) return Boolean is
8022 begin
8023 case Nkind (N) is
8024 when N_Access_Definition |
8025 N_Access_Function_Definition |
8026 N_Access_Procedure_Definition |
8027 N_Access_To_Object_Definition |
8028 N_Allocator |
8029 N_Derived_Type_Definition |
8030 N_Function_Specification |
8031 N_Subtype_Declaration =>
8032 return Null_Exclusion_Present (N);
8034 when N_Component_Definition |
8035 N_Formal_Object_Declaration |
8036 N_Object_Renaming_Declaration =>
8037 if Present (Subtype_Mark (N)) then
8038 return Null_Exclusion_Present (N);
8039 else pragma Assert (Present (Access_Definition (N)));
8040 return Null_Exclusion_Present (Access_Definition (N));
8041 end if;
8043 when N_Discriminant_Specification =>
8044 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
8045 return Null_Exclusion_Present (Discriminant_Type (N));
8046 else
8047 return Null_Exclusion_Present (N);
8048 end if;
8050 when N_Object_Declaration =>
8051 if Nkind (Object_Definition (N)) = N_Access_Definition then
8052 return Null_Exclusion_Present (Object_Definition (N));
8053 else
8054 return Null_Exclusion_Present (N);
8055 end if;
8057 when N_Parameter_Specification =>
8058 if Nkind (Parameter_Type (N)) = N_Access_Definition then
8059 return Null_Exclusion_Present (Parameter_Type (N));
8060 else
8061 return Null_Exclusion_Present (N);
8062 end if;
8064 when others =>
8065 return False;
8067 end case;
8068 end Has_Null_Exclusion;
8070 ------------------------
8071 -- Has_Null_Extension --
8072 ------------------------
8074 function Has_Null_Extension (T : Entity_Id) return Boolean is
8075 B : constant Entity_Id := Base_Type (T);
8076 Comps : Node_Id;
8077 Ext : Node_Id;
8079 begin
8080 if Nkind (Parent (B)) = N_Full_Type_Declaration
8081 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
8082 then
8083 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
8085 if Present (Ext) then
8086 if Null_Present (Ext) then
8087 return True;
8088 else
8089 Comps := Component_List (Ext);
8091 -- The null component list is rewritten during analysis to
8092 -- include the parent component. Any other component indicates
8093 -- that the extension was not originally null.
8095 return Null_Present (Comps)
8096 or else No (Next (First (Component_Items (Comps))));
8097 end if;
8098 else
8099 return False;
8100 end if;
8102 else
8103 return False;
8104 end if;
8105 end Has_Null_Extension;
8107 -------------------------------
8108 -- Has_Overriding_Initialize --
8109 -------------------------------
8111 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
8112 BT : constant Entity_Id := Base_Type (T);
8113 P : Elmt_Id;
8115 begin
8116 if Is_Controlled (BT) then
8117 if Is_RTU (Scope (BT), Ada_Finalization) then
8118 return False;
8120 elsif Present (Primitive_Operations (BT)) then
8121 P := First_Elmt (Primitive_Operations (BT));
8122 while Present (P) loop
8123 declare
8124 Init : constant Entity_Id := Node (P);
8125 Formal : constant Entity_Id := First_Formal (Init);
8126 begin
8127 if Ekind (Init) = E_Procedure
8128 and then Chars (Init) = Name_Initialize
8129 and then Comes_From_Source (Init)
8130 and then Present (Formal)
8131 and then Etype (Formal) = BT
8132 and then No (Next_Formal (Formal))
8133 and then (Ada_Version < Ada_2012
8134 or else not Null_Present (Parent (Init)))
8135 then
8136 return True;
8137 end if;
8138 end;
8140 Next_Elmt (P);
8141 end loop;
8142 end if;
8144 -- Here if type itself does not have a non-null Initialize operation:
8145 -- check immediate ancestor.
8147 if Is_Derived_Type (BT)
8148 and then Has_Overriding_Initialize (Etype (BT))
8149 then
8150 return True;
8151 end if;
8152 end if;
8154 return False;
8155 end Has_Overriding_Initialize;
8157 --------------------------------------
8158 -- Has_Preelaborable_Initialization --
8159 --------------------------------------
8161 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
8162 Has_PE : Boolean;
8164 procedure Check_Components (E : Entity_Id);
8165 -- Check component/discriminant chain, sets Has_PE False if a component
8166 -- or discriminant does not meet the preelaborable initialization rules.
8168 ----------------------
8169 -- Check_Components --
8170 ----------------------
8172 procedure Check_Components (E : Entity_Id) is
8173 Ent : Entity_Id;
8174 Exp : Node_Id;
8176 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
8177 -- Returns True if and only if the expression denoted by N does not
8178 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8180 ---------------------------------
8181 -- Is_Preelaborable_Expression --
8182 ---------------------------------
8184 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
8185 Exp : Node_Id;
8186 Assn : Node_Id;
8187 Choice : Node_Id;
8188 Comp_Type : Entity_Id;
8189 Is_Array_Aggr : Boolean;
8191 begin
8192 if Is_OK_Static_Expression (N) then
8193 return True;
8195 elsif Nkind (N) = N_Null then
8196 return True;
8198 -- Attributes are allowed in general, even if their prefix is a
8199 -- formal type. (It seems that certain attributes known not to be
8200 -- static might not be allowed, but there are no rules to prevent
8201 -- them.)
8203 elsif Nkind (N) = N_Attribute_Reference then
8204 return True;
8206 -- The name of a discriminant evaluated within its parent type is
8207 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8208 -- names that denote discriminals as well as discriminants to
8209 -- catch references occurring within init procs.
8211 elsif Is_Entity_Name (N)
8212 and then
8213 (Ekind (Entity (N)) = E_Discriminant
8214 or else
8215 ((Ekind (Entity (N)) = E_Constant
8216 or else Ekind (Entity (N)) = E_In_Parameter)
8217 and then Present (Discriminal_Link (Entity (N)))))
8218 then
8219 return True;
8221 elsif Nkind (N) = N_Qualified_Expression then
8222 return Is_Preelaborable_Expression (Expression (N));
8224 -- For aggregates we have to check that each of the associations
8225 -- is preelaborable.
8227 elsif Nkind (N) = N_Aggregate
8228 or else Nkind (N) = N_Extension_Aggregate
8229 then
8230 Is_Array_Aggr := Is_Array_Type (Etype (N));
8232 if Is_Array_Aggr then
8233 Comp_Type := Component_Type (Etype (N));
8234 end if;
8236 -- Check the ancestor part of extension aggregates, which must
8237 -- be either the name of a type that has preelaborable init or
8238 -- an expression that is preelaborable.
8240 if Nkind (N) = N_Extension_Aggregate then
8241 declare
8242 Anc_Part : constant Node_Id := Ancestor_Part (N);
8244 begin
8245 if Is_Entity_Name (Anc_Part)
8246 and then Is_Type (Entity (Anc_Part))
8247 then
8248 if not Has_Preelaborable_Initialization
8249 (Entity (Anc_Part))
8250 then
8251 return False;
8252 end if;
8254 elsif not Is_Preelaborable_Expression (Anc_Part) then
8255 return False;
8256 end if;
8257 end;
8258 end if;
8260 -- Check positional associations
8262 Exp := First (Expressions (N));
8263 while Present (Exp) loop
8264 if not Is_Preelaborable_Expression (Exp) then
8265 return False;
8266 end if;
8268 Next (Exp);
8269 end loop;
8271 -- Check named associations
8273 Assn := First (Component_Associations (N));
8274 while Present (Assn) loop
8275 Choice := First (Choices (Assn));
8276 while Present (Choice) loop
8277 if Is_Array_Aggr then
8278 if Nkind (Choice) = N_Others_Choice then
8279 null;
8281 elsif Nkind (Choice) = N_Range then
8282 if not Is_OK_Static_Range (Choice) then
8283 return False;
8284 end if;
8286 elsif not Is_OK_Static_Expression (Choice) then
8287 return False;
8288 end if;
8290 else
8291 Comp_Type := Etype (Choice);
8292 end if;
8294 Next (Choice);
8295 end loop;
8297 -- If the association has a <> at this point, then we have
8298 -- to check whether the component's type has preelaborable
8299 -- initialization. Note that this only occurs when the
8300 -- association's corresponding component does not have a
8301 -- default expression, the latter case having already been
8302 -- expanded as an expression for the association.
8304 if Box_Present (Assn) then
8305 if not Has_Preelaborable_Initialization (Comp_Type) then
8306 return False;
8307 end if;
8309 -- In the expression case we check whether the expression
8310 -- is preelaborable.
8312 elsif
8313 not Is_Preelaborable_Expression (Expression (Assn))
8314 then
8315 return False;
8316 end if;
8318 Next (Assn);
8319 end loop;
8321 -- If we get here then aggregate as a whole is preelaborable
8323 return True;
8325 -- All other cases are not preelaborable
8327 else
8328 return False;
8329 end if;
8330 end Is_Preelaborable_Expression;
8332 -- Start of processing for Check_Components
8334 begin
8335 -- Loop through entities of record or protected type
8337 Ent := E;
8338 while Present (Ent) loop
8340 -- We are interested only in components and discriminants
8342 Exp := Empty;
8344 case Ekind (Ent) is
8345 when E_Component =>
8347 -- Get default expression if any. If there is no declaration
8348 -- node, it means we have an internal entity. The parent and
8349 -- tag fields are examples of such entities. For such cases,
8350 -- we just test the type of the entity.
8352 if Present (Declaration_Node (Ent)) then
8353 Exp := Expression (Declaration_Node (Ent));
8354 end if;
8356 when E_Discriminant =>
8358 -- Note: for a renamed discriminant, the Declaration_Node
8359 -- may point to the one from the ancestor, and have a
8360 -- different expression, so use the proper attribute to
8361 -- retrieve the expression from the derived constraint.
8363 Exp := Discriminant_Default_Value (Ent);
8365 when others =>
8366 goto Check_Next_Entity;
8367 end case;
8369 -- A component has PI if it has no default expression and the
8370 -- component type has PI.
8372 if No (Exp) then
8373 if not Has_Preelaborable_Initialization (Etype (Ent)) then
8374 Has_PE := False;
8375 exit;
8376 end if;
8378 -- Require the default expression to be preelaborable
8380 elsif not Is_Preelaborable_Expression (Exp) then
8381 Has_PE := False;
8382 exit;
8383 end if;
8385 <<Check_Next_Entity>>
8386 Next_Entity (Ent);
8387 end loop;
8388 end Check_Components;
8390 -- Start of processing for Has_Preelaborable_Initialization
8392 begin
8393 -- Immediate return if already marked as known preelaborable init. This
8394 -- covers types for which this function has already been called once
8395 -- and returned True (in which case the result is cached), and also
8396 -- types to which a pragma Preelaborable_Initialization applies.
8398 if Known_To_Have_Preelab_Init (E) then
8399 return True;
8400 end if;
8402 -- If the type is a subtype representing a generic actual type, then
8403 -- test whether its base type has preelaborable initialization since
8404 -- the subtype representing the actual does not inherit this attribute
8405 -- from the actual or formal. (but maybe it should???)
8407 if Is_Generic_Actual_Type (E) then
8408 return Has_Preelaborable_Initialization (Base_Type (E));
8409 end if;
8411 -- All elementary types have preelaborable initialization
8413 if Is_Elementary_Type (E) then
8414 Has_PE := True;
8416 -- Array types have PI if the component type has PI
8418 elsif Is_Array_Type (E) then
8419 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
8421 -- A derived type has preelaborable initialization if its parent type
8422 -- has preelaborable initialization and (in the case of a derived record
8423 -- extension) if the non-inherited components all have preelaborable
8424 -- initialization. However, a user-defined controlled type with an
8425 -- overriding Initialize procedure does not have preelaborable
8426 -- initialization.
8428 elsif Is_Derived_Type (E) then
8430 -- If the derived type is a private extension then it doesn't have
8431 -- preelaborable initialization.
8433 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
8434 return False;
8435 end if;
8437 -- First check whether ancestor type has preelaborable initialization
8439 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
8441 -- If OK, check extension components (if any)
8443 if Has_PE and then Is_Record_Type (E) then
8444 Check_Components (First_Entity (E));
8445 end if;
8447 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8448 -- with a user defined Initialize procedure does not have PI. If
8449 -- the type is untagged, the control primitives come from a component
8450 -- that has already been checked.
8452 if Has_PE
8453 and then Is_Controlled (E)
8454 and then Is_Tagged_Type (E)
8455 and then Has_Overriding_Initialize (E)
8456 then
8457 Has_PE := False;
8458 end if;
8460 -- Private types not derived from a type having preelaborable init and
8461 -- that are not marked with pragma Preelaborable_Initialization do not
8462 -- have preelaborable initialization.
8464 elsif Is_Private_Type (E) then
8465 return False;
8467 -- Record type has PI if it is non private and all components have PI
8469 elsif Is_Record_Type (E) then
8470 Has_PE := True;
8471 Check_Components (First_Entity (E));
8473 -- Protected types must not have entries, and components must meet
8474 -- same set of rules as for record components.
8476 elsif Is_Protected_Type (E) then
8477 if Has_Entries (E) then
8478 Has_PE := False;
8479 else
8480 Has_PE := True;
8481 Check_Components (First_Entity (E));
8482 Check_Components (First_Private_Entity (E));
8483 end if;
8485 -- Type System.Address always has preelaborable initialization
8487 elsif Is_RTE (E, RE_Address) then
8488 Has_PE := True;
8490 -- In all other cases, type does not have preelaborable initialization
8492 else
8493 return False;
8494 end if;
8496 -- If type has preelaborable initialization, cache result
8498 if Has_PE then
8499 Set_Known_To_Have_Preelab_Init (E);
8500 end if;
8502 return Has_PE;
8503 end Has_Preelaborable_Initialization;
8505 ---------------------------
8506 -- Has_Private_Component --
8507 ---------------------------
8509 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
8510 Btype : Entity_Id := Base_Type (Type_Id);
8511 Component : Entity_Id;
8513 begin
8514 if Error_Posted (Type_Id)
8515 or else Error_Posted (Btype)
8516 then
8517 return False;
8518 end if;
8520 if Is_Class_Wide_Type (Btype) then
8521 Btype := Root_Type (Btype);
8522 end if;
8524 if Is_Private_Type (Btype) then
8525 declare
8526 UT : constant Entity_Id := Underlying_Type (Btype);
8527 begin
8528 if No (UT) then
8529 if No (Full_View (Btype)) then
8530 return not Is_Generic_Type (Btype)
8531 and then not Is_Generic_Type (Root_Type (Btype));
8532 else
8533 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
8534 end if;
8535 else
8536 return not Is_Frozen (UT) and then Has_Private_Component (UT);
8537 end if;
8538 end;
8540 elsif Is_Array_Type (Btype) then
8541 return Has_Private_Component (Component_Type (Btype));
8543 elsif Is_Record_Type (Btype) then
8544 Component := First_Component (Btype);
8545 while Present (Component) loop
8546 if Has_Private_Component (Etype (Component)) then
8547 return True;
8548 end if;
8550 Next_Component (Component);
8551 end loop;
8553 return False;
8555 elsif Is_Protected_Type (Btype)
8556 and then Present (Corresponding_Record_Type (Btype))
8557 then
8558 return Has_Private_Component (Corresponding_Record_Type (Btype));
8560 else
8561 return False;
8562 end if;
8563 end Has_Private_Component;
8565 ----------------------
8566 -- Has_Signed_Zeros --
8567 ----------------------
8569 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
8570 begin
8571 return Is_Floating_Point_Type (E) and then Signed_Zeros_On_Target;
8572 end Has_Signed_Zeros;
8574 -----------------------------
8575 -- Has_Static_Array_Bounds --
8576 -----------------------------
8578 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
8579 Ndims : constant Nat := Number_Dimensions (Typ);
8581 Index : Node_Id;
8582 Low : Node_Id;
8583 High : Node_Id;
8585 begin
8586 -- Unconstrained types do not have static bounds
8588 if not Is_Constrained (Typ) then
8589 return False;
8590 end if;
8592 -- First treat string literals specially, as the lower bound and length
8593 -- of string literals are not stored like those of arrays.
8595 -- A string literal always has static bounds
8597 if Ekind (Typ) = E_String_Literal_Subtype then
8598 return True;
8599 end if;
8601 -- Treat all dimensions in turn
8603 Index := First_Index (Typ);
8604 for Indx in 1 .. Ndims loop
8606 -- In case of an illegal index which is not a discrete type, return
8607 -- that the type is not static.
8609 if not Is_Discrete_Type (Etype (Index))
8610 or else Etype (Index) = Any_Type
8611 then
8612 return False;
8613 end if;
8615 Get_Index_Bounds (Index, Low, High);
8617 if Error_Posted (Low) or else Error_Posted (High) then
8618 return False;
8619 end if;
8621 if Is_OK_Static_Expression (Low)
8622 and then
8623 Is_OK_Static_Expression (High)
8624 then
8625 null;
8626 else
8627 return False;
8628 end if;
8630 Next (Index);
8631 end loop;
8633 -- If we fall through the loop, all indexes matched
8635 return True;
8636 end Has_Static_Array_Bounds;
8638 ----------------
8639 -- Has_Stream --
8640 ----------------
8642 function Has_Stream (T : Entity_Id) return Boolean is
8643 E : Entity_Id;
8645 begin
8646 if No (T) then
8647 return False;
8649 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
8650 return True;
8652 elsif Is_Array_Type (T) then
8653 return Has_Stream (Component_Type (T));
8655 elsif Is_Record_Type (T) then
8656 E := First_Component (T);
8657 while Present (E) loop
8658 if Has_Stream (Etype (E)) then
8659 return True;
8660 else
8661 Next_Component (E);
8662 end if;
8663 end loop;
8665 return False;
8667 elsif Is_Private_Type (T) then
8668 return Has_Stream (Underlying_Type (T));
8670 else
8671 return False;
8672 end if;
8673 end Has_Stream;
8675 ----------------
8676 -- Has_Suffix --
8677 ----------------
8679 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
8680 begin
8681 Get_Name_String (Chars (E));
8682 return Name_Buffer (Name_Len) = Suffix;
8683 end Has_Suffix;
8685 ----------------
8686 -- Add_Suffix --
8687 ----------------
8689 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8690 begin
8691 Get_Name_String (Chars (E));
8692 Add_Char_To_Name_Buffer (Suffix);
8693 return Name_Find;
8694 end Add_Suffix;
8696 -------------------
8697 -- Remove_Suffix --
8698 -------------------
8700 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8701 begin
8702 pragma Assert (Has_Suffix (E, Suffix));
8703 Get_Name_String (Chars (E));
8704 Name_Len := Name_Len - 1;
8705 return Name_Find;
8706 end Remove_Suffix;
8708 --------------------------
8709 -- Has_Tagged_Component --
8710 --------------------------
8712 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
8713 Comp : Entity_Id;
8715 begin
8716 if Is_Private_Type (Typ)
8717 and then Present (Underlying_Type (Typ))
8718 then
8719 return Has_Tagged_Component (Underlying_Type (Typ));
8721 elsif Is_Array_Type (Typ) then
8722 return Has_Tagged_Component (Component_Type (Typ));
8724 elsif Is_Tagged_Type (Typ) then
8725 return True;
8727 elsif Is_Record_Type (Typ) then
8728 Comp := First_Component (Typ);
8729 while Present (Comp) loop
8730 if Has_Tagged_Component (Etype (Comp)) then
8731 return True;
8732 end if;
8734 Next_Component (Comp);
8735 end loop;
8737 return False;
8739 else
8740 return False;
8741 end if;
8742 end Has_Tagged_Component;
8744 ----------------------------
8745 -- Has_Volatile_Component --
8746 ----------------------------
8748 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
8749 Comp : Entity_Id;
8751 begin
8752 if Has_Volatile_Components (Typ) then
8753 return True;
8755 elsif Is_Array_Type (Typ) then
8756 return Is_Volatile (Component_Type (Typ));
8758 elsif Is_Record_Type (Typ) then
8759 Comp := First_Component (Typ);
8760 while Present (Comp) loop
8761 if Is_Volatile_Object (Comp) then
8762 return True;
8763 end if;
8765 Comp := Next_Component (Comp);
8766 end loop;
8767 end if;
8769 return False;
8770 end Has_Volatile_Component;
8772 -------------------------
8773 -- Implementation_Kind --
8774 -------------------------
8776 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
8777 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
8778 Arg : Node_Id;
8779 begin
8780 pragma Assert (Present (Impl_Prag));
8781 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
8782 return Chars (Get_Pragma_Arg (Arg));
8783 end Implementation_Kind;
8785 --------------------------
8786 -- Implements_Interface --
8787 --------------------------
8789 function Implements_Interface
8790 (Typ_Ent : Entity_Id;
8791 Iface_Ent : Entity_Id;
8792 Exclude_Parents : Boolean := False) return Boolean
8794 Ifaces_List : Elist_Id;
8795 Elmt : Elmt_Id;
8796 Iface : Entity_Id := Base_Type (Iface_Ent);
8797 Typ : Entity_Id := Base_Type (Typ_Ent);
8799 begin
8800 if Is_Class_Wide_Type (Typ) then
8801 Typ := Root_Type (Typ);
8802 end if;
8804 if not Has_Interfaces (Typ) then
8805 return False;
8806 end if;
8808 if Is_Class_Wide_Type (Iface) then
8809 Iface := Root_Type (Iface);
8810 end if;
8812 Collect_Interfaces (Typ, Ifaces_List);
8814 Elmt := First_Elmt (Ifaces_List);
8815 while Present (Elmt) loop
8816 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
8817 and then Exclude_Parents
8818 then
8819 null;
8821 elsif Node (Elmt) = Iface then
8822 return True;
8823 end if;
8825 Next_Elmt (Elmt);
8826 end loop;
8828 return False;
8829 end Implements_Interface;
8831 ------------------------------------
8832 -- In_Assertion_Expression_Pragma --
8833 ------------------------------------
8835 function In_Assertion_Expression_Pragma (N : Node_Id) return Boolean is
8836 Par : Node_Id;
8837 Prag : Node_Id := Empty;
8839 begin
8840 -- Climb the parent chain looking for an enclosing pragma
8842 Par := N;
8843 while Present (Par) loop
8844 if Nkind (Par) = N_Pragma then
8845 Prag := Par;
8846 exit;
8848 -- Precondition-like pragmas are expanded into if statements, check
8849 -- the original node instead.
8851 elsif Nkind (Original_Node (Par)) = N_Pragma then
8852 Prag := Original_Node (Par);
8853 exit;
8855 -- The expansion of attribute 'Old generates a constant to capture
8856 -- the result of the prefix. If the parent traversal reaches
8857 -- one of these constants, then the node technically came from a
8858 -- postcondition-like pragma. Note that the Ekind is not tested here
8859 -- because N may be the expression of an object declaration which is
8860 -- currently being analyzed. Such objects carry Ekind of E_Void.
8862 elsif Nkind (Par) = N_Object_Declaration
8863 and then Constant_Present (Par)
8864 and then Stores_Attribute_Old_Prefix (Defining_Entity (Par))
8865 then
8866 return True;
8868 -- Prevent the search from going too far
8870 elsif Is_Body_Or_Package_Declaration (Par) then
8871 return False;
8872 end if;
8874 Par := Parent (Par);
8875 end loop;
8877 return
8878 Present (Prag)
8879 and then Assertion_Expression_Pragma (Get_Pragma_Id (Prag));
8880 end In_Assertion_Expression_Pragma;
8882 -----------------
8883 -- In_Instance --
8884 -----------------
8886 function In_Instance return Boolean is
8887 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
8888 S : Entity_Id;
8890 begin
8891 S := Current_Scope;
8892 while Present (S) and then S /= Standard_Standard loop
8893 if (Ekind (S) = E_Function
8894 or else Ekind (S) = E_Package
8895 or else Ekind (S) = E_Procedure)
8896 and then Is_Generic_Instance (S)
8897 then
8898 -- A child instance is always compiled in the context of a parent
8899 -- instance. Nevertheless, the actuals are not analyzed in an
8900 -- instance context. We detect this case by examining the current
8901 -- compilation unit, which must be a child instance, and checking
8902 -- that it is not currently on the scope stack.
8904 if Is_Child_Unit (Curr_Unit)
8905 and then Nkind (Unit (Cunit (Current_Sem_Unit))) =
8906 N_Package_Instantiation
8907 and then not In_Open_Scopes (Curr_Unit)
8908 then
8909 return False;
8910 else
8911 return True;
8912 end if;
8913 end if;
8915 S := Scope (S);
8916 end loop;
8918 return False;
8919 end In_Instance;
8921 ----------------------
8922 -- In_Instance_Body --
8923 ----------------------
8925 function In_Instance_Body return Boolean is
8926 S : Entity_Id;
8928 begin
8929 S := Current_Scope;
8930 while Present (S) and then S /= Standard_Standard loop
8931 if Ekind_In (S, E_Function, E_Procedure)
8932 and then Is_Generic_Instance (S)
8933 then
8934 return True;
8936 elsif Ekind (S) = E_Package
8937 and then In_Package_Body (S)
8938 and then Is_Generic_Instance (S)
8939 then
8940 return True;
8941 end if;
8943 S := Scope (S);
8944 end loop;
8946 return False;
8947 end In_Instance_Body;
8949 -----------------------------
8950 -- In_Instance_Not_Visible --
8951 -----------------------------
8953 function In_Instance_Not_Visible return Boolean is
8954 S : Entity_Id;
8956 begin
8957 S := Current_Scope;
8958 while Present (S) and then S /= Standard_Standard loop
8959 if Ekind_In (S, E_Function, E_Procedure)
8960 and then Is_Generic_Instance (S)
8961 then
8962 return True;
8964 elsif Ekind (S) = E_Package
8965 and then (In_Package_Body (S) or else In_Private_Part (S))
8966 and then Is_Generic_Instance (S)
8967 then
8968 return True;
8969 end if;
8971 S := Scope (S);
8972 end loop;
8974 return False;
8975 end In_Instance_Not_Visible;
8977 ------------------------------
8978 -- In_Instance_Visible_Part --
8979 ------------------------------
8981 function In_Instance_Visible_Part return Boolean is
8982 S : Entity_Id;
8984 begin
8985 S := Current_Scope;
8986 while Present (S) and then S /= Standard_Standard loop
8987 if Ekind (S) = E_Package
8988 and then Is_Generic_Instance (S)
8989 and then not In_Package_Body (S)
8990 and then not In_Private_Part (S)
8991 then
8992 return True;
8993 end if;
8995 S := Scope (S);
8996 end loop;
8998 return False;
8999 end In_Instance_Visible_Part;
9001 ---------------------
9002 -- In_Package_Body --
9003 ---------------------
9005 function In_Package_Body return Boolean is
9006 S : Entity_Id;
9008 begin
9009 S := Current_Scope;
9010 while Present (S) and then S /= Standard_Standard loop
9011 if Ekind (S) = E_Package and then In_Package_Body (S) then
9012 return True;
9013 else
9014 S := Scope (S);
9015 end if;
9016 end loop;
9018 return False;
9019 end In_Package_Body;
9021 --------------------------------
9022 -- In_Parameter_Specification --
9023 --------------------------------
9025 function In_Parameter_Specification (N : Node_Id) return Boolean is
9026 PN : Node_Id;
9028 begin
9029 PN := Parent (N);
9030 while Present (PN) loop
9031 if Nkind (PN) = N_Parameter_Specification then
9032 return True;
9033 end if;
9035 PN := Parent (PN);
9036 end loop;
9038 return False;
9039 end In_Parameter_Specification;
9041 --------------------------
9042 -- In_Pragma_Expression --
9043 --------------------------
9045 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
9046 P : Node_Id;
9047 begin
9048 P := Parent (N);
9049 loop
9050 if No (P) then
9051 return False;
9052 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
9053 return True;
9054 else
9055 P := Parent (P);
9056 end if;
9057 end loop;
9058 end In_Pragma_Expression;
9060 -------------------------------------
9061 -- In_Reverse_Storage_Order_Object --
9062 -------------------------------------
9064 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
9065 Pref : Node_Id;
9066 Btyp : Entity_Id := Empty;
9068 begin
9069 -- Climb up indexed components
9071 Pref := N;
9072 loop
9073 case Nkind (Pref) is
9074 when N_Selected_Component =>
9075 Pref := Prefix (Pref);
9076 exit;
9078 when N_Indexed_Component =>
9079 Pref := Prefix (Pref);
9081 when others =>
9082 Pref := Empty;
9083 exit;
9084 end case;
9085 end loop;
9087 if Present (Pref) then
9088 Btyp := Base_Type (Etype (Pref));
9089 end if;
9091 return Present (Btyp)
9092 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
9093 and then Reverse_Storage_Order (Btyp);
9094 end In_Reverse_Storage_Order_Object;
9096 --------------------------------------
9097 -- In_Subprogram_Or_Concurrent_Unit --
9098 --------------------------------------
9100 function In_Subprogram_Or_Concurrent_Unit return Boolean is
9101 E : Entity_Id;
9102 K : Entity_Kind;
9104 begin
9105 -- Use scope chain to check successively outer scopes
9107 E := Current_Scope;
9108 loop
9109 K := Ekind (E);
9111 if K in Subprogram_Kind
9112 or else K in Concurrent_Kind
9113 or else K in Generic_Subprogram_Kind
9114 then
9115 return True;
9117 elsif E = Standard_Standard then
9118 return False;
9119 end if;
9121 E := Scope (E);
9122 end loop;
9123 end In_Subprogram_Or_Concurrent_Unit;
9125 ---------------------
9126 -- In_Visible_Part --
9127 ---------------------
9129 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
9130 begin
9131 return Is_Package_Or_Generic_Package (Scope_Id)
9132 and then In_Open_Scopes (Scope_Id)
9133 and then not In_Package_Body (Scope_Id)
9134 and then not In_Private_Part (Scope_Id);
9135 end In_Visible_Part;
9137 --------------------------------
9138 -- Incomplete_Or_Private_View --
9139 --------------------------------
9141 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
9142 function Inspect_Decls
9143 (Decls : List_Id;
9144 Taft : Boolean := False) return Entity_Id;
9145 -- Check whether a declarative region contains the incomplete or private
9146 -- view of Typ.
9148 -------------------
9149 -- Inspect_Decls --
9150 -------------------
9152 function Inspect_Decls
9153 (Decls : List_Id;
9154 Taft : Boolean := False) return Entity_Id
9156 Decl : Node_Id;
9157 Match : Node_Id;
9159 begin
9160 Decl := First (Decls);
9161 while Present (Decl) loop
9162 Match := Empty;
9164 if Taft then
9165 if Nkind (Decl) = N_Incomplete_Type_Declaration then
9166 Match := Defining_Identifier (Decl);
9167 end if;
9169 else
9170 if Nkind_In (Decl, N_Private_Extension_Declaration,
9171 N_Private_Type_Declaration)
9172 then
9173 Match := Defining_Identifier (Decl);
9174 end if;
9175 end if;
9177 if Present (Match)
9178 and then Present (Full_View (Match))
9179 and then Full_View (Match) = Typ
9180 then
9181 return Match;
9182 end if;
9184 Next (Decl);
9185 end loop;
9187 return Empty;
9188 end Inspect_Decls;
9190 -- Local variables
9192 Prev : Entity_Id;
9194 -- Start of processing for Incomplete_Or_Partial_View
9196 begin
9197 -- Incomplete type case
9199 Prev := Current_Entity_In_Scope (Typ);
9201 if Present (Prev)
9202 and then Is_Incomplete_Type (Prev)
9203 and then Present (Full_View (Prev))
9204 and then Full_View (Prev) = Typ
9205 then
9206 return Prev;
9207 end if;
9209 -- Private or Taft amendment type case
9211 declare
9212 Pkg : constant Entity_Id := Scope (Typ);
9213 Pkg_Decl : Node_Id := Pkg;
9215 begin
9216 if Ekind (Pkg) = E_Package then
9217 while Nkind (Pkg_Decl) /= N_Package_Specification loop
9218 Pkg_Decl := Parent (Pkg_Decl);
9219 end loop;
9221 -- It is knows that Typ has a private view, look for it in the
9222 -- visible declarations of the enclosing scope. A special case
9223 -- of this is when the two views have been exchanged - the full
9224 -- appears earlier than the private.
9226 if Has_Private_Declaration (Typ) then
9227 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
9229 -- Exchanged view case, look in the private declarations
9231 if No (Prev) then
9232 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
9233 end if;
9235 return Prev;
9237 -- Otherwise if this is the package body, then Typ is a potential
9238 -- Taft amendment type. The incomplete view should be located in
9239 -- the private declarations of the enclosing scope.
9241 elsif In_Package_Body (Pkg) then
9242 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
9243 end if;
9244 end if;
9245 end;
9247 -- The type has no incomplete or private view
9249 return Empty;
9250 end Incomplete_Or_Private_View;
9252 -----------------------------------------
9253 -- Inherit_Default_Init_Cond_Procedure --
9254 -----------------------------------------
9256 procedure Inherit_Default_Init_Cond_Procedure (Typ : Entity_Id) is
9257 Par_Typ : constant Entity_Id := Etype (Typ);
9259 begin
9260 -- A derived type inherits the default initial condition procedure of
9261 -- its parent type.
9263 if No (Default_Init_Cond_Procedure (Typ)) then
9264 Set_Default_Init_Cond_Procedure
9265 (Typ, Default_Init_Cond_Procedure (Par_Typ));
9266 end if;
9267 end Inherit_Default_Init_Cond_Procedure;
9269 ---------------------------------
9270 -- Insert_Explicit_Dereference --
9271 ---------------------------------
9273 procedure Insert_Explicit_Dereference (N : Node_Id) is
9274 New_Prefix : constant Node_Id := Relocate_Node (N);
9275 Ent : Entity_Id := Empty;
9276 Pref : Node_Id;
9277 I : Interp_Index;
9278 It : Interp;
9279 T : Entity_Id;
9281 begin
9282 Save_Interps (N, New_Prefix);
9284 Rewrite (N,
9285 Make_Explicit_Dereference (Sloc (Parent (N)),
9286 Prefix => New_Prefix));
9288 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
9290 if Is_Overloaded (New_Prefix) then
9292 -- The dereference is also overloaded, and its interpretations are
9293 -- the designated types of the interpretations of the original node.
9295 Set_Etype (N, Any_Type);
9297 Get_First_Interp (New_Prefix, I, It);
9298 while Present (It.Nam) loop
9299 T := It.Typ;
9301 if Is_Access_Type (T) then
9302 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
9303 end if;
9305 Get_Next_Interp (I, It);
9306 end loop;
9308 End_Interp_List;
9310 else
9311 -- Prefix is unambiguous: mark the original prefix (which might
9312 -- Come_From_Source) as a reference, since the new (relocated) one
9313 -- won't be taken into account.
9315 if Is_Entity_Name (New_Prefix) then
9316 Ent := Entity (New_Prefix);
9317 Pref := New_Prefix;
9319 -- For a retrieval of a subcomponent of some composite object,
9320 -- retrieve the ultimate entity if there is one.
9322 elsif Nkind_In (New_Prefix, N_Selected_Component,
9323 N_Indexed_Component)
9324 then
9325 Pref := Prefix (New_Prefix);
9326 while Present (Pref)
9327 and then Nkind_In (Pref, N_Selected_Component,
9328 N_Indexed_Component)
9329 loop
9330 Pref := Prefix (Pref);
9331 end loop;
9333 if Present (Pref) and then Is_Entity_Name (Pref) then
9334 Ent := Entity (Pref);
9335 end if;
9336 end if;
9338 -- Place the reference on the entity node
9340 if Present (Ent) then
9341 Generate_Reference (Ent, Pref);
9342 end if;
9343 end if;
9344 end Insert_Explicit_Dereference;
9346 ------------------------------------------
9347 -- Inspect_Deferred_Constant_Completion --
9348 ------------------------------------------
9350 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
9351 Decl : Node_Id;
9353 begin
9354 Decl := First (Decls);
9355 while Present (Decl) loop
9357 -- Deferred constant signature
9359 if Nkind (Decl) = N_Object_Declaration
9360 and then Constant_Present (Decl)
9361 and then No (Expression (Decl))
9363 -- No need to check internally generated constants
9365 and then Comes_From_Source (Decl)
9367 -- The constant is not completed. A full object declaration or a
9368 -- pragma Import complete a deferred constant.
9370 and then not Has_Completion (Defining_Identifier (Decl))
9371 then
9372 Error_Msg_N
9373 ("constant declaration requires initialization expression",
9374 Defining_Identifier (Decl));
9375 end if;
9377 Decl := Next (Decl);
9378 end loop;
9379 end Inspect_Deferred_Constant_Completion;
9381 -----------------------------
9382 -- Is_Actual_Out_Parameter --
9383 -----------------------------
9385 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
9386 Formal : Entity_Id;
9387 Call : Node_Id;
9388 begin
9389 Find_Actual (N, Formal, Call);
9390 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
9391 end Is_Actual_Out_Parameter;
9393 -------------------------
9394 -- Is_Actual_Parameter --
9395 -------------------------
9397 function Is_Actual_Parameter (N : Node_Id) return Boolean is
9398 PK : constant Node_Kind := Nkind (Parent (N));
9400 begin
9401 case PK is
9402 when N_Parameter_Association =>
9403 return N = Explicit_Actual_Parameter (Parent (N));
9405 when N_Subprogram_Call =>
9406 return Is_List_Member (N)
9407 and then
9408 List_Containing (N) = Parameter_Associations (Parent (N));
9410 when others =>
9411 return False;
9412 end case;
9413 end Is_Actual_Parameter;
9415 --------------------------------
9416 -- Is_Actual_Tagged_Parameter --
9417 --------------------------------
9419 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
9420 Formal : Entity_Id;
9421 Call : Node_Id;
9422 begin
9423 Find_Actual (N, Formal, Call);
9424 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
9425 end Is_Actual_Tagged_Parameter;
9427 ---------------------
9428 -- Is_Aliased_View --
9429 ---------------------
9431 function Is_Aliased_View (Obj : Node_Id) return Boolean is
9432 E : Entity_Id;
9434 begin
9435 if Is_Entity_Name (Obj) then
9436 E := Entity (Obj);
9438 return
9439 (Is_Object (E)
9440 and then
9441 (Is_Aliased (E)
9442 or else (Present (Renamed_Object (E))
9443 and then Is_Aliased_View (Renamed_Object (E)))))
9445 or else ((Is_Formal (E)
9446 or else Ekind (E) = E_Generic_In_Out_Parameter
9447 or else Ekind (E) = E_Generic_In_Parameter)
9448 and then Is_Tagged_Type (Etype (E)))
9450 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
9452 -- Current instance of type, either directly or as rewritten
9453 -- reference to the current object.
9455 or else (Is_Entity_Name (Original_Node (Obj))
9456 and then Present (Entity (Original_Node (Obj)))
9457 and then Is_Type (Entity (Original_Node (Obj))))
9459 or else (Is_Type (E) and then E = Current_Scope)
9461 or else (Is_Incomplete_Or_Private_Type (E)
9462 and then Full_View (E) = Current_Scope)
9464 -- Ada 2012 AI05-0053: the return object of an extended return
9465 -- statement is aliased if its type is immutably limited.
9467 or else (Is_Return_Object (E)
9468 and then Is_Limited_View (Etype (E)));
9470 elsif Nkind (Obj) = N_Selected_Component then
9471 return Is_Aliased (Entity (Selector_Name (Obj)));
9473 elsif Nkind (Obj) = N_Indexed_Component then
9474 return Has_Aliased_Components (Etype (Prefix (Obj)))
9475 or else
9476 (Is_Access_Type (Etype (Prefix (Obj)))
9477 and then Has_Aliased_Components
9478 (Designated_Type (Etype (Prefix (Obj)))));
9480 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
9481 return Is_Tagged_Type (Etype (Obj))
9482 and then Is_Aliased_View (Expression (Obj));
9484 elsif Nkind (Obj) = N_Explicit_Dereference then
9485 return Nkind (Original_Node (Obj)) /= N_Function_Call;
9487 else
9488 return False;
9489 end if;
9490 end Is_Aliased_View;
9492 -------------------------
9493 -- Is_Ancestor_Package --
9494 -------------------------
9496 function Is_Ancestor_Package
9497 (E1 : Entity_Id;
9498 E2 : Entity_Id) return Boolean
9500 Par : Entity_Id;
9502 begin
9503 Par := E2;
9504 while Present (Par) and then Par /= Standard_Standard loop
9505 if Par = E1 then
9506 return True;
9507 end if;
9509 Par := Scope (Par);
9510 end loop;
9512 return False;
9513 end Is_Ancestor_Package;
9515 ----------------------
9516 -- Is_Atomic_Object --
9517 ----------------------
9519 function Is_Atomic_Object (N : Node_Id) return Boolean is
9521 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
9522 -- Determines if given object has atomic components
9524 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
9525 -- If prefix is an implicit dereference, examine designated type
9527 ----------------------
9528 -- Is_Atomic_Prefix --
9529 ----------------------
9531 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
9532 begin
9533 if Is_Access_Type (Etype (N)) then
9534 return
9535 Has_Atomic_Components (Designated_Type (Etype (N)));
9536 else
9537 return Object_Has_Atomic_Components (N);
9538 end if;
9539 end Is_Atomic_Prefix;
9541 ----------------------------------
9542 -- Object_Has_Atomic_Components --
9543 ----------------------------------
9545 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
9546 begin
9547 if Has_Atomic_Components (Etype (N))
9548 or else Is_Atomic (Etype (N))
9549 then
9550 return True;
9552 elsif Is_Entity_Name (N)
9553 and then (Has_Atomic_Components (Entity (N))
9554 or else Is_Atomic (Entity (N)))
9555 then
9556 return True;
9558 elsif Nkind (N) = N_Selected_Component
9559 and then Is_Atomic (Entity (Selector_Name (N)))
9560 then
9561 return True;
9563 elsif Nkind (N) = N_Indexed_Component
9564 or else Nkind (N) = N_Selected_Component
9565 then
9566 return Is_Atomic_Prefix (Prefix (N));
9568 else
9569 return False;
9570 end if;
9571 end Object_Has_Atomic_Components;
9573 -- Start of processing for Is_Atomic_Object
9575 begin
9576 -- Predicate is not relevant to subprograms
9578 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
9579 return False;
9581 elsif Is_Atomic (Etype (N))
9582 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
9583 then
9584 return True;
9586 elsif Nkind (N) = N_Selected_Component
9587 and then Is_Atomic (Entity (Selector_Name (N)))
9588 then
9589 return True;
9591 elsif Nkind (N) = N_Indexed_Component
9592 or else Nkind (N) = N_Selected_Component
9593 then
9594 return Is_Atomic_Prefix (Prefix (N));
9596 else
9597 return False;
9598 end if;
9599 end Is_Atomic_Object;
9601 -------------------------
9602 -- Is_Attribute_Result --
9603 -------------------------
9605 function Is_Attribute_Result (N : Node_Id) return Boolean is
9606 begin
9607 return Nkind (N) = N_Attribute_Reference
9608 and then Attribute_Name (N) = Name_Result;
9609 end Is_Attribute_Result;
9611 ------------------------------------
9612 -- Is_Body_Or_Package_Declaration --
9613 ------------------------------------
9615 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
9616 begin
9617 return Nkind_In (N, N_Entry_Body,
9618 N_Package_Body,
9619 N_Package_Declaration,
9620 N_Protected_Body,
9621 N_Subprogram_Body,
9622 N_Task_Body);
9623 end Is_Body_Or_Package_Declaration;
9625 -----------------------
9626 -- Is_Bounded_String --
9627 -----------------------
9629 function Is_Bounded_String (T : Entity_Id) return Boolean is
9630 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
9632 begin
9633 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9634 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9635 -- be True for all the Bounded_String types in instances of the
9636 -- Generic_Bounded_Length generics, and for types derived from those.
9638 return Present (Under)
9639 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
9640 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
9641 Is_RTE (Root_Type (Under), RO_WW_Super_String));
9642 end Is_Bounded_String;
9644 -------------------------
9645 -- Is_Child_Or_Sibling --
9646 -------------------------
9648 function Is_Child_Or_Sibling
9649 (Pack_1 : Entity_Id;
9650 Pack_2 : Entity_Id) return Boolean
9652 function Distance_From_Standard (Pack : Entity_Id) return Nat;
9653 -- Given an arbitrary package, return the number of "climbs" necessary
9654 -- to reach scope Standard_Standard.
9656 procedure Equalize_Depths
9657 (Pack : in out Entity_Id;
9658 Depth : in out Nat;
9659 Depth_To_Reach : Nat);
9660 -- Given an arbitrary package, its depth and a target depth to reach,
9661 -- climb the scope chain until the said depth is reached. The pointer
9662 -- to the package and its depth a modified during the climb.
9664 ----------------------------
9665 -- Distance_From_Standard --
9666 ----------------------------
9668 function Distance_From_Standard (Pack : Entity_Id) return Nat is
9669 Dist : Nat;
9670 Scop : Entity_Id;
9672 begin
9673 Dist := 0;
9674 Scop := Pack;
9675 while Present (Scop) and then Scop /= Standard_Standard loop
9676 Dist := Dist + 1;
9677 Scop := Scope (Scop);
9678 end loop;
9680 return Dist;
9681 end Distance_From_Standard;
9683 ---------------------
9684 -- Equalize_Depths --
9685 ---------------------
9687 procedure Equalize_Depths
9688 (Pack : in out Entity_Id;
9689 Depth : in out Nat;
9690 Depth_To_Reach : Nat)
9692 begin
9693 -- The package must be at a greater or equal depth
9695 if Depth < Depth_To_Reach then
9696 raise Program_Error;
9697 end if;
9699 -- Climb the scope chain until the desired depth is reached
9701 while Present (Pack) and then Depth /= Depth_To_Reach loop
9702 Pack := Scope (Pack);
9703 Depth := Depth - 1;
9704 end loop;
9705 end Equalize_Depths;
9707 -- Local variables
9709 P_1 : Entity_Id := Pack_1;
9710 P_1_Child : Boolean := False;
9711 P_1_Depth : Nat := Distance_From_Standard (P_1);
9712 P_2 : Entity_Id := Pack_2;
9713 P_2_Child : Boolean := False;
9714 P_2_Depth : Nat := Distance_From_Standard (P_2);
9716 -- Start of processing for Is_Child_Or_Sibling
9718 begin
9719 pragma Assert
9720 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
9722 -- Both packages denote the same entity, therefore they cannot be
9723 -- children or siblings.
9725 if P_1 = P_2 then
9726 return False;
9728 -- One of the packages is at a deeper level than the other. Note that
9729 -- both may still come from differen hierarchies.
9731 -- (root) P_2
9732 -- / \ :
9733 -- X P_2 or X
9734 -- : :
9735 -- P_1 P_1
9737 elsif P_1_Depth > P_2_Depth then
9738 Equalize_Depths
9739 (Pack => P_1,
9740 Depth => P_1_Depth,
9741 Depth_To_Reach => P_2_Depth);
9742 P_1_Child := True;
9744 -- (root) P_1
9745 -- / \ :
9746 -- P_1 X or X
9747 -- : :
9748 -- P_2 P_2
9750 elsif P_2_Depth > P_1_Depth then
9751 Equalize_Depths
9752 (Pack => P_2,
9753 Depth => P_2_Depth,
9754 Depth_To_Reach => P_1_Depth);
9755 P_2_Child := True;
9756 end if;
9758 -- At this stage the package pointers have been elevated to the same
9759 -- depth. If the related entities are the same, then one package is a
9760 -- potential child of the other:
9762 -- P_1
9763 -- :
9764 -- X became P_1 P_2 or vica versa
9765 -- :
9766 -- P_2
9768 if P_1 = P_2 then
9769 if P_1_Child then
9770 return Is_Child_Unit (Pack_1);
9772 else pragma Assert (P_2_Child);
9773 return Is_Child_Unit (Pack_2);
9774 end if;
9776 -- The packages may come from the same package chain or from entirely
9777 -- different hierarcies. To determine this, climb the scope stack until
9778 -- a common root is found.
9780 -- (root) (root 1) (root 2)
9781 -- / \ | |
9782 -- P_1 P_2 P_1 P_2
9784 else
9785 while Present (P_1) and then Present (P_2) loop
9787 -- The two packages may be siblings
9789 if P_1 = P_2 then
9790 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
9791 end if;
9793 P_1 := Scope (P_1);
9794 P_2 := Scope (P_2);
9795 end loop;
9796 end if;
9798 return False;
9799 end Is_Child_Or_Sibling;
9801 -----------------------------
9802 -- Is_Concurrent_Interface --
9803 -----------------------------
9805 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
9806 begin
9807 return Is_Interface (T)
9808 and then
9809 (Is_Protected_Interface (T)
9810 or else Is_Synchronized_Interface (T)
9811 or else Is_Task_Interface (T));
9812 end Is_Concurrent_Interface;
9814 ---------------------------
9815 -- Is_Container_Element --
9816 ---------------------------
9818 function Is_Container_Element (Exp : Node_Id) return Boolean is
9819 Loc : constant Source_Ptr := Sloc (Exp);
9820 Pref : constant Node_Id := Prefix (Exp);
9822 Call : Node_Id;
9823 -- Call to an indexing aspect
9825 Cont_Typ : Entity_Id;
9826 -- The type of the container being accessed
9828 Elem_Typ : Entity_Id;
9829 -- Its element type
9831 Indexing : Entity_Id;
9832 Is_Const : Boolean;
9833 -- Indicates that constant indexing is used, and the element is thus
9834 -- a constant.
9836 Ref_Typ : Entity_Id;
9837 -- The reference type returned by the indexing operation
9839 begin
9840 -- If C is a container, in a context that imposes the element type of
9841 -- that container, the indexing notation C (X) is rewritten as:
9843 -- Indexing (C, X).Discr.all
9845 -- where Indexing is one of the indexing aspects of the container.
9846 -- If the context does not require a reference, the construct can be
9847 -- rewritten as
9849 -- Element (C, X)
9851 -- First, verify that the construct has the proper form
9853 if not Expander_Active then
9854 return False;
9856 elsif Nkind (Pref) /= N_Selected_Component then
9857 return False;
9859 elsif Nkind (Prefix (Pref)) /= N_Function_Call then
9860 return False;
9862 else
9863 Call := Prefix (Pref);
9864 Ref_Typ := Etype (Call);
9865 end if;
9867 if not Has_Implicit_Dereference (Ref_Typ)
9868 or else No (First (Parameter_Associations (Call)))
9869 or else not Is_Entity_Name (Name (Call))
9870 then
9871 return False;
9872 end if;
9874 -- Retrieve type of container object, and its iterator aspects
9876 Cont_Typ := Etype (First (Parameter_Associations (Call)));
9877 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Constant_Indexing);
9878 Is_Const := False;
9880 if No (Indexing) then
9882 -- Container should have at least one indexing operation
9884 return False;
9886 elsif Entity (Name (Call)) /= Entity (Indexing) then
9888 -- This may be a variable indexing operation
9890 Indexing := Find_Value_Of_Aspect (Cont_Typ, Aspect_Variable_Indexing);
9892 if No (Indexing)
9893 or else Entity (Name (Call)) /= Entity (Indexing)
9894 then
9895 return False;
9896 end if;
9898 else
9899 Is_Const := True;
9900 end if;
9902 Elem_Typ := Find_Value_Of_Aspect (Cont_Typ, Aspect_Iterator_Element);
9904 if No (Elem_Typ) or else Entity (Elem_Typ) /= Etype (Exp) then
9905 return False;
9906 end if;
9908 -- Check that the expression is not the target of an assignment, in
9909 -- which case the rewriting is not possible.
9911 if not Is_Const then
9912 declare
9913 Par : Node_Id;
9915 begin
9916 Par := Exp;
9917 while Present (Par)
9918 loop
9919 if Nkind (Parent (Par)) = N_Assignment_Statement
9920 and then Par = Name (Parent (Par))
9921 then
9922 return False;
9924 -- A renaming produces a reference, and the transformation
9925 -- does not apply.
9927 elsif Nkind (Parent (Par)) = N_Object_Renaming_Declaration then
9928 return False;
9930 elsif Nkind_In
9931 (Nkind (Parent (Par)), N_Function_Call,
9932 N_Procedure_Call_Statement,
9933 N_Entry_Call_Statement)
9934 then
9935 -- Check that the element is not part of an actual for an
9936 -- in-out parameter.
9938 declare
9939 F : Entity_Id;
9940 A : Node_Id;
9942 begin
9943 F := First_Formal (Entity (Name (Parent (Par))));
9944 A := First (Parameter_Associations (Parent (Par)));
9945 while Present (F) loop
9946 if A = Par and then Ekind (F) /= E_In_Parameter then
9947 return False;
9948 end if;
9950 Next_Formal (F);
9951 Next (A);
9952 end loop;
9953 end;
9955 -- E_In_Parameter in a call: element is not modified.
9957 exit;
9958 end if;
9960 Par := Parent (Par);
9961 end loop;
9962 end;
9963 end if;
9965 -- The expression has the proper form and the context requires the
9966 -- element type. Retrieve the Element function of the container and
9967 -- rewrite the construct as a call to it.
9969 declare
9970 Op : Elmt_Id;
9972 begin
9973 Op := First_Elmt (Primitive_Operations (Cont_Typ));
9974 while Present (Op) loop
9975 exit when Chars (Node (Op)) = Name_Element;
9976 Next_Elmt (Op);
9977 end loop;
9979 if No (Op) then
9980 return False;
9982 else
9983 Rewrite (Exp,
9984 Make_Function_Call (Loc,
9985 Name => New_Occurrence_Of (Node (Op), Loc),
9986 Parameter_Associations => Parameter_Associations (Call)));
9987 Analyze_And_Resolve (Exp, Entity (Elem_Typ));
9988 return True;
9989 end if;
9990 end;
9991 end Is_Container_Element;
9993 -----------------------
9994 -- Is_Constant_Bound --
9995 -----------------------
9997 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
9998 begin
9999 if Compile_Time_Known_Value (Exp) then
10000 return True;
10002 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
10003 return Is_Constant_Object (Entity (Exp))
10004 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
10006 elsif Nkind (Exp) in N_Binary_Op then
10007 return Is_Constant_Bound (Left_Opnd (Exp))
10008 and then Is_Constant_Bound (Right_Opnd (Exp))
10009 and then Scope (Entity (Exp)) = Standard_Standard;
10011 else
10012 return False;
10013 end if;
10014 end Is_Constant_Bound;
10016 --------------------------------------
10017 -- Is_Controlling_Limited_Procedure --
10018 --------------------------------------
10020 function Is_Controlling_Limited_Procedure
10021 (Proc_Nam : Entity_Id) return Boolean
10023 Param_Typ : Entity_Id := Empty;
10025 begin
10026 if Ekind (Proc_Nam) = E_Procedure
10027 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
10028 then
10029 Param_Typ := Etype (Parameter_Type (First (
10030 Parameter_Specifications (Parent (Proc_Nam)))));
10032 -- In this case where an Itype was created, the procedure call has been
10033 -- rewritten.
10035 elsif Present (Associated_Node_For_Itype (Proc_Nam))
10036 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
10037 and then
10038 Present (Parameter_Associations
10039 (Associated_Node_For_Itype (Proc_Nam)))
10040 then
10041 Param_Typ :=
10042 Etype (First (Parameter_Associations
10043 (Associated_Node_For_Itype (Proc_Nam))));
10044 end if;
10046 if Present (Param_Typ) then
10047 return
10048 Is_Interface (Param_Typ)
10049 and then Is_Limited_Record (Param_Typ);
10050 end if;
10052 return False;
10053 end Is_Controlling_Limited_Procedure;
10055 -----------------------------
10056 -- Is_CPP_Constructor_Call --
10057 -----------------------------
10059 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
10060 begin
10061 return Nkind (N) = N_Function_Call
10062 and then Is_CPP_Class (Etype (Etype (N)))
10063 and then Is_Constructor (Entity (Name (N)))
10064 and then Is_Imported (Entity (Name (N)));
10065 end Is_CPP_Constructor_Call;
10067 -----------------
10068 -- Is_Delegate --
10069 -----------------
10071 function Is_Delegate (T : Entity_Id) return Boolean is
10072 Desig_Type : Entity_Id;
10074 begin
10075 if VM_Target /= CLI_Target then
10076 return False;
10077 end if;
10079 -- Access-to-subprograms are delegates in CIL
10081 if Ekind (T) = E_Access_Subprogram_Type then
10082 return True;
10083 end if;
10085 if not Is_Access_Type (T) then
10087 -- A delegate is a managed pointer. If no designated type is defined
10088 -- it means that it's not a delegate.
10090 return False;
10091 end if;
10093 Desig_Type := Etype (Directly_Designated_Type (T));
10095 if not Is_Tagged_Type (Desig_Type) then
10096 return False;
10097 end if;
10099 -- Test if the type is inherited from [mscorlib]System.Delegate
10101 while Etype (Desig_Type) /= Desig_Type loop
10102 if Chars (Scope (Desig_Type)) /= No_Name
10103 and then Is_Imported (Scope (Desig_Type))
10104 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
10105 then
10106 return True;
10107 end if;
10109 Desig_Type := Etype (Desig_Type);
10110 end loop;
10112 return False;
10113 end Is_Delegate;
10115 ----------------------------------------------
10116 -- Is_Dependent_Component_Of_Mutable_Object --
10117 ----------------------------------------------
10119 function Is_Dependent_Component_Of_Mutable_Object
10120 (Object : Node_Id) return Boolean
10122 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
10123 -- Returns True if and only if Comp is declared within a variant part
10125 --------------------------------
10126 -- Is_Declared_Within_Variant --
10127 --------------------------------
10129 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
10130 Comp_Decl : constant Node_Id := Parent (Comp);
10131 Comp_List : constant Node_Id := Parent (Comp_Decl);
10132 begin
10133 return Nkind (Parent (Comp_List)) = N_Variant;
10134 end Is_Declared_Within_Variant;
10136 P : Node_Id;
10137 Prefix_Type : Entity_Id;
10138 P_Aliased : Boolean := False;
10139 Comp : Entity_Id;
10141 Deref : Node_Id := Object;
10142 -- Dereference node, in something like X.all.Y(2)
10144 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10146 begin
10147 -- Find the dereference node if any
10149 while Nkind_In (Deref, N_Indexed_Component,
10150 N_Selected_Component,
10151 N_Slice)
10152 loop
10153 Deref := Prefix (Deref);
10154 end loop;
10156 -- Ada 2005: If we have a component or slice of a dereference,
10157 -- something like X.all.Y (2), and the type of X is access-to-constant,
10158 -- Is_Variable will return False, because it is indeed a constant
10159 -- view. But it might be a view of a variable object, so we want the
10160 -- following condition to be True in that case.
10162 if Is_Variable (Object)
10163 or else (Ada_Version >= Ada_2005
10164 and then Nkind (Deref) = N_Explicit_Dereference)
10165 then
10166 if Nkind (Object) = N_Selected_Component then
10167 P := Prefix (Object);
10168 Prefix_Type := Etype (P);
10170 if Is_Entity_Name (P) then
10171 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
10172 Prefix_Type := Base_Type (Prefix_Type);
10173 end if;
10175 if Is_Aliased (Entity (P)) then
10176 P_Aliased := True;
10177 end if;
10179 -- A discriminant check on a selected component may be expanded
10180 -- into a dereference when removing side-effects. Recover the
10181 -- original node and its type, which may be unconstrained.
10183 elsif Nkind (P) = N_Explicit_Dereference
10184 and then not (Comes_From_Source (P))
10185 then
10186 P := Original_Node (P);
10187 Prefix_Type := Etype (P);
10189 else
10190 -- Check for prefix being an aliased component???
10192 null;
10194 end if;
10196 -- A heap object is constrained by its initial value
10198 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10199 -- the dereferenced case, since the access value might denote an
10200 -- unconstrained aliased object, whereas in Ada 95 the designated
10201 -- object is guaranteed to be constrained. A worst-case assumption
10202 -- has to apply in Ada 2005 because we can't tell at compile
10203 -- time whether the object is "constrained by its initial value"
10204 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10205 -- rules (these rules are acknowledged to need fixing).
10207 if Ada_Version < Ada_2005 then
10208 if Is_Access_Type (Prefix_Type)
10209 or else Nkind (P) = N_Explicit_Dereference
10210 then
10211 return False;
10212 end if;
10214 else pragma Assert (Ada_Version >= Ada_2005);
10215 if Is_Access_Type (Prefix_Type) then
10217 -- If the access type is pool-specific, and there is no
10218 -- constrained partial view of the designated type, then the
10219 -- designated object is known to be constrained.
10221 if Ekind (Prefix_Type) = E_Access_Type
10222 and then not Object_Type_Has_Constrained_Partial_View
10223 (Typ => Designated_Type (Prefix_Type),
10224 Scop => Current_Scope)
10225 then
10226 return False;
10228 -- Otherwise (general access type, or there is a constrained
10229 -- partial view of the designated type), we need to check
10230 -- based on the designated type.
10232 else
10233 Prefix_Type := Designated_Type (Prefix_Type);
10234 end if;
10235 end if;
10236 end if;
10238 Comp :=
10239 Original_Record_Component (Entity (Selector_Name (Object)));
10241 -- As per AI-0017, the renaming is illegal in a generic body, even
10242 -- if the subtype is indefinite.
10244 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10246 if not Is_Constrained (Prefix_Type)
10247 and then (not Is_Indefinite_Subtype (Prefix_Type)
10248 or else
10249 (Is_Generic_Type (Prefix_Type)
10250 and then Ekind (Current_Scope) = E_Generic_Package
10251 and then In_Package_Body (Current_Scope)))
10253 and then (Is_Declared_Within_Variant (Comp)
10254 or else Has_Discriminant_Dependent_Constraint (Comp))
10255 and then (not P_Aliased or else Ada_Version >= Ada_2005)
10256 then
10257 return True;
10259 -- If the prefix is of an access type at this point, then we want
10260 -- to return False, rather than calling this function recursively
10261 -- on the access object (which itself might be a discriminant-
10262 -- dependent component of some other object, but that isn't
10263 -- relevant to checking the object passed to us). This avoids
10264 -- issuing wrong errors when compiling with -gnatc, where there
10265 -- can be implicit dereferences that have not been expanded.
10267 elsif Is_Access_Type (Etype (Prefix (Object))) then
10268 return False;
10270 else
10271 return
10272 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10273 end if;
10275 elsif Nkind (Object) = N_Indexed_Component
10276 or else Nkind (Object) = N_Slice
10277 then
10278 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
10280 -- A type conversion that Is_Variable is a view conversion:
10281 -- go back to the denoted object.
10283 elsif Nkind (Object) = N_Type_Conversion then
10284 return
10285 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
10286 end if;
10287 end if;
10289 return False;
10290 end Is_Dependent_Component_Of_Mutable_Object;
10292 ---------------------
10293 -- Is_Dereferenced --
10294 ---------------------
10296 function Is_Dereferenced (N : Node_Id) return Boolean is
10297 P : constant Node_Id := Parent (N);
10298 begin
10299 return Nkind_In (P, N_Selected_Component,
10300 N_Explicit_Dereference,
10301 N_Indexed_Component,
10302 N_Slice)
10303 and then Prefix (P) = N;
10304 end Is_Dereferenced;
10306 ----------------------
10307 -- Is_Descendent_Of --
10308 ----------------------
10310 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
10311 T : Entity_Id;
10312 Etyp : Entity_Id;
10314 begin
10315 pragma Assert (Nkind (T1) in N_Entity);
10316 pragma Assert (Nkind (T2) in N_Entity);
10318 T := Base_Type (T1);
10320 -- Immediate return if the types match
10322 if T = T2 then
10323 return True;
10325 -- Comment needed here ???
10327 elsif Ekind (T) = E_Class_Wide_Type then
10328 return Etype (T) = T2;
10330 -- All other cases
10332 else
10333 loop
10334 Etyp := Etype (T);
10336 -- Done if we found the type we are looking for
10338 if Etyp = T2 then
10339 return True;
10341 -- Done if no more derivations to check
10343 elsif T = T1
10344 or else T = Etyp
10345 then
10346 return False;
10348 -- Following test catches error cases resulting from prev errors
10350 elsif No (Etyp) then
10351 return False;
10353 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
10354 return False;
10356 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
10357 return False;
10358 end if;
10360 T := Base_Type (Etyp);
10361 end loop;
10362 end if;
10363 end Is_Descendent_Of;
10365 -----------------------------
10366 -- Is_Effectively_Volatile --
10367 -----------------------------
10369 function Is_Effectively_Volatile (Id : Entity_Id) return Boolean is
10370 begin
10371 if Is_Type (Id) then
10373 -- An arbitrary type is effectively volatile when it is subject to
10374 -- pragma Atomic or Volatile.
10376 if Is_Volatile (Id) then
10377 return True;
10379 -- An array type is effectively volatile when it is subject to pragma
10380 -- Atomic_Components or Volatile_Components or its compolent type is
10381 -- effectively volatile.
10383 elsif Is_Array_Type (Id) then
10384 return
10385 Has_Volatile_Components (Id)
10386 or else
10387 Is_Effectively_Volatile (Component_Type (Base_Type (Id)));
10389 else
10390 return False;
10391 end if;
10393 -- Otherwise Id denotes an object
10395 else
10396 return
10397 Is_Volatile (Id)
10398 or else Has_Volatile_Components (Id)
10399 or else Is_Effectively_Volatile (Etype (Id));
10400 end if;
10401 end Is_Effectively_Volatile;
10403 ------------------------------------
10404 -- Is_Effectively_Volatile_Object --
10405 ------------------------------------
10407 function Is_Effectively_Volatile_Object (N : Node_Id) return Boolean is
10408 begin
10409 if Is_Entity_Name (N) then
10410 return Is_Effectively_Volatile (Entity (N));
10412 elsif Nkind (N) = N_Expanded_Name then
10413 return Is_Effectively_Volatile (Entity (N));
10415 elsif Nkind (N) = N_Indexed_Component then
10416 return Is_Effectively_Volatile_Object (Prefix (N));
10418 elsif Nkind (N) = N_Selected_Component then
10419 return
10420 Is_Effectively_Volatile_Object (Prefix (N))
10421 or else
10422 Is_Effectively_Volatile_Object (Selector_Name (N));
10424 else
10425 return False;
10426 end if;
10427 end Is_Effectively_Volatile_Object;
10429 ----------------------------
10430 -- Is_Expression_Function --
10431 ----------------------------
10433 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
10434 Decl : Node_Id;
10436 begin
10437 if Ekind (Subp) /= E_Function then
10438 return False;
10440 else
10441 Decl := Unit_Declaration_Node (Subp);
10442 return Nkind (Decl) = N_Subprogram_Declaration
10443 and then
10444 (Nkind (Original_Node (Decl)) = N_Expression_Function
10445 or else
10446 (Present (Corresponding_Body (Decl))
10447 and then
10448 Nkind (Original_Node
10449 (Unit_Declaration_Node
10450 (Corresponding_Body (Decl)))) =
10451 N_Expression_Function));
10452 end if;
10453 end Is_Expression_Function;
10455 --------------
10456 -- Is_False --
10457 --------------
10459 function Is_False (U : Uint) return Boolean is
10460 begin
10461 return (U = 0);
10462 end Is_False;
10464 ---------------------------
10465 -- Is_Fixed_Model_Number --
10466 ---------------------------
10468 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
10469 S : constant Ureal := Small_Value (T);
10470 M : Urealp.Save_Mark;
10471 R : Boolean;
10472 begin
10473 M := Urealp.Mark;
10474 R := (U = UR_Trunc (U / S) * S);
10475 Urealp.Release (M);
10476 return R;
10477 end Is_Fixed_Model_Number;
10479 -------------------------------
10480 -- Is_Fully_Initialized_Type --
10481 -------------------------------
10483 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
10484 begin
10485 -- In Ada2012, a scalar type with an aspect Default_Value
10486 -- is fully initialized.
10488 if Is_Scalar_Type (Typ) then
10489 return Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ);
10491 elsif Is_Access_Type (Typ) then
10492 return True;
10494 elsif Is_Array_Type (Typ) then
10495 if Is_Fully_Initialized_Type (Component_Type (Typ))
10496 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
10497 then
10498 return True;
10499 end if;
10501 -- An interesting case, if we have a constrained type one of whose
10502 -- bounds is known to be null, then there are no elements to be
10503 -- initialized, so all the elements are initialized.
10505 if Is_Constrained (Typ) then
10506 declare
10507 Indx : Node_Id;
10508 Indx_Typ : Entity_Id;
10509 Lbd, Hbd : Node_Id;
10511 begin
10512 Indx := First_Index (Typ);
10513 while Present (Indx) loop
10514 if Etype (Indx) = Any_Type then
10515 return False;
10517 -- If index is a range, use directly
10519 elsif Nkind (Indx) = N_Range then
10520 Lbd := Low_Bound (Indx);
10521 Hbd := High_Bound (Indx);
10523 else
10524 Indx_Typ := Etype (Indx);
10526 if Is_Private_Type (Indx_Typ) then
10527 Indx_Typ := Full_View (Indx_Typ);
10528 end if;
10530 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
10531 return False;
10532 else
10533 Lbd := Type_Low_Bound (Indx_Typ);
10534 Hbd := Type_High_Bound (Indx_Typ);
10535 end if;
10536 end if;
10538 if Compile_Time_Known_Value (Lbd)
10539 and then
10540 Compile_Time_Known_Value (Hbd)
10541 then
10542 if Expr_Value (Hbd) < Expr_Value (Lbd) then
10543 return True;
10544 end if;
10545 end if;
10547 Next_Index (Indx);
10548 end loop;
10549 end;
10550 end if;
10552 -- If no null indexes, then type is not fully initialized
10554 return False;
10556 -- Record types
10558 elsif Is_Record_Type (Typ) then
10559 if Has_Discriminants (Typ)
10560 and then
10561 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
10562 and then Is_Fully_Initialized_Variant (Typ)
10563 then
10564 return True;
10565 end if;
10567 -- We consider bounded string types to be fully initialized, because
10568 -- otherwise we get false alarms when the Data component is not
10569 -- default-initialized.
10571 if Is_Bounded_String (Typ) then
10572 return True;
10573 end if;
10575 -- Controlled records are considered to be fully initialized if
10576 -- there is a user defined Initialize routine. This may not be
10577 -- entirely correct, but as the spec notes, we are guessing here
10578 -- what is best from the point of view of issuing warnings.
10580 if Is_Controlled (Typ) then
10581 declare
10582 Utyp : constant Entity_Id := Underlying_Type (Typ);
10584 begin
10585 if Present (Utyp) then
10586 declare
10587 Init : constant Entity_Id :=
10588 (Find_Prim_Op
10589 (Underlying_Type (Typ), Name_Initialize));
10591 begin
10592 if Present (Init)
10593 and then Comes_From_Source (Init)
10594 and then not
10595 Is_Predefined_File_Name
10596 (File_Name (Get_Source_File_Index (Sloc (Init))))
10597 then
10598 return True;
10600 elsif Has_Null_Extension (Typ)
10601 and then
10602 Is_Fully_Initialized_Type
10603 (Etype (Base_Type (Typ)))
10604 then
10605 return True;
10606 end if;
10607 end;
10608 end if;
10609 end;
10610 end if;
10612 -- Otherwise see if all record components are initialized
10614 declare
10615 Ent : Entity_Id;
10617 begin
10618 Ent := First_Entity (Typ);
10619 while Present (Ent) loop
10620 if Ekind (Ent) = E_Component
10621 and then (No (Parent (Ent))
10622 or else No (Expression (Parent (Ent))))
10623 and then not Is_Fully_Initialized_Type (Etype (Ent))
10625 -- Special VM case for tag components, which need to be
10626 -- defined in this case, but are never initialized as VMs
10627 -- are using other dispatching mechanisms. Ignore this
10628 -- uninitialized case. Note that this applies both to the
10629 -- uTag entry and the main vtable pointer (CPP_Class case).
10631 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
10632 then
10633 return False;
10634 end if;
10636 Next_Entity (Ent);
10637 end loop;
10638 end;
10640 -- No uninitialized components, so type is fully initialized.
10641 -- Note that this catches the case of no components as well.
10643 return True;
10645 elsif Is_Concurrent_Type (Typ) then
10646 return True;
10648 elsif Is_Private_Type (Typ) then
10649 declare
10650 U : constant Entity_Id := Underlying_Type (Typ);
10652 begin
10653 if No (U) then
10654 return False;
10655 else
10656 return Is_Fully_Initialized_Type (U);
10657 end if;
10658 end;
10660 else
10661 return False;
10662 end if;
10663 end Is_Fully_Initialized_Type;
10665 ----------------------------------
10666 -- Is_Fully_Initialized_Variant --
10667 ----------------------------------
10669 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
10670 Loc : constant Source_Ptr := Sloc (Typ);
10671 Constraints : constant List_Id := New_List;
10672 Components : constant Elist_Id := New_Elmt_List;
10673 Comp_Elmt : Elmt_Id;
10674 Comp_Id : Node_Id;
10675 Comp_List : Node_Id;
10676 Discr : Entity_Id;
10677 Discr_Val : Node_Id;
10679 Report_Errors : Boolean;
10680 pragma Warnings (Off, Report_Errors);
10682 begin
10683 if Serious_Errors_Detected > 0 then
10684 return False;
10685 end if;
10687 if Is_Record_Type (Typ)
10688 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
10689 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
10690 then
10691 Comp_List := Component_List (Type_Definition (Parent (Typ)));
10693 Discr := First_Discriminant (Typ);
10694 while Present (Discr) loop
10695 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
10696 Discr_Val := Expression (Parent (Discr));
10698 if Present (Discr_Val)
10699 and then Is_OK_Static_Expression (Discr_Val)
10700 then
10701 Append_To (Constraints,
10702 Make_Component_Association (Loc,
10703 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
10704 Expression => New_Copy (Discr_Val)));
10705 else
10706 return False;
10707 end if;
10708 else
10709 return False;
10710 end if;
10712 Next_Discriminant (Discr);
10713 end loop;
10715 Gather_Components
10716 (Typ => Typ,
10717 Comp_List => Comp_List,
10718 Governed_By => Constraints,
10719 Into => Components,
10720 Report_Errors => Report_Errors);
10722 -- Check that each component present is fully initialized
10724 Comp_Elmt := First_Elmt (Components);
10725 while Present (Comp_Elmt) loop
10726 Comp_Id := Node (Comp_Elmt);
10728 if Ekind (Comp_Id) = E_Component
10729 and then (No (Parent (Comp_Id))
10730 or else No (Expression (Parent (Comp_Id))))
10731 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
10732 then
10733 return False;
10734 end if;
10736 Next_Elmt (Comp_Elmt);
10737 end loop;
10739 return True;
10741 elsif Is_Private_Type (Typ) then
10742 declare
10743 U : constant Entity_Id := Underlying_Type (Typ);
10745 begin
10746 if No (U) then
10747 return False;
10748 else
10749 return Is_Fully_Initialized_Variant (U);
10750 end if;
10751 end;
10753 else
10754 return False;
10755 end if;
10756 end Is_Fully_Initialized_Variant;
10758 ----------------------------
10759 -- Is_Inherited_Operation --
10760 ----------------------------
10762 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
10763 pragma Assert (Is_Overloadable (E));
10764 Kind : constant Node_Kind := Nkind (Parent (E));
10765 begin
10766 return Kind = N_Full_Type_Declaration
10767 or else Kind = N_Private_Extension_Declaration
10768 or else Kind = N_Subtype_Declaration
10769 or else (Ekind (E) = E_Enumeration_Literal
10770 and then Is_Derived_Type (Etype (E)));
10771 end Is_Inherited_Operation;
10773 -------------------------------------
10774 -- Is_Inherited_Operation_For_Type --
10775 -------------------------------------
10777 function Is_Inherited_Operation_For_Type
10778 (E : Entity_Id;
10779 Typ : Entity_Id) return Boolean
10781 begin
10782 -- Check that the operation has been created by the type declaration
10784 return Is_Inherited_Operation (E)
10785 and then Defining_Identifier (Parent (E)) = Typ;
10786 end Is_Inherited_Operation_For_Type;
10788 -----------------
10789 -- Is_Iterator --
10790 -----------------
10792 function Is_Iterator (Typ : Entity_Id) return Boolean is
10793 Ifaces_List : Elist_Id;
10794 Iface_Elmt : Elmt_Id;
10795 Iface : Entity_Id;
10797 begin
10798 if Is_Class_Wide_Type (Typ)
10799 and then Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
10800 Name_Reversible_Iterator)
10801 and then
10802 Is_Predefined_File_Name
10803 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
10804 then
10805 return True;
10807 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
10808 return False;
10810 elsif Present (Find_Value_Of_Aspect (Typ, Aspect_Iterable)) then
10811 return True;
10813 else
10814 Collect_Interfaces (Typ, Ifaces_List);
10816 Iface_Elmt := First_Elmt (Ifaces_List);
10817 while Present (Iface_Elmt) loop
10818 Iface := Node (Iface_Elmt);
10819 if Chars (Iface) = Name_Forward_Iterator
10820 and then
10821 Is_Predefined_File_Name
10822 (Unit_File_Name (Get_Source_Unit (Iface)))
10823 then
10824 return True;
10825 end if;
10827 Next_Elmt (Iface_Elmt);
10828 end loop;
10830 return False;
10831 end if;
10832 end Is_Iterator;
10834 ------------
10835 -- Is_LHS --
10836 ------------
10838 -- We seem to have a lot of overlapping functions that do similar things
10839 -- (testing for left hand sides or lvalues???).
10841 function Is_LHS (N : Node_Id) return Is_LHS_Result is
10842 P : constant Node_Id := Parent (N);
10844 begin
10845 -- Return True if we are the left hand side of an assignment statement
10847 if Nkind (P) = N_Assignment_Statement then
10848 if Name (P) = N then
10849 return Yes;
10850 else
10851 return No;
10852 end if;
10854 -- Case of prefix of indexed or selected component or slice
10856 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
10857 and then N = Prefix (P)
10858 then
10859 -- Here we have the case where the parent P is N.Q or N(Q .. R).
10860 -- If P is an LHS, then N is also effectively an LHS, but there
10861 -- is an important exception. If N is of an access type, then
10862 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
10863 -- case this makes N.all a left hand side but not N itself.
10865 -- If we don't know the type yet, this is the case where we return
10866 -- Unknown, since the answer depends on the type which is unknown.
10868 if No (Etype (N)) then
10869 return Unknown;
10871 -- We have an Etype set, so we can check it
10873 elsif Is_Access_Type (Etype (N)) then
10874 return No;
10876 -- OK, not access type case, so just test whole expression
10878 else
10879 return Is_LHS (P);
10880 end if;
10882 -- All other cases are not left hand sides
10884 else
10885 return No;
10886 end if;
10887 end Is_LHS;
10889 -----------------------------
10890 -- Is_Library_Level_Entity --
10891 -----------------------------
10893 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
10894 begin
10895 -- The following is a small optimization, and it also properly handles
10896 -- discriminals, which in task bodies might appear in expressions before
10897 -- the corresponding procedure has been created, and which therefore do
10898 -- not have an assigned scope.
10900 if Is_Formal (E) then
10901 return False;
10902 end if;
10904 -- Normal test is simply that the enclosing dynamic scope is Standard
10906 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
10907 end Is_Library_Level_Entity;
10909 --------------------------------
10910 -- Is_Limited_Class_Wide_Type --
10911 --------------------------------
10913 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
10914 begin
10915 return
10916 Is_Class_Wide_Type (Typ)
10917 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
10918 end Is_Limited_Class_Wide_Type;
10920 ---------------------------------
10921 -- Is_Local_Variable_Reference --
10922 ---------------------------------
10924 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
10925 begin
10926 if not Is_Entity_Name (Expr) then
10927 return False;
10929 else
10930 declare
10931 Ent : constant Entity_Id := Entity (Expr);
10932 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
10933 begin
10934 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
10935 return False;
10936 else
10937 return Present (Sub) and then Sub = Current_Subprogram;
10938 end if;
10939 end;
10940 end if;
10941 end Is_Local_Variable_Reference;
10943 -------------------------
10944 -- Is_Object_Reference --
10945 -------------------------
10947 function Is_Object_Reference (N : Node_Id) return Boolean is
10949 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
10950 -- Determine whether N is the name of an internally-generated renaming
10952 --------------------------------------
10953 -- Is_Internally_Generated_Renaming --
10954 --------------------------------------
10956 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
10957 P : Node_Id;
10959 begin
10960 P := N;
10961 while Present (P) loop
10962 if Nkind (P) = N_Object_Renaming_Declaration then
10963 return not Comes_From_Source (P);
10964 elsif Is_List_Member (P) then
10965 return False;
10966 end if;
10968 P := Parent (P);
10969 end loop;
10971 return False;
10972 end Is_Internally_Generated_Renaming;
10974 -- Start of processing for Is_Object_Reference
10976 begin
10977 if Is_Entity_Name (N) then
10978 return Present (Entity (N)) and then Is_Object (Entity (N));
10980 else
10981 case Nkind (N) is
10982 when N_Indexed_Component | N_Slice =>
10983 return
10984 Is_Object_Reference (Prefix (N))
10985 or else Is_Access_Type (Etype (Prefix (N)));
10987 -- In Ada 95, a function call is a constant object; a procedure
10988 -- call is not.
10990 when N_Function_Call =>
10991 return Etype (N) /= Standard_Void_Type;
10993 -- Attributes 'Input, 'Old and 'Result produce objects
10995 when N_Attribute_Reference =>
10996 return
10997 Nam_In
10998 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
11000 when N_Selected_Component =>
11001 return
11002 Is_Object_Reference (Selector_Name (N))
11003 and then
11004 (Is_Object_Reference (Prefix (N))
11005 or else Is_Access_Type (Etype (Prefix (N))));
11007 when N_Explicit_Dereference =>
11008 return True;
11010 -- A view conversion of a tagged object is an object reference
11012 when N_Type_Conversion =>
11013 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
11014 and then Is_Tagged_Type (Etype (Expression (N)))
11015 and then Is_Object_Reference (Expression (N));
11017 -- An unchecked type conversion is considered to be an object if
11018 -- the operand is an object (this construction arises only as a
11019 -- result of expansion activities).
11021 when N_Unchecked_Type_Conversion =>
11022 return True;
11024 -- Allow string literals to act as objects as long as they appear
11025 -- in internally-generated renamings. The expansion of iterators
11026 -- may generate such renamings when the range involves a string
11027 -- literal.
11029 when N_String_Literal =>
11030 return Is_Internally_Generated_Renaming (Parent (N));
11032 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11033 -- This allows disambiguation of function calls and the use
11034 -- of aggregates in more contexts.
11036 when N_Qualified_Expression =>
11037 if Ada_Version < Ada_2012 then
11038 return False;
11039 else
11040 return Is_Object_Reference (Expression (N))
11041 or else Nkind (Expression (N)) = N_Aggregate;
11042 end if;
11044 when others =>
11045 return False;
11046 end case;
11047 end if;
11048 end Is_Object_Reference;
11050 -----------------------------------
11051 -- Is_OK_Variable_For_Out_Formal --
11052 -----------------------------------
11054 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
11055 begin
11056 Note_Possible_Modification (AV, Sure => True);
11058 -- We must reject parenthesized variable names. Comes_From_Source is
11059 -- checked because there are currently cases where the compiler violates
11060 -- this rule (e.g. passing a task object to its controlled Initialize
11061 -- routine). This should be properly documented in sinfo???
11063 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
11064 return False;
11066 -- A variable is always allowed
11068 elsif Is_Variable (AV) then
11069 return True;
11071 -- Unchecked conversions are allowed only if they come from the
11072 -- generated code, which sometimes uses unchecked conversions for out
11073 -- parameters in cases where code generation is unaffected. We tell
11074 -- source unchecked conversions by seeing if they are rewrites of
11075 -- an original Unchecked_Conversion function call, or of an explicit
11076 -- conversion of a function call or an aggregate (as may happen in the
11077 -- expansion of a packed array aggregate).
11079 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
11080 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
11081 return False;
11083 elsif Comes_From_Source (AV)
11084 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
11085 then
11086 return False;
11088 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
11089 return Is_OK_Variable_For_Out_Formal (Expression (AV));
11091 else
11092 return True;
11093 end if;
11095 -- Normal type conversions are allowed if argument is a variable
11097 elsif Nkind (AV) = N_Type_Conversion then
11098 if Is_Variable (Expression (AV))
11099 and then Paren_Count (Expression (AV)) = 0
11100 then
11101 Note_Possible_Modification (Expression (AV), Sure => True);
11102 return True;
11104 -- We also allow a non-parenthesized expression that raises
11105 -- constraint error if it rewrites what used to be a variable
11107 elsif Raises_Constraint_Error (Expression (AV))
11108 and then Paren_Count (Expression (AV)) = 0
11109 and then Is_Variable (Original_Node (Expression (AV)))
11110 then
11111 return True;
11113 -- Type conversion of something other than a variable
11115 else
11116 return False;
11117 end if;
11119 -- If this node is rewritten, then test the original form, if that is
11120 -- OK, then we consider the rewritten node OK (for example, if the
11121 -- original node is a conversion, then Is_Variable will not be true
11122 -- but we still want to allow the conversion if it converts a variable).
11124 elsif Original_Node (AV) /= AV then
11126 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11127 -- Reference function.
11129 if Ada_Version >= Ada_2012
11130 and then Nkind (Original_Node (AV)) = N_Function_Call
11131 and then
11132 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
11133 then
11134 return True;
11136 else
11137 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
11138 end if;
11140 -- All other non-variables are rejected
11142 else
11143 return False;
11144 end if;
11145 end Is_OK_Variable_For_Out_Formal;
11147 -----------------------------------
11148 -- Is_Partially_Initialized_Type --
11149 -----------------------------------
11151 function Is_Partially_Initialized_Type
11152 (Typ : Entity_Id;
11153 Include_Implicit : Boolean := True) return Boolean
11155 begin
11156 if Is_Scalar_Type (Typ) then
11157 return False;
11159 elsif Is_Access_Type (Typ) then
11160 return Include_Implicit;
11162 elsif Is_Array_Type (Typ) then
11164 -- If component type is partially initialized, so is array type
11166 if Is_Partially_Initialized_Type
11167 (Component_Type (Typ), Include_Implicit)
11168 then
11169 return True;
11171 -- Otherwise we are only partially initialized if we are fully
11172 -- initialized (this is the empty array case, no point in us
11173 -- duplicating that code here).
11175 else
11176 return Is_Fully_Initialized_Type (Typ);
11177 end if;
11179 elsif Is_Record_Type (Typ) then
11181 -- A discriminated type is always partially initialized if in
11182 -- all mode
11184 if Has_Discriminants (Typ) and then Include_Implicit then
11185 return True;
11187 -- A tagged type is always partially initialized
11189 elsif Is_Tagged_Type (Typ) then
11190 return True;
11192 -- Case of non-discriminated record
11194 else
11195 declare
11196 Ent : Entity_Id;
11198 Component_Present : Boolean := False;
11199 -- Set True if at least one component is present. If no
11200 -- components are present, then record type is fully
11201 -- initialized (another odd case, like the null array).
11203 begin
11204 -- Loop through components
11206 Ent := First_Entity (Typ);
11207 while Present (Ent) loop
11208 if Ekind (Ent) = E_Component then
11209 Component_Present := True;
11211 -- If a component has an initialization expression then
11212 -- the enclosing record type is partially initialized
11214 if Present (Parent (Ent))
11215 and then Present (Expression (Parent (Ent)))
11216 then
11217 return True;
11219 -- If a component is of a type which is itself partially
11220 -- initialized, then the enclosing record type is also.
11222 elsif Is_Partially_Initialized_Type
11223 (Etype (Ent), Include_Implicit)
11224 then
11225 return True;
11226 end if;
11227 end if;
11229 Next_Entity (Ent);
11230 end loop;
11232 -- No initialized components found. If we found any components
11233 -- they were all uninitialized so the result is false.
11235 if Component_Present then
11236 return False;
11238 -- But if we found no components, then all the components are
11239 -- initialized so we consider the type to be initialized.
11241 else
11242 return True;
11243 end if;
11244 end;
11245 end if;
11247 -- Concurrent types are always fully initialized
11249 elsif Is_Concurrent_Type (Typ) then
11250 return True;
11252 -- For a private type, go to underlying type. If there is no underlying
11253 -- type then just assume this partially initialized. Not clear if this
11254 -- can happen in a non-error case, but no harm in testing for this.
11256 elsif Is_Private_Type (Typ) then
11257 declare
11258 U : constant Entity_Id := Underlying_Type (Typ);
11259 begin
11260 if No (U) then
11261 return True;
11262 else
11263 return Is_Partially_Initialized_Type (U, Include_Implicit);
11264 end if;
11265 end;
11267 -- For any other type (are there any?) assume partially initialized
11269 else
11270 return True;
11271 end if;
11272 end Is_Partially_Initialized_Type;
11274 ------------------------------------
11275 -- Is_Potentially_Persistent_Type --
11276 ------------------------------------
11278 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
11279 Comp : Entity_Id;
11280 Indx : Node_Id;
11282 begin
11283 -- For private type, test corresponding full type
11285 if Is_Private_Type (T) then
11286 return Is_Potentially_Persistent_Type (Full_View (T));
11288 -- Scalar types are potentially persistent
11290 elsif Is_Scalar_Type (T) then
11291 return True;
11293 -- Record type is potentially persistent if not tagged and the types of
11294 -- all it components are potentially persistent, and no component has
11295 -- an initialization expression.
11297 elsif Is_Record_Type (T)
11298 and then not Is_Tagged_Type (T)
11299 and then not Is_Partially_Initialized_Type (T)
11300 then
11301 Comp := First_Component (T);
11302 while Present (Comp) loop
11303 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
11304 return False;
11305 else
11306 Next_Entity (Comp);
11307 end if;
11308 end loop;
11310 return True;
11312 -- Array type is potentially persistent if its component type is
11313 -- potentially persistent and if all its constraints are static.
11315 elsif Is_Array_Type (T) then
11316 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
11317 return False;
11318 end if;
11320 Indx := First_Index (T);
11321 while Present (Indx) loop
11322 if not Is_OK_Static_Subtype (Etype (Indx)) then
11323 return False;
11324 else
11325 Next_Index (Indx);
11326 end if;
11327 end loop;
11329 return True;
11331 -- All other types are not potentially persistent
11333 else
11334 return False;
11335 end if;
11336 end Is_Potentially_Persistent_Type;
11338 --------------------------------
11339 -- Is_Potentially_Unevaluated --
11340 --------------------------------
11342 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
11343 Par : Node_Id;
11344 Expr : Node_Id;
11346 begin
11347 Expr := N;
11348 Par := Parent (N);
11350 -- A postcondition whose expression is a short-circuit is broken down
11351 -- into individual aspects for better exception reporting. The original
11352 -- short-circuit expression is rewritten as the second operand, and an
11353 -- occurrence of 'Old in that operand is potentially unevaluated.
11354 -- See Sem_ch13.adb for details of this transformation.
11356 if Nkind (Original_Node (Par)) = N_And_Then then
11357 return True;
11358 end if;
11360 while not Nkind_In (Par, N_If_Expression,
11361 N_Case_Expression,
11362 N_And_Then,
11363 N_Or_Else,
11364 N_In,
11365 N_Not_In)
11366 loop
11367 Expr := Par;
11368 Par := Parent (Par);
11370 -- If the context is not an expression, or if is the result of
11371 -- expansion of an enclosing construct (such as another attribute)
11372 -- the predicate does not apply.
11374 if Nkind (Par) not in N_Subexpr
11375 or else not Comes_From_Source (Par)
11376 then
11377 return False;
11378 end if;
11379 end loop;
11381 if Nkind (Par) = N_If_Expression then
11382 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
11384 elsif Nkind (Par) = N_Case_Expression then
11385 return Expr /= Expression (Par);
11387 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
11388 return Expr = Right_Opnd (Par);
11390 elsif Nkind_In (Par, N_In, N_Not_In) then
11391 return Expr /= Left_Opnd (Par);
11393 else
11394 return False;
11395 end if;
11396 end Is_Potentially_Unevaluated;
11398 ---------------------------------
11399 -- Is_Protected_Self_Reference --
11400 ---------------------------------
11402 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
11404 function In_Access_Definition (N : Node_Id) return Boolean;
11405 -- Returns true if N belongs to an access definition
11407 --------------------------
11408 -- In_Access_Definition --
11409 --------------------------
11411 function In_Access_Definition (N : Node_Id) return Boolean is
11412 P : Node_Id;
11414 begin
11415 P := Parent (N);
11416 while Present (P) loop
11417 if Nkind (P) = N_Access_Definition then
11418 return True;
11419 end if;
11421 P := Parent (P);
11422 end loop;
11424 return False;
11425 end In_Access_Definition;
11427 -- Start of processing for Is_Protected_Self_Reference
11429 begin
11430 -- Verify that prefix is analyzed and has the proper form. Note that
11431 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11432 -- which also produce the address of an entity, do not analyze their
11433 -- prefix because they denote entities that are not necessarily visible.
11434 -- Neither of them can apply to a protected type.
11436 return Ada_Version >= Ada_2005
11437 and then Is_Entity_Name (N)
11438 and then Present (Entity (N))
11439 and then Is_Protected_Type (Entity (N))
11440 and then In_Open_Scopes (Entity (N))
11441 and then not In_Access_Definition (N);
11442 end Is_Protected_Self_Reference;
11444 -----------------------------
11445 -- Is_RCI_Pkg_Spec_Or_Body --
11446 -----------------------------
11448 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
11450 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
11451 -- Return True if the unit of Cunit is an RCI package declaration
11453 ---------------------------
11454 -- Is_RCI_Pkg_Decl_Cunit --
11455 ---------------------------
11457 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
11458 The_Unit : constant Node_Id := Unit (Cunit);
11460 begin
11461 if Nkind (The_Unit) /= N_Package_Declaration then
11462 return False;
11463 end if;
11465 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
11466 end Is_RCI_Pkg_Decl_Cunit;
11468 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11470 begin
11471 return Is_RCI_Pkg_Decl_Cunit (Cunit)
11472 or else
11473 (Nkind (Unit (Cunit)) = N_Package_Body
11474 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
11475 end Is_RCI_Pkg_Spec_Or_Body;
11477 -----------------------------------------
11478 -- Is_Remote_Access_To_Class_Wide_Type --
11479 -----------------------------------------
11481 function Is_Remote_Access_To_Class_Wide_Type
11482 (E : Entity_Id) return Boolean
11484 begin
11485 -- A remote access to class-wide type is a general access to object type
11486 -- declared in the visible part of a Remote_Types or Remote_Call_
11487 -- Interface unit.
11489 return Ekind (E) = E_General_Access_Type
11490 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11491 end Is_Remote_Access_To_Class_Wide_Type;
11493 -----------------------------------------
11494 -- Is_Remote_Access_To_Subprogram_Type --
11495 -----------------------------------------
11497 function Is_Remote_Access_To_Subprogram_Type
11498 (E : Entity_Id) return Boolean
11500 begin
11501 return (Ekind (E) = E_Access_Subprogram_Type
11502 or else (Ekind (E) = E_Record_Type
11503 and then Present (Corresponding_Remote_Type (E))))
11504 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
11505 end Is_Remote_Access_To_Subprogram_Type;
11507 --------------------
11508 -- Is_Remote_Call --
11509 --------------------
11511 function Is_Remote_Call (N : Node_Id) return Boolean is
11512 begin
11513 if Nkind (N) not in N_Subprogram_Call then
11515 -- An entry call cannot be remote
11517 return False;
11519 elsif Nkind (Name (N)) in N_Has_Entity
11520 and then Is_Remote_Call_Interface (Entity (Name (N)))
11521 then
11522 -- A subprogram declared in the spec of a RCI package is remote
11524 return True;
11526 elsif Nkind (Name (N)) = N_Explicit_Dereference
11527 and then Is_Remote_Access_To_Subprogram_Type
11528 (Etype (Prefix (Name (N))))
11529 then
11530 -- The dereference of a RAS is a remote call
11532 return True;
11534 elsif Present (Controlling_Argument (N))
11535 and then Is_Remote_Access_To_Class_Wide_Type
11536 (Etype (Controlling_Argument (N)))
11537 then
11538 -- Any primitive operation call with a controlling argument of
11539 -- a RACW type is a remote call.
11541 return True;
11542 end if;
11544 -- All other calls are local calls
11546 return False;
11547 end Is_Remote_Call;
11549 ----------------------
11550 -- Is_Renamed_Entry --
11551 ----------------------
11553 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
11554 Orig_Node : Node_Id := Empty;
11555 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
11557 function Is_Entry (Nam : Node_Id) return Boolean;
11558 -- Determine whether Nam is an entry. Traverse selectors if there are
11559 -- nested selected components.
11561 --------------
11562 -- Is_Entry --
11563 --------------
11565 function Is_Entry (Nam : Node_Id) return Boolean is
11566 begin
11567 if Nkind (Nam) = N_Selected_Component then
11568 return Is_Entry (Selector_Name (Nam));
11569 end if;
11571 return Ekind (Entity (Nam)) = E_Entry;
11572 end Is_Entry;
11574 -- Start of processing for Is_Renamed_Entry
11576 begin
11577 if Present (Alias (Proc_Nam)) then
11578 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
11579 end if;
11581 -- Look for a rewritten subprogram renaming declaration
11583 if Nkind (Subp_Decl) = N_Subprogram_Declaration
11584 and then Present (Original_Node (Subp_Decl))
11585 then
11586 Orig_Node := Original_Node (Subp_Decl);
11587 end if;
11589 -- The rewritten subprogram is actually an entry
11591 if Present (Orig_Node)
11592 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
11593 and then Is_Entry (Name (Orig_Node))
11594 then
11595 return True;
11596 end if;
11598 return False;
11599 end Is_Renamed_Entry;
11601 ----------------------------
11602 -- Is_Reversible_Iterator --
11603 ----------------------------
11605 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
11606 Ifaces_List : Elist_Id;
11607 Iface_Elmt : Elmt_Id;
11608 Iface : Entity_Id;
11610 begin
11611 if Is_Class_Wide_Type (Typ)
11612 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
11613 and then Is_Predefined_File_Name
11614 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
11615 then
11616 return True;
11618 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
11619 return False;
11621 else
11622 Collect_Interfaces (Typ, Ifaces_List);
11624 Iface_Elmt := First_Elmt (Ifaces_List);
11625 while Present (Iface_Elmt) loop
11626 Iface := Node (Iface_Elmt);
11627 if Chars (Iface) = Name_Reversible_Iterator
11628 and then
11629 Is_Predefined_File_Name
11630 (Unit_File_Name (Get_Source_Unit (Iface)))
11631 then
11632 return True;
11633 end if;
11635 Next_Elmt (Iface_Elmt);
11636 end loop;
11637 end if;
11639 return False;
11640 end Is_Reversible_Iterator;
11642 ----------------------
11643 -- Is_Selector_Name --
11644 ----------------------
11646 function Is_Selector_Name (N : Node_Id) return Boolean is
11647 begin
11648 if not Is_List_Member (N) then
11649 declare
11650 P : constant Node_Id := Parent (N);
11651 begin
11652 return Nkind_In (P, N_Expanded_Name,
11653 N_Generic_Association,
11654 N_Parameter_Association,
11655 N_Selected_Component)
11656 and then Selector_Name (P) = N;
11657 end;
11659 else
11660 declare
11661 L : constant List_Id := List_Containing (N);
11662 P : constant Node_Id := Parent (L);
11663 begin
11664 return (Nkind (P) = N_Discriminant_Association
11665 and then Selector_Names (P) = L)
11666 or else
11667 (Nkind (P) = N_Component_Association
11668 and then Choices (P) = L);
11669 end;
11670 end if;
11671 end Is_Selector_Name;
11673 -------------------------------------
11674 -- Is_SPARK_05_Initialization_Expr --
11675 -------------------------------------
11677 function Is_SPARK_05_Initialization_Expr (N : Node_Id) return Boolean is
11678 Is_Ok : Boolean;
11679 Expr : Node_Id;
11680 Comp_Assn : Node_Id;
11681 Orig_N : constant Node_Id := Original_Node (N);
11683 begin
11684 Is_Ok := True;
11686 if not Comes_From_Source (Orig_N) then
11687 goto Done;
11688 end if;
11690 pragma Assert (Nkind (Orig_N) in N_Subexpr);
11692 case Nkind (Orig_N) is
11693 when N_Character_Literal |
11694 N_Integer_Literal |
11695 N_Real_Literal |
11696 N_String_Literal =>
11697 null;
11699 when N_Identifier |
11700 N_Expanded_Name =>
11701 if Is_Entity_Name (Orig_N)
11702 and then Present (Entity (Orig_N)) -- needed in some cases
11703 then
11704 case Ekind (Entity (Orig_N)) is
11705 when E_Constant |
11706 E_Enumeration_Literal |
11707 E_Named_Integer |
11708 E_Named_Real =>
11709 null;
11710 when others =>
11711 if Is_Type (Entity (Orig_N)) then
11712 null;
11713 else
11714 Is_Ok := False;
11715 end if;
11716 end case;
11717 end if;
11719 when N_Qualified_Expression |
11720 N_Type_Conversion =>
11721 Is_Ok := Is_SPARK_05_Initialization_Expr (Expression (Orig_N));
11723 when N_Unary_Op =>
11724 Is_Ok := Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
11726 when N_Binary_Op |
11727 N_Short_Circuit |
11728 N_Membership_Test =>
11729 Is_Ok := Is_SPARK_05_Initialization_Expr (Left_Opnd (Orig_N))
11730 and then
11731 Is_SPARK_05_Initialization_Expr (Right_Opnd (Orig_N));
11733 when N_Aggregate |
11734 N_Extension_Aggregate =>
11735 if Nkind (Orig_N) = N_Extension_Aggregate then
11736 Is_Ok :=
11737 Is_SPARK_05_Initialization_Expr (Ancestor_Part (Orig_N));
11738 end if;
11740 Expr := First (Expressions (Orig_N));
11741 while Present (Expr) loop
11742 if not Is_SPARK_05_Initialization_Expr (Expr) then
11743 Is_Ok := False;
11744 goto Done;
11745 end if;
11747 Next (Expr);
11748 end loop;
11750 Comp_Assn := First (Component_Associations (Orig_N));
11751 while Present (Comp_Assn) loop
11752 Expr := Expression (Comp_Assn);
11753 if Present (Expr) -- needed for box association
11754 and then not Is_SPARK_05_Initialization_Expr (Expr)
11755 then
11756 Is_Ok := False;
11757 goto Done;
11758 end if;
11760 Next (Comp_Assn);
11761 end loop;
11763 when N_Attribute_Reference =>
11764 if Nkind (Prefix (Orig_N)) in N_Subexpr then
11765 Is_Ok := Is_SPARK_05_Initialization_Expr (Prefix (Orig_N));
11766 end if;
11768 Expr := First (Expressions (Orig_N));
11769 while Present (Expr) loop
11770 if not Is_SPARK_05_Initialization_Expr (Expr) then
11771 Is_Ok := False;
11772 goto Done;
11773 end if;
11775 Next (Expr);
11776 end loop;
11778 -- Selected components might be expanded named not yet resolved, so
11779 -- default on the safe side. (Eg on sparklex.ads)
11781 when N_Selected_Component =>
11782 null;
11784 when others =>
11785 Is_Ok := False;
11786 end case;
11788 <<Done>>
11789 return Is_Ok;
11790 end Is_SPARK_05_Initialization_Expr;
11792 ----------------------------------
11793 -- Is_SPARK_05_Object_Reference --
11794 ----------------------------------
11796 function Is_SPARK_05_Object_Reference (N : Node_Id) return Boolean is
11797 begin
11798 if Is_Entity_Name (N) then
11799 return Present (Entity (N))
11800 and then
11801 (Ekind_In (Entity (N), E_Constant, E_Variable)
11802 or else Ekind (Entity (N)) in Formal_Kind);
11804 else
11805 case Nkind (N) is
11806 when N_Selected_Component =>
11807 return Is_SPARK_05_Object_Reference (Prefix (N));
11809 when others =>
11810 return False;
11811 end case;
11812 end if;
11813 end Is_SPARK_05_Object_Reference;
11815 ------------------
11816 -- Is_Statement --
11817 ------------------
11819 function Is_Statement (N : Node_Id) return Boolean is
11820 begin
11821 return
11822 Nkind (N) in N_Statement_Other_Than_Procedure_Call
11823 or else Nkind (N) = N_Procedure_Call_Statement;
11824 end Is_Statement;
11826 --------------------------------------------------
11827 -- Is_Subprogram_Stub_Without_Prior_Declaration --
11828 --------------------------------------------------
11830 function Is_Subprogram_Stub_Without_Prior_Declaration
11831 (N : Node_Id) return Boolean
11833 begin
11834 -- A subprogram stub without prior declaration serves as declaration for
11835 -- the actual subprogram body. As such, it has an attached defining
11836 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
11838 return Nkind (N) = N_Subprogram_Body_Stub
11839 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
11840 end Is_Subprogram_Stub_Without_Prior_Declaration;
11842 ---------------------------------
11843 -- Is_Synchronized_Tagged_Type --
11844 ---------------------------------
11846 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
11847 Kind : constant Entity_Kind := Ekind (Base_Type (E));
11849 begin
11850 -- A task or protected type derived from an interface is a tagged type.
11851 -- Such a tagged type is called a synchronized tagged type, as are
11852 -- synchronized interfaces and private extensions whose declaration
11853 -- includes the reserved word synchronized.
11855 return (Is_Tagged_Type (E)
11856 and then (Kind = E_Task_Type
11857 or else Kind = E_Protected_Type))
11858 or else
11859 (Is_Interface (E)
11860 and then Is_Synchronized_Interface (E))
11861 or else
11862 (Ekind (E) = E_Record_Type_With_Private
11863 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
11864 and then (Synchronized_Present (Parent (E))
11865 or else Is_Synchronized_Interface (Etype (E))));
11866 end Is_Synchronized_Tagged_Type;
11868 -----------------
11869 -- Is_Transfer --
11870 -----------------
11872 function Is_Transfer (N : Node_Id) return Boolean is
11873 Kind : constant Node_Kind := Nkind (N);
11875 begin
11876 if Kind = N_Simple_Return_Statement
11877 or else
11878 Kind = N_Extended_Return_Statement
11879 or else
11880 Kind = N_Goto_Statement
11881 or else
11882 Kind = N_Raise_Statement
11883 or else
11884 Kind = N_Requeue_Statement
11885 then
11886 return True;
11888 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
11889 and then No (Condition (N))
11890 then
11891 return True;
11893 elsif Kind = N_Procedure_Call_Statement
11894 and then Is_Entity_Name (Name (N))
11895 and then Present (Entity (Name (N)))
11896 and then No_Return (Entity (Name (N)))
11897 then
11898 return True;
11900 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
11901 return True;
11903 else
11904 return False;
11905 end if;
11906 end Is_Transfer;
11908 -------------
11909 -- Is_True --
11910 -------------
11912 function Is_True (U : Uint) return Boolean is
11913 begin
11914 return (U /= 0);
11915 end Is_True;
11917 --------------------------------------
11918 -- Is_Unchecked_Conversion_Instance --
11919 --------------------------------------
11921 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
11922 Gen_Par : Entity_Id;
11924 begin
11925 -- Look for a function whose generic parent is the predefined intrinsic
11926 -- function Unchecked_Conversion.
11928 if Ekind (Id) = E_Function then
11929 Gen_Par := Generic_Parent (Parent (Id));
11931 return
11932 Present (Gen_Par)
11933 and then Chars (Gen_Par) = Name_Unchecked_Conversion
11934 and then Is_Intrinsic_Subprogram (Gen_Par)
11935 and then Is_Predefined_File_Name
11936 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
11937 end if;
11939 return False;
11940 end Is_Unchecked_Conversion_Instance;
11942 -------------------------------
11943 -- Is_Universal_Numeric_Type --
11944 -------------------------------
11946 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
11947 begin
11948 return T = Universal_Integer or else T = Universal_Real;
11949 end Is_Universal_Numeric_Type;
11951 -------------------
11952 -- Is_Value_Type --
11953 -------------------
11955 function Is_Value_Type (T : Entity_Id) return Boolean is
11956 begin
11957 return VM_Target = CLI_Target
11958 and then Nkind (T) in N_Has_Chars
11959 and then Chars (T) /= No_Name
11960 and then Get_Name_String (Chars (T)) = "valuetype";
11961 end Is_Value_Type;
11963 ----------------------------
11964 -- Is_Variable_Size_Array --
11965 ----------------------------
11967 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
11968 Idx : Node_Id;
11970 begin
11971 pragma Assert (Is_Array_Type (E));
11973 -- Check if some index is initialized with a non-constant value
11975 Idx := First_Index (E);
11976 while Present (Idx) loop
11977 if Nkind (Idx) = N_Range then
11978 if not Is_Constant_Bound (Low_Bound (Idx))
11979 or else not Is_Constant_Bound (High_Bound (Idx))
11980 then
11981 return True;
11982 end if;
11983 end if;
11985 Idx := Next_Index (Idx);
11986 end loop;
11988 return False;
11989 end Is_Variable_Size_Array;
11991 -----------------------------
11992 -- Is_Variable_Size_Record --
11993 -----------------------------
11995 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
11996 Comp : Entity_Id;
11997 Comp_Typ : Entity_Id;
11999 begin
12000 pragma Assert (Is_Record_Type (E));
12002 Comp := First_Entity (E);
12003 while Present (Comp) loop
12004 Comp_Typ := Etype (Comp);
12006 -- Recursive call if the record type has discriminants
12008 if Is_Record_Type (Comp_Typ)
12009 and then Has_Discriminants (Comp_Typ)
12010 and then Is_Variable_Size_Record (Comp_Typ)
12011 then
12012 return True;
12014 elsif Is_Array_Type (Comp_Typ)
12015 and then Is_Variable_Size_Array (Comp_Typ)
12016 then
12017 return True;
12018 end if;
12020 Next_Entity (Comp);
12021 end loop;
12023 return False;
12024 end Is_Variable_Size_Record;
12026 -----------------
12027 -- Is_Variable --
12028 -----------------
12030 function Is_Variable
12031 (N : Node_Id;
12032 Use_Original_Node : Boolean := True) return Boolean
12034 Orig_Node : Node_Id;
12036 function In_Protected_Function (E : Entity_Id) return Boolean;
12037 -- Within a protected function, the private components of the enclosing
12038 -- protected type are constants. A function nested within a (protected)
12039 -- procedure is not itself protected. Within the body of a protected
12040 -- function the current instance of the protected type is a constant.
12042 function Is_Variable_Prefix (P : Node_Id) return Boolean;
12043 -- Prefixes can involve implicit dereferences, in which case we must
12044 -- test for the case of a reference of a constant access type, which can
12045 -- can never be a variable.
12047 ---------------------------
12048 -- In_Protected_Function --
12049 ---------------------------
12051 function In_Protected_Function (E : Entity_Id) return Boolean is
12052 Prot : Entity_Id;
12053 S : Entity_Id;
12055 begin
12056 -- E is the current instance of a type
12058 if Is_Type (E) then
12059 Prot := E;
12061 -- E is an object
12063 else
12064 Prot := Scope (E);
12065 end if;
12067 if not Is_Protected_Type (Prot) then
12068 return False;
12070 else
12071 S := Current_Scope;
12072 while Present (S) and then S /= Prot loop
12073 if Ekind (S) = E_Function and then Scope (S) = Prot then
12074 return True;
12075 end if;
12077 S := Scope (S);
12078 end loop;
12080 return False;
12081 end if;
12082 end In_Protected_Function;
12084 ------------------------
12085 -- Is_Variable_Prefix --
12086 ------------------------
12088 function Is_Variable_Prefix (P : Node_Id) return Boolean is
12089 begin
12090 if Is_Access_Type (Etype (P)) then
12091 return not Is_Access_Constant (Root_Type (Etype (P)));
12093 -- For the case of an indexed component whose prefix has a packed
12094 -- array type, the prefix has been rewritten into a type conversion.
12095 -- Determine variable-ness from the converted expression.
12097 elsif Nkind (P) = N_Type_Conversion
12098 and then not Comes_From_Source (P)
12099 and then Is_Array_Type (Etype (P))
12100 and then Is_Packed (Etype (P))
12101 then
12102 return Is_Variable (Expression (P));
12104 else
12105 return Is_Variable (P);
12106 end if;
12107 end Is_Variable_Prefix;
12109 -- Start of processing for Is_Variable
12111 begin
12112 -- Check if we perform the test on the original node since this may be a
12113 -- test of syntactic categories which must not be disturbed by whatever
12114 -- rewriting might have occurred. For example, an aggregate, which is
12115 -- certainly NOT a variable, could be turned into a variable by
12116 -- expansion.
12118 if Use_Original_Node then
12119 Orig_Node := Original_Node (N);
12120 else
12121 Orig_Node := N;
12122 end if;
12124 -- Definitely OK if Assignment_OK is set. Since this is something that
12125 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12127 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
12128 return True;
12130 -- Normally we go to the original node, but there is one exception where
12131 -- we use the rewritten node, namely when it is an explicit dereference.
12132 -- The generated code may rewrite a prefix which is an access type with
12133 -- an explicit dereference. The dereference is a variable, even though
12134 -- the original node may not be (since it could be a constant of the
12135 -- access type).
12137 -- In Ada 2005 we have a further case to consider: the prefix may be a
12138 -- function call given in prefix notation. The original node appears to
12139 -- be a selected component, but we need to examine the call.
12141 elsif Nkind (N) = N_Explicit_Dereference
12142 and then Nkind (Orig_Node) /= N_Explicit_Dereference
12143 and then Present (Etype (Orig_Node))
12144 and then Is_Access_Type (Etype (Orig_Node))
12145 then
12146 -- Note that if the prefix is an explicit dereference that does not
12147 -- come from source, we must check for a rewritten function call in
12148 -- prefixed notation before other forms of rewriting, to prevent a
12149 -- compiler crash.
12151 return
12152 (Nkind (Orig_Node) = N_Function_Call
12153 and then not Is_Access_Constant (Etype (Prefix (N))))
12154 or else
12155 Is_Variable_Prefix (Original_Node (Prefix (N)));
12157 -- in Ada 2012, the dereference may have been added for a type with
12158 -- a declared implicit dereference aspect.
12160 elsif Nkind (N) = N_Explicit_Dereference
12161 and then Present (Etype (Orig_Node))
12162 and then Ada_Version >= Ada_2012
12163 and then Has_Implicit_Dereference (Etype (Orig_Node))
12164 then
12165 return True;
12167 -- A function call is never a variable
12169 elsif Nkind (N) = N_Function_Call then
12170 return False;
12172 -- All remaining checks use the original node
12174 elsif Is_Entity_Name (Orig_Node)
12175 and then Present (Entity (Orig_Node))
12176 then
12177 declare
12178 E : constant Entity_Id := Entity (Orig_Node);
12179 K : constant Entity_Kind := Ekind (E);
12181 begin
12182 return (K = E_Variable
12183 and then Nkind (Parent (E)) /= N_Exception_Handler)
12184 or else (K = E_Component
12185 and then not In_Protected_Function (E))
12186 or else K = E_Out_Parameter
12187 or else K = E_In_Out_Parameter
12188 or else K = E_Generic_In_Out_Parameter
12190 -- Current instance of type. If this is a protected type, check
12191 -- we are not within the body of one of its protected functions.
12193 or else (Is_Type (E)
12194 and then In_Open_Scopes (E)
12195 and then not In_Protected_Function (E))
12197 or else (Is_Incomplete_Or_Private_Type (E)
12198 and then In_Open_Scopes (Full_View (E)));
12199 end;
12201 else
12202 case Nkind (Orig_Node) is
12203 when N_Indexed_Component | N_Slice =>
12204 return Is_Variable_Prefix (Prefix (Orig_Node));
12206 when N_Selected_Component =>
12207 return (Is_Variable (Selector_Name (Orig_Node))
12208 and then Is_Variable_Prefix (Prefix (Orig_Node)))
12209 or else
12210 (Nkind (N) = N_Expanded_Name
12211 and then Scope (Entity (N)) = Entity (Prefix (N)));
12213 -- For an explicit dereference, the type of the prefix cannot
12214 -- be an access to constant or an access to subprogram.
12216 when N_Explicit_Dereference =>
12217 declare
12218 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
12219 begin
12220 return Is_Access_Type (Typ)
12221 and then not Is_Access_Constant (Root_Type (Typ))
12222 and then Ekind (Typ) /= E_Access_Subprogram_Type;
12223 end;
12225 -- The type conversion is the case where we do not deal with the
12226 -- context dependent special case of an actual parameter. Thus
12227 -- the type conversion is only considered a variable for the
12228 -- purposes of this routine if the target type is tagged. However,
12229 -- a type conversion is considered to be a variable if it does not
12230 -- come from source (this deals for example with the conversions
12231 -- of expressions to their actual subtypes).
12233 when N_Type_Conversion =>
12234 return Is_Variable (Expression (Orig_Node))
12235 and then
12236 (not Comes_From_Source (Orig_Node)
12237 or else
12238 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
12239 and then
12240 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
12242 -- GNAT allows an unchecked type conversion as a variable. This
12243 -- only affects the generation of internal expanded code, since
12244 -- calls to instantiations of Unchecked_Conversion are never
12245 -- considered variables (since they are function calls).
12247 when N_Unchecked_Type_Conversion =>
12248 return Is_Variable (Expression (Orig_Node));
12250 when others =>
12251 return False;
12252 end case;
12253 end if;
12254 end Is_Variable;
12256 ---------------------------
12257 -- Is_Visibly_Controlled --
12258 ---------------------------
12260 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
12261 Root : constant Entity_Id := Root_Type (T);
12262 begin
12263 return Chars (Scope (Root)) = Name_Finalization
12264 and then Chars (Scope (Scope (Root))) = Name_Ada
12265 and then Scope (Scope (Scope (Root))) = Standard_Standard;
12266 end Is_Visibly_Controlled;
12268 ------------------------
12269 -- Is_Volatile_Object --
12270 ------------------------
12272 function Is_Volatile_Object (N : Node_Id) return Boolean is
12274 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
12275 -- If prefix is an implicit dereference, examine designated type
12277 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
12278 -- Determines if given object has volatile components
12280 ------------------------
12281 -- Is_Volatile_Prefix --
12282 ------------------------
12284 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
12285 Typ : constant Entity_Id := Etype (N);
12287 begin
12288 if Is_Access_Type (Typ) then
12289 declare
12290 Dtyp : constant Entity_Id := Designated_Type (Typ);
12292 begin
12293 return Is_Volatile (Dtyp)
12294 or else Has_Volatile_Components (Dtyp);
12295 end;
12297 else
12298 return Object_Has_Volatile_Components (N);
12299 end if;
12300 end Is_Volatile_Prefix;
12302 ------------------------------------
12303 -- Object_Has_Volatile_Components --
12304 ------------------------------------
12306 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
12307 Typ : constant Entity_Id := Etype (N);
12309 begin
12310 if Is_Volatile (Typ)
12311 or else Has_Volatile_Components (Typ)
12312 then
12313 return True;
12315 elsif Is_Entity_Name (N)
12316 and then (Has_Volatile_Components (Entity (N))
12317 or else Is_Volatile (Entity (N)))
12318 then
12319 return True;
12321 elsif Nkind (N) = N_Indexed_Component
12322 or else Nkind (N) = N_Selected_Component
12323 then
12324 return Is_Volatile_Prefix (Prefix (N));
12326 else
12327 return False;
12328 end if;
12329 end Object_Has_Volatile_Components;
12331 -- Start of processing for Is_Volatile_Object
12333 begin
12334 if Nkind (N) = N_Defining_Identifier then
12335 return Is_Volatile (N) or else Is_Volatile (Etype (N));
12337 elsif Nkind (N) = N_Expanded_Name then
12338 return Is_Volatile_Object (Entity (N));
12340 elsif Is_Volatile (Etype (N))
12341 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
12342 then
12343 return True;
12345 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
12346 and then Is_Volatile_Prefix (Prefix (N))
12347 then
12348 return True;
12350 elsif Nkind (N) = N_Selected_Component
12351 and then Is_Volatile (Entity (Selector_Name (N)))
12352 then
12353 return True;
12355 else
12356 return False;
12357 end if;
12358 end Is_Volatile_Object;
12360 ---------------------------
12361 -- Itype_Has_Declaration --
12362 ---------------------------
12364 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
12365 begin
12366 pragma Assert (Is_Itype (Id));
12367 return Present (Parent (Id))
12368 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
12369 N_Subtype_Declaration)
12370 and then Defining_Entity (Parent (Id)) = Id;
12371 end Itype_Has_Declaration;
12373 -------------------------
12374 -- Kill_Current_Values --
12375 -------------------------
12377 procedure Kill_Current_Values
12378 (Ent : Entity_Id;
12379 Last_Assignment_Only : Boolean := False)
12381 begin
12382 if Is_Assignable (Ent) then
12383 Set_Last_Assignment (Ent, Empty);
12384 end if;
12386 if Is_Object (Ent) then
12387 if not Last_Assignment_Only then
12388 Kill_Checks (Ent);
12389 Set_Current_Value (Ent, Empty);
12391 if not Can_Never_Be_Null (Ent) then
12392 Set_Is_Known_Non_Null (Ent, False);
12393 end if;
12395 Set_Is_Known_Null (Ent, False);
12397 -- Reset Is_Known_Valid unless type is always valid, or if we have
12398 -- a loop parameter (loop parameters are always valid, since their
12399 -- bounds are defined by the bounds given in the loop header).
12401 if not Is_Known_Valid (Etype (Ent))
12402 and then Ekind (Ent) /= E_Loop_Parameter
12403 then
12404 Set_Is_Known_Valid (Ent, False);
12405 end if;
12406 end if;
12407 end if;
12408 end Kill_Current_Values;
12410 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
12411 S : Entity_Id;
12413 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
12414 -- Clear current value for entity E and all entities chained to E
12416 ------------------------------------------
12417 -- Kill_Current_Values_For_Entity_Chain --
12418 ------------------------------------------
12420 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
12421 Ent : Entity_Id;
12422 begin
12423 Ent := E;
12424 while Present (Ent) loop
12425 Kill_Current_Values (Ent, Last_Assignment_Only);
12426 Next_Entity (Ent);
12427 end loop;
12428 end Kill_Current_Values_For_Entity_Chain;
12430 -- Start of processing for Kill_Current_Values
12432 begin
12433 -- Kill all saved checks, a special case of killing saved values
12435 if not Last_Assignment_Only then
12436 Kill_All_Checks;
12437 end if;
12439 -- Loop through relevant scopes, which includes the current scope and
12440 -- any parent scopes if the current scope is a block or a package.
12442 S := Current_Scope;
12443 Scope_Loop : loop
12445 -- Clear current values of all entities in current scope
12447 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
12449 -- If scope is a package, also clear current values of all private
12450 -- entities in the scope.
12452 if Is_Package_Or_Generic_Package (S)
12453 or else Is_Concurrent_Type (S)
12454 then
12455 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
12456 end if;
12458 -- If this is a not a subprogram, deal with parents
12460 if not Is_Subprogram (S) then
12461 S := Scope (S);
12462 exit Scope_Loop when S = Standard_Standard;
12463 else
12464 exit Scope_Loop;
12465 end if;
12466 end loop Scope_Loop;
12467 end Kill_Current_Values;
12469 --------------------------
12470 -- Kill_Size_Check_Code --
12471 --------------------------
12473 procedure Kill_Size_Check_Code (E : Entity_Id) is
12474 begin
12475 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
12476 and then Present (Size_Check_Code (E))
12477 then
12478 Remove (Size_Check_Code (E));
12479 Set_Size_Check_Code (E, Empty);
12480 end if;
12481 end Kill_Size_Check_Code;
12483 --------------------------
12484 -- Known_To_Be_Assigned --
12485 --------------------------
12487 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
12488 P : constant Node_Id := Parent (N);
12490 begin
12491 case Nkind (P) is
12493 -- Test left side of assignment
12495 when N_Assignment_Statement =>
12496 return N = Name (P);
12498 -- Function call arguments are never lvalues
12500 when N_Function_Call =>
12501 return False;
12503 -- Positional parameter for procedure or accept call
12505 when N_Procedure_Call_Statement |
12506 N_Accept_Statement
12508 declare
12509 Proc : Entity_Id;
12510 Form : Entity_Id;
12511 Act : Node_Id;
12513 begin
12514 Proc := Get_Subprogram_Entity (P);
12516 if No (Proc) then
12517 return False;
12518 end if;
12520 -- If we are not a list member, something is strange, so
12521 -- be conservative and return False.
12523 if not Is_List_Member (N) then
12524 return False;
12525 end if;
12527 -- We are going to find the right formal by stepping forward
12528 -- through the formals, as we step backwards in the actuals.
12530 Form := First_Formal (Proc);
12531 Act := N;
12532 loop
12533 -- If no formal, something is weird, so be conservative
12534 -- and return False.
12536 if No (Form) then
12537 return False;
12538 end if;
12540 Prev (Act);
12541 exit when No (Act);
12542 Next_Formal (Form);
12543 end loop;
12545 return Ekind (Form) /= E_In_Parameter;
12546 end;
12548 -- Named parameter for procedure or accept call
12550 when N_Parameter_Association =>
12551 declare
12552 Proc : Entity_Id;
12553 Form : Entity_Id;
12555 begin
12556 Proc := Get_Subprogram_Entity (Parent (P));
12558 if No (Proc) then
12559 return False;
12560 end if;
12562 -- Loop through formals to find the one that matches
12564 Form := First_Formal (Proc);
12565 loop
12566 -- If no matching formal, that's peculiar, some kind of
12567 -- previous error, so return False to be conservative.
12568 -- Actually this also happens in legal code in the case
12569 -- where P is a parameter association for an Extra_Formal???
12571 if No (Form) then
12572 return False;
12573 end if;
12575 -- Else test for match
12577 if Chars (Form) = Chars (Selector_Name (P)) then
12578 return Ekind (Form) /= E_In_Parameter;
12579 end if;
12581 Next_Formal (Form);
12582 end loop;
12583 end;
12585 -- Test for appearing in a conversion that itself appears
12586 -- in an lvalue context, since this should be an lvalue.
12588 when N_Type_Conversion =>
12589 return Known_To_Be_Assigned (P);
12591 -- All other references are definitely not known to be modifications
12593 when others =>
12594 return False;
12596 end case;
12597 end Known_To_Be_Assigned;
12599 ---------------------------
12600 -- Last_Source_Statement --
12601 ---------------------------
12603 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
12604 N : Node_Id;
12606 begin
12607 N := Last (Statements (HSS));
12608 while Present (N) loop
12609 exit when Comes_From_Source (N);
12610 Prev (N);
12611 end loop;
12613 return N;
12614 end Last_Source_Statement;
12616 ----------------------------------
12617 -- Matching_Static_Array_Bounds --
12618 ----------------------------------
12620 function Matching_Static_Array_Bounds
12621 (L_Typ : Node_Id;
12622 R_Typ : Node_Id) return Boolean
12624 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
12625 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
12627 L_Index : Node_Id;
12628 R_Index : Node_Id;
12629 L_Low : Node_Id;
12630 L_High : Node_Id;
12631 L_Len : Uint;
12632 R_Low : Node_Id;
12633 R_High : Node_Id;
12634 R_Len : Uint;
12636 begin
12637 if L_Ndims /= R_Ndims then
12638 return False;
12639 end if;
12641 -- Unconstrained types do not have static bounds
12643 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
12644 return False;
12645 end if;
12647 -- First treat specially the first dimension, as the lower bound and
12648 -- length of string literals are not stored like those of arrays.
12650 if Ekind (L_Typ) = E_String_Literal_Subtype then
12651 L_Low := String_Literal_Low_Bound (L_Typ);
12652 L_Len := String_Literal_Length (L_Typ);
12653 else
12654 L_Index := First_Index (L_Typ);
12655 Get_Index_Bounds (L_Index, L_Low, L_High);
12657 if Is_OK_Static_Expression (L_Low)
12658 and then
12659 Is_OK_Static_Expression (L_High)
12660 then
12661 if Expr_Value (L_High) < Expr_Value (L_Low) then
12662 L_Len := Uint_0;
12663 else
12664 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
12665 end if;
12666 else
12667 return False;
12668 end if;
12669 end if;
12671 if Ekind (R_Typ) = E_String_Literal_Subtype then
12672 R_Low := String_Literal_Low_Bound (R_Typ);
12673 R_Len := String_Literal_Length (R_Typ);
12674 else
12675 R_Index := First_Index (R_Typ);
12676 Get_Index_Bounds (R_Index, R_Low, R_High);
12678 if Is_OK_Static_Expression (R_Low)
12679 and then
12680 Is_OK_Static_Expression (R_High)
12681 then
12682 if Expr_Value (R_High) < Expr_Value (R_Low) then
12683 R_Len := Uint_0;
12684 else
12685 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
12686 end if;
12687 else
12688 return False;
12689 end if;
12690 end if;
12692 if (Is_OK_Static_Expression (L_Low)
12693 and then
12694 Is_OK_Static_Expression (R_Low))
12695 and then Expr_Value (L_Low) = Expr_Value (R_Low)
12696 and then L_Len = R_Len
12697 then
12698 null;
12699 else
12700 return False;
12701 end if;
12703 -- Then treat all other dimensions
12705 for Indx in 2 .. L_Ndims loop
12706 Next (L_Index);
12707 Next (R_Index);
12709 Get_Index_Bounds (L_Index, L_Low, L_High);
12710 Get_Index_Bounds (R_Index, R_Low, R_High);
12712 if (Is_OK_Static_Expression (L_Low) and then
12713 Is_OK_Static_Expression (L_High) and then
12714 Is_OK_Static_Expression (R_Low) and then
12715 Is_OK_Static_Expression (R_High))
12716 and then (Expr_Value (L_Low) = Expr_Value (R_Low)
12717 and then
12718 Expr_Value (L_High) = Expr_Value (R_High))
12719 then
12720 null;
12721 else
12722 return False;
12723 end if;
12724 end loop;
12726 -- If we fall through the loop, all indexes matched
12728 return True;
12729 end Matching_Static_Array_Bounds;
12731 -------------------
12732 -- May_Be_Lvalue --
12733 -------------------
12735 function May_Be_Lvalue (N : Node_Id) return Boolean is
12736 P : constant Node_Id := Parent (N);
12738 begin
12739 case Nkind (P) is
12741 -- Test left side of assignment
12743 when N_Assignment_Statement =>
12744 return N = Name (P);
12746 -- Test prefix of component or attribute. Note that the prefix of an
12747 -- explicit or implicit dereference cannot be an l-value.
12749 when N_Attribute_Reference =>
12750 return N = Prefix (P)
12751 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
12753 -- For an expanded name, the name is an lvalue if the expanded name
12754 -- is an lvalue, but the prefix is never an lvalue, since it is just
12755 -- the scope where the name is found.
12757 when N_Expanded_Name =>
12758 if N = Prefix (P) then
12759 return May_Be_Lvalue (P);
12760 else
12761 return False;
12762 end if;
12764 -- For a selected component A.B, A is certainly an lvalue if A.B is.
12765 -- B is a little interesting, if we have A.B := 3, there is some
12766 -- discussion as to whether B is an lvalue or not, we choose to say
12767 -- it is. Note however that A is not an lvalue if it is of an access
12768 -- type since this is an implicit dereference.
12770 when N_Selected_Component =>
12771 if N = Prefix (P)
12772 and then Present (Etype (N))
12773 and then Is_Access_Type (Etype (N))
12774 then
12775 return False;
12776 else
12777 return May_Be_Lvalue (P);
12778 end if;
12780 -- For an indexed component or slice, the index or slice bounds is
12781 -- never an lvalue. The prefix is an lvalue if the indexed component
12782 -- or slice is an lvalue, except if it is an access type, where we
12783 -- have an implicit dereference.
12785 when N_Indexed_Component | N_Slice =>
12786 if N /= Prefix (P)
12787 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
12788 then
12789 return False;
12790 else
12791 return May_Be_Lvalue (P);
12792 end if;
12794 -- Prefix of a reference is an lvalue if the reference is an lvalue
12796 when N_Reference =>
12797 return May_Be_Lvalue (P);
12799 -- Prefix of explicit dereference is never an lvalue
12801 when N_Explicit_Dereference =>
12802 return False;
12804 -- Positional parameter for subprogram, entry, or accept call.
12805 -- In older versions of Ada function call arguments are never
12806 -- lvalues. In Ada 2012 functions can have in-out parameters.
12808 when N_Subprogram_Call |
12809 N_Entry_Call_Statement |
12810 N_Accept_Statement
12812 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
12813 return False;
12814 end if;
12816 -- The following mechanism is clumsy and fragile. A single flag
12817 -- set in Resolve_Actuals would be preferable ???
12819 declare
12820 Proc : Entity_Id;
12821 Form : Entity_Id;
12822 Act : Node_Id;
12824 begin
12825 Proc := Get_Subprogram_Entity (P);
12827 if No (Proc) then
12828 return True;
12829 end if;
12831 -- If we are not a list member, something is strange, so be
12832 -- conservative and return True.
12834 if not Is_List_Member (N) then
12835 return True;
12836 end if;
12838 -- We are going to find the right formal by stepping forward
12839 -- through the formals, as we step backwards in the actuals.
12841 Form := First_Formal (Proc);
12842 Act := N;
12843 loop
12844 -- If no formal, something is weird, so be conservative and
12845 -- return True.
12847 if No (Form) then
12848 return True;
12849 end if;
12851 Prev (Act);
12852 exit when No (Act);
12853 Next_Formal (Form);
12854 end loop;
12856 return Ekind (Form) /= E_In_Parameter;
12857 end;
12859 -- Named parameter for procedure or accept call
12861 when N_Parameter_Association =>
12862 declare
12863 Proc : Entity_Id;
12864 Form : Entity_Id;
12866 begin
12867 Proc := Get_Subprogram_Entity (Parent (P));
12869 if No (Proc) then
12870 return True;
12871 end if;
12873 -- Loop through formals to find the one that matches
12875 Form := First_Formal (Proc);
12876 loop
12877 -- If no matching formal, that's peculiar, some kind of
12878 -- previous error, so return True to be conservative.
12879 -- Actually happens with legal code for an unresolved call
12880 -- where we may get the wrong homonym???
12882 if No (Form) then
12883 return True;
12884 end if;
12886 -- Else test for match
12888 if Chars (Form) = Chars (Selector_Name (P)) then
12889 return Ekind (Form) /= E_In_Parameter;
12890 end if;
12892 Next_Formal (Form);
12893 end loop;
12894 end;
12896 -- Test for appearing in a conversion that itself appears in an
12897 -- lvalue context, since this should be an lvalue.
12899 when N_Type_Conversion =>
12900 return May_Be_Lvalue (P);
12902 -- Test for appearance in object renaming declaration
12904 when N_Object_Renaming_Declaration =>
12905 return True;
12907 -- All other references are definitely not lvalues
12909 when others =>
12910 return False;
12912 end case;
12913 end May_Be_Lvalue;
12915 -----------------------
12916 -- Mark_Coextensions --
12917 -----------------------
12919 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
12920 Is_Dynamic : Boolean;
12921 -- Indicates whether the context causes nested coextensions to be
12922 -- dynamic or static
12924 function Mark_Allocator (N : Node_Id) return Traverse_Result;
12925 -- Recognize an allocator node and label it as a dynamic coextension
12927 --------------------
12928 -- Mark_Allocator --
12929 --------------------
12931 function Mark_Allocator (N : Node_Id) return Traverse_Result is
12932 begin
12933 if Nkind (N) = N_Allocator then
12934 if Is_Dynamic then
12935 Set_Is_Dynamic_Coextension (N);
12937 -- If the allocator expression is potentially dynamic, it may
12938 -- be expanded out of order and require dynamic allocation
12939 -- anyway, so we treat the coextension itself as dynamic.
12940 -- Potential optimization ???
12942 elsif Nkind (Expression (N)) = N_Qualified_Expression
12943 and then Nkind (Expression (Expression (N))) = N_Op_Concat
12944 then
12945 Set_Is_Dynamic_Coextension (N);
12946 else
12947 Set_Is_Static_Coextension (N);
12948 end if;
12949 end if;
12951 return OK;
12952 end Mark_Allocator;
12954 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
12956 -- Start of processing Mark_Coextensions
12958 begin
12959 case Nkind (Context_Nod) is
12961 -- Comment here ???
12963 when N_Assignment_Statement =>
12964 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
12966 -- An allocator that is a component of a returned aggregate
12967 -- must be dynamic.
12969 when N_Simple_Return_Statement =>
12970 declare
12971 Expr : constant Node_Id := Expression (Context_Nod);
12972 begin
12973 Is_Dynamic :=
12974 Nkind (Expr) = N_Allocator
12975 or else
12976 (Nkind (Expr) = N_Qualified_Expression
12977 and then Nkind (Expression (Expr)) = N_Aggregate);
12978 end;
12980 -- An alloctor within an object declaration in an extended return
12981 -- statement is of necessity dynamic.
12983 when N_Object_Declaration =>
12984 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
12985 or else
12986 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
12988 -- This routine should not be called for constructs which may not
12989 -- contain coextensions.
12991 when others =>
12992 raise Program_Error;
12993 end case;
12995 Mark_Allocators (Root_Nod);
12996 end Mark_Coextensions;
12998 -----------------
12999 -- Must_Inline --
13000 -----------------
13002 function Must_Inline (Subp : Entity_Id) return Boolean is
13003 begin
13004 return
13005 (Optimization_Level = 0
13007 -- AAMP and VM targets have no support for inlining in the backend.
13008 -- Hence we do as much inlining as possible in the front end.
13010 or else AAMP_On_Target
13011 or else VM_Target /= No_VM)
13012 and then Has_Pragma_Inline (Subp)
13013 and then (Has_Pragma_Inline_Always (Subp) or else Front_End_Inlining);
13014 end Must_Inline;
13016 ----------------------
13017 -- Needs_One_Actual --
13018 ----------------------
13020 function Needs_One_Actual (E : Entity_Id) return Boolean is
13021 Formal : Entity_Id;
13023 begin
13024 -- Ada 2005 or later, and formals present
13026 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
13027 Formal := Next_Formal (First_Formal (E));
13028 while Present (Formal) loop
13029 if No (Default_Value (Formal)) then
13030 return False;
13031 end if;
13033 Next_Formal (Formal);
13034 end loop;
13036 return True;
13038 -- Ada 83/95 or no formals
13040 else
13041 return False;
13042 end if;
13043 end Needs_One_Actual;
13045 ------------------------
13046 -- New_Copy_List_Tree --
13047 ------------------------
13049 function New_Copy_List_Tree (List : List_Id) return List_Id is
13050 NL : List_Id;
13051 E : Node_Id;
13053 begin
13054 if List = No_List then
13055 return No_List;
13057 else
13058 NL := New_List;
13059 E := First (List);
13061 while Present (E) loop
13062 Append (New_Copy_Tree (E), NL);
13063 E := Next (E);
13064 end loop;
13066 return NL;
13067 end if;
13068 end New_Copy_List_Tree;
13070 -------------------
13071 -- New_Copy_Tree --
13072 -------------------
13074 use Atree.Unchecked_Access;
13075 use Atree_Private_Part;
13077 -- Our approach here requires a two pass traversal of the tree. The
13078 -- first pass visits all nodes that eventually will be copied looking
13079 -- for defining Itypes. If any defining Itypes are found, then they are
13080 -- copied, and an entry is added to the replacement map. In the second
13081 -- phase, the tree is copied, using the replacement map to replace any
13082 -- Itype references within the copied tree.
13084 -- The following hash tables are used if the Map supplied has more
13085 -- than hash threshold entries to speed up access to the map. If
13086 -- there are fewer entries, then the map is searched sequentially
13087 -- (because setting up a hash table for only a few entries takes
13088 -- more time than it saves.
13090 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
13091 -- Hash function used for hash operations
13093 -------------------
13094 -- New_Copy_Hash --
13095 -------------------
13097 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
13098 begin
13099 return Nat (E) mod (NCT_Header_Num'Last + 1);
13100 end New_Copy_Hash;
13102 ---------------
13103 -- NCT_Assoc --
13104 ---------------
13106 -- The hash table NCT_Assoc associates old entities in the table
13107 -- with their corresponding new entities (i.e. the pairs of entries
13108 -- presented in the original Map argument are Key-Element pairs).
13110 package NCT_Assoc is new Simple_HTable (
13111 Header_Num => NCT_Header_Num,
13112 Element => Entity_Id,
13113 No_Element => Empty,
13114 Key => Entity_Id,
13115 Hash => New_Copy_Hash,
13116 Equal => Types."=");
13118 ---------------------
13119 -- NCT_Itype_Assoc --
13120 ---------------------
13122 -- The hash table NCT_Itype_Assoc contains entries only for those
13123 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13124 -- The key is the associated node, and the element is the new node
13125 -- itself (NOT the associated node for the new node).
13127 package NCT_Itype_Assoc is new Simple_HTable (
13128 Header_Num => NCT_Header_Num,
13129 Element => Entity_Id,
13130 No_Element => Empty,
13131 Key => Entity_Id,
13132 Hash => New_Copy_Hash,
13133 Equal => Types."=");
13135 -- Start of processing for New_Copy_Tree function
13137 function New_Copy_Tree
13138 (Source : Node_Id;
13139 Map : Elist_Id := No_Elist;
13140 New_Sloc : Source_Ptr := No_Location;
13141 New_Scope : Entity_Id := Empty) return Node_Id
13143 Actual_Map : Elist_Id := Map;
13144 -- This is the actual map for the copy. It is initialized with the
13145 -- given elements, and then enlarged as required for Itypes that are
13146 -- copied during the first phase of the copy operation. The visit
13147 -- procedures add elements to this map as Itypes are encountered.
13148 -- The reason we cannot use Map directly, is that it may well be
13149 -- (and normally is) initialized to No_Elist, and if we have mapped
13150 -- entities, we have to reset it to point to a real Elist.
13152 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
13153 -- Called during second phase to map entities into their corresponding
13154 -- copies using Actual_Map. If the argument is not an entity, or is not
13155 -- in Actual_Map, then it is returned unchanged.
13157 procedure Build_NCT_Hash_Tables;
13158 -- Builds hash tables (number of elements >= threshold value)
13160 function Copy_Elist_With_Replacement
13161 (Old_Elist : Elist_Id) return Elist_Id;
13162 -- Called during second phase to copy element list doing replacements
13164 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
13165 -- Called during the second phase to process a copied Itype. The actual
13166 -- copy happened during the first phase (so that we could make the entry
13167 -- in the mapping), but we still have to deal with the descendents of
13168 -- the copied Itype and copy them where necessary.
13170 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
13171 -- Called during second phase to copy list doing replacements
13173 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
13174 -- Called during second phase to copy node doing replacements
13176 procedure Visit_Elist (E : Elist_Id);
13177 -- Called during first phase to visit all elements of an Elist
13179 procedure Visit_Field (F : Union_Id; N : Node_Id);
13180 -- Visit a single field, recursing to call Visit_Node or Visit_List
13181 -- if the field is a syntactic descendent of the current node (i.e.
13182 -- its parent is Node N).
13184 procedure Visit_Itype (Old_Itype : Entity_Id);
13185 -- Called during first phase to visit subsidiary fields of a defining
13186 -- Itype, and also create a copy and make an entry in the replacement
13187 -- map for the new copy.
13189 procedure Visit_List (L : List_Id);
13190 -- Called during first phase to visit all elements of a List
13192 procedure Visit_Node (N : Node_Or_Entity_Id);
13193 -- Called during first phase to visit a node and all its subtrees
13195 -----------
13196 -- Assoc --
13197 -----------
13199 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
13200 E : Elmt_Id;
13201 Ent : Entity_Id;
13203 begin
13204 if not Has_Extension (N) or else No (Actual_Map) then
13205 return N;
13207 elsif NCT_Hash_Tables_Used then
13208 Ent := NCT_Assoc.Get (Entity_Id (N));
13210 if Present (Ent) then
13211 return Ent;
13212 else
13213 return N;
13214 end if;
13216 -- No hash table used, do serial search
13218 else
13219 E := First_Elmt (Actual_Map);
13220 while Present (E) loop
13221 if Node (E) = N then
13222 return Node (Next_Elmt (E));
13223 else
13224 E := Next_Elmt (Next_Elmt (E));
13225 end if;
13226 end loop;
13227 end if;
13229 return N;
13230 end Assoc;
13232 ---------------------------
13233 -- Build_NCT_Hash_Tables --
13234 ---------------------------
13236 procedure Build_NCT_Hash_Tables is
13237 Elmt : Elmt_Id;
13238 Ent : Entity_Id;
13239 begin
13240 if NCT_Hash_Table_Setup then
13241 NCT_Assoc.Reset;
13242 NCT_Itype_Assoc.Reset;
13243 end if;
13245 Elmt := First_Elmt (Actual_Map);
13246 while Present (Elmt) loop
13247 Ent := Node (Elmt);
13249 -- Get new entity, and associate old and new
13251 Next_Elmt (Elmt);
13252 NCT_Assoc.Set (Ent, Node (Elmt));
13254 if Is_Type (Ent) then
13255 declare
13256 Anode : constant Entity_Id :=
13257 Associated_Node_For_Itype (Ent);
13259 begin
13260 if Present (Anode) then
13262 -- Enter a link between the associated node of the
13263 -- old Itype and the new Itype, for updating later
13264 -- when node is copied.
13266 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
13267 end if;
13268 end;
13269 end if;
13271 Next_Elmt (Elmt);
13272 end loop;
13274 NCT_Hash_Tables_Used := True;
13275 NCT_Hash_Table_Setup := True;
13276 end Build_NCT_Hash_Tables;
13278 ---------------------------------
13279 -- Copy_Elist_With_Replacement --
13280 ---------------------------------
13282 function Copy_Elist_With_Replacement
13283 (Old_Elist : Elist_Id) return Elist_Id
13285 M : Elmt_Id;
13286 New_Elist : Elist_Id;
13288 begin
13289 if No (Old_Elist) then
13290 return No_Elist;
13292 else
13293 New_Elist := New_Elmt_List;
13295 M := First_Elmt (Old_Elist);
13296 while Present (M) loop
13297 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
13298 Next_Elmt (M);
13299 end loop;
13300 end if;
13302 return New_Elist;
13303 end Copy_Elist_With_Replacement;
13305 ---------------------------------
13306 -- Copy_Itype_With_Replacement --
13307 ---------------------------------
13309 -- This routine exactly parallels its phase one analog Visit_Itype,
13311 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
13312 begin
13313 -- Translate Next_Entity, Scope and Etype fields, in case they
13314 -- reference entities that have been mapped into copies.
13316 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
13317 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
13319 if Present (New_Scope) then
13320 Set_Scope (New_Itype, New_Scope);
13321 else
13322 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
13323 end if;
13325 -- Copy referenced fields
13327 if Is_Discrete_Type (New_Itype) then
13328 Set_Scalar_Range (New_Itype,
13329 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
13331 elsif Has_Discriminants (Base_Type (New_Itype)) then
13332 Set_Discriminant_Constraint (New_Itype,
13333 Copy_Elist_With_Replacement
13334 (Discriminant_Constraint (New_Itype)));
13336 elsif Is_Array_Type (New_Itype) then
13337 if Present (First_Index (New_Itype)) then
13338 Set_First_Index (New_Itype,
13339 First (Copy_List_With_Replacement
13340 (List_Containing (First_Index (New_Itype)))));
13341 end if;
13343 if Is_Packed (New_Itype) then
13344 Set_Packed_Array_Impl_Type (New_Itype,
13345 Copy_Node_With_Replacement
13346 (Packed_Array_Impl_Type (New_Itype)));
13347 end if;
13348 end if;
13349 end Copy_Itype_With_Replacement;
13351 --------------------------------
13352 -- Copy_List_With_Replacement --
13353 --------------------------------
13355 function Copy_List_With_Replacement
13356 (Old_List : List_Id) return List_Id
13358 New_List : List_Id;
13359 E : Node_Id;
13361 begin
13362 if Old_List = No_List then
13363 return No_List;
13365 else
13366 New_List := Empty_List;
13368 E := First (Old_List);
13369 while Present (E) loop
13370 Append (Copy_Node_With_Replacement (E), New_List);
13371 Next (E);
13372 end loop;
13374 return New_List;
13375 end if;
13376 end Copy_List_With_Replacement;
13378 --------------------------------
13379 -- Copy_Node_With_Replacement --
13380 --------------------------------
13382 function Copy_Node_With_Replacement
13383 (Old_Node : Node_Id) return Node_Id
13385 New_Node : Node_Id;
13387 procedure Adjust_Named_Associations
13388 (Old_Node : Node_Id;
13389 New_Node : Node_Id);
13390 -- If a call node has named associations, these are chained through
13391 -- the First_Named_Actual, Next_Named_Actual links. These must be
13392 -- propagated separately to the new parameter list, because these
13393 -- are not syntactic fields.
13395 function Copy_Field_With_Replacement
13396 (Field : Union_Id) return Union_Id;
13397 -- Given Field, which is a field of Old_Node, return a copy of it
13398 -- if it is a syntactic field (i.e. its parent is Node), setting
13399 -- the parent of the copy to poit to New_Node. Otherwise returns
13400 -- the field (possibly mapped if it is an entity).
13402 -------------------------------
13403 -- Adjust_Named_Associations --
13404 -------------------------------
13406 procedure Adjust_Named_Associations
13407 (Old_Node : Node_Id;
13408 New_Node : Node_Id)
13410 Old_E : Node_Id;
13411 New_E : Node_Id;
13413 Old_Next : Node_Id;
13414 New_Next : Node_Id;
13416 begin
13417 Old_E := First (Parameter_Associations (Old_Node));
13418 New_E := First (Parameter_Associations (New_Node));
13419 while Present (Old_E) loop
13420 if Nkind (Old_E) = N_Parameter_Association
13421 and then Present (Next_Named_Actual (Old_E))
13422 then
13423 if First_Named_Actual (Old_Node)
13424 = Explicit_Actual_Parameter (Old_E)
13425 then
13426 Set_First_Named_Actual
13427 (New_Node, Explicit_Actual_Parameter (New_E));
13428 end if;
13430 -- Now scan parameter list from the beginning,to locate
13431 -- next named actual, which can be out of order.
13433 Old_Next := First (Parameter_Associations (Old_Node));
13434 New_Next := First (Parameter_Associations (New_Node));
13436 while Nkind (Old_Next) /= N_Parameter_Association
13437 or else Explicit_Actual_Parameter (Old_Next)
13438 /= Next_Named_Actual (Old_E)
13439 loop
13440 Next (Old_Next);
13441 Next (New_Next);
13442 end loop;
13444 Set_Next_Named_Actual
13445 (New_E, Explicit_Actual_Parameter (New_Next));
13446 end if;
13448 Next (Old_E);
13449 Next (New_E);
13450 end loop;
13451 end Adjust_Named_Associations;
13453 ---------------------------------
13454 -- Copy_Field_With_Replacement --
13455 ---------------------------------
13457 function Copy_Field_With_Replacement
13458 (Field : Union_Id) return Union_Id
13460 begin
13461 if Field = Union_Id (Empty) then
13462 return Field;
13464 elsif Field in Node_Range then
13465 declare
13466 Old_N : constant Node_Id := Node_Id (Field);
13467 New_N : Node_Id;
13469 begin
13470 -- If syntactic field, as indicated by the parent pointer
13471 -- being set, then copy the referenced node recursively.
13473 if Parent (Old_N) = Old_Node then
13474 New_N := Copy_Node_With_Replacement (Old_N);
13476 if New_N /= Old_N then
13477 Set_Parent (New_N, New_Node);
13478 end if;
13480 -- For semantic fields, update possible entity reference
13481 -- from the replacement map.
13483 else
13484 New_N := Assoc (Old_N);
13485 end if;
13487 return Union_Id (New_N);
13488 end;
13490 elsif Field in List_Range then
13491 declare
13492 Old_L : constant List_Id := List_Id (Field);
13493 New_L : List_Id;
13495 begin
13496 -- If syntactic field, as indicated by the parent pointer,
13497 -- then recursively copy the entire referenced list.
13499 if Parent (Old_L) = Old_Node then
13500 New_L := Copy_List_With_Replacement (Old_L);
13501 Set_Parent (New_L, New_Node);
13503 -- For semantic list, just returned unchanged
13505 else
13506 New_L := Old_L;
13507 end if;
13509 return Union_Id (New_L);
13510 end;
13512 -- Anything other than a list or a node is returned unchanged
13514 else
13515 return Field;
13516 end if;
13517 end Copy_Field_With_Replacement;
13519 -- Start of processing for Copy_Node_With_Replacement
13521 begin
13522 if Old_Node <= Empty_Or_Error then
13523 return Old_Node;
13525 elsif Has_Extension (Old_Node) then
13526 return Assoc (Old_Node);
13528 else
13529 New_Node := New_Copy (Old_Node);
13531 -- If the node we are copying is the associated node of a
13532 -- previously copied Itype, then adjust the associated node
13533 -- of the copy of that Itype accordingly.
13535 if Present (Actual_Map) then
13536 declare
13537 E : Elmt_Id;
13538 Ent : Entity_Id;
13540 begin
13541 -- Case of hash table used
13543 if NCT_Hash_Tables_Used then
13544 Ent := NCT_Itype_Assoc.Get (Old_Node);
13546 if Present (Ent) then
13547 Set_Associated_Node_For_Itype (Ent, New_Node);
13548 end if;
13550 -- Case of no hash table used
13552 else
13553 E := First_Elmt (Actual_Map);
13554 while Present (E) loop
13555 if Is_Itype (Node (E))
13556 and then
13557 Old_Node = Associated_Node_For_Itype (Node (E))
13558 then
13559 Set_Associated_Node_For_Itype
13560 (Node (Next_Elmt (E)), New_Node);
13561 end if;
13563 E := Next_Elmt (Next_Elmt (E));
13564 end loop;
13565 end if;
13566 end;
13567 end if;
13569 -- Recursively copy descendents
13571 Set_Field1
13572 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
13573 Set_Field2
13574 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
13575 Set_Field3
13576 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
13577 Set_Field4
13578 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
13579 Set_Field5
13580 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
13582 -- Adjust Sloc of new node if necessary
13584 if New_Sloc /= No_Location then
13585 Set_Sloc (New_Node, New_Sloc);
13587 -- If we adjust the Sloc, then we are essentially making
13588 -- a completely new node, so the Comes_From_Source flag
13589 -- should be reset to the proper default value.
13591 Nodes.Table (New_Node).Comes_From_Source :=
13592 Default_Node.Comes_From_Source;
13593 end if;
13595 -- If the node is call and has named associations,
13596 -- set the corresponding links in the copy.
13598 if (Nkind (Old_Node) = N_Function_Call
13599 or else Nkind (Old_Node) = N_Entry_Call_Statement
13600 or else
13601 Nkind (Old_Node) = N_Procedure_Call_Statement)
13602 and then Present (First_Named_Actual (Old_Node))
13603 then
13604 Adjust_Named_Associations (Old_Node, New_Node);
13605 end if;
13607 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
13608 -- The replacement mechanism applies to entities, and is not used
13609 -- here. Eventually we may need a more general graph-copying
13610 -- routine. For now, do a sequential search to find desired node.
13612 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
13613 and then Present (First_Real_Statement (Old_Node))
13614 then
13615 declare
13616 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
13617 N1, N2 : Node_Id;
13619 begin
13620 N1 := First (Statements (Old_Node));
13621 N2 := First (Statements (New_Node));
13623 while N1 /= Old_F loop
13624 Next (N1);
13625 Next (N2);
13626 end loop;
13628 Set_First_Real_Statement (New_Node, N2);
13629 end;
13630 end if;
13631 end if;
13633 -- All done, return copied node
13635 return New_Node;
13636 end Copy_Node_With_Replacement;
13638 -----------------
13639 -- Visit_Elist --
13640 -----------------
13642 procedure Visit_Elist (E : Elist_Id) is
13643 Elmt : Elmt_Id;
13644 begin
13645 if Present (E) then
13646 Elmt := First_Elmt (E);
13648 while Elmt /= No_Elmt loop
13649 Visit_Node (Node (Elmt));
13650 Next_Elmt (Elmt);
13651 end loop;
13652 end if;
13653 end Visit_Elist;
13655 -----------------
13656 -- Visit_Field --
13657 -----------------
13659 procedure Visit_Field (F : Union_Id; N : Node_Id) is
13660 begin
13661 if F = Union_Id (Empty) then
13662 return;
13664 elsif F in Node_Range then
13666 -- Copy node if it is syntactic, i.e. its parent pointer is
13667 -- set to point to the field that referenced it (certain
13668 -- Itypes will also meet this criterion, which is fine, since
13669 -- these are clearly Itypes that do need to be copied, since
13670 -- we are copying their parent.)
13672 if Parent (Node_Id (F)) = N then
13673 Visit_Node (Node_Id (F));
13674 return;
13676 -- Another case, if we are pointing to an Itype, then we want
13677 -- to copy it if its associated node is somewhere in the tree
13678 -- being copied.
13680 -- Note: the exclusion of self-referential copies is just an
13681 -- optimization, since the search of the already copied list
13682 -- would catch it, but it is a common case (Etype pointing
13683 -- to itself for an Itype that is a base type).
13685 elsif Has_Extension (Node_Id (F))
13686 and then Is_Itype (Entity_Id (F))
13687 and then Node_Id (F) /= N
13688 then
13689 declare
13690 P : Node_Id;
13692 begin
13693 P := Associated_Node_For_Itype (Node_Id (F));
13694 while Present (P) loop
13695 if P = Source then
13696 Visit_Node (Node_Id (F));
13697 return;
13698 else
13699 P := Parent (P);
13700 end if;
13701 end loop;
13703 -- An Itype whose parent is not being copied definitely
13704 -- should NOT be copied, since it does not belong in any
13705 -- sense to the copied subtree.
13707 return;
13708 end;
13709 end if;
13711 elsif F in List_Range and then Parent (List_Id (F)) = N then
13712 Visit_List (List_Id (F));
13713 return;
13714 end if;
13715 end Visit_Field;
13717 -----------------
13718 -- Visit_Itype --
13719 -----------------
13721 procedure Visit_Itype (Old_Itype : Entity_Id) is
13722 New_Itype : Entity_Id;
13723 E : Elmt_Id;
13724 Ent : Entity_Id;
13726 begin
13727 -- Itypes that describe the designated type of access to subprograms
13728 -- have the structure of subprogram declarations, with signatures,
13729 -- etc. Either we duplicate the signatures completely, or choose to
13730 -- share such itypes, which is fine because their elaboration will
13731 -- have no side effects.
13733 if Ekind (Old_Itype) = E_Subprogram_Type then
13734 return;
13735 end if;
13737 New_Itype := New_Copy (Old_Itype);
13739 -- The new Itype has all the attributes of the old one, and
13740 -- we just copy the contents of the entity. However, the back-end
13741 -- needs different names for debugging purposes, so we create a
13742 -- new internal name for it in all cases.
13744 Set_Chars (New_Itype, New_Internal_Name ('T'));
13746 -- If our associated node is an entity that has already been copied,
13747 -- then set the associated node of the copy to point to the right
13748 -- copy. If we have copied an Itype that is itself the associated
13749 -- node of some previously copied Itype, then we set the right
13750 -- pointer in the other direction.
13752 if Present (Actual_Map) then
13754 -- Case of hash tables used
13756 if NCT_Hash_Tables_Used then
13758 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
13760 if Present (Ent) then
13761 Set_Associated_Node_For_Itype (New_Itype, Ent);
13762 end if;
13764 Ent := NCT_Itype_Assoc.Get (Old_Itype);
13765 if Present (Ent) then
13766 Set_Associated_Node_For_Itype (Ent, New_Itype);
13768 -- If the hash table has no association for this Itype and
13769 -- its associated node, enter one now.
13771 else
13772 NCT_Itype_Assoc.Set
13773 (Associated_Node_For_Itype (Old_Itype), New_Itype);
13774 end if;
13776 -- Case of hash tables not used
13778 else
13779 E := First_Elmt (Actual_Map);
13780 while Present (E) loop
13781 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
13782 Set_Associated_Node_For_Itype
13783 (New_Itype, Node (Next_Elmt (E)));
13784 end if;
13786 if Is_Type (Node (E))
13787 and then Old_Itype = Associated_Node_For_Itype (Node (E))
13788 then
13789 Set_Associated_Node_For_Itype
13790 (Node (Next_Elmt (E)), New_Itype);
13791 end if;
13793 E := Next_Elmt (Next_Elmt (E));
13794 end loop;
13795 end if;
13796 end if;
13798 if Present (Freeze_Node (New_Itype)) then
13799 Set_Is_Frozen (New_Itype, False);
13800 Set_Freeze_Node (New_Itype, Empty);
13801 end if;
13803 -- Add new association to map
13805 if No (Actual_Map) then
13806 Actual_Map := New_Elmt_List;
13807 end if;
13809 Append_Elmt (Old_Itype, Actual_Map);
13810 Append_Elmt (New_Itype, Actual_Map);
13812 if NCT_Hash_Tables_Used then
13813 NCT_Assoc.Set (Old_Itype, New_Itype);
13815 else
13816 NCT_Table_Entries := NCT_Table_Entries + 1;
13818 if NCT_Table_Entries > NCT_Hash_Threshold then
13819 Build_NCT_Hash_Tables;
13820 end if;
13821 end if;
13823 -- If a record subtype is simply copied, the entity list will be
13824 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
13826 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
13827 Set_Cloned_Subtype (New_Itype, Old_Itype);
13828 end if;
13830 -- Visit descendents that eventually get copied
13832 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
13834 if Is_Discrete_Type (Old_Itype) then
13835 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
13837 elsif Has_Discriminants (Base_Type (Old_Itype)) then
13838 -- ??? This should involve call to Visit_Field
13839 Visit_Elist (Discriminant_Constraint (Old_Itype));
13841 elsif Is_Array_Type (Old_Itype) then
13842 if Present (First_Index (Old_Itype)) then
13843 Visit_Field (Union_Id (List_Containing
13844 (First_Index (Old_Itype))),
13845 Old_Itype);
13846 end if;
13848 if Is_Packed (Old_Itype) then
13849 Visit_Field (Union_Id (Packed_Array_Impl_Type (Old_Itype)),
13850 Old_Itype);
13851 end if;
13852 end if;
13853 end Visit_Itype;
13855 ----------------
13856 -- Visit_List --
13857 ----------------
13859 procedure Visit_List (L : List_Id) is
13860 N : Node_Id;
13861 begin
13862 if L /= No_List then
13863 N := First (L);
13865 while Present (N) loop
13866 Visit_Node (N);
13867 Next (N);
13868 end loop;
13869 end if;
13870 end Visit_List;
13872 ----------------
13873 -- Visit_Node --
13874 ----------------
13876 procedure Visit_Node (N : Node_Or_Entity_Id) is
13878 -- Start of processing for Visit_Node
13880 begin
13881 -- Handle case of an Itype, which must be copied
13883 if Has_Extension (N) and then Is_Itype (N) then
13885 -- Nothing to do if already in the list. This can happen with an
13886 -- Itype entity that appears more than once in the tree.
13887 -- Note that we do not want to visit descendents in this case.
13889 -- Test for already in list when hash table is used
13891 if NCT_Hash_Tables_Used then
13892 if Present (NCT_Assoc.Get (Entity_Id (N))) then
13893 return;
13894 end if;
13896 -- Test for already in list when hash table not used
13898 else
13899 declare
13900 E : Elmt_Id;
13901 begin
13902 if Present (Actual_Map) then
13903 E := First_Elmt (Actual_Map);
13904 while Present (E) loop
13905 if Node (E) = N then
13906 return;
13907 else
13908 E := Next_Elmt (Next_Elmt (E));
13909 end if;
13910 end loop;
13911 end if;
13912 end;
13913 end if;
13915 Visit_Itype (N);
13916 end if;
13918 -- Visit descendents
13920 Visit_Field (Field1 (N), N);
13921 Visit_Field (Field2 (N), N);
13922 Visit_Field (Field3 (N), N);
13923 Visit_Field (Field4 (N), N);
13924 Visit_Field (Field5 (N), N);
13925 end Visit_Node;
13927 -- Start of processing for New_Copy_Tree
13929 begin
13930 Actual_Map := Map;
13932 -- See if we should use hash table
13934 if No (Actual_Map) then
13935 NCT_Hash_Tables_Used := False;
13937 else
13938 declare
13939 Elmt : Elmt_Id;
13941 begin
13942 NCT_Table_Entries := 0;
13944 Elmt := First_Elmt (Actual_Map);
13945 while Present (Elmt) loop
13946 NCT_Table_Entries := NCT_Table_Entries + 1;
13947 Next_Elmt (Elmt);
13948 Next_Elmt (Elmt);
13949 end loop;
13951 if NCT_Table_Entries > NCT_Hash_Threshold then
13952 Build_NCT_Hash_Tables;
13953 else
13954 NCT_Hash_Tables_Used := False;
13955 end if;
13956 end;
13957 end if;
13959 -- Hash table set up if required, now start phase one by visiting
13960 -- top node (we will recursively visit the descendents).
13962 Visit_Node (Source);
13964 -- Now the second phase of the copy can start. First we process
13965 -- all the mapped entities, copying their descendents.
13967 if Present (Actual_Map) then
13968 declare
13969 Elmt : Elmt_Id;
13970 New_Itype : Entity_Id;
13971 begin
13972 Elmt := First_Elmt (Actual_Map);
13973 while Present (Elmt) loop
13974 Next_Elmt (Elmt);
13975 New_Itype := Node (Elmt);
13976 Copy_Itype_With_Replacement (New_Itype);
13977 Next_Elmt (Elmt);
13978 end loop;
13979 end;
13980 end if;
13982 -- Now we can copy the actual tree
13984 return Copy_Node_With_Replacement (Source);
13985 end New_Copy_Tree;
13987 -------------------------
13988 -- New_External_Entity --
13989 -------------------------
13991 function New_External_Entity
13992 (Kind : Entity_Kind;
13993 Scope_Id : Entity_Id;
13994 Sloc_Value : Source_Ptr;
13995 Related_Id : Entity_Id;
13996 Suffix : Character;
13997 Suffix_Index : Nat := 0;
13998 Prefix : Character := ' ') return Entity_Id
14000 N : constant Entity_Id :=
14001 Make_Defining_Identifier (Sloc_Value,
14002 New_External_Name
14003 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
14005 begin
14006 Set_Ekind (N, Kind);
14007 Set_Is_Internal (N, True);
14008 Append_Entity (N, Scope_Id);
14009 Set_Public_Status (N);
14011 if Kind in Type_Kind then
14012 Init_Size_Align (N);
14013 end if;
14015 return N;
14016 end New_External_Entity;
14018 -------------------------
14019 -- New_Internal_Entity --
14020 -------------------------
14022 function New_Internal_Entity
14023 (Kind : Entity_Kind;
14024 Scope_Id : Entity_Id;
14025 Sloc_Value : Source_Ptr;
14026 Id_Char : Character) return Entity_Id
14028 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
14030 begin
14031 Set_Ekind (N, Kind);
14032 Set_Is_Internal (N, True);
14033 Append_Entity (N, Scope_Id);
14035 if Kind in Type_Kind then
14036 Init_Size_Align (N);
14037 end if;
14039 return N;
14040 end New_Internal_Entity;
14042 -----------------
14043 -- Next_Actual --
14044 -----------------
14046 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
14047 N : Node_Id;
14049 begin
14050 -- If we are pointing at a positional parameter, it is a member of a
14051 -- node list (the list of parameters), and the next parameter is the
14052 -- next node on the list, unless we hit a parameter association, then
14053 -- we shift to using the chain whose head is the First_Named_Actual in
14054 -- the parent, and then is threaded using the Next_Named_Actual of the
14055 -- Parameter_Association. All this fiddling is because the original node
14056 -- list is in the textual call order, and what we need is the
14057 -- declaration order.
14059 if Is_List_Member (Actual_Id) then
14060 N := Next (Actual_Id);
14062 if Nkind (N) = N_Parameter_Association then
14063 return First_Named_Actual (Parent (Actual_Id));
14064 else
14065 return N;
14066 end if;
14068 else
14069 return Next_Named_Actual (Parent (Actual_Id));
14070 end if;
14071 end Next_Actual;
14073 procedure Next_Actual (Actual_Id : in out Node_Id) is
14074 begin
14075 Actual_Id := Next_Actual (Actual_Id);
14076 end Next_Actual;
14078 -----------------------
14079 -- Normalize_Actuals --
14080 -----------------------
14082 -- Chain actuals according to formals of subprogram. If there are no named
14083 -- associations, the chain is simply the list of Parameter Associations,
14084 -- since the order is the same as the declaration order. If there are named
14085 -- associations, then the First_Named_Actual field in the N_Function_Call
14086 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14087 -- node for the parameter that comes first in declaration order. The
14088 -- remaining named parameters are then chained in declaration order using
14089 -- Next_Named_Actual.
14091 -- This routine also verifies that the number of actuals is compatible with
14092 -- the number and default values of formals, but performs no type checking
14093 -- (type checking is done by the caller).
14095 -- If the matching succeeds, Success is set to True and the caller proceeds
14096 -- with type-checking. If the match is unsuccessful, then Success is set to
14097 -- False, and the caller attempts a different interpretation, if there is
14098 -- one.
14100 -- If the flag Report is on, the call is not overloaded, and a failure to
14101 -- match can be reported here, rather than in the caller.
14103 procedure Normalize_Actuals
14104 (N : Node_Id;
14105 S : Entity_Id;
14106 Report : Boolean;
14107 Success : out Boolean)
14109 Actuals : constant List_Id := Parameter_Associations (N);
14110 Actual : Node_Id := Empty;
14111 Formal : Entity_Id;
14112 Last : Node_Id := Empty;
14113 First_Named : Node_Id := Empty;
14114 Found : Boolean;
14116 Formals_To_Match : Integer := 0;
14117 Actuals_To_Match : Integer := 0;
14119 procedure Chain (A : Node_Id);
14120 -- Add named actual at the proper place in the list, using the
14121 -- Next_Named_Actual link.
14123 function Reporting return Boolean;
14124 -- Determines if an error is to be reported. To report an error, we
14125 -- need Report to be True, and also we do not report errors caused
14126 -- by calls to init procs that occur within other init procs. Such
14127 -- errors must always be cascaded errors, since if all the types are
14128 -- declared correctly, the compiler will certainly build decent calls.
14130 -----------
14131 -- Chain --
14132 -----------
14134 procedure Chain (A : Node_Id) is
14135 begin
14136 if No (Last) then
14138 -- Call node points to first actual in list
14140 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
14142 else
14143 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
14144 end if;
14146 Last := A;
14147 Set_Next_Named_Actual (Last, Empty);
14148 end Chain;
14150 ---------------
14151 -- Reporting --
14152 ---------------
14154 function Reporting return Boolean is
14155 begin
14156 if not Report then
14157 return False;
14159 elsif not Within_Init_Proc then
14160 return True;
14162 elsif Is_Init_Proc (Entity (Name (N))) then
14163 return False;
14165 else
14166 return True;
14167 end if;
14168 end Reporting;
14170 -- Start of processing for Normalize_Actuals
14172 begin
14173 if Is_Access_Type (S) then
14175 -- The name in the call is a function call that returns an access
14176 -- to subprogram. The designated type has the list of formals.
14178 Formal := First_Formal (Designated_Type (S));
14179 else
14180 Formal := First_Formal (S);
14181 end if;
14183 while Present (Formal) loop
14184 Formals_To_Match := Formals_To_Match + 1;
14185 Next_Formal (Formal);
14186 end loop;
14188 -- Find if there is a named association, and verify that no positional
14189 -- associations appear after named ones.
14191 if Present (Actuals) then
14192 Actual := First (Actuals);
14193 end if;
14195 while Present (Actual)
14196 and then Nkind (Actual) /= N_Parameter_Association
14197 loop
14198 Actuals_To_Match := Actuals_To_Match + 1;
14199 Next (Actual);
14200 end loop;
14202 if No (Actual) and Actuals_To_Match = Formals_To_Match then
14204 -- Most common case: positional notation, no defaults
14206 Success := True;
14207 return;
14209 elsif Actuals_To_Match > Formals_To_Match then
14211 -- Too many actuals: will not work
14213 if Reporting then
14214 if Is_Entity_Name (Name (N)) then
14215 Error_Msg_N ("too many arguments in call to&", Name (N));
14216 else
14217 Error_Msg_N ("too many arguments in call", N);
14218 end if;
14219 end if;
14221 Success := False;
14222 return;
14223 end if;
14225 First_Named := Actual;
14227 while Present (Actual) loop
14228 if Nkind (Actual) /= N_Parameter_Association then
14229 Error_Msg_N
14230 ("positional parameters not allowed after named ones", Actual);
14231 Success := False;
14232 return;
14234 else
14235 Actuals_To_Match := Actuals_To_Match + 1;
14236 end if;
14238 Next (Actual);
14239 end loop;
14241 if Present (Actuals) then
14242 Actual := First (Actuals);
14243 end if;
14245 Formal := First_Formal (S);
14246 while Present (Formal) loop
14248 -- Match the formals in order. If the corresponding actual is
14249 -- positional, nothing to do. Else scan the list of named actuals
14250 -- to find the one with the right name.
14252 if Present (Actual)
14253 and then Nkind (Actual) /= N_Parameter_Association
14254 then
14255 Next (Actual);
14256 Actuals_To_Match := Actuals_To_Match - 1;
14257 Formals_To_Match := Formals_To_Match - 1;
14259 else
14260 -- For named parameters, search the list of actuals to find
14261 -- one that matches the next formal name.
14263 Actual := First_Named;
14264 Found := False;
14265 while Present (Actual) loop
14266 if Chars (Selector_Name (Actual)) = Chars (Formal) then
14267 Found := True;
14268 Chain (Actual);
14269 Actuals_To_Match := Actuals_To_Match - 1;
14270 Formals_To_Match := Formals_To_Match - 1;
14271 exit;
14272 end if;
14274 Next (Actual);
14275 end loop;
14277 if not Found then
14278 if Ekind (Formal) /= E_In_Parameter
14279 or else No (Default_Value (Formal))
14280 then
14281 if Reporting then
14282 if (Comes_From_Source (S)
14283 or else Sloc (S) = Standard_Location)
14284 and then Is_Overloadable (S)
14285 then
14286 if No (Actuals)
14287 and then
14288 Nkind_In (Parent (N), N_Procedure_Call_Statement,
14289 N_Function_Call,
14290 N_Parameter_Association)
14291 and then Ekind (S) /= E_Function
14292 then
14293 Set_Etype (N, Etype (S));
14295 else
14296 Error_Msg_Name_1 := Chars (S);
14297 Error_Msg_Sloc := Sloc (S);
14298 Error_Msg_NE
14299 ("missing argument for parameter & " &
14300 "in call to % declared #", N, Formal);
14301 end if;
14303 elsif Is_Overloadable (S) then
14304 Error_Msg_Name_1 := Chars (S);
14306 -- Point to type derivation that generated the
14307 -- operation.
14309 Error_Msg_Sloc := Sloc (Parent (S));
14311 Error_Msg_NE
14312 ("missing argument for parameter & " &
14313 "in call to % (inherited) #", N, Formal);
14315 else
14316 Error_Msg_NE
14317 ("missing argument for parameter &", N, Formal);
14318 end if;
14319 end if;
14321 Success := False;
14322 return;
14324 else
14325 Formals_To_Match := Formals_To_Match - 1;
14326 end if;
14327 end if;
14328 end if;
14330 Next_Formal (Formal);
14331 end loop;
14333 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
14334 Success := True;
14335 return;
14337 else
14338 if Reporting then
14340 -- Find some superfluous named actual that did not get
14341 -- attached to the list of associations.
14343 Actual := First (Actuals);
14344 while Present (Actual) loop
14345 if Nkind (Actual) = N_Parameter_Association
14346 and then Actual /= Last
14347 and then No (Next_Named_Actual (Actual))
14348 then
14349 Error_Msg_N ("unmatched actual & in call",
14350 Selector_Name (Actual));
14351 exit;
14352 end if;
14354 Next (Actual);
14355 end loop;
14356 end if;
14358 Success := False;
14359 return;
14360 end if;
14361 end Normalize_Actuals;
14363 --------------------------------
14364 -- Note_Possible_Modification --
14365 --------------------------------
14367 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
14368 Modification_Comes_From_Source : constant Boolean :=
14369 Comes_From_Source (Parent (N));
14371 Ent : Entity_Id;
14372 Exp : Node_Id;
14374 begin
14375 -- Loop to find referenced entity, if there is one
14377 Exp := N;
14378 loop
14379 Ent := Empty;
14381 if Is_Entity_Name (Exp) then
14382 Ent := Entity (Exp);
14384 -- If the entity is missing, it is an undeclared identifier,
14385 -- and there is nothing to annotate.
14387 if No (Ent) then
14388 return;
14389 end if;
14391 elsif Nkind (Exp) = N_Explicit_Dereference then
14392 declare
14393 P : constant Node_Id := Prefix (Exp);
14395 begin
14396 -- In formal verification mode, keep track of all reads and
14397 -- writes through explicit dereferences.
14399 if GNATprove_Mode then
14400 SPARK_Specific.Generate_Dereference (N, 'm');
14401 end if;
14403 if Nkind (P) = N_Selected_Component
14404 and then Present (Entry_Formal (Entity (Selector_Name (P))))
14405 then
14406 -- Case of a reference to an entry formal
14408 Ent := Entry_Formal (Entity (Selector_Name (P)));
14410 elsif Nkind (P) = N_Identifier
14411 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
14412 and then Present (Expression (Parent (Entity (P))))
14413 and then Nkind (Expression (Parent (Entity (P)))) =
14414 N_Reference
14415 then
14416 -- Case of a reference to a value on which side effects have
14417 -- been removed.
14419 Exp := Prefix (Expression (Parent (Entity (P))));
14420 goto Continue;
14422 else
14423 return;
14424 end if;
14425 end;
14427 elsif Nkind_In (Exp, N_Type_Conversion,
14428 N_Unchecked_Type_Conversion)
14429 then
14430 Exp := Expression (Exp);
14431 goto Continue;
14433 elsif Nkind_In (Exp, N_Slice,
14434 N_Indexed_Component,
14435 N_Selected_Component)
14436 then
14437 -- Special check, if the prefix is an access type, then return
14438 -- since we are modifying the thing pointed to, not the prefix.
14439 -- When we are expanding, most usually the prefix is replaced
14440 -- by an explicit dereference, and this test is not needed, but
14441 -- in some cases (notably -gnatc mode and generics) when we do
14442 -- not do full expansion, we need this special test.
14444 if Is_Access_Type (Etype (Prefix (Exp))) then
14445 return;
14447 -- Otherwise go to prefix and keep going
14449 else
14450 Exp := Prefix (Exp);
14451 goto Continue;
14452 end if;
14454 -- All other cases, not a modification
14456 else
14457 return;
14458 end if;
14460 -- Now look for entity being referenced
14462 if Present (Ent) then
14463 if Is_Object (Ent) then
14464 if Comes_From_Source (Exp)
14465 or else Modification_Comes_From_Source
14466 then
14467 -- Give warning if pragma unmodified given and we are
14468 -- sure this is a modification.
14470 if Has_Pragma_Unmodified (Ent) and then Sure then
14471 Error_Msg_NE
14472 ("??pragma Unmodified given for &!", N, Ent);
14473 end if;
14475 Set_Never_Set_In_Source (Ent, False);
14476 end if;
14478 Set_Is_True_Constant (Ent, False);
14479 Set_Current_Value (Ent, Empty);
14480 Set_Is_Known_Null (Ent, False);
14482 if not Can_Never_Be_Null (Ent) then
14483 Set_Is_Known_Non_Null (Ent, False);
14484 end if;
14486 -- Follow renaming chain
14488 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
14489 and then Present (Renamed_Object (Ent))
14490 then
14491 Exp := Renamed_Object (Ent);
14493 -- If the entity is the loop variable in an iteration over
14494 -- a container, retrieve container expression to indicate
14495 -- possible modificastion.
14497 if Present (Related_Expression (Ent))
14498 and then Nkind (Parent (Related_Expression (Ent))) =
14499 N_Iterator_Specification
14500 then
14501 Exp := Original_Node (Related_Expression (Ent));
14502 end if;
14504 goto Continue;
14506 -- The expression may be the renaming of a subcomponent of an
14507 -- array or container. The assignment to the subcomponent is
14508 -- a modification of the container.
14510 elsif Comes_From_Source (Original_Node (Exp))
14511 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
14512 N_Indexed_Component)
14513 then
14514 Exp := Prefix (Original_Node (Exp));
14515 goto Continue;
14516 end if;
14518 -- Generate a reference only if the assignment comes from
14519 -- source. This excludes, for example, calls to a dispatching
14520 -- assignment operation when the left-hand side is tagged. In
14521 -- GNATprove mode, we need those references also on generated
14522 -- code, as these are used to compute the local effects of
14523 -- subprograms.
14525 if Modification_Comes_From_Source or GNATprove_Mode then
14526 Generate_Reference (Ent, Exp, 'm');
14528 -- If the target of the assignment is the bound variable
14529 -- in an iterator, indicate that the corresponding array
14530 -- or container is also modified.
14532 if Ada_Version >= Ada_2012
14533 and then Nkind (Parent (Ent)) = N_Iterator_Specification
14534 then
14535 declare
14536 Domain : constant Node_Id := Name (Parent (Ent));
14538 begin
14539 -- TBD : in the full version of the construct, the
14540 -- domain of iteration can be given by an expression.
14542 if Is_Entity_Name (Domain) then
14543 Generate_Reference (Entity (Domain), Exp, 'm');
14544 Set_Is_True_Constant (Entity (Domain), False);
14545 Set_Never_Set_In_Source (Entity (Domain), False);
14546 end if;
14547 end;
14548 end if;
14549 end if;
14551 Check_Nested_Access (Ent);
14552 end if;
14554 Kill_Checks (Ent);
14556 -- If we are sure this is a modification from source, and we know
14557 -- this modifies a constant, then give an appropriate warning.
14559 if Overlays_Constant (Ent)
14560 and then Modification_Comes_From_Source
14561 and then Sure
14562 then
14563 declare
14564 A : constant Node_Id := Address_Clause (Ent);
14565 begin
14566 if Present (A) then
14567 declare
14568 Exp : constant Node_Id := Expression (A);
14569 begin
14570 if Nkind (Exp) = N_Attribute_Reference
14571 and then Attribute_Name (Exp) = Name_Address
14572 and then Is_Entity_Name (Prefix (Exp))
14573 then
14574 Error_Msg_Sloc := Sloc (A);
14575 Error_Msg_NE
14576 ("constant& may be modified via address "
14577 & "clause#??", N, Entity (Prefix (Exp)));
14578 end if;
14579 end;
14580 end if;
14581 end;
14582 end if;
14584 return;
14585 end if;
14587 <<Continue>>
14588 null;
14589 end loop;
14590 end Note_Possible_Modification;
14592 -------------------------
14593 -- Object_Access_Level --
14594 -------------------------
14596 -- Returns the static accessibility level of the view denoted by Obj. Note
14597 -- that the value returned is the result of a call to Scope_Depth. Only
14598 -- scope depths associated with dynamic scopes can actually be returned.
14599 -- Since only relative levels matter for accessibility checking, the fact
14600 -- that the distance between successive levels of accessibility is not
14601 -- always one is immaterial (invariant: if level(E2) is deeper than
14602 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
14604 function Object_Access_Level (Obj : Node_Id) return Uint is
14605 function Is_Interface_Conversion (N : Node_Id) return Boolean;
14606 -- Determine whether N is a construct of the form
14607 -- Some_Type (Operand._tag'Address)
14608 -- This construct appears in the context of dispatching calls.
14610 function Reference_To (Obj : Node_Id) return Node_Id;
14611 -- An explicit dereference is created when removing side-effects from
14612 -- expressions for constraint checking purposes. In this case a local
14613 -- access type is created for it. The correct access level is that of
14614 -- the original source node. We detect this case by noting that the
14615 -- prefix of the dereference is created by an object declaration whose
14616 -- initial expression is a reference.
14618 -----------------------------
14619 -- Is_Interface_Conversion --
14620 -----------------------------
14622 function Is_Interface_Conversion (N : Node_Id) return Boolean is
14623 begin
14624 return Nkind (N) = N_Unchecked_Type_Conversion
14625 and then Nkind (Expression (N)) = N_Attribute_Reference
14626 and then Attribute_Name (Expression (N)) = Name_Address;
14627 end Is_Interface_Conversion;
14629 ------------------
14630 -- Reference_To --
14631 ------------------
14633 function Reference_To (Obj : Node_Id) return Node_Id is
14634 Pref : constant Node_Id := Prefix (Obj);
14635 begin
14636 if Is_Entity_Name (Pref)
14637 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
14638 and then Present (Expression (Parent (Entity (Pref))))
14639 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
14640 then
14641 return (Prefix (Expression (Parent (Entity (Pref)))));
14642 else
14643 return Empty;
14644 end if;
14645 end Reference_To;
14647 -- Local variables
14649 E : Entity_Id;
14651 -- Start of processing for Object_Access_Level
14653 begin
14654 if Nkind (Obj) = N_Defining_Identifier
14655 or else Is_Entity_Name (Obj)
14656 then
14657 if Nkind (Obj) = N_Defining_Identifier then
14658 E := Obj;
14659 else
14660 E := Entity (Obj);
14661 end if;
14663 if Is_Prival (E) then
14664 E := Prival_Link (E);
14665 end if;
14667 -- If E is a type then it denotes a current instance. For this case
14668 -- we add one to the normal accessibility level of the type to ensure
14669 -- that current instances are treated as always being deeper than
14670 -- than the level of any visible named access type (see 3.10.2(21)).
14672 if Is_Type (E) then
14673 return Type_Access_Level (E) + 1;
14675 elsif Present (Renamed_Object (E)) then
14676 return Object_Access_Level (Renamed_Object (E));
14678 -- Similarly, if E is a component of the current instance of a
14679 -- protected type, any instance of it is assumed to be at a deeper
14680 -- level than the type. For a protected object (whose type is an
14681 -- anonymous protected type) its components are at the same level
14682 -- as the type itself.
14684 elsif not Is_Overloadable (E)
14685 and then Ekind (Scope (E)) = E_Protected_Type
14686 and then Comes_From_Source (Scope (E))
14687 then
14688 return Type_Access_Level (Scope (E)) + 1;
14690 else
14691 -- Aliased formals take their access level from the point of call.
14692 -- This is smaller than the level of the subprogram itself.
14694 if Is_Formal (E) and then Is_Aliased (E) then
14695 return Type_Access_Level (Etype (E));
14697 else
14698 return Scope_Depth (Enclosing_Dynamic_Scope (E));
14699 end if;
14700 end if;
14702 elsif Nkind (Obj) = N_Selected_Component then
14703 if Is_Access_Type (Etype (Prefix (Obj))) then
14704 return Type_Access_Level (Etype (Prefix (Obj)));
14705 else
14706 return Object_Access_Level (Prefix (Obj));
14707 end if;
14709 elsif Nkind (Obj) = N_Indexed_Component then
14710 if Is_Access_Type (Etype (Prefix (Obj))) then
14711 return Type_Access_Level (Etype (Prefix (Obj)));
14712 else
14713 return Object_Access_Level (Prefix (Obj));
14714 end if;
14716 elsif Nkind (Obj) = N_Explicit_Dereference then
14718 -- If the prefix is a selected access discriminant then we make a
14719 -- recursive call on the prefix, which will in turn check the level
14720 -- of the prefix object of the selected discriminant.
14722 if Nkind (Prefix (Obj)) = N_Selected_Component
14723 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
14724 and then
14725 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
14726 then
14727 return Object_Access_Level (Prefix (Obj));
14729 -- Detect an interface conversion in the context of a dispatching
14730 -- call. Use the original form of the conversion to find the access
14731 -- level of the operand.
14733 elsif Is_Interface (Etype (Obj))
14734 and then Is_Interface_Conversion (Prefix (Obj))
14735 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
14736 then
14737 return Object_Access_Level (Original_Node (Obj));
14739 elsif not Comes_From_Source (Obj) then
14740 declare
14741 Ref : constant Node_Id := Reference_To (Obj);
14742 begin
14743 if Present (Ref) then
14744 return Object_Access_Level (Ref);
14745 else
14746 return Type_Access_Level (Etype (Prefix (Obj)));
14747 end if;
14748 end;
14750 else
14751 return Type_Access_Level (Etype (Prefix (Obj)));
14752 end if;
14754 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
14755 return Object_Access_Level (Expression (Obj));
14757 elsif Nkind (Obj) = N_Function_Call then
14759 -- Function results are objects, so we get either the access level of
14760 -- the function or, in the case of an indirect call, the level of the
14761 -- access-to-subprogram type. (This code is used for Ada 95, but it
14762 -- looks wrong, because it seems that we should be checking the level
14763 -- of the call itself, even for Ada 95. However, using the Ada 2005
14764 -- version of the code causes regressions in several tests that are
14765 -- compiled with -gnat95. ???)
14767 if Ada_Version < Ada_2005 then
14768 if Is_Entity_Name (Name (Obj)) then
14769 return Subprogram_Access_Level (Entity (Name (Obj)));
14770 else
14771 return Type_Access_Level (Etype (Prefix (Name (Obj))));
14772 end if;
14774 -- For Ada 2005, the level of the result object of a function call is
14775 -- defined to be the level of the call's innermost enclosing master.
14776 -- We determine that by querying the depth of the innermost enclosing
14777 -- dynamic scope.
14779 else
14780 Return_Master_Scope_Depth_Of_Call : declare
14782 function Innermost_Master_Scope_Depth
14783 (N : Node_Id) return Uint;
14784 -- Returns the scope depth of the given node's innermost
14785 -- enclosing dynamic scope (effectively the accessibility
14786 -- level of the innermost enclosing master).
14788 ----------------------------------
14789 -- Innermost_Master_Scope_Depth --
14790 ----------------------------------
14792 function Innermost_Master_Scope_Depth
14793 (N : Node_Id) return Uint
14795 Node_Par : Node_Id := Parent (N);
14797 begin
14798 -- Locate the nearest enclosing node (by traversing Parents)
14799 -- that Defining_Entity can be applied to, and return the
14800 -- depth of that entity's nearest enclosing dynamic scope.
14802 while Present (Node_Par) loop
14803 case Nkind (Node_Par) is
14804 when N_Component_Declaration |
14805 N_Entry_Declaration |
14806 N_Formal_Object_Declaration |
14807 N_Formal_Type_Declaration |
14808 N_Full_Type_Declaration |
14809 N_Incomplete_Type_Declaration |
14810 N_Loop_Parameter_Specification |
14811 N_Object_Declaration |
14812 N_Protected_Type_Declaration |
14813 N_Private_Extension_Declaration |
14814 N_Private_Type_Declaration |
14815 N_Subtype_Declaration |
14816 N_Function_Specification |
14817 N_Procedure_Specification |
14818 N_Task_Type_Declaration |
14819 N_Body_Stub |
14820 N_Generic_Instantiation |
14821 N_Proper_Body |
14822 N_Implicit_Label_Declaration |
14823 N_Package_Declaration |
14824 N_Single_Task_Declaration |
14825 N_Subprogram_Declaration |
14826 N_Generic_Declaration |
14827 N_Renaming_Declaration |
14828 N_Block_Statement |
14829 N_Formal_Subprogram_Declaration |
14830 N_Abstract_Subprogram_Declaration |
14831 N_Entry_Body |
14832 N_Exception_Declaration |
14833 N_Formal_Package_Declaration |
14834 N_Number_Declaration |
14835 N_Package_Specification |
14836 N_Parameter_Specification |
14837 N_Single_Protected_Declaration |
14838 N_Subunit =>
14840 return Scope_Depth
14841 (Nearest_Dynamic_Scope
14842 (Defining_Entity (Node_Par)));
14844 when others =>
14845 null;
14846 end case;
14848 Node_Par := Parent (Node_Par);
14849 end loop;
14851 pragma Assert (False);
14853 -- Should never reach the following return
14855 return Scope_Depth (Current_Scope) + 1;
14856 end Innermost_Master_Scope_Depth;
14858 -- Start of processing for Return_Master_Scope_Depth_Of_Call
14860 begin
14861 return Innermost_Master_Scope_Depth (Obj);
14862 end Return_Master_Scope_Depth_Of_Call;
14863 end if;
14865 -- For convenience we handle qualified expressions, even though they
14866 -- aren't technically object names.
14868 elsif Nkind (Obj) = N_Qualified_Expression then
14869 return Object_Access_Level (Expression (Obj));
14871 -- Ditto for aggregates. They have the level of the temporary that
14872 -- will hold their value.
14874 elsif Nkind (Obj) = N_Aggregate then
14875 return Object_Access_Level (Current_Scope);
14877 -- Otherwise return the scope level of Standard. (If there are cases
14878 -- that fall through to this point they will be treated as having
14879 -- global accessibility for now. ???)
14881 else
14882 return Scope_Depth (Standard_Standard);
14883 end if;
14884 end Object_Access_Level;
14886 --------------------------
14887 -- Original_Aspect_Name --
14888 --------------------------
14890 function Original_Aspect_Name (N : Node_Id) return Name_Id is
14891 Pras : Node_Id;
14892 Name : Name_Id;
14894 begin
14895 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
14896 Pras := N;
14898 if Is_Rewrite_Substitution (Pras)
14899 and then Nkind (Original_Node (Pras)) = N_Pragma
14900 then
14901 Pras := Original_Node (Pras);
14902 end if;
14904 -- Case where we came from aspect specication
14906 if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
14907 Pras := Corresponding_Aspect (Pras);
14908 end if;
14910 -- Get name from aspect or pragma
14912 if Nkind (Pras) = N_Pragma then
14913 Name := Pragma_Name (Pras);
14914 else
14915 Name := Chars (Identifier (Pras));
14916 end if;
14918 -- Deal with 'Class
14920 if Class_Present (Pras) then
14921 case Name is
14923 -- Names that need converting to special _xxx form
14925 when Name_Pre |
14926 Name_Pre_Class =>
14927 Name := Name_uPre;
14929 when Name_Post |
14930 Name_Post_Class =>
14931 Name := Name_uPost;
14933 when Name_Invariant =>
14934 Name := Name_uInvariant;
14936 when Name_Type_Invariant |
14937 Name_Type_Invariant_Class =>
14938 Name := Name_uType_Invariant;
14940 -- Nothing to do for other cases (e.g. a Check that derived
14941 -- from Pre_Class and has the flag set). Also we do nothing
14942 -- if the name is already in special _xxx form.
14944 when others =>
14945 null;
14946 end case;
14947 end if;
14949 return Name;
14950 end Original_Aspect_Name;
14952 --------------------------------------
14953 -- Original_Corresponding_Operation --
14954 --------------------------------------
14956 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
14958 Typ : constant Entity_Id := Find_Dispatching_Type (S);
14960 begin
14961 -- If S is an inherited primitive S2 the original corresponding
14962 -- operation of S is the original corresponding operation of S2
14964 if Present (Alias (S))
14965 and then Find_Dispatching_Type (Alias (S)) /= Typ
14966 then
14967 return Original_Corresponding_Operation (Alias (S));
14969 -- If S overrides an inherited subprogram S2 the original corresponding
14970 -- operation of S is the original corresponding operation of S2
14972 elsif Present (Overridden_Operation (S)) then
14973 return Original_Corresponding_Operation (Overridden_Operation (S));
14975 -- otherwise it is S itself
14977 else
14978 return S;
14979 end if;
14980 end Original_Corresponding_Operation;
14982 ----------------------------------
14983 -- Predicate_Tests_On_Arguments --
14984 ----------------------------------
14986 function Predicate_Tests_On_Arguments (Subp : Entity_Id) return Boolean is
14987 begin
14988 -- Always test predicates on indirect call
14990 if Ekind (Subp) = E_Subprogram_Type then
14991 return True;
14993 -- Do not test predicates on call to generated default Finalize, since
14994 -- we are not interested in whether something we are finalizing (and
14995 -- typically destroying) satisfies its predicates.
14997 elsif Chars (Subp) = Name_Finalize
14998 and then not Comes_From_Source (Subp)
14999 then
15000 return False;
15002 -- Do not test predicates on any internally generated routines
15004 elsif Is_Internal_Name (Chars (Subp)) then
15005 return False;
15007 -- Do not test predicates on call to Init_Proc, since if needed the
15008 -- predicate test will occur at some other point.
15010 elsif Is_Init_Proc (Subp) then
15011 return False;
15013 -- Do not test predicates on call to predicate function, since this
15014 -- would cause infinite recursion.
15016 elsif Ekind (Subp) = E_Function
15017 and then (Is_Predicate_Function (Subp)
15018 or else
15019 Is_Predicate_Function_M (Subp))
15020 then
15021 return False;
15023 -- For now, no other exceptions
15025 else
15026 return True;
15027 end if;
15028 end Predicate_Tests_On_Arguments;
15030 -----------------------
15031 -- Private_Component --
15032 -----------------------
15034 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
15035 Ancestor : constant Entity_Id := Base_Type (Type_Id);
15037 function Trace_Components
15038 (T : Entity_Id;
15039 Check : Boolean) return Entity_Id;
15040 -- Recursive function that does the work, and checks against circular
15041 -- definition for each subcomponent type.
15043 ----------------------
15044 -- Trace_Components --
15045 ----------------------
15047 function Trace_Components
15048 (T : Entity_Id;
15049 Check : Boolean) return Entity_Id
15051 Btype : constant Entity_Id := Base_Type (T);
15052 Component : Entity_Id;
15053 P : Entity_Id;
15054 Candidate : Entity_Id := Empty;
15056 begin
15057 if Check and then Btype = Ancestor then
15058 Error_Msg_N ("circular type definition", Type_Id);
15059 return Any_Type;
15060 end if;
15062 if Is_Private_Type (Btype) and then not Is_Generic_Type (Btype) then
15063 if Present (Full_View (Btype))
15064 and then Is_Record_Type (Full_View (Btype))
15065 and then not Is_Frozen (Btype)
15066 then
15067 -- To indicate that the ancestor depends on a private type, the
15068 -- current Btype is sufficient. However, to check for circular
15069 -- definition we must recurse on the full view.
15071 Candidate := Trace_Components (Full_View (Btype), True);
15073 if Candidate = Any_Type then
15074 return Any_Type;
15075 else
15076 return Btype;
15077 end if;
15079 else
15080 return Btype;
15081 end if;
15083 elsif Is_Array_Type (Btype) then
15084 return Trace_Components (Component_Type (Btype), True);
15086 elsif Is_Record_Type (Btype) then
15087 Component := First_Entity (Btype);
15088 while Present (Component)
15089 and then Comes_From_Source (Component)
15090 loop
15091 -- Skip anonymous types generated by constrained components
15093 if not Is_Type (Component) then
15094 P := Trace_Components (Etype (Component), True);
15096 if Present (P) then
15097 if P = Any_Type then
15098 return P;
15099 else
15100 Candidate := P;
15101 end if;
15102 end if;
15103 end if;
15105 Next_Entity (Component);
15106 end loop;
15108 return Candidate;
15110 else
15111 return Empty;
15112 end if;
15113 end Trace_Components;
15115 -- Start of processing for Private_Component
15117 begin
15118 return Trace_Components (Type_Id, False);
15119 end Private_Component;
15121 ---------------------------
15122 -- Primitive_Names_Match --
15123 ---------------------------
15125 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
15127 function Non_Internal_Name (E : Entity_Id) return Name_Id;
15128 -- Given an internal name, returns the corresponding non-internal name
15130 ------------------------
15131 -- Non_Internal_Name --
15132 ------------------------
15134 function Non_Internal_Name (E : Entity_Id) return Name_Id is
15135 begin
15136 Get_Name_String (Chars (E));
15137 Name_Len := Name_Len - 1;
15138 return Name_Find;
15139 end Non_Internal_Name;
15141 -- Start of processing for Primitive_Names_Match
15143 begin
15144 pragma Assert (Present (E1) and then Present (E2));
15146 return Chars (E1) = Chars (E2)
15147 or else
15148 (not Is_Internal_Name (Chars (E1))
15149 and then Is_Internal_Name (Chars (E2))
15150 and then Non_Internal_Name (E2) = Chars (E1))
15151 or else
15152 (not Is_Internal_Name (Chars (E2))
15153 and then Is_Internal_Name (Chars (E1))
15154 and then Non_Internal_Name (E1) = Chars (E2))
15155 or else
15156 (Is_Predefined_Dispatching_Operation (E1)
15157 and then Is_Predefined_Dispatching_Operation (E2)
15158 and then Same_TSS (E1, E2))
15159 or else
15160 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
15161 end Primitive_Names_Match;
15163 -----------------------
15164 -- Process_End_Label --
15165 -----------------------
15167 procedure Process_End_Label
15168 (N : Node_Id;
15169 Typ : Character;
15170 Ent : Entity_Id)
15172 Loc : Source_Ptr;
15173 Nam : Node_Id;
15174 Scop : Entity_Id;
15176 Label_Ref : Boolean;
15177 -- Set True if reference to end label itself is required
15179 Endl : Node_Id;
15180 -- Gets set to the operator symbol or identifier that references the
15181 -- entity Ent. For the child unit case, this is the identifier from the
15182 -- designator. For other cases, this is simply Endl.
15184 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
15185 -- N is an identifier node that appears as a parent unit reference in
15186 -- the case where Ent is a child unit. This procedure generates an
15187 -- appropriate cross-reference entry. E is the corresponding entity.
15189 -------------------------
15190 -- Generate_Parent_Ref --
15191 -------------------------
15193 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
15194 begin
15195 -- If names do not match, something weird, skip reference
15197 if Chars (E) = Chars (N) then
15199 -- Generate the reference. We do NOT consider this as a reference
15200 -- for unreferenced symbol purposes.
15202 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
15204 if Style_Check then
15205 Style.Check_Identifier (N, E);
15206 end if;
15207 end if;
15208 end Generate_Parent_Ref;
15210 -- Start of processing for Process_End_Label
15212 begin
15213 -- If no node, ignore. This happens in some error situations, and
15214 -- also for some internally generated structures where no end label
15215 -- references are required in any case.
15217 if No (N) then
15218 return;
15219 end if;
15221 -- Nothing to do if no End_Label, happens for internally generated
15222 -- constructs where we don't want an end label reference anyway. Also
15223 -- nothing to do if Endl is a string literal, which means there was
15224 -- some prior error (bad operator symbol)
15226 Endl := End_Label (N);
15228 if No (Endl) or else Nkind (Endl) = N_String_Literal then
15229 return;
15230 end if;
15232 -- Reference node is not in extended main source unit
15234 if not In_Extended_Main_Source_Unit (N) then
15236 -- Generally we do not collect references except for the extended
15237 -- main source unit. The one exception is the 'e' entry for a
15238 -- package spec, where it is useful for a client to have the
15239 -- ending information to define scopes.
15241 if Typ /= 'e' then
15242 return;
15244 else
15245 Label_Ref := False;
15247 -- For this case, we can ignore any parent references, but we
15248 -- need the package name itself for the 'e' entry.
15250 if Nkind (Endl) = N_Designator then
15251 Endl := Identifier (Endl);
15252 end if;
15253 end if;
15255 -- Reference is in extended main source unit
15257 else
15258 Label_Ref := True;
15260 -- For designator, generate references for the parent entries
15262 if Nkind (Endl) = N_Designator then
15264 -- Generate references for the prefix if the END line comes from
15265 -- source (otherwise we do not need these references) We climb the
15266 -- scope stack to find the expected entities.
15268 if Comes_From_Source (Endl) then
15269 Nam := Name (Endl);
15270 Scop := Current_Scope;
15271 while Nkind (Nam) = N_Selected_Component loop
15272 Scop := Scope (Scop);
15273 exit when No (Scop);
15274 Generate_Parent_Ref (Selector_Name (Nam), Scop);
15275 Nam := Prefix (Nam);
15276 end loop;
15278 if Present (Scop) then
15279 Generate_Parent_Ref (Nam, Scope (Scop));
15280 end if;
15281 end if;
15283 Endl := Identifier (Endl);
15284 end if;
15285 end if;
15287 -- If the end label is not for the given entity, then either we have
15288 -- some previous error, or this is a generic instantiation for which
15289 -- we do not need to make a cross-reference in this case anyway. In
15290 -- either case we simply ignore the call.
15292 if Chars (Ent) /= Chars (Endl) then
15293 return;
15294 end if;
15296 -- If label was really there, then generate a normal reference and then
15297 -- adjust the location in the end label to point past the name (which
15298 -- should almost always be the semicolon).
15300 Loc := Sloc (Endl);
15302 if Comes_From_Source (Endl) then
15304 -- If a label reference is required, then do the style check and
15305 -- generate an l-type cross-reference entry for the label
15307 if Label_Ref then
15308 if Style_Check then
15309 Style.Check_Identifier (Endl, Ent);
15310 end if;
15312 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
15313 end if;
15315 -- Set the location to point past the label (normally this will
15316 -- mean the semicolon immediately following the label). This is
15317 -- done for the sake of the 'e' or 't' entry generated below.
15319 Get_Decoded_Name_String (Chars (Endl));
15320 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
15322 else
15323 -- In SPARK mode, no missing label is allowed for packages and
15324 -- subprogram bodies. Detect those cases by testing whether
15325 -- Process_End_Label was called for a body (Typ = 't') or a package.
15327 if Restriction_Check_Required (SPARK_05)
15328 and then (Typ = 't' or else Ekind (Ent) = E_Package)
15329 then
15330 Error_Msg_Node_1 := Endl;
15331 Check_SPARK_05_Restriction
15332 ("`END &` required", Endl, Force => True);
15333 end if;
15334 end if;
15336 -- Now generate the e/t reference
15338 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
15340 -- Restore Sloc, in case modified above, since we have an identifier
15341 -- and the normal Sloc should be left set in the tree.
15343 Set_Sloc (Endl, Loc);
15344 end Process_End_Label;
15346 ----------------
15347 -- Referenced --
15348 ----------------
15350 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
15351 Seen : Boolean := False;
15353 function Is_Reference (N : Node_Id) return Traverse_Result;
15354 -- Determine whether node N denotes a reference to Id. If this is the
15355 -- case, set global flag Seen to True and stop the traversal.
15357 ------------------
15358 -- Is_Reference --
15359 ------------------
15361 function Is_Reference (N : Node_Id) return Traverse_Result is
15362 begin
15363 if Is_Entity_Name (N)
15364 and then Present (Entity (N))
15365 and then Entity (N) = Id
15366 then
15367 Seen := True;
15368 return Abandon;
15369 else
15370 return OK;
15371 end if;
15372 end Is_Reference;
15374 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
15376 -- Start of processing for Referenced
15378 begin
15379 Inspect_Expression (Expr);
15380 return Seen;
15381 end Referenced;
15383 ------------------------------------
15384 -- References_Generic_Formal_Type --
15385 ------------------------------------
15387 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
15389 function Process (N : Node_Id) return Traverse_Result;
15390 -- Process one node in search for generic formal type
15392 -------------
15393 -- Process --
15394 -------------
15396 function Process (N : Node_Id) return Traverse_Result is
15397 begin
15398 if Nkind (N) in N_Has_Entity then
15399 declare
15400 E : constant Entity_Id := Entity (N);
15401 begin
15402 if Present (E) then
15403 if Is_Generic_Type (E) then
15404 return Abandon;
15405 elsif Present (Etype (E))
15406 and then Is_Generic_Type (Etype (E))
15407 then
15408 return Abandon;
15409 end if;
15410 end if;
15411 end;
15412 end if;
15414 return Atree.OK;
15415 end Process;
15417 function Traverse is new Traverse_Func (Process);
15418 -- Traverse tree to look for generic type
15420 begin
15421 if Inside_A_Generic then
15422 return Traverse (N) = Abandon;
15423 else
15424 return False;
15425 end if;
15426 end References_Generic_Formal_Type;
15428 --------------------
15429 -- Remove_Homonym --
15430 --------------------
15432 procedure Remove_Homonym (E : Entity_Id) is
15433 Prev : Entity_Id := Empty;
15434 H : Entity_Id;
15436 begin
15437 if E = Current_Entity (E) then
15438 if Present (Homonym (E)) then
15439 Set_Current_Entity (Homonym (E));
15440 else
15441 Set_Name_Entity_Id (Chars (E), Empty);
15442 end if;
15444 else
15445 H := Current_Entity (E);
15446 while Present (H) and then H /= E loop
15447 Prev := H;
15448 H := Homonym (H);
15449 end loop;
15451 -- If E is not on the homonym chain, nothing to do
15453 if Present (H) then
15454 Set_Homonym (Prev, Homonym (E));
15455 end if;
15456 end if;
15457 end Remove_Homonym;
15459 ---------------------
15460 -- Rep_To_Pos_Flag --
15461 ---------------------
15463 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
15464 begin
15465 return New_Occurrence_Of
15466 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
15467 end Rep_To_Pos_Flag;
15469 --------------------
15470 -- Require_Entity --
15471 --------------------
15473 procedure Require_Entity (N : Node_Id) is
15474 begin
15475 if Is_Entity_Name (N) and then No (Entity (N)) then
15476 if Total_Errors_Detected /= 0 then
15477 Set_Entity (N, Any_Id);
15478 else
15479 raise Program_Error;
15480 end if;
15481 end if;
15482 end Require_Entity;
15484 -------------------------------
15485 -- Requires_State_Refinement --
15486 -------------------------------
15488 function Requires_State_Refinement
15489 (Spec_Id : Entity_Id;
15490 Body_Id : Entity_Id) return Boolean
15492 function Mode_Is_Off (Prag : Node_Id) return Boolean;
15493 -- Given pragma SPARK_Mode, determine whether the mode is Off
15495 -----------------
15496 -- Mode_Is_Off --
15497 -----------------
15499 function Mode_Is_Off (Prag : Node_Id) return Boolean is
15500 Mode : Node_Id;
15502 begin
15503 -- The default SPARK mode is On
15505 if No (Prag) then
15506 return False;
15507 end if;
15509 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
15511 -- Then the pragma lacks an argument, the default mode is On
15513 if No (Mode) then
15514 return False;
15515 else
15516 return Chars (Mode) = Name_Off;
15517 end if;
15518 end Mode_Is_Off;
15520 -- Start of processing for Requires_State_Refinement
15522 begin
15523 -- A package that does not define at least one abstract state cannot
15524 -- possibly require refinement.
15526 if No (Abstract_States (Spec_Id)) then
15527 return False;
15529 -- The package instroduces a single null state which does not merit
15530 -- refinement.
15532 elsif Has_Null_Abstract_State (Spec_Id) then
15533 return False;
15535 -- Check whether the package body is subject to pragma SPARK_Mode. If
15536 -- it is and the mode is Off, the package body is considered to be in
15537 -- regular Ada and does not require refinement.
15539 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
15540 return False;
15542 -- The body's SPARK_Mode may be inherited from a similar pragma that
15543 -- appears in the private declarations of the spec. The pragma we are
15544 -- interested appears as the second entry in SPARK_Pragma.
15546 elsif Present (SPARK_Pragma (Spec_Id))
15547 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
15548 then
15549 return False;
15551 -- The spec defines at least one abstract state and the body has no way
15552 -- of circumventing the refinement.
15554 else
15555 return True;
15556 end if;
15557 end Requires_State_Refinement;
15559 ------------------------------
15560 -- Requires_Transient_Scope --
15561 ------------------------------
15563 -- A transient scope is required when variable-sized temporaries are
15564 -- allocated in the primary or secondary stack, or when finalization
15565 -- actions must be generated before the next instruction.
15567 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
15568 Typ : constant Entity_Id := Underlying_Type (Id);
15570 -- Start of processing for Requires_Transient_Scope
15572 begin
15573 -- This is a private type which is not completed yet. This can only
15574 -- happen in a default expression (of a formal parameter or of a
15575 -- record component). Do not expand transient scope in this case
15577 if No (Typ) then
15578 return False;
15580 -- Do not expand transient scope for non-existent procedure return
15582 elsif Typ = Standard_Void_Type then
15583 return False;
15585 -- Elementary types do not require a transient scope
15587 elsif Is_Elementary_Type (Typ) then
15588 return False;
15590 -- Generally, indefinite subtypes require a transient scope, since the
15591 -- back end cannot generate temporaries, since this is not a valid type
15592 -- for declaring an object. It might be possible to relax this in the
15593 -- future, e.g. by declaring the maximum possible space for the type.
15595 elsif Is_Indefinite_Subtype (Typ) then
15596 return True;
15598 -- Functions returning tagged types may dispatch on result so their
15599 -- returned value is allocated on the secondary stack. Controlled
15600 -- type temporaries need finalization.
15602 elsif Is_Tagged_Type (Typ)
15603 or else Has_Controlled_Component (Typ)
15604 then
15605 return not Is_Value_Type (Typ);
15607 -- Record type
15609 elsif Is_Record_Type (Typ) then
15610 declare
15611 Comp : Entity_Id;
15612 begin
15613 Comp := First_Entity (Typ);
15614 while Present (Comp) loop
15615 if Ekind (Comp) = E_Component
15616 and then Requires_Transient_Scope (Etype (Comp))
15617 then
15618 return True;
15619 else
15620 Next_Entity (Comp);
15621 end if;
15622 end loop;
15623 end;
15625 return False;
15627 -- String literal types never require transient scope
15629 elsif Ekind (Typ) = E_String_Literal_Subtype then
15630 return False;
15632 -- Array type. Note that we already know that this is a constrained
15633 -- array, since unconstrained arrays will fail the indefinite test.
15635 elsif Is_Array_Type (Typ) then
15637 -- If component type requires a transient scope, the array does too
15639 if Requires_Transient_Scope (Component_Type (Typ)) then
15640 return True;
15642 -- Otherwise, we only need a transient scope if the size depends on
15643 -- the value of one or more discriminants.
15645 else
15646 return Size_Depends_On_Discriminant (Typ);
15647 end if;
15649 -- All other cases do not require a transient scope
15651 else
15652 return False;
15653 end if;
15654 end Requires_Transient_Scope;
15656 --------------------------
15657 -- Reset_Analyzed_Flags --
15658 --------------------------
15660 procedure Reset_Analyzed_Flags (N : Node_Id) is
15662 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
15663 -- Function used to reset Analyzed flags in tree. Note that we do
15664 -- not reset Analyzed flags in entities, since there is no need to
15665 -- reanalyze entities, and indeed, it is wrong to do so, since it
15666 -- can result in generating auxiliary stuff more than once.
15668 --------------------
15669 -- Clear_Analyzed --
15670 --------------------
15672 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
15673 begin
15674 if not Has_Extension (N) then
15675 Set_Analyzed (N, False);
15676 end if;
15678 return OK;
15679 end Clear_Analyzed;
15681 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
15683 -- Start of processing for Reset_Analyzed_Flags
15685 begin
15686 Reset_Analyzed (N);
15687 end Reset_Analyzed_Flags;
15689 ------------------------
15690 -- Restore_SPARK_Mode --
15691 ------------------------
15693 procedure Restore_SPARK_Mode (Mode : SPARK_Mode_Type) is
15694 begin
15695 SPARK_Mode := Mode;
15696 end Restore_SPARK_Mode;
15698 --------------------------------
15699 -- Returns_Unconstrained_Type --
15700 --------------------------------
15702 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
15703 begin
15704 return Ekind (Subp) = E_Function
15705 and then not Is_Scalar_Type (Etype (Subp))
15706 and then not Is_Access_Type (Etype (Subp))
15707 and then not Is_Constrained (Etype (Subp));
15708 end Returns_Unconstrained_Type;
15710 ----------------------------
15711 -- Root_Type_Of_Full_View --
15712 ----------------------------
15714 function Root_Type_Of_Full_View (T : Entity_Id) return Entity_Id is
15715 Rtyp : constant Entity_Id := Root_Type (T);
15717 begin
15718 -- The root type of the full view may itself be a private type. Keep
15719 -- looking for the ultimate derivation parent.
15721 if Is_Private_Type (Rtyp) and then Present (Full_View (Rtyp)) then
15722 return Root_Type_Of_Full_View (Full_View (Rtyp));
15723 else
15724 return Rtyp;
15725 end if;
15726 end Root_Type_Of_Full_View;
15728 ---------------------------
15729 -- Safe_To_Capture_Value --
15730 ---------------------------
15732 function Safe_To_Capture_Value
15733 (N : Node_Id;
15734 Ent : Entity_Id;
15735 Cond : Boolean := False) return Boolean
15737 begin
15738 -- The only entities for which we track constant values are variables
15739 -- which are not renamings, constants, out parameters, and in out
15740 -- parameters, so check if we have this case.
15742 -- Note: it may seem odd to track constant values for constants, but in
15743 -- fact this routine is used for other purposes than simply capturing
15744 -- the value. In particular, the setting of Known[_Non]_Null.
15746 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
15747 or else
15748 Ekind (Ent) = E_Constant
15749 or else
15750 Ekind (Ent) = E_Out_Parameter
15751 or else
15752 Ekind (Ent) = E_In_Out_Parameter
15753 then
15754 null;
15756 -- For conditionals, we also allow loop parameters and all formals,
15757 -- including in parameters.
15759 elsif Cond and then Ekind_In (Ent, E_Loop_Parameter, E_In_Parameter) then
15760 null;
15762 -- For all other cases, not just unsafe, but impossible to capture
15763 -- Current_Value, since the above are the only entities which have
15764 -- Current_Value fields.
15766 else
15767 return False;
15768 end if;
15770 -- Skip if volatile or aliased, since funny things might be going on in
15771 -- these cases which we cannot necessarily track. Also skip any variable
15772 -- for which an address clause is given, or whose address is taken. Also
15773 -- never capture value of library level variables (an attempt to do so
15774 -- can occur in the case of package elaboration code).
15776 if Treat_As_Volatile (Ent)
15777 or else Is_Aliased (Ent)
15778 or else Present (Address_Clause (Ent))
15779 or else Address_Taken (Ent)
15780 or else (Is_Library_Level_Entity (Ent)
15781 and then Ekind (Ent) = E_Variable)
15782 then
15783 return False;
15784 end if;
15786 -- OK, all above conditions are met. We also require that the scope of
15787 -- the reference be the same as the scope of the entity, not counting
15788 -- packages and blocks and loops.
15790 declare
15791 E_Scope : constant Entity_Id := Scope (Ent);
15792 R_Scope : Entity_Id;
15794 begin
15795 R_Scope := Current_Scope;
15796 while R_Scope /= Standard_Standard loop
15797 exit when R_Scope = E_Scope;
15799 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
15800 return False;
15801 else
15802 R_Scope := Scope (R_Scope);
15803 end if;
15804 end loop;
15805 end;
15807 -- We also require that the reference does not appear in a context
15808 -- where it is not sure to be executed (i.e. a conditional context
15809 -- or an exception handler). We skip this if Cond is True, since the
15810 -- capturing of values from conditional tests handles this ok.
15812 if Cond then
15813 return True;
15814 end if;
15816 declare
15817 Desc : Node_Id;
15818 P : Node_Id;
15820 begin
15821 Desc := N;
15823 -- Seems dubious that case expressions are not handled here ???
15825 P := Parent (N);
15826 while Present (P) loop
15827 if Nkind (P) = N_If_Statement
15828 or else Nkind (P) = N_Case_Statement
15829 or else (Nkind (P) in N_Short_Circuit
15830 and then Desc = Right_Opnd (P))
15831 or else (Nkind (P) = N_If_Expression
15832 and then Desc /= First (Expressions (P)))
15833 or else Nkind (P) = N_Exception_Handler
15834 or else Nkind (P) = N_Selective_Accept
15835 or else Nkind (P) = N_Conditional_Entry_Call
15836 or else Nkind (P) = N_Timed_Entry_Call
15837 or else Nkind (P) = N_Asynchronous_Select
15838 then
15839 return False;
15841 else
15842 Desc := P;
15843 P := Parent (P);
15845 -- A special Ada 2012 case: the original node may be part
15846 -- of the else_actions of a conditional expression, in which
15847 -- case it might not have been expanded yet, and appears in
15848 -- a non-syntactic list of actions. In that case it is clearly
15849 -- not safe to save a value.
15851 if No (P)
15852 and then Is_List_Member (Desc)
15853 and then No (Parent (List_Containing (Desc)))
15854 then
15855 return False;
15856 end if;
15857 end if;
15858 end loop;
15859 end;
15861 -- OK, looks safe to set value
15863 return True;
15864 end Safe_To_Capture_Value;
15866 ---------------
15867 -- Same_Name --
15868 ---------------
15870 function Same_Name (N1, N2 : Node_Id) return Boolean is
15871 K1 : constant Node_Kind := Nkind (N1);
15872 K2 : constant Node_Kind := Nkind (N2);
15874 begin
15875 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
15876 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
15877 then
15878 return Chars (N1) = Chars (N2);
15880 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
15881 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
15882 then
15883 return Same_Name (Selector_Name (N1), Selector_Name (N2))
15884 and then Same_Name (Prefix (N1), Prefix (N2));
15886 else
15887 return False;
15888 end if;
15889 end Same_Name;
15891 -----------------
15892 -- Same_Object --
15893 -----------------
15895 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
15896 N1 : constant Node_Id := Original_Node (Node1);
15897 N2 : constant Node_Id := Original_Node (Node2);
15898 -- We do the tests on original nodes, since we are most interested
15899 -- in the original source, not any expansion that got in the way.
15901 K1 : constant Node_Kind := Nkind (N1);
15902 K2 : constant Node_Kind := Nkind (N2);
15904 begin
15905 -- First case, both are entities with same entity
15907 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
15908 declare
15909 EN1 : constant Entity_Id := Entity (N1);
15910 EN2 : constant Entity_Id := Entity (N2);
15911 begin
15912 if Present (EN1) and then Present (EN2)
15913 and then (Ekind_In (EN1, E_Variable, E_Constant)
15914 or else Is_Formal (EN1))
15915 and then EN1 = EN2
15916 then
15917 return True;
15918 end if;
15919 end;
15920 end if;
15922 -- Second case, selected component with same selector, same record
15924 if K1 = N_Selected_Component
15925 and then K2 = N_Selected_Component
15926 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
15927 then
15928 return Same_Object (Prefix (N1), Prefix (N2));
15930 -- Third case, indexed component with same subscripts, same array
15932 elsif K1 = N_Indexed_Component
15933 and then K2 = N_Indexed_Component
15934 and then Same_Object (Prefix (N1), Prefix (N2))
15935 then
15936 declare
15937 E1, E2 : Node_Id;
15938 begin
15939 E1 := First (Expressions (N1));
15940 E2 := First (Expressions (N2));
15941 while Present (E1) loop
15942 if not Same_Value (E1, E2) then
15943 return False;
15944 else
15945 Next (E1);
15946 Next (E2);
15947 end if;
15948 end loop;
15950 return True;
15951 end;
15953 -- Fourth case, slice of same array with same bounds
15955 elsif K1 = N_Slice
15956 and then K2 = N_Slice
15957 and then Nkind (Discrete_Range (N1)) = N_Range
15958 and then Nkind (Discrete_Range (N2)) = N_Range
15959 and then Same_Value (Low_Bound (Discrete_Range (N1)),
15960 Low_Bound (Discrete_Range (N2)))
15961 and then Same_Value (High_Bound (Discrete_Range (N1)),
15962 High_Bound (Discrete_Range (N2)))
15963 then
15964 return Same_Name (Prefix (N1), Prefix (N2));
15966 -- All other cases, not clearly the same object
15968 else
15969 return False;
15970 end if;
15971 end Same_Object;
15973 ---------------
15974 -- Same_Type --
15975 ---------------
15977 function Same_Type (T1, T2 : Entity_Id) return Boolean is
15978 begin
15979 if T1 = T2 then
15980 return True;
15982 elsif not Is_Constrained (T1)
15983 and then not Is_Constrained (T2)
15984 and then Base_Type (T1) = Base_Type (T2)
15985 then
15986 return True;
15988 -- For now don't bother with case of identical constraints, to be
15989 -- fiddled with later on perhaps (this is only used for optimization
15990 -- purposes, so it is not critical to do a best possible job)
15992 else
15993 return False;
15994 end if;
15995 end Same_Type;
15997 ----------------
15998 -- Same_Value --
15999 ----------------
16001 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
16002 begin
16003 if Compile_Time_Known_Value (Node1)
16004 and then Compile_Time_Known_Value (Node2)
16005 and then Expr_Value (Node1) = Expr_Value (Node2)
16006 then
16007 return True;
16008 elsif Same_Object (Node1, Node2) then
16009 return True;
16010 else
16011 return False;
16012 end if;
16013 end Same_Value;
16015 -----------------------------
16016 -- Save_SPARK_Mode_And_Set --
16017 -----------------------------
16019 procedure Save_SPARK_Mode_And_Set
16020 (Context : Entity_Id;
16021 Mode : out SPARK_Mode_Type)
16023 begin
16024 -- Save the current mode in effect
16026 Mode := SPARK_Mode;
16028 -- Do not consider illegal or partially decorated constructs
16030 if Ekind (Context) = E_Void or else Error_Posted (Context) then
16031 null;
16033 elsif Present (SPARK_Pragma (Context)) then
16034 SPARK_Mode := Get_SPARK_Mode_From_Pragma (SPARK_Pragma (Context));
16035 end if;
16036 end Save_SPARK_Mode_And_Set;
16038 -------------------------
16039 -- Scalar_Part_Present --
16040 -------------------------
16042 function Scalar_Part_Present (T : Entity_Id) return Boolean is
16043 C : Entity_Id;
16045 begin
16046 if Is_Scalar_Type (T) then
16047 return True;
16049 elsif Is_Array_Type (T) then
16050 return Scalar_Part_Present (Component_Type (T));
16052 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
16053 C := First_Component_Or_Discriminant (T);
16054 while Present (C) loop
16055 if Scalar_Part_Present (Etype (C)) then
16056 return True;
16057 else
16058 Next_Component_Or_Discriminant (C);
16059 end if;
16060 end loop;
16061 end if;
16063 return False;
16064 end Scalar_Part_Present;
16066 ------------------------
16067 -- Scope_Is_Transient --
16068 ------------------------
16070 function Scope_Is_Transient return Boolean is
16071 begin
16072 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
16073 end Scope_Is_Transient;
16075 ------------------
16076 -- Scope_Within --
16077 ------------------
16079 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
16080 Scop : Entity_Id;
16082 begin
16083 Scop := Scope1;
16084 while Scop /= Standard_Standard loop
16085 Scop := Scope (Scop);
16087 if Scop = Scope2 then
16088 return True;
16089 end if;
16090 end loop;
16092 return False;
16093 end Scope_Within;
16095 --------------------------
16096 -- Scope_Within_Or_Same --
16097 --------------------------
16099 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
16100 Scop : Entity_Id;
16102 begin
16103 Scop := Scope1;
16104 while Scop /= Standard_Standard loop
16105 if Scop = Scope2 then
16106 return True;
16107 else
16108 Scop := Scope (Scop);
16109 end if;
16110 end loop;
16112 return False;
16113 end Scope_Within_Or_Same;
16115 --------------------
16116 -- Set_Convention --
16117 --------------------
16119 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
16120 begin
16121 Basic_Set_Convention (E, Val);
16123 if Is_Type (E)
16124 and then Is_Access_Subprogram_Type (Base_Type (E))
16125 and then Has_Foreign_Convention (E)
16126 then
16127 Set_Can_Use_Internal_Rep (E, False);
16128 end if;
16130 -- If E is an object or component, and the type of E is an anonymous
16131 -- access type with no convention set, then also set the convention of
16132 -- the anonymous access type. We do not do this for anonymous protected
16133 -- types, since protected types always have the default convention.
16135 if Present (Etype (E))
16136 and then (Is_Object (E)
16137 or else Ekind (E) = E_Component
16139 -- Allow E_Void (happens for pragma Convention appearing
16140 -- in the middle of a record applying to a component)
16142 or else Ekind (E) = E_Void)
16143 then
16144 declare
16145 Typ : constant Entity_Id := Etype (E);
16147 begin
16148 if Ekind_In (Typ, E_Anonymous_Access_Type,
16149 E_Anonymous_Access_Subprogram_Type)
16150 and then not Has_Convention_Pragma (Typ)
16151 then
16152 Basic_Set_Convention (Typ, Val);
16153 Set_Has_Convention_Pragma (Typ);
16155 -- And for the access subprogram type, deal similarly with the
16156 -- designated E_Subprogram_Type if it is also internal (which
16157 -- it always is?)
16159 if Ekind (Typ) = E_Anonymous_Access_Subprogram_Type then
16160 declare
16161 Dtype : constant Entity_Id := Designated_Type (Typ);
16162 begin
16163 if Ekind (Dtype) = E_Subprogram_Type
16164 and then Is_Itype (Dtype)
16165 and then not Has_Convention_Pragma (Dtype)
16166 then
16167 Basic_Set_Convention (Dtype, Val);
16168 Set_Has_Convention_Pragma (Dtype);
16169 end if;
16170 end;
16171 end if;
16172 end if;
16173 end;
16174 end if;
16175 end Set_Convention;
16177 ------------------------
16178 -- Set_Current_Entity --
16179 ------------------------
16181 -- The given entity is to be set as the currently visible definition of its
16182 -- associated name (i.e. the Node_Id associated with its name). All we have
16183 -- to do is to get the name from the identifier, and then set the
16184 -- associated Node_Id to point to the given entity.
16186 procedure Set_Current_Entity (E : Entity_Id) is
16187 begin
16188 Set_Name_Entity_Id (Chars (E), E);
16189 end Set_Current_Entity;
16191 ---------------------------
16192 -- Set_Debug_Info_Needed --
16193 ---------------------------
16195 procedure Set_Debug_Info_Needed (T : Entity_Id) is
16197 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
16198 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
16199 -- Used to set debug info in a related node if not set already
16201 --------------------------------------
16202 -- Set_Debug_Info_Needed_If_Not_Set --
16203 --------------------------------------
16205 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
16206 begin
16207 if Present (E) and then not Needs_Debug_Info (E) then
16208 Set_Debug_Info_Needed (E);
16210 -- For a private type, indicate that the full view also needs
16211 -- debug information.
16213 if Is_Type (E)
16214 and then Is_Private_Type (E)
16215 and then Present (Full_View (E))
16216 then
16217 Set_Debug_Info_Needed (Full_View (E));
16218 end if;
16219 end if;
16220 end Set_Debug_Info_Needed_If_Not_Set;
16222 -- Start of processing for Set_Debug_Info_Needed
16224 begin
16225 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16226 -- indicates that Debug_Info_Needed is never required for the entity.
16228 if No (T)
16229 or else Debug_Info_Off (T)
16230 then
16231 return;
16232 end if;
16234 -- Set flag in entity itself. Note that we will go through the following
16235 -- circuitry even if the flag is already set on T. That's intentional,
16236 -- it makes sure that the flag will be set in subsidiary entities.
16238 Set_Needs_Debug_Info (T);
16240 -- Set flag on subsidiary entities if not set already
16242 if Is_Object (T) then
16243 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16245 elsif Is_Type (T) then
16246 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
16248 if Is_Record_Type (T) then
16249 declare
16250 Ent : Entity_Id := First_Entity (T);
16251 begin
16252 while Present (Ent) loop
16253 Set_Debug_Info_Needed_If_Not_Set (Ent);
16254 Next_Entity (Ent);
16255 end loop;
16256 end;
16258 -- For a class wide subtype, we also need debug information
16259 -- for the equivalent type.
16261 if Ekind (T) = E_Class_Wide_Subtype then
16262 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
16263 end if;
16265 elsif Is_Array_Type (T) then
16266 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
16268 declare
16269 Indx : Node_Id := First_Index (T);
16270 begin
16271 while Present (Indx) loop
16272 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
16273 Indx := Next_Index (Indx);
16274 end loop;
16275 end;
16277 -- For a packed array type, we also need debug information for
16278 -- the type used to represent the packed array. Conversely, we
16279 -- also need it for the former if we need it for the latter.
16281 if Is_Packed (T) then
16282 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Impl_Type (T));
16283 end if;
16285 if Is_Packed_Array_Impl_Type (T) then
16286 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
16287 end if;
16289 elsif Is_Access_Type (T) then
16290 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
16292 elsif Is_Private_Type (T) then
16293 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
16295 elsif Is_Protected_Type (T) then
16296 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
16298 elsif Is_Scalar_Type (T) then
16300 -- If the subrange bounds are materialized by dedicated constant
16301 -- objects, also include them in the debug info to make sure the
16302 -- debugger can properly use them.
16304 if Present (Scalar_Range (T))
16305 and then Nkind (Scalar_Range (T)) = N_Range
16306 then
16307 declare
16308 Low_Bnd : constant Node_Id := Type_Low_Bound (T);
16309 High_Bnd : constant Node_Id := Type_High_Bound (T);
16311 begin
16312 if Is_Entity_Name (Low_Bnd) then
16313 Set_Debug_Info_Needed_If_Not_Set (Entity (Low_Bnd));
16314 end if;
16316 if Is_Entity_Name (High_Bnd) then
16317 Set_Debug_Info_Needed_If_Not_Set (Entity (High_Bnd));
16318 end if;
16319 end;
16320 end if;
16321 end if;
16322 end if;
16323 end Set_Debug_Info_Needed;
16325 ----------------------------
16326 -- Set_Entity_With_Checks --
16327 ----------------------------
16329 procedure Set_Entity_With_Checks (N : Node_Id; Val : Entity_Id) is
16330 Val_Actual : Entity_Id;
16331 Nod : Node_Id;
16332 Post_Node : Node_Id;
16334 begin
16335 -- Unconditionally set the entity
16337 Set_Entity (N, Val);
16339 -- The node to post on is the selector in the case of an expanded name,
16340 -- and otherwise the node itself.
16342 if Nkind (N) = N_Expanded_Name then
16343 Post_Node := Selector_Name (N);
16344 else
16345 Post_Node := N;
16346 end if;
16348 -- Check for violation of No_Fixed_IO
16350 if Restriction_Check_Required (No_Fixed_IO)
16351 and then
16352 ((RTU_Loaded (Ada_Text_IO)
16353 and then (Is_RTE (Val, RE_Decimal_IO)
16354 or else
16355 Is_RTE (Val, RE_Fixed_IO)))
16357 or else
16358 (RTU_Loaded (Ada_Wide_Text_IO)
16359 and then (Is_RTE (Val, RO_WT_Decimal_IO)
16360 or else
16361 Is_RTE (Val, RO_WT_Fixed_IO)))
16363 or else
16364 (RTU_Loaded (Ada_Wide_Wide_Text_IO)
16365 and then (Is_RTE (Val, RO_WW_Decimal_IO)
16366 or else
16367 Is_RTE (Val, RO_WW_Fixed_IO))))
16369 -- A special extra check, don't complain about a reference from within
16370 -- the Ada.Interrupts package itself!
16372 and then not In_Same_Extended_Unit (N, Val)
16373 then
16374 Check_Restriction (No_Fixed_IO, Post_Node);
16375 end if;
16377 -- Remaining checks are only done on source nodes. Note that we test
16378 -- for violation of No_Fixed_IO even on non-source nodes, because the
16379 -- cases for checking violations of this restriction are instantiations
16380 -- where the reference in the instance has Comes_From_Source False.
16382 if not Comes_From_Source (N) then
16383 return;
16384 end if;
16386 -- Check for violation of No_Abort_Statements, which is triggered by
16387 -- call to Ada.Task_Identification.Abort_Task.
16389 if Restriction_Check_Required (No_Abort_Statements)
16390 and then (Is_RTE (Val, RE_Abort_Task))
16392 -- A special extra check, don't complain about a reference from within
16393 -- the Ada.Task_Identification package itself!
16395 and then not In_Same_Extended_Unit (N, Val)
16396 then
16397 Check_Restriction (No_Abort_Statements, Post_Node);
16398 end if;
16400 if Val = Standard_Long_Long_Integer then
16401 Check_Restriction (No_Long_Long_Integers, Post_Node);
16402 end if;
16404 -- Check for violation of No_Dynamic_Attachment
16406 if Restriction_Check_Required (No_Dynamic_Attachment)
16407 and then RTU_Loaded (Ada_Interrupts)
16408 and then (Is_RTE (Val, RE_Is_Reserved) or else
16409 Is_RTE (Val, RE_Is_Attached) or else
16410 Is_RTE (Val, RE_Current_Handler) or else
16411 Is_RTE (Val, RE_Attach_Handler) or else
16412 Is_RTE (Val, RE_Exchange_Handler) or else
16413 Is_RTE (Val, RE_Detach_Handler) or else
16414 Is_RTE (Val, RE_Reference))
16416 -- A special extra check, don't complain about a reference from within
16417 -- the Ada.Interrupts package itself!
16419 and then not In_Same_Extended_Unit (N, Val)
16420 then
16421 Check_Restriction (No_Dynamic_Attachment, Post_Node);
16422 end if;
16424 -- Check for No_Implementation_Identifiers
16426 if Restriction_Check_Required (No_Implementation_Identifiers) then
16428 -- We have an implementation defined entity if it is marked as
16429 -- implementation defined, or is defined in a package marked as
16430 -- implementation defined. However, library packages themselves
16431 -- are excluded (we don't want to flag Interfaces itself, just
16432 -- the entities within it).
16434 if (Is_Implementation_Defined (Val)
16435 or else
16436 Is_Implementation_Defined (Scope (Val)))
16437 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
16438 and then Is_Library_Level_Entity (Val))
16439 then
16440 Check_Restriction (No_Implementation_Identifiers, Post_Node);
16441 end if;
16442 end if;
16444 -- Do the style check
16446 if Style_Check
16447 and then not Suppress_Style_Checks (Val)
16448 and then not In_Instance
16449 then
16450 if Nkind (N) = N_Identifier then
16451 Nod := N;
16452 elsif Nkind (N) = N_Expanded_Name then
16453 Nod := Selector_Name (N);
16454 else
16455 return;
16456 end if;
16458 -- A special situation arises for derived operations, where we want
16459 -- to do the check against the parent (since the Sloc of the derived
16460 -- operation points to the derived type declaration itself).
16462 Val_Actual := Val;
16463 while not Comes_From_Source (Val_Actual)
16464 and then Nkind (Val_Actual) in N_Entity
16465 and then (Ekind (Val_Actual) = E_Enumeration_Literal
16466 or else Is_Subprogram (Val_Actual)
16467 or else Is_Generic_Subprogram (Val_Actual))
16468 and then Present (Alias (Val_Actual))
16469 loop
16470 Val_Actual := Alias (Val_Actual);
16471 end loop;
16473 -- Renaming declarations for generic actuals do not come from source,
16474 -- and have a different name from that of the entity they rename, so
16475 -- there is no style check to perform here.
16477 if Chars (Nod) = Chars (Val_Actual) then
16478 Style.Check_Identifier (Nod, Val_Actual);
16479 end if;
16480 end if;
16482 Set_Entity (N, Val);
16483 end Set_Entity_With_Checks;
16485 ------------------------
16486 -- Set_Name_Entity_Id --
16487 ------------------------
16489 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
16490 begin
16491 Set_Name_Table_Info (Id, Int (Val));
16492 end Set_Name_Entity_Id;
16494 ---------------------
16495 -- Set_Next_Actual --
16496 ---------------------
16498 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
16499 begin
16500 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
16501 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
16502 end if;
16503 end Set_Next_Actual;
16505 ----------------------------------
16506 -- Set_Optimize_Alignment_Flags --
16507 ----------------------------------
16509 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
16510 begin
16511 if Optimize_Alignment = 'S' then
16512 Set_Optimize_Alignment_Space (E);
16513 elsif Optimize_Alignment = 'T' then
16514 Set_Optimize_Alignment_Time (E);
16515 end if;
16516 end Set_Optimize_Alignment_Flags;
16518 -----------------------
16519 -- Set_Public_Status --
16520 -----------------------
16522 procedure Set_Public_Status (Id : Entity_Id) is
16523 S : constant Entity_Id := Current_Scope;
16525 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
16526 -- Determines if E is defined within handled statement sequence or
16527 -- an if statement, returns True if so, False otherwise.
16529 ----------------------
16530 -- Within_HSS_Or_If --
16531 ----------------------
16533 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
16534 N : Node_Id;
16535 begin
16536 N := Declaration_Node (E);
16537 loop
16538 N := Parent (N);
16540 if No (N) then
16541 return False;
16543 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
16544 N_If_Statement)
16545 then
16546 return True;
16547 end if;
16548 end loop;
16549 end Within_HSS_Or_If;
16551 -- Start of processing for Set_Public_Status
16553 begin
16554 -- Everything in the scope of Standard is public
16556 if S = Standard_Standard then
16557 Set_Is_Public (Id);
16559 -- Entity is definitely not public if enclosing scope is not public
16561 elsif not Is_Public (S) then
16562 return;
16564 -- An object or function declaration that occurs in a handled sequence
16565 -- of statements or within an if statement is the declaration for a
16566 -- temporary object or local subprogram generated by the expander. It
16567 -- never needs to be made public and furthermore, making it public can
16568 -- cause back end problems.
16570 elsif Nkind_In (Parent (Id), N_Object_Declaration,
16571 N_Function_Specification)
16572 and then Within_HSS_Or_If (Id)
16573 then
16574 return;
16576 -- Entities in public packages or records are public
16578 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
16579 Set_Is_Public (Id);
16581 -- The bounds of an entry family declaration can generate object
16582 -- declarations that are visible to the back-end, e.g. in the
16583 -- the declaration of a composite type that contains tasks.
16585 elsif Is_Concurrent_Type (S)
16586 and then not Has_Completion (S)
16587 and then Nkind (Parent (Id)) = N_Object_Declaration
16588 then
16589 Set_Is_Public (Id);
16590 end if;
16591 end Set_Public_Status;
16593 -----------------------------
16594 -- Set_Referenced_Modified --
16595 -----------------------------
16597 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
16598 Pref : Node_Id;
16600 begin
16601 -- Deal with indexed or selected component where prefix is modified
16603 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
16604 Pref := Prefix (N);
16606 -- If prefix is access type, then it is the designated object that is
16607 -- being modified, which means we have no entity to set the flag on.
16609 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
16610 return;
16612 -- Otherwise chase the prefix
16614 else
16615 Set_Referenced_Modified (Pref, Out_Param);
16616 end if;
16618 -- Otherwise see if we have an entity name (only other case to process)
16620 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
16621 Set_Referenced_As_LHS (Entity (N), not Out_Param);
16622 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
16623 end if;
16624 end Set_Referenced_Modified;
16626 ----------------------------
16627 -- Set_Scope_Is_Transient --
16628 ----------------------------
16630 procedure Set_Scope_Is_Transient (V : Boolean := True) is
16631 begin
16632 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
16633 end Set_Scope_Is_Transient;
16635 -------------------
16636 -- Set_Size_Info --
16637 -------------------
16639 procedure Set_Size_Info (T1, T2 : Entity_Id) is
16640 begin
16641 -- We copy Esize, but not RM_Size, since in general RM_Size is
16642 -- subtype specific and does not get inherited by all subtypes.
16644 Set_Esize (T1, Esize (T2));
16645 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
16647 if Is_Discrete_Or_Fixed_Point_Type (T1)
16648 and then
16649 Is_Discrete_Or_Fixed_Point_Type (T2)
16650 then
16651 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
16652 end if;
16654 Set_Alignment (T1, Alignment (T2));
16655 end Set_Size_Info;
16657 --------------------
16658 -- Static_Boolean --
16659 --------------------
16661 function Static_Boolean (N : Node_Id) return Uint is
16662 begin
16663 Analyze_And_Resolve (N, Standard_Boolean);
16665 if N = Error
16666 or else Error_Posted (N)
16667 or else Etype (N) = Any_Type
16668 then
16669 return No_Uint;
16670 end if;
16672 if Is_OK_Static_Expression (N) then
16673 if not Raises_Constraint_Error (N) then
16674 return Expr_Value (N);
16675 else
16676 return No_Uint;
16677 end if;
16679 elsif Etype (N) = Any_Type then
16680 return No_Uint;
16682 else
16683 Flag_Non_Static_Expr
16684 ("static boolean expression required here", N);
16685 return No_Uint;
16686 end if;
16687 end Static_Boolean;
16689 --------------------
16690 -- Static_Integer --
16691 --------------------
16693 function Static_Integer (N : Node_Id) return Uint is
16694 begin
16695 Analyze_And_Resolve (N, Any_Integer);
16697 if N = Error
16698 or else Error_Posted (N)
16699 or else Etype (N) = Any_Type
16700 then
16701 return No_Uint;
16702 end if;
16704 if Is_OK_Static_Expression (N) then
16705 if not Raises_Constraint_Error (N) then
16706 return Expr_Value (N);
16707 else
16708 return No_Uint;
16709 end if;
16711 elsif Etype (N) = Any_Type then
16712 return No_Uint;
16714 else
16715 Flag_Non_Static_Expr
16716 ("static integer expression required here", N);
16717 return No_Uint;
16718 end if;
16719 end Static_Integer;
16721 --------------------------
16722 -- Statically_Different --
16723 --------------------------
16725 function Statically_Different (E1, E2 : Node_Id) return Boolean is
16726 R1 : constant Node_Id := Get_Referenced_Object (E1);
16727 R2 : constant Node_Id := Get_Referenced_Object (E2);
16728 begin
16729 return Is_Entity_Name (R1)
16730 and then Is_Entity_Name (R2)
16731 and then Entity (R1) /= Entity (R2)
16732 and then not Is_Formal (Entity (R1))
16733 and then not Is_Formal (Entity (R2));
16734 end Statically_Different;
16736 --------------------------------------
16737 -- Subject_To_Loop_Entry_Attributes --
16738 --------------------------------------
16740 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
16741 Stmt : Node_Id;
16743 begin
16744 Stmt := N;
16746 -- The expansion mechanism transform a loop subject to at least one
16747 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
16748 -- the conditional part.
16750 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
16751 and then Nkind (Original_Node (N)) = N_Loop_Statement
16752 then
16753 Stmt := Original_Node (N);
16754 end if;
16756 return
16757 Nkind (Stmt) = N_Loop_Statement
16758 and then Present (Identifier (Stmt))
16759 and then Present (Entity (Identifier (Stmt)))
16760 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
16761 end Subject_To_Loop_Entry_Attributes;
16763 -----------------------------
16764 -- Subprogram_Access_Level --
16765 -----------------------------
16767 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
16768 begin
16769 if Present (Alias (Subp)) then
16770 return Subprogram_Access_Level (Alias (Subp));
16771 else
16772 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
16773 end if;
16774 end Subprogram_Access_Level;
16776 -------------------------------
16777 -- Support_Atomic_Primitives --
16778 -------------------------------
16780 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
16781 Size : Int;
16783 begin
16784 -- Verify the alignment of Typ is known
16786 if not Known_Alignment (Typ) then
16787 return False;
16788 end if;
16790 if Known_Static_Esize (Typ) then
16791 Size := UI_To_Int (Esize (Typ));
16793 -- If the Esize (Object_Size) is unknown at compile time, look at the
16794 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
16796 elsif Known_Static_RM_Size (Typ) then
16797 Size := UI_To_Int (RM_Size (Typ));
16799 -- Otherwise, the size is considered to be unknown.
16801 else
16802 return False;
16803 end if;
16805 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
16806 -- Typ is properly aligned.
16808 case Size is
16809 when 8 | 16 | 32 | 64 =>
16810 return Size = UI_To_Int (Alignment (Typ)) * 8;
16811 when others =>
16812 return False;
16813 end case;
16814 end Support_Atomic_Primitives;
16816 -----------------
16817 -- Trace_Scope --
16818 -----------------
16820 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
16821 begin
16822 if Debug_Flag_W then
16823 for J in 0 .. Scope_Stack.Last loop
16824 Write_Str (" ");
16825 end loop;
16827 Write_Str (Msg);
16828 Write_Name (Chars (E));
16829 Write_Str (" from ");
16830 Write_Location (Sloc (N));
16831 Write_Eol;
16832 end if;
16833 end Trace_Scope;
16835 -----------------------
16836 -- Transfer_Entities --
16837 -----------------------
16839 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
16840 Ent : Entity_Id := First_Entity (From);
16842 begin
16843 if No (Ent) then
16844 return;
16845 end if;
16847 if (Last_Entity (To)) = Empty then
16848 Set_First_Entity (To, Ent);
16849 else
16850 Set_Next_Entity (Last_Entity (To), Ent);
16851 end if;
16853 Set_Last_Entity (To, Last_Entity (From));
16855 while Present (Ent) loop
16856 Set_Scope (Ent, To);
16858 if not Is_Public (Ent) then
16859 Set_Public_Status (Ent);
16861 if Is_Public (Ent) and then Ekind (Ent) = E_Record_Subtype then
16863 -- The components of the propagated Itype must also be public
16865 declare
16866 Comp : Entity_Id;
16867 begin
16868 Comp := First_Entity (Ent);
16869 while Present (Comp) loop
16870 Set_Is_Public (Comp);
16871 Next_Entity (Comp);
16872 end loop;
16873 end;
16874 end if;
16875 end if;
16877 Next_Entity (Ent);
16878 end loop;
16880 Set_First_Entity (From, Empty);
16881 Set_Last_Entity (From, Empty);
16882 end Transfer_Entities;
16884 -----------------------
16885 -- Type_Access_Level --
16886 -----------------------
16888 function Type_Access_Level (Typ : Entity_Id) return Uint is
16889 Btyp : Entity_Id;
16891 begin
16892 Btyp := Base_Type (Typ);
16894 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
16895 -- simply use the level where the type is declared. This is true for
16896 -- stand-alone object declarations, and for anonymous access types
16897 -- associated with components the level is the same as that of the
16898 -- enclosing composite type. However, special treatment is needed for
16899 -- the cases of access parameters, return objects of an anonymous access
16900 -- type, and, in Ada 95, access discriminants of limited types.
16902 if Is_Access_Type (Btyp) then
16903 if Ekind (Btyp) = E_Anonymous_Access_Type then
16905 -- If the type is a nonlocal anonymous access type (such as for
16906 -- an access parameter) we treat it as being declared at the
16907 -- library level to ensure that names such as X.all'access don't
16908 -- fail static accessibility checks.
16910 if not Is_Local_Anonymous_Access (Typ) then
16911 return Scope_Depth (Standard_Standard);
16913 -- If this is a return object, the accessibility level is that of
16914 -- the result subtype of the enclosing function. The test here is
16915 -- little complicated, because we have to account for extended
16916 -- return statements that have been rewritten as blocks, in which
16917 -- case we have to find and the Is_Return_Object attribute of the
16918 -- itype's associated object. It would be nice to find a way to
16919 -- simplify this test, but it doesn't seem worthwhile to add a new
16920 -- flag just for purposes of this test. ???
16922 elsif Ekind (Scope (Btyp)) = E_Return_Statement
16923 or else
16924 (Is_Itype (Btyp)
16925 and then Nkind (Associated_Node_For_Itype (Btyp)) =
16926 N_Object_Declaration
16927 and then Is_Return_Object
16928 (Defining_Identifier
16929 (Associated_Node_For_Itype (Btyp))))
16930 then
16931 declare
16932 Scop : Entity_Id;
16934 begin
16935 Scop := Scope (Scope (Btyp));
16936 while Present (Scop) loop
16937 exit when Ekind (Scop) = E_Function;
16938 Scop := Scope (Scop);
16939 end loop;
16941 -- Treat the return object's type as having the level of the
16942 -- function's result subtype (as per RM05-6.5(5.3/2)).
16944 return Type_Access_Level (Etype (Scop));
16945 end;
16946 end if;
16947 end if;
16949 Btyp := Root_Type (Btyp);
16951 -- The accessibility level of anonymous access types associated with
16952 -- discriminants is that of the current instance of the type, and
16953 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
16955 -- AI-402: access discriminants have accessibility based on the
16956 -- object rather than the type in Ada 2005, so the above paragraph
16957 -- doesn't apply.
16959 -- ??? Needs completion with rules from AI-416
16961 if Ada_Version <= Ada_95
16962 and then Ekind (Typ) = E_Anonymous_Access_Type
16963 and then Present (Associated_Node_For_Itype (Typ))
16964 and then Nkind (Associated_Node_For_Itype (Typ)) =
16965 N_Discriminant_Specification
16966 then
16967 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
16968 end if;
16969 end if;
16971 -- Return library level for a generic formal type. This is done because
16972 -- RM(10.3.2) says that "The statically deeper relationship does not
16973 -- apply to ... a descendant of a generic formal type". Rather than
16974 -- checking at each point where a static accessibility check is
16975 -- performed to see if we are dealing with a formal type, this rule is
16976 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
16977 -- return extreme values for a formal type; Deepest_Type_Access_Level
16978 -- returns Int'Last. By calling the appropriate function from among the
16979 -- two, we ensure that the static accessibility check will pass if we
16980 -- happen to run into a formal type. More specifically, we should call
16981 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
16982 -- call occurs as part of a static accessibility check and the error
16983 -- case is the case where the type's level is too shallow (as opposed
16984 -- to too deep).
16986 if Is_Generic_Type (Root_Type (Btyp)) then
16987 return Scope_Depth (Standard_Standard);
16988 end if;
16990 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
16991 end Type_Access_Level;
16993 ------------------------------------
16994 -- Type_Without_Stream_Operation --
16995 ------------------------------------
16997 function Type_Without_Stream_Operation
16998 (T : Entity_Id;
16999 Op : TSS_Name_Type := TSS_Null) return Entity_Id
17001 BT : constant Entity_Id := Base_Type (T);
17002 Op_Missing : Boolean;
17004 begin
17005 if not Restriction_Active (No_Default_Stream_Attributes) then
17006 return Empty;
17007 end if;
17009 if Is_Elementary_Type (T) then
17010 if Op = TSS_Null then
17011 Op_Missing :=
17012 No (TSS (BT, TSS_Stream_Read))
17013 or else No (TSS (BT, TSS_Stream_Write));
17015 else
17016 Op_Missing := No (TSS (BT, Op));
17017 end if;
17019 if Op_Missing then
17020 return T;
17021 else
17022 return Empty;
17023 end if;
17025 elsif Is_Array_Type (T) then
17026 return Type_Without_Stream_Operation (Component_Type (T), Op);
17028 elsif Is_Record_Type (T) then
17029 declare
17030 Comp : Entity_Id;
17031 C_Typ : Entity_Id;
17033 begin
17034 Comp := First_Component (T);
17035 while Present (Comp) loop
17036 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
17038 if Present (C_Typ) then
17039 return C_Typ;
17040 end if;
17042 Next_Component (Comp);
17043 end loop;
17045 return Empty;
17046 end;
17048 elsif Is_Private_Type (T) and then Present (Full_View (T)) then
17049 return Type_Without_Stream_Operation (Full_View (T), Op);
17050 else
17051 return Empty;
17052 end if;
17053 end Type_Without_Stream_Operation;
17055 ----------------------------
17056 -- Unique_Defining_Entity --
17057 ----------------------------
17059 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
17060 begin
17061 return Unique_Entity (Defining_Entity (N));
17062 end Unique_Defining_Entity;
17064 -------------------
17065 -- Unique_Entity --
17066 -------------------
17068 function Unique_Entity (E : Entity_Id) return Entity_Id is
17069 U : Entity_Id := E;
17070 P : Node_Id;
17072 begin
17073 case Ekind (E) is
17074 when E_Constant =>
17075 if Present (Full_View (E)) then
17076 U := Full_View (E);
17077 end if;
17079 when Type_Kind =>
17080 if Present (Full_View (E)) then
17081 U := Full_View (E);
17082 end if;
17084 when E_Package_Body =>
17085 P := Parent (E);
17087 if Nkind (P) = N_Defining_Program_Unit_Name then
17088 P := Parent (P);
17089 end if;
17091 U := Corresponding_Spec (P);
17093 when E_Subprogram_Body =>
17094 P := Parent (E);
17096 if Nkind (P) = N_Defining_Program_Unit_Name then
17097 P := Parent (P);
17098 end if;
17100 P := Parent (P);
17102 if Nkind (P) = N_Subprogram_Body_Stub then
17103 if Present (Library_Unit (P)) then
17105 -- Get to the function or procedure (generic) entity through
17106 -- the body entity.
17108 U :=
17109 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
17110 end if;
17111 else
17112 U := Corresponding_Spec (P);
17113 end if;
17115 when Formal_Kind =>
17116 if Present (Spec_Entity (E)) then
17117 U := Spec_Entity (E);
17118 end if;
17120 when others =>
17121 null;
17122 end case;
17124 return U;
17125 end Unique_Entity;
17127 -----------------
17128 -- Unique_Name --
17129 -----------------
17131 function Unique_Name (E : Entity_Id) return String is
17133 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17134 -- reliable, as they may not include the overloading suffix. Instead,
17135 -- when looking for the name of E or one of its enclosing scope, we get
17136 -- the name of the corresponding Unique_Entity.
17138 function Get_Scoped_Name (E : Entity_Id) return String;
17139 -- Return the name of E prefixed by all the names of the scopes to which
17140 -- E belongs, except for Standard.
17142 ---------------------
17143 -- Get_Scoped_Name --
17144 ---------------------
17146 function Get_Scoped_Name (E : Entity_Id) return String is
17147 Name : constant String := Get_Name_String (Chars (E));
17148 begin
17149 if Has_Fully_Qualified_Name (E)
17150 or else Scope (E) = Standard_Standard
17151 then
17152 return Name;
17153 else
17154 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
17155 end if;
17156 end Get_Scoped_Name;
17158 -- Start of processing for Unique_Name
17160 begin
17161 if E = Standard_Standard then
17162 return Get_Name_String (Name_Standard);
17164 elsif Scope (E) = Standard_Standard
17165 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
17166 then
17167 return Get_Name_String (Name_Standard) & "__" &
17168 Get_Name_String (Chars (E));
17170 elsif Ekind (E) = E_Enumeration_Literal then
17171 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
17173 else
17174 return Get_Scoped_Name (Unique_Entity (E));
17175 end if;
17176 end Unique_Name;
17178 ---------------------
17179 -- Unit_Is_Visible --
17180 ---------------------
17182 function Unit_Is_Visible (U : Entity_Id) return Boolean is
17183 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
17184 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
17186 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
17187 -- For a child unit, check whether unit appears in a with_clause
17188 -- of a parent.
17190 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
17191 -- Scan the context clause of one compilation unit looking for a
17192 -- with_clause for the unit in question.
17194 ----------------------------
17195 -- Unit_In_Parent_Context --
17196 ----------------------------
17198 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
17199 begin
17200 if Unit_In_Context (Par_Unit) then
17201 return True;
17203 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
17204 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
17206 else
17207 return False;
17208 end if;
17209 end Unit_In_Parent_Context;
17211 ---------------------
17212 -- Unit_In_Context --
17213 ---------------------
17215 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
17216 Clause : Node_Id;
17218 begin
17219 Clause := First (Context_Items (Comp_Unit));
17220 while Present (Clause) loop
17221 if Nkind (Clause) = N_With_Clause then
17222 if Library_Unit (Clause) = U then
17223 return True;
17225 -- The with_clause may denote a renaming of the unit we are
17226 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17228 elsif
17229 Renamed_Entity (Entity (Name (Clause))) =
17230 Defining_Entity (Unit (U))
17231 then
17232 return True;
17233 end if;
17234 end if;
17236 Next (Clause);
17237 end loop;
17239 return False;
17240 end Unit_In_Context;
17242 -- Start of processing for Unit_Is_Visible
17244 begin
17245 -- The currrent unit is directly visible
17247 if Curr = U then
17248 return True;
17250 elsif Unit_In_Context (Curr) then
17251 return True;
17253 -- If the current unit is a body, check the context of the spec
17255 elsif Nkind (Unit (Curr)) = N_Package_Body
17256 or else
17257 (Nkind (Unit (Curr)) = N_Subprogram_Body
17258 and then not Acts_As_Spec (Unit (Curr)))
17259 then
17260 if Unit_In_Context (Library_Unit (Curr)) then
17261 return True;
17262 end if;
17263 end if;
17265 -- If the spec is a child unit, examine the parents
17267 if Is_Child_Unit (Curr_Entity) then
17268 if Nkind (Unit (Curr)) in N_Unit_Body then
17269 return
17270 Unit_In_Parent_Context
17271 (Parent_Spec (Unit (Library_Unit (Curr))));
17272 else
17273 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
17274 end if;
17276 else
17277 return False;
17278 end if;
17279 end Unit_Is_Visible;
17281 ------------------------------
17282 -- Universal_Interpretation --
17283 ------------------------------
17285 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
17286 Index : Interp_Index;
17287 It : Interp;
17289 begin
17290 -- The argument may be a formal parameter of an operator or subprogram
17291 -- with multiple interpretations, or else an expression for an actual.
17293 if Nkind (Opnd) = N_Defining_Identifier
17294 or else not Is_Overloaded (Opnd)
17295 then
17296 if Etype (Opnd) = Universal_Integer
17297 or else Etype (Opnd) = Universal_Real
17298 then
17299 return Etype (Opnd);
17300 else
17301 return Empty;
17302 end if;
17304 else
17305 Get_First_Interp (Opnd, Index, It);
17306 while Present (It.Typ) loop
17307 if It.Typ = Universal_Integer
17308 or else It.Typ = Universal_Real
17309 then
17310 return It.Typ;
17311 end if;
17313 Get_Next_Interp (Index, It);
17314 end loop;
17316 return Empty;
17317 end if;
17318 end Universal_Interpretation;
17320 ---------------
17321 -- Unqualify --
17322 ---------------
17324 function Unqualify (Expr : Node_Id) return Node_Id is
17325 begin
17326 -- Recurse to handle unlikely case of multiple levels of qualification
17328 if Nkind (Expr) = N_Qualified_Expression then
17329 return Unqualify (Expression (Expr));
17331 -- Normal case, not a qualified expression
17333 else
17334 return Expr;
17335 end if;
17336 end Unqualify;
17338 -----------------------
17339 -- Visible_Ancestors --
17340 -----------------------
17342 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
17343 List_1 : Elist_Id;
17344 List_2 : Elist_Id;
17345 Elmt : Elmt_Id;
17347 begin
17348 pragma Assert (Is_Record_Type (Typ) and then Is_Tagged_Type (Typ));
17350 -- Collect all the parents and progenitors of Typ. If the full-view of
17351 -- private parents and progenitors is available then it is used to
17352 -- generate the list of visible ancestors; otherwise their partial
17353 -- view is added to the resulting list.
17355 Collect_Parents
17356 (T => Typ,
17357 List => List_1,
17358 Use_Full_View => True);
17360 Collect_Interfaces
17361 (T => Typ,
17362 Ifaces_List => List_2,
17363 Exclude_Parents => True,
17364 Use_Full_View => True);
17366 -- Join the two lists. Avoid duplications because an interface may
17367 -- simultaneously be parent and progenitor of a type.
17369 Elmt := First_Elmt (List_2);
17370 while Present (Elmt) loop
17371 Append_Unique_Elmt (Node (Elmt), List_1);
17372 Next_Elmt (Elmt);
17373 end loop;
17375 return List_1;
17376 end Visible_Ancestors;
17378 ----------------------
17379 -- Within_Init_Proc --
17380 ----------------------
17382 function Within_Init_Proc return Boolean is
17383 S : Entity_Id;
17385 begin
17386 S := Current_Scope;
17387 while not Is_Overloadable (S) loop
17388 if S = Standard_Standard then
17389 return False;
17390 else
17391 S := Scope (S);
17392 end if;
17393 end loop;
17395 return Is_Init_Proc (S);
17396 end Within_Init_Proc;
17398 ------------------
17399 -- Within_Scope --
17400 ------------------
17402 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
17403 SE : Entity_Id;
17404 begin
17405 SE := Scope (E);
17406 loop
17407 if SE = S then
17408 return True;
17409 elsif SE = Standard_Standard then
17410 return False;
17411 else
17412 SE := Scope (SE);
17413 end if;
17414 end loop;
17415 end Within_Scope;
17417 ----------------
17418 -- Wrong_Type --
17419 ----------------
17421 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
17422 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
17423 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
17425 Matching_Field : Entity_Id;
17426 -- Entity to give a more precise suggestion on how to write a one-
17427 -- element positional aggregate.
17429 function Has_One_Matching_Field return Boolean;
17430 -- Determines if Expec_Type is a record type with a single component or
17431 -- discriminant whose type matches the found type or is one dimensional
17432 -- array whose component type matches the found type. In the case of
17433 -- one discriminant, we ignore the variant parts. That's not accurate,
17434 -- but good enough for the warning.
17436 ----------------------------
17437 -- Has_One_Matching_Field --
17438 ----------------------------
17440 function Has_One_Matching_Field return Boolean is
17441 E : Entity_Id;
17443 begin
17444 Matching_Field := Empty;
17446 if Is_Array_Type (Expec_Type)
17447 and then Number_Dimensions (Expec_Type) = 1
17448 and then Covers (Etype (Component_Type (Expec_Type)), Found_Type)
17449 then
17450 -- Use type name if available. This excludes multidimensional
17451 -- arrays and anonymous arrays.
17453 if Comes_From_Source (Expec_Type) then
17454 Matching_Field := Expec_Type;
17456 -- For an assignment, use name of target
17458 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
17459 and then Is_Entity_Name (Name (Parent (Expr)))
17460 then
17461 Matching_Field := Entity (Name (Parent (Expr)));
17462 end if;
17464 return True;
17466 elsif not Is_Record_Type (Expec_Type) then
17467 return False;
17469 else
17470 E := First_Entity (Expec_Type);
17471 loop
17472 if No (E) then
17473 return False;
17475 elsif not Ekind_In (E, E_Discriminant, E_Component)
17476 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
17477 then
17478 Next_Entity (E);
17480 else
17481 exit;
17482 end if;
17483 end loop;
17485 if not Covers (Etype (E), Found_Type) then
17486 return False;
17488 elsif Present (Next_Entity (E))
17489 and then (Ekind (E) = E_Component
17490 or else Ekind (Next_Entity (E)) = E_Discriminant)
17491 then
17492 return False;
17494 else
17495 Matching_Field := E;
17496 return True;
17497 end if;
17498 end if;
17499 end Has_One_Matching_Field;
17501 -- Start of processing for Wrong_Type
17503 begin
17504 -- Don't output message if either type is Any_Type, or if a message
17505 -- has already been posted for this node. We need to do the latter
17506 -- check explicitly (it is ordinarily done in Errout), because we
17507 -- are using ! to force the output of the error messages.
17509 if Expec_Type = Any_Type
17510 or else Found_Type = Any_Type
17511 or else Error_Posted (Expr)
17512 then
17513 return;
17515 -- If one of the types is a Taft-Amendment type and the other it its
17516 -- completion, it must be an illegal use of a TAT in the spec, for
17517 -- which an error was already emitted. Avoid cascaded errors.
17519 elsif Is_Incomplete_Type (Expec_Type)
17520 and then Has_Completion_In_Body (Expec_Type)
17521 and then Full_View (Expec_Type) = Etype (Expr)
17522 then
17523 return;
17525 elsif Is_Incomplete_Type (Etype (Expr))
17526 and then Has_Completion_In_Body (Etype (Expr))
17527 and then Full_View (Etype (Expr)) = Expec_Type
17528 then
17529 return;
17531 -- In an instance, there is an ongoing problem with completion of
17532 -- type derived from private types. Their structure is what Gigi
17533 -- expects, but the Etype is the parent type rather than the
17534 -- derived private type itself. Do not flag error in this case. The
17535 -- private completion is an entity without a parent, like an Itype.
17536 -- Similarly, full and partial views may be incorrect in the instance.
17537 -- There is no simple way to insure that it is consistent ???
17539 -- A similar view discrepancy can happen in an inlined body, for the
17540 -- same reason: inserted body may be outside of the original package
17541 -- and only partial views are visible at the point of insertion.
17543 elsif In_Instance or else In_Inlined_Body then
17544 if Etype (Etype (Expr)) = Etype (Expected_Type)
17545 and then
17546 (Has_Private_Declaration (Expected_Type)
17547 or else Has_Private_Declaration (Etype (Expr)))
17548 and then No (Parent (Expected_Type))
17549 then
17550 return;
17552 elsif Nkind (Parent (Expr)) = N_Qualified_Expression
17553 and then Entity (Subtype_Mark (Parent (Expr))) = Expected_Type
17554 then
17555 return;
17557 elsif Is_Private_Type (Expected_Type)
17558 and then Present (Full_View (Expected_Type))
17559 and then Covers (Full_View (Expected_Type), Etype (Expr))
17560 then
17561 return;
17562 end if;
17563 end if;
17565 -- An interesting special check. If the expression is parenthesized
17566 -- and its type corresponds to the type of the sole component of the
17567 -- expected record type, or to the component type of the expected one
17568 -- dimensional array type, then assume we have a bad aggregate attempt.
17570 if Nkind (Expr) in N_Subexpr
17571 and then Paren_Count (Expr) /= 0
17572 and then Has_One_Matching_Field
17573 then
17574 Error_Msg_N ("positional aggregate cannot have one component", Expr);
17575 if Present (Matching_Field) then
17576 if Is_Array_Type (Expec_Type) then
17577 Error_Msg_NE
17578 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
17580 else
17581 Error_Msg_NE
17582 ("\write instead `& ='> ...`", Expr, Matching_Field);
17583 end if;
17584 end if;
17586 -- Another special check, if we are looking for a pool-specific access
17587 -- type and we found an E_Access_Attribute_Type, then we have the case
17588 -- of an Access attribute being used in a context which needs a pool-
17589 -- specific type, which is never allowed. The one extra check we make
17590 -- is that the expected designated type covers the Found_Type.
17592 elsif Is_Access_Type (Expec_Type)
17593 and then Ekind (Found_Type) = E_Access_Attribute_Type
17594 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
17595 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
17596 and then Covers
17597 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
17598 then
17599 Error_Msg_N -- CODEFIX
17600 ("result must be general access type!", Expr);
17601 Error_Msg_NE -- CODEFIX
17602 ("add ALL to }!", Expr, Expec_Type);
17604 -- Another special check, if the expected type is an integer type,
17605 -- but the expression is of type System.Address, and the parent is
17606 -- an addition or subtraction operation whose left operand is the
17607 -- expression in question and whose right operand is of an integral
17608 -- type, then this is an attempt at address arithmetic, so give
17609 -- appropriate message.
17611 elsif Is_Integer_Type (Expec_Type)
17612 and then Is_RTE (Found_Type, RE_Address)
17613 and then Nkind_In (Parent (Expr), N_Op_Add, N_Op_Subtract)
17614 and then Expr = Left_Opnd (Parent (Expr))
17615 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
17616 then
17617 Error_Msg_N
17618 ("address arithmetic not predefined in package System",
17619 Parent (Expr));
17620 Error_Msg_N
17621 ("\possible missing with/use of System.Storage_Elements",
17622 Parent (Expr));
17623 return;
17625 -- If the expected type is an anonymous access type, as for access
17626 -- parameters and discriminants, the error is on the designated types.
17628 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
17629 if Comes_From_Source (Expec_Type) then
17630 Error_Msg_NE ("expected}!", Expr, Expec_Type);
17631 else
17632 Error_Msg_NE
17633 ("expected an access type with designated}",
17634 Expr, Designated_Type (Expec_Type));
17635 end if;
17637 if Is_Access_Type (Found_Type)
17638 and then not Comes_From_Source (Found_Type)
17639 then
17640 Error_Msg_NE
17641 ("\\found an access type with designated}!",
17642 Expr, Designated_Type (Found_Type));
17643 else
17644 if From_Limited_With (Found_Type) then
17645 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
17646 Error_Msg_Qual_Level := 99;
17647 Error_Msg_NE -- CODEFIX
17648 ("\\missing `WITH &;", Expr, Scope (Found_Type));
17649 Error_Msg_Qual_Level := 0;
17650 else
17651 Error_Msg_NE ("found}!", Expr, Found_Type);
17652 end if;
17653 end if;
17655 -- Normal case of one type found, some other type expected
17657 else
17658 -- If the names of the two types are the same, see if some number
17659 -- of levels of qualification will help. Don't try more than three
17660 -- levels, and if we get to standard, it's no use (and probably
17661 -- represents an error in the compiler) Also do not bother with
17662 -- internal scope names.
17664 declare
17665 Expec_Scope : Entity_Id;
17666 Found_Scope : Entity_Id;
17668 begin
17669 Expec_Scope := Expec_Type;
17670 Found_Scope := Found_Type;
17672 for Levels in Int range 0 .. 3 loop
17673 if Chars (Expec_Scope) /= Chars (Found_Scope) then
17674 Error_Msg_Qual_Level := Levels;
17675 exit;
17676 end if;
17678 Expec_Scope := Scope (Expec_Scope);
17679 Found_Scope := Scope (Found_Scope);
17681 exit when Expec_Scope = Standard_Standard
17682 or else Found_Scope = Standard_Standard
17683 or else not Comes_From_Source (Expec_Scope)
17684 or else not Comes_From_Source (Found_Scope);
17685 end loop;
17686 end;
17688 if Is_Record_Type (Expec_Type)
17689 and then Present (Corresponding_Remote_Type (Expec_Type))
17690 then
17691 Error_Msg_NE ("expected}!", Expr,
17692 Corresponding_Remote_Type (Expec_Type));
17693 else
17694 Error_Msg_NE ("expected}!", Expr, Expec_Type);
17695 end if;
17697 if Is_Entity_Name (Expr)
17698 and then Is_Package_Or_Generic_Package (Entity (Expr))
17699 then
17700 Error_Msg_N ("\\found package name!", Expr);
17702 elsif Is_Entity_Name (Expr)
17703 and then Ekind_In (Entity (Expr), E_Procedure, E_Generic_Procedure)
17704 then
17705 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
17706 Error_Msg_N
17707 ("found procedure name, possibly missing Access attribute!",
17708 Expr);
17709 else
17710 Error_Msg_N
17711 ("\\found procedure name instead of function!", Expr);
17712 end if;
17714 elsif Nkind (Expr) = N_Function_Call
17715 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
17716 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
17717 and then No (Parameter_Associations (Expr))
17718 then
17719 Error_Msg_N
17720 ("found function name, possibly missing Access attribute!",
17721 Expr);
17723 -- Catch common error: a prefix or infix operator which is not
17724 -- directly visible because the type isn't.
17726 elsif Nkind (Expr) in N_Op
17727 and then Is_Overloaded (Expr)
17728 and then not Is_Immediately_Visible (Expec_Type)
17729 and then not Is_Potentially_Use_Visible (Expec_Type)
17730 and then not In_Use (Expec_Type)
17731 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
17732 then
17733 Error_Msg_N
17734 ("operator of the type is not directly visible!", Expr);
17736 elsif Ekind (Found_Type) = E_Void
17737 and then Present (Parent (Found_Type))
17738 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
17739 then
17740 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
17742 else
17743 Error_Msg_NE ("\\found}!", Expr, Found_Type);
17744 end if;
17746 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
17747 -- of the same modular type, and (M1 and M2) = 0 was intended.
17749 if Expec_Type = Standard_Boolean
17750 and then Is_Modular_Integer_Type (Found_Type)
17751 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
17752 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
17753 then
17754 declare
17755 Op : constant Node_Id := Right_Opnd (Parent (Expr));
17756 L : constant Node_Id := Left_Opnd (Op);
17757 R : constant Node_Id := Right_Opnd (Op);
17758 begin
17759 -- The case for the message is when the left operand of the
17760 -- comparison is the same modular type, or when it is an
17761 -- integer literal (or other universal integer expression),
17762 -- which would have been typed as the modular type if the
17763 -- parens had been there.
17765 if (Etype (L) = Found_Type
17766 or else
17767 Etype (L) = Universal_Integer)
17768 and then Is_Integer_Type (Etype (R))
17769 then
17770 Error_Msg_N
17771 ("\\possible missing parens for modular operation", Expr);
17772 end if;
17773 end;
17774 end if;
17776 -- Reset error message qualification indication
17778 Error_Msg_Qual_Level := 0;
17779 end if;
17780 end Wrong_Type;
17782 end Sem_Util;