2014-01-30 Richard Biener <rguenther@suse.de>
[official-gcc.git] / gcc / ada / sem_util.adb
blob85c8592959ff70514bb068e6af59d3744fd07730
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-2013, 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 Atree; use Atree;
27 with Casing; use Casing;
28 with Checks; use Checks;
29 with Debug; use Debug;
30 with Elists; use Elists;
31 with Errout; use Errout;
32 with Exp_Ch11; use Exp_Ch11;
33 with Exp_Disp; use Exp_Disp;
34 with Exp_Util; use Exp_Util;
35 with Fname; use Fname;
36 with Freeze; use Freeze;
37 with Lib; use Lib;
38 with Lib.Xref; use Lib.Xref;
39 with Namet.Sp; use Namet.Sp;
40 with Nlists; use Nlists;
41 with Nmake; use Nmake;
42 with Output; use Output;
43 with Opt; use Opt;
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_Disp; use Sem_Disp;
52 with Sem_Eval; use Sem_Eval;
53 with Sem_Res; use Sem_Res;
54 with Sem_Type; use Sem_Type;
55 with Sinfo; use Sinfo;
56 with Sinput; use Sinput;
57 with Stand; use Stand;
58 with Style;
59 with Stringt; use Stringt;
60 with Targparm; use Targparm;
61 with Tbuild; use Tbuild;
62 with Ttypes; use Ttypes;
63 with Uname; use Uname;
65 with GNAT.HTable; use GNAT.HTable;
67 package body Sem_Util is
69 ----------------------------------------
70 -- Global_Variables for New_Copy_Tree --
71 ----------------------------------------
73 -- These global variables are used by New_Copy_Tree. See description
74 -- of the body of this subprogram for details. Global variables can be
75 -- safely used by New_Copy_Tree, since there is no case of a recursive
76 -- call from the processing inside New_Copy_Tree.
78 NCT_Hash_Threshold : constant := 20;
79 -- If there are more than this number of pairs of entries in the
80 -- map, then Hash_Tables_Used will be set, and the hash tables will
81 -- be initialized and used for the searches.
83 NCT_Hash_Tables_Used : Boolean := False;
84 -- Set to True if hash tables are in use
86 NCT_Table_Entries : Nat := 0;
87 -- Count entries in table to see if threshold is reached
89 NCT_Hash_Table_Setup : Boolean := False;
90 -- Set to True if hash table contains data. We set this True if we
91 -- setup the hash table with data, and leave it set permanently
92 -- from then on, this is a signal that second and subsequent users
93 -- of the hash table must clear the old entries before reuse.
95 subtype NCT_Header_Num is Int range 0 .. 511;
96 -- Defines range of headers in hash tables (512 headers)
98 -----------------------
99 -- Local Subprograms --
100 -----------------------
102 function Build_Component_Subtype
103 (C : List_Id;
104 Loc : Source_Ptr;
105 T : Entity_Id) return Node_Id;
106 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
107 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
108 -- Loc is the source location, T is the original subtype.
110 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean;
111 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
112 -- with discriminants whose default values are static, examine only the
113 -- components in the selected variant to determine whether all of them
114 -- have a default.
116 function Has_Enabled_Property
117 (State_Id : Node_Id;
118 Prop_Nam : Name_Id) return Boolean;
119 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
120 -- Determine whether an abstract state denoted by its entity State_Id has
121 -- enabled property Prop_Name.
123 function Has_Null_Extension (T : Entity_Id) return Boolean;
124 -- T is a derived tagged type. Check whether the type extension is null.
125 -- If the parent type is fully initialized, T can be treated as such.
127 ------------------------------
128 -- Abstract_Interface_List --
129 ------------------------------
131 function Abstract_Interface_List (Typ : Entity_Id) return List_Id is
132 Nod : Node_Id;
134 begin
135 if Is_Concurrent_Type (Typ) then
137 -- If we are dealing with a synchronized subtype, go to the base
138 -- type, whose declaration has the interface list.
140 -- Shouldn't this be Declaration_Node???
142 Nod := Parent (Base_Type (Typ));
144 if Nkind (Nod) = N_Full_Type_Declaration then
145 return Empty_List;
146 end if;
148 elsif Ekind (Typ) = E_Record_Type_With_Private then
149 if Nkind (Parent (Typ)) = N_Full_Type_Declaration then
150 Nod := Type_Definition (Parent (Typ));
152 elsif Nkind (Parent (Typ)) = N_Private_Type_Declaration then
153 if Present (Full_View (Typ))
154 and then Nkind (Parent (Full_View (Typ)))
155 = N_Full_Type_Declaration
156 then
157 Nod := Type_Definition (Parent (Full_View (Typ)));
159 -- If the full-view is not available we cannot do anything else
160 -- here (the source has errors).
162 else
163 return Empty_List;
164 end if;
166 -- Support for generic formals with interfaces is still missing ???
168 elsif Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
169 return Empty_List;
171 else
172 pragma Assert
173 (Nkind (Parent (Typ)) = N_Private_Extension_Declaration);
174 Nod := Parent (Typ);
175 end if;
177 elsif Ekind (Typ) = E_Record_Subtype then
178 Nod := Type_Definition (Parent (Etype (Typ)));
180 elsif Ekind (Typ) = E_Record_Subtype_With_Private then
182 -- Recurse, because parent may still be a private extension. Also
183 -- note that the full view of the subtype or the full view of its
184 -- base type may (both) be unavailable.
186 return Abstract_Interface_List (Etype (Typ));
188 else pragma Assert ((Ekind (Typ)) = E_Record_Type);
189 if Nkind (Parent (Typ)) = N_Formal_Type_Declaration then
190 Nod := Formal_Type_Definition (Parent (Typ));
191 else
192 Nod := Type_Definition (Parent (Typ));
193 end if;
194 end if;
196 return Interface_List (Nod);
197 end Abstract_Interface_List;
199 --------------------------------
200 -- Add_Access_Type_To_Process --
201 --------------------------------
203 procedure Add_Access_Type_To_Process (E : Entity_Id; A : Entity_Id) is
204 L : Elist_Id;
206 begin
207 Ensure_Freeze_Node (E);
208 L := Access_Types_To_Process (Freeze_Node (E));
210 if No (L) then
211 L := New_Elmt_List;
212 Set_Access_Types_To_Process (Freeze_Node (E), L);
213 end if;
215 Append_Elmt (A, L);
216 end Add_Access_Type_To_Process;
218 -----------------------
219 -- Add_Contract_Item --
220 -----------------------
222 procedure Add_Contract_Item (Prag : Node_Id; Id : Entity_Id) is
223 Items : constant Node_Id := Contract (Id);
224 Nam : Name_Id;
225 N : Node_Id;
227 begin
228 -- The related context must have a contract and the item to be added
229 -- must be a pragma.
231 pragma Assert (Present (Items));
232 pragma Assert (Nkind (Prag) = N_Pragma);
234 Nam := Original_Aspect_Name (Prag);
236 -- Contract items related to [generic] packages or instantiations. The
237 -- applicable pragmas are:
238 -- Abstract_States
239 -- Initial_Condition
240 -- Initializes
241 -- Part_Of (instantiation only)
243 if Ekind_In (Id, E_Generic_Package, E_Package) then
244 if Nam_In (Nam, Name_Abstract_State,
245 Name_Initial_Condition,
246 Name_Initializes)
247 then
248 Set_Next_Pragma (Prag, Classifications (Items));
249 Set_Classifications (Items, Prag);
251 -- Indicator Part_Of must be associated with a package instantiation
253 elsif Nam = Name_Part_Of and then Is_Generic_Instance (Id) then
254 Set_Next_Pragma (Prag, Classifications (Items));
255 Set_Classifications (Items, Prag);
257 -- The pragma is not a proper contract item
259 else
260 raise Program_Error;
261 end if;
263 -- Contract items related to package bodies. The applicable pragmas are:
264 -- Refined_States
266 elsif Ekind (Id) = E_Package_Body then
267 if Nam = Name_Refined_State then
268 Set_Next_Pragma (Prag, Classifications (Items));
269 Set_Classifications (Items, Prag);
271 -- The pragma is not a proper contract item
273 else
274 raise Program_Error;
275 end if;
277 -- Contract items related to subprogram or entry declarations. The
278 -- applicable pragmas are:
279 -- Contract_Cases
280 -- Depends
281 -- Global
282 -- Post
283 -- Postcondition
284 -- Pre
285 -- Precondition
286 -- Test_Case
288 elsif Ekind_In (Id, E_Entry, E_Entry_Family)
289 or else Is_Generic_Subprogram (Id)
290 or else Is_Subprogram (Id)
291 then
292 if Nam_In (Nam, Name_Precondition,
293 Name_Postcondition,
294 Name_Pre,
295 Name_Post,
296 Name_uPre,
297 Name_uPost)
298 then
299 -- Before we add a precondition or postcondition to the list,
300 -- make sure we do not have a disallowed duplicate, which can
301 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
302 -- instead of the corresponding aspect.
304 if not From_Aspect_Specification (Prag)
305 and then Nam_In (Nam, Name_Pre_Class,
306 Name_Pre,
307 Name_uPre,
308 Name_Post_Class,
309 Name_Post,
310 Name_uPost)
311 then
312 N := Pre_Post_Conditions (Items);
313 while Present (N) loop
314 if not Split_PPC (N)
315 and then Original_Aspect_Name (N) = Nam
316 then
317 Error_Msg_Sloc := Sloc (N);
318 Error_Msg_NE
319 ("duplication of aspect for & given#", Prag, Id);
320 return;
321 else
322 N := Next_Pragma (N);
323 end if;
324 end loop;
325 end if;
327 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
328 Set_Pre_Post_Conditions (Items, Prag);
330 elsif Nam_In (Nam, Name_Contract_Cases, Name_Test_Case) then
331 Set_Next_Pragma (Prag, Contract_Test_Cases (Items));
332 Set_Contract_Test_Cases (Items, Prag);
334 elsif Nam_In (Nam, Name_Depends, Name_Global) then
335 Set_Next_Pragma (Prag, Classifications (Items));
336 Set_Classifications (Items, Prag);
338 -- The pragma is not a proper contract item
340 else
341 raise Program_Error;
342 end if;
344 -- Contract items related to subprogram bodies. The applicable pragmas
345 -- are:
346 -- Refined_Depends
347 -- Refined_Global
348 -- Refined_Post
350 elsif Ekind (Id) = E_Subprogram_Body then
351 if Nam = Name_Refined_Post then
352 Set_Next_Pragma (Prag, Pre_Post_Conditions (Items));
353 Set_Pre_Post_Conditions (Items, Prag);
355 elsif Nam_In (Nam, Name_Refined_Depends, Name_Refined_Global) then
356 Set_Next_Pragma (Prag, Classifications (Items));
357 Set_Classifications (Items, Prag);
359 -- The pragma is not a proper contract item
361 else
362 raise Program_Error;
363 end if;
365 -- Contract items related to variables. The applicable pragmas are:
366 -- Async_Readers
367 -- Async_Writers
368 -- Effective_Reads
369 -- Effective_Writes
370 -- Part_Of
372 elsif Ekind (Id) = E_Variable then
373 if Nam_In (Nam, Name_Async_Readers,
374 Name_Async_Writers,
375 Name_Effective_Reads,
376 Name_Effective_Writes,
377 Name_Part_Of)
378 then
379 Set_Next_Pragma (Prag, Classifications (Items));
380 Set_Classifications (Items, Prag);
382 -- The pragma is not a proper contract item
384 else
385 raise Program_Error;
386 end if;
387 end if;
388 end Add_Contract_Item;
390 ----------------------------
391 -- Add_Global_Declaration --
392 ----------------------------
394 procedure Add_Global_Declaration (N : Node_Id) is
395 Aux_Node : constant Node_Id := Aux_Decls_Node (Cunit (Current_Sem_Unit));
397 begin
398 if No (Declarations (Aux_Node)) then
399 Set_Declarations (Aux_Node, New_List);
400 end if;
402 Append_To (Declarations (Aux_Node), N);
403 Analyze (N);
404 end Add_Global_Declaration;
406 --------------------------------
407 -- Address_Integer_Convert_OK --
408 --------------------------------
410 function Address_Integer_Convert_OK (T1, T2 : Entity_Id) return Boolean is
411 begin
412 if Allow_Integer_Address
413 and then ((Is_Descendent_Of_Address (T1)
414 and then Is_Private_Type (T1)
415 and then Is_Integer_Type (T2))
416 or else
417 (Is_Descendent_Of_Address (T2)
418 and then Is_Private_Type (T2)
419 and then Is_Integer_Type (T1)))
420 then
421 return True;
422 else
423 return False;
424 end if;
425 end Address_Integer_Convert_OK;
427 -----------------
428 -- Addressable --
429 -----------------
431 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
433 function Addressable (V : Uint) return Boolean is
434 begin
435 return V = Uint_8 or else
436 V = Uint_16 or else
437 V = Uint_32 or else
438 V = Uint_64;
439 end Addressable;
441 function Addressable (V : Int) return Boolean is
442 begin
443 return V = 8 or else
444 V = 16 or else
445 V = 32 or else
446 V = 64;
447 end Addressable;
449 -----------------------
450 -- Alignment_In_Bits --
451 -----------------------
453 function Alignment_In_Bits (E : Entity_Id) return Uint is
454 begin
455 return Alignment (E) * System_Storage_Unit;
456 end Alignment_In_Bits;
458 ---------------------------------
459 -- Append_Inherited_Subprogram --
460 ---------------------------------
462 procedure Append_Inherited_Subprogram (S : Entity_Id) is
463 Par : constant Entity_Id := Alias (S);
464 -- The parent subprogram
466 Scop : constant Entity_Id := Scope (Par);
467 -- The scope of definition of the parent subprogram
469 Typ : constant Entity_Id := Defining_Entity (Parent (S));
470 -- The derived type of which S is a primitive operation
472 Decl : Node_Id;
473 Next_E : Entity_Id;
475 begin
476 if Ekind (Current_Scope) = E_Package
477 and then In_Private_Part (Current_Scope)
478 and then Has_Private_Declaration (Typ)
479 and then Is_Tagged_Type (Typ)
480 and then Scop = Current_Scope
481 then
482 -- The inherited operation is available at the earliest place after
483 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
484 -- relevant for type extensions. If the parent operation appears
485 -- after the type extension, the operation is not visible.
487 Decl := First
488 (Visible_Declarations
489 (Package_Specification (Current_Scope)));
490 while Present (Decl) loop
491 if Nkind (Decl) = N_Private_Extension_Declaration
492 and then Defining_Entity (Decl) = Typ
493 then
494 if Sloc (Decl) > Sloc (Par) then
495 Next_E := Next_Entity (Par);
496 Set_Next_Entity (Par, S);
497 Set_Next_Entity (S, Next_E);
498 return;
500 else
501 exit;
502 end if;
503 end if;
505 Next (Decl);
506 end loop;
507 end if;
509 -- If partial view is not a type extension, or it appears before the
510 -- subprogram declaration, insert normally at end of entity list.
512 Append_Entity (S, Current_Scope);
513 end Append_Inherited_Subprogram;
515 -----------------------------------------
516 -- Apply_Compile_Time_Constraint_Error --
517 -----------------------------------------
519 procedure Apply_Compile_Time_Constraint_Error
520 (N : Node_Id;
521 Msg : String;
522 Reason : RT_Exception_Code;
523 Ent : Entity_Id := Empty;
524 Typ : Entity_Id := Empty;
525 Loc : Source_Ptr := No_Location;
526 Rep : Boolean := True;
527 Warn : Boolean := False)
529 Stat : constant Boolean := Is_Static_Expression (N);
530 R_Stat : constant Node_Id :=
531 Make_Raise_Constraint_Error (Sloc (N), Reason => Reason);
532 Rtyp : Entity_Id;
534 begin
535 if No (Typ) then
536 Rtyp := Etype (N);
537 else
538 Rtyp := Typ;
539 end if;
541 Discard_Node
542 (Compile_Time_Constraint_Error (N, Msg, Ent, Loc, Warn => Warn));
544 if not Rep then
545 return;
546 end if;
548 -- Now we replace the node by an N_Raise_Constraint_Error node
549 -- This does not need reanalyzing, so set it as analyzed now.
551 Rewrite (N, R_Stat);
552 Set_Analyzed (N, True);
554 Set_Etype (N, Rtyp);
555 Set_Raises_Constraint_Error (N);
557 -- Now deal with possible local raise handling
559 Possible_Local_Raise (N, Standard_Constraint_Error);
561 -- If the original expression was marked as static, the result is
562 -- still marked as static, but the Raises_Constraint_Error flag is
563 -- always set so that further static evaluation is not attempted.
565 if Stat then
566 Set_Is_Static_Expression (N);
567 end if;
568 end Apply_Compile_Time_Constraint_Error;
570 ---------------------------
571 -- Async_Readers_Enabled --
572 ---------------------------
574 function Async_Readers_Enabled (Id : Entity_Id) return Boolean is
575 begin
576 if Ekind (Id) = E_Abstract_State then
577 return Has_Enabled_Property (Id, Name_Async_Readers);
579 else pragma Assert (Ekind (Id) = E_Variable);
580 return Present (Get_Pragma (Id, Pragma_Async_Readers));
581 end if;
582 end Async_Readers_Enabled;
584 ---------------------------
585 -- Async_Writers_Enabled --
586 ---------------------------
588 function Async_Writers_Enabled (Id : Entity_Id) return Boolean is
589 begin
590 if Ekind (Id) = E_Abstract_State then
591 return Has_Enabled_Property (Id, Name_Async_Writers);
593 else pragma Assert (Ekind (Id) = E_Variable);
594 return Present (Get_Pragma (Id, Pragma_Async_Writers));
595 end if;
596 end Async_Writers_Enabled;
598 --------------------------------------
599 -- Available_Full_View_Of_Component --
600 --------------------------------------
602 function Available_Full_View_Of_Component (T : Entity_Id) return Boolean is
603 ST : constant Entity_Id := Scope (T);
604 SCT : constant Entity_Id := Scope (Component_Type (T));
605 begin
606 return In_Open_Scopes (ST)
607 and then In_Open_Scopes (SCT)
608 and then Scope_Depth (ST) >= Scope_Depth (SCT);
609 end Available_Full_View_Of_Component;
611 -------------------
612 -- Bad_Attribute --
613 -------------------
615 procedure Bad_Attribute
616 (N : Node_Id;
617 Nam : Name_Id;
618 Warn : Boolean := False)
620 begin
621 Error_Msg_Warn := Warn;
622 Error_Msg_N ("unrecognized attribute&<", N);
624 -- Check for possible misspelling
626 Error_Msg_Name_1 := First_Attribute_Name;
627 while Error_Msg_Name_1 <= Last_Attribute_Name loop
628 if Is_Bad_Spelling_Of (Nam, Error_Msg_Name_1) then
629 Error_Msg_N -- CODEFIX
630 ("\possible misspelling of %<", N);
631 exit;
632 end if;
634 Error_Msg_Name_1 := Error_Msg_Name_1 + 1;
635 end loop;
636 end Bad_Attribute;
638 --------------------------------
639 -- Bad_Predicated_Subtype_Use --
640 --------------------------------
642 procedure Bad_Predicated_Subtype_Use
643 (Msg : String;
644 N : Node_Id;
645 Typ : Entity_Id;
646 Suggest_Static : Boolean := False)
648 begin
649 if Has_Predicates (Typ) then
650 if Is_Generic_Actual_Type (Typ) then
651 Error_Msg_Warn := SPARK_Mode /= On;
652 Error_Msg_FE (Msg & "<<", N, Typ);
653 Error_Msg_F ("\Program_Error [<<", N);
654 Insert_Action (N,
655 Make_Raise_Program_Error (Sloc (N),
656 Reason => PE_Bad_Predicated_Generic_Type));
658 else
659 Error_Msg_FE (Msg, N, Typ);
660 end if;
662 -- Emit an optional suggestion on how to remedy the error if the
663 -- context warrants it.
665 if Suggest_Static and then Present (Static_Predicate (Typ)) then
666 Error_Msg_FE ("\predicate of & should be marked static", N, Typ);
667 end if;
668 end if;
669 end Bad_Predicated_Subtype_Use;
671 --------------------------
672 -- Build_Actual_Subtype --
673 --------------------------
675 function Build_Actual_Subtype
676 (T : Entity_Id;
677 N : Node_Or_Entity_Id) return Node_Id
679 Loc : Source_Ptr;
680 -- Normally Sloc (N), but may point to corresponding body in some cases
682 Constraints : List_Id;
683 Decl : Node_Id;
684 Discr : Entity_Id;
685 Hi : Node_Id;
686 Lo : Node_Id;
687 Subt : Entity_Id;
688 Disc_Type : Entity_Id;
689 Obj : Node_Id;
691 begin
692 Loc := Sloc (N);
694 if Nkind (N) = N_Defining_Identifier then
695 Obj := New_Reference_To (N, Loc);
697 -- If this is a formal parameter of a subprogram declaration, and
698 -- we are compiling the body, we want the declaration for the
699 -- actual subtype to carry the source position of the body, to
700 -- prevent anomalies in gdb when stepping through the code.
702 if Is_Formal (N) then
703 declare
704 Decl : constant Node_Id := Unit_Declaration_Node (Scope (N));
705 begin
706 if Nkind (Decl) = N_Subprogram_Declaration
707 and then Present (Corresponding_Body (Decl))
708 then
709 Loc := Sloc (Corresponding_Body (Decl));
710 end if;
711 end;
712 end if;
714 else
715 Obj := N;
716 end if;
718 if Is_Array_Type (T) then
719 Constraints := New_List;
720 for J in 1 .. Number_Dimensions (T) loop
722 -- Build an array subtype declaration with the nominal subtype and
723 -- the bounds of the actual. Add the declaration in front of the
724 -- local declarations for the subprogram, for analysis before any
725 -- reference to the formal in the body.
727 Lo :=
728 Make_Attribute_Reference (Loc,
729 Prefix =>
730 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
731 Attribute_Name => Name_First,
732 Expressions => New_List (
733 Make_Integer_Literal (Loc, J)));
735 Hi :=
736 Make_Attribute_Reference (Loc,
737 Prefix =>
738 Duplicate_Subexpr_No_Checks (Obj, Name_Req => True),
739 Attribute_Name => Name_Last,
740 Expressions => New_List (
741 Make_Integer_Literal (Loc, J)));
743 Append (Make_Range (Loc, Lo, Hi), Constraints);
744 end loop;
746 -- If the type has unknown discriminants there is no constrained
747 -- subtype to build. This is never called for a formal or for a
748 -- lhs, so returning the type is ok ???
750 elsif Has_Unknown_Discriminants (T) then
751 return T;
753 else
754 Constraints := New_List;
756 -- Type T is a generic derived type, inherit the discriminants from
757 -- the parent type.
759 if Is_Private_Type (T)
760 and then No (Full_View (T))
762 -- T was flagged as an error if it was declared as a formal
763 -- derived type with known discriminants. In this case there
764 -- is no need to look at the parent type since T already carries
765 -- its own discriminants.
767 and then not Error_Posted (T)
768 then
769 Disc_Type := Etype (Base_Type (T));
770 else
771 Disc_Type := T;
772 end if;
774 Discr := First_Discriminant (Disc_Type);
775 while Present (Discr) loop
776 Append_To (Constraints,
777 Make_Selected_Component (Loc,
778 Prefix =>
779 Duplicate_Subexpr_No_Checks (Obj),
780 Selector_Name => New_Occurrence_Of (Discr, Loc)));
781 Next_Discriminant (Discr);
782 end loop;
783 end if;
785 Subt := Make_Temporary (Loc, 'S', Related_Node => N);
786 Set_Is_Internal (Subt);
788 Decl :=
789 Make_Subtype_Declaration (Loc,
790 Defining_Identifier => Subt,
791 Subtype_Indication =>
792 Make_Subtype_Indication (Loc,
793 Subtype_Mark => New_Reference_To (T, Loc),
794 Constraint =>
795 Make_Index_Or_Discriminant_Constraint (Loc,
796 Constraints => Constraints)));
798 Mark_Rewrite_Insertion (Decl);
799 return Decl;
800 end Build_Actual_Subtype;
802 ---------------------------------------
803 -- Build_Actual_Subtype_Of_Component --
804 ---------------------------------------
806 function Build_Actual_Subtype_Of_Component
807 (T : Entity_Id;
808 N : Node_Id) return Node_Id
810 Loc : constant Source_Ptr := Sloc (N);
811 P : constant Node_Id := Prefix (N);
812 D : Elmt_Id;
813 Id : Node_Id;
814 Index_Typ : Entity_Id;
816 Desig_Typ : Entity_Id;
817 -- This is either a copy of T, or if T is an access type, then it is
818 -- the directly designated type of this access type.
820 function Build_Actual_Array_Constraint return List_Id;
821 -- If one or more of the bounds of the component depends on
822 -- discriminants, build actual constraint using the discriminants
823 -- of the prefix.
825 function Build_Actual_Record_Constraint return List_Id;
826 -- Similar to previous one, for discriminated components constrained
827 -- by the discriminant of the enclosing object.
829 -----------------------------------
830 -- Build_Actual_Array_Constraint --
831 -----------------------------------
833 function Build_Actual_Array_Constraint return List_Id is
834 Constraints : constant List_Id := New_List;
835 Indx : Node_Id;
836 Hi : Node_Id;
837 Lo : Node_Id;
838 Old_Hi : Node_Id;
839 Old_Lo : Node_Id;
841 begin
842 Indx := First_Index (Desig_Typ);
843 while Present (Indx) loop
844 Old_Lo := Type_Low_Bound (Etype (Indx));
845 Old_Hi := Type_High_Bound (Etype (Indx));
847 if Denotes_Discriminant (Old_Lo) then
848 Lo :=
849 Make_Selected_Component (Loc,
850 Prefix => New_Copy_Tree (P),
851 Selector_Name => New_Occurrence_Of (Entity (Old_Lo), Loc));
853 else
854 Lo := New_Copy_Tree (Old_Lo);
856 -- The new bound will be reanalyzed in the enclosing
857 -- declaration. For literal bounds that come from a type
858 -- declaration, the type of the context must be imposed, so
859 -- insure that analysis will take place. For non-universal
860 -- types this is not strictly necessary.
862 Set_Analyzed (Lo, False);
863 end if;
865 if Denotes_Discriminant (Old_Hi) then
866 Hi :=
867 Make_Selected_Component (Loc,
868 Prefix => New_Copy_Tree (P),
869 Selector_Name => New_Occurrence_Of (Entity (Old_Hi), Loc));
871 else
872 Hi := New_Copy_Tree (Old_Hi);
873 Set_Analyzed (Hi, False);
874 end if;
876 Append (Make_Range (Loc, Lo, Hi), Constraints);
877 Next_Index (Indx);
878 end loop;
880 return Constraints;
881 end Build_Actual_Array_Constraint;
883 ------------------------------------
884 -- Build_Actual_Record_Constraint --
885 ------------------------------------
887 function Build_Actual_Record_Constraint return List_Id is
888 Constraints : constant List_Id := New_List;
889 D : Elmt_Id;
890 D_Val : Node_Id;
892 begin
893 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
894 while Present (D) loop
895 if Denotes_Discriminant (Node (D)) then
896 D_Val := Make_Selected_Component (Loc,
897 Prefix => New_Copy_Tree (P),
898 Selector_Name => New_Occurrence_Of (Entity (Node (D)), Loc));
900 else
901 D_Val := New_Copy_Tree (Node (D));
902 end if;
904 Append (D_Val, Constraints);
905 Next_Elmt (D);
906 end loop;
908 return Constraints;
909 end Build_Actual_Record_Constraint;
911 -- Start of processing for Build_Actual_Subtype_Of_Component
913 begin
914 -- Why the test for Spec_Expression mode here???
916 if In_Spec_Expression then
917 return Empty;
919 -- More comments for the rest of this body would be good ???
921 elsif Nkind (N) = N_Explicit_Dereference then
922 if Is_Composite_Type (T)
923 and then not Is_Constrained (T)
924 and then not (Is_Class_Wide_Type (T)
925 and then Is_Constrained (Root_Type (T)))
926 and then not Has_Unknown_Discriminants (T)
927 then
928 -- If the type of the dereference is already constrained, it is an
929 -- actual subtype.
931 if Is_Array_Type (Etype (N))
932 and then Is_Constrained (Etype (N))
933 then
934 return Empty;
935 else
936 Remove_Side_Effects (P);
937 return Build_Actual_Subtype (T, N);
938 end if;
939 else
940 return Empty;
941 end if;
942 end if;
944 if Ekind (T) = E_Access_Subtype then
945 Desig_Typ := Designated_Type (T);
946 else
947 Desig_Typ := T;
948 end if;
950 if Ekind (Desig_Typ) = E_Array_Subtype then
951 Id := First_Index (Desig_Typ);
952 while Present (Id) loop
953 Index_Typ := Underlying_Type (Etype (Id));
955 if Denotes_Discriminant (Type_Low_Bound (Index_Typ))
956 or else
957 Denotes_Discriminant (Type_High_Bound (Index_Typ))
958 then
959 Remove_Side_Effects (P);
960 return
961 Build_Component_Subtype
962 (Build_Actual_Array_Constraint, Loc, Base_Type (T));
963 end if;
965 Next_Index (Id);
966 end loop;
968 elsif Is_Composite_Type (Desig_Typ)
969 and then Has_Discriminants (Desig_Typ)
970 and then not Has_Unknown_Discriminants (Desig_Typ)
971 then
972 if Is_Private_Type (Desig_Typ)
973 and then No (Discriminant_Constraint (Desig_Typ))
974 then
975 Desig_Typ := Full_View (Desig_Typ);
976 end if;
978 D := First_Elmt (Discriminant_Constraint (Desig_Typ));
979 while Present (D) loop
980 if Denotes_Discriminant (Node (D)) then
981 Remove_Side_Effects (P);
982 return
983 Build_Component_Subtype (
984 Build_Actual_Record_Constraint, Loc, Base_Type (T));
985 end if;
987 Next_Elmt (D);
988 end loop;
989 end if;
991 -- If none of the above, the actual and nominal subtypes are the same
993 return Empty;
994 end Build_Actual_Subtype_Of_Component;
996 -----------------------------
997 -- Build_Component_Subtype --
998 -----------------------------
1000 function Build_Component_Subtype
1001 (C : List_Id;
1002 Loc : Source_Ptr;
1003 T : Entity_Id) return Node_Id
1005 Subt : Entity_Id;
1006 Decl : Node_Id;
1008 begin
1009 -- Unchecked_Union components do not require component subtypes
1011 if Is_Unchecked_Union (T) then
1012 return Empty;
1013 end if;
1015 Subt := Make_Temporary (Loc, 'S');
1016 Set_Is_Internal (Subt);
1018 Decl :=
1019 Make_Subtype_Declaration (Loc,
1020 Defining_Identifier => Subt,
1021 Subtype_Indication =>
1022 Make_Subtype_Indication (Loc,
1023 Subtype_Mark => New_Reference_To (Base_Type (T), Loc),
1024 Constraint =>
1025 Make_Index_Or_Discriminant_Constraint (Loc,
1026 Constraints => C)));
1028 Mark_Rewrite_Insertion (Decl);
1029 return Decl;
1030 end Build_Component_Subtype;
1032 ---------------------------
1033 -- Build_Default_Subtype --
1034 ---------------------------
1036 function Build_Default_Subtype
1037 (T : Entity_Id;
1038 N : Node_Id) return Entity_Id
1040 Loc : constant Source_Ptr := Sloc (N);
1041 Disc : Entity_Id;
1043 Bas : Entity_Id;
1044 -- The base type that is to be constrained by the defaults
1046 begin
1047 if not Has_Discriminants (T) or else Is_Constrained (T) then
1048 return T;
1049 end if;
1051 Bas := Base_Type (T);
1053 -- If T is non-private but its base type is private, this is the
1054 -- completion of a subtype declaration whose parent type is private
1055 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1056 -- are to be found in the full view of the base.
1058 if Is_Private_Type (Bas) and then Present (Full_View (Bas)) then
1059 Bas := Full_View (Bas);
1060 end if;
1062 Disc := First_Discriminant (T);
1064 if No (Discriminant_Default_Value (Disc)) then
1065 return T;
1066 end if;
1068 declare
1069 Act : constant Entity_Id := Make_Temporary (Loc, 'S');
1070 Constraints : constant List_Id := New_List;
1071 Decl : Node_Id;
1073 begin
1074 while Present (Disc) loop
1075 Append_To (Constraints,
1076 New_Copy_Tree (Discriminant_Default_Value (Disc)));
1077 Next_Discriminant (Disc);
1078 end loop;
1080 Decl :=
1081 Make_Subtype_Declaration (Loc,
1082 Defining_Identifier => Act,
1083 Subtype_Indication =>
1084 Make_Subtype_Indication (Loc,
1085 Subtype_Mark => New_Occurrence_Of (Bas, Loc),
1086 Constraint =>
1087 Make_Index_Or_Discriminant_Constraint (Loc,
1088 Constraints => Constraints)));
1090 Insert_Action (N, Decl);
1091 Analyze (Decl);
1092 return Act;
1093 end;
1094 end Build_Default_Subtype;
1096 --------------------------------------------
1097 -- Build_Discriminal_Subtype_Of_Component --
1098 --------------------------------------------
1100 function Build_Discriminal_Subtype_Of_Component
1101 (T : Entity_Id) return Node_Id
1103 Loc : constant Source_Ptr := Sloc (T);
1104 D : Elmt_Id;
1105 Id : Node_Id;
1107 function Build_Discriminal_Array_Constraint return List_Id;
1108 -- If one or more of the bounds of the component depends on
1109 -- discriminants, build actual constraint using the discriminants
1110 -- of the prefix.
1112 function Build_Discriminal_Record_Constraint return List_Id;
1113 -- Similar to previous one, for discriminated components constrained by
1114 -- the discriminant of the enclosing object.
1116 ----------------------------------------
1117 -- Build_Discriminal_Array_Constraint --
1118 ----------------------------------------
1120 function Build_Discriminal_Array_Constraint return List_Id is
1121 Constraints : constant List_Id := New_List;
1122 Indx : Node_Id;
1123 Hi : Node_Id;
1124 Lo : Node_Id;
1125 Old_Hi : Node_Id;
1126 Old_Lo : Node_Id;
1128 begin
1129 Indx := First_Index (T);
1130 while Present (Indx) loop
1131 Old_Lo := Type_Low_Bound (Etype (Indx));
1132 Old_Hi := Type_High_Bound (Etype (Indx));
1134 if Denotes_Discriminant (Old_Lo) then
1135 Lo := New_Occurrence_Of (Discriminal (Entity (Old_Lo)), Loc);
1137 else
1138 Lo := New_Copy_Tree (Old_Lo);
1139 end if;
1141 if Denotes_Discriminant (Old_Hi) then
1142 Hi := New_Occurrence_Of (Discriminal (Entity (Old_Hi)), Loc);
1144 else
1145 Hi := New_Copy_Tree (Old_Hi);
1146 end if;
1148 Append (Make_Range (Loc, Lo, Hi), Constraints);
1149 Next_Index (Indx);
1150 end loop;
1152 return Constraints;
1153 end Build_Discriminal_Array_Constraint;
1155 -----------------------------------------
1156 -- Build_Discriminal_Record_Constraint --
1157 -----------------------------------------
1159 function Build_Discriminal_Record_Constraint return List_Id is
1160 Constraints : constant List_Id := New_List;
1161 D : Elmt_Id;
1162 D_Val : Node_Id;
1164 begin
1165 D := First_Elmt (Discriminant_Constraint (T));
1166 while Present (D) loop
1167 if Denotes_Discriminant (Node (D)) then
1168 D_Val :=
1169 New_Occurrence_Of (Discriminal (Entity (Node (D))), Loc);
1171 else
1172 D_Val := New_Copy_Tree (Node (D));
1173 end if;
1175 Append (D_Val, Constraints);
1176 Next_Elmt (D);
1177 end loop;
1179 return Constraints;
1180 end Build_Discriminal_Record_Constraint;
1182 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1184 begin
1185 if Ekind (T) = E_Array_Subtype then
1186 Id := First_Index (T);
1187 while Present (Id) loop
1188 if Denotes_Discriminant (Type_Low_Bound (Etype (Id))) or else
1189 Denotes_Discriminant (Type_High_Bound (Etype (Id)))
1190 then
1191 return Build_Component_Subtype
1192 (Build_Discriminal_Array_Constraint, Loc, T);
1193 end if;
1195 Next_Index (Id);
1196 end loop;
1198 elsif Ekind (T) = E_Record_Subtype
1199 and then Has_Discriminants (T)
1200 and then not Has_Unknown_Discriminants (T)
1201 then
1202 D := First_Elmt (Discriminant_Constraint (T));
1203 while Present (D) loop
1204 if Denotes_Discriminant (Node (D)) then
1205 return Build_Component_Subtype
1206 (Build_Discriminal_Record_Constraint, Loc, T);
1207 end if;
1209 Next_Elmt (D);
1210 end loop;
1211 end if;
1213 -- If none of the above, the actual and nominal subtypes are the same
1215 return Empty;
1216 end Build_Discriminal_Subtype_Of_Component;
1218 ------------------------------
1219 -- Build_Elaboration_Entity --
1220 ------------------------------
1222 procedure Build_Elaboration_Entity (N : Node_Id; Spec_Id : Entity_Id) is
1223 Loc : constant Source_Ptr := Sloc (N);
1224 Decl : Node_Id;
1225 Elab_Ent : Entity_Id;
1227 procedure Set_Package_Name (Ent : Entity_Id);
1228 -- Given an entity, sets the fully qualified name of the entity in
1229 -- Name_Buffer, with components separated by double underscores. This
1230 -- is a recursive routine that climbs the scope chain to Standard.
1232 ----------------------
1233 -- Set_Package_Name --
1234 ----------------------
1236 procedure Set_Package_Name (Ent : Entity_Id) is
1237 begin
1238 if Scope (Ent) /= Standard_Standard then
1239 Set_Package_Name (Scope (Ent));
1241 declare
1242 Nam : constant String := Get_Name_String (Chars (Ent));
1243 begin
1244 Name_Buffer (Name_Len + 1) := '_';
1245 Name_Buffer (Name_Len + 2) := '_';
1246 Name_Buffer (Name_Len + 3 .. Name_Len + Nam'Length + 2) := Nam;
1247 Name_Len := Name_Len + Nam'Length + 2;
1248 end;
1250 else
1251 Get_Name_String (Chars (Ent));
1252 end if;
1253 end Set_Package_Name;
1255 -- Start of processing for Build_Elaboration_Entity
1257 begin
1258 -- Ignore if already constructed
1260 if Present (Elaboration_Entity (Spec_Id)) then
1261 return;
1262 end if;
1264 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1265 -- no role in analysis.
1267 if ASIS_Mode then
1268 return;
1269 end if;
1271 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1272 -- name with dots replaced by double underscore. We have to manually
1273 -- construct this name, since it will be elaborated in the outer scope,
1274 -- and thus will not have the unit name automatically prepended.
1276 Set_Package_Name (Spec_Id);
1277 Add_Str_To_Name_Buffer ("_E");
1279 -- Create elaboration counter
1281 Elab_Ent := Make_Defining_Identifier (Loc, Chars => Name_Find);
1282 Set_Elaboration_Entity (Spec_Id, Elab_Ent);
1284 Decl :=
1285 Make_Object_Declaration (Loc,
1286 Defining_Identifier => Elab_Ent,
1287 Object_Definition =>
1288 New_Occurrence_Of (Standard_Short_Integer, Loc),
1289 Expression => Make_Integer_Literal (Loc, Uint_0));
1291 Push_Scope (Standard_Standard);
1292 Add_Global_Declaration (Decl);
1293 Pop_Scope;
1295 -- Reset True_Constant indication, since we will indeed assign a value
1296 -- to the variable in the binder main. We also kill the Current_Value
1297 -- and Last_Assignment fields for the same reason.
1299 Set_Is_True_Constant (Elab_Ent, False);
1300 Set_Current_Value (Elab_Ent, Empty);
1301 Set_Last_Assignment (Elab_Ent, Empty);
1303 -- We do not want any further qualification of the name (if we did not
1304 -- do this, we would pick up the name of the generic package in the case
1305 -- of a library level generic instantiation).
1307 Set_Has_Qualified_Name (Elab_Ent);
1308 Set_Has_Fully_Qualified_Name (Elab_Ent);
1309 end Build_Elaboration_Entity;
1311 --------------------------------
1312 -- Build_Explicit_Dereference --
1313 --------------------------------
1315 procedure Build_Explicit_Dereference
1316 (Expr : Node_Id;
1317 Disc : Entity_Id)
1319 Loc : constant Source_Ptr := Sloc (Expr);
1320 begin
1322 -- An entity of a type with a reference aspect is overloaded with
1323 -- both interpretations: with and without the dereference. Now that
1324 -- the dereference is made explicit, set the type of the node properly,
1325 -- to prevent anomalies in the backend. Same if the expression is an
1326 -- overloaded function call whose return type has a reference aspect.
1328 if Is_Entity_Name (Expr) then
1329 Set_Etype (Expr, Etype (Entity (Expr)));
1331 elsif Nkind (Expr) = N_Function_Call then
1332 Set_Etype (Expr, Etype (Name (Expr)));
1333 end if;
1335 Set_Is_Overloaded (Expr, False);
1336 Rewrite (Expr,
1337 Make_Explicit_Dereference (Loc,
1338 Prefix =>
1339 Make_Selected_Component (Loc,
1340 Prefix => Relocate_Node (Expr),
1341 Selector_Name => New_Occurrence_Of (Disc, Loc))));
1342 Set_Etype (Prefix (Expr), Etype (Disc));
1343 Set_Etype (Expr, Designated_Type (Etype (Disc)));
1344 end Build_Explicit_Dereference;
1346 -----------------------------------
1347 -- Cannot_Raise_Constraint_Error --
1348 -----------------------------------
1350 function Cannot_Raise_Constraint_Error (Expr : Node_Id) return Boolean is
1351 begin
1352 if Compile_Time_Known_Value (Expr) then
1353 return True;
1355 elsif Do_Range_Check (Expr) then
1356 return False;
1358 elsif Raises_Constraint_Error (Expr) then
1359 return False;
1361 else
1362 case Nkind (Expr) is
1363 when N_Identifier =>
1364 return True;
1366 when N_Expanded_Name =>
1367 return True;
1369 when N_Selected_Component =>
1370 return not Do_Discriminant_Check (Expr);
1372 when N_Attribute_Reference =>
1373 if Do_Overflow_Check (Expr) then
1374 return False;
1376 elsif No (Expressions (Expr)) then
1377 return True;
1379 else
1380 declare
1381 N : Node_Id;
1383 begin
1384 N := First (Expressions (Expr));
1385 while Present (N) loop
1386 if Cannot_Raise_Constraint_Error (N) then
1387 Next (N);
1388 else
1389 return False;
1390 end if;
1391 end loop;
1393 return True;
1394 end;
1395 end if;
1397 when N_Type_Conversion =>
1398 if Do_Overflow_Check (Expr)
1399 or else Do_Length_Check (Expr)
1400 or else Do_Tag_Check (Expr)
1401 then
1402 return False;
1403 else
1404 return Cannot_Raise_Constraint_Error (Expression (Expr));
1405 end if;
1407 when N_Unchecked_Type_Conversion =>
1408 return Cannot_Raise_Constraint_Error (Expression (Expr));
1410 when N_Unary_Op =>
1411 if Do_Overflow_Check (Expr) then
1412 return False;
1413 else
1414 return Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1415 end if;
1417 when N_Op_Divide |
1418 N_Op_Mod |
1419 N_Op_Rem
1421 if Do_Division_Check (Expr)
1422 or else Do_Overflow_Check (Expr)
1423 then
1424 return False;
1425 else
1426 return
1427 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1428 and then
1429 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1430 end if;
1432 when N_Op_Add |
1433 N_Op_And |
1434 N_Op_Concat |
1435 N_Op_Eq |
1436 N_Op_Expon |
1437 N_Op_Ge |
1438 N_Op_Gt |
1439 N_Op_Le |
1440 N_Op_Lt |
1441 N_Op_Multiply |
1442 N_Op_Ne |
1443 N_Op_Or |
1444 N_Op_Rotate_Left |
1445 N_Op_Rotate_Right |
1446 N_Op_Shift_Left |
1447 N_Op_Shift_Right |
1448 N_Op_Shift_Right_Arithmetic |
1449 N_Op_Subtract |
1450 N_Op_Xor
1452 if Do_Overflow_Check (Expr) then
1453 return False;
1454 else
1455 return
1456 Cannot_Raise_Constraint_Error (Left_Opnd (Expr))
1457 and then
1458 Cannot_Raise_Constraint_Error (Right_Opnd (Expr));
1459 end if;
1461 when others =>
1462 return False;
1463 end case;
1464 end if;
1465 end Cannot_Raise_Constraint_Error;
1467 -----------------------------------------
1468 -- Check_Dynamically_Tagged_Expression --
1469 -----------------------------------------
1471 procedure Check_Dynamically_Tagged_Expression
1472 (Expr : Node_Id;
1473 Typ : Entity_Id;
1474 Related_Nod : Node_Id)
1476 begin
1477 pragma Assert (Is_Tagged_Type (Typ));
1479 -- In order to avoid spurious errors when analyzing the expanded code,
1480 -- this check is done only for nodes that come from source and for
1481 -- actuals of generic instantiations.
1483 if (Comes_From_Source (Related_Nod)
1484 or else In_Generic_Actual (Expr))
1485 and then (Is_Class_Wide_Type (Etype (Expr))
1486 or else Is_Dynamically_Tagged (Expr))
1487 and then Is_Tagged_Type (Typ)
1488 and then not Is_Class_Wide_Type (Typ)
1489 then
1490 Error_Msg_N ("dynamically tagged expression not allowed!", Expr);
1491 end if;
1492 end Check_Dynamically_Tagged_Expression;
1494 -----------------------------------------------
1495 -- Check_Expression_Against_Static_Predicate --
1496 -----------------------------------------------
1498 procedure Check_Expression_Against_Static_Predicate
1499 (Expr : Node_Id;
1500 Typ : Entity_Id)
1502 begin
1503 -- When the predicate is static and the value of the expression is known
1504 -- at compile time, evaluate the predicate check. A type is non-static
1505 -- when it has aspect Dynamic_Predicate.
1507 if Compile_Time_Known_Value (Expr)
1508 and then Has_Predicates (Typ)
1509 and then Present (Static_Predicate (Typ))
1510 and then not Has_Dynamic_Predicate_Aspect (Typ)
1511 then
1512 -- Either -gnatc is enabled or the expression is ok
1514 if Operating_Mode < Generate_Code
1515 or else Eval_Static_Predicate_Check (Expr, Typ)
1516 then
1517 null;
1519 -- The expression is prohibited by the static predicate
1521 else
1522 Error_Msg_NE
1523 ("?static expression fails static predicate check on &",
1524 Expr, Typ);
1525 end if;
1526 end if;
1527 end Check_Expression_Against_Static_Predicate;
1529 --------------------------
1530 -- Check_Fully_Declared --
1531 --------------------------
1533 procedure Check_Fully_Declared (T : Entity_Id; N : Node_Id) is
1534 begin
1535 if Ekind (T) = E_Incomplete_Type then
1537 -- Ada 2005 (AI-50217): If the type is available through a limited
1538 -- with_clause, verify that its full view has been analyzed.
1540 if From_Limited_With (T)
1541 and then Present (Non_Limited_View (T))
1542 and then Ekind (Non_Limited_View (T)) /= E_Incomplete_Type
1543 then
1544 -- The non-limited view is fully declared
1545 null;
1547 else
1548 Error_Msg_NE
1549 ("premature usage of incomplete}", N, First_Subtype (T));
1550 end if;
1552 -- Need comments for these tests ???
1554 elsif Has_Private_Component (T)
1555 and then not Is_Generic_Type (Root_Type (T))
1556 and then not In_Spec_Expression
1557 then
1558 -- Special case: if T is the anonymous type created for a single
1559 -- task or protected object, use the name of the source object.
1561 if Is_Concurrent_Type (T)
1562 and then not Comes_From_Source (T)
1563 and then Nkind (N) = N_Object_Declaration
1564 then
1565 Error_Msg_NE ("type of& has incomplete component", N,
1566 Defining_Identifier (N));
1568 else
1569 Error_Msg_NE
1570 ("premature usage of incomplete}", N, First_Subtype (T));
1571 end if;
1572 end if;
1573 end Check_Fully_Declared;
1575 -------------------------------------
1576 -- Check_Function_Writable_Actuals --
1577 -------------------------------------
1579 procedure Check_Function_Writable_Actuals (N : Node_Id) is
1580 Writable_Actuals_List : Elist_Id := No_Elist;
1581 Identifiers_List : Elist_Id := No_Elist;
1582 Error_Node : Node_Id := Empty;
1584 procedure Collect_Identifiers (N : Node_Id);
1585 -- In a single traversal of subtree N collect in Writable_Actuals_List
1586 -- all the actuals of functions with writable actuals, and in the list
1587 -- Identifiers_List collect all the identifiers that are not actuals of
1588 -- functions with writable actuals. If a writable actual is referenced
1589 -- twice as writable actual then Error_Node is set to reference its
1590 -- second occurrence, the error is reported, and the tree traversal
1591 -- is abandoned.
1593 function Get_Function_Id (Call : Node_Id) return Entity_Id;
1594 -- Return the entity associated with the function call
1596 procedure Preanalyze_Without_Errors (N : Node_Id);
1597 -- Preanalyze N without reporting errors. Very dubious, you can't just
1598 -- go analyzing things more than once???
1600 -------------------------
1601 -- Collect_Identifiers --
1602 -------------------------
1604 procedure Collect_Identifiers (N : Node_Id) is
1606 function Check_Node (N : Node_Id) return Traverse_Result;
1607 -- Process a single node during the tree traversal to collect the
1608 -- writable actuals of functions and all the identifiers which are
1609 -- not writable actuals of functions.
1611 function Contains (List : Elist_Id; N : Node_Id) return Boolean;
1612 -- Returns True if List has a node whose Entity is Entity (N)
1614 -------------------------
1615 -- Check_Function_Call --
1616 -------------------------
1618 function Check_Node (N : Node_Id) return Traverse_Result is
1619 Is_Writable_Actual : Boolean := False;
1620 Id : Entity_Id;
1622 begin
1623 if Nkind (N) = N_Identifier then
1625 -- No analysis possible if the entity is not decorated
1627 if No (Entity (N)) then
1628 return Skip;
1630 -- Don't collect identifiers of packages, called functions, etc
1632 elsif Ekind_In (Entity (N), E_Package,
1633 E_Function,
1634 E_Procedure,
1635 E_Entry)
1636 then
1637 return Skip;
1639 -- Analyze if N is a writable actual of a function
1641 elsif Nkind (Parent (N)) = N_Function_Call then
1642 declare
1643 Call : constant Node_Id := Parent (N);
1644 Actual : Node_Id;
1645 Formal : Node_Id;
1647 begin
1648 Id := Get_Function_Id (Call);
1650 Formal := First_Formal (Id);
1651 Actual := First_Actual (Call);
1652 while Present (Actual) and then Present (Formal) loop
1653 if Actual = N then
1654 if Ekind_In (Formal, E_Out_Parameter,
1655 E_In_Out_Parameter)
1656 then
1657 Is_Writable_Actual := True;
1658 end if;
1660 exit;
1661 end if;
1663 Next_Formal (Formal);
1664 Next_Actual (Actual);
1665 end loop;
1666 end;
1667 end if;
1669 if Is_Writable_Actual then
1670 if Contains (Writable_Actuals_List, N) then
1671 Error_Msg_NE
1672 ("value may be affected by call to& "
1673 & "because order of evaluation is arbitrary", N, Id);
1674 Error_Node := N;
1675 return Abandon;
1676 end if;
1678 if Writable_Actuals_List = No_Elist then
1679 Writable_Actuals_List := New_Elmt_List;
1680 end if;
1682 Append_Elmt (N, Writable_Actuals_List);
1683 else
1684 if Identifiers_List = No_Elist then
1685 Identifiers_List := New_Elmt_List;
1686 end if;
1688 Append_Unique_Elmt (N, Identifiers_List);
1689 end if;
1690 end if;
1692 return OK;
1693 end Check_Node;
1695 --------------
1696 -- Contains --
1697 --------------
1699 function Contains
1700 (List : Elist_Id;
1701 N : Node_Id) return Boolean
1703 pragma Assert (Nkind (N) in N_Has_Entity);
1705 Elmt : Elmt_Id;
1707 begin
1708 if List = No_Elist then
1709 return False;
1710 end if;
1712 Elmt := First_Elmt (List);
1713 while Present (Elmt) loop
1714 if Entity (Node (Elmt)) = Entity (N) then
1715 return True;
1716 else
1717 Next_Elmt (Elmt);
1718 end if;
1719 end loop;
1721 return False;
1722 end Contains;
1724 ------------------
1725 -- Do_Traversal --
1726 ------------------
1728 procedure Do_Traversal is new Traverse_Proc (Check_Node);
1729 -- The traversal procedure
1731 -- Start of processing for Collect_Identifiers
1733 begin
1734 if Present (Error_Node) then
1735 return;
1736 end if;
1738 if Nkind (N) in N_Subexpr
1739 and then Is_Static_Expression (N)
1740 then
1741 return;
1742 end if;
1744 Do_Traversal (N);
1745 end Collect_Identifiers;
1747 ---------------------
1748 -- Get_Function_Id --
1749 ---------------------
1751 function Get_Function_Id (Call : Node_Id) return Entity_Id is
1752 Nam : constant Node_Id := Name (Call);
1753 Id : Entity_Id;
1755 begin
1756 if Nkind (Nam) = N_Explicit_Dereference then
1757 Id := Etype (Nam);
1758 pragma Assert (Ekind (Id) = E_Subprogram_Type);
1760 elsif Nkind (Nam) = N_Selected_Component then
1761 Id := Entity (Selector_Name (Nam));
1763 elsif Nkind (Nam) = N_Indexed_Component then
1764 Id := Entity (Selector_Name (Prefix (Nam)));
1766 else
1767 Id := Entity (Nam);
1768 end if;
1770 return Id;
1771 end Get_Function_Id;
1773 ---------------------------
1774 -- Preanalyze_Expression --
1775 ---------------------------
1777 procedure Preanalyze_Without_Errors (N : Node_Id) is
1778 Status : constant Boolean := Get_Ignore_Errors;
1779 begin
1780 Set_Ignore_Errors (True);
1781 Preanalyze (N);
1782 Set_Ignore_Errors (Status);
1783 end Preanalyze_Without_Errors;
1785 -- Start of processing for Check_Function_Writable_Actuals
1787 begin
1788 -- The check only applies to Ada 2012 code, and only to constructs that
1789 -- have multiple constituents whose order of evaluation is not specified
1790 -- by the language.
1792 if Ada_Version < Ada_2012
1793 or else (not (Nkind (N) in N_Op)
1794 and then not (Nkind (N) in N_Membership_Test)
1795 and then not Nkind_In (N, N_Range,
1796 N_Aggregate,
1797 N_Extension_Aggregate,
1798 N_Full_Type_Declaration,
1799 N_Function_Call,
1800 N_Procedure_Call_Statement,
1801 N_Entry_Call_Statement))
1802 or else (Nkind (N) = N_Full_Type_Declaration
1803 and then not Is_Record_Type (Defining_Identifier (N)))
1805 -- In addition, this check only applies to source code, not to code
1806 -- generated by constraint checks.
1808 or else not Comes_From_Source (N)
1809 then
1810 return;
1811 end if;
1813 -- If a construct C has two or more direct constituents that are names
1814 -- or expressions whose evaluation may occur in an arbitrary order, at
1815 -- least one of which contains a function call with an in out or out
1816 -- parameter, then the construct is legal only if: for each name N that
1817 -- is passed as a parameter of mode in out or out to some inner function
1818 -- call C2 (not including the construct C itself), there is no other
1819 -- name anywhere within a direct constituent of the construct C other
1820 -- than the one containing C2, that is known to refer to the same
1821 -- object (RM 6.4.1(6.17/3)).
1823 case Nkind (N) is
1824 when N_Range =>
1825 Collect_Identifiers (Low_Bound (N));
1826 Collect_Identifiers (High_Bound (N));
1828 when N_Op | N_Membership_Test =>
1829 declare
1830 Expr : Node_Id;
1831 begin
1832 Collect_Identifiers (Left_Opnd (N));
1834 if Present (Right_Opnd (N)) then
1835 Collect_Identifiers (Right_Opnd (N));
1836 end if;
1838 if Nkind_In (N, N_In, N_Not_In)
1839 and then Present (Alternatives (N))
1840 then
1841 Expr := First (Alternatives (N));
1842 while Present (Expr) loop
1843 Collect_Identifiers (Expr);
1845 Next (Expr);
1846 end loop;
1847 end if;
1848 end;
1850 when N_Full_Type_Declaration =>
1851 declare
1852 function Get_Record_Part (N : Node_Id) return Node_Id;
1853 -- Return the record part of this record type definition
1855 function Get_Record_Part (N : Node_Id) return Node_Id is
1856 Type_Def : constant Node_Id := Type_Definition (N);
1857 begin
1858 if Nkind (Type_Def) = N_Derived_Type_Definition then
1859 return Record_Extension_Part (Type_Def);
1860 else
1861 return Type_Def;
1862 end if;
1863 end Get_Record_Part;
1865 Comp : Node_Id;
1866 Def_Id : Entity_Id := Defining_Identifier (N);
1867 Rec : Node_Id := Get_Record_Part (N);
1869 begin
1870 -- No need to perform any analysis if the record has no
1871 -- components
1873 if No (Rec) or else No (Component_List (Rec)) then
1874 return;
1875 end if;
1877 -- Collect the identifiers starting from the deepest
1878 -- derivation. Done to report the error in the deepest
1879 -- derivation.
1881 loop
1882 if Present (Component_List (Rec)) then
1883 Comp := First (Component_Items (Component_List (Rec)));
1884 while Present (Comp) loop
1885 if Nkind (Comp) = N_Component_Declaration
1886 and then Present (Expression (Comp))
1887 then
1888 Collect_Identifiers (Expression (Comp));
1889 end if;
1891 Next (Comp);
1892 end loop;
1893 end if;
1895 exit when No (Underlying_Type (Etype (Def_Id)))
1896 or else Base_Type (Underlying_Type (Etype (Def_Id)))
1897 = Def_Id;
1899 Def_Id := Base_Type (Underlying_Type (Etype (Def_Id)));
1900 Rec := Get_Record_Part (Parent (Def_Id));
1901 end loop;
1902 end;
1904 when N_Subprogram_Call |
1905 N_Entry_Call_Statement =>
1906 declare
1907 Id : constant Entity_Id := Get_Function_Id (N);
1908 Formal : Node_Id;
1909 Actual : Node_Id;
1911 begin
1912 Formal := First_Formal (Id);
1913 Actual := First_Actual (N);
1914 while Present (Actual) and then Present (Formal) loop
1915 if Ekind_In (Formal, E_Out_Parameter,
1916 E_In_Out_Parameter)
1917 then
1918 Collect_Identifiers (Actual);
1919 end if;
1921 Next_Formal (Formal);
1922 Next_Actual (Actual);
1923 end loop;
1924 end;
1926 when N_Aggregate |
1927 N_Extension_Aggregate =>
1928 declare
1929 Assoc : Node_Id;
1930 Choice : Node_Id;
1931 Comp_Expr : Node_Id;
1933 begin
1934 -- Handle the N_Others_Choice of array aggregates with static
1935 -- bounds. There is no need to perform this analysis in
1936 -- aggregates without static bounds since we cannot evaluate
1937 -- if the N_Others_Choice covers several elements. There is
1938 -- no need to handle the N_Others choice of record aggregates
1939 -- since at this stage it has been already expanded by
1940 -- Resolve_Record_Aggregate.
1942 if Is_Array_Type (Etype (N))
1943 and then Nkind (N) = N_Aggregate
1944 and then Present (Aggregate_Bounds (N))
1945 and then Compile_Time_Known_Bounds (Etype (N))
1946 and then Expr_Value (High_Bound (Aggregate_Bounds (N)))
1947 > Expr_Value (Low_Bound (Aggregate_Bounds (N)))
1948 then
1949 declare
1950 Count_Components : Uint := Uint_0;
1951 Num_Components : Uint;
1952 Others_Assoc : Node_Id;
1953 Others_Choice : Node_Id := Empty;
1954 Others_Box_Present : Boolean := False;
1956 begin
1957 -- Count positional associations
1959 if Present (Expressions (N)) then
1960 Comp_Expr := First (Expressions (N));
1961 while Present (Comp_Expr) loop
1962 Count_Components := Count_Components + 1;
1963 Next (Comp_Expr);
1964 end loop;
1965 end if;
1967 -- Count the rest of elements and locate the N_Others
1968 -- choice (if any)
1970 Assoc := First (Component_Associations (N));
1971 while Present (Assoc) loop
1972 Choice := First (Choices (Assoc));
1973 while Present (Choice) loop
1974 if Nkind (Choice) = N_Others_Choice then
1975 Others_Assoc := Assoc;
1976 Others_Choice := Choice;
1977 Others_Box_Present := Box_Present (Assoc);
1979 -- Count several components
1981 elsif Nkind_In (Choice, N_Range,
1982 N_Subtype_Indication)
1983 or else (Is_Entity_Name (Choice)
1984 and then Is_Type (Entity (Choice)))
1985 then
1986 declare
1987 L, H : Node_Id;
1988 begin
1989 Get_Index_Bounds (Choice, L, H);
1990 pragma Assert
1991 (Compile_Time_Known_Value (L)
1992 and then Compile_Time_Known_Value (H));
1993 Count_Components :=
1994 Count_Components
1995 + Expr_Value (H) - Expr_Value (L) + 1;
1996 end;
1998 -- Count single component. No other case available
1999 -- since we are handling an aggregate with static
2000 -- bounds.
2002 else
2003 pragma Assert (Is_Static_Expression (Choice)
2004 or else Nkind (Choice) = N_Identifier
2005 or else Nkind (Choice) = N_Integer_Literal);
2007 Count_Components := Count_Components + 1;
2008 end if;
2010 Next (Choice);
2011 end loop;
2013 Next (Assoc);
2014 end loop;
2016 Num_Components :=
2017 Expr_Value (High_Bound (Aggregate_Bounds (N))) -
2018 Expr_Value (Low_Bound (Aggregate_Bounds (N))) + 1;
2020 pragma Assert (Count_Components <= Num_Components);
2022 -- Handle the N_Others choice if it covers several
2023 -- components
2025 if Present (Others_Choice)
2026 and then (Num_Components - Count_Components) > 1
2027 then
2028 if not Others_Box_Present then
2030 -- At this stage, if expansion is active, the
2031 -- expression of the others choice has not been
2032 -- analyzed. Hence we generate a duplicate and
2033 -- we analyze it silently to have available the
2034 -- minimum decoration required to collect the
2035 -- identifiers.
2037 if not Expander_Active then
2038 Comp_Expr := Expression (Others_Assoc);
2039 else
2040 Comp_Expr :=
2041 New_Copy_Tree (Expression (Others_Assoc));
2042 Preanalyze_Without_Errors (Comp_Expr);
2043 end if;
2045 Collect_Identifiers (Comp_Expr);
2047 if Writable_Actuals_List /= No_Elist then
2049 -- As suggested by Robert, at current stage we
2050 -- report occurrences of this case as warnings.
2052 Error_Msg_N
2053 ("writable function parameter may affect "
2054 & "value in other component because order "
2055 & "of evaluation is unspecified?",
2056 Node (First_Elmt (Writable_Actuals_List)));
2057 end if;
2058 end if;
2059 end if;
2060 end;
2061 end if;
2063 -- Handle ancestor part of extension aggregates
2065 if Nkind (N) = N_Extension_Aggregate then
2066 Collect_Identifiers (Ancestor_Part (N));
2067 end if;
2069 -- Handle positional associations
2071 if Present (Expressions (N)) then
2072 Comp_Expr := First (Expressions (N));
2073 while Present (Comp_Expr) loop
2074 if not Is_Static_Expression (Comp_Expr) then
2075 Collect_Identifiers (Comp_Expr);
2076 end if;
2078 Next (Comp_Expr);
2079 end loop;
2080 end if;
2082 -- Handle discrete associations
2084 if Present (Component_Associations (N)) then
2085 Assoc := First (Component_Associations (N));
2086 while Present (Assoc) loop
2088 if not Box_Present (Assoc) then
2089 Choice := First (Choices (Assoc));
2090 while Present (Choice) loop
2092 -- For now we skip discriminants since it requires
2093 -- performing the analysis in two phases: first one
2094 -- analyzing discriminants and second one analyzing
2095 -- the rest of components since discriminants are
2096 -- evaluated prior to components: too much extra
2097 -- work to detect a corner case???
2099 if Nkind (Choice) in N_Has_Entity
2100 and then Present (Entity (Choice))
2101 and then Ekind (Entity (Choice)) = E_Discriminant
2102 then
2103 null;
2105 elsif Box_Present (Assoc) then
2106 null;
2108 else
2109 if not Analyzed (Expression (Assoc)) then
2110 Comp_Expr :=
2111 New_Copy_Tree (Expression (Assoc));
2112 Set_Parent (Comp_Expr, Parent (N));
2113 Preanalyze_Without_Errors (Comp_Expr);
2114 else
2115 Comp_Expr := Expression (Assoc);
2116 end if;
2118 Collect_Identifiers (Comp_Expr);
2119 end if;
2121 Next (Choice);
2122 end loop;
2123 end if;
2125 Next (Assoc);
2126 end loop;
2127 end if;
2128 end;
2130 when others =>
2131 return;
2132 end case;
2134 -- No further action needed if we already reported an error
2136 if Present (Error_Node) then
2137 return;
2138 end if;
2140 -- Check if some writable argument of a function is referenced
2142 if Writable_Actuals_List /= No_Elist
2143 and then Identifiers_List /= No_Elist
2144 then
2145 declare
2146 Elmt_1 : Elmt_Id;
2147 Elmt_2 : Elmt_Id;
2149 begin
2150 Elmt_1 := First_Elmt (Writable_Actuals_List);
2151 while Present (Elmt_1) loop
2152 Elmt_2 := First_Elmt (Identifiers_List);
2153 while Present (Elmt_2) loop
2154 if Entity (Node (Elmt_1)) = Entity (Node (Elmt_2)) then
2155 case Nkind (Parent (Node (Elmt_2))) is
2156 when N_Aggregate |
2157 N_Component_Association |
2158 N_Component_Declaration =>
2159 Error_Msg_N
2160 ("value may be affected by call in other "
2161 & "component because they are evaluated "
2162 & "in unspecified order",
2163 Node (Elmt_2));
2165 when N_In | N_Not_In =>
2166 Error_Msg_N
2167 ("value may be affected by call in other "
2168 & "alternative because they are evaluated "
2169 & "in unspecified order",
2170 Node (Elmt_2));
2172 when others =>
2173 Error_Msg_N
2174 ("value of actual may be affected by call in "
2175 & "other actual because they are evaluated "
2176 & "in unspecified order",
2177 Node (Elmt_2));
2178 end case;
2179 end if;
2181 Next_Elmt (Elmt_2);
2182 end loop;
2184 Next_Elmt (Elmt_1);
2185 end loop;
2186 end;
2187 end if;
2188 end Check_Function_Writable_Actuals;
2190 --------------------------------
2191 -- Check_Implicit_Dereference --
2192 --------------------------------
2194 procedure Check_Implicit_Dereference (Nam : Node_Id; Typ : Entity_Id) is
2195 Disc : Entity_Id;
2196 Desig : Entity_Id;
2198 begin
2199 if Ada_Version < Ada_2012
2200 or else not Has_Implicit_Dereference (Base_Type (Typ))
2201 then
2202 return;
2204 elsif not Comes_From_Source (Nam) then
2205 return;
2207 elsif Is_Entity_Name (Nam)
2208 and then Is_Type (Entity (Nam))
2209 then
2210 null;
2212 else
2213 Disc := First_Discriminant (Typ);
2214 while Present (Disc) loop
2215 if Has_Implicit_Dereference (Disc) then
2216 Desig := Designated_Type (Etype (Disc));
2217 Add_One_Interp (Nam, Disc, Desig);
2218 exit;
2219 end if;
2221 Next_Discriminant (Disc);
2222 end loop;
2223 end if;
2224 end Check_Implicit_Dereference;
2226 ----------------------------------
2227 -- Check_Internal_Protected_Use --
2228 ----------------------------------
2230 procedure Check_Internal_Protected_Use (N : Node_Id; Nam : Entity_Id) is
2231 S : Entity_Id;
2232 Prot : Entity_Id;
2234 begin
2235 S := Current_Scope;
2236 while Present (S) loop
2237 if S = Standard_Standard then
2238 return;
2240 elsif Ekind (S) = E_Function
2241 and then Ekind (Scope (S)) = E_Protected_Type
2242 then
2243 Prot := Scope (S);
2244 exit;
2245 end if;
2247 S := Scope (S);
2248 end loop;
2250 if Scope (Nam) = Prot and then Ekind (Nam) /= E_Function then
2252 -- An indirect function call (e.g. a callback within a protected
2253 -- function body) is not statically illegal. If the access type is
2254 -- anonymous and is the type of an access parameter, the scope of Nam
2255 -- will be the protected type, but it is not a protected operation.
2257 if Ekind (Nam) = E_Subprogram_Type
2258 and then
2259 Nkind (Associated_Node_For_Itype (Nam)) = N_Function_Specification
2260 then
2261 null;
2263 elsif Nkind (N) = N_Subprogram_Renaming_Declaration then
2264 Error_Msg_N
2265 ("within protected function cannot use protected "
2266 & "procedure in renaming or as generic actual", N);
2268 elsif Nkind (N) = N_Attribute_Reference then
2269 Error_Msg_N
2270 ("within protected function cannot take access of "
2271 & " protected procedure", N);
2273 else
2274 Error_Msg_N
2275 ("within protected function, protected object is constant", N);
2276 Error_Msg_N
2277 ("\cannot call operation that may modify it", N);
2278 end if;
2279 end if;
2280 end Check_Internal_Protected_Use;
2282 ---------------------------------------
2283 -- Check_Later_Vs_Basic_Declarations --
2284 ---------------------------------------
2286 procedure Check_Later_Vs_Basic_Declarations
2287 (Decls : List_Id;
2288 During_Parsing : Boolean)
2290 Body_Sloc : Source_Ptr;
2291 Decl : Node_Id;
2293 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean;
2294 -- Return whether Decl is considered as a declarative item.
2295 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2296 -- When During_Parsing is False, the semantics of SPARK is followed.
2298 -------------------------------
2299 -- Is_Later_Declarative_Item --
2300 -------------------------------
2302 function Is_Later_Declarative_Item (Decl : Node_Id) return Boolean is
2303 begin
2304 if Nkind (Decl) in N_Later_Decl_Item then
2305 return True;
2307 elsif Nkind (Decl) = N_Pragma then
2308 return True;
2310 elsif During_Parsing then
2311 return False;
2313 -- In SPARK, a package declaration is not considered as a later
2314 -- declarative item.
2316 elsif Nkind (Decl) = N_Package_Declaration then
2317 return False;
2319 -- In SPARK, a renaming is considered as a later declarative item
2321 elsif Nkind (Decl) in N_Renaming_Declaration then
2322 return True;
2324 else
2325 return False;
2326 end if;
2327 end Is_Later_Declarative_Item;
2329 -- Start of Check_Later_Vs_Basic_Declarations
2331 begin
2332 Decl := First (Decls);
2334 -- Loop through sequence of basic declarative items
2336 Outer : while Present (Decl) loop
2337 if not Nkind_In (Decl, N_Subprogram_Body, N_Package_Body, N_Task_Body)
2338 and then Nkind (Decl) not in N_Body_Stub
2339 then
2340 Next (Decl);
2342 -- Once a body is encountered, we only allow later declarative
2343 -- items. The inner loop checks the rest of the list.
2345 else
2346 Body_Sloc := Sloc (Decl);
2348 Inner : while Present (Decl) loop
2349 if not Is_Later_Declarative_Item (Decl) then
2350 if During_Parsing then
2351 if Ada_Version = Ada_83 then
2352 Error_Msg_Sloc := Body_Sloc;
2353 Error_Msg_N
2354 ("(Ada 83) decl cannot appear after body#", Decl);
2355 end if;
2356 else
2357 Error_Msg_Sloc := Body_Sloc;
2358 Check_SPARK_Restriction
2359 ("decl cannot appear after body#", Decl);
2360 end if;
2361 end if;
2363 Next (Decl);
2364 end loop Inner;
2365 end if;
2366 end loop Outer;
2367 end Check_Later_Vs_Basic_Declarations;
2369 -------------------------
2370 -- Check_Nested_Access --
2371 -------------------------
2373 procedure Check_Nested_Access (Ent : Entity_Id) is
2374 Scop : constant Entity_Id := Current_Scope;
2375 Current_Subp : Entity_Id;
2376 Enclosing : Entity_Id;
2378 begin
2379 -- Currently only enabled for VM back-ends for efficiency, should we
2380 -- enable it more systematically ???
2382 -- Check for Is_Imported needs commenting below ???
2384 if VM_Target /= No_VM
2385 and then (Ekind (Ent) = E_Variable
2386 or else
2387 Ekind (Ent) = E_Constant
2388 or else
2389 Ekind (Ent) = E_Loop_Parameter)
2390 and then Scope (Ent) /= Empty
2391 and then not Is_Library_Level_Entity (Ent)
2392 and then not Is_Imported (Ent)
2393 then
2394 if Is_Subprogram (Scop)
2395 or else Is_Generic_Subprogram (Scop)
2396 or else Is_Entry (Scop)
2397 then
2398 Current_Subp := Scop;
2399 else
2400 Current_Subp := Current_Subprogram;
2401 end if;
2403 Enclosing := Enclosing_Subprogram (Ent);
2405 if Enclosing /= Empty
2406 and then Enclosing /= Current_Subp
2407 then
2408 Set_Has_Up_Level_Access (Ent, True);
2409 end if;
2410 end if;
2411 end Check_Nested_Access;
2413 ---------------------------
2414 -- Check_No_Hidden_State --
2415 ---------------------------
2417 procedure Check_No_Hidden_State (Id : Entity_Id) is
2418 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean;
2419 -- Determine whether the entity of a package denoted by Pkg has a null
2420 -- abstract state.
2422 -----------------------------
2423 -- Has_Null_Abstract_State --
2424 -----------------------------
2426 function Has_Null_Abstract_State (Pkg : Entity_Id) return Boolean is
2427 States : constant Elist_Id := Abstract_States (Pkg);
2429 begin
2430 -- Check first available state of related package. A null abstract
2431 -- state always appears as the sole element of the state list.
2433 return
2434 Present (States)
2435 and then Is_Null_State (Node (First_Elmt (States)));
2436 end Has_Null_Abstract_State;
2438 -- Local variables
2440 Context : Entity_Id := Empty;
2441 Not_Visible : Boolean := False;
2442 Scop : Entity_Id;
2444 -- Start of processing for Check_No_Hidden_State
2446 begin
2447 pragma Assert (Ekind_In (Id, E_Abstract_State, E_Variable));
2449 -- Find the proper context where the object or state appears
2451 Scop := Scope (Id);
2452 while Present (Scop) loop
2453 Context := Scop;
2455 -- Keep track of the context's visibility
2457 Not_Visible := Not_Visible or else In_Private_Part (Context);
2459 -- Prevent the search from going too far
2461 if Context = Standard_Standard then
2462 return;
2464 -- Objects and states that appear immediately within a subprogram or
2465 -- inside a construct nested within a subprogram do not introduce a
2466 -- hidden state. They behave as local variable declarations.
2468 elsif Is_Subprogram (Context) then
2469 return;
2471 -- When examining a package body, use the entity of the spec as it
2472 -- carries the abstract state declarations.
2474 elsif Ekind (Context) = E_Package_Body then
2475 Context := Spec_Entity (Context);
2476 end if;
2478 -- Stop the traversal when a package subject to a null abstract state
2479 -- has been found.
2481 if Ekind_In (Context, E_Generic_Package, E_Package)
2482 and then Has_Null_Abstract_State (Context)
2483 then
2484 exit;
2485 end if;
2487 Scop := Scope (Scop);
2488 end loop;
2490 -- At this point we know that there is at least one package with a null
2491 -- abstract state in visibility. Emit an error message unconditionally
2492 -- if the entity being processed is a state because the placement of the
2493 -- related package is irrelevant. This is not the case for objects as
2494 -- the intermediate context matters.
2496 if Present (Context)
2497 and then (Ekind (Id) = E_Abstract_State or else Not_Visible)
2498 then
2499 Error_Msg_N ("cannot introduce hidden state &", Id);
2500 Error_Msg_NE ("\package & has null abstract state", Id, Context);
2501 end if;
2502 end Check_No_Hidden_State;
2504 ------------------------------------------
2505 -- Check_Potentially_Blocking_Operation --
2506 ------------------------------------------
2508 procedure Check_Potentially_Blocking_Operation (N : Node_Id) is
2509 S : Entity_Id;
2511 begin
2512 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2513 -- When pragma Detect_Blocking is active, the run time will raise
2514 -- Program_Error. Here we only issue a warning, since we generally
2515 -- support the use of potentially blocking operations in the absence
2516 -- of the pragma.
2518 -- Indirect blocking through a subprogram call cannot be diagnosed
2519 -- statically without interprocedural analysis, so we do not attempt
2520 -- to do it here.
2522 S := Scope (Current_Scope);
2523 while Present (S) and then S /= Standard_Standard loop
2524 if Is_Protected_Type (S) then
2525 Error_Msg_N
2526 ("potentially blocking operation in protected operation??", N);
2527 return;
2528 end if;
2530 S := Scope (S);
2531 end loop;
2532 end Check_Potentially_Blocking_Operation;
2534 ---------------------------------
2535 -- Check_Result_And_Post_State --
2536 ---------------------------------
2538 procedure Check_Result_And_Post_State
2539 (Prag : Node_Id;
2540 Result_Seen : in out Boolean)
2542 procedure Check_Expression (Expr : Node_Id);
2543 -- Perform the 'Result and post-state checks on a given expression
2545 function Is_Function_Result (N : Node_Id) return Traverse_Result;
2546 -- Attempt to find attribute 'Result in a subtree denoted by N
2548 function Is_Trivial_Boolean (N : Node_Id) return Boolean;
2549 -- Determine whether source node N denotes "True" or "False"
2551 function Mentions_Post_State (N : Node_Id) return Boolean;
2552 -- Determine whether a subtree denoted by N mentions any construct that
2553 -- denotes a post-state.
2555 procedure Check_Function_Result is
2556 new Traverse_Proc (Is_Function_Result);
2558 ----------------------
2559 -- Check_Expression --
2560 ----------------------
2562 procedure Check_Expression (Expr : Node_Id) is
2563 begin
2564 if not Is_Trivial_Boolean (Expr) then
2565 Check_Function_Result (Expr);
2567 if not Mentions_Post_State (Expr) then
2568 if Pragma_Name (Prag) = Name_Contract_Cases then
2569 Error_Msg_N
2570 ("contract case refers only to pre-state?T?", Expr);
2572 elsif Pragma_Name (Prag) = Name_Refined_Post then
2573 Error_Msg_N
2574 ("refined postcondition refers only to pre-state?T?",
2575 Prag);
2577 else
2578 Error_Msg_N
2579 ("postcondition refers only to pre-state?T?", Prag);
2580 end if;
2581 end if;
2582 end if;
2583 end Check_Expression;
2585 ------------------------
2586 -- Is_Function_Result --
2587 ------------------------
2589 function Is_Function_Result (N : Node_Id) return Traverse_Result is
2590 begin
2591 if Is_Attribute_Result (N) then
2592 Result_Seen := True;
2593 return Abandon;
2595 -- Continue the traversal
2597 else
2598 return OK;
2599 end if;
2600 end Is_Function_Result;
2602 ------------------------
2603 -- Is_Trivial_Boolean --
2604 ------------------------
2606 function Is_Trivial_Boolean (N : Node_Id) return Boolean is
2607 begin
2608 return
2609 Comes_From_Source (N)
2610 and then Is_Entity_Name (N)
2611 and then (Entity (N) = Standard_True
2612 or else Entity (N) = Standard_False);
2613 end Is_Trivial_Boolean;
2615 -------------------------
2616 -- Mentions_Post_State --
2617 -------------------------
2619 function Mentions_Post_State (N : Node_Id) return Boolean is
2620 Post_State_Seen : Boolean := False;
2622 function Is_Post_State (N : Node_Id) return Traverse_Result;
2623 -- Attempt to find a construct that denotes a post-state. If this is
2624 -- the case, set flag Post_State_Seen.
2626 -------------------
2627 -- Is_Post_State --
2628 -------------------
2630 function Is_Post_State (N : Node_Id) return Traverse_Result is
2631 Ent : Entity_Id;
2633 begin
2634 if Nkind_In (N, N_Explicit_Dereference, N_Function_Call) then
2635 Post_State_Seen := True;
2636 return Abandon;
2638 elsif Nkind_In (N, N_Expanded_Name, N_Identifier) then
2639 Ent := Entity (N);
2641 -- The entity may be modifiable through an implicit dereference
2643 if No (Ent)
2644 or else Ekind (Ent) in Assignable_Kind
2645 or else (Is_Access_Type (Etype (Ent))
2646 and then Nkind (Parent (N)) = N_Selected_Component)
2647 then
2648 Post_State_Seen := True;
2649 return Abandon;
2650 end if;
2652 elsif Nkind (N) = N_Attribute_Reference then
2653 if Attribute_Name (N) = Name_Old then
2654 return Skip;
2656 elsif Attribute_Name (N) = Name_Result then
2657 Post_State_Seen := True;
2658 return Abandon;
2659 end if;
2660 end if;
2662 return OK;
2663 end Is_Post_State;
2665 procedure Find_Post_State is new Traverse_Proc (Is_Post_State);
2667 -- Start of processing for Mentions_Post_State
2669 begin
2670 Find_Post_State (N);
2672 return Post_State_Seen;
2673 end Mentions_Post_State;
2675 -- Local variables
2677 Expr : constant Node_Id :=
2678 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
2679 Nam : constant Name_Id := Pragma_Name (Prag);
2680 CCase : Node_Id;
2682 -- Start of processing for Check_Result_And_Post_State
2684 begin
2685 -- Examine all consequences
2687 if Nam = Name_Contract_Cases then
2688 CCase := First (Component_Associations (Expr));
2689 while Present (CCase) loop
2690 Check_Expression (Expression (CCase));
2692 Next (CCase);
2693 end loop;
2695 -- Examine the expression of a postcondition
2697 else pragma Assert (Nam_In (Nam, Name_Postcondition, Name_Refined_Post));
2698 Check_Expression (Expr);
2699 end if;
2700 end Check_Result_And_Post_State;
2702 ------------------------------
2703 -- Check_Unprotected_Access --
2704 ------------------------------
2706 procedure Check_Unprotected_Access
2707 (Context : Node_Id;
2708 Expr : Node_Id)
2710 Cont_Encl_Typ : Entity_Id;
2711 Pref_Encl_Typ : Entity_Id;
2713 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id;
2714 -- Check whether Obj is a private component of a protected object.
2715 -- Return the protected type where the component resides, Empty
2716 -- otherwise.
2718 function Is_Public_Operation return Boolean;
2719 -- Verify that the enclosing operation is callable from outside the
2720 -- protected object, to minimize false positives.
2722 ------------------------------
2723 -- Enclosing_Protected_Type --
2724 ------------------------------
2726 function Enclosing_Protected_Type (Obj : Node_Id) return Entity_Id is
2727 begin
2728 if Is_Entity_Name (Obj) then
2729 declare
2730 Ent : Entity_Id := Entity (Obj);
2732 begin
2733 -- The object can be a renaming of a private component, use
2734 -- the original record component.
2736 if Is_Prival (Ent) then
2737 Ent := Prival_Link (Ent);
2738 end if;
2740 if Is_Protected_Type (Scope (Ent)) then
2741 return Scope (Ent);
2742 end if;
2743 end;
2744 end if;
2746 -- For indexed and selected components, recursively check the prefix
2748 if Nkind_In (Obj, N_Indexed_Component, N_Selected_Component) then
2749 return Enclosing_Protected_Type (Prefix (Obj));
2751 -- The object does not denote a protected component
2753 else
2754 return Empty;
2755 end if;
2756 end Enclosing_Protected_Type;
2758 -------------------------
2759 -- Is_Public_Operation --
2760 -------------------------
2762 function Is_Public_Operation return Boolean is
2763 S : Entity_Id;
2764 E : Entity_Id;
2766 begin
2767 S := Current_Scope;
2768 while Present (S)
2769 and then S /= Pref_Encl_Typ
2770 loop
2771 if Scope (S) = Pref_Encl_Typ then
2772 E := First_Entity (Pref_Encl_Typ);
2773 while Present (E)
2774 and then E /= First_Private_Entity (Pref_Encl_Typ)
2775 loop
2776 if E = S then
2777 return True;
2778 end if;
2779 Next_Entity (E);
2780 end loop;
2781 end if;
2783 S := Scope (S);
2784 end loop;
2786 return False;
2787 end Is_Public_Operation;
2789 -- Start of processing for Check_Unprotected_Access
2791 begin
2792 if Nkind (Expr) = N_Attribute_Reference
2793 and then Attribute_Name (Expr) = Name_Unchecked_Access
2794 then
2795 Cont_Encl_Typ := Enclosing_Protected_Type (Context);
2796 Pref_Encl_Typ := Enclosing_Protected_Type (Prefix (Expr));
2798 -- Check whether we are trying to export a protected component to a
2799 -- context with an equal or lower access level.
2801 if Present (Pref_Encl_Typ)
2802 and then No (Cont_Encl_Typ)
2803 and then Is_Public_Operation
2804 and then Scope_Depth (Pref_Encl_Typ) >=
2805 Object_Access_Level (Context)
2806 then
2807 Error_Msg_N
2808 ("??possible unprotected access to protected data", Expr);
2809 end if;
2810 end if;
2811 end Check_Unprotected_Access;
2813 ---------------
2814 -- Check_VMS --
2815 ---------------
2817 procedure Check_VMS (Construct : Node_Id) is
2818 begin
2819 if not OpenVMS_On_Target then
2820 Error_Msg_N
2821 ("this construct is allowed only in Open'V'M'S", Construct);
2822 end if;
2823 end Check_VMS;
2825 ------------------------
2826 -- Collect_Interfaces --
2827 ------------------------
2829 procedure Collect_Interfaces
2830 (T : Entity_Id;
2831 Ifaces_List : out Elist_Id;
2832 Exclude_Parents : Boolean := False;
2833 Use_Full_View : Boolean := True)
2835 procedure Collect (Typ : Entity_Id);
2836 -- Subsidiary subprogram used to traverse the whole list
2837 -- of directly and indirectly implemented interfaces
2839 -------------
2840 -- Collect --
2841 -------------
2843 procedure Collect (Typ : Entity_Id) is
2844 Ancestor : Entity_Id;
2845 Full_T : Entity_Id;
2846 Id : Node_Id;
2847 Iface : Entity_Id;
2849 begin
2850 Full_T := Typ;
2852 -- Handle private types
2854 if Use_Full_View
2855 and then Is_Private_Type (Typ)
2856 and then Present (Full_View (Typ))
2857 then
2858 Full_T := Full_View (Typ);
2859 end if;
2861 -- Include the ancestor if we are generating the whole list of
2862 -- abstract interfaces.
2864 if Etype (Full_T) /= Typ
2866 -- Protect the frontend against wrong sources. For example:
2868 -- package P is
2869 -- type A is tagged null record;
2870 -- type B is new A with private;
2871 -- type C is new A with private;
2872 -- private
2873 -- type B is new C with null record;
2874 -- type C is new B with null record;
2875 -- end P;
2877 and then Etype (Full_T) /= T
2878 then
2879 Ancestor := Etype (Full_T);
2880 Collect (Ancestor);
2882 if Is_Interface (Ancestor)
2883 and then not Exclude_Parents
2884 then
2885 Append_Unique_Elmt (Ancestor, Ifaces_List);
2886 end if;
2887 end if;
2889 -- Traverse the graph of ancestor interfaces
2891 if Is_Non_Empty_List (Abstract_Interface_List (Full_T)) then
2892 Id := First (Abstract_Interface_List (Full_T));
2893 while Present (Id) loop
2894 Iface := Etype (Id);
2896 -- Protect against wrong uses. For example:
2897 -- type I is interface;
2898 -- type O is tagged null record;
2899 -- type Wrong is new I and O with null record; -- ERROR
2901 if Is_Interface (Iface) then
2902 if Exclude_Parents
2903 and then Etype (T) /= T
2904 and then Interface_Present_In_Ancestor (Etype (T), Iface)
2905 then
2906 null;
2907 else
2908 Collect (Iface);
2909 Append_Unique_Elmt (Iface, Ifaces_List);
2910 end if;
2911 end if;
2913 Next (Id);
2914 end loop;
2915 end if;
2916 end Collect;
2918 -- Start of processing for Collect_Interfaces
2920 begin
2921 pragma Assert (Is_Tagged_Type (T) or else Is_Concurrent_Type (T));
2922 Ifaces_List := New_Elmt_List;
2923 Collect (T);
2924 end Collect_Interfaces;
2926 ----------------------------------
2927 -- Collect_Interface_Components --
2928 ----------------------------------
2930 procedure Collect_Interface_Components
2931 (Tagged_Type : Entity_Id;
2932 Components_List : out Elist_Id)
2934 procedure Collect (Typ : Entity_Id);
2935 -- Subsidiary subprogram used to climb to the parents
2937 -------------
2938 -- Collect --
2939 -------------
2941 procedure Collect (Typ : Entity_Id) is
2942 Tag_Comp : Entity_Id;
2943 Parent_Typ : Entity_Id;
2945 begin
2946 -- Handle private types
2948 if Present (Full_View (Etype (Typ))) then
2949 Parent_Typ := Full_View (Etype (Typ));
2950 else
2951 Parent_Typ := Etype (Typ);
2952 end if;
2954 if Parent_Typ /= Typ
2956 -- Protect the frontend against wrong sources. For example:
2958 -- package P is
2959 -- type A is tagged null record;
2960 -- type B is new A with private;
2961 -- type C is new A with private;
2962 -- private
2963 -- type B is new C with null record;
2964 -- type C is new B with null record;
2965 -- end P;
2967 and then Parent_Typ /= Tagged_Type
2968 then
2969 Collect (Parent_Typ);
2970 end if;
2972 -- Collect the components containing tags of secondary dispatch
2973 -- tables.
2975 Tag_Comp := Next_Tag_Component (First_Tag_Component (Typ));
2976 while Present (Tag_Comp) loop
2977 pragma Assert (Present (Related_Type (Tag_Comp)));
2978 Append_Elmt (Tag_Comp, Components_List);
2980 Tag_Comp := Next_Tag_Component (Tag_Comp);
2981 end loop;
2982 end Collect;
2984 -- Start of processing for Collect_Interface_Components
2986 begin
2987 pragma Assert (Ekind (Tagged_Type) = E_Record_Type
2988 and then Is_Tagged_Type (Tagged_Type));
2990 Components_List := New_Elmt_List;
2991 Collect (Tagged_Type);
2992 end Collect_Interface_Components;
2994 -----------------------------
2995 -- Collect_Interfaces_Info --
2996 -----------------------------
2998 procedure Collect_Interfaces_Info
2999 (T : Entity_Id;
3000 Ifaces_List : out Elist_Id;
3001 Components_List : out Elist_Id;
3002 Tags_List : out Elist_Id)
3004 Comps_List : Elist_Id;
3005 Comp_Elmt : Elmt_Id;
3006 Comp_Iface : Entity_Id;
3007 Iface_Elmt : Elmt_Id;
3008 Iface : Entity_Id;
3010 function Search_Tag (Iface : Entity_Id) return Entity_Id;
3011 -- Search for the secondary tag associated with the interface type
3012 -- Iface that is implemented by T.
3014 ----------------
3015 -- Search_Tag --
3016 ----------------
3018 function Search_Tag (Iface : Entity_Id) return Entity_Id is
3019 ADT : Elmt_Id;
3020 begin
3021 if not Is_CPP_Class (T) then
3022 ADT := Next_Elmt (Next_Elmt (First_Elmt (Access_Disp_Table (T))));
3023 else
3024 ADT := Next_Elmt (First_Elmt (Access_Disp_Table (T)));
3025 end if;
3027 while Present (ADT)
3028 and then Is_Tag (Node (ADT))
3029 and then Related_Type (Node (ADT)) /= Iface
3030 loop
3031 -- Skip secondary dispatch table referencing thunks to user
3032 -- defined primitives covered by this interface.
3034 pragma Assert (Has_Suffix (Node (ADT), 'P'));
3035 Next_Elmt (ADT);
3037 -- Skip secondary dispatch tables of Ada types
3039 if not Is_CPP_Class (T) then
3041 -- Skip secondary dispatch table referencing thunks to
3042 -- predefined primitives.
3044 pragma Assert (Has_Suffix (Node (ADT), 'Y'));
3045 Next_Elmt (ADT);
3047 -- Skip secondary dispatch table referencing user-defined
3048 -- primitives covered by this interface.
3050 pragma Assert (Has_Suffix (Node (ADT), 'D'));
3051 Next_Elmt (ADT);
3053 -- Skip secondary dispatch table referencing predefined
3054 -- primitives.
3056 pragma Assert (Has_Suffix (Node (ADT), 'Z'));
3057 Next_Elmt (ADT);
3058 end if;
3059 end loop;
3061 pragma Assert (Is_Tag (Node (ADT)));
3062 return Node (ADT);
3063 end Search_Tag;
3065 -- Start of processing for Collect_Interfaces_Info
3067 begin
3068 Collect_Interfaces (T, Ifaces_List);
3069 Collect_Interface_Components (T, Comps_List);
3071 -- Search for the record component and tag associated with each
3072 -- interface type of T.
3074 Components_List := New_Elmt_List;
3075 Tags_List := New_Elmt_List;
3077 Iface_Elmt := First_Elmt (Ifaces_List);
3078 while Present (Iface_Elmt) loop
3079 Iface := Node (Iface_Elmt);
3081 -- Associate the primary tag component and the primary dispatch table
3082 -- with all the interfaces that are parents of T
3084 if Is_Ancestor (Iface, T, Use_Full_View => True) then
3085 Append_Elmt (First_Tag_Component (T), Components_List);
3086 Append_Elmt (Node (First_Elmt (Access_Disp_Table (T))), Tags_List);
3088 -- Otherwise search for the tag component and secondary dispatch
3089 -- table of Iface
3091 else
3092 Comp_Elmt := First_Elmt (Comps_List);
3093 while Present (Comp_Elmt) loop
3094 Comp_Iface := Related_Type (Node (Comp_Elmt));
3096 if Comp_Iface = Iface
3097 or else Is_Ancestor (Iface, Comp_Iface, Use_Full_View => True)
3098 then
3099 Append_Elmt (Node (Comp_Elmt), Components_List);
3100 Append_Elmt (Search_Tag (Comp_Iface), Tags_List);
3101 exit;
3102 end if;
3104 Next_Elmt (Comp_Elmt);
3105 end loop;
3106 pragma Assert (Present (Comp_Elmt));
3107 end if;
3109 Next_Elmt (Iface_Elmt);
3110 end loop;
3111 end Collect_Interfaces_Info;
3113 ---------------------
3114 -- Collect_Parents --
3115 ---------------------
3117 procedure Collect_Parents
3118 (T : Entity_Id;
3119 List : out Elist_Id;
3120 Use_Full_View : Boolean := True)
3122 Current_Typ : Entity_Id := T;
3123 Parent_Typ : Entity_Id;
3125 begin
3126 List := New_Elmt_List;
3128 -- No action if the if the type has no parents
3130 if T = Etype (T) then
3131 return;
3132 end if;
3134 loop
3135 Parent_Typ := Etype (Current_Typ);
3137 if Is_Private_Type (Parent_Typ)
3138 and then Present (Full_View (Parent_Typ))
3139 and then Use_Full_View
3140 then
3141 Parent_Typ := Full_View (Base_Type (Parent_Typ));
3142 end if;
3144 Append_Elmt (Parent_Typ, List);
3146 exit when Parent_Typ = Current_Typ;
3147 Current_Typ := Parent_Typ;
3148 end loop;
3149 end Collect_Parents;
3151 ----------------------------------
3152 -- Collect_Primitive_Operations --
3153 ----------------------------------
3155 function Collect_Primitive_Operations (T : Entity_Id) return Elist_Id is
3156 B_Type : constant Entity_Id := Base_Type (T);
3157 B_Decl : constant Node_Id := Original_Node (Parent (B_Type));
3158 B_Scope : Entity_Id := Scope (B_Type);
3159 Op_List : Elist_Id;
3160 Formal : Entity_Id;
3161 Is_Prim : Boolean;
3162 Is_Type_In_Pkg : Boolean;
3163 Formal_Derived : Boolean := False;
3164 Id : Entity_Id;
3166 function Match (E : Entity_Id) return Boolean;
3167 -- True if E's base type is B_Type, or E is of an anonymous access type
3168 -- and the base type of its designated type is B_Type.
3170 -----------
3171 -- Match --
3172 -----------
3174 function Match (E : Entity_Id) return Boolean is
3175 Etyp : Entity_Id := Etype (E);
3177 begin
3178 if Ekind (Etyp) = E_Anonymous_Access_Type then
3179 Etyp := Designated_Type (Etyp);
3180 end if;
3182 return Base_Type (Etyp) = B_Type;
3183 end Match;
3185 -- Start of processing for Collect_Primitive_Operations
3187 begin
3188 -- For tagged types, the primitive operations are collected as they
3189 -- are declared, and held in an explicit list which is simply returned.
3191 if Is_Tagged_Type (B_Type) then
3192 return Primitive_Operations (B_Type);
3194 -- An untagged generic type that is a derived type inherits the
3195 -- primitive operations of its parent type. Other formal types only
3196 -- have predefined operators, which are not explicitly represented.
3198 elsif Is_Generic_Type (B_Type) then
3199 if Nkind (B_Decl) = N_Formal_Type_Declaration
3200 and then Nkind (Formal_Type_Definition (B_Decl))
3201 = N_Formal_Derived_Type_Definition
3202 then
3203 Formal_Derived := True;
3204 else
3205 return New_Elmt_List;
3206 end if;
3207 end if;
3209 Op_List := New_Elmt_List;
3211 if B_Scope = Standard_Standard then
3212 if B_Type = Standard_String then
3213 Append_Elmt (Standard_Op_Concat, Op_List);
3215 elsif B_Type = Standard_Wide_String then
3216 Append_Elmt (Standard_Op_Concatw, Op_List);
3218 else
3219 null;
3220 end if;
3222 -- Locate the primitive subprograms of the type
3224 else
3225 -- The primitive operations appear after the base type, except
3226 -- if the derivation happens within the private part of B_Scope
3227 -- and the type is a private type, in which case both the type
3228 -- and some primitive operations may appear before the base
3229 -- type, and the list of candidates starts after the type.
3231 if In_Open_Scopes (B_Scope)
3232 and then Scope (T) = B_Scope
3233 and then In_Private_Part (B_Scope)
3234 then
3235 Id := Next_Entity (T);
3236 else
3237 Id := Next_Entity (B_Type);
3238 end if;
3240 -- Set flag if this is a type in a package spec
3242 Is_Type_In_Pkg :=
3243 Is_Package_Or_Generic_Package (B_Scope)
3244 and then
3245 Nkind (Parent (Declaration_Node (First_Subtype (T)))) /=
3246 N_Package_Body;
3248 while Present (Id) loop
3250 -- Test whether the result type or any of the parameter types of
3251 -- each subprogram following the type match that type when the
3252 -- type is declared in a package spec, is a derived type, or the
3253 -- subprogram is marked as primitive. (The Is_Primitive test is
3254 -- needed to find primitives of nonderived types in declarative
3255 -- parts that happen to override the predefined "=" operator.)
3257 -- Note that generic formal subprograms are not considered to be
3258 -- primitive operations and thus are never inherited.
3260 if Is_Overloadable (Id)
3261 and then (Is_Type_In_Pkg
3262 or else Is_Derived_Type (B_Type)
3263 or else Is_Primitive (Id))
3264 and then Nkind (Parent (Parent (Id)))
3265 not in N_Formal_Subprogram_Declaration
3266 then
3267 Is_Prim := False;
3269 if Match (Id) then
3270 Is_Prim := True;
3272 else
3273 Formal := First_Formal (Id);
3274 while Present (Formal) loop
3275 if Match (Formal) then
3276 Is_Prim := True;
3277 exit;
3278 end if;
3280 Next_Formal (Formal);
3281 end loop;
3282 end if;
3284 -- For a formal derived type, the only primitives are the ones
3285 -- inherited from the parent type. Operations appearing in the
3286 -- package declaration are not primitive for it.
3288 if Is_Prim
3289 and then (not Formal_Derived
3290 or else Present (Alias (Id)))
3291 then
3292 -- In the special case of an equality operator aliased to
3293 -- an overriding dispatching equality belonging to the same
3294 -- type, we don't include it in the list of primitives.
3295 -- This avoids inheriting multiple equality operators when
3296 -- deriving from untagged private types whose full type is
3297 -- tagged, which can otherwise cause ambiguities. Note that
3298 -- this should only happen for this kind of untagged parent
3299 -- type, since normally dispatching operations are inherited
3300 -- using the type's Primitive_Operations list.
3302 if Chars (Id) = Name_Op_Eq
3303 and then Is_Dispatching_Operation (Id)
3304 and then Present (Alias (Id))
3305 and then Present (Overridden_Operation (Alias (Id)))
3306 and then Base_Type (Etype (First_Entity (Id))) =
3307 Base_Type (Etype (First_Entity (Alias (Id))))
3308 then
3309 null;
3311 -- Include the subprogram in the list of primitives
3313 else
3314 Append_Elmt (Id, Op_List);
3315 end if;
3316 end if;
3317 end if;
3319 Next_Entity (Id);
3321 -- For a type declared in System, some of its operations may
3322 -- appear in the target-specific extension to System.
3324 if No (Id)
3325 and then B_Scope = RTU_Entity (System)
3326 and then Present_System_Aux
3327 then
3328 B_Scope := System_Aux_Id;
3329 Id := First_Entity (System_Aux_Id);
3330 end if;
3331 end loop;
3332 end if;
3334 return Op_List;
3335 end Collect_Primitive_Operations;
3337 -----------------------------------
3338 -- Compile_Time_Constraint_Error --
3339 -----------------------------------
3341 function Compile_Time_Constraint_Error
3342 (N : Node_Id;
3343 Msg : String;
3344 Ent : Entity_Id := Empty;
3345 Loc : Source_Ptr := No_Location;
3346 Warn : Boolean := False) return Node_Id
3348 Msgc : String (1 .. Msg'Length + 3);
3349 -- Copy of message, with room for possible ?? or << and ! at end
3351 Msgl : Natural;
3352 Wmsg : Boolean;
3353 P : Node_Id;
3354 OldP : Node_Id;
3355 Msgs : Boolean;
3356 Eloc : Source_Ptr;
3358 begin
3359 -- If this is a warning, convert it into an error if we are in code
3360 -- subject to SPARK_Mode being set ON.
3362 Error_Msg_Warn := SPARK_Mode /= On;
3364 -- A static constraint error in an instance body is not a fatal error.
3365 -- we choose to inhibit the message altogether, because there is no
3366 -- obvious node (for now) on which to post it. On the other hand the
3367 -- offending node must be replaced with a constraint_error in any case.
3369 -- No messages are generated if we already posted an error on this node
3371 if not Error_Posted (N) then
3372 if Loc /= No_Location then
3373 Eloc := Loc;
3374 else
3375 Eloc := Sloc (N);
3376 end if;
3378 -- Copy message to Msgc, converting any ? in the message into
3379 -- < instead, so that we have an error in GNATprove mode.
3381 Msgl := Msg'Length;
3383 for J in 1 .. Msgl loop
3384 if Msg (J) = '?' and then (J = 1 or else Msg (J) /= ''') then
3385 Msgc (J) := '<';
3386 else
3387 Msgc (J) := Msg (J);
3388 end if;
3389 end loop;
3391 -- Message is a warning, even in Ada 95 case
3393 if Msg (Msg'Last) = '?' or else Msg (Msg'Last) = '<' then
3394 Wmsg := True;
3396 -- In Ada 83, all messages are warnings. In the private part and
3397 -- the body of an instance, constraint_checks are only warnings.
3398 -- We also make this a warning if the Warn parameter is set.
3400 elsif Warn
3401 or else (Ada_Version = Ada_83 and then Comes_From_Source (N))
3402 then
3403 Msgl := Msgl + 1;
3404 Msgc (Msgl) := '<';
3405 Msgl := Msgl + 1;
3406 Msgc (Msgl) := '<';
3407 Wmsg := True;
3409 elsif In_Instance_Not_Visible then
3410 Msgl := Msgl + 1;
3411 Msgc (Msgl) := '<';
3412 Msgl := Msgl + 1;
3413 Msgc (Msgl) := '<';
3414 Wmsg := True;
3416 -- Otherwise we have a real error message (Ada 95 static case)
3417 -- and we make this an unconditional message. Note that in the
3418 -- warning case we do not make the message unconditional, it seems
3419 -- quite reasonable to delete messages like this (about exceptions
3420 -- that will be raised) in dead code.
3422 else
3423 Wmsg := False;
3424 Msgl := Msgl + 1;
3425 Msgc (Msgl) := '!';
3426 end if;
3428 -- Should we generate a warning? The answer is not quite yes. The
3429 -- very annoying exception occurs in the case of a short circuit
3430 -- operator where the left operand is static and decisive. Climb
3431 -- parents to see if that is the case we have here. Conditional
3432 -- expressions with decisive conditions are a similar situation.
3434 Msgs := True;
3435 P := N;
3436 loop
3437 OldP := P;
3438 P := Parent (P);
3440 -- And then with False as left operand
3442 if Nkind (P) = N_And_Then
3443 and then Compile_Time_Known_Value (Left_Opnd (P))
3444 and then Is_False (Expr_Value (Left_Opnd (P)))
3445 then
3446 Msgs := False;
3447 exit;
3449 -- OR ELSE with True as left operand
3451 elsif Nkind (P) = N_Or_Else
3452 and then Compile_Time_Known_Value (Left_Opnd (P))
3453 and then Is_True (Expr_Value (Left_Opnd (P)))
3454 then
3455 Msgs := False;
3456 exit;
3458 -- If expression
3460 elsif Nkind (P) = N_If_Expression then
3461 declare
3462 Cond : constant Node_Id := First (Expressions (P));
3463 Texp : constant Node_Id := Next (Cond);
3464 Fexp : constant Node_Id := Next (Texp);
3466 begin
3467 if Compile_Time_Known_Value (Cond) then
3469 -- Condition is True and we are in the right operand
3471 if Is_True (Expr_Value (Cond))
3472 and then OldP = Fexp
3473 then
3474 Msgs := False;
3475 exit;
3477 -- Condition is False and we are in the left operand
3479 elsif Is_False (Expr_Value (Cond))
3480 and then OldP = Texp
3481 then
3482 Msgs := False;
3483 exit;
3484 end if;
3485 end if;
3486 end;
3488 -- Special case for component association in aggregates, where
3489 -- we want to keep climbing up to the parent aggregate.
3491 elsif Nkind (P) = N_Component_Association
3492 and then Nkind (Parent (P)) = N_Aggregate
3493 then
3494 null;
3496 -- Keep going if within subexpression
3498 else
3499 exit when Nkind (P) not in N_Subexpr;
3500 end if;
3501 end loop;
3503 if Msgs then
3504 Error_Msg_Warn := SPARK_Mode /= On;
3506 if Present (Ent) then
3507 Error_Msg_NEL (Msgc (1 .. Msgl), N, Ent, Eloc);
3508 else
3509 Error_Msg_NEL (Msgc (1 .. Msgl), N, Etype (N), Eloc);
3510 end if;
3512 if Wmsg then
3514 -- Check whether the context is an Init_Proc
3516 if Inside_Init_Proc then
3517 declare
3518 Conc_Typ : constant Entity_Id :=
3519 Corresponding_Concurrent_Type
3520 (Entity (Parameter_Type (First
3521 (Parameter_Specifications
3522 (Parent (Current_Scope))))));
3524 begin
3525 -- Don't complain if the corresponding concurrent type
3526 -- doesn't come from source (i.e. a single task/protected
3527 -- object).
3529 if Present (Conc_Typ)
3530 and then not Comes_From_Source (Conc_Typ)
3531 then
3532 Error_Msg_NEL
3533 ("\& [<<", N, Standard_Constraint_Error, Eloc);
3535 else
3536 if GNATprove_Mode then
3537 Error_Msg_NEL
3538 ("\& would have been raised for objects of this "
3539 & "type", N, Standard_Constraint_Error, Eloc);
3540 else
3541 Error_Msg_NEL
3542 ("\& will be raised for objects of this type??",
3543 N, Standard_Constraint_Error, Eloc);
3544 end if;
3545 end if;
3546 end;
3548 else
3549 Error_Msg_NEL ("\& [<<", N, Standard_Constraint_Error, Eloc);
3550 end if;
3552 else
3553 Error_Msg ("\static expression fails Constraint_Check", Eloc);
3554 Set_Error_Posted (N);
3555 end if;
3556 end if;
3557 end if;
3559 return N;
3560 end Compile_Time_Constraint_Error;
3562 -----------------------
3563 -- Conditional_Delay --
3564 -----------------------
3566 procedure Conditional_Delay (New_Ent, Old_Ent : Entity_Id) is
3567 begin
3568 if Has_Delayed_Freeze (Old_Ent) and then not Is_Frozen (Old_Ent) then
3569 Set_Has_Delayed_Freeze (New_Ent);
3570 end if;
3571 end Conditional_Delay;
3573 ----------------------------
3574 -- Contains_Refined_State --
3575 ----------------------------
3577 function Contains_Refined_State (Prag : Node_Id) return Boolean is
3578 function Has_State_In_Dependency (List : Node_Id) return Boolean;
3579 -- Determine whether a dependency list mentions a state with a visible
3580 -- refinement.
3582 function Has_State_In_Global (List : Node_Id) return Boolean;
3583 -- Determine whether a global list mentions a state with a visible
3584 -- refinement.
3586 function Is_Refined_State (Item : Node_Id) return Boolean;
3587 -- Determine whether Item is a reference to an abstract state with a
3588 -- visible refinement.
3590 -----------------------------
3591 -- Has_State_In_Dependency --
3592 -----------------------------
3594 function Has_State_In_Dependency (List : Node_Id) return Boolean is
3595 Clause : Node_Id;
3596 Output : Node_Id;
3598 begin
3599 -- A null dependency list does not mention any states
3601 if Nkind (List) = N_Null then
3602 return False;
3604 -- Dependency clauses appear as component associations of an
3605 -- aggregate.
3607 elsif Nkind (List) = N_Aggregate
3608 and then Present (Component_Associations (List))
3609 then
3610 Clause := First (Component_Associations (List));
3611 while Present (Clause) loop
3613 -- Inspect the outputs of a dependency clause
3615 Output := First (Choices (Clause));
3616 while Present (Output) loop
3617 if Is_Refined_State (Output) then
3618 return True;
3619 end if;
3621 Next (Output);
3622 end loop;
3624 -- Inspect the outputs of a dependency clause
3626 if Is_Refined_State (Expression (Clause)) then
3627 return True;
3628 end if;
3630 Next (Clause);
3631 end loop;
3633 -- If we get here, then none of the dependency clauses mention a
3634 -- state with visible refinement.
3636 return False;
3638 -- An illegal pragma managed to sneak in
3640 else
3641 raise Program_Error;
3642 end if;
3643 end Has_State_In_Dependency;
3645 -------------------------
3646 -- Has_State_In_Global --
3647 -------------------------
3649 function Has_State_In_Global (List : Node_Id) return Boolean is
3650 Item : Node_Id;
3652 begin
3653 -- A null global list does not mention any states
3655 if Nkind (List) = N_Null then
3656 return False;
3658 -- Simple global list or moded global list declaration
3660 elsif Nkind (List) = N_Aggregate then
3662 -- The declaration of a simple global list appear as a collection
3663 -- of expressions.
3665 if Present (Expressions (List)) then
3666 Item := First (Expressions (List));
3667 while Present (Item) loop
3668 if Is_Refined_State (Item) then
3669 return True;
3670 end if;
3672 Next (Item);
3673 end loop;
3675 -- The declaration of a moded global list appears as a collection
3676 -- of component associations where individual choices denote
3677 -- modes.
3679 else
3680 Item := First (Component_Associations (List));
3681 while Present (Item) loop
3682 if Has_State_In_Global (Expression (Item)) then
3683 return True;
3684 end if;
3686 Next (Item);
3687 end loop;
3688 end if;
3690 -- If we get here, then the simple/moded global list did not
3691 -- mention any states with a visible refinement.
3693 return False;
3695 -- Single global item declaration
3697 elsif Is_Entity_Name (List) then
3698 return Is_Refined_State (List);
3700 -- An illegal pragma managed to sneak in
3702 else
3703 raise Program_Error;
3704 end if;
3705 end Has_State_In_Global;
3707 ----------------------
3708 -- Is_Refined_State --
3709 ----------------------
3711 function Is_Refined_State (Item : Node_Id) return Boolean is
3712 Elmt : Node_Id;
3713 Item_Id : Entity_Id;
3715 begin
3716 if Nkind (Item) = N_Null then
3717 return False;
3719 -- States cannot be subject to attribute 'Result. This case arises
3720 -- in dependency relations.
3722 elsif Nkind (Item) = N_Attribute_Reference
3723 and then Attribute_Name (Item) = Name_Result
3724 then
3725 return False;
3727 -- Multiple items appear as an aggregate. This case arises in
3728 -- dependency relations.
3730 elsif Nkind (Item) = N_Aggregate
3731 and then Present (Expressions (Item))
3732 then
3733 Elmt := First (Expressions (Item));
3734 while Present (Elmt) loop
3735 if Is_Refined_State (Elmt) then
3736 return True;
3737 end if;
3739 Next (Elmt);
3740 end loop;
3742 -- If we get here, then none of the inputs or outputs reference a
3743 -- state with visible refinement.
3745 return False;
3747 -- Single item
3749 else
3750 Item_Id := Entity_Of (Item);
3752 return
3753 Present (Item_Id)
3754 and then Ekind (Item_Id) = E_Abstract_State
3755 and then Has_Visible_Refinement (Item_Id);
3756 end if;
3757 end Is_Refined_State;
3759 -- Local variables
3761 Arg : constant Node_Id :=
3762 Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
3763 Nam : constant Name_Id := Pragma_Name (Prag);
3765 -- Start of processing for Contains_Refined_State
3767 begin
3768 if Nam = Name_Depends then
3769 return Has_State_In_Dependency (Arg);
3771 else pragma Assert (Nam = Name_Global);
3772 return Has_State_In_Global (Arg);
3773 end if;
3774 end Contains_Refined_State;
3776 -------------------------
3777 -- Copy_Component_List --
3778 -------------------------
3780 function Copy_Component_List
3781 (R_Typ : Entity_Id;
3782 Loc : Source_Ptr) return List_Id
3784 Comp : Node_Id;
3785 Comps : constant List_Id := New_List;
3787 begin
3788 Comp := First_Component (Underlying_Type (R_Typ));
3789 while Present (Comp) loop
3790 if Comes_From_Source (Comp) then
3791 declare
3792 Comp_Decl : constant Node_Id := Declaration_Node (Comp);
3793 begin
3794 Append_To (Comps,
3795 Make_Component_Declaration (Loc,
3796 Defining_Identifier =>
3797 Make_Defining_Identifier (Loc, Chars (Comp)),
3798 Component_Definition =>
3799 New_Copy_Tree
3800 (Component_Definition (Comp_Decl), New_Sloc => Loc)));
3801 end;
3802 end if;
3804 Next_Component (Comp);
3805 end loop;
3807 return Comps;
3808 end Copy_Component_List;
3810 -------------------------
3811 -- Copy_Parameter_List --
3812 -------------------------
3814 function Copy_Parameter_List (Subp_Id : Entity_Id) return List_Id is
3815 Loc : constant Source_Ptr := Sloc (Subp_Id);
3816 Plist : List_Id;
3817 Formal : Entity_Id;
3819 begin
3820 if No (First_Formal (Subp_Id)) then
3821 return No_List;
3822 else
3823 Plist := New_List;
3824 Formal := First_Formal (Subp_Id);
3825 while Present (Formal) loop
3826 Append
3827 (Make_Parameter_Specification (Loc,
3828 Defining_Identifier =>
3829 Make_Defining_Identifier (Sloc (Formal),
3830 Chars => Chars (Formal)),
3831 In_Present => In_Present (Parent (Formal)),
3832 Out_Present => Out_Present (Parent (Formal)),
3833 Parameter_Type =>
3834 New_Reference_To (Etype (Formal), Loc),
3835 Expression =>
3836 New_Copy_Tree (Expression (Parent (Formal)))),
3837 Plist);
3839 Next_Formal (Formal);
3840 end loop;
3841 end if;
3843 return Plist;
3844 end Copy_Parameter_List;
3846 --------------------------------
3847 -- Corresponding_Generic_Type --
3848 --------------------------------
3850 function Corresponding_Generic_Type (T : Entity_Id) return Entity_Id is
3851 Inst : Entity_Id;
3852 Gen : Entity_Id;
3853 Typ : Entity_Id;
3855 begin
3856 if not Is_Generic_Actual_Type (T) then
3857 return Any_Type;
3859 -- If the actual is the actual of an enclosing instance, resolution
3860 -- was correct in the generic.
3862 elsif Nkind (Parent (T)) = N_Subtype_Declaration
3863 and then Is_Entity_Name (Subtype_Indication (Parent (T)))
3864 and then
3865 Is_Generic_Actual_Type (Entity (Subtype_Indication (Parent (T))))
3866 then
3867 return Any_Type;
3869 else
3870 Inst := Scope (T);
3872 if Is_Wrapper_Package (Inst) then
3873 Inst := Related_Instance (Inst);
3874 end if;
3876 Gen :=
3877 Generic_Parent
3878 (Specification (Unit_Declaration_Node (Inst)));
3880 -- Generic actual has the same name as the corresponding formal
3882 Typ := First_Entity (Gen);
3883 while Present (Typ) loop
3884 if Chars (Typ) = Chars (T) then
3885 return Typ;
3886 end if;
3888 Next_Entity (Typ);
3889 end loop;
3891 return Any_Type;
3892 end if;
3893 end Corresponding_Generic_Type;
3895 --------------------
3896 -- Current_Entity --
3897 --------------------
3899 -- The currently visible definition for a given identifier is the
3900 -- one most chained at the start of the visibility chain, i.e. the
3901 -- one that is referenced by the Node_Id value of the name of the
3902 -- given identifier.
3904 function Current_Entity (N : Node_Id) return Entity_Id is
3905 begin
3906 return Get_Name_Entity_Id (Chars (N));
3907 end Current_Entity;
3909 -----------------------------
3910 -- Current_Entity_In_Scope --
3911 -----------------------------
3913 function Current_Entity_In_Scope (N : Node_Id) return Entity_Id is
3914 E : Entity_Id;
3915 CS : constant Entity_Id := Current_Scope;
3917 Transient_Case : constant Boolean := Scope_Is_Transient;
3919 begin
3920 E := Get_Name_Entity_Id (Chars (N));
3921 while Present (E)
3922 and then Scope (E) /= CS
3923 and then (not Transient_Case or else Scope (E) /= Scope (CS))
3924 loop
3925 E := Homonym (E);
3926 end loop;
3928 return E;
3929 end Current_Entity_In_Scope;
3931 -------------------
3932 -- Current_Scope --
3933 -------------------
3935 function Current_Scope return Entity_Id is
3936 begin
3937 if Scope_Stack.Last = -1 then
3938 return Standard_Standard;
3939 else
3940 declare
3941 C : constant Entity_Id :=
3942 Scope_Stack.Table (Scope_Stack.Last).Entity;
3943 begin
3944 if Present (C) then
3945 return C;
3946 else
3947 return Standard_Standard;
3948 end if;
3949 end;
3950 end if;
3951 end Current_Scope;
3953 ------------------------
3954 -- Current_Subprogram --
3955 ------------------------
3957 function Current_Subprogram return Entity_Id is
3958 Scop : constant Entity_Id := Current_Scope;
3959 begin
3960 if Is_Subprogram (Scop) or else Is_Generic_Subprogram (Scop) then
3961 return Scop;
3962 else
3963 return Enclosing_Subprogram (Scop);
3964 end if;
3965 end Current_Subprogram;
3967 ----------------------------------
3968 -- Deepest_Type_Access_Level --
3969 ----------------------------------
3971 function Deepest_Type_Access_Level (Typ : Entity_Id) return Uint is
3972 begin
3973 if Ekind (Typ) = E_Anonymous_Access_Type
3974 and then not Is_Local_Anonymous_Access (Typ)
3975 and then Nkind (Associated_Node_For_Itype (Typ)) = N_Object_Declaration
3976 then
3977 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
3978 -- access type.
3980 return
3981 Scope_Depth (Enclosing_Dynamic_Scope
3982 (Defining_Identifier
3983 (Associated_Node_For_Itype (Typ))));
3985 -- For generic formal type, return Int'Last (infinite).
3986 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
3988 elsif Is_Generic_Type (Root_Type (Typ)) then
3989 return UI_From_Int (Int'Last);
3991 else
3992 return Type_Access_Level (Typ);
3993 end if;
3994 end Deepest_Type_Access_Level;
3996 ----------------------------
3997 -- Default_Initialization --
3998 ----------------------------
4000 function Default_Initialization
4001 (Typ : Entity_Id) return Default_Initialization_Kind
4003 Comp : Entity_Id;
4004 Init : Default_Initialization_Kind;
4006 FDI : Boolean := False;
4007 NDI : Boolean := False;
4008 -- Two flags used to designate whether a record type has at least one
4009 -- fully default initialized component and/or one not fully default
4010 -- initialized component.
4012 begin
4013 -- Access types are always fully default initialized
4015 if Is_Access_Type (Typ) then
4016 return Full_Default_Initialization;
4018 -- An array type subject to aspect/pragma Default_Component_Value is
4019 -- fully default initialized. Otherwise its initialization status is
4020 -- that of its component type.
4022 elsif Is_Array_Type (Typ) then
4023 if Present (Default_Aspect_Component_Value (Base_Type (Typ))) then
4024 return Full_Default_Initialization;
4025 else
4026 return Default_Initialization (Component_Type (Typ));
4027 end if;
4029 -- The initialization status of a private type depends on its full view
4031 elsif Is_Private_Type (Typ) and then Present (Full_View (Typ)) then
4032 return Default_Initialization (Full_View (Typ));
4034 -- Record and protected types offer several initialization options
4035 -- depending on their components (if any).
4037 elsif Is_Record_Type (Typ) or else Is_Protected_Type (Typ) then
4038 Comp := First_Component (Typ);
4040 -- Inspect all components
4042 if Present (Comp) then
4043 while Present (Comp) loop
4045 -- Do not process internally generated components except for
4046 -- _parent which represents the ancestor portion of a derived
4047 -- type.
4049 if Comes_From_Source (Comp)
4050 or else Chars (Comp) = Name_uParent
4051 then
4052 Init := Default_Initialization (Base_Type (Etype (Comp)));
4054 -- A component with mixed initialization renders the whole
4055 -- record/protected type mixed.
4057 if Init = Mixed_Initialization then
4058 return Mixed_Initialization;
4060 -- The component is fully default initialized when its type
4061 -- is fully default initialized or when the component has an
4062 -- initialization expression. Note that this has precedence
4063 -- given that the component type may lack initialization.
4065 elsif Init = Full_Default_Initialization
4066 or else Present (Expression (Parent (Comp)))
4067 then
4068 FDI := True;
4070 -- Components with no possible initialization are ignored
4072 elsif Init = No_Possible_Initialization then
4073 null;
4075 -- The component has no full default initialization
4077 else
4078 NDI := True;
4079 end if;
4080 end if;
4082 Next_Component (Comp);
4083 end loop;
4085 -- Detect a mixed case of initialization
4087 if FDI and NDI then
4088 return Mixed_Initialization;
4090 elsif FDI then
4091 return Full_Default_Initialization;
4093 elsif NDI then
4094 return No_Default_Initialization;
4096 -- The type either has no components or they are all internally
4097 -- generated.
4099 else
4100 return No_Possible_Initialization;
4101 end if;
4103 -- The record type is null, there is nothing to initialize
4105 else
4106 return No_Possible_Initialization;
4107 end if;
4109 -- A scalar type subject to aspect/pragma Default_Value is fully default
4110 -- initialized.
4112 elsif Is_Scalar_Type (Typ)
4113 and then Present (Default_Aspect_Value (Base_Type (Typ)))
4114 then
4115 return Full_Default_Initialization;
4117 -- Task types are always fully default initialized
4119 elsif Is_Task_Type (Typ) then
4120 return Full_Default_Initialization;
4121 end if;
4123 -- The type has no full default initialization
4125 return No_Default_Initialization;
4126 end Default_Initialization;
4128 ---------------------
4129 -- Defining_Entity --
4130 ---------------------
4132 function Defining_Entity (N : Node_Id) return Entity_Id is
4133 K : constant Node_Kind := Nkind (N);
4134 Err : Entity_Id := Empty;
4136 begin
4137 case K is
4138 when
4139 N_Subprogram_Declaration |
4140 N_Abstract_Subprogram_Declaration |
4141 N_Subprogram_Body |
4142 N_Package_Declaration |
4143 N_Subprogram_Renaming_Declaration |
4144 N_Subprogram_Body_Stub |
4145 N_Generic_Subprogram_Declaration |
4146 N_Generic_Package_Declaration |
4147 N_Formal_Subprogram_Declaration |
4148 N_Expression_Function
4150 return Defining_Entity (Specification (N));
4152 when
4153 N_Component_Declaration |
4154 N_Defining_Program_Unit_Name |
4155 N_Discriminant_Specification |
4156 N_Entry_Body |
4157 N_Entry_Declaration |
4158 N_Entry_Index_Specification |
4159 N_Exception_Declaration |
4160 N_Exception_Renaming_Declaration |
4161 N_Formal_Object_Declaration |
4162 N_Formal_Package_Declaration |
4163 N_Formal_Type_Declaration |
4164 N_Full_Type_Declaration |
4165 N_Implicit_Label_Declaration |
4166 N_Incomplete_Type_Declaration |
4167 N_Loop_Parameter_Specification |
4168 N_Number_Declaration |
4169 N_Object_Declaration |
4170 N_Object_Renaming_Declaration |
4171 N_Package_Body_Stub |
4172 N_Parameter_Specification |
4173 N_Private_Extension_Declaration |
4174 N_Private_Type_Declaration |
4175 N_Protected_Body |
4176 N_Protected_Body_Stub |
4177 N_Protected_Type_Declaration |
4178 N_Single_Protected_Declaration |
4179 N_Single_Task_Declaration |
4180 N_Subtype_Declaration |
4181 N_Task_Body |
4182 N_Task_Body_Stub |
4183 N_Task_Type_Declaration
4185 return Defining_Identifier (N);
4187 when N_Subunit =>
4188 return Defining_Entity (Proper_Body (N));
4190 when
4191 N_Function_Instantiation |
4192 N_Function_Specification |
4193 N_Generic_Function_Renaming_Declaration |
4194 N_Generic_Package_Renaming_Declaration |
4195 N_Generic_Procedure_Renaming_Declaration |
4196 N_Package_Body |
4197 N_Package_Instantiation |
4198 N_Package_Renaming_Declaration |
4199 N_Package_Specification |
4200 N_Procedure_Instantiation |
4201 N_Procedure_Specification
4203 declare
4204 Nam : constant Node_Id := Defining_Unit_Name (N);
4206 begin
4207 if Nkind (Nam) in N_Entity then
4208 return Nam;
4210 -- For Error, make up a name and attach to declaration
4211 -- so we can continue semantic analysis
4213 elsif Nam = Error then
4214 Err := Make_Temporary (Sloc (N), 'T');
4215 Set_Defining_Unit_Name (N, Err);
4217 return Err;
4219 -- If not an entity, get defining identifier
4221 else
4222 return Defining_Identifier (Nam);
4223 end if;
4224 end;
4226 when N_Block_Statement =>
4227 return Entity (Identifier (N));
4229 when others =>
4230 raise Program_Error;
4232 end case;
4233 end Defining_Entity;
4235 --------------------------
4236 -- Denotes_Discriminant --
4237 --------------------------
4239 function Denotes_Discriminant
4240 (N : Node_Id;
4241 Check_Concurrent : Boolean := False) return Boolean
4243 E : Entity_Id;
4244 begin
4245 if not Is_Entity_Name (N)
4246 or else No (Entity (N))
4247 then
4248 return False;
4249 else
4250 E := Entity (N);
4251 end if;
4253 -- If we are checking for a protected type, the discriminant may have
4254 -- been rewritten as the corresponding discriminal of the original type
4255 -- or of the corresponding concurrent record, depending on whether we
4256 -- are in the spec or body of the protected type.
4258 return Ekind (E) = E_Discriminant
4259 or else
4260 (Check_Concurrent
4261 and then Ekind (E) = E_In_Parameter
4262 and then Present (Discriminal_Link (E))
4263 and then
4264 (Is_Concurrent_Type (Scope (Discriminal_Link (E)))
4265 or else
4266 Is_Concurrent_Record_Type (Scope (Discriminal_Link (E)))));
4268 end Denotes_Discriminant;
4270 -------------------------
4271 -- Denotes_Same_Object --
4272 -------------------------
4274 function Denotes_Same_Object (A1, A2 : Node_Id) return Boolean is
4275 Obj1 : Node_Id := A1;
4276 Obj2 : Node_Id := A2;
4278 function Has_Prefix (N : Node_Id) return Boolean;
4279 -- Return True if N has attribute Prefix
4281 function Is_Renaming (N : Node_Id) return Boolean;
4282 -- Return true if N names a renaming entity
4284 function Is_Valid_Renaming (N : Node_Id) return Boolean;
4285 -- For renamings, return False if the prefix of any dereference within
4286 -- the renamed object_name is a variable, or any expression within the
4287 -- renamed object_name contains references to variables or calls on
4288 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4290 ----------------
4291 -- Has_Prefix --
4292 ----------------
4294 function Has_Prefix (N : Node_Id) return Boolean is
4295 begin
4296 return
4297 Nkind_In (N,
4298 N_Attribute_Reference,
4299 N_Expanded_Name,
4300 N_Explicit_Dereference,
4301 N_Indexed_Component,
4302 N_Reference,
4303 N_Selected_Component,
4304 N_Slice);
4305 end Has_Prefix;
4307 -----------------
4308 -- Is_Renaming --
4309 -----------------
4311 function Is_Renaming (N : Node_Id) return Boolean is
4312 begin
4313 return Is_Entity_Name (N)
4314 and then Present (Renamed_Entity (Entity (N)));
4315 end Is_Renaming;
4317 -----------------------
4318 -- Is_Valid_Renaming --
4319 -----------------------
4321 function Is_Valid_Renaming (N : Node_Id) return Boolean is
4323 function Check_Renaming (N : Node_Id) return Boolean;
4324 -- Recursive function used to traverse all the prefixes of N
4326 function Check_Renaming (N : Node_Id) return Boolean is
4327 begin
4328 if Is_Renaming (N)
4329 and then not Check_Renaming (Renamed_Entity (Entity (N)))
4330 then
4331 return False;
4332 end if;
4334 if Nkind (N) = N_Indexed_Component then
4335 declare
4336 Indx : Node_Id;
4338 begin
4339 Indx := First (Expressions (N));
4340 while Present (Indx) loop
4341 if not Is_OK_Static_Expression (Indx) then
4342 return False;
4343 end if;
4345 Next_Index (Indx);
4346 end loop;
4347 end;
4348 end if;
4350 if Has_Prefix (N) then
4351 declare
4352 P : constant Node_Id := Prefix (N);
4354 begin
4355 if Nkind (N) = N_Explicit_Dereference
4356 and then Is_Variable (P)
4357 then
4358 return False;
4360 elsif Is_Entity_Name (P)
4361 and then Ekind (Entity (P)) = E_Function
4362 then
4363 return False;
4365 elsif Nkind (P) = N_Function_Call then
4366 return False;
4367 end if;
4369 -- Recursion to continue traversing the prefix of the
4370 -- renaming expression
4372 return Check_Renaming (P);
4373 end;
4374 end if;
4376 return True;
4377 end Check_Renaming;
4379 -- Start of processing for Is_Valid_Renaming
4381 begin
4382 return Check_Renaming (N);
4383 end Is_Valid_Renaming;
4385 -- Start of processing for Denotes_Same_Object
4387 begin
4388 -- Both names statically denote the same stand-alone object or parameter
4389 -- (RM 6.4.1(6.5/3))
4391 if Is_Entity_Name (Obj1)
4392 and then Is_Entity_Name (Obj2)
4393 and then Entity (Obj1) = Entity (Obj2)
4394 then
4395 return True;
4396 end if;
4398 -- For renamings, the prefix of any dereference within the renamed
4399 -- object_name is not a variable, and any expression within the
4400 -- renamed object_name contains no references to variables nor
4401 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4403 if Is_Renaming (Obj1) then
4404 if Is_Valid_Renaming (Obj1) then
4405 Obj1 := Renamed_Entity (Entity (Obj1));
4406 else
4407 return False;
4408 end if;
4409 end if;
4411 if Is_Renaming (Obj2) then
4412 if Is_Valid_Renaming (Obj2) then
4413 Obj2 := Renamed_Entity (Entity (Obj2));
4414 else
4415 return False;
4416 end if;
4417 end if;
4419 -- No match if not same node kind (such cases are handled by
4420 -- Denotes_Same_Prefix)
4422 if Nkind (Obj1) /= Nkind (Obj2) then
4423 return False;
4425 -- After handling valid renamings, one of the two names statically
4426 -- denoted a renaming declaration whose renamed object_name is known
4427 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4429 elsif Is_Entity_Name (Obj1) then
4430 if Is_Entity_Name (Obj2) then
4431 return Entity (Obj1) = Entity (Obj2);
4432 else
4433 return False;
4434 end if;
4436 -- Both names are selected_components, their prefixes are known to
4437 -- denote the same object, and their selector_names denote the same
4438 -- component (RM 6.4.1(6.6/3)
4440 elsif Nkind (Obj1) = N_Selected_Component then
4441 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4442 and then
4443 Entity (Selector_Name (Obj1)) = Entity (Selector_Name (Obj2));
4445 -- Both names are dereferences and the dereferenced names are known to
4446 -- denote the same object (RM 6.4.1(6.7/3))
4448 elsif Nkind (Obj1) = N_Explicit_Dereference then
4449 return Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2));
4451 -- Both names are indexed_components, their prefixes are known to denote
4452 -- the same object, and each of the pairs of corresponding index values
4453 -- are either both static expressions with the same static value or both
4454 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4456 elsif Nkind (Obj1) = N_Indexed_Component then
4457 if not Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2)) then
4458 return False;
4459 else
4460 declare
4461 Indx1 : Node_Id;
4462 Indx2 : Node_Id;
4464 begin
4465 Indx1 := First (Expressions (Obj1));
4466 Indx2 := First (Expressions (Obj2));
4467 while Present (Indx1) loop
4469 -- Indexes must denote the same static value or same object
4471 if Is_OK_Static_Expression (Indx1) then
4472 if not Is_OK_Static_Expression (Indx2) then
4473 return False;
4475 elsif Expr_Value (Indx1) /= Expr_Value (Indx2) then
4476 return False;
4477 end if;
4479 elsif not Denotes_Same_Object (Indx1, Indx2) then
4480 return False;
4481 end if;
4483 Next (Indx1);
4484 Next (Indx2);
4485 end loop;
4487 return True;
4488 end;
4489 end if;
4491 -- Both names are slices, their prefixes are known to denote the same
4492 -- object, and the two slices have statically matching index constraints
4493 -- (RM 6.4.1(6.9/3))
4495 elsif Nkind (Obj1) = N_Slice
4496 and then Denotes_Same_Object (Prefix (Obj1), Prefix (Obj2))
4497 then
4498 declare
4499 Lo1, Lo2, Hi1, Hi2 : Node_Id;
4501 begin
4502 Get_Index_Bounds (Etype (Obj1), Lo1, Hi1);
4503 Get_Index_Bounds (Etype (Obj2), Lo2, Hi2);
4505 -- Check whether bounds are statically identical. There is no
4506 -- attempt to detect partial overlap of slices.
4508 return Denotes_Same_Object (Lo1, Lo2)
4509 and then Denotes_Same_Object (Hi1, Hi2);
4510 end;
4512 -- In the recursion, literals appear as indexes.
4514 elsif Nkind (Obj1) = N_Integer_Literal
4515 and then Nkind (Obj2) = N_Integer_Literal
4516 then
4517 return Intval (Obj1) = Intval (Obj2);
4519 else
4520 return False;
4521 end if;
4522 end Denotes_Same_Object;
4524 -------------------------
4525 -- Denotes_Same_Prefix --
4526 -------------------------
4528 function Denotes_Same_Prefix (A1, A2 : Node_Id) return Boolean is
4530 begin
4531 if Is_Entity_Name (A1) then
4532 if Nkind_In (A2, N_Selected_Component, N_Indexed_Component)
4533 and then not Is_Access_Type (Etype (A1))
4534 then
4535 return Denotes_Same_Object (A1, Prefix (A2))
4536 or else Denotes_Same_Prefix (A1, Prefix (A2));
4537 else
4538 return False;
4539 end if;
4541 elsif Is_Entity_Name (A2) then
4542 return Denotes_Same_Prefix (A1 => A2, A2 => A1);
4544 elsif Nkind_In (A1, N_Selected_Component, N_Indexed_Component, N_Slice)
4545 and then
4546 Nkind_In (A2, N_Selected_Component, N_Indexed_Component, N_Slice)
4547 then
4548 declare
4549 Root1, Root2 : Node_Id;
4550 Depth1, Depth2 : Int := 0;
4552 begin
4553 Root1 := Prefix (A1);
4554 while not Is_Entity_Name (Root1) loop
4555 if not Nkind_In
4556 (Root1, N_Selected_Component, N_Indexed_Component)
4557 then
4558 return False;
4559 else
4560 Root1 := Prefix (Root1);
4561 end if;
4563 Depth1 := Depth1 + 1;
4564 end loop;
4566 Root2 := Prefix (A2);
4567 while not Is_Entity_Name (Root2) loop
4568 if not Nkind_In
4569 (Root2, N_Selected_Component, N_Indexed_Component)
4570 then
4571 return False;
4572 else
4573 Root2 := Prefix (Root2);
4574 end if;
4576 Depth2 := Depth2 + 1;
4577 end loop;
4579 -- If both have the same depth and they do not denote the same
4580 -- object, they are disjoint and no warning is needed.
4582 if Depth1 = Depth2 then
4583 return False;
4585 elsif Depth1 > Depth2 then
4586 Root1 := Prefix (A1);
4587 for I in 1 .. Depth1 - Depth2 - 1 loop
4588 Root1 := Prefix (Root1);
4589 end loop;
4591 return Denotes_Same_Object (Root1, A2);
4593 else
4594 Root2 := Prefix (A2);
4595 for I in 1 .. Depth2 - Depth1 - 1 loop
4596 Root2 := Prefix (Root2);
4597 end loop;
4599 return Denotes_Same_Object (A1, Root2);
4600 end if;
4601 end;
4603 else
4604 return False;
4605 end if;
4606 end Denotes_Same_Prefix;
4608 ----------------------
4609 -- Denotes_Variable --
4610 ----------------------
4612 function Denotes_Variable (N : Node_Id) return Boolean is
4613 begin
4614 return Is_Variable (N) and then Paren_Count (N) = 0;
4615 end Denotes_Variable;
4617 -----------------------------
4618 -- Depends_On_Discriminant --
4619 -----------------------------
4621 function Depends_On_Discriminant (N : Node_Id) return Boolean is
4622 L : Node_Id;
4623 H : Node_Id;
4625 begin
4626 Get_Index_Bounds (N, L, H);
4627 return Denotes_Discriminant (L) or else Denotes_Discriminant (H);
4628 end Depends_On_Discriminant;
4630 -------------------------
4631 -- Designate_Same_Unit --
4632 -------------------------
4634 function Designate_Same_Unit
4635 (Name1 : Node_Id;
4636 Name2 : Node_Id) return Boolean
4638 K1 : constant Node_Kind := Nkind (Name1);
4639 K2 : constant Node_Kind := Nkind (Name2);
4641 function Prefix_Node (N : Node_Id) return Node_Id;
4642 -- Returns the parent unit name node of a defining program unit name
4643 -- or the prefix if N is a selected component or an expanded name.
4645 function Select_Node (N : Node_Id) return Node_Id;
4646 -- Returns the defining identifier node of a defining program unit
4647 -- name or the selector node if N is a selected component or an
4648 -- expanded name.
4650 -----------------
4651 -- Prefix_Node --
4652 -----------------
4654 function Prefix_Node (N : Node_Id) return Node_Id is
4655 begin
4656 if Nkind (N) = N_Defining_Program_Unit_Name then
4657 return Name (N);
4659 else
4660 return Prefix (N);
4661 end if;
4662 end Prefix_Node;
4664 -----------------
4665 -- Select_Node --
4666 -----------------
4668 function Select_Node (N : Node_Id) return Node_Id is
4669 begin
4670 if Nkind (N) = N_Defining_Program_Unit_Name then
4671 return Defining_Identifier (N);
4673 else
4674 return Selector_Name (N);
4675 end if;
4676 end Select_Node;
4678 -- Start of processing for Designate_Next_Unit
4680 begin
4681 if (K1 = N_Identifier or else
4682 K1 = N_Defining_Identifier)
4683 and then
4684 (K2 = N_Identifier or else
4685 K2 = N_Defining_Identifier)
4686 then
4687 return Chars (Name1) = Chars (Name2);
4689 elsif
4690 (K1 = N_Expanded_Name or else
4691 K1 = N_Selected_Component or else
4692 K1 = N_Defining_Program_Unit_Name)
4693 and then
4694 (K2 = N_Expanded_Name or else
4695 K2 = N_Selected_Component or else
4696 K2 = N_Defining_Program_Unit_Name)
4697 then
4698 return
4699 (Chars (Select_Node (Name1)) = Chars (Select_Node (Name2)))
4700 and then
4701 Designate_Same_Unit (Prefix_Node (Name1), Prefix_Node (Name2));
4703 else
4704 return False;
4705 end if;
4706 end Designate_Same_Unit;
4708 ------------------------------------------
4709 -- function Dynamic_Accessibility_Level --
4710 ------------------------------------------
4712 function Dynamic_Accessibility_Level (Expr : Node_Id) return Node_Id is
4713 E : Entity_Id;
4714 Loc : constant Source_Ptr := Sloc (Expr);
4716 function Make_Level_Literal (Level : Uint) return Node_Id;
4717 -- Construct an integer literal representing an accessibility level
4718 -- with its type set to Natural.
4720 ------------------------
4721 -- Make_Level_Literal --
4722 ------------------------
4724 function Make_Level_Literal (Level : Uint) return Node_Id is
4725 Result : constant Node_Id := Make_Integer_Literal (Loc, Level);
4726 begin
4727 Set_Etype (Result, Standard_Natural);
4728 return Result;
4729 end Make_Level_Literal;
4731 -- Start of processing for Dynamic_Accessibility_Level
4733 begin
4734 if Is_Entity_Name (Expr) then
4735 E := Entity (Expr);
4737 if Present (Renamed_Object (E)) then
4738 return Dynamic_Accessibility_Level (Renamed_Object (E));
4739 end if;
4741 if Is_Formal (E) or else Ekind_In (E, E_Variable, E_Constant) then
4742 if Present (Extra_Accessibility (E)) then
4743 return New_Occurrence_Of (Extra_Accessibility (E), Loc);
4744 end if;
4745 end if;
4746 end if;
4748 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4750 case Nkind (Expr) is
4752 -- For access discriminant, the level of the enclosing object
4754 when N_Selected_Component =>
4755 if Ekind (Entity (Selector_Name (Expr))) = E_Discriminant
4756 and then Ekind (Etype (Entity (Selector_Name (Expr)))) =
4757 E_Anonymous_Access_Type
4758 then
4759 return Make_Level_Literal (Object_Access_Level (Expr));
4760 end if;
4762 when N_Attribute_Reference =>
4763 case Get_Attribute_Id (Attribute_Name (Expr)) is
4765 -- For X'Access, the level of the prefix X
4767 when Attribute_Access =>
4768 return Make_Level_Literal
4769 (Object_Access_Level (Prefix (Expr)));
4771 -- Treat the unchecked attributes as library-level
4773 when Attribute_Unchecked_Access |
4774 Attribute_Unrestricted_Access =>
4775 return Make_Level_Literal (Scope_Depth (Standard_Standard));
4777 -- No other access-valued attributes
4779 when others =>
4780 raise Program_Error;
4781 end case;
4783 when N_Allocator =>
4785 -- Unimplemented: depends on context. As an actual parameter where
4786 -- formal type is anonymous, use
4787 -- Scope_Depth (Current_Scope) + 1.
4788 -- For other cases, see 3.10.2(14/3) and following. ???
4790 null;
4792 when N_Type_Conversion =>
4793 if not Is_Local_Anonymous_Access (Etype (Expr)) then
4795 -- Handle type conversions introduced for a rename of an
4796 -- Ada 2012 stand-alone object of an anonymous access type.
4798 return Dynamic_Accessibility_Level (Expression (Expr));
4799 end if;
4801 when others =>
4802 null;
4803 end case;
4805 return Make_Level_Literal (Type_Access_Level (Etype (Expr)));
4806 end Dynamic_Accessibility_Level;
4808 -----------------------------------
4809 -- Effective_Extra_Accessibility --
4810 -----------------------------------
4812 function Effective_Extra_Accessibility (Id : Entity_Id) return Entity_Id is
4813 begin
4814 if Present (Renamed_Object (Id))
4815 and then Is_Entity_Name (Renamed_Object (Id))
4816 then
4817 return Effective_Extra_Accessibility (Entity (Renamed_Object (Id)));
4818 else
4819 return Extra_Accessibility (Id);
4820 end if;
4821 end Effective_Extra_Accessibility;
4823 -----------------------------
4824 -- Effective_Reads_Enabled --
4825 -----------------------------
4827 function Effective_Reads_Enabled (Id : Entity_Id) return Boolean is
4828 begin
4829 if Ekind (Id) = E_Abstract_State then
4830 return Has_Enabled_Property (Id, Name_Effective_Reads);
4832 else pragma Assert (Ekind (Id) = E_Variable);
4833 return Present (Get_Pragma (Id, Pragma_Effective_Reads));
4834 end if;
4835 end Effective_Reads_Enabled;
4837 ------------------------------
4838 -- Effective_Writes_Enabled --
4839 ------------------------------
4841 function Effective_Writes_Enabled (Id : Entity_Id) return Boolean is
4842 begin
4843 if Ekind (Id) = E_Abstract_State then
4844 return Has_Enabled_Property (Id, Name_Effective_Writes);
4846 else pragma Assert (Ekind (Id) = E_Variable);
4847 return Present (Get_Pragma (Id, Pragma_Effective_Writes));
4848 end if;
4849 end Effective_Writes_Enabled;
4851 ------------------------------
4852 -- Enclosing_Comp_Unit_Node --
4853 ------------------------------
4855 function Enclosing_Comp_Unit_Node (N : Node_Id) return Node_Id is
4856 Current_Node : Node_Id;
4858 begin
4859 Current_Node := N;
4860 while Present (Current_Node)
4861 and then Nkind (Current_Node) /= N_Compilation_Unit
4862 loop
4863 Current_Node := Parent (Current_Node);
4864 end loop;
4866 if Nkind (Current_Node) /= N_Compilation_Unit then
4867 return Empty;
4868 else
4869 return Current_Node;
4870 end if;
4871 end Enclosing_Comp_Unit_Node;
4873 --------------------------
4874 -- Enclosing_CPP_Parent --
4875 --------------------------
4877 function Enclosing_CPP_Parent (Typ : Entity_Id) return Entity_Id is
4878 Parent_Typ : Entity_Id := Typ;
4880 begin
4881 while not Is_CPP_Class (Parent_Typ)
4882 and then Etype (Parent_Typ) /= Parent_Typ
4883 loop
4884 Parent_Typ := Etype (Parent_Typ);
4886 if Is_Private_Type (Parent_Typ) then
4887 Parent_Typ := Full_View (Base_Type (Parent_Typ));
4888 end if;
4889 end loop;
4891 pragma Assert (Is_CPP_Class (Parent_Typ));
4892 return Parent_Typ;
4893 end Enclosing_CPP_Parent;
4895 ----------------------------
4896 -- Enclosing_Generic_Body --
4897 ----------------------------
4899 function Enclosing_Generic_Body
4900 (N : Node_Id) return Node_Id
4902 P : Node_Id;
4903 Decl : Node_Id;
4904 Spec : Node_Id;
4906 begin
4907 P := Parent (N);
4908 while Present (P) loop
4909 if Nkind (P) = N_Package_Body
4910 or else Nkind (P) = N_Subprogram_Body
4911 then
4912 Spec := Corresponding_Spec (P);
4914 if Present (Spec) then
4915 Decl := Unit_Declaration_Node (Spec);
4917 if Nkind (Decl) = N_Generic_Package_Declaration
4918 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
4919 then
4920 return P;
4921 end if;
4922 end if;
4923 end if;
4925 P := Parent (P);
4926 end loop;
4928 return Empty;
4929 end Enclosing_Generic_Body;
4931 ----------------------------
4932 -- Enclosing_Generic_Unit --
4933 ----------------------------
4935 function Enclosing_Generic_Unit
4936 (N : Node_Id) return Node_Id
4938 P : Node_Id;
4939 Decl : Node_Id;
4940 Spec : Node_Id;
4942 begin
4943 P := Parent (N);
4944 while Present (P) loop
4945 if Nkind (P) = N_Generic_Package_Declaration
4946 or else Nkind (P) = N_Generic_Subprogram_Declaration
4947 then
4948 return P;
4950 elsif Nkind (P) = N_Package_Body
4951 or else Nkind (P) = N_Subprogram_Body
4952 then
4953 Spec := Corresponding_Spec (P);
4955 if Present (Spec) then
4956 Decl := Unit_Declaration_Node (Spec);
4958 if Nkind (Decl) = N_Generic_Package_Declaration
4959 or else Nkind (Decl) = N_Generic_Subprogram_Declaration
4960 then
4961 return Decl;
4962 end if;
4963 end if;
4964 end if;
4966 P := Parent (P);
4967 end loop;
4969 return Empty;
4970 end Enclosing_Generic_Unit;
4972 -------------------------------
4973 -- Enclosing_Lib_Unit_Entity --
4974 -------------------------------
4976 function Enclosing_Lib_Unit_Entity
4977 (E : Entity_Id := Current_Scope) return Entity_Id
4979 Unit_Entity : Entity_Id;
4981 begin
4982 -- Look for enclosing library unit entity by following scope links.
4983 -- Equivalent to, but faster than indexing through the scope stack.
4985 Unit_Entity := E;
4986 while (Present (Scope (Unit_Entity))
4987 and then Scope (Unit_Entity) /= Standard_Standard)
4988 and not Is_Child_Unit (Unit_Entity)
4989 loop
4990 Unit_Entity := Scope (Unit_Entity);
4991 end loop;
4993 return Unit_Entity;
4994 end Enclosing_Lib_Unit_Entity;
4996 -----------------------
4997 -- Enclosing_Package --
4998 -----------------------
5000 function Enclosing_Package (E : Entity_Id) return Entity_Id is
5001 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5003 begin
5004 if Dynamic_Scope = Standard_Standard then
5005 return Standard_Standard;
5007 elsif Dynamic_Scope = Empty then
5008 return Empty;
5010 elsif Ekind_In (Dynamic_Scope, E_Package, E_Package_Body,
5011 E_Generic_Package)
5012 then
5013 return Dynamic_Scope;
5015 else
5016 return Enclosing_Package (Dynamic_Scope);
5017 end if;
5018 end Enclosing_Package;
5020 --------------------------
5021 -- Enclosing_Subprogram --
5022 --------------------------
5024 function Enclosing_Subprogram (E : Entity_Id) return Entity_Id is
5025 Dynamic_Scope : constant Entity_Id := Enclosing_Dynamic_Scope (E);
5027 begin
5028 if Dynamic_Scope = Standard_Standard then
5029 return Empty;
5031 elsif Dynamic_Scope = Empty then
5032 return Empty;
5034 elsif Ekind (Dynamic_Scope) = E_Subprogram_Body then
5035 return Corresponding_Spec (Parent (Parent (Dynamic_Scope)));
5037 elsif Ekind (Dynamic_Scope) = E_Block
5038 or else Ekind (Dynamic_Scope) = E_Return_Statement
5039 then
5040 return Enclosing_Subprogram (Dynamic_Scope);
5042 elsif Ekind (Dynamic_Scope) = E_Task_Type then
5043 return Get_Task_Body_Procedure (Dynamic_Scope);
5045 elsif Ekind (Dynamic_Scope) = E_Limited_Private_Type
5046 and then Present (Full_View (Dynamic_Scope))
5047 and then Ekind (Full_View (Dynamic_Scope)) = E_Task_Type
5048 then
5049 return Get_Task_Body_Procedure (Full_View (Dynamic_Scope));
5051 -- No body is generated if the protected operation is eliminated
5053 elsif Convention (Dynamic_Scope) = Convention_Protected
5054 and then not Is_Eliminated (Dynamic_Scope)
5055 and then Present (Protected_Body_Subprogram (Dynamic_Scope))
5056 then
5057 return Protected_Body_Subprogram (Dynamic_Scope);
5059 else
5060 return Dynamic_Scope;
5061 end if;
5062 end Enclosing_Subprogram;
5064 ------------------------
5065 -- Ensure_Freeze_Node --
5066 ------------------------
5068 procedure Ensure_Freeze_Node (E : Entity_Id) is
5069 FN : Node_Id;
5070 begin
5071 if No (Freeze_Node (E)) then
5072 FN := Make_Freeze_Entity (Sloc (E));
5073 Set_Has_Delayed_Freeze (E);
5074 Set_Freeze_Node (E, FN);
5075 Set_Access_Types_To_Process (FN, No_Elist);
5076 Set_TSS_Elist (FN, No_Elist);
5077 Set_Entity (FN, E);
5078 end if;
5079 end Ensure_Freeze_Node;
5081 ----------------
5082 -- Enter_Name --
5083 ----------------
5085 procedure Enter_Name (Def_Id : Entity_Id) is
5086 C : constant Entity_Id := Current_Entity (Def_Id);
5087 E : constant Entity_Id := Current_Entity_In_Scope (Def_Id);
5088 S : constant Entity_Id := Current_Scope;
5090 begin
5091 Generate_Definition (Def_Id);
5093 -- Add new name to current scope declarations. Check for duplicate
5094 -- declaration, which may or may not be a genuine error.
5096 if Present (E) then
5098 -- Case of previous entity entered because of a missing declaration
5099 -- or else a bad subtype indication. Best is to use the new entity,
5100 -- and make the previous one invisible.
5102 if Etype (E) = Any_Type then
5103 Set_Is_Immediately_Visible (E, False);
5105 -- Case of renaming declaration constructed for package instances.
5106 -- if there is an explicit declaration with the same identifier,
5107 -- the renaming is not immediately visible any longer, but remains
5108 -- visible through selected component notation.
5110 elsif Nkind (Parent (E)) = N_Package_Renaming_Declaration
5111 and then not Comes_From_Source (E)
5112 then
5113 Set_Is_Immediately_Visible (E, False);
5115 -- The new entity may be the package renaming, which has the same
5116 -- same name as a generic formal which has been seen already.
5118 elsif Nkind (Parent (Def_Id)) = N_Package_Renaming_Declaration
5119 and then not Comes_From_Source (Def_Id)
5120 then
5121 Set_Is_Immediately_Visible (E, False);
5123 -- For a fat pointer corresponding to a remote access to subprogram,
5124 -- we use the same identifier as the RAS type, so that the proper
5125 -- name appears in the stub. This type is only retrieved through
5126 -- the RAS type and never by visibility, and is not added to the
5127 -- visibility list (see below).
5129 elsif Nkind (Parent (Def_Id)) = N_Full_Type_Declaration
5130 and then Present (Corresponding_Remote_Type (Def_Id))
5131 then
5132 null;
5134 -- Case of an implicit operation or derived literal. The new entity
5135 -- hides the implicit one, which is removed from all visibility,
5136 -- i.e. the entity list of its scope, and homonym chain of its name.
5138 elsif (Is_Overloadable (E) and then Is_Inherited_Operation (E))
5139 or else Is_Internal (E)
5140 then
5141 declare
5142 Prev : Entity_Id;
5143 Prev_Vis : Entity_Id;
5144 Decl : constant Node_Id := Parent (E);
5146 begin
5147 -- If E is an implicit declaration, it cannot be the first
5148 -- entity in the scope.
5150 Prev := First_Entity (Current_Scope);
5151 while Present (Prev)
5152 and then Next_Entity (Prev) /= E
5153 loop
5154 Next_Entity (Prev);
5155 end loop;
5157 if No (Prev) then
5159 -- If E is not on the entity chain of the current scope,
5160 -- it is an implicit declaration in the generic formal
5161 -- part of a generic subprogram. When analyzing the body,
5162 -- the generic formals are visible but not on the entity
5163 -- chain of the subprogram. The new entity will become
5164 -- the visible one in the body.
5166 pragma Assert
5167 (Nkind (Parent (Decl)) = N_Generic_Subprogram_Declaration);
5168 null;
5170 else
5171 Set_Next_Entity (Prev, Next_Entity (E));
5173 if No (Next_Entity (Prev)) then
5174 Set_Last_Entity (Current_Scope, Prev);
5175 end if;
5177 if E = Current_Entity (E) then
5178 Prev_Vis := Empty;
5180 else
5181 Prev_Vis := Current_Entity (E);
5182 while Homonym (Prev_Vis) /= E loop
5183 Prev_Vis := Homonym (Prev_Vis);
5184 end loop;
5185 end if;
5187 if Present (Prev_Vis) then
5189 -- Skip E in the visibility chain
5191 Set_Homonym (Prev_Vis, Homonym (E));
5193 else
5194 Set_Name_Entity_Id (Chars (E), Homonym (E));
5195 end if;
5196 end if;
5197 end;
5199 -- This section of code could use a comment ???
5201 elsif Present (Etype (E))
5202 and then Is_Concurrent_Type (Etype (E))
5203 and then E = Def_Id
5204 then
5205 return;
5207 -- If the homograph is a protected component renaming, it should not
5208 -- be hiding the current entity. Such renamings are treated as weak
5209 -- declarations.
5211 elsif Is_Prival (E) then
5212 Set_Is_Immediately_Visible (E, False);
5214 -- In this case the current entity is a protected component renaming.
5215 -- Perform minimal decoration by setting the scope and return since
5216 -- the prival should not be hiding other visible entities.
5218 elsif Is_Prival (Def_Id) then
5219 Set_Scope (Def_Id, Current_Scope);
5220 return;
5222 -- Analogous to privals, the discriminal generated for an entry index
5223 -- parameter acts as a weak declaration. Perform minimal decoration
5224 -- to avoid bogus errors.
5226 elsif Is_Discriminal (Def_Id)
5227 and then Ekind (Discriminal_Link (Def_Id)) = E_Entry_Index_Parameter
5228 then
5229 Set_Scope (Def_Id, Current_Scope);
5230 return;
5232 -- In the body or private part of an instance, a type extension may
5233 -- introduce a component with the same name as that of an actual. The
5234 -- legality rule is not enforced, but the semantics of the full type
5235 -- with two components of same name are not clear at this point???
5237 elsif In_Instance_Not_Visible then
5238 null;
5240 -- When compiling a package body, some child units may have become
5241 -- visible. They cannot conflict with local entities that hide them.
5243 elsif Is_Child_Unit (E)
5244 and then In_Open_Scopes (Scope (E))
5245 and then not Is_Immediately_Visible (E)
5246 then
5247 null;
5249 -- Conversely, with front-end inlining we may compile the parent body
5250 -- first, and a child unit subsequently. The context is now the
5251 -- parent spec, and body entities are not visible.
5253 elsif Is_Child_Unit (Def_Id)
5254 and then Is_Package_Body_Entity (E)
5255 and then not In_Package_Body (Current_Scope)
5256 then
5257 null;
5259 -- Case of genuine duplicate declaration
5261 else
5262 Error_Msg_Sloc := Sloc (E);
5264 -- If the previous declaration is an incomplete type declaration
5265 -- this may be an attempt to complete it with a private type. The
5266 -- following avoids confusing cascaded errors.
5268 if Nkind (Parent (E)) = N_Incomplete_Type_Declaration
5269 and then Nkind (Parent (Def_Id)) = N_Private_Type_Declaration
5270 then
5271 Error_Msg_N
5272 ("incomplete type cannot be completed with a private " &
5273 "declaration", Parent (Def_Id));
5274 Set_Is_Immediately_Visible (E, False);
5275 Set_Full_View (E, Def_Id);
5277 -- An inherited component of a record conflicts with a new
5278 -- discriminant. The discriminant is inserted first in the scope,
5279 -- but the error should be posted on it, not on the component.
5281 elsif Ekind (E) = E_Discriminant
5282 and then Present (Scope (Def_Id))
5283 and then Scope (Def_Id) /= Current_Scope
5284 then
5285 Error_Msg_Sloc := Sloc (Def_Id);
5286 Error_Msg_N ("& conflicts with declaration#", E);
5287 return;
5289 -- If the name of the unit appears in its own context clause, a
5290 -- dummy package with the name has already been created, and the
5291 -- error emitted. Try to continue quietly.
5293 elsif Error_Posted (E)
5294 and then Sloc (E) = No_Location
5295 and then Nkind (Parent (E)) = N_Package_Specification
5296 and then Current_Scope = Standard_Standard
5297 then
5298 Set_Scope (Def_Id, Current_Scope);
5299 return;
5301 else
5302 Error_Msg_N ("& conflicts with declaration#", Def_Id);
5304 -- Avoid cascaded messages with duplicate components in
5305 -- derived types.
5307 if Ekind_In (E, E_Component, E_Discriminant) then
5308 return;
5309 end if;
5310 end if;
5312 if Nkind (Parent (Parent (Def_Id))) =
5313 N_Generic_Subprogram_Declaration
5314 and then Def_Id =
5315 Defining_Entity (Specification (Parent (Parent (Def_Id))))
5316 then
5317 Error_Msg_N ("\generic units cannot be overloaded", Def_Id);
5318 end if;
5320 -- If entity is in standard, then we are in trouble, because it
5321 -- means that we have a library package with a duplicated name.
5322 -- That's hard to recover from, so abort.
5324 if S = Standard_Standard then
5325 raise Unrecoverable_Error;
5327 -- Otherwise we continue with the declaration. Having two
5328 -- identical declarations should not cause us too much trouble.
5330 else
5331 null;
5332 end if;
5333 end if;
5334 end if;
5336 -- If we fall through, declaration is OK, at least OK enough to continue
5338 -- If Def_Id is a discriminant or a record component we are in the midst
5339 -- of inheriting components in a derived record definition. Preserve
5340 -- their Ekind and Etype.
5342 if Ekind_In (Def_Id, E_Discriminant, E_Component) then
5343 null;
5345 -- If a type is already set, leave it alone (happens when a type
5346 -- declaration is reanalyzed following a call to the optimizer).
5348 elsif Present (Etype (Def_Id)) then
5349 null;
5351 -- Otherwise, the kind E_Void insures that premature uses of the entity
5352 -- will be detected. Any_Type insures that no cascaded errors will occur
5354 else
5355 Set_Ekind (Def_Id, E_Void);
5356 Set_Etype (Def_Id, Any_Type);
5357 end if;
5359 -- Inherited discriminants and components in derived record types are
5360 -- immediately visible. Itypes are not.
5362 -- Unless the Itype is for a record type with a corresponding remote
5363 -- type (what is that about, it was not commented ???)
5365 if Ekind_In (Def_Id, E_Discriminant, E_Component)
5366 or else
5367 ((not Is_Record_Type (Def_Id)
5368 or else No (Corresponding_Remote_Type (Def_Id)))
5369 and then not Is_Itype (Def_Id))
5370 then
5371 Set_Is_Immediately_Visible (Def_Id);
5372 Set_Current_Entity (Def_Id);
5373 end if;
5375 Set_Homonym (Def_Id, C);
5376 Append_Entity (Def_Id, S);
5377 Set_Public_Status (Def_Id);
5379 -- Declaring a homonym is not allowed in SPARK ...
5381 if Present (C)
5382 and then Restriction_Check_Required (SPARK_05)
5383 then
5384 declare
5385 Enclosing_Subp : constant Node_Id := Enclosing_Subprogram (Def_Id);
5386 Enclosing_Pack : constant Node_Id := Enclosing_Package (Def_Id);
5387 Other_Scope : constant Node_Id := Enclosing_Dynamic_Scope (C);
5389 begin
5390 -- ... unless the new declaration is in a subprogram, and the
5391 -- visible declaration is a variable declaration or a parameter
5392 -- specification outside that subprogram.
5394 if Present (Enclosing_Subp)
5395 and then Nkind_In (Parent (C), N_Object_Declaration,
5396 N_Parameter_Specification)
5397 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Subp)
5398 then
5399 null;
5401 -- ... or the new declaration is in a package, and the visible
5402 -- declaration occurs outside that package.
5404 elsif Present (Enclosing_Pack)
5405 and then not Scope_Within_Or_Same (Other_Scope, Enclosing_Pack)
5406 then
5407 null;
5409 -- ... or the new declaration is a component declaration in a
5410 -- record type definition.
5412 elsif Nkind (Parent (Def_Id)) = N_Component_Declaration then
5413 null;
5415 -- Don't issue error for non-source entities
5417 elsif Comes_From_Source (Def_Id)
5418 and then Comes_From_Source (C)
5419 then
5420 Error_Msg_Sloc := Sloc (C);
5421 Check_SPARK_Restriction
5422 ("redeclaration of identifier &#", Def_Id);
5423 end if;
5424 end;
5425 end if;
5427 -- Warn if new entity hides an old one
5429 if Warn_On_Hiding and then Present (C)
5431 -- Don't warn for record components since they always have a well
5432 -- defined scope which does not confuse other uses. Note that in
5433 -- some cases, Ekind has not been set yet.
5435 and then Ekind (C) /= E_Component
5436 and then Ekind (C) /= E_Discriminant
5437 and then Nkind (Parent (C)) /= N_Component_Declaration
5438 and then Ekind (Def_Id) /= E_Component
5439 and then Ekind (Def_Id) /= E_Discriminant
5440 and then Nkind (Parent (Def_Id)) /= N_Component_Declaration
5442 -- Don't warn for one character variables. It is too common to use
5443 -- such variables as locals and will just cause too many false hits.
5445 and then Length_Of_Name (Chars (C)) /= 1
5447 -- Don't warn for non-source entities
5449 and then Comes_From_Source (C)
5450 and then Comes_From_Source (Def_Id)
5452 -- Don't warn unless entity in question is in extended main source
5454 and then In_Extended_Main_Source_Unit (Def_Id)
5456 -- Finally, the hidden entity must be either immediately visible or
5457 -- use visible (i.e. from a used package).
5459 and then
5460 (Is_Immediately_Visible (C)
5461 or else
5462 Is_Potentially_Use_Visible (C))
5463 then
5464 Error_Msg_Sloc := Sloc (C);
5465 Error_Msg_N ("declaration hides &#?h?", Def_Id);
5466 end if;
5467 end Enter_Name;
5469 ---------------
5470 -- Entity_Of --
5471 ---------------
5473 function Entity_Of (N : Node_Id) return Entity_Id is
5474 Id : Entity_Id;
5476 begin
5477 Id := Empty;
5479 if Is_Entity_Name (N) then
5480 Id := Entity (N);
5482 -- Follow a possible chain of renamings to reach the root renamed
5483 -- object.
5485 while Present (Id) and then Present (Renamed_Object (Id)) loop
5486 if Is_Entity_Name (Renamed_Object (Id)) then
5487 Id := Entity (Renamed_Object (Id));
5488 else
5489 Id := Empty;
5490 exit;
5491 end if;
5492 end loop;
5493 end if;
5495 return Id;
5496 end Entity_Of;
5498 --------------------------
5499 -- Explain_Limited_Type --
5500 --------------------------
5502 procedure Explain_Limited_Type (T : Entity_Id; N : Node_Id) is
5503 C : Entity_Id;
5505 begin
5506 -- For array, component type must be limited
5508 if Is_Array_Type (T) then
5509 Error_Msg_Node_2 := T;
5510 Error_Msg_NE
5511 ("\component type& of type& is limited", N, Component_Type (T));
5512 Explain_Limited_Type (Component_Type (T), N);
5514 elsif Is_Record_Type (T) then
5516 -- No need for extra messages if explicit limited record
5518 if Is_Limited_Record (Base_Type (T)) then
5519 return;
5520 end if;
5522 -- Otherwise find a limited component. Check only components that
5523 -- come from source, or inherited components that appear in the
5524 -- source of the ancestor.
5526 C := First_Component (T);
5527 while Present (C) loop
5528 if Is_Limited_Type (Etype (C))
5529 and then
5530 (Comes_From_Source (C)
5531 or else
5532 (Present (Original_Record_Component (C))
5533 and then
5534 Comes_From_Source (Original_Record_Component (C))))
5535 then
5536 Error_Msg_Node_2 := T;
5537 Error_Msg_NE ("\component& of type& has limited type", N, C);
5538 Explain_Limited_Type (Etype (C), N);
5539 return;
5540 end if;
5542 Next_Component (C);
5543 end loop;
5545 -- The type may be declared explicitly limited, even if no component
5546 -- of it is limited, in which case we fall out of the loop.
5547 return;
5548 end if;
5549 end Explain_Limited_Type;
5551 -----------------
5552 -- Find_Actual --
5553 -----------------
5555 procedure Find_Actual
5556 (N : Node_Id;
5557 Formal : out Entity_Id;
5558 Call : out Node_Id)
5560 Parnt : constant Node_Id := Parent (N);
5561 Actual : Node_Id;
5563 begin
5564 if (Nkind (Parnt) = N_Indexed_Component
5565 or else
5566 Nkind (Parnt) = N_Selected_Component)
5567 and then N = Prefix (Parnt)
5568 then
5569 Find_Actual (Parnt, Formal, Call);
5570 return;
5572 elsif Nkind (Parnt) = N_Parameter_Association
5573 and then N = Explicit_Actual_Parameter (Parnt)
5574 then
5575 Call := Parent (Parnt);
5577 elsif Nkind (Parnt) in N_Subprogram_Call then
5578 Call := Parnt;
5580 else
5581 Formal := Empty;
5582 Call := Empty;
5583 return;
5584 end if;
5586 -- If we have a call to a subprogram look for the parameter. Note that
5587 -- we exclude overloaded calls, since we don't know enough to be sure
5588 -- of giving the right answer in this case.
5590 if Is_Entity_Name (Name (Call))
5591 and then Present (Entity (Name (Call)))
5592 and then Is_Overloadable (Entity (Name (Call)))
5593 and then not Is_Overloaded (Name (Call))
5594 then
5595 -- Fall here if we are definitely a parameter
5597 Actual := First_Actual (Call);
5598 Formal := First_Formal (Entity (Name (Call)));
5599 while Present (Formal) and then Present (Actual) loop
5600 if Actual = N then
5601 return;
5602 else
5603 Actual := Next_Actual (Actual);
5604 Formal := Next_Formal (Formal);
5605 end if;
5606 end loop;
5607 end if;
5609 -- Fall through here if we did not find matching actual
5611 Formal := Empty;
5612 Call := Empty;
5613 end Find_Actual;
5615 ---------------------------
5616 -- Find_Body_Discriminal --
5617 ---------------------------
5619 function Find_Body_Discriminal
5620 (Spec_Discriminant : Entity_Id) return Entity_Id
5622 Tsk : Entity_Id;
5623 Disc : Entity_Id;
5625 begin
5626 -- If expansion is suppressed, then the scope can be the concurrent type
5627 -- itself rather than a corresponding concurrent record type.
5629 if Is_Concurrent_Type (Scope (Spec_Discriminant)) then
5630 Tsk := Scope (Spec_Discriminant);
5632 else
5633 pragma Assert (Is_Concurrent_Record_Type (Scope (Spec_Discriminant)));
5635 Tsk := Corresponding_Concurrent_Type (Scope (Spec_Discriminant));
5636 end if;
5638 -- Find discriminant of original concurrent type, and use its current
5639 -- discriminal, which is the renaming within the task/protected body.
5641 Disc := First_Discriminant (Tsk);
5642 while Present (Disc) loop
5643 if Chars (Disc) = Chars (Spec_Discriminant) then
5644 return Discriminal (Disc);
5645 end if;
5647 Next_Discriminant (Disc);
5648 end loop;
5650 -- That loop should always succeed in finding a matching entry and
5651 -- returning. Fatal error if not.
5653 raise Program_Error;
5654 end Find_Body_Discriminal;
5656 -------------------------------------
5657 -- Find_Corresponding_Discriminant --
5658 -------------------------------------
5660 function Find_Corresponding_Discriminant
5661 (Id : Node_Id;
5662 Typ : Entity_Id) return Entity_Id
5664 Par_Disc : Entity_Id;
5665 Old_Disc : Entity_Id;
5666 New_Disc : Entity_Id;
5668 begin
5669 Par_Disc := Original_Record_Component (Original_Discriminant (Id));
5671 -- The original type may currently be private, and the discriminant
5672 -- only appear on its full view.
5674 if Is_Private_Type (Scope (Par_Disc))
5675 and then not Has_Discriminants (Scope (Par_Disc))
5676 and then Present (Full_View (Scope (Par_Disc)))
5677 then
5678 Old_Disc := First_Discriminant (Full_View (Scope (Par_Disc)));
5679 else
5680 Old_Disc := First_Discriminant (Scope (Par_Disc));
5681 end if;
5683 if Is_Class_Wide_Type (Typ) then
5684 New_Disc := First_Discriminant (Root_Type (Typ));
5685 else
5686 New_Disc := First_Discriminant (Typ);
5687 end if;
5689 while Present (Old_Disc) and then Present (New_Disc) loop
5690 if Old_Disc = Par_Disc then
5691 return New_Disc;
5692 else
5693 Next_Discriminant (Old_Disc);
5694 Next_Discriminant (New_Disc);
5695 end if;
5696 end loop;
5698 -- Should always find it
5700 raise Program_Error;
5701 end Find_Corresponding_Discriminant;
5703 ------------------------------------
5704 -- Find_Loop_In_Conditional_Block --
5705 ------------------------------------
5707 function Find_Loop_In_Conditional_Block (N : Node_Id) return Node_Id is
5708 Stmt : Node_Id;
5710 begin
5711 Stmt := N;
5713 if Nkind (Stmt) = N_If_Statement then
5714 Stmt := First (Then_Statements (Stmt));
5715 end if;
5717 pragma Assert (Nkind (Stmt) = N_Block_Statement);
5719 -- Inspect the statements of the conditional block. In general the loop
5720 -- should be the first statement in the statement sequence of the block,
5721 -- but the finalization machinery may have introduced extra object
5722 -- declarations.
5724 Stmt := First (Statements (Handled_Statement_Sequence (Stmt)));
5725 while Present (Stmt) loop
5726 if Nkind (Stmt) = N_Loop_Statement then
5727 return Stmt;
5728 end if;
5730 Next (Stmt);
5731 end loop;
5733 -- The expansion of attribute 'Loop_Entry produced a malformed block
5735 raise Program_Error;
5736 end Find_Loop_In_Conditional_Block;
5738 --------------------------
5739 -- Find_Overlaid_Entity --
5740 --------------------------
5742 procedure Find_Overlaid_Entity
5743 (N : Node_Id;
5744 Ent : out Entity_Id;
5745 Off : out Boolean)
5747 Expr : Node_Id;
5749 begin
5750 -- We are looking for one of the two following forms:
5752 -- for X'Address use Y'Address
5754 -- or
5756 -- Const : constant Address := expr;
5757 -- ...
5758 -- for X'Address use Const;
5760 -- In the second case, the expr is either Y'Address, or recursively a
5761 -- constant that eventually references Y'Address.
5763 Ent := Empty;
5764 Off := False;
5766 if Nkind (N) = N_Attribute_Definition_Clause
5767 and then Chars (N) = Name_Address
5768 then
5769 Expr := Expression (N);
5771 -- This loop checks the form of the expression for Y'Address,
5772 -- using recursion to deal with intermediate constants.
5774 loop
5775 -- Check for Y'Address
5777 if Nkind (Expr) = N_Attribute_Reference
5778 and then Attribute_Name (Expr) = Name_Address
5779 then
5780 Expr := Prefix (Expr);
5781 exit;
5783 -- Check for Const where Const is a constant entity
5785 elsif Is_Entity_Name (Expr)
5786 and then Ekind (Entity (Expr)) = E_Constant
5787 then
5788 Expr := Constant_Value (Entity (Expr));
5790 -- Anything else does not need checking
5792 else
5793 return;
5794 end if;
5795 end loop;
5797 -- This loop checks the form of the prefix for an entity, using
5798 -- recursion to deal with intermediate components.
5800 loop
5801 -- Check for Y where Y is an entity
5803 if Is_Entity_Name (Expr) then
5804 Ent := Entity (Expr);
5805 return;
5807 -- Check for components
5809 elsif
5810 Nkind_In (Expr, N_Selected_Component, N_Indexed_Component)
5811 then
5812 Expr := Prefix (Expr);
5813 Off := True;
5815 -- Anything else does not need checking
5817 else
5818 return;
5819 end if;
5820 end loop;
5821 end if;
5822 end Find_Overlaid_Entity;
5824 -------------------------
5825 -- Find_Parameter_Type --
5826 -------------------------
5828 function Find_Parameter_Type (Param : Node_Id) return Entity_Id is
5829 begin
5830 if Nkind (Param) /= N_Parameter_Specification then
5831 return Empty;
5833 -- For an access parameter, obtain the type from the formal entity
5834 -- itself, because access to subprogram nodes do not carry a type.
5835 -- Shouldn't we always use the formal entity ???
5837 elsif Nkind (Parameter_Type (Param)) = N_Access_Definition then
5838 return Etype (Defining_Identifier (Param));
5840 else
5841 return Etype (Parameter_Type (Param));
5842 end if;
5843 end Find_Parameter_Type;
5845 -----------------------------------
5846 -- Find_Placement_In_State_Space --
5847 -----------------------------------
5849 procedure Find_Placement_In_State_Space
5850 (Item_Id : Entity_Id;
5851 Placement : out State_Space_Kind;
5852 Pack_Id : out Entity_Id)
5854 Context : Entity_Id;
5856 begin
5857 -- Assume that the item does not appear in the state space of a package
5859 Placement := Not_In_Package;
5860 Pack_Id := Empty;
5862 -- Climb the scope stack and examine the enclosing context
5864 Context := Scope (Item_Id);
5865 while Present (Context) and then Context /= Standard_Standard loop
5866 if Ekind (Context) = E_Package then
5867 Pack_Id := Context;
5869 -- A package body is a cut off point for the traversal as the item
5870 -- cannot be visible to the outside from this point on. Note that
5871 -- this test must be done first as a body is also classified as a
5872 -- private part.
5874 if In_Package_Body (Context) then
5875 Placement := Body_State_Space;
5876 return;
5878 -- The private part of a package is a cut off point for the
5879 -- traversal as the item cannot be visible to the outside from
5880 -- this point on.
5882 elsif In_Private_Part (Context) then
5883 Placement := Private_State_Space;
5884 return;
5886 -- When the item appears in the visible state space of a package,
5887 -- continue to climb the scope stack as this may not be the final
5888 -- state space.
5890 else
5891 Placement := Visible_State_Space;
5893 -- The visible state space of a child unit acts as the proper
5894 -- placement of an item.
5896 if Is_Child_Unit (Context) then
5897 return;
5898 end if;
5899 end if;
5901 -- The item or its enclosing package appear in a construct that has
5902 -- no state space.
5904 else
5905 Placement := Not_In_Package;
5906 return;
5907 end if;
5909 Context := Scope (Context);
5910 end loop;
5911 end Find_Placement_In_State_Space;
5913 -----------------------------
5914 -- Find_Static_Alternative --
5915 -----------------------------
5917 function Find_Static_Alternative (N : Node_Id) return Node_Id is
5918 Expr : constant Node_Id := Expression (N);
5919 Val : constant Uint := Expr_Value (Expr);
5920 Alt : Node_Id;
5921 Choice : Node_Id;
5923 begin
5924 Alt := First (Alternatives (N));
5926 Search : loop
5927 if Nkind (Alt) /= N_Pragma then
5928 Choice := First (Discrete_Choices (Alt));
5929 while Present (Choice) loop
5931 -- Others choice, always matches
5933 if Nkind (Choice) = N_Others_Choice then
5934 exit Search;
5936 -- Range, check if value is in the range
5938 elsif Nkind (Choice) = N_Range then
5939 exit Search when
5940 Val >= Expr_Value (Low_Bound (Choice))
5941 and then
5942 Val <= Expr_Value (High_Bound (Choice));
5944 -- Choice is a subtype name. Note that we know it must
5945 -- be a static subtype, since otherwise it would have
5946 -- been diagnosed as illegal.
5948 elsif Is_Entity_Name (Choice)
5949 and then Is_Type (Entity (Choice))
5950 then
5951 exit Search when Is_In_Range (Expr, Etype (Choice),
5952 Assume_Valid => False);
5954 -- Choice is a subtype indication
5956 elsif Nkind (Choice) = N_Subtype_Indication then
5957 declare
5958 C : constant Node_Id := Constraint (Choice);
5959 R : constant Node_Id := Range_Expression (C);
5961 begin
5962 exit Search when
5963 Val >= Expr_Value (Low_Bound (R))
5964 and then
5965 Val <= Expr_Value (High_Bound (R));
5966 end;
5968 -- Choice is a simple expression
5970 else
5971 exit Search when Val = Expr_Value (Choice);
5972 end if;
5974 Next (Choice);
5975 end loop;
5976 end if;
5978 Next (Alt);
5979 pragma Assert (Present (Alt));
5980 end loop Search;
5982 -- The above loop *must* terminate by finding a match, since
5983 -- we know the case statement is valid, and the value of the
5984 -- expression is known at compile time. When we fall out of
5985 -- the loop, Alt points to the alternative that we know will
5986 -- be selected at run time.
5988 return Alt;
5989 end Find_Static_Alternative;
5991 ------------------
5992 -- First_Actual --
5993 ------------------
5995 function First_Actual (Node : Node_Id) return Node_Id is
5996 N : Node_Id;
5998 begin
5999 if No (Parameter_Associations (Node)) then
6000 return Empty;
6001 end if;
6003 N := First (Parameter_Associations (Node));
6005 if Nkind (N) = N_Parameter_Association then
6006 return First_Named_Actual (Node);
6007 else
6008 return N;
6009 end if;
6010 end First_Actual;
6012 -----------------------
6013 -- Gather_Components --
6014 -----------------------
6016 procedure Gather_Components
6017 (Typ : Entity_Id;
6018 Comp_List : Node_Id;
6019 Governed_By : List_Id;
6020 Into : Elist_Id;
6021 Report_Errors : out Boolean)
6023 Assoc : Node_Id;
6024 Variant : Node_Id;
6025 Discrete_Choice : Node_Id;
6026 Comp_Item : Node_Id;
6028 Discrim : Entity_Id;
6029 Discrim_Name : Node_Id;
6030 Discrim_Value : Node_Id;
6032 begin
6033 Report_Errors := False;
6035 if No (Comp_List) or else Null_Present (Comp_List) then
6036 return;
6038 elsif Present (Component_Items (Comp_List)) then
6039 Comp_Item := First (Component_Items (Comp_List));
6041 else
6042 Comp_Item := Empty;
6043 end if;
6045 while Present (Comp_Item) loop
6047 -- Skip the tag of a tagged record, the interface tags, as well
6048 -- as all items that are not user components (anonymous types,
6049 -- rep clauses, Parent field, controller field).
6051 if Nkind (Comp_Item) = N_Component_Declaration then
6052 declare
6053 Comp : constant Entity_Id := Defining_Identifier (Comp_Item);
6054 begin
6055 if not Is_Tag (Comp)
6056 and then Chars (Comp) /= Name_uParent
6057 then
6058 Append_Elmt (Comp, Into);
6059 end if;
6060 end;
6061 end if;
6063 Next (Comp_Item);
6064 end loop;
6066 if No (Variant_Part (Comp_List)) then
6067 return;
6068 else
6069 Discrim_Name := Name (Variant_Part (Comp_List));
6070 Variant := First_Non_Pragma (Variants (Variant_Part (Comp_List)));
6071 end if;
6073 -- Look for the discriminant that governs this variant part.
6074 -- The discriminant *must* be in the Governed_By List
6076 Assoc := First (Governed_By);
6077 Find_Constraint : loop
6078 Discrim := First (Choices (Assoc));
6079 exit Find_Constraint when Chars (Discrim_Name) = Chars (Discrim)
6080 or else (Present (Corresponding_Discriminant (Entity (Discrim)))
6081 and then
6082 Chars (Corresponding_Discriminant (Entity (Discrim))) =
6083 Chars (Discrim_Name))
6084 or else Chars (Original_Record_Component (Entity (Discrim)))
6085 = Chars (Discrim_Name);
6087 if No (Next (Assoc)) then
6088 if not Is_Constrained (Typ)
6089 and then Is_Derived_Type (Typ)
6090 and then Present (Stored_Constraint (Typ))
6091 then
6092 -- If the type is a tagged type with inherited discriminants,
6093 -- use the stored constraint on the parent in order to find
6094 -- the values of discriminants that are otherwise hidden by an
6095 -- explicit constraint. Renamed discriminants are handled in
6096 -- the code above.
6098 -- If several parent discriminants are renamed by a single
6099 -- discriminant of the derived type, the call to obtain the
6100 -- Corresponding_Discriminant field only retrieves the last
6101 -- of them. We recover the constraint on the others from the
6102 -- Stored_Constraint as well.
6104 declare
6105 D : Entity_Id;
6106 C : Elmt_Id;
6108 begin
6109 D := First_Discriminant (Etype (Typ));
6110 C := First_Elmt (Stored_Constraint (Typ));
6111 while Present (D) and then Present (C) loop
6112 if Chars (Discrim_Name) = Chars (D) then
6113 if Is_Entity_Name (Node (C))
6114 and then Entity (Node (C)) = Entity (Discrim)
6115 then
6116 -- D is renamed by Discrim, whose value is given in
6117 -- Assoc.
6119 null;
6121 else
6122 Assoc :=
6123 Make_Component_Association (Sloc (Typ),
6124 New_List
6125 (New_Occurrence_Of (D, Sloc (Typ))),
6126 Duplicate_Subexpr_No_Checks (Node (C)));
6127 end if;
6128 exit Find_Constraint;
6129 end if;
6131 Next_Discriminant (D);
6132 Next_Elmt (C);
6133 end loop;
6134 end;
6135 end if;
6136 end if;
6138 if No (Next (Assoc)) then
6139 Error_Msg_NE (" missing value for discriminant&",
6140 First (Governed_By), Discrim_Name);
6141 Report_Errors := True;
6142 return;
6143 end if;
6145 Next (Assoc);
6146 end loop Find_Constraint;
6148 Discrim_Value := Expression (Assoc);
6150 if not Is_OK_Static_Expression (Discrim_Value) then
6151 Error_Msg_FE
6152 ("value for discriminant & must be static!",
6153 Discrim_Value, Discrim);
6154 Why_Not_Static (Discrim_Value);
6155 Report_Errors := True;
6156 return;
6157 end if;
6159 Search_For_Discriminant_Value : declare
6160 Low : Node_Id;
6161 High : Node_Id;
6163 UI_High : Uint;
6164 UI_Low : Uint;
6165 UI_Discrim_Value : constant Uint := Expr_Value (Discrim_Value);
6167 begin
6168 Find_Discrete_Value : while Present (Variant) loop
6169 Discrete_Choice := First (Discrete_Choices (Variant));
6170 while Present (Discrete_Choice) loop
6171 exit Find_Discrete_Value when
6172 Nkind (Discrete_Choice) = N_Others_Choice;
6174 Get_Index_Bounds (Discrete_Choice, Low, High);
6176 UI_Low := Expr_Value (Low);
6177 UI_High := Expr_Value (High);
6179 exit Find_Discrete_Value when
6180 UI_Low <= UI_Discrim_Value
6181 and then
6182 UI_High >= UI_Discrim_Value;
6184 Next (Discrete_Choice);
6185 end loop;
6187 Next_Non_Pragma (Variant);
6188 end loop Find_Discrete_Value;
6189 end Search_For_Discriminant_Value;
6191 if No (Variant) then
6192 Error_Msg_NE
6193 ("value of discriminant & is out of range", Discrim_Value, Discrim);
6194 Report_Errors := True;
6195 return;
6196 end if;
6198 -- If we have found the corresponding choice, recursively add its
6199 -- components to the Into list.
6201 Gather_Components
6202 (Empty, Component_List (Variant), Governed_By, Into, Report_Errors);
6203 end Gather_Components;
6205 ------------------------
6206 -- Get_Actual_Subtype --
6207 ------------------------
6209 function Get_Actual_Subtype (N : Node_Id) return Entity_Id is
6210 Typ : constant Entity_Id := Etype (N);
6211 Utyp : Entity_Id := Underlying_Type (Typ);
6212 Decl : Node_Id;
6213 Atyp : Entity_Id;
6215 begin
6216 if No (Utyp) then
6217 Utyp := Typ;
6218 end if;
6220 -- If what we have is an identifier that references a subprogram
6221 -- formal, or a variable or constant object, then we get the actual
6222 -- subtype from the referenced entity if one has been built.
6224 if Nkind (N) = N_Identifier
6225 and then
6226 (Is_Formal (Entity (N))
6227 or else Ekind (Entity (N)) = E_Constant
6228 or else Ekind (Entity (N)) = E_Variable)
6229 and then Present (Actual_Subtype (Entity (N)))
6230 then
6231 return Actual_Subtype (Entity (N));
6233 -- Actual subtype of unchecked union is always itself. We never need
6234 -- the "real" actual subtype. If we did, we couldn't get it anyway
6235 -- because the discriminant is not available. The restrictions on
6236 -- Unchecked_Union are designed to make sure that this is OK.
6238 elsif Is_Unchecked_Union (Base_Type (Utyp)) then
6239 return Typ;
6241 -- Here for the unconstrained case, we must find actual subtype
6242 -- No actual subtype is available, so we must build it on the fly.
6244 -- Checking the type, not the underlying type, for constrainedness
6245 -- seems to be necessary. Maybe all the tests should be on the type???
6247 elsif (not Is_Constrained (Typ))
6248 and then (Is_Array_Type (Utyp)
6249 or else (Is_Record_Type (Utyp)
6250 and then Has_Discriminants (Utyp)))
6251 and then not Has_Unknown_Discriminants (Utyp)
6252 and then not (Ekind (Utyp) = E_String_Literal_Subtype)
6253 then
6254 -- Nothing to do if in spec expression (why not???)
6256 if In_Spec_Expression then
6257 return Typ;
6259 elsif Is_Private_Type (Typ)
6260 and then not Has_Discriminants (Typ)
6261 then
6262 -- If the type has no discriminants, there is no subtype to
6263 -- build, even if the underlying type is discriminated.
6265 return Typ;
6267 -- Else build the actual subtype
6269 else
6270 Decl := Build_Actual_Subtype (Typ, N);
6271 Atyp := Defining_Identifier (Decl);
6273 -- If Build_Actual_Subtype generated a new declaration then use it
6275 if Atyp /= Typ then
6277 -- The actual subtype is an Itype, so analyze the declaration,
6278 -- but do not attach it to the tree, to get the type defined.
6280 Set_Parent (Decl, N);
6281 Set_Is_Itype (Atyp);
6282 Analyze (Decl, Suppress => All_Checks);
6283 Set_Associated_Node_For_Itype (Atyp, N);
6284 Set_Has_Delayed_Freeze (Atyp, False);
6286 -- We need to freeze the actual subtype immediately. This is
6287 -- needed, because otherwise this Itype will not get frozen
6288 -- at all, and it is always safe to freeze on creation because
6289 -- any associated types must be frozen at this point.
6291 Freeze_Itype (Atyp, N);
6292 return Atyp;
6294 -- Otherwise we did not build a declaration, so return original
6296 else
6297 return Typ;
6298 end if;
6299 end if;
6301 -- For all remaining cases, the actual subtype is the same as
6302 -- the nominal type.
6304 else
6305 return Typ;
6306 end if;
6307 end Get_Actual_Subtype;
6309 -------------------------------------
6310 -- Get_Actual_Subtype_If_Available --
6311 -------------------------------------
6313 function Get_Actual_Subtype_If_Available (N : Node_Id) return Entity_Id is
6314 Typ : constant Entity_Id := Etype (N);
6316 begin
6317 -- If what we have is an identifier that references a subprogram
6318 -- formal, or a variable or constant object, then we get the actual
6319 -- subtype from the referenced entity if one has been built.
6321 if Nkind (N) = N_Identifier
6322 and then
6323 (Is_Formal (Entity (N))
6324 or else Ekind (Entity (N)) = E_Constant
6325 or else Ekind (Entity (N)) = E_Variable)
6326 and then Present (Actual_Subtype (Entity (N)))
6327 then
6328 return Actual_Subtype (Entity (N));
6330 -- Otherwise the Etype of N is returned unchanged
6332 else
6333 return Typ;
6334 end if;
6335 end Get_Actual_Subtype_If_Available;
6337 ------------------------
6338 -- Get_Body_From_Stub --
6339 ------------------------
6341 function Get_Body_From_Stub (N : Node_Id) return Node_Id is
6342 begin
6343 return Proper_Body (Unit (Library_Unit (N)));
6344 end Get_Body_From_Stub;
6346 -------------------------------
6347 -- Get_Default_External_Name --
6348 -------------------------------
6350 function Get_Default_External_Name (E : Node_Or_Entity_Id) return Node_Id is
6351 begin
6352 Get_Decoded_Name_String (Chars (E));
6354 if Opt.External_Name_Imp_Casing = Uppercase then
6355 Set_Casing (All_Upper_Case);
6356 else
6357 Set_Casing (All_Lower_Case);
6358 end if;
6360 return
6361 Make_String_Literal (Sloc (E),
6362 Strval => String_From_Name_Buffer);
6363 end Get_Default_External_Name;
6365 --------------------------
6366 -- Get_Enclosing_Object --
6367 --------------------------
6369 function Get_Enclosing_Object (N : Node_Id) return Entity_Id is
6370 begin
6371 if Is_Entity_Name (N) then
6372 return Entity (N);
6373 else
6374 case Nkind (N) is
6375 when N_Indexed_Component |
6376 N_Slice |
6377 N_Selected_Component =>
6379 -- If not generating code, a dereference may be left implicit.
6380 -- In thoses cases, return Empty.
6382 if Is_Access_Type (Etype (Prefix (N))) then
6383 return Empty;
6384 else
6385 return Get_Enclosing_Object (Prefix (N));
6386 end if;
6388 when N_Type_Conversion =>
6389 return Get_Enclosing_Object (Expression (N));
6391 when others =>
6392 return Empty;
6393 end case;
6394 end if;
6395 end Get_Enclosing_Object;
6397 ---------------------------
6398 -- Get_Enum_Lit_From_Pos --
6399 ---------------------------
6401 function Get_Enum_Lit_From_Pos
6402 (T : Entity_Id;
6403 Pos : Uint;
6404 Loc : Source_Ptr) return Node_Id
6406 Btyp : Entity_Id := Base_Type (T);
6407 Lit : Node_Id;
6409 begin
6410 -- In the case where the literal is of type Character, Wide_Character
6411 -- or Wide_Wide_Character or of a type derived from them, there needs
6412 -- to be some special handling since there is no explicit chain of
6413 -- literals to search. Instead, an N_Character_Literal node is created
6414 -- with the appropriate Char_Code and Chars fields.
6416 if Is_Standard_Character_Type (T) then
6417 Set_Character_Literal_Name (UI_To_CC (Pos));
6418 return
6419 Make_Character_Literal (Loc,
6420 Chars => Name_Find,
6421 Char_Literal_Value => Pos);
6423 -- For all other cases, we have a complete table of literals, and
6424 -- we simply iterate through the chain of literal until the one
6425 -- with the desired position value is found.
6428 else
6429 if Is_Private_Type (Btyp) and then Present (Full_View (Btyp)) then
6430 Btyp := Full_View (Btyp);
6431 end if;
6433 Lit := First_Literal (Btyp);
6434 for J in 1 .. UI_To_Int (Pos) loop
6435 Next_Literal (Lit);
6436 end loop;
6438 return New_Occurrence_Of (Lit, Loc);
6439 end if;
6440 end Get_Enum_Lit_From_Pos;
6442 ---------------------------------
6443 -- Get_Ensures_From_CTC_Pragma --
6444 ---------------------------------
6446 function Get_Ensures_From_CTC_Pragma (N : Node_Id) return Node_Id is
6447 Args : constant List_Id := Pragma_Argument_Associations (N);
6448 Res : Node_Id;
6450 begin
6451 if List_Length (Args) = 4 then
6452 Res := Pick (Args, 4);
6454 elsif List_Length (Args) = 3 then
6455 Res := Pick (Args, 3);
6457 if Chars (Res) /= Name_Ensures then
6458 Res := Empty;
6459 end if;
6461 else
6462 Res := Empty;
6463 end if;
6465 return Res;
6466 end Get_Ensures_From_CTC_Pragma;
6468 ------------------------
6469 -- Get_Generic_Entity --
6470 ------------------------
6472 function Get_Generic_Entity (N : Node_Id) return Entity_Id is
6473 Ent : constant Entity_Id := Entity (Name (N));
6474 begin
6475 if Present (Renamed_Object (Ent)) then
6476 return Renamed_Object (Ent);
6477 else
6478 return Ent;
6479 end if;
6480 end Get_Generic_Entity;
6482 -------------------------------------
6483 -- Get_Incomplete_View_Of_Ancestor --
6484 -------------------------------------
6486 function Get_Incomplete_View_Of_Ancestor (E : Entity_Id) return Entity_Id is
6487 Cur_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
6488 Par_Scope : Entity_Id;
6489 Par_Type : Entity_Id;
6491 begin
6492 -- The incomplete view of an ancestor is only relevant for private
6493 -- derived types in child units.
6495 if not Is_Derived_Type (E)
6496 or else not Is_Child_Unit (Cur_Unit)
6497 then
6498 return Empty;
6500 else
6501 Par_Scope := Scope (Cur_Unit);
6502 if No (Par_Scope) then
6503 return Empty;
6504 end if;
6506 Par_Type := Etype (Base_Type (E));
6508 -- Traverse list of ancestor types until we find one declared in
6509 -- a parent or grandparent unit (two levels seem sufficient).
6511 while Present (Par_Type) loop
6512 if Scope (Par_Type) = Par_Scope
6513 or else Scope (Par_Type) = Scope (Par_Scope)
6514 then
6515 return Par_Type;
6517 elsif not Is_Derived_Type (Par_Type) then
6518 return Empty;
6520 else
6521 Par_Type := Etype (Base_Type (Par_Type));
6522 end if;
6523 end loop;
6525 -- If none found, there is no relevant ancestor type.
6527 return Empty;
6528 end if;
6529 end Get_Incomplete_View_Of_Ancestor;
6531 ----------------------
6532 -- Get_Index_Bounds --
6533 ----------------------
6535 procedure Get_Index_Bounds (N : Node_Id; L, H : out Node_Id) is
6536 Kind : constant Node_Kind := Nkind (N);
6537 R : Node_Id;
6539 begin
6540 if Kind = N_Range then
6541 L := Low_Bound (N);
6542 H := High_Bound (N);
6544 elsif Kind = N_Subtype_Indication then
6545 R := Range_Expression (Constraint (N));
6547 if R = Error then
6548 L := Error;
6549 H := Error;
6550 return;
6552 else
6553 L := Low_Bound (Range_Expression (Constraint (N)));
6554 H := High_Bound (Range_Expression (Constraint (N)));
6555 end if;
6557 elsif Is_Entity_Name (N) and then Is_Type (Entity (N)) then
6558 if Error_Posted (Scalar_Range (Entity (N))) then
6559 L := Error;
6560 H := Error;
6562 elsif Nkind (Scalar_Range (Entity (N))) = N_Subtype_Indication then
6563 Get_Index_Bounds (Scalar_Range (Entity (N)), L, H);
6565 else
6566 L := Low_Bound (Scalar_Range (Entity (N)));
6567 H := High_Bound (Scalar_Range (Entity (N)));
6568 end if;
6570 else
6571 -- N is an expression, indicating a range with one value
6573 L := N;
6574 H := N;
6575 end if;
6576 end Get_Index_Bounds;
6578 ----------------------------------
6579 -- Get_Library_Unit_Name_string --
6580 ----------------------------------
6582 procedure Get_Library_Unit_Name_String (Decl_Node : Node_Id) is
6583 Unit_Name_Id : constant Unit_Name_Type := Get_Unit_Name (Decl_Node);
6585 begin
6586 Get_Unit_Name_String (Unit_Name_Id);
6588 -- Remove seven last character (" (spec)" or " (body)")
6590 Name_Len := Name_Len - 7;
6591 pragma Assert (Name_Buffer (Name_Len + 1) = ' ');
6592 end Get_Library_Unit_Name_String;
6594 ------------------------
6595 -- Get_Name_Entity_Id --
6596 ------------------------
6598 function Get_Name_Entity_Id (Id : Name_Id) return Entity_Id is
6599 begin
6600 return Entity_Id (Get_Name_Table_Info (Id));
6601 end Get_Name_Entity_Id;
6603 ------------------------------
6604 -- Get_Name_From_CTC_Pragma --
6605 ------------------------------
6607 function Get_Name_From_CTC_Pragma (N : Node_Id) return String_Id is
6608 Arg : constant Node_Id :=
6609 Get_Pragma_Arg (First (Pragma_Argument_Associations (N)));
6610 begin
6611 return Strval (Expr_Value_S (Arg));
6612 end Get_Name_From_CTC_Pragma;
6614 -------------------
6615 -- Get_Pragma_Id --
6616 -------------------
6618 function Get_Pragma_Id (N : Node_Id) return Pragma_Id is
6619 begin
6620 return Get_Pragma_Id (Pragma_Name (N));
6621 end Get_Pragma_Id;
6623 ---------------------------
6624 -- Get_Referenced_Object --
6625 ---------------------------
6627 function Get_Referenced_Object (N : Node_Id) return Node_Id is
6628 R : Node_Id;
6630 begin
6631 R := N;
6632 while Is_Entity_Name (R)
6633 and then Present (Renamed_Object (Entity (R)))
6634 loop
6635 R := Renamed_Object (Entity (R));
6636 end loop;
6638 return R;
6639 end Get_Referenced_Object;
6641 ------------------------
6642 -- Get_Renamed_Entity --
6643 ------------------------
6645 function Get_Renamed_Entity (E : Entity_Id) return Entity_Id is
6646 R : Entity_Id;
6648 begin
6649 R := E;
6650 while Present (Renamed_Entity (R)) loop
6651 R := Renamed_Entity (R);
6652 end loop;
6654 return R;
6655 end Get_Renamed_Entity;
6657 ----------------------------------
6658 -- Get_Requires_From_CTC_Pragma --
6659 ----------------------------------
6661 function Get_Requires_From_CTC_Pragma (N : Node_Id) return Node_Id is
6662 Args : constant List_Id := Pragma_Argument_Associations (N);
6663 Res : Node_Id;
6665 begin
6666 if List_Length (Args) >= 3 then
6667 Res := Pick (Args, 3);
6669 if Chars (Res) /= Name_Requires then
6670 Res := Empty;
6671 end if;
6673 else
6674 Res := Empty;
6675 end if;
6677 return Res;
6678 end Get_Requires_From_CTC_Pragma;
6680 -------------------------
6681 -- Get_Subprogram_Body --
6682 -------------------------
6684 function Get_Subprogram_Body (E : Entity_Id) return Node_Id is
6685 Decl : Node_Id;
6687 begin
6688 Decl := Unit_Declaration_Node (E);
6690 if Nkind (Decl) = N_Subprogram_Body then
6691 return Decl;
6693 -- The below comment is bad, because it is possible for
6694 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
6696 else -- Nkind (Decl) = N_Subprogram_Declaration
6698 if Present (Corresponding_Body (Decl)) then
6699 return Unit_Declaration_Node (Corresponding_Body (Decl));
6701 -- Imported subprogram case
6703 else
6704 return Empty;
6705 end if;
6706 end if;
6707 end Get_Subprogram_Body;
6709 ---------------------------
6710 -- Get_Subprogram_Entity --
6711 ---------------------------
6713 function Get_Subprogram_Entity (Nod : Node_Id) return Entity_Id is
6714 Subp : Node_Id;
6715 Subp_Id : Entity_Id;
6717 begin
6718 if Nkind (Nod) = N_Accept_Statement then
6719 Subp := Entry_Direct_Name (Nod);
6721 elsif Nkind (Nod) = N_Slice then
6722 Subp := Prefix (Nod);
6724 else
6725 Subp := Name (Nod);
6726 end if;
6728 -- Strip the subprogram call
6730 loop
6731 if Nkind_In (Subp, N_Explicit_Dereference,
6732 N_Indexed_Component,
6733 N_Selected_Component)
6734 then
6735 Subp := Prefix (Subp);
6737 elsif Nkind_In (Subp, N_Type_Conversion,
6738 N_Unchecked_Type_Conversion)
6739 then
6740 Subp := Expression (Subp);
6742 else
6743 exit;
6744 end if;
6745 end loop;
6747 -- Extract the entity of the subprogram call
6749 if Is_Entity_Name (Subp) then
6750 Subp_Id := Entity (Subp);
6752 if Ekind (Subp_Id) = E_Access_Subprogram_Type then
6753 Subp_Id := Directly_Designated_Type (Subp_Id);
6754 end if;
6756 if Is_Subprogram (Subp_Id) then
6757 return Subp_Id;
6758 else
6759 return Empty;
6760 end if;
6762 -- The search did not find a construct that denotes a subprogram
6764 else
6765 return Empty;
6766 end if;
6767 end Get_Subprogram_Entity;
6769 -----------------------------
6770 -- Get_Task_Body_Procedure --
6771 -----------------------------
6773 function Get_Task_Body_Procedure (E : Entity_Id) return Node_Id is
6774 begin
6775 -- Note: A task type may be the completion of a private type with
6776 -- discriminants. When performing elaboration checks on a task
6777 -- declaration, the current view of the type may be the private one,
6778 -- and the procedure that holds the body of the task is held in its
6779 -- underlying type.
6781 -- This is an odd function, why not have Task_Body_Procedure do
6782 -- the following digging???
6784 return Task_Body_Procedure (Underlying_Type (Root_Type (E)));
6785 end Get_Task_Body_Procedure;
6787 -----------------------
6788 -- Has_Access_Values --
6789 -----------------------
6791 function Has_Access_Values (T : Entity_Id) return Boolean is
6792 Typ : constant Entity_Id := Underlying_Type (T);
6794 begin
6795 -- Case of a private type which is not completed yet. This can only
6796 -- happen in the case of a generic format type appearing directly, or
6797 -- as a component of the type to which this function is being applied
6798 -- at the top level. Return False in this case, since we certainly do
6799 -- not know that the type contains access types.
6801 if No (Typ) then
6802 return False;
6804 elsif Is_Access_Type (Typ) then
6805 return True;
6807 elsif Is_Array_Type (Typ) then
6808 return Has_Access_Values (Component_Type (Typ));
6810 elsif Is_Record_Type (Typ) then
6811 declare
6812 Comp : Entity_Id;
6814 begin
6815 -- Loop to Check components
6817 Comp := First_Component_Or_Discriminant (Typ);
6818 while Present (Comp) loop
6820 -- Check for access component, tag field does not count, even
6821 -- though it is implemented internally using an access type.
6823 if Has_Access_Values (Etype (Comp))
6824 and then Chars (Comp) /= Name_uTag
6825 then
6826 return True;
6827 end if;
6829 Next_Component_Or_Discriminant (Comp);
6830 end loop;
6831 end;
6833 return False;
6835 else
6836 return False;
6837 end if;
6838 end Has_Access_Values;
6840 ------------------------------
6841 -- Has_Compatible_Alignment --
6842 ------------------------------
6844 function Has_Compatible_Alignment
6845 (Obj : Entity_Id;
6846 Expr : Node_Id) return Alignment_Result
6848 function Has_Compatible_Alignment_Internal
6849 (Obj : Entity_Id;
6850 Expr : Node_Id;
6851 Default : Alignment_Result) return Alignment_Result;
6852 -- This is the internal recursive function that actually does the work.
6853 -- There is one additional parameter, which says what the result should
6854 -- be if no alignment information is found, and there is no definite
6855 -- indication of compatible alignments. At the outer level, this is set
6856 -- to Unknown, but for internal recursive calls in the case where types
6857 -- are known to be correct, it is set to Known_Compatible.
6859 ---------------------------------------
6860 -- Has_Compatible_Alignment_Internal --
6861 ---------------------------------------
6863 function Has_Compatible_Alignment_Internal
6864 (Obj : Entity_Id;
6865 Expr : Node_Id;
6866 Default : Alignment_Result) return Alignment_Result
6868 Result : Alignment_Result := Known_Compatible;
6869 -- Holds the current status of the result. Note that once a value of
6870 -- Known_Incompatible is set, it is sticky and does not get changed
6871 -- to Unknown (the value in Result only gets worse as we go along,
6872 -- never better).
6874 Offs : Uint := No_Uint;
6875 -- Set to a factor of the offset from the base object when Expr is a
6876 -- selected or indexed component, based on Component_Bit_Offset and
6877 -- Component_Size respectively. A negative value is used to represent
6878 -- a value which is not known at compile time.
6880 procedure Check_Prefix;
6881 -- Checks the prefix recursively in the case where the expression
6882 -- is an indexed or selected component.
6884 procedure Set_Result (R : Alignment_Result);
6885 -- If R represents a worse outcome (unknown instead of known
6886 -- compatible, or known incompatible), then set Result to R.
6888 ------------------
6889 -- Check_Prefix --
6890 ------------------
6892 procedure Check_Prefix is
6893 begin
6894 -- The subtlety here is that in doing a recursive call to check
6895 -- the prefix, we have to decide what to do in the case where we
6896 -- don't find any specific indication of an alignment problem.
6898 -- At the outer level, we normally set Unknown as the result in
6899 -- this case, since we can only set Known_Compatible if we really
6900 -- know that the alignment value is OK, but for the recursive
6901 -- call, in the case where the types match, and we have not
6902 -- specified a peculiar alignment for the object, we are only
6903 -- concerned about suspicious rep clauses, the default case does
6904 -- not affect us, since the compiler will, in the absence of such
6905 -- rep clauses, ensure that the alignment is correct.
6907 if Default = Known_Compatible
6908 or else
6909 (Etype (Obj) = Etype (Expr)
6910 and then (Unknown_Alignment (Obj)
6911 or else
6912 Alignment (Obj) = Alignment (Etype (Obj))))
6913 then
6914 Set_Result
6915 (Has_Compatible_Alignment_Internal
6916 (Obj, Prefix (Expr), Known_Compatible));
6918 -- In all other cases, we need a full check on the prefix
6920 else
6921 Set_Result
6922 (Has_Compatible_Alignment_Internal
6923 (Obj, Prefix (Expr), Unknown));
6924 end if;
6925 end Check_Prefix;
6927 ----------------
6928 -- Set_Result --
6929 ----------------
6931 procedure Set_Result (R : Alignment_Result) is
6932 begin
6933 if R > Result then
6934 Result := R;
6935 end if;
6936 end Set_Result;
6938 -- Start of processing for Has_Compatible_Alignment_Internal
6940 begin
6941 -- If Expr is a selected component, we must make sure there is no
6942 -- potentially troublesome component clause, and that the record is
6943 -- not packed.
6945 if Nkind (Expr) = N_Selected_Component then
6947 -- Packed record always generate unknown alignment
6949 if Is_Packed (Etype (Prefix (Expr))) then
6950 Set_Result (Unknown);
6951 end if;
6953 -- Check prefix and component offset
6955 Check_Prefix;
6956 Offs := Component_Bit_Offset (Entity (Selector_Name (Expr)));
6958 -- If Expr is an indexed component, we must make sure there is no
6959 -- potentially troublesome Component_Size clause and that the array
6960 -- is not bit-packed.
6962 elsif Nkind (Expr) = N_Indexed_Component then
6963 declare
6964 Typ : constant Entity_Id := Etype (Prefix (Expr));
6965 Ind : constant Node_Id := First_Index (Typ);
6967 begin
6968 -- Bit packed array always generates unknown alignment
6970 if Is_Bit_Packed_Array (Typ) then
6971 Set_Result (Unknown);
6972 end if;
6974 -- Check prefix and component offset
6976 Check_Prefix;
6977 Offs := Component_Size (Typ);
6979 -- Small optimization: compute the full offset when possible
6981 if Offs /= No_Uint
6982 and then Offs > Uint_0
6983 and then Present (Ind)
6984 and then Nkind (Ind) = N_Range
6985 and then Compile_Time_Known_Value (Low_Bound (Ind))
6986 and then Compile_Time_Known_Value (First (Expressions (Expr)))
6987 then
6988 Offs := Offs * (Expr_Value (First (Expressions (Expr)))
6989 - Expr_Value (Low_Bound ((Ind))));
6990 end if;
6991 end;
6992 end if;
6994 -- If we have a null offset, the result is entirely determined by
6995 -- the base object and has already been computed recursively.
6997 if Offs = Uint_0 then
6998 null;
7000 -- Case where we know the alignment of the object
7002 elsif Known_Alignment (Obj) then
7003 declare
7004 ObjA : constant Uint := Alignment (Obj);
7005 ExpA : Uint := No_Uint;
7006 SizA : Uint := No_Uint;
7008 begin
7009 -- If alignment of Obj is 1, then we are always OK
7011 if ObjA = 1 then
7012 Set_Result (Known_Compatible);
7014 -- Alignment of Obj is greater than 1, so we need to check
7016 else
7017 -- If we have an offset, see if it is compatible
7019 if Offs /= No_Uint and Offs > Uint_0 then
7020 if Offs mod (System_Storage_Unit * ObjA) /= 0 then
7021 Set_Result (Known_Incompatible);
7022 end if;
7024 -- See if Expr is an object with known alignment
7026 elsif Is_Entity_Name (Expr)
7027 and then Known_Alignment (Entity (Expr))
7028 then
7029 ExpA := Alignment (Entity (Expr));
7031 -- Otherwise, we can use the alignment of the type of
7032 -- Expr given that we already checked for
7033 -- discombobulating rep clauses for the cases of indexed
7034 -- and selected components above.
7036 elsif Known_Alignment (Etype (Expr)) then
7037 ExpA := Alignment (Etype (Expr));
7039 -- Otherwise the alignment is unknown
7041 else
7042 Set_Result (Default);
7043 end if;
7045 -- If we got an alignment, see if it is acceptable
7047 if ExpA /= No_Uint and then ExpA < ObjA then
7048 Set_Result (Known_Incompatible);
7049 end if;
7051 -- If Expr is not a piece of a larger object, see if size
7052 -- is given. If so, check that it is not too small for the
7053 -- required alignment.
7055 if Offs /= No_Uint then
7056 null;
7058 -- See if Expr is an object with known size
7060 elsif Is_Entity_Name (Expr)
7061 and then Known_Static_Esize (Entity (Expr))
7062 then
7063 SizA := Esize (Entity (Expr));
7065 -- Otherwise, we check the object size of the Expr type
7067 elsif Known_Static_Esize (Etype (Expr)) then
7068 SizA := Esize (Etype (Expr));
7069 end if;
7071 -- If we got a size, see if it is a multiple of the Obj
7072 -- alignment, if not, then the alignment cannot be
7073 -- acceptable, since the size is always a multiple of the
7074 -- alignment.
7076 if SizA /= No_Uint then
7077 if SizA mod (ObjA * Ttypes.System_Storage_Unit) /= 0 then
7078 Set_Result (Known_Incompatible);
7079 end if;
7080 end if;
7081 end if;
7082 end;
7084 -- If we do not know required alignment, any non-zero offset is a
7085 -- potential problem (but certainly may be OK, so result is unknown).
7087 elsif Offs /= No_Uint then
7088 Set_Result (Unknown);
7090 -- If we can't find the result by direct comparison of alignment
7091 -- values, then there is still one case that we can determine known
7092 -- result, and that is when we can determine that the types are the
7093 -- same, and no alignments are specified. Then we known that the
7094 -- alignments are compatible, even if we don't know the alignment
7095 -- value in the front end.
7097 elsif Etype (Obj) = Etype (Expr) then
7099 -- Types are the same, but we have to check for possible size
7100 -- and alignments on the Expr object that may make the alignment
7101 -- different, even though the types are the same.
7103 if Is_Entity_Name (Expr) then
7105 -- First check alignment of the Expr object. Any alignment less
7106 -- than Maximum_Alignment is worrisome since this is the case
7107 -- where we do not know the alignment of Obj.
7109 if Known_Alignment (Entity (Expr))
7110 and then
7111 UI_To_Int (Alignment (Entity (Expr))) <
7112 Ttypes.Maximum_Alignment
7113 then
7114 Set_Result (Unknown);
7116 -- Now check size of Expr object. Any size that is not an
7117 -- even multiple of Maximum_Alignment is also worrisome
7118 -- since it may cause the alignment of the object to be less
7119 -- than the alignment of the type.
7121 elsif Known_Static_Esize (Entity (Expr))
7122 and then
7123 (UI_To_Int (Esize (Entity (Expr))) mod
7124 (Ttypes.Maximum_Alignment * Ttypes.System_Storage_Unit))
7125 /= 0
7126 then
7127 Set_Result (Unknown);
7129 -- Otherwise same type is decisive
7131 else
7132 Set_Result (Known_Compatible);
7133 end if;
7134 end if;
7136 -- Another case to deal with is when there is an explicit size or
7137 -- alignment clause when the types are not the same. If so, then the
7138 -- result is Unknown. We don't need to do this test if the Default is
7139 -- Unknown, since that result will be set in any case.
7141 elsif Default /= Unknown
7142 and then (Has_Size_Clause (Etype (Expr))
7143 or else
7144 Has_Alignment_Clause (Etype (Expr)))
7145 then
7146 Set_Result (Unknown);
7148 -- If no indication found, set default
7150 else
7151 Set_Result (Default);
7152 end if;
7154 -- Return worst result found
7156 return Result;
7157 end Has_Compatible_Alignment_Internal;
7159 -- Start of processing for Has_Compatible_Alignment
7161 begin
7162 -- If Obj has no specified alignment, then set alignment from the type
7163 -- alignment. Perhaps we should always do this, but for sure we should
7164 -- do it when there is an address clause since we can do more if the
7165 -- alignment is known.
7167 if Unknown_Alignment (Obj) then
7168 Set_Alignment (Obj, Alignment (Etype (Obj)));
7169 end if;
7171 -- Now do the internal call that does all the work
7173 return Has_Compatible_Alignment_Internal (Obj, Expr, Unknown);
7174 end Has_Compatible_Alignment;
7176 ----------------------
7177 -- Has_Declarations --
7178 ----------------------
7180 function Has_Declarations (N : Node_Id) return Boolean is
7181 begin
7182 return Nkind_In (Nkind (N), N_Accept_Statement,
7183 N_Block_Statement,
7184 N_Compilation_Unit_Aux,
7185 N_Entry_Body,
7186 N_Package_Body,
7187 N_Protected_Body,
7188 N_Subprogram_Body,
7189 N_Task_Body,
7190 N_Package_Specification);
7191 end Has_Declarations;
7193 -------------------
7194 -- Has_Denormals --
7195 -------------------
7197 function Has_Denormals (E : Entity_Id) return Boolean is
7198 begin
7199 return Is_Floating_Point_Type (E)
7200 and then Denorm_On_Target
7201 and then not Vax_Float (E);
7202 end Has_Denormals;
7204 -------------------------------------------
7205 -- Has_Discriminant_Dependent_Constraint --
7206 -------------------------------------------
7208 function Has_Discriminant_Dependent_Constraint
7209 (Comp : Entity_Id) return Boolean
7211 Comp_Decl : constant Node_Id := Parent (Comp);
7212 Subt_Indic : constant Node_Id :=
7213 Subtype_Indication (Component_Definition (Comp_Decl));
7214 Constr : Node_Id;
7215 Assn : Node_Id;
7217 begin
7218 if Nkind (Subt_Indic) = N_Subtype_Indication then
7219 Constr := Constraint (Subt_Indic);
7221 if Nkind (Constr) = N_Index_Or_Discriminant_Constraint then
7222 Assn := First (Constraints (Constr));
7223 while Present (Assn) loop
7224 case Nkind (Assn) is
7225 when N_Subtype_Indication |
7226 N_Range |
7227 N_Identifier
7229 if Depends_On_Discriminant (Assn) then
7230 return True;
7231 end if;
7233 when N_Discriminant_Association =>
7234 if Depends_On_Discriminant (Expression (Assn)) then
7235 return True;
7236 end if;
7238 when others =>
7239 null;
7241 end case;
7243 Next (Assn);
7244 end loop;
7245 end if;
7246 end if;
7248 return False;
7249 end Has_Discriminant_Dependent_Constraint;
7251 --------------------------
7252 -- Has_Enabled_Property --
7253 --------------------------
7255 function Has_Enabled_Property
7256 (State_Id : Node_Id;
7257 Prop_Nam : Name_Id) return Boolean
7259 Decl : constant Node_Id := Parent (State_Id);
7260 Opt : Node_Id;
7261 Opt_Nam : Node_Id;
7262 Prop : Node_Id;
7263 Props : Node_Id;
7265 begin
7266 -- The declaration of an external abstract state appears as an extension
7267 -- aggregate. If this is not the case, properties can never be set.
7269 if Nkind (Decl) /= N_Extension_Aggregate then
7270 return False;
7271 end if;
7273 -- When External appears as a simple option, it automatically enables
7274 -- all properties.
7276 Opt := First (Expressions (Decl));
7277 while Present (Opt) loop
7278 if Nkind (Opt) = N_Identifier
7279 and then Chars (Opt) = Name_External
7280 then
7281 return True;
7282 end if;
7284 Next (Opt);
7285 end loop;
7287 -- When External specifies particular properties, inspect those and
7288 -- find the desired one (if any).
7290 Opt := First (Component_Associations (Decl));
7291 while Present (Opt) loop
7292 Opt_Nam := First (Choices (Opt));
7294 if Nkind (Opt_Nam) = N_Identifier
7295 and then Chars (Opt_Nam) = Name_External
7296 then
7297 Props := Expression (Opt);
7299 -- Multiple properties appear as an aggregate
7301 if Nkind (Props) = N_Aggregate then
7303 -- Simple property form
7305 Prop := First (Expressions (Props));
7306 while Present (Prop) loop
7307 if Chars (Prop) = Prop_Nam then
7308 return True;
7309 end if;
7311 Next (Prop);
7312 end loop;
7314 -- Property with expression form
7316 Prop := First (Component_Associations (Props));
7317 while Present (Prop) loop
7318 if Chars (Prop) = Prop_Nam then
7319 return Is_True (Expr_Value (Expression (Prop)));
7320 end if;
7322 Next (Prop);
7323 end loop;
7325 -- Single property
7327 else
7328 return Chars (Props) = Prop_Nam;
7329 end if;
7330 end if;
7332 Next (Opt);
7333 end loop;
7335 return False;
7336 end Has_Enabled_Property;
7338 --------------------
7339 -- Has_Infinities --
7340 --------------------
7342 function Has_Infinities (E : Entity_Id) return Boolean is
7343 begin
7344 return
7345 Is_Floating_Point_Type (E)
7346 and then Nkind (Scalar_Range (E)) = N_Range
7347 and then Includes_Infinities (Scalar_Range (E));
7348 end Has_Infinities;
7350 --------------------
7351 -- Has_Interfaces --
7352 --------------------
7354 function Has_Interfaces
7355 (T : Entity_Id;
7356 Use_Full_View : Boolean := True) return Boolean
7358 Typ : Entity_Id := Base_Type (T);
7360 begin
7361 -- Handle concurrent types
7363 if Is_Concurrent_Type (Typ) then
7364 Typ := Corresponding_Record_Type (Typ);
7365 end if;
7367 if not Present (Typ)
7368 or else not Is_Record_Type (Typ)
7369 or else not Is_Tagged_Type (Typ)
7370 then
7371 return False;
7372 end if;
7374 -- Handle private types
7376 if Use_Full_View
7377 and then Present (Full_View (Typ))
7378 then
7379 Typ := Full_View (Typ);
7380 end if;
7382 -- Handle concurrent record types
7384 if Is_Concurrent_Record_Type (Typ)
7385 and then Is_Non_Empty_List (Abstract_Interface_List (Typ))
7386 then
7387 return True;
7388 end if;
7390 loop
7391 if Is_Interface (Typ)
7392 or else
7393 (Is_Record_Type (Typ)
7394 and then Present (Interfaces (Typ))
7395 and then not Is_Empty_Elmt_List (Interfaces (Typ)))
7396 then
7397 return True;
7398 end if;
7400 exit when Etype (Typ) = Typ
7402 -- Handle private types
7404 or else (Present (Full_View (Etype (Typ)))
7405 and then Full_View (Etype (Typ)) = Typ)
7407 -- Protect the frontend against wrong source with cyclic
7408 -- derivations
7410 or else Etype (Typ) = T;
7412 -- Climb to the ancestor type handling private types
7414 if Present (Full_View (Etype (Typ))) then
7415 Typ := Full_View (Etype (Typ));
7416 else
7417 Typ := Etype (Typ);
7418 end if;
7419 end loop;
7421 return False;
7422 end Has_Interfaces;
7424 ---------------------------------
7425 -- Has_No_Obvious_Side_Effects --
7426 ---------------------------------
7428 function Has_No_Obvious_Side_Effects (N : Node_Id) return Boolean is
7429 begin
7430 -- For now, just handle literals, constants, and non-volatile
7431 -- variables and expressions combining these with operators or
7432 -- short circuit forms.
7434 if Nkind (N) in N_Numeric_Or_String_Literal then
7435 return True;
7437 elsif Nkind (N) = N_Character_Literal then
7438 return True;
7440 elsif Nkind (N) in N_Unary_Op then
7441 return Has_No_Obvious_Side_Effects (Right_Opnd (N));
7443 elsif Nkind (N) in N_Binary_Op or else Nkind (N) in N_Short_Circuit then
7444 return Has_No_Obvious_Side_Effects (Left_Opnd (N))
7445 and then
7446 Has_No_Obvious_Side_Effects (Right_Opnd (N));
7448 elsif Nkind (N) = N_Expression_With_Actions
7449 and then
7450 Is_Empty_List (Actions (N))
7451 then
7452 return Has_No_Obvious_Side_Effects (Expression (N));
7454 elsif Nkind (N) in N_Has_Entity then
7455 return Present (Entity (N))
7456 and then Ekind_In (Entity (N), E_Variable,
7457 E_Constant,
7458 E_Enumeration_Literal,
7459 E_In_Parameter,
7460 E_Out_Parameter,
7461 E_In_Out_Parameter)
7462 and then not Is_Volatile (Entity (N));
7464 else
7465 return False;
7466 end if;
7467 end Has_No_Obvious_Side_Effects;
7469 ------------------------
7470 -- Has_Null_Exclusion --
7471 ------------------------
7473 function Has_Null_Exclusion (N : Node_Id) return Boolean is
7474 begin
7475 case Nkind (N) is
7476 when N_Access_Definition |
7477 N_Access_Function_Definition |
7478 N_Access_Procedure_Definition |
7479 N_Access_To_Object_Definition |
7480 N_Allocator |
7481 N_Derived_Type_Definition |
7482 N_Function_Specification |
7483 N_Subtype_Declaration =>
7484 return Null_Exclusion_Present (N);
7486 when N_Component_Definition |
7487 N_Formal_Object_Declaration |
7488 N_Object_Renaming_Declaration =>
7489 if Present (Subtype_Mark (N)) then
7490 return Null_Exclusion_Present (N);
7491 else pragma Assert (Present (Access_Definition (N)));
7492 return Null_Exclusion_Present (Access_Definition (N));
7493 end if;
7495 when N_Discriminant_Specification =>
7496 if Nkind (Discriminant_Type (N)) = N_Access_Definition then
7497 return Null_Exclusion_Present (Discriminant_Type (N));
7498 else
7499 return Null_Exclusion_Present (N);
7500 end if;
7502 when N_Object_Declaration =>
7503 if Nkind (Object_Definition (N)) = N_Access_Definition then
7504 return Null_Exclusion_Present (Object_Definition (N));
7505 else
7506 return Null_Exclusion_Present (N);
7507 end if;
7509 when N_Parameter_Specification =>
7510 if Nkind (Parameter_Type (N)) = N_Access_Definition then
7511 return Null_Exclusion_Present (Parameter_Type (N));
7512 else
7513 return Null_Exclusion_Present (N);
7514 end if;
7516 when others =>
7517 return False;
7519 end case;
7520 end Has_Null_Exclusion;
7522 ------------------------
7523 -- Has_Null_Extension --
7524 ------------------------
7526 function Has_Null_Extension (T : Entity_Id) return Boolean is
7527 B : constant Entity_Id := Base_Type (T);
7528 Comps : Node_Id;
7529 Ext : Node_Id;
7531 begin
7532 if Nkind (Parent (B)) = N_Full_Type_Declaration
7533 and then Present (Record_Extension_Part (Type_Definition (Parent (B))))
7534 then
7535 Ext := Record_Extension_Part (Type_Definition (Parent (B)));
7537 if Present (Ext) then
7538 if Null_Present (Ext) then
7539 return True;
7540 else
7541 Comps := Component_List (Ext);
7543 -- The null component list is rewritten during analysis to
7544 -- include the parent component. Any other component indicates
7545 -- that the extension was not originally null.
7547 return Null_Present (Comps)
7548 or else No (Next (First (Component_Items (Comps))));
7549 end if;
7550 else
7551 return False;
7552 end if;
7554 else
7555 return False;
7556 end if;
7557 end Has_Null_Extension;
7559 -------------------------------
7560 -- Has_Overriding_Initialize --
7561 -------------------------------
7563 function Has_Overriding_Initialize (T : Entity_Id) return Boolean is
7564 BT : constant Entity_Id := Base_Type (T);
7565 P : Elmt_Id;
7567 begin
7568 if Is_Controlled (BT) then
7569 if Is_RTU (Scope (BT), Ada_Finalization) then
7570 return False;
7572 elsif Present (Primitive_Operations (BT)) then
7573 P := First_Elmt (Primitive_Operations (BT));
7574 while Present (P) loop
7575 declare
7576 Init : constant Entity_Id := Node (P);
7577 Formal : constant Entity_Id := First_Formal (Init);
7578 begin
7579 if Ekind (Init) = E_Procedure
7580 and then Chars (Init) = Name_Initialize
7581 and then Comes_From_Source (Init)
7582 and then Present (Formal)
7583 and then Etype (Formal) = BT
7584 and then No (Next_Formal (Formal))
7585 and then (Ada_Version < Ada_2012
7586 or else not Null_Present (Parent (Init)))
7587 then
7588 return True;
7589 end if;
7590 end;
7592 Next_Elmt (P);
7593 end loop;
7594 end if;
7596 -- Here if type itself does not have a non-null Initialize operation:
7597 -- check immediate ancestor.
7599 if Is_Derived_Type (BT)
7600 and then Has_Overriding_Initialize (Etype (BT))
7601 then
7602 return True;
7603 end if;
7604 end if;
7606 return False;
7607 end Has_Overriding_Initialize;
7609 --------------------------------------
7610 -- Has_Preelaborable_Initialization --
7611 --------------------------------------
7613 function Has_Preelaborable_Initialization (E : Entity_Id) return Boolean is
7614 Has_PE : Boolean;
7616 procedure Check_Components (E : Entity_Id);
7617 -- Check component/discriminant chain, sets Has_PE False if a component
7618 -- or discriminant does not meet the preelaborable initialization rules.
7620 ----------------------
7621 -- Check_Components --
7622 ----------------------
7624 procedure Check_Components (E : Entity_Id) is
7625 Ent : Entity_Id;
7626 Exp : Node_Id;
7628 function Is_Preelaborable_Expression (N : Node_Id) return Boolean;
7629 -- Returns True if and only if the expression denoted by N does not
7630 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
7632 ---------------------------------
7633 -- Is_Preelaborable_Expression --
7634 ---------------------------------
7636 function Is_Preelaborable_Expression (N : Node_Id) return Boolean is
7637 Exp : Node_Id;
7638 Assn : Node_Id;
7639 Choice : Node_Id;
7640 Comp_Type : Entity_Id;
7641 Is_Array_Aggr : Boolean;
7643 begin
7644 if Is_Static_Expression (N) then
7645 return True;
7647 elsif Nkind (N) = N_Null then
7648 return True;
7650 -- Attributes are allowed in general, even if their prefix is a
7651 -- formal type. (It seems that certain attributes known not to be
7652 -- static might not be allowed, but there are no rules to prevent
7653 -- them.)
7655 elsif Nkind (N) = N_Attribute_Reference then
7656 return True;
7658 -- The name of a discriminant evaluated within its parent type is
7659 -- defined to be preelaborable (10.2.1(8)). Note that we test for
7660 -- names that denote discriminals as well as discriminants to
7661 -- catch references occurring within init procs.
7663 elsif Is_Entity_Name (N)
7664 and then
7665 (Ekind (Entity (N)) = E_Discriminant
7666 or else
7667 ((Ekind (Entity (N)) = E_Constant
7668 or else Ekind (Entity (N)) = E_In_Parameter)
7669 and then Present (Discriminal_Link (Entity (N)))))
7670 then
7671 return True;
7673 elsif Nkind (N) = N_Qualified_Expression then
7674 return Is_Preelaborable_Expression (Expression (N));
7676 -- For aggregates we have to check that each of the associations
7677 -- is preelaborable.
7679 elsif Nkind (N) = N_Aggregate
7680 or else Nkind (N) = N_Extension_Aggregate
7681 then
7682 Is_Array_Aggr := Is_Array_Type (Etype (N));
7684 if Is_Array_Aggr then
7685 Comp_Type := Component_Type (Etype (N));
7686 end if;
7688 -- Check the ancestor part of extension aggregates, which must
7689 -- be either the name of a type that has preelaborable init or
7690 -- an expression that is preelaborable.
7692 if Nkind (N) = N_Extension_Aggregate then
7693 declare
7694 Anc_Part : constant Node_Id := Ancestor_Part (N);
7696 begin
7697 if Is_Entity_Name (Anc_Part)
7698 and then Is_Type (Entity (Anc_Part))
7699 then
7700 if not Has_Preelaborable_Initialization
7701 (Entity (Anc_Part))
7702 then
7703 return False;
7704 end if;
7706 elsif not Is_Preelaborable_Expression (Anc_Part) then
7707 return False;
7708 end if;
7709 end;
7710 end if;
7712 -- Check positional associations
7714 Exp := First (Expressions (N));
7715 while Present (Exp) loop
7716 if not Is_Preelaborable_Expression (Exp) then
7717 return False;
7718 end if;
7720 Next (Exp);
7721 end loop;
7723 -- Check named associations
7725 Assn := First (Component_Associations (N));
7726 while Present (Assn) loop
7727 Choice := First (Choices (Assn));
7728 while Present (Choice) loop
7729 if Is_Array_Aggr then
7730 if Nkind (Choice) = N_Others_Choice then
7731 null;
7733 elsif Nkind (Choice) = N_Range then
7734 if not Is_Static_Range (Choice) then
7735 return False;
7736 end if;
7738 elsif not Is_Static_Expression (Choice) then
7739 return False;
7740 end if;
7742 else
7743 Comp_Type := Etype (Choice);
7744 end if;
7746 Next (Choice);
7747 end loop;
7749 -- If the association has a <> at this point, then we have
7750 -- to check whether the component's type has preelaborable
7751 -- initialization. Note that this only occurs when the
7752 -- association's corresponding component does not have a
7753 -- default expression, the latter case having already been
7754 -- expanded as an expression for the association.
7756 if Box_Present (Assn) then
7757 if not Has_Preelaborable_Initialization (Comp_Type) then
7758 return False;
7759 end if;
7761 -- In the expression case we check whether the expression
7762 -- is preelaborable.
7764 elsif
7765 not Is_Preelaborable_Expression (Expression (Assn))
7766 then
7767 return False;
7768 end if;
7770 Next (Assn);
7771 end loop;
7773 -- If we get here then aggregate as a whole is preelaborable
7775 return True;
7777 -- All other cases are not preelaborable
7779 else
7780 return False;
7781 end if;
7782 end Is_Preelaborable_Expression;
7784 -- Start of processing for Check_Components
7786 begin
7787 -- Loop through entities of record or protected type
7789 Ent := E;
7790 while Present (Ent) loop
7792 -- We are interested only in components and discriminants
7794 Exp := Empty;
7796 case Ekind (Ent) is
7797 when E_Component =>
7799 -- Get default expression if any. If there is no declaration
7800 -- node, it means we have an internal entity. The parent and
7801 -- tag fields are examples of such entities. For such cases,
7802 -- we just test the type of the entity.
7804 if Present (Declaration_Node (Ent)) then
7805 Exp := Expression (Declaration_Node (Ent));
7806 end if;
7808 when E_Discriminant =>
7810 -- Note: for a renamed discriminant, the Declaration_Node
7811 -- may point to the one from the ancestor, and have a
7812 -- different expression, so use the proper attribute to
7813 -- retrieve the expression from the derived constraint.
7815 Exp := Discriminant_Default_Value (Ent);
7817 when others =>
7818 goto Check_Next_Entity;
7819 end case;
7821 -- A component has PI if it has no default expression and the
7822 -- component type has PI.
7824 if No (Exp) then
7825 if not Has_Preelaborable_Initialization (Etype (Ent)) then
7826 Has_PE := False;
7827 exit;
7828 end if;
7830 -- Require the default expression to be preelaborable
7832 elsif not Is_Preelaborable_Expression (Exp) then
7833 Has_PE := False;
7834 exit;
7835 end if;
7837 <<Check_Next_Entity>>
7838 Next_Entity (Ent);
7839 end loop;
7840 end Check_Components;
7842 -- Start of processing for Has_Preelaborable_Initialization
7844 begin
7845 -- Immediate return if already marked as known preelaborable init. This
7846 -- covers types for which this function has already been called once
7847 -- and returned True (in which case the result is cached), and also
7848 -- types to which a pragma Preelaborable_Initialization applies.
7850 if Known_To_Have_Preelab_Init (E) then
7851 return True;
7852 end if;
7854 -- If the type is a subtype representing a generic actual type, then
7855 -- test whether its base type has preelaborable initialization since
7856 -- the subtype representing the actual does not inherit this attribute
7857 -- from the actual or formal. (but maybe it should???)
7859 if Is_Generic_Actual_Type (E) then
7860 return Has_Preelaborable_Initialization (Base_Type (E));
7861 end if;
7863 -- All elementary types have preelaborable initialization
7865 if Is_Elementary_Type (E) then
7866 Has_PE := True;
7868 -- Array types have PI if the component type has PI
7870 elsif Is_Array_Type (E) then
7871 Has_PE := Has_Preelaborable_Initialization (Component_Type (E));
7873 -- A derived type has preelaborable initialization if its parent type
7874 -- has preelaborable initialization and (in the case of a derived record
7875 -- extension) if the non-inherited components all have preelaborable
7876 -- initialization. However, a user-defined controlled type with an
7877 -- overriding Initialize procedure does not have preelaborable
7878 -- initialization.
7880 elsif Is_Derived_Type (E) then
7882 -- If the derived type is a private extension then it doesn't have
7883 -- preelaborable initialization.
7885 if Ekind (Base_Type (E)) = E_Record_Type_With_Private then
7886 return False;
7887 end if;
7889 -- First check whether ancestor type has preelaborable initialization
7891 Has_PE := Has_Preelaborable_Initialization (Etype (Base_Type (E)));
7893 -- If OK, check extension components (if any)
7895 if Has_PE and then Is_Record_Type (E) then
7896 Check_Components (First_Entity (E));
7897 end if;
7899 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
7900 -- with a user defined Initialize procedure does not have PI.
7902 if Has_PE
7903 and then Is_Controlled (E)
7904 and then Has_Overriding_Initialize (E)
7905 then
7906 Has_PE := False;
7907 end if;
7909 -- Private types not derived from a type having preelaborable init and
7910 -- that are not marked with pragma Preelaborable_Initialization do not
7911 -- have preelaborable initialization.
7913 elsif Is_Private_Type (E) then
7914 return False;
7916 -- Record type has PI if it is non private and all components have PI
7918 elsif Is_Record_Type (E) then
7919 Has_PE := True;
7920 Check_Components (First_Entity (E));
7922 -- Protected types must not have entries, and components must meet
7923 -- same set of rules as for record components.
7925 elsif Is_Protected_Type (E) then
7926 if Has_Entries (E) then
7927 Has_PE := False;
7928 else
7929 Has_PE := True;
7930 Check_Components (First_Entity (E));
7931 Check_Components (First_Private_Entity (E));
7932 end if;
7934 -- Type System.Address always has preelaborable initialization
7936 elsif Is_RTE (E, RE_Address) then
7937 Has_PE := True;
7939 -- In all other cases, type does not have preelaborable initialization
7941 else
7942 return False;
7943 end if;
7945 -- If type has preelaborable initialization, cache result
7947 if Has_PE then
7948 Set_Known_To_Have_Preelab_Init (E);
7949 end if;
7951 return Has_PE;
7952 end Has_Preelaborable_Initialization;
7954 ---------------------------
7955 -- Has_Private_Component --
7956 ---------------------------
7958 function Has_Private_Component (Type_Id : Entity_Id) return Boolean is
7959 Btype : Entity_Id := Base_Type (Type_Id);
7960 Component : Entity_Id;
7962 begin
7963 if Error_Posted (Type_Id)
7964 or else Error_Posted (Btype)
7965 then
7966 return False;
7967 end if;
7969 if Is_Class_Wide_Type (Btype) then
7970 Btype := Root_Type (Btype);
7971 end if;
7973 if Is_Private_Type (Btype) then
7974 declare
7975 UT : constant Entity_Id := Underlying_Type (Btype);
7976 begin
7977 if No (UT) then
7978 if No (Full_View (Btype)) then
7979 return not Is_Generic_Type (Btype)
7980 and then not Is_Generic_Type (Root_Type (Btype));
7981 else
7982 return not Is_Generic_Type (Root_Type (Full_View (Btype)));
7983 end if;
7984 else
7985 return not Is_Frozen (UT) and then Has_Private_Component (UT);
7986 end if;
7987 end;
7989 elsif Is_Array_Type (Btype) then
7990 return Has_Private_Component (Component_Type (Btype));
7992 elsif Is_Record_Type (Btype) then
7993 Component := First_Component (Btype);
7994 while Present (Component) loop
7995 if Has_Private_Component (Etype (Component)) then
7996 return True;
7997 end if;
7999 Next_Component (Component);
8000 end loop;
8002 return False;
8004 elsif Is_Protected_Type (Btype)
8005 and then Present (Corresponding_Record_Type (Btype))
8006 then
8007 return Has_Private_Component (Corresponding_Record_Type (Btype));
8009 else
8010 return False;
8011 end if;
8012 end Has_Private_Component;
8014 ----------------------
8015 -- Has_Signed_Zeros --
8016 ----------------------
8018 function Has_Signed_Zeros (E : Entity_Id) return Boolean is
8019 begin
8020 return Is_Floating_Point_Type (E)
8021 and then Signed_Zeros_On_Target
8022 and then not Vax_Float (E);
8023 end Has_Signed_Zeros;
8025 -----------------------------
8026 -- Has_Static_Array_Bounds --
8027 -----------------------------
8029 function Has_Static_Array_Bounds (Typ : Node_Id) return Boolean is
8030 Ndims : constant Nat := Number_Dimensions (Typ);
8032 Index : Node_Id;
8033 Low : Node_Id;
8034 High : Node_Id;
8036 begin
8037 -- Unconstrained types do not have static bounds
8039 if not Is_Constrained (Typ) then
8040 return False;
8041 end if;
8043 -- First treat string literals specially, as the lower bound and length
8044 -- of string literals are not stored like those of arrays.
8046 -- A string literal always has static bounds
8048 if Ekind (Typ) = E_String_Literal_Subtype then
8049 return True;
8050 end if;
8052 -- Treat all dimensions in turn
8054 Index := First_Index (Typ);
8055 for Indx in 1 .. Ndims loop
8057 -- In case of an erroneous index which is not a discrete type, return
8058 -- that the type is not static.
8060 if not Is_Discrete_Type (Etype (Index))
8061 or else Etype (Index) = Any_Type
8062 then
8063 return False;
8064 end if;
8066 Get_Index_Bounds (Index, Low, High);
8068 if Error_Posted (Low) or else Error_Posted (High) then
8069 return False;
8070 end if;
8072 if Is_OK_Static_Expression (Low)
8073 and then
8074 Is_OK_Static_Expression (High)
8075 then
8076 null;
8077 else
8078 return False;
8079 end if;
8081 Next (Index);
8082 end loop;
8084 -- If we fall through the loop, all indexes matched
8086 return True;
8087 end Has_Static_Array_Bounds;
8089 ----------------
8090 -- Has_Stream --
8091 ----------------
8093 function Has_Stream (T : Entity_Id) return Boolean is
8094 E : Entity_Id;
8096 begin
8097 if No (T) then
8098 return False;
8100 elsif Is_RTE (Root_Type (T), RE_Root_Stream_Type) then
8101 return True;
8103 elsif Is_Array_Type (T) then
8104 return Has_Stream (Component_Type (T));
8106 elsif Is_Record_Type (T) then
8107 E := First_Component (T);
8108 while Present (E) loop
8109 if Has_Stream (Etype (E)) then
8110 return True;
8111 else
8112 Next_Component (E);
8113 end if;
8114 end loop;
8116 return False;
8118 elsif Is_Private_Type (T) then
8119 return Has_Stream (Underlying_Type (T));
8121 else
8122 return False;
8123 end if;
8124 end Has_Stream;
8126 ----------------
8127 -- Has_Suffix --
8128 ----------------
8130 function Has_Suffix (E : Entity_Id; Suffix : Character) return Boolean is
8131 begin
8132 Get_Name_String (Chars (E));
8133 return Name_Buffer (Name_Len) = Suffix;
8134 end Has_Suffix;
8136 ----------------
8137 -- Add_Suffix --
8138 ----------------
8140 function Add_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8141 begin
8142 Get_Name_String (Chars (E));
8143 Add_Char_To_Name_Buffer (Suffix);
8144 return Name_Find;
8145 end Add_Suffix;
8147 -------------------
8148 -- Remove_Suffix --
8149 -------------------
8151 function Remove_Suffix (E : Entity_Id; Suffix : Character) return Name_Id is
8152 begin
8153 pragma Assert (Has_Suffix (E, Suffix));
8154 Get_Name_String (Chars (E));
8155 Name_Len := Name_Len - 1;
8156 return Name_Find;
8157 end Remove_Suffix;
8159 --------------------------
8160 -- Has_Tagged_Component --
8161 --------------------------
8163 function Has_Tagged_Component (Typ : Entity_Id) return Boolean is
8164 Comp : Entity_Id;
8166 begin
8167 if Is_Private_Type (Typ)
8168 and then Present (Underlying_Type (Typ))
8169 then
8170 return Has_Tagged_Component (Underlying_Type (Typ));
8172 elsif Is_Array_Type (Typ) then
8173 return Has_Tagged_Component (Component_Type (Typ));
8175 elsif Is_Tagged_Type (Typ) then
8176 return True;
8178 elsif Is_Record_Type (Typ) then
8179 Comp := First_Component (Typ);
8180 while Present (Comp) loop
8181 if Has_Tagged_Component (Etype (Comp)) then
8182 return True;
8183 end if;
8185 Next_Component (Comp);
8186 end loop;
8188 return False;
8190 else
8191 return False;
8192 end if;
8193 end Has_Tagged_Component;
8195 ----------------------------
8196 -- Has_Volatile_Component --
8197 ----------------------------
8199 function Has_Volatile_Component (Typ : Entity_Id) return Boolean is
8200 Comp : Entity_Id;
8202 begin
8203 if Has_Volatile_Components (Typ) then
8204 return True;
8206 elsif Is_Array_Type (Typ) then
8207 return Is_Volatile (Component_Type (Typ));
8209 elsif Is_Record_Type (Typ) then
8210 Comp := First_Component (Typ);
8211 while Present (Comp) loop
8212 if Is_Volatile_Object (Comp) then
8213 return True;
8214 end if;
8216 Comp := Next_Component (Comp);
8217 end loop;
8218 end if;
8220 return False;
8221 end Has_Volatile_Component;
8223 -------------------------
8224 -- Implementation_Kind --
8225 -------------------------
8227 function Implementation_Kind (Subp : Entity_Id) return Name_Id is
8228 Impl_Prag : constant Node_Id := Get_Rep_Pragma (Subp, Name_Implemented);
8229 Arg : Node_Id;
8230 begin
8231 pragma Assert (Present (Impl_Prag));
8232 Arg := Last (Pragma_Argument_Associations (Impl_Prag));
8233 return Chars (Get_Pragma_Arg (Arg));
8234 end Implementation_Kind;
8236 --------------------------
8237 -- Implements_Interface --
8238 --------------------------
8240 function Implements_Interface
8241 (Typ_Ent : Entity_Id;
8242 Iface_Ent : Entity_Id;
8243 Exclude_Parents : Boolean := False) return Boolean
8245 Ifaces_List : Elist_Id;
8246 Elmt : Elmt_Id;
8247 Iface : Entity_Id := Base_Type (Iface_Ent);
8248 Typ : Entity_Id := Base_Type (Typ_Ent);
8250 begin
8251 if Is_Class_Wide_Type (Typ) then
8252 Typ := Root_Type (Typ);
8253 end if;
8255 if not Has_Interfaces (Typ) then
8256 return False;
8257 end if;
8259 if Is_Class_Wide_Type (Iface) then
8260 Iface := Root_Type (Iface);
8261 end if;
8263 Collect_Interfaces (Typ, Ifaces_List);
8265 Elmt := First_Elmt (Ifaces_List);
8266 while Present (Elmt) loop
8267 if Is_Ancestor (Node (Elmt), Typ, Use_Full_View => True)
8268 and then Exclude_Parents
8269 then
8270 null;
8272 elsif Node (Elmt) = Iface then
8273 return True;
8274 end if;
8276 Next_Elmt (Elmt);
8277 end loop;
8279 return False;
8280 end Implements_Interface;
8282 -----------------
8283 -- In_Instance --
8284 -----------------
8286 function In_Instance return Boolean is
8287 Curr_Unit : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
8288 S : Entity_Id;
8290 begin
8291 S := Current_Scope;
8292 while Present (S)
8293 and then S /= Standard_Standard
8294 loop
8295 if (Ekind (S) = E_Function
8296 or else Ekind (S) = E_Package
8297 or else Ekind (S) = E_Procedure)
8298 and then Is_Generic_Instance (S)
8299 then
8300 -- A child instance is always compiled in the context of a parent
8301 -- instance. Nevertheless, the actuals are not analyzed in an
8302 -- instance context. We detect this case by examining the current
8303 -- compilation unit, which must be a child instance, and checking
8304 -- that it is not currently on the scope stack.
8306 if Is_Child_Unit (Curr_Unit)
8307 and then
8308 Nkind (Unit (Cunit (Current_Sem_Unit)))
8309 = N_Package_Instantiation
8310 and then not In_Open_Scopes (Curr_Unit)
8311 then
8312 return False;
8313 else
8314 return True;
8315 end if;
8316 end if;
8318 S := Scope (S);
8319 end loop;
8321 return False;
8322 end In_Instance;
8324 ----------------------
8325 -- In_Instance_Body --
8326 ----------------------
8328 function In_Instance_Body return Boolean is
8329 S : Entity_Id;
8331 begin
8332 S := Current_Scope;
8333 while Present (S)
8334 and then S /= Standard_Standard
8335 loop
8336 if (Ekind (S) = E_Function
8337 or else Ekind (S) = E_Procedure)
8338 and then Is_Generic_Instance (S)
8339 then
8340 return True;
8342 elsif Ekind (S) = E_Package
8343 and then In_Package_Body (S)
8344 and then Is_Generic_Instance (S)
8345 then
8346 return True;
8347 end if;
8349 S := Scope (S);
8350 end loop;
8352 return False;
8353 end In_Instance_Body;
8355 -----------------------------
8356 -- In_Instance_Not_Visible --
8357 -----------------------------
8359 function In_Instance_Not_Visible return Boolean is
8360 S : Entity_Id;
8362 begin
8363 S := Current_Scope;
8364 while Present (S)
8365 and then S /= Standard_Standard
8366 loop
8367 if (Ekind (S) = E_Function
8368 or else Ekind (S) = E_Procedure)
8369 and then Is_Generic_Instance (S)
8370 then
8371 return True;
8373 elsif Ekind (S) = E_Package
8374 and then (In_Package_Body (S) or else In_Private_Part (S))
8375 and then Is_Generic_Instance (S)
8376 then
8377 return True;
8378 end if;
8380 S := Scope (S);
8381 end loop;
8383 return False;
8384 end In_Instance_Not_Visible;
8386 ------------------------------
8387 -- In_Instance_Visible_Part --
8388 ------------------------------
8390 function In_Instance_Visible_Part return Boolean is
8391 S : Entity_Id;
8393 begin
8394 S := Current_Scope;
8395 while Present (S)
8396 and then S /= Standard_Standard
8397 loop
8398 if Ekind (S) = E_Package
8399 and then Is_Generic_Instance (S)
8400 and then not In_Package_Body (S)
8401 and then not In_Private_Part (S)
8402 then
8403 return True;
8404 end if;
8406 S := Scope (S);
8407 end loop;
8409 return False;
8410 end In_Instance_Visible_Part;
8412 ---------------------
8413 -- In_Package_Body --
8414 ---------------------
8416 function In_Package_Body return Boolean is
8417 S : Entity_Id;
8419 begin
8420 S := Current_Scope;
8421 while Present (S)
8422 and then S /= Standard_Standard
8423 loop
8424 if Ekind (S) = E_Package
8425 and then In_Package_Body (S)
8426 then
8427 return True;
8428 else
8429 S := Scope (S);
8430 end if;
8431 end loop;
8433 return False;
8434 end In_Package_Body;
8436 --------------------------------
8437 -- In_Parameter_Specification --
8438 --------------------------------
8440 function In_Parameter_Specification (N : Node_Id) return Boolean is
8441 PN : Node_Id;
8443 begin
8444 PN := Parent (N);
8445 while Present (PN) loop
8446 if Nkind (PN) = N_Parameter_Specification then
8447 return True;
8448 end if;
8450 PN := Parent (PN);
8451 end loop;
8453 return False;
8454 end In_Parameter_Specification;
8456 --------------------------
8457 -- In_Pragma_Expression --
8458 --------------------------
8460 function In_Pragma_Expression (N : Node_Id; Nam : Name_Id) return Boolean is
8461 P : Node_Id;
8462 begin
8463 P := Parent (N);
8464 loop
8465 if No (P) then
8466 return False;
8467 elsif Nkind (P) = N_Pragma and then Pragma_Name (P) = Nam then
8468 return True;
8469 else
8470 P := Parent (P);
8471 end if;
8472 end loop;
8473 end In_Pragma_Expression;
8475 -------------------------------------
8476 -- In_Reverse_Storage_Order_Object --
8477 -------------------------------------
8479 function In_Reverse_Storage_Order_Object (N : Node_Id) return Boolean is
8480 Pref : Node_Id;
8481 Btyp : Entity_Id := Empty;
8483 begin
8484 -- Climb up indexed components
8486 Pref := N;
8487 loop
8488 case Nkind (Pref) is
8489 when N_Selected_Component =>
8490 Pref := Prefix (Pref);
8491 exit;
8493 when N_Indexed_Component =>
8494 Pref := Prefix (Pref);
8496 when others =>
8497 Pref := Empty;
8498 exit;
8499 end case;
8500 end loop;
8502 if Present (Pref) then
8503 Btyp := Base_Type (Etype (Pref));
8504 end if;
8506 return
8507 Present (Btyp)
8508 and then (Is_Record_Type (Btyp) or else Is_Array_Type (Btyp))
8509 and then Reverse_Storage_Order (Btyp);
8510 end In_Reverse_Storage_Order_Object;
8512 --------------------------------------
8513 -- In_Subprogram_Or_Concurrent_Unit --
8514 --------------------------------------
8516 function In_Subprogram_Or_Concurrent_Unit return Boolean is
8517 E : Entity_Id;
8518 K : Entity_Kind;
8520 begin
8521 -- Use scope chain to check successively outer scopes
8523 E := Current_Scope;
8524 loop
8525 K := Ekind (E);
8527 if K in Subprogram_Kind
8528 or else K in Concurrent_Kind
8529 or else K in Generic_Subprogram_Kind
8530 then
8531 return True;
8533 elsif E = Standard_Standard then
8534 return False;
8535 end if;
8537 E := Scope (E);
8538 end loop;
8539 end In_Subprogram_Or_Concurrent_Unit;
8541 ---------------------
8542 -- In_Visible_Part --
8543 ---------------------
8545 function In_Visible_Part (Scope_Id : Entity_Id) return Boolean is
8546 begin
8547 return
8548 Is_Package_Or_Generic_Package (Scope_Id)
8549 and then In_Open_Scopes (Scope_Id)
8550 and then not In_Package_Body (Scope_Id)
8551 and then not In_Private_Part (Scope_Id);
8552 end In_Visible_Part;
8554 --------------------------------
8555 -- Incomplete_Or_Private_View --
8556 --------------------------------
8558 function Incomplete_Or_Private_View (Typ : Entity_Id) return Entity_Id is
8559 function Inspect_Decls
8560 (Decls : List_Id;
8561 Taft : Boolean := False) return Entity_Id;
8562 -- Check whether a declarative region contains the incomplete or private
8563 -- view of Typ.
8565 -------------------
8566 -- Inspect_Decls --
8567 -------------------
8569 function Inspect_Decls
8570 (Decls : List_Id;
8571 Taft : Boolean := False) return Entity_Id
8573 Decl : Node_Id;
8574 Match : Node_Id;
8576 begin
8577 Decl := First (Decls);
8578 while Present (Decl) loop
8579 Match := Empty;
8581 if Taft then
8582 if Nkind (Decl) = N_Incomplete_Type_Declaration then
8583 Match := Defining_Identifier (Decl);
8584 end if;
8586 else
8587 if Nkind_In (Decl, N_Private_Extension_Declaration,
8588 N_Private_Type_Declaration)
8589 then
8590 Match := Defining_Identifier (Decl);
8591 end if;
8592 end if;
8594 if Present (Match)
8595 and then Present (Full_View (Match))
8596 and then Full_View (Match) = Typ
8597 then
8598 return Match;
8599 end if;
8601 Next (Decl);
8602 end loop;
8604 return Empty;
8605 end Inspect_Decls;
8607 -- Local variables
8609 Prev : Entity_Id;
8611 -- Start of processing for Incomplete_Or_Partial_View
8613 begin
8614 -- Incomplete type case
8616 Prev := Current_Entity_In_Scope (Typ);
8618 if Present (Prev)
8619 and then Is_Incomplete_Type (Prev)
8620 and then Present (Full_View (Prev))
8621 and then Full_View (Prev) = Typ
8622 then
8623 return Prev;
8624 end if;
8626 -- Private or Taft amendment type case
8628 declare
8629 Pkg : constant Entity_Id := Scope (Typ);
8630 Pkg_Decl : Node_Id := Pkg;
8632 begin
8633 if Ekind (Pkg) = E_Package then
8634 while Nkind (Pkg_Decl) /= N_Package_Specification loop
8635 Pkg_Decl := Parent (Pkg_Decl);
8636 end loop;
8638 -- It is knows that Typ has a private view, look for it in the
8639 -- visible declarations of the enclosing scope. A special case
8640 -- of this is when the two views have been exchanged - the full
8641 -- appears earlier than the private.
8643 if Has_Private_Declaration (Typ) then
8644 Prev := Inspect_Decls (Visible_Declarations (Pkg_Decl));
8646 -- Exchanged view case, look in the private declarations
8648 if No (Prev) then
8649 Prev := Inspect_Decls (Private_Declarations (Pkg_Decl));
8650 end if;
8652 return Prev;
8654 -- Otherwise if this is the package body, then Typ is a potential
8655 -- Taft amendment type. The incomplete view should be located in
8656 -- the private declarations of the enclosing scope.
8658 elsif In_Package_Body (Pkg) then
8659 return Inspect_Decls (Private_Declarations (Pkg_Decl), True);
8660 end if;
8661 end if;
8662 end;
8664 -- The type has no incomplete or private view
8666 return Empty;
8667 end Incomplete_Or_Private_View;
8669 ---------------------------------
8670 -- Insert_Explicit_Dereference --
8671 ---------------------------------
8673 procedure Insert_Explicit_Dereference (N : Node_Id) is
8674 New_Prefix : constant Node_Id := Relocate_Node (N);
8675 Ent : Entity_Id := Empty;
8676 Pref : Node_Id;
8677 I : Interp_Index;
8678 It : Interp;
8679 T : Entity_Id;
8681 begin
8682 Save_Interps (N, New_Prefix);
8684 Rewrite (N,
8685 Make_Explicit_Dereference (Sloc (Parent (N)),
8686 Prefix => New_Prefix));
8688 Set_Etype (N, Designated_Type (Etype (New_Prefix)));
8690 if Is_Overloaded (New_Prefix) then
8692 -- The dereference is also overloaded, and its interpretations are
8693 -- the designated types of the interpretations of the original node.
8695 Set_Etype (N, Any_Type);
8697 Get_First_Interp (New_Prefix, I, It);
8698 while Present (It.Nam) loop
8699 T := It.Typ;
8701 if Is_Access_Type (T) then
8702 Add_One_Interp (N, Designated_Type (T), Designated_Type (T));
8703 end if;
8705 Get_Next_Interp (I, It);
8706 end loop;
8708 End_Interp_List;
8710 else
8711 -- Prefix is unambiguous: mark the original prefix (which might
8712 -- Come_From_Source) as a reference, since the new (relocated) one
8713 -- won't be taken into account.
8715 if Is_Entity_Name (New_Prefix) then
8716 Ent := Entity (New_Prefix);
8717 Pref := New_Prefix;
8719 -- For a retrieval of a subcomponent of some composite object,
8720 -- retrieve the ultimate entity if there is one.
8722 elsif Nkind (New_Prefix) = N_Selected_Component
8723 or else Nkind (New_Prefix) = N_Indexed_Component
8724 then
8725 Pref := Prefix (New_Prefix);
8726 while Present (Pref)
8727 and then
8728 (Nkind (Pref) = N_Selected_Component
8729 or else Nkind (Pref) = N_Indexed_Component)
8730 loop
8731 Pref := Prefix (Pref);
8732 end loop;
8734 if Present (Pref) and then Is_Entity_Name (Pref) then
8735 Ent := Entity (Pref);
8736 end if;
8737 end if;
8739 -- Place the reference on the entity node
8741 if Present (Ent) then
8742 Generate_Reference (Ent, Pref);
8743 end if;
8744 end if;
8745 end Insert_Explicit_Dereference;
8747 ------------------------------------------
8748 -- Inspect_Deferred_Constant_Completion --
8749 ------------------------------------------
8751 procedure Inspect_Deferred_Constant_Completion (Decls : List_Id) is
8752 Decl : Node_Id;
8754 begin
8755 Decl := First (Decls);
8756 while Present (Decl) loop
8758 -- Deferred constant signature
8760 if Nkind (Decl) = N_Object_Declaration
8761 and then Constant_Present (Decl)
8762 and then No (Expression (Decl))
8764 -- No need to check internally generated constants
8766 and then Comes_From_Source (Decl)
8768 -- The constant is not completed. A full object declaration or a
8769 -- pragma Import complete a deferred constant.
8771 and then not Has_Completion (Defining_Identifier (Decl))
8772 then
8773 Error_Msg_N
8774 ("constant declaration requires initialization expression",
8775 Defining_Identifier (Decl));
8776 end if;
8778 Decl := Next (Decl);
8779 end loop;
8780 end Inspect_Deferred_Constant_Completion;
8782 -----------------------------
8783 -- Is_Actual_Out_Parameter --
8784 -----------------------------
8786 function Is_Actual_Out_Parameter (N : Node_Id) return Boolean is
8787 Formal : Entity_Id;
8788 Call : Node_Id;
8789 begin
8790 Find_Actual (N, Formal, Call);
8791 return Present (Formal) and then Ekind (Formal) = E_Out_Parameter;
8792 end Is_Actual_Out_Parameter;
8794 -------------------------
8795 -- Is_Actual_Parameter --
8796 -------------------------
8798 function Is_Actual_Parameter (N : Node_Id) return Boolean is
8799 PK : constant Node_Kind := Nkind (Parent (N));
8801 begin
8802 case PK is
8803 when N_Parameter_Association =>
8804 return N = Explicit_Actual_Parameter (Parent (N));
8806 when N_Subprogram_Call =>
8807 return Is_List_Member (N)
8808 and then
8809 List_Containing (N) = Parameter_Associations (Parent (N));
8811 when others =>
8812 return False;
8813 end case;
8814 end Is_Actual_Parameter;
8816 --------------------------------
8817 -- Is_Actual_Tagged_Parameter --
8818 --------------------------------
8820 function Is_Actual_Tagged_Parameter (N : Node_Id) return Boolean is
8821 Formal : Entity_Id;
8822 Call : Node_Id;
8823 begin
8824 Find_Actual (N, Formal, Call);
8825 return Present (Formal) and then Is_Tagged_Type (Etype (Formal));
8826 end Is_Actual_Tagged_Parameter;
8828 ---------------------
8829 -- Is_Aliased_View --
8830 ---------------------
8832 function Is_Aliased_View (Obj : Node_Id) return Boolean is
8833 E : Entity_Id;
8835 begin
8836 if Is_Entity_Name (Obj) then
8837 E := Entity (Obj);
8839 return
8840 (Is_Object (E)
8841 and then
8842 (Is_Aliased (E)
8843 or else (Present (Renamed_Object (E))
8844 and then Is_Aliased_View (Renamed_Object (E)))))
8846 or else ((Is_Formal (E)
8847 or else Ekind (E) = E_Generic_In_Out_Parameter
8848 or else Ekind (E) = E_Generic_In_Parameter)
8849 and then Is_Tagged_Type (Etype (E)))
8851 or else (Is_Concurrent_Type (E) and then In_Open_Scopes (E))
8853 -- Current instance of type, either directly or as rewritten
8854 -- reference to the current object.
8856 or else (Is_Entity_Name (Original_Node (Obj))
8857 and then Present (Entity (Original_Node (Obj)))
8858 and then Is_Type (Entity (Original_Node (Obj))))
8860 or else (Is_Type (E) and then E = Current_Scope)
8862 or else (Is_Incomplete_Or_Private_Type (E)
8863 and then Full_View (E) = Current_Scope)
8865 -- Ada 2012 AI05-0053: the return object of an extended return
8866 -- statement is aliased if its type is immutably limited.
8868 or else (Is_Return_Object (E)
8869 and then Is_Limited_View (Etype (E)));
8871 elsif Nkind (Obj) = N_Selected_Component then
8872 return Is_Aliased (Entity (Selector_Name (Obj)));
8874 elsif Nkind (Obj) = N_Indexed_Component then
8875 return Has_Aliased_Components (Etype (Prefix (Obj)))
8876 or else
8877 (Is_Access_Type (Etype (Prefix (Obj)))
8878 and then Has_Aliased_Components
8879 (Designated_Type (Etype (Prefix (Obj)))));
8881 elsif Nkind_In (Obj, N_Unchecked_Type_Conversion, N_Type_Conversion) then
8882 return Is_Tagged_Type (Etype (Obj))
8883 and then Is_Aliased_View (Expression (Obj));
8885 elsif Nkind (Obj) = N_Explicit_Dereference then
8886 return Nkind (Original_Node (Obj)) /= N_Function_Call;
8888 else
8889 return False;
8890 end if;
8891 end Is_Aliased_View;
8893 -------------------------
8894 -- Is_Ancestor_Package --
8895 -------------------------
8897 function Is_Ancestor_Package
8898 (E1 : Entity_Id;
8899 E2 : Entity_Id) return Boolean
8901 Par : Entity_Id;
8903 begin
8904 Par := E2;
8905 while Present (Par)
8906 and then Par /= Standard_Standard
8907 loop
8908 if Par = E1 then
8909 return True;
8910 end if;
8912 Par := Scope (Par);
8913 end loop;
8915 return False;
8916 end Is_Ancestor_Package;
8918 ----------------------
8919 -- Is_Atomic_Object --
8920 ----------------------
8922 function Is_Atomic_Object (N : Node_Id) return Boolean is
8924 function Object_Has_Atomic_Components (N : Node_Id) return Boolean;
8925 -- Determines if given object has atomic components
8927 function Is_Atomic_Prefix (N : Node_Id) return Boolean;
8928 -- If prefix is an implicit dereference, examine designated type
8930 ----------------------
8931 -- Is_Atomic_Prefix --
8932 ----------------------
8934 function Is_Atomic_Prefix (N : Node_Id) return Boolean is
8935 begin
8936 if Is_Access_Type (Etype (N)) then
8937 return
8938 Has_Atomic_Components (Designated_Type (Etype (N)));
8939 else
8940 return Object_Has_Atomic_Components (N);
8941 end if;
8942 end Is_Atomic_Prefix;
8944 ----------------------------------
8945 -- Object_Has_Atomic_Components --
8946 ----------------------------------
8948 function Object_Has_Atomic_Components (N : Node_Id) return Boolean is
8949 begin
8950 if Has_Atomic_Components (Etype (N))
8951 or else Is_Atomic (Etype (N))
8952 then
8953 return True;
8955 elsif Is_Entity_Name (N)
8956 and then (Has_Atomic_Components (Entity (N))
8957 or else Is_Atomic (Entity (N)))
8958 then
8959 return True;
8961 elsif Nkind (N) = N_Selected_Component
8962 and then Is_Atomic (Entity (Selector_Name (N)))
8963 then
8964 return True;
8966 elsif Nkind (N) = N_Indexed_Component
8967 or else Nkind (N) = N_Selected_Component
8968 then
8969 return Is_Atomic_Prefix (Prefix (N));
8971 else
8972 return False;
8973 end if;
8974 end Object_Has_Atomic_Components;
8976 -- Start of processing for Is_Atomic_Object
8978 begin
8979 -- Predicate is not relevant to subprograms
8981 if Is_Entity_Name (N) and then Is_Overloadable (Entity (N)) then
8982 return False;
8984 elsif Is_Atomic (Etype (N))
8985 or else (Is_Entity_Name (N) and then Is_Atomic (Entity (N)))
8986 then
8987 return True;
8989 elsif Nkind (N) = N_Selected_Component
8990 and then Is_Atomic (Entity (Selector_Name (N)))
8991 then
8992 return True;
8994 elsif Nkind (N) = N_Indexed_Component
8995 or else Nkind (N) = N_Selected_Component
8996 then
8997 return Is_Atomic_Prefix (Prefix (N));
8999 else
9000 return False;
9001 end if;
9002 end Is_Atomic_Object;
9004 -------------------------
9005 -- Is_Attribute_Result --
9006 -------------------------
9008 function Is_Attribute_Result (N : Node_Id) return Boolean is
9009 begin
9010 return
9011 Nkind (N) = N_Attribute_Reference
9012 and then Attribute_Name (N) = Name_Result;
9013 end Is_Attribute_Result;
9015 ------------------------------------
9016 -- Is_Body_Or_Package_Declaration --
9017 ------------------------------------
9019 function Is_Body_Or_Package_Declaration (N : Node_Id) return Boolean is
9020 begin
9021 return Nkind_In (N, N_Entry_Body,
9022 N_Package_Body,
9023 N_Package_Declaration,
9024 N_Protected_Body,
9025 N_Subprogram_Body,
9026 N_Task_Body);
9027 end Is_Body_Or_Package_Declaration;
9029 -----------------------
9030 -- Is_Bounded_String --
9031 -----------------------
9033 function Is_Bounded_String (T : Entity_Id) return Boolean is
9034 Under : constant Entity_Id := Underlying_Type (Root_Type (T));
9036 begin
9037 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9038 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9039 -- be True for all the Bounded_String types in instances of the
9040 -- Generic_Bounded_Length generics, and for types derived from those.
9042 return Present (Under)
9043 and then (Is_RTE (Root_Type (Under), RO_SU_Super_String) or else
9044 Is_RTE (Root_Type (Under), RO_WI_Super_String) or else
9045 Is_RTE (Root_Type (Under), RO_WW_Super_String));
9046 end Is_Bounded_String;
9048 -------------------------
9049 -- Is_Child_Or_Sibling --
9050 -------------------------
9052 function Is_Child_Or_Sibling
9053 (Pack_1 : Entity_Id;
9054 Pack_2 : Entity_Id) return Boolean
9056 function Distance_From_Standard (Pack : Entity_Id) return Nat;
9057 -- Given an arbitrary package, return the number of "climbs" necessary
9058 -- to reach scope Standard_Standard.
9060 procedure Equalize_Depths
9061 (Pack : in out Entity_Id;
9062 Depth : in out Nat;
9063 Depth_To_Reach : Nat);
9064 -- Given an arbitrary package, its depth and a target depth to reach,
9065 -- climb the scope chain until the said depth is reached. The pointer
9066 -- to the package and its depth a modified during the climb.
9068 ----------------------------
9069 -- Distance_From_Standard --
9070 ----------------------------
9072 function Distance_From_Standard (Pack : Entity_Id) return Nat is
9073 Dist : Nat;
9074 Scop : Entity_Id;
9076 begin
9077 Dist := 0;
9078 Scop := Pack;
9079 while Present (Scop) and then Scop /= Standard_Standard loop
9080 Dist := Dist + 1;
9081 Scop := Scope (Scop);
9082 end loop;
9084 return Dist;
9085 end Distance_From_Standard;
9087 ---------------------
9088 -- Equalize_Depths --
9089 ---------------------
9091 procedure Equalize_Depths
9092 (Pack : in out Entity_Id;
9093 Depth : in out Nat;
9094 Depth_To_Reach : Nat)
9096 begin
9097 -- The package must be at a greater or equal depth
9099 if Depth < Depth_To_Reach then
9100 raise Program_Error;
9101 end if;
9103 -- Climb the scope chain until the desired depth is reached
9105 while Present (Pack) and then Depth /= Depth_To_Reach loop
9106 Pack := Scope (Pack);
9107 Depth := Depth - 1;
9108 end loop;
9109 end Equalize_Depths;
9111 -- Local variables
9113 P_1 : Entity_Id := Pack_1;
9114 P_1_Child : Boolean := False;
9115 P_1_Depth : Nat := Distance_From_Standard (P_1);
9116 P_2 : Entity_Id := Pack_2;
9117 P_2_Child : Boolean := False;
9118 P_2_Depth : Nat := Distance_From_Standard (P_2);
9120 -- Start of processing for Is_Child_Or_Sibling
9122 begin
9123 pragma Assert
9124 (Ekind (Pack_1) = E_Package and then Ekind (Pack_2) = E_Package);
9126 -- Both packages denote the same entity, therefore they cannot be
9127 -- children or siblings.
9129 if P_1 = P_2 then
9130 return False;
9132 -- One of the packages is at a deeper level than the other. Note that
9133 -- both may still come from differen hierarchies.
9135 -- (root) P_2
9136 -- / \ :
9137 -- X P_2 or X
9138 -- : :
9139 -- P_1 P_1
9141 elsif P_1_Depth > P_2_Depth then
9142 Equalize_Depths
9143 (Pack => P_1,
9144 Depth => P_1_Depth,
9145 Depth_To_Reach => P_2_Depth);
9146 P_1_Child := True;
9148 -- (root) P_1
9149 -- / \ :
9150 -- P_1 X or X
9151 -- : :
9152 -- P_2 P_2
9154 elsif P_2_Depth > P_1_Depth then
9155 Equalize_Depths
9156 (Pack => P_2,
9157 Depth => P_2_Depth,
9158 Depth_To_Reach => P_1_Depth);
9159 P_2_Child := True;
9160 end if;
9162 -- At this stage the package pointers have been elevated to the same
9163 -- depth. If the related entities are the same, then one package is a
9164 -- potential child of the other:
9166 -- P_1
9167 -- :
9168 -- X became P_1 P_2 or vica versa
9169 -- :
9170 -- P_2
9172 if P_1 = P_2 then
9173 if P_1_Child then
9174 return Is_Child_Unit (Pack_1);
9176 else pragma Assert (P_2_Child);
9177 return Is_Child_Unit (Pack_2);
9178 end if;
9180 -- The packages may come from the same package chain or from entirely
9181 -- different hierarcies. To determine this, climb the scope stack until
9182 -- a common root is found.
9184 -- (root) (root 1) (root 2)
9185 -- / \ | |
9186 -- P_1 P_2 P_1 P_2
9188 else
9189 while Present (P_1) and then Present (P_2) loop
9191 -- The two packages may be siblings
9193 if P_1 = P_2 then
9194 return Is_Child_Unit (Pack_1) and then Is_Child_Unit (Pack_2);
9195 end if;
9197 P_1 := Scope (P_1);
9198 P_2 := Scope (P_2);
9199 end loop;
9200 end if;
9202 return False;
9203 end Is_Child_Or_Sibling;
9205 -----------------------------
9206 -- Is_Concurrent_Interface --
9207 -----------------------------
9209 function Is_Concurrent_Interface (T : Entity_Id) return Boolean is
9210 begin
9211 return
9212 Is_Interface (T)
9213 and then
9214 (Is_Protected_Interface (T)
9215 or else Is_Synchronized_Interface (T)
9216 or else Is_Task_Interface (T));
9217 end Is_Concurrent_Interface;
9219 -----------------------
9220 -- Is_Constant_Bound --
9221 -----------------------
9223 function Is_Constant_Bound (Exp : Node_Id) return Boolean is
9224 begin
9225 if Compile_Time_Known_Value (Exp) then
9226 return True;
9228 elsif Is_Entity_Name (Exp) and then Present (Entity (Exp)) then
9229 return Is_Constant_Object (Entity (Exp))
9230 or else Ekind (Entity (Exp)) = E_Enumeration_Literal;
9232 elsif Nkind (Exp) in N_Binary_Op then
9233 return Is_Constant_Bound (Left_Opnd (Exp))
9234 and then Is_Constant_Bound (Right_Opnd (Exp))
9235 and then Scope (Entity (Exp)) = Standard_Standard;
9237 else
9238 return False;
9239 end if;
9240 end Is_Constant_Bound;
9242 --------------------------------------
9243 -- Is_Controlling_Limited_Procedure --
9244 --------------------------------------
9246 function Is_Controlling_Limited_Procedure
9247 (Proc_Nam : Entity_Id) return Boolean
9249 Param_Typ : Entity_Id := Empty;
9251 begin
9252 if Ekind (Proc_Nam) = E_Procedure
9253 and then Present (Parameter_Specifications (Parent (Proc_Nam)))
9254 then
9255 Param_Typ := Etype (Parameter_Type (First (
9256 Parameter_Specifications (Parent (Proc_Nam)))));
9258 -- In this case where an Itype was created, the procedure call has been
9259 -- rewritten.
9261 elsif Present (Associated_Node_For_Itype (Proc_Nam))
9262 and then Present (Original_Node (Associated_Node_For_Itype (Proc_Nam)))
9263 and then
9264 Present (Parameter_Associations
9265 (Associated_Node_For_Itype (Proc_Nam)))
9266 then
9267 Param_Typ :=
9268 Etype (First (Parameter_Associations
9269 (Associated_Node_For_Itype (Proc_Nam))));
9270 end if;
9272 if Present (Param_Typ) then
9273 return
9274 Is_Interface (Param_Typ)
9275 and then Is_Limited_Record (Param_Typ);
9276 end if;
9278 return False;
9279 end Is_Controlling_Limited_Procedure;
9281 -----------------------------
9282 -- Is_CPP_Constructor_Call --
9283 -----------------------------
9285 function Is_CPP_Constructor_Call (N : Node_Id) return Boolean is
9286 begin
9287 return Nkind (N) = N_Function_Call
9288 and then Is_CPP_Class (Etype (Etype (N)))
9289 and then Is_Constructor (Entity (Name (N)))
9290 and then Is_Imported (Entity (Name (N)));
9291 end Is_CPP_Constructor_Call;
9293 -----------------
9294 -- Is_Delegate --
9295 -----------------
9297 function Is_Delegate (T : Entity_Id) return Boolean is
9298 Desig_Type : Entity_Id;
9300 begin
9301 if VM_Target /= CLI_Target then
9302 return False;
9303 end if;
9305 -- Access-to-subprograms are delegates in CIL
9307 if Ekind (T) = E_Access_Subprogram_Type then
9308 return True;
9309 end if;
9311 if Ekind (T) not in Access_Kind then
9313 -- A delegate is a managed pointer. If no designated type is defined
9314 -- it means that it's not a delegate.
9316 return False;
9317 end if;
9319 Desig_Type := Etype (Directly_Designated_Type (T));
9321 if not Is_Tagged_Type (Desig_Type) then
9322 return False;
9323 end if;
9325 -- Test if the type is inherited from [mscorlib]System.Delegate
9327 while Etype (Desig_Type) /= Desig_Type loop
9328 if Chars (Scope (Desig_Type)) /= No_Name
9329 and then Is_Imported (Scope (Desig_Type))
9330 and then Get_Name_String (Chars (Scope (Desig_Type))) = "delegate"
9331 then
9332 return True;
9333 end if;
9335 Desig_Type := Etype (Desig_Type);
9336 end loop;
9338 return False;
9339 end Is_Delegate;
9341 ----------------------------------------------
9342 -- Is_Dependent_Component_Of_Mutable_Object --
9343 ----------------------------------------------
9345 function Is_Dependent_Component_Of_Mutable_Object
9346 (Object : Node_Id) return Boolean
9348 P : Node_Id;
9349 Prefix_Type : Entity_Id;
9350 P_Aliased : Boolean := False;
9351 Comp : Entity_Id;
9353 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean;
9354 -- Returns True if and only if Comp is declared within a variant part
9356 --------------------------------
9357 -- Is_Declared_Within_Variant --
9358 --------------------------------
9360 function Is_Declared_Within_Variant (Comp : Entity_Id) return Boolean is
9361 Comp_Decl : constant Node_Id := Parent (Comp);
9362 Comp_List : constant Node_Id := Parent (Comp_Decl);
9363 begin
9364 return Nkind (Parent (Comp_List)) = N_Variant;
9365 end Is_Declared_Within_Variant;
9367 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
9369 begin
9370 if Is_Variable (Object) then
9372 if Nkind (Object) = N_Selected_Component then
9373 P := Prefix (Object);
9374 Prefix_Type := Etype (P);
9376 if Is_Entity_Name (P) then
9378 if Ekind (Entity (P)) = E_Generic_In_Out_Parameter then
9379 Prefix_Type := Base_Type (Prefix_Type);
9380 end if;
9382 if Is_Aliased (Entity (P)) then
9383 P_Aliased := True;
9384 end if;
9386 -- A discriminant check on a selected component may be expanded
9387 -- into a dereference when removing side-effects. Recover the
9388 -- original node and its type, which may be unconstrained.
9390 elsif Nkind (P) = N_Explicit_Dereference
9391 and then not (Comes_From_Source (P))
9392 then
9393 P := Original_Node (P);
9394 Prefix_Type := Etype (P);
9396 else
9397 -- Check for prefix being an aliased component???
9399 null;
9401 end if;
9403 -- A heap object is constrained by its initial value
9405 -- Ada 2005 (AI-363): Always assume the object could be mutable in
9406 -- the dereferenced case, since the access value might denote an
9407 -- unconstrained aliased object, whereas in Ada 95 the designated
9408 -- object is guaranteed to be constrained. A worst-case assumption
9409 -- has to apply in Ada 2005 because we can't tell at compile time
9410 -- whether the object is "constrained by its initial value"
9411 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are
9412 -- semantic rules -- these rules are acknowledged to need fixing).
9414 if Ada_Version < Ada_2005 then
9415 if Is_Access_Type (Prefix_Type)
9416 or else Nkind (P) = N_Explicit_Dereference
9417 then
9418 return False;
9419 end if;
9421 elsif Ada_Version >= Ada_2005 then
9422 if Is_Access_Type (Prefix_Type) then
9424 -- If the access type is pool-specific, and there is no
9425 -- constrained partial view of the designated type, then the
9426 -- designated object is known to be constrained.
9428 if Ekind (Prefix_Type) = E_Access_Type
9429 and then not Object_Type_Has_Constrained_Partial_View
9430 (Typ => Designated_Type (Prefix_Type),
9431 Scop => Current_Scope)
9432 then
9433 return False;
9435 -- Otherwise (general access type, or there is a constrained
9436 -- partial view of the designated type), we need to check
9437 -- based on the designated type.
9439 else
9440 Prefix_Type := Designated_Type (Prefix_Type);
9441 end if;
9442 end if;
9443 end if;
9445 Comp :=
9446 Original_Record_Component (Entity (Selector_Name (Object)));
9448 -- As per AI-0017, the renaming is illegal in a generic body, even
9449 -- if the subtype is indefinite.
9451 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
9453 if not Is_Constrained (Prefix_Type)
9454 and then (not Is_Indefinite_Subtype (Prefix_Type)
9455 or else
9456 (Is_Generic_Type (Prefix_Type)
9457 and then Ekind (Current_Scope) = E_Generic_Package
9458 and then In_Package_Body (Current_Scope)))
9460 and then (Is_Declared_Within_Variant (Comp)
9461 or else Has_Discriminant_Dependent_Constraint (Comp))
9462 and then (not P_Aliased or else Ada_Version >= Ada_2005)
9463 then
9464 return True;
9466 -- If the prefix is of an access type at this point, then we want
9467 -- to return False, rather than calling this function recursively
9468 -- on the access object (which itself might be a discriminant-
9469 -- dependent component of some other object, but that isn't
9470 -- relevant to checking the object passed to us). This avoids
9471 -- issuing wrong errors when compiling with -gnatc, where there
9472 -- can be implicit dereferences that have not been expanded.
9474 elsif Is_Access_Type (Etype (Prefix (Object))) then
9475 return False;
9477 else
9478 return
9479 Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
9480 end if;
9482 elsif Nkind (Object) = N_Indexed_Component
9483 or else Nkind (Object) = N_Slice
9484 then
9485 return Is_Dependent_Component_Of_Mutable_Object (Prefix (Object));
9487 -- A type conversion that Is_Variable is a view conversion:
9488 -- go back to the denoted object.
9490 elsif Nkind (Object) = N_Type_Conversion then
9491 return
9492 Is_Dependent_Component_Of_Mutable_Object (Expression (Object));
9493 end if;
9494 end if;
9496 return False;
9497 end Is_Dependent_Component_Of_Mutable_Object;
9499 ---------------------
9500 -- Is_Dereferenced --
9501 ---------------------
9503 function Is_Dereferenced (N : Node_Id) return Boolean is
9504 P : constant Node_Id := Parent (N);
9505 begin
9506 return
9507 (Nkind (P) = N_Selected_Component
9508 or else
9509 Nkind (P) = N_Explicit_Dereference
9510 or else
9511 Nkind (P) = N_Indexed_Component
9512 or else
9513 Nkind (P) = N_Slice)
9514 and then Prefix (P) = N;
9515 end Is_Dereferenced;
9517 ----------------------
9518 -- Is_Descendent_Of --
9519 ----------------------
9521 function Is_Descendent_Of (T1 : Entity_Id; T2 : Entity_Id) return Boolean is
9522 T : Entity_Id;
9523 Etyp : Entity_Id;
9525 begin
9526 pragma Assert (Nkind (T1) in N_Entity);
9527 pragma Assert (Nkind (T2) in N_Entity);
9529 T := Base_Type (T1);
9531 -- Immediate return if the types match
9533 if T = T2 then
9534 return True;
9536 -- Comment needed here ???
9538 elsif Ekind (T) = E_Class_Wide_Type then
9539 return Etype (T) = T2;
9541 -- All other cases
9543 else
9544 loop
9545 Etyp := Etype (T);
9547 -- Done if we found the type we are looking for
9549 if Etyp = T2 then
9550 return True;
9552 -- Done if no more derivations to check
9554 elsif T = T1
9555 or else T = Etyp
9556 then
9557 return False;
9559 -- Following test catches error cases resulting from prev errors
9561 elsif No (Etyp) then
9562 return False;
9564 elsif Is_Private_Type (T) and then Etyp = Full_View (T) then
9565 return False;
9567 elsif Is_Private_Type (Etyp) and then Full_View (Etyp) = T then
9568 return False;
9569 end if;
9571 T := Base_Type (Etyp);
9572 end loop;
9573 end if;
9574 end Is_Descendent_Of;
9576 ----------------------------
9577 -- Is_Expression_Function --
9578 ----------------------------
9580 function Is_Expression_Function (Subp : Entity_Id) return Boolean is
9581 Decl : Node_Id;
9583 begin
9584 if Ekind (Subp) /= E_Function then
9585 return False;
9587 else
9588 Decl := Unit_Declaration_Node (Subp);
9589 return Nkind (Decl) = N_Subprogram_Declaration
9590 and then
9591 (Nkind (Original_Node (Decl)) = N_Expression_Function
9592 or else
9593 (Present (Corresponding_Body (Decl))
9594 and then
9595 Nkind (Original_Node
9596 (Unit_Declaration_Node
9597 (Corresponding_Body (Decl)))) =
9598 N_Expression_Function));
9599 end if;
9600 end Is_Expression_Function;
9602 --------------
9603 -- Is_False --
9604 --------------
9606 function Is_False (U : Uint) return Boolean is
9607 begin
9608 return (U = 0);
9609 end Is_False;
9611 ---------------------------
9612 -- Is_Fixed_Model_Number --
9613 ---------------------------
9615 function Is_Fixed_Model_Number (U : Ureal; T : Entity_Id) return Boolean is
9616 S : constant Ureal := Small_Value (T);
9617 M : Urealp.Save_Mark;
9618 R : Boolean;
9619 begin
9620 M := Urealp.Mark;
9621 R := (U = UR_Trunc (U / S) * S);
9622 Urealp.Release (M);
9623 return R;
9624 end Is_Fixed_Model_Number;
9626 -------------------------------
9627 -- Is_Fully_Initialized_Type --
9628 -------------------------------
9630 function Is_Fully_Initialized_Type (Typ : Entity_Id) return Boolean is
9631 begin
9632 -- In Ada2012, a scalar type with an aspect Default_Value
9633 -- is fully initialized.
9635 if Is_Scalar_Type (Typ) then
9636 return Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ);
9638 elsif Is_Access_Type (Typ) then
9639 return True;
9641 elsif Is_Array_Type (Typ) then
9642 if Is_Fully_Initialized_Type (Component_Type (Typ))
9643 or else (Ada_Version >= Ada_2012 and then Has_Default_Aspect (Typ))
9644 then
9645 return True;
9646 end if;
9648 -- An interesting case, if we have a constrained type one of whose
9649 -- bounds is known to be null, then there are no elements to be
9650 -- initialized, so all the elements are initialized.
9652 if Is_Constrained (Typ) then
9653 declare
9654 Indx : Node_Id;
9655 Indx_Typ : Entity_Id;
9656 Lbd, Hbd : Node_Id;
9658 begin
9659 Indx := First_Index (Typ);
9660 while Present (Indx) loop
9661 if Etype (Indx) = Any_Type then
9662 return False;
9664 -- If index is a range, use directly
9666 elsif Nkind (Indx) = N_Range then
9667 Lbd := Low_Bound (Indx);
9668 Hbd := High_Bound (Indx);
9670 else
9671 Indx_Typ := Etype (Indx);
9673 if Is_Private_Type (Indx_Typ) then
9674 Indx_Typ := Full_View (Indx_Typ);
9675 end if;
9677 if No (Indx_Typ) or else Etype (Indx_Typ) = Any_Type then
9678 return False;
9679 else
9680 Lbd := Type_Low_Bound (Indx_Typ);
9681 Hbd := Type_High_Bound (Indx_Typ);
9682 end if;
9683 end if;
9685 if Compile_Time_Known_Value (Lbd)
9686 and then Compile_Time_Known_Value (Hbd)
9687 then
9688 if Expr_Value (Hbd) < Expr_Value (Lbd) then
9689 return True;
9690 end if;
9691 end if;
9693 Next_Index (Indx);
9694 end loop;
9695 end;
9696 end if;
9698 -- If no null indexes, then type is not fully initialized
9700 return False;
9702 -- Record types
9704 elsif Is_Record_Type (Typ) then
9705 if Has_Discriminants (Typ)
9706 and then
9707 Present (Discriminant_Default_Value (First_Discriminant (Typ)))
9708 and then Is_Fully_Initialized_Variant (Typ)
9709 then
9710 return True;
9711 end if;
9713 -- We consider bounded string types to be fully initialized, because
9714 -- otherwise we get false alarms when the Data component is not
9715 -- default-initialized.
9717 if Is_Bounded_String (Typ) then
9718 return True;
9719 end if;
9721 -- Controlled records are considered to be fully initialized if
9722 -- there is a user defined Initialize routine. This may not be
9723 -- entirely correct, but as the spec notes, we are guessing here
9724 -- what is best from the point of view of issuing warnings.
9726 if Is_Controlled (Typ) then
9727 declare
9728 Utyp : constant Entity_Id := Underlying_Type (Typ);
9730 begin
9731 if Present (Utyp) then
9732 declare
9733 Init : constant Entity_Id :=
9734 (Find_Prim_Op
9735 (Underlying_Type (Typ), Name_Initialize));
9737 begin
9738 if Present (Init)
9739 and then Comes_From_Source (Init)
9740 and then not
9741 Is_Predefined_File_Name
9742 (File_Name (Get_Source_File_Index (Sloc (Init))))
9743 then
9744 return True;
9746 elsif Has_Null_Extension (Typ)
9747 and then
9748 Is_Fully_Initialized_Type
9749 (Etype (Base_Type (Typ)))
9750 then
9751 return True;
9752 end if;
9753 end;
9754 end if;
9755 end;
9756 end if;
9758 -- Otherwise see if all record components are initialized
9760 declare
9761 Ent : Entity_Id;
9763 begin
9764 Ent := First_Entity (Typ);
9765 while Present (Ent) loop
9766 if Ekind (Ent) = E_Component
9767 and then (No (Parent (Ent))
9768 or else No (Expression (Parent (Ent))))
9769 and then not Is_Fully_Initialized_Type (Etype (Ent))
9771 -- Special VM case for tag components, which need to be
9772 -- defined in this case, but are never initialized as VMs
9773 -- are using other dispatching mechanisms. Ignore this
9774 -- uninitialized case. Note that this applies both to the
9775 -- uTag entry and the main vtable pointer (CPP_Class case).
9777 and then (Tagged_Type_Expansion or else not Is_Tag (Ent))
9778 then
9779 return False;
9780 end if;
9782 Next_Entity (Ent);
9783 end loop;
9784 end;
9786 -- No uninitialized components, so type is fully initialized.
9787 -- Note that this catches the case of no components as well.
9789 return True;
9791 elsif Is_Concurrent_Type (Typ) then
9792 return True;
9794 elsif Is_Private_Type (Typ) then
9795 declare
9796 U : constant Entity_Id := Underlying_Type (Typ);
9798 begin
9799 if No (U) then
9800 return False;
9801 else
9802 return Is_Fully_Initialized_Type (U);
9803 end if;
9804 end;
9806 else
9807 return False;
9808 end if;
9809 end Is_Fully_Initialized_Type;
9811 ----------------------------------
9812 -- Is_Fully_Initialized_Variant --
9813 ----------------------------------
9815 function Is_Fully_Initialized_Variant (Typ : Entity_Id) return Boolean is
9816 Loc : constant Source_Ptr := Sloc (Typ);
9817 Constraints : constant List_Id := New_List;
9818 Components : constant Elist_Id := New_Elmt_List;
9819 Comp_Elmt : Elmt_Id;
9820 Comp_Id : Node_Id;
9821 Comp_List : Node_Id;
9822 Discr : Entity_Id;
9823 Discr_Val : Node_Id;
9825 Report_Errors : Boolean;
9826 pragma Warnings (Off, Report_Errors);
9828 begin
9829 if Serious_Errors_Detected > 0 then
9830 return False;
9831 end if;
9833 if Is_Record_Type (Typ)
9834 and then Nkind (Parent (Typ)) = N_Full_Type_Declaration
9835 and then Nkind (Type_Definition (Parent (Typ))) = N_Record_Definition
9836 then
9837 Comp_List := Component_List (Type_Definition (Parent (Typ)));
9839 Discr := First_Discriminant (Typ);
9840 while Present (Discr) loop
9841 if Nkind (Parent (Discr)) = N_Discriminant_Specification then
9842 Discr_Val := Expression (Parent (Discr));
9844 if Present (Discr_Val)
9845 and then Is_OK_Static_Expression (Discr_Val)
9846 then
9847 Append_To (Constraints,
9848 Make_Component_Association (Loc,
9849 Choices => New_List (New_Occurrence_Of (Discr, Loc)),
9850 Expression => New_Copy (Discr_Val)));
9851 else
9852 return False;
9853 end if;
9854 else
9855 return False;
9856 end if;
9858 Next_Discriminant (Discr);
9859 end loop;
9861 Gather_Components
9862 (Typ => Typ,
9863 Comp_List => Comp_List,
9864 Governed_By => Constraints,
9865 Into => Components,
9866 Report_Errors => Report_Errors);
9868 -- Check that each component present is fully initialized
9870 Comp_Elmt := First_Elmt (Components);
9871 while Present (Comp_Elmt) loop
9872 Comp_Id := Node (Comp_Elmt);
9874 if Ekind (Comp_Id) = E_Component
9875 and then (No (Parent (Comp_Id))
9876 or else No (Expression (Parent (Comp_Id))))
9877 and then not Is_Fully_Initialized_Type (Etype (Comp_Id))
9878 then
9879 return False;
9880 end if;
9882 Next_Elmt (Comp_Elmt);
9883 end loop;
9885 return True;
9887 elsif Is_Private_Type (Typ) then
9888 declare
9889 U : constant Entity_Id := Underlying_Type (Typ);
9891 begin
9892 if No (U) then
9893 return False;
9894 else
9895 return Is_Fully_Initialized_Variant (U);
9896 end if;
9897 end;
9899 else
9900 return False;
9901 end if;
9902 end Is_Fully_Initialized_Variant;
9904 ----------------------------
9905 -- Is_Inherited_Operation --
9906 ----------------------------
9908 function Is_Inherited_Operation (E : Entity_Id) return Boolean is
9909 pragma Assert (Is_Overloadable (E));
9910 Kind : constant Node_Kind := Nkind (Parent (E));
9911 begin
9912 return Kind = N_Full_Type_Declaration
9913 or else Kind = N_Private_Extension_Declaration
9914 or else Kind = N_Subtype_Declaration
9915 or else (Ekind (E) = E_Enumeration_Literal
9916 and then Is_Derived_Type (Etype (E)));
9917 end Is_Inherited_Operation;
9919 -------------------------------------
9920 -- Is_Inherited_Operation_For_Type --
9921 -------------------------------------
9923 function Is_Inherited_Operation_For_Type
9924 (E : Entity_Id;
9925 Typ : Entity_Id) return Boolean
9927 begin
9928 -- Check that the operation has been created by the type declaration
9930 return Is_Inherited_Operation (E)
9931 and then Defining_Identifier (Parent (E)) = Typ;
9932 end Is_Inherited_Operation_For_Type;
9934 -----------------
9935 -- Is_Iterator --
9936 -----------------
9938 function Is_Iterator (Typ : Entity_Id) return Boolean is
9939 Ifaces_List : Elist_Id;
9940 Iface_Elmt : Elmt_Id;
9941 Iface : Entity_Id;
9943 begin
9944 if Is_Class_Wide_Type (Typ)
9945 and then
9946 Nam_In (Chars (Etype (Typ)), Name_Forward_Iterator,
9947 Name_Reversible_Iterator)
9948 and then
9949 Is_Predefined_File_Name
9950 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
9951 then
9952 return True;
9954 elsif not Is_Tagged_Type (Typ) or else not Is_Derived_Type (Typ) then
9955 return False;
9957 else
9958 Collect_Interfaces (Typ, Ifaces_List);
9960 Iface_Elmt := First_Elmt (Ifaces_List);
9961 while Present (Iface_Elmt) loop
9962 Iface := Node (Iface_Elmt);
9963 if Chars (Iface) = Name_Forward_Iterator
9964 and then
9965 Is_Predefined_File_Name
9966 (Unit_File_Name (Get_Source_Unit (Iface)))
9967 then
9968 return True;
9969 end if;
9971 Next_Elmt (Iface_Elmt);
9972 end loop;
9974 return False;
9975 end if;
9976 end Is_Iterator;
9978 ------------
9979 -- Is_LHS --
9980 ------------
9982 -- We seem to have a lot of overlapping functions that do similar things
9983 -- (testing for left hand sides or lvalues???).
9985 function Is_LHS (N : Node_Id) return Boolean is
9986 P : constant Node_Id := Parent (N);
9988 begin
9989 -- Return True if we are the left hand side of an assignment statement
9991 if Nkind (P) = N_Assignment_Statement then
9992 return Name (P) = N;
9994 -- Case of prefix of indexed or selected component or slice
9996 elsif Nkind_In (P, N_Indexed_Component, N_Selected_Component, N_Slice)
9997 and then N = Prefix (P)
9998 then
9999 -- Here we have the case where the parent P is N.Q or N(Q .. R).
10000 -- If P is an LHS, then N is also effectively an LHS, but there
10001 -- is an important exception. If N is of an access type, then
10002 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
10003 -- case this makes N.all a left hand side but not N itself.
10005 -- Here follows a worrisome kludge. If Etype (N) is not set, which
10006 -- for sure happens in the call from Find_Direct_Name, that means we
10007 -- don't know if N is of an access type, so we can't give an accurate
10008 -- answer. For now, we assume we do not have an access type, which
10009 -- means for example that P.Q.R := X will look like a modification
10010 -- of P, even if P.Q eventually turns out to be an access type. The
10011 -- consequence is at least that in some cases we incorrectly identify
10012 -- a reference as a modification. It is not clear if there are any
10013 -- other bad consequences. ???
10015 if No (Etype (N)) then
10016 return False;
10018 -- We have an Etype set, so we can check it
10020 elsif Is_Access_Type (Etype (N)) then
10021 return False;
10023 -- OK, not access type case, so just test whole expression
10025 else
10026 return Is_LHS (P);
10027 end if;
10029 -- All other cases are not left hand sides
10031 else
10032 return False;
10033 end if;
10034 end Is_LHS;
10036 -----------------------------
10037 -- Is_Library_Level_Entity --
10038 -----------------------------
10040 function Is_Library_Level_Entity (E : Entity_Id) return Boolean is
10041 begin
10042 -- The following is a small optimization, and it also properly handles
10043 -- discriminals, which in task bodies might appear in expressions before
10044 -- the corresponding procedure has been created, and which therefore do
10045 -- not have an assigned scope.
10047 if Is_Formal (E) then
10048 return False;
10049 end if;
10051 -- Normal test is simply that the enclosing dynamic scope is Standard
10053 return Enclosing_Dynamic_Scope (E) = Standard_Standard;
10054 end Is_Library_Level_Entity;
10056 --------------------------------
10057 -- Is_Limited_Class_Wide_Type --
10058 --------------------------------
10060 function Is_Limited_Class_Wide_Type (Typ : Entity_Id) return Boolean is
10061 begin
10062 return
10063 Is_Class_Wide_Type (Typ)
10064 and then (Is_Limited_Type (Typ) or else From_Limited_With (Typ));
10065 end Is_Limited_Class_Wide_Type;
10067 ---------------------------------
10068 -- Is_Local_Variable_Reference --
10069 ---------------------------------
10071 function Is_Local_Variable_Reference (Expr : Node_Id) return Boolean is
10072 begin
10073 if not Is_Entity_Name (Expr) then
10074 return False;
10076 else
10077 declare
10078 Ent : constant Entity_Id := Entity (Expr);
10079 Sub : constant Entity_Id := Enclosing_Subprogram (Ent);
10080 begin
10081 if not Ekind_In (Ent, E_Variable, E_In_Out_Parameter) then
10082 return False;
10083 else
10084 return Present (Sub) and then Sub = Current_Subprogram;
10085 end if;
10086 end;
10087 end if;
10088 end Is_Local_Variable_Reference;
10090 -------------------------
10091 -- Is_Object_Reference --
10092 -------------------------
10094 function Is_Object_Reference (N : Node_Id) return Boolean is
10096 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean;
10097 -- Determine whether N is the name of an internally-generated renaming
10099 --------------------------------------
10100 -- Is_Internally_Generated_Renaming --
10101 --------------------------------------
10103 function Is_Internally_Generated_Renaming (N : Node_Id) return Boolean is
10104 P : Node_Id;
10106 begin
10107 P := N;
10108 while Present (P) loop
10109 if Nkind (P) = N_Object_Renaming_Declaration then
10110 return not Comes_From_Source (P);
10111 elsif Is_List_Member (P) then
10112 return False;
10113 end if;
10115 P := Parent (P);
10116 end loop;
10118 return False;
10119 end Is_Internally_Generated_Renaming;
10121 -- Start of processing for Is_Object_Reference
10123 begin
10124 if Is_Entity_Name (N) then
10125 return Present (Entity (N)) and then Is_Object (Entity (N));
10127 else
10128 case Nkind (N) is
10129 when N_Indexed_Component | N_Slice =>
10130 return
10131 Is_Object_Reference (Prefix (N))
10132 or else Is_Access_Type (Etype (Prefix (N)));
10134 -- In Ada 95, a function call is a constant object; a procedure
10135 -- call is not.
10137 when N_Function_Call =>
10138 return Etype (N) /= Standard_Void_Type;
10140 -- Attributes 'Input, 'Old and 'Result produce objects
10142 when N_Attribute_Reference =>
10143 return
10144 Nam_In
10145 (Attribute_Name (N), Name_Input, Name_Old, Name_Result);
10147 when N_Selected_Component =>
10148 return
10149 Is_Object_Reference (Selector_Name (N))
10150 and then
10151 (Is_Object_Reference (Prefix (N))
10152 or else Is_Access_Type (Etype (Prefix (N))));
10154 when N_Explicit_Dereference =>
10155 return True;
10157 -- A view conversion of a tagged object is an object reference
10159 when N_Type_Conversion =>
10160 return Is_Tagged_Type (Etype (Subtype_Mark (N)))
10161 and then Is_Tagged_Type (Etype (Expression (N)))
10162 and then Is_Object_Reference (Expression (N));
10164 -- An unchecked type conversion is considered to be an object if
10165 -- the operand is an object (this construction arises only as a
10166 -- result of expansion activities).
10168 when N_Unchecked_Type_Conversion =>
10169 return True;
10171 -- Allow string literals to act as objects as long as they appear
10172 -- in internally-generated renamings. The expansion of iterators
10173 -- may generate such renamings when the range involves a string
10174 -- literal.
10176 when N_String_Literal =>
10177 return Is_Internally_Generated_Renaming (Parent (N));
10179 -- AI05-0003: In Ada 2012 a qualified expression is a name.
10180 -- This allows disambiguation of function calls and the use
10181 -- of aggregates in more contexts.
10183 when N_Qualified_Expression =>
10184 if Ada_Version < Ada_2012 then
10185 return False;
10186 else
10187 return Is_Object_Reference (Expression (N))
10188 or else Nkind (Expression (N)) = N_Aggregate;
10189 end if;
10191 when others =>
10192 return False;
10193 end case;
10194 end if;
10195 end Is_Object_Reference;
10197 -----------------------------------
10198 -- Is_OK_Variable_For_Out_Formal --
10199 -----------------------------------
10201 function Is_OK_Variable_For_Out_Formal (AV : Node_Id) return Boolean is
10202 begin
10203 Note_Possible_Modification (AV, Sure => True);
10205 -- We must reject parenthesized variable names. Comes_From_Source is
10206 -- checked because there are currently cases where the compiler violates
10207 -- this rule (e.g. passing a task object to its controlled Initialize
10208 -- routine). This should be properly documented in sinfo???
10210 if Paren_Count (AV) > 0 and then Comes_From_Source (AV) then
10211 return False;
10213 -- A variable is always allowed
10215 elsif Is_Variable (AV) then
10216 return True;
10218 -- Unchecked conversions are allowed only if they come from the
10219 -- generated code, which sometimes uses unchecked conversions for out
10220 -- parameters in cases where code generation is unaffected. We tell
10221 -- source unchecked conversions by seeing if they are rewrites of
10222 -- an original Unchecked_Conversion function call, or of an explicit
10223 -- conversion of a function call or an aggregate (as may happen in the
10224 -- expansion of a packed array aggregate).
10226 elsif Nkind (AV) = N_Unchecked_Type_Conversion then
10227 if Nkind_In (Original_Node (AV), N_Function_Call, N_Aggregate) then
10228 return False;
10230 elsif Comes_From_Source (AV)
10231 and then Nkind (Original_Node (Expression (AV))) = N_Function_Call
10232 then
10233 return False;
10235 elsif Nkind (Original_Node (AV)) = N_Type_Conversion then
10236 return Is_OK_Variable_For_Out_Formal (Expression (AV));
10238 else
10239 return True;
10240 end if;
10242 -- Normal type conversions are allowed if argument is a variable
10244 elsif Nkind (AV) = N_Type_Conversion then
10245 if Is_Variable (Expression (AV))
10246 and then Paren_Count (Expression (AV)) = 0
10247 then
10248 Note_Possible_Modification (Expression (AV), Sure => True);
10249 return True;
10251 -- We also allow a non-parenthesized expression that raises
10252 -- constraint error if it rewrites what used to be a variable
10254 elsif Raises_Constraint_Error (Expression (AV))
10255 and then Paren_Count (Expression (AV)) = 0
10256 and then Is_Variable (Original_Node (Expression (AV)))
10257 then
10258 return True;
10260 -- Type conversion of something other than a variable
10262 else
10263 return False;
10264 end if;
10266 -- If this node is rewritten, then test the original form, if that is
10267 -- OK, then we consider the rewritten node OK (for example, if the
10268 -- original node is a conversion, then Is_Variable will not be true
10269 -- but we still want to allow the conversion if it converts a variable).
10271 elsif Original_Node (AV) /= AV then
10273 -- In Ada 2012, the explicit dereference may be a rewritten call to a
10274 -- Reference function.
10276 if Ada_Version >= Ada_2012
10277 and then Nkind (Original_Node (AV)) = N_Function_Call
10278 and then
10279 Has_Implicit_Dereference (Etype (Name (Original_Node (AV))))
10280 then
10281 return True;
10283 else
10284 return Is_OK_Variable_For_Out_Formal (Original_Node (AV));
10285 end if;
10287 -- All other non-variables are rejected
10289 else
10290 return False;
10291 end if;
10292 end Is_OK_Variable_For_Out_Formal;
10294 -----------------------------------
10295 -- Is_Partially_Initialized_Type --
10296 -----------------------------------
10298 function Is_Partially_Initialized_Type
10299 (Typ : Entity_Id;
10300 Include_Implicit : Boolean := True) return Boolean
10302 begin
10303 if Is_Scalar_Type (Typ) then
10304 return False;
10306 elsif Is_Access_Type (Typ) then
10307 return Include_Implicit;
10309 elsif Is_Array_Type (Typ) then
10311 -- If component type is partially initialized, so is array type
10313 if Is_Partially_Initialized_Type
10314 (Component_Type (Typ), Include_Implicit)
10315 then
10316 return True;
10318 -- Otherwise we are only partially initialized if we are fully
10319 -- initialized (this is the empty array case, no point in us
10320 -- duplicating that code here).
10322 else
10323 return Is_Fully_Initialized_Type (Typ);
10324 end if;
10326 elsif Is_Record_Type (Typ) then
10328 -- A discriminated type is always partially initialized if in
10329 -- all mode
10331 if Has_Discriminants (Typ) and then Include_Implicit then
10332 return True;
10334 -- A tagged type is always partially initialized
10336 elsif Is_Tagged_Type (Typ) then
10337 return True;
10339 -- Case of non-discriminated record
10341 else
10342 declare
10343 Ent : Entity_Id;
10345 Component_Present : Boolean := False;
10346 -- Set True if at least one component is present. If no
10347 -- components are present, then record type is fully
10348 -- initialized (another odd case, like the null array).
10350 begin
10351 -- Loop through components
10353 Ent := First_Entity (Typ);
10354 while Present (Ent) loop
10355 if Ekind (Ent) = E_Component then
10356 Component_Present := True;
10358 -- If a component has an initialization expression then
10359 -- the enclosing record type is partially initialized
10361 if Present (Parent (Ent))
10362 and then Present (Expression (Parent (Ent)))
10363 then
10364 return True;
10366 -- If a component is of a type which is itself partially
10367 -- initialized, then the enclosing record type is also.
10369 elsif Is_Partially_Initialized_Type
10370 (Etype (Ent), Include_Implicit)
10371 then
10372 return True;
10373 end if;
10374 end if;
10376 Next_Entity (Ent);
10377 end loop;
10379 -- No initialized components found. If we found any components
10380 -- they were all uninitialized so the result is false.
10382 if Component_Present then
10383 return False;
10385 -- But if we found no components, then all the components are
10386 -- initialized so we consider the type to be initialized.
10388 else
10389 return True;
10390 end if;
10391 end;
10392 end if;
10394 -- Concurrent types are always fully initialized
10396 elsif Is_Concurrent_Type (Typ) then
10397 return True;
10399 -- For a private type, go to underlying type. If there is no underlying
10400 -- type then just assume this partially initialized. Not clear if this
10401 -- can happen in a non-error case, but no harm in testing for this.
10403 elsif Is_Private_Type (Typ) then
10404 declare
10405 U : constant Entity_Id := Underlying_Type (Typ);
10406 begin
10407 if No (U) then
10408 return True;
10409 else
10410 return Is_Partially_Initialized_Type (U, Include_Implicit);
10411 end if;
10412 end;
10414 -- For any other type (are there any?) assume partially initialized
10416 else
10417 return True;
10418 end if;
10419 end Is_Partially_Initialized_Type;
10421 ------------------------------------
10422 -- Is_Potentially_Persistent_Type --
10423 ------------------------------------
10425 function Is_Potentially_Persistent_Type (T : Entity_Id) return Boolean is
10426 Comp : Entity_Id;
10427 Indx : Node_Id;
10429 begin
10430 -- For private type, test corresponding full type
10432 if Is_Private_Type (T) then
10433 return Is_Potentially_Persistent_Type (Full_View (T));
10435 -- Scalar types are potentially persistent
10437 elsif Is_Scalar_Type (T) then
10438 return True;
10440 -- Record type is potentially persistent if not tagged and the types of
10441 -- all it components are potentially persistent, and no component has
10442 -- an initialization expression.
10444 elsif Is_Record_Type (T)
10445 and then not Is_Tagged_Type (T)
10446 and then not Is_Partially_Initialized_Type (T)
10447 then
10448 Comp := First_Component (T);
10449 while Present (Comp) loop
10450 if not Is_Potentially_Persistent_Type (Etype (Comp)) then
10451 return False;
10452 else
10453 Next_Entity (Comp);
10454 end if;
10455 end loop;
10457 return True;
10459 -- Array type is potentially persistent if its component type is
10460 -- potentially persistent and if all its constraints are static.
10462 elsif Is_Array_Type (T) then
10463 if not Is_Potentially_Persistent_Type (Component_Type (T)) then
10464 return False;
10465 end if;
10467 Indx := First_Index (T);
10468 while Present (Indx) loop
10469 if not Is_OK_Static_Subtype (Etype (Indx)) then
10470 return False;
10471 else
10472 Next_Index (Indx);
10473 end if;
10474 end loop;
10476 return True;
10478 -- All other types are not potentially persistent
10480 else
10481 return False;
10482 end if;
10483 end Is_Potentially_Persistent_Type;
10485 --------------------------------
10486 -- Is_Potentially_Unevaluated --
10487 --------------------------------
10489 function Is_Potentially_Unevaluated (N : Node_Id) return Boolean is
10490 Par : Node_Id;
10491 Expr : Node_Id;
10493 begin
10494 Expr := N;
10495 Par := Parent (N);
10496 while not Nkind_In (Par, N_If_Expression,
10497 N_Case_Expression,
10498 N_And_Then,
10499 N_Or_Else,
10500 N_In,
10501 N_Not_In)
10502 loop
10503 Expr := Par;
10504 Par := Parent (Par);
10506 -- If the context is not an expression, or if is the result of
10507 -- expansion of an enclosing construct (such as another attribute)
10508 -- the predicate does not apply.
10510 if Nkind (Par) not in N_Subexpr
10511 or else not Comes_From_Source (Par)
10512 then
10513 return False;
10514 end if;
10515 end loop;
10517 if Nkind (Par) = N_If_Expression then
10518 return Is_Elsif (Par) or else Expr /= First (Expressions (Par));
10520 elsif Nkind (Par) = N_Case_Expression then
10521 return Expr /= Expression (Par);
10523 elsif Nkind_In (Par, N_And_Then, N_Or_Else) then
10524 return Expr = Right_Opnd (Par);
10526 elsif Nkind_In (Par, N_In, N_Not_In) then
10527 return Expr /= Left_Opnd (Par);
10529 else
10530 return False;
10531 end if;
10532 end Is_Potentially_Unevaluated;
10534 ---------------------------------
10535 -- Is_Protected_Self_Reference --
10536 ---------------------------------
10538 function Is_Protected_Self_Reference (N : Node_Id) return Boolean is
10540 function In_Access_Definition (N : Node_Id) return Boolean;
10541 -- Returns true if N belongs to an access definition
10543 --------------------------
10544 -- In_Access_Definition --
10545 --------------------------
10547 function In_Access_Definition (N : Node_Id) return Boolean is
10548 P : Node_Id;
10550 begin
10551 P := Parent (N);
10552 while Present (P) loop
10553 if Nkind (P) = N_Access_Definition then
10554 return True;
10555 end if;
10557 P := Parent (P);
10558 end loop;
10560 return False;
10561 end In_Access_Definition;
10563 -- Start of processing for Is_Protected_Self_Reference
10565 begin
10566 -- Verify that prefix is analyzed and has the proper form. Note that
10567 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
10568 -- which also produce the address of an entity, do not analyze their
10569 -- prefix because they denote entities that are not necessarily visible.
10570 -- Neither of them can apply to a protected type.
10572 return Ada_Version >= Ada_2005
10573 and then Is_Entity_Name (N)
10574 and then Present (Entity (N))
10575 and then Is_Protected_Type (Entity (N))
10576 and then In_Open_Scopes (Entity (N))
10577 and then not In_Access_Definition (N);
10578 end Is_Protected_Self_Reference;
10580 -----------------------------
10581 -- Is_RCI_Pkg_Spec_Or_Body --
10582 -----------------------------
10584 function Is_RCI_Pkg_Spec_Or_Body (Cunit : Node_Id) return Boolean is
10586 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean;
10587 -- Return True if the unit of Cunit is an RCI package declaration
10589 ---------------------------
10590 -- Is_RCI_Pkg_Decl_Cunit --
10591 ---------------------------
10593 function Is_RCI_Pkg_Decl_Cunit (Cunit : Node_Id) return Boolean is
10594 The_Unit : constant Node_Id := Unit (Cunit);
10596 begin
10597 if Nkind (The_Unit) /= N_Package_Declaration then
10598 return False;
10599 end if;
10601 return Is_Remote_Call_Interface (Defining_Entity (The_Unit));
10602 end Is_RCI_Pkg_Decl_Cunit;
10604 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
10606 begin
10607 return Is_RCI_Pkg_Decl_Cunit (Cunit)
10608 or else
10609 (Nkind (Unit (Cunit)) = N_Package_Body
10610 and then Is_RCI_Pkg_Decl_Cunit (Library_Unit (Cunit)));
10611 end Is_RCI_Pkg_Spec_Or_Body;
10613 -----------------------------------------
10614 -- Is_Remote_Access_To_Class_Wide_Type --
10615 -----------------------------------------
10617 function Is_Remote_Access_To_Class_Wide_Type
10618 (E : Entity_Id) return Boolean
10620 begin
10621 -- A remote access to class-wide type is a general access to object type
10622 -- declared in the visible part of a Remote_Types or Remote_Call_
10623 -- Interface unit.
10625 return Ekind (E) = E_General_Access_Type
10626 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
10627 end Is_Remote_Access_To_Class_Wide_Type;
10629 -----------------------------------------
10630 -- Is_Remote_Access_To_Subprogram_Type --
10631 -----------------------------------------
10633 function Is_Remote_Access_To_Subprogram_Type
10634 (E : Entity_Id) return Boolean
10636 begin
10637 return (Ekind (E) = E_Access_Subprogram_Type
10638 or else (Ekind (E) = E_Record_Type
10639 and then Present (Corresponding_Remote_Type (E))))
10640 and then (Is_Remote_Call_Interface (E) or else Is_Remote_Types (E));
10641 end Is_Remote_Access_To_Subprogram_Type;
10643 --------------------
10644 -- Is_Remote_Call --
10645 --------------------
10647 function Is_Remote_Call (N : Node_Id) return Boolean is
10648 begin
10649 if Nkind (N) not in N_Subprogram_Call then
10651 -- An entry call cannot be remote
10653 return False;
10655 elsif Nkind (Name (N)) in N_Has_Entity
10656 and then Is_Remote_Call_Interface (Entity (Name (N)))
10657 then
10658 -- A subprogram declared in the spec of a RCI package is remote
10660 return True;
10662 elsif Nkind (Name (N)) = N_Explicit_Dereference
10663 and then Is_Remote_Access_To_Subprogram_Type
10664 (Etype (Prefix (Name (N))))
10665 then
10666 -- The dereference of a RAS is a remote call
10668 return True;
10670 elsif Present (Controlling_Argument (N))
10671 and then Is_Remote_Access_To_Class_Wide_Type
10672 (Etype (Controlling_Argument (N)))
10673 then
10674 -- Any primitive operation call with a controlling argument of
10675 -- a RACW type is a remote call.
10677 return True;
10678 end if;
10680 -- All other calls are local calls
10682 return False;
10683 end Is_Remote_Call;
10685 ----------------------
10686 -- Is_Renamed_Entry --
10687 ----------------------
10689 function Is_Renamed_Entry (Proc_Nam : Entity_Id) return Boolean is
10690 Orig_Node : Node_Id := Empty;
10691 Subp_Decl : Node_Id := Parent (Parent (Proc_Nam));
10693 function Is_Entry (Nam : Node_Id) return Boolean;
10694 -- Determine whether Nam is an entry. Traverse selectors if there are
10695 -- nested selected components.
10697 --------------
10698 -- Is_Entry --
10699 --------------
10701 function Is_Entry (Nam : Node_Id) return Boolean is
10702 begin
10703 if Nkind (Nam) = N_Selected_Component then
10704 return Is_Entry (Selector_Name (Nam));
10705 end if;
10707 return Ekind (Entity (Nam)) = E_Entry;
10708 end Is_Entry;
10710 -- Start of processing for Is_Renamed_Entry
10712 begin
10713 if Present (Alias (Proc_Nam)) then
10714 Subp_Decl := Parent (Parent (Alias (Proc_Nam)));
10715 end if;
10717 -- Look for a rewritten subprogram renaming declaration
10719 if Nkind (Subp_Decl) = N_Subprogram_Declaration
10720 and then Present (Original_Node (Subp_Decl))
10721 then
10722 Orig_Node := Original_Node (Subp_Decl);
10723 end if;
10725 -- The rewritten subprogram is actually an entry
10727 if Present (Orig_Node)
10728 and then Nkind (Orig_Node) = N_Subprogram_Renaming_Declaration
10729 and then Is_Entry (Name (Orig_Node))
10730 then
10731 return True;
10732 end if;
10734 return False;
10735 end Is_Renamed_Entry;
10737 ----------------------------
10738 -- Is_Reversible_Iterator --
10739 ----------------------------
10741 function Is_Reversible_Iterator (Typ : Entity_Id) return Boolean is
10742 Ifaces_List : Elist_Id;
10743 Iface_Elmt : Elmt_Id;
10744 Iface : Entity_Id;
10746 begin
10747 if Is_Class_Wide_Type (Typ)
10748 and then Chars (Etype (Typ)) = Name_Reversible_Iterator
10749 and then
10750 Is_Predefined_File_Name
10751 (Unit_File_Name (Get_Source_Unit (Etype (Typ))))
10752 then
10753 return True;
10755 elsif not Is_Tagged_Type (Typ)
10756 or else not Is_Derived_Type (Typ)
10757 then
10758 return False;
10760 else
10761 Collect_Interfaces (Typ, Ifaces_List);
10763 Iface_Elmt := First_Elmt (Ifaces_List);
10764 while Present (Iface_Elmt) loop
10765 Iface := Node (Iface_Elmt);
10766 if Chars (Iface) = Name_Reversible_Iterator
10767 and then
10768 Is_Predefined_File_Name
10769 (Unit_File_Name (Get_Source_Unit (Iface)))
10770 then
10771 return True;
10772 end if;
10774 Next_Elmt (Iface_Elmt);
10775 end loop;
10776 end if;
10778 return False;
10779 end Is_Reversible_Iterator;
10781 ----------------------
10782 -- Is_Selector_Name --
10783 ----------------------
10785 function Is_Selector_Name (N : Node_Id) return Boolean is
10786 begin
10787 if not Is_List_Member (N) then
10788 declare
10789 P : constant Node_Id := Parent (N);
10790 K : constant Node_Kind := Nkind (P);
10791 begin
10792 return
10793 (K = N_Expanded_Name or else
10794 K = N_Generic_Association or else
10795 K = N_Parameter_Association or else
10796 K = N_Selected_Component)
10797 and then Selector_Name (P) = N;
10798 end;
10800 else
10801 declare
10802 L : constant List_Id := List_Containing (N);
10803 P : constant Node_Id := Parent (L);
10804 begin
10805 return (Nkind (P) = N_Discriminant_Association
10806 and then Selector_Names (P) = L)
10807 or else
10808 (Nkind (P) = N_Component_Association
10809 and then Choices (P) = L);
10810 end;
10811 end if;
10812 end Is_Selector_Name;
10814 ----------------------------------
10815 -- Is_SPARK_Initialization_Expr --
10816 ----------------------------------
10818 function Is_SPARK_Initialization_Expr (N : Node_Id) return Boolean is
10819 Is_Ok : Boolean;
10820 Expr : Node_Id;
10821 Comp_Assn : Node_Id;
10822 Orig_N : constant Node_Id := Original_Node (N);
10824 begin
10825 Is_Ok := True;
10827 if not Comes_From_Source (Orig_N) then
10828 goto Done;
10829 end if;
10831 pragma Assert (Nkind (Orig_N) in N_Subexpr);
10833 case Nkind (Orig_N) is
10834 when N_Character_Literal |
10835 N_Integer_Literal |
10836 N_Real_Literal |
10837 N_String_Literal =>
10838 null;
10840 when N_Identifier |
10841 N_Expanded_Name =>
10842 if Is_Entity_Name (Orig_N)
10843 and then Present (Entity (Orig_N)) -- needed in some cases
10844 then
10845 case Ekind (Entity (Orig_N)) is
10846 when E_Constant |
10847 E_Enumeration_Literal |
10848 E_Named_Integer |
10849 E_Named_Real =>
10850 null;
10851 when others =>
10852 if Is_Type (Entity (Orig_N)) then
10853 null;
10854 else
10855 Is_Ok := False;
10856 end if;
10857 end case;
10858 end if;
10860 when N_Qualified_Expression |
10861 N_Type_Conversion =>
10862 Is_Ok := Is_SPARK_Initialization_Expr (Expression (Orig_N));
10864 when N_Unary_Op =>
10865 Is_Ok := Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
10867 when N_Binary_Op |
10868 N_Short_Circuit |
10869 N_Membership_Test =>
10870 Is_Ok := Is_SPARK_Initialization_Expr (Left_Opnd (Orig_N))
10871 and then Is_SPARK_Initialization_Expr (Right_Opnd (Orig_N));
10873 when N_Aggregate |
10874 N_Extension_Aggregate =>
10875 if Nkind (Orig_N) = N_Extension_Aggregate then
10876 Is_Ok := Is_SPARK_Initialization_Expr (Ancestor_Part (Orig_N));
10877 end if;
10879 Expr := First (Expressions (Orig_N));
10880 while Present (Expr) loop
10881 if not Is_SPARK_Initialization_Expr (Expr) then
10882 Is_Ok := False;
10883 goto Done;
10884 end if;
10886 Next (Expr);
10887 end loop;
10889 Comp_Assn := First (Component_Associations (Orig_N));
10890 while Present (Comp_Assn) loop
10891 Expr := Expression (Comp_Assn);
10892 if Present (Expr) -- needed for box association
10893 and then not Is_SPARK_Initialization_Expr (Expr)
10894 then
10895 Is_Ok := False;
10896 goto Done;
10897 end if;
10899 Next (Comp_Assn);
10900 end loop;
10902 when N_Attribute_Reference =>
10903 if Nkind (Prefix (Orig_N)) in N_Subexpr then
10904 Is_Ok := Is_SPARK_Initialization_Expr (Prefix (Orig_N));
10905 end if;
10907 Expr := First (Expressions (Orig_N));
10908 while Present (Expr) loop
10909 if not Is_SPARK_Initialization_Expr (Expr) then
10910 Is_Ok := False;
10911 goto Done;
10912 end if;
10914 Next (Expr);
10915 end loop;
10917 -- Selected components might be expanded named not yet resolved, so
10918 -- default on the safe side. (Eg on sparklex.ads)
10920 when N_Selected_Component =>
10921 null;
10923 when others =>
10924 Is_Ok := False;
10925 end case;
10927 <<Done>>
10928 return Is_Ok;
10929 end Is_SPARK_Initialization_Expr;
10931 -------------------------------
10932 -- Is_SPARK_Object_Reference --
10933 -------------------------------
10935 function Is_SPARK_Object_Reference (N : Node_Id) return Boolean is
10936 begin
10937 if Is_Entity_Name (N) then
10938 return Present (Entity (N))
10939 and then
10940 (Ekind_In (Entity (N), E_Constant, E_Variable)
10941 or else Ekind (Entity (N)) in Formal_Kind);
10943 else
10944 case Nkind (N) is
10945 when N_Selected_Component =>
10946 return Is_SPARK_Object_Reference (Prefix (N));
10948 when others =>
10949 return False;
10950 end case;
10951 end if;
10952 end Is_SPARK_Object_Reference;
10954 ------------------------------
10955 -- Is_SPARK_Volatile_Object --
10956 ------------------------------
10958 function Is_SPARK_Volatile_Object (N : Node_Id) return Boolean is
10959 begin
10960 if Nkind (N) = N_Defining_Identifier then
10961 return Is_Volatile (N) or else Is_Volatile (Etype (N));
10963 elsif Is_Entity_Name (N) then
10964 return
10965 Is_SPARK_Volatile_Object (Entity (N))
10966 or else Is_Volatile (Etype (N));
10968 elsif Nkind (N) = N_Expanded_Name then
10969 return Is_SPARK_Volatile_Object (Entity (N));
10971 elsif Nkind (N) = N_Indexed_Component then
10972 return Is_SPARK_Volatile_Object (Prefix (N));
10974 elsif Nkind (N) = N_Selected_Component then
10975 return
10976 Is_SPARK_Volatile_Object (Prefix (N))
10977 or else
10978 Is_SPARK_Volatile_Object (Selector_Name (N));
10980 else
10981 return False;
10982 end if;
10983 end Is_SPARK_Volatile_Object;
10985 ------------------
10986 -- Is_Statement --
10987 ------------------
10989 function Is_Statement (N : Node_Id) return Boolean is
10990 begin
10991 return
10992 Nkind (N) in N_Statement_Other_Than_Procedure_Call
10993 or else Nkind (N) = N_Procedure_Call_Statement;
10994 end Is_Statement;
10996 --------------------------------------------------
10997 -- Is_Subprogram_Stub_Without_Prior_Declaration --
10998 --------------------------------------------------
11000 function Is_Subprogram_Stub_Without_Prior_Declaration
11001 (N : Node_Id) return Boolean
11003 begin
11004 -- A subprogram stub without prior declaration serves as declaration for
11005 -- the actual subprogram body. As such, it has an attached defining
11006 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
11008 return Nkind (N) = N_Subprogram_Body_Stub
11009 and then Ekind (Defining_Entity (N)) /= E_Subprogram_Body;
11010 end Is_Subprogram_Stub_Without_Prior_Declaration;
11012 ---------------------------------
11013 -- Is_Synchronized_Tagged_Type --
11014 ---------------------------------
11016 function Is_Synchronized_Tagged_Type (E : Entity_Id) return Boolean is
11017 Kind : constant Entity_Kind := Ekind (Base_Type (E));
11019 begin
11020 -- A task or protected type derived from an interface is a tagged type.
11021 -- Such a tagged type is called a synchronized tagged type, as are
11022 -- synchronized interfaces and private extensions whose declaration
11023 -- includes the reserved word synchronized.
11025 return (Is_Tagged_Type (E)
11026 and then (Kind = E_Task_Type
11027 or else Kind = E_Protected_Type))
11028 or else
11029 (Is_Interface (E)
11030 and then Is_Synchronized_Interface (E))
11031 or else
11032 (Ekind (E) = E_Record_Type_With_Private
11033 and then Nkind (Parent (E)) = N_Private_Extension_Declaration
11034 and then (Synchronized_Present (Parent (E))
11035 or else Is_Synchronized_Interface (Etype (E))));
11036 end Is_Synchronized_Tagged_Type;
11038 -----------------
11039 -- Is_Transfer --
11040 -----------------
11042 function Is_Transfer (N : Node_Id) return Boolean is
11043 Kind : constant Node_Kind := Nkind (N);
11045 begin
11046 if Kind = N_Simple_Return_Statement
11047 or else
11048 Kind = N_Extended_Return_Statement
11049 or else
11050 Kind = N_Goto_Statement
11051 or else
11052 Kind = N_Raise_Statement
11053 or else
11054 Kind = N_Requeue_Statement
11055 then
11056 return True;
11058 elsif (Kind = N_Exit_Statement or else Kind in N_Raise_xxx_Error)
11059 and then No (Condition (N))
11060 then
11061 return True;
11063 elsif Kind = N_Procedure_Call_Statement
11064 and then Is_Entity_Name (Name (N))
11065 and then Present (Entity (Name (N)))
11066 and then No_Return (Entity (Name (N)))
11067 then
11068 return True;
11070 elsif Nkind (Original_Node (N)) = N_Raise_Statement then
11071 return True;
11073 else
11074 return False;
11075 end if;
11076 end Is_Transfer;
11078 -------------
11079 -- Is_True --
11080 -------------
11082 function Is_True (U : Uint) return Boolean is
11083 begin
11084 return (U /= 0);
11085 end Is_True;
11087 --------------------------------------
11088 -- Is_Unchecked_Conversion_Instance --
11089 --------------------------------------
11091 function Is_Unchecked_Conversion_Instance (Id : Entity_Id) return Boolean is
11092 Gen_Par : Entity_Id;
11094 begin
11095 -- Look for a function whose generic parent is the predefined intrinsic
11096 -- function Unchecked_Conversion.
11098 if Ekind (Id) = E_Function then
11099 Gen_Par := Generic_Parent (Parent (Id));
11101 return
11102 Present (Gen_Par)
11103 and then Chars (Gen_Par) = Name_Unchecked_Conversion
11104 and then Is_Intrinsic_Subprogram (Gen_Par)
11105 and then Is_Predefined_File_Name
11106 (Unit_File_Name (Get_Source_Unit (Gen_Par)));
11107 end if;
11109 return False;
11110 end Is_Unchecked_Conversion_Instance;
11112 -------------------------------
11113 -- Is_Universal_Numeric_Type --
11114 -------------------------------
11116 function Is_Universal_Numeric_Type (T : Entity_Id) return Boolean is
11117 begin
11118 return T = Universal_Integer or else T = Universal_Real;
11119 end Is_Universal_Numeric_Type;
11121 -------------------
11122 -- Is_Value_Type --
11123 -------------------
11125 function Is_Value_Type (T : Entity_Id) return Boolean is
11126 begin
11127 return VM_Target = CLI_Target
11128 and then Nkind (T) in N_Has_Chars
11129 and then Chars (T) /= No_Name
11130 and then Get_Name_String (Chars (T)) = "valuetype";
11131 end Is_Value_Type;
11133 ----------------------------
11134 -- Is_Variable_Size_Array --
11135 ----------------------------
11137 function Is_Variable_Size_Array (E : Entity_Id) return Boolean is
11138 Idx : Node_Id;
11140 begin
11141 pragma Assert (Is_Array_Type (E));
11143 -- Check if some index is initialized with a non-constant value
11145 Idx := First_Index (E);
11146 while Present (Idx) loop
11147 if Nkind (Idx) = N_Range then
11148 if not Is_Constant_Bound (Low_Bound (Idx))
11149 or else not Is_Constant_Bound (High_Bound (Idx))
11150 then
11151 return True;
11152 end if;
11153 end if;
11155 Idx := Next_Index (Idx);
11156 end loop;
11158 return False;
11159 end Is_Variable_Size_Array;
11161 -----------------------------
11162 -- Is_Variable_Size_Record --
11163 -----------------------------
11165 function Is_Variable_Size_Record (E : Entity_Id) return Boolean is
11166 Comp : Entity_Id;
11167 Comp_Typ : Entity_Id;
11169 begin
11170 pragma Assert (Is_Record_Type (E));
11172 Comp := First_Entity (E);
11173 while Present (Comp) loop
11174 Comp_Typ := Etype (Comp);
11176 -- Recursive call if the record type has discriminants
11178 if Is_Record_Type (Comp_Typ)
11179 and then Has_Discriminants (Comp_Typ)
11180 and then Is_Variable_Size_Record (Comp_Typ)
11181 then
11182 return True;
11184 elsif Is_Array_Type (Comp_Typ)
11185 and then Is_Variable_Size_Array (Comp_Typ)
11186 then
11187 return True;
11188 end if;
11190 Next_Entity (Comp);
11191 end loop;
11193 return False;
11194 end Is_Variable_Size_Record;
11196 ---------------------
11197 -- Is_VMS_Operator --
11198 ---------------------
11200 function Is_VMS_Operator (Op : Entity_Id) return Boolean is
11201 begin
11202 -- The VMS operators are declared in a child of System that is loaded
11203 -- through pragma Extend_System. In some rare cases a program is run
11204 -- with this extension but without indicating that the target is VMS.
11206 return Ekind (Op) = E_Function
11207 and then Is_Intrinsic_Subprogram (Op)
11208 and then
11209 ((Present_System_Aux and then Scope (Op) = System_Aux_Id)
11210 or else
11211 (True_VMS_Target
11212 and then Scope (Scope (Op)) = RTU_Entity (System)));
11213 end Is_VMS_Operator;
11215 -----------------
11216 -- Is_Variable --
11217 -----------------
11219 function Is_Variable
11220 (N : Node_Id;
11221 Use_Original_Node : Boolean := True) return Boolean
11223 Orig_Node : Node_Id;
11225 function In_Protected_Function (E : Entity_Id) return Boolean;
11226 -- Within a protected function, the private components of the enclosing
11227 -- protected type are constants. A function nested within a (protected)
11228 -- procedure is not itself protected. Within the body of a protected
11229 -- function the current instance of the protected type is a constant.
11231 function Is_Variable_Prefix (P : Node_Id) return Boolean;
11232 -- Prefixes can involve implicit dereferences, in which case we must
11233 -- test for the case of a reference of a constant access type, which can
11234 -- can never be a variable.
11236 ---------------------------
11237 -- In_Protected_Function --
11238 ---------------------------
11240 function In_Protected_Function (E : Entity_Id) return Boolean is
11241 Prot : Entity_Id;
11242 S : Entity_Id;
11244 begin
11245 -- E is the current instance of a type
11247 if Is_Type (E) then
11248 Prot := E;
11250 -- E is an object
11252 else
11253 Prot := Scope (E);
11254 end if;
11256 if not Is_Protected_Type (Prot) then
11257 return False;
11259 else
11260 S := Current_Scope;
11261 while Present (S) and then S /= Prot loop
11262 if Ekind (S) = E_Function and then Scope (S) = Prot then
11263 return True;
11264 end if;
11266 S := Scope (S);
11267 end loop;
11269 return False;
11270 end if;
11271 end In_Protected_Function;
11273 ------------------------
11274 -- Is_Variable_Prefix --
11275 ------------------------
11277 function Is_Variable_Prefix (P : Node_Id) return Boolean is
11278 begin
11279 if Is_Access_Type (Etype (P)) then
11280 return not Is_Access_Constant (Root_Type (Etype (P)));
11282 -- For the case of an indexed component whose prefix has a packed
11283 -- array type, the prefix has been rewritten into a type conversion.
11284 -- Determine variable-ness from the converted expression.
11286 elsif Nkind (P) = N_Type_Conversion
11287 and then not Comes_From_Source (P)
11288 and then Is_Array_Type (Etype (P))
11289 and then Is_Packed (Etype (P))
11290 then
11291 return Is_Variable (Expression (P));
11293 else
11294 return Is_Variable (P);
11295 end if;
11296 end Is_Variable_Prefix;
11298 -- Start of processing for Is_Variable
11300 begin
11301 -- Check if we perform the test on the original node since this may be a
11302 -- test of syntactic categories which must not be disturbed by whatever
11303 -- rewriting might have occurred. For example, an aggregate, which is
11304 -- certainly NOT a variable, could be turned into a variable by
11305 -- expansion.
11307 if Use_Original_Node then
11308 Orig_Node := Original_Node (N);
11309 else
11310 Orig_Node := N;
11311 end if;
11313 -- Definitely OK if Assignment_OK is set. Since this is something that
11314 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
11316 if Nkind (N) in N_Subexpr and then Assignment_OK (N) then
11317 return True;
11319 -- Normally we go to the original node, but there is one exception where
11320 -- we use the rewritten node, namely when it is an explicit dereference.
11321 -- The generated code may rewrite a prefix which is an access type with
11322 -- an explicit dereference. The dereference is a variable, even though
11323 -- the original node may not be (since it could be a constant of the
11324 -- access type).
11326 -- In Ada 2005 we have a further case to consider: the prefix may be a
11327 -- function call given in prefix notation. The original node appears to
11328 -- be a selected component, but we need to examine the call.
11330 elsif Nkind (N) = N_Explicit_Dereference
11331 and then Nkind (Orig_Node) /= N_Explicit_Dereference
11332 and then Present (Etype (Orig_Node))
11333 and then Is_Access_Type (Etype (Orig_Node))
11334 then
11335 -- Note that if the prefix is an explicit dereference that does not
11336 -- come from source, we must check for a rewritten function call in
11337 -- prefixed notation before other forms of rewriting, to prevent a
11338 -- compiler crash.
11340 return
11341 (Nkind (Orig_Node) = N_Function_Call
11342 and then not Is_Access_Constant (Etype (Prefix (N))))
11343 or else
11344 Is_Variable_Prefix (Original_Node (Prefix (N)));
11346 -- in Ada 2012, the dereference may have been added for a type with
11347 -- a declared implicit dereference aspect.
11349 elsif Nkind (N) = N_Explicit_Dereference
11350 and then Present (Etype (Orig_Node))
11351 and then Ada_Version >= Ada_2012
11352 and then Has_Implicit_Dereference (Etype (Orig_Node))
11353 then
11354 return True;
11356 -- A function call is never a variable
11358 elsif Nkind (N) = N_Function_Call then
11359 return False;
11361 -- All remaining checks use the original node
11363 elsif Is_Entity_Name (Orig_Node)
11364 and then Present (Entity (Orig_Node))
11365 then
11366 declare
11367 E : constant Entity_Id := Entity (Orig_Node);
11368 K : constant Entity_Kind := Ekind (E);
11370 begin
11371 return (K = E_Variable
11372 and then Nkind (Parent (E)) /= N_Exception_Handler)
11373 or else (K = E_Component
11374 and then not In_Protected_Function (E))
11375 or else K = E_Out_Parameter
11376 or else K = E_In_Out_Parameter
11377 or else K = E_Generic_In_Out_Parameter
11379 -- Current instance of type. If this is a protected type, check
11380 -- we are not within the body of one of its protected functions.
11382 or else (Is_Type (E)
11383 and then In_Open_Scopes (E)
11384 and then not In_Protected_Function (E))
11386 or else (Is_Incomplete_Or_Private_Type (E)
11387 and then In_Open_Scopes (Full_View (E)));
11388 end;
11390 else
11391 case Nkind (Orig_Node) is
11392 when N_Indexed_Component | N_Slice =>
11393 return Is_Variable_Prefix (Prefix (Orig_Node));
11395 when N_Selected_Component =>
11396 return Is_Variable_Prefix (Prefix (Orig_Node))
11397 and then Is_Variable (Selector_Name (Orig_Node));
11399 -- For an explicit dereference, the type of the prefix cannot
11400 -- be an access to constant or an access to subprogram.
11402 when N_Explicit_Dereference =>
11403 declare
11404 Typ : constant Entity_Id := Etype (Prefix (Orig_Node));
11405 begin
11406 return Is_Access_Type (Typ)
11407 and then not Is_Access_Constant (Root_Type (Typ))
11408 and then Ekind (Typ) /= E_Access_Subprogram_Type;
11409 end;
11411 -- The type conversion is the case where we do not deal with the
11412 -- context dependent special case of an actual parameter. Thus
11413 -- the type conversion is only considered a variable for the
11414 -- purposes of this routine if the target type is tagged. However,
11415 -- a type conversion is considered to be a variable if it does not
11416 -- come from source (this deals for example with the conversions
11417 -- of expressions to their actual subtypes).
11419 when N_Type_Conversion =>
11420 return Is_Variable (Expression (Orig_Node))
11421 and then
11422 (not Comes_From_Source (Orig_Node)
11423 or else
11424 (Is_Tagged_Type (Etype (Subtype_Mark (Orig_Node)))
11425 and then
11426 Is_Tagged_Type (Etype (Expression (Orig_Node)))));
11428 -- GNAT allows an unchecked type conversion as a variable. This
11429 -- only affects the generation of internal expanded code, since
11430 -- calls to instantiations of Unchecked_Conversion are never
11431 -- considered variables (since they are function calls).
11433 when N_Unchecked_Type_Conversion =>
11434 return Is_Variable (Expression (Orig_Node));
11436 when others =>
11437 return False;
11438 end case;
11439 end if;
11440 end Is_Variable;
11442 ---------------------------
11443 -- Is_Visibly_Controlled --
11444 ---------------------------
11446 function Is_Visibly_Controlled (T : Entity_Id) return Boolean is
11447 Root : constant Entity_Id := Root_Type (T);
11448 begin
11449 return Chars (Scope (Root)) = Name_Finalization
11450 and then Chars (Scope (Scope (Root))) = Name_Ada
11451 and then Scope (Scope (Scope (Root))) = Standard_Standard;
11452 end Is_Visibly_Controlled;
11454 ------------------------
11455 -- Is_Volatile_Object --
11456 ------------------------
11458 function Is_Volatile_Object (N : Node_Id) return Boolean is
11460 function Is_Volatile_Prefix (N : Node_Id) return Boolean;
11461 -- If prefix is an implicit dereference, examine designated type
11463 function Object_Has_Volatile_Components (N : Node_Id) return Boolean;
11464 -- Determines if given object has volatile components
11466 ------------------------
11467 -- Is_Volatile_Prefix --
11468 ------------------------
11470 function Is_Volatile_Prefix (N : Node_Id) return Boolean is
11471 Typ : constant Entity_Id := Etype (N);
11473 begin
11474 if Is_Access_Type (Typ) then
11475 declare
11476 Dtyp : constant Entity_Id := Designated_Type (Typ);
11478 begin
11479 return Is_Volatile (Dtyp)
11480 or else Has_Volatile_Components (Dtyp);
11481 end;
11483 else
11484 return Object_Has_Volatile_Components (N);
11485 end if;
11486 end Is_Volatile_Prefix;
11488 ------------------------------------
11489 -- Object_Has_Volatile_Components --
11490 ------------------------------------
11492 function Object_Has_Volatile_Components (N : Node_Id) return Boolean is
11493 Typ : constant Entity_Id := Etype (N);
11495 begin
11496 if Is_Volatile (Typ)
11497 or else Has_Volatile_Components (Typ)
11498 then
11499 return True;
11501 elsif Is_Entity_Name (N)
11502 and then (Has_Volatile_Components (Entity (N))
11503 or else Is_Volatile (Entity (N)))
11504 then
11505 return True;
11507 elsif Nkind (N) = N_Indexed_Component
11508 or else Nkind (N) = N_Selected_Component
11509 then
11510 return Is_Volatile_Prefix (Prefix (N));
11512 else
11513 return False;
11514 end if;
11515 end Object_Has_Volatile_Components;
11517 -- Start of processing for Is_Volatile_Object
11519 begin
11520 if Nkind (N) = N_Defining_Identifier then
11521 return Is_Volatile (N) or else Is_Volatile (Etype (N));
11523 elsif Nkind (N) = N_Expanded_Name then
11524 return Is_Volatile_Object (Entity (N));
11526 elsif Is_Volatile (Etype (N))
11527 or else (Is_Entity_Name (N) and then Is_Volatile (Entity (N)))
11528 then
11529 return True;
11531 elsif Nkind_In (N, N_Indexed_Component, N_Selected_Component)
11532 and then Is_Volatile_Prefix (Prefix (N))
11533 then
11534 return True;
11536 elsif Nkind (N) = N_Selected_Component
11537 and then Is_Volatile (Entity (Selector_Name (N)))
11538 then
11539 return True;
11541 else
11542 return False;
11543 end if;
11544 end Is_Volatile_Object;
11546 ---------------------------
11547 -- Itype_Has_Declaration --
11548 ---------------------------
11550 function Itype_Has_Declaration (Id : Entity_Id) return Boolean is
11551 begin
11552 pragma Assert (Is_Itype (Id));
11553 return Present (Parent (Id))
11554 and then Nkind_In (Parent (Id), N_Full_Type_Declaration,
11555 N_Subtype_Declaration)
11556 and then Defining_Entity (Parent (Id)) = Id;
11557 end Itype_Has_Declaration;
11559 -------------------------
11560 -- Kill_Current_Values --
11561 -------------------------
11563 procedure Kill_Current_Values
11564 (Ent : Entity_Id;
11565 Last_Assignment_Only : Boolean := False)
11567 begin
11568 -- ??? do we have to worry about clearing cached checks?
11570 if Is_Assignable (Ent) then
11571 Set_Last_Assignment (Ent, Empty);
11572 end if;
11574 if Is_Object (Ent) then
11575 if not Last_Assignment_Only then
11576 Kill_Checks (Ent);
11577 Set_Current_Value (Ent, Empty);
11579 if not Can_Never_Be_Null (Ent) then
11580 Set_Is_Known_Non_Null (Ent, False);
11581 end if;
11583 Set_Is_Known_Null (Ent, False);
11585 -- Reset Is_Known_Valid unless type is always valid, or if we have
11586 -- a loop parameter (loop parameters are always valid, since their
11587 -- bounds are defined by the bounds given in the loop header).
11589 if not Is_Known_Valid (Etype (Ent))
11590 and then Ekind (Ent) /= E_Loop_Parameter
11591 then
11592 Set_Is_Known_Valid (Ent, False);
11593 end if;
11594 end if;
11595 end if;
11596 end Kill_Current_Values;
11598 procedure Kill_Current_Values (Last_Assignment_Only : Boolean := False) is
11599 S : Entity_Id;
11601 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id);
11602 -- Clear current value for entity E and all entities chained to E
11604 ------------------------------------------
11605 -- Kill_Current_Values_For_Entity_Chain --
11606 ------------------------------------------
11608 procedure Kill_Current_Values_For_Entity_Chain (E : Entity_Id) is
11609 Ent : Entity_Id;
11610 begin
11611 Ent := E;
11612 while Present (Ent) loop
11613 Kill_Current_Values (Ent, Last_Assignment_Only);
11614 Next_Entity (Ent);
11615 end loop;
11616 end Kill_Current_Values_For_Entity_Chain;
11618 -- Start of processing for Kill_Current_Values
11620 begin
11621 -- Kill all saved checks, a special case of killing saved values
11623 if not Last_Assignment_Only then
11624 Kill_All_Checks;
11625 end if;
11627 -- Loop through relevant scopes, which includes the current scope and
11628 -- any parent scopes if the current scope is a block or a package.
11630 S := Current_Scope;
11631 Scope_Loop : loop
11633 -- Clear current values of all entities in current scope
11635 Kill_Current_Values_For_Entity_Chain (First_Entity (S));
11637 -- If scope is a package, also clear current values of all private
11638 -- entities in the scope.
11640 if Is_Package_Or_Generic_Package (S)
11641 or else Is_Concurrent_Type (S)
11642 then
11643 Kill_Current_Values_For_Entity_Chain (First_Private_Entity (S));
11644 end if;
11646 -- If this is a not a subprogram, deal with parents
11648 if not Is_Subprogram (S) then
11649 S := Scope (S);
11650 exit Scope_Loop when S = Standard_Standard;
11651 else
11652 exit Scope_Loop;
11653 end if;
11654 end loop Scope_Loop;
11655 end Kill_Current_Values;
11657 --------------------------
11658 -- Kill_Size_Check_Code --
11659 --------------------------
11661 procedure Kill_Size_Check_Code (E : Entity_Id) is
11662 begin
11663 if (Ekind (E) = E_Constant or else Ekind (E) = E_Variable)
11664 and then Present (Size_Check_Code (E))
11665 then
11666 Remove (Size_Check_Code (E));
11667 Set_Size_Check_Code (E, Empty);
11668 end if;
11669 end Kill_Size_Check_Code;
11671 --------------------------
11672 -- Known_To_Be_Assigned --
11673 --------------------------
11675 function Known_To_Be_Assigned (N : Node_Id) return Boolean is
11676 P : constant Node_Id := Parent (N);
11678 begin
11679 case Nkind (P) is
11681 -- Test left side of assignment
11683 when N_Assignment_Statement =>
11684 return N = Name (P);
11686 -- Function call arguments are never lvalues
11688 when N_Function_Call =>
11689 return False;
11691 -- Positional parameter for procedure or accept call
11693 when N_Procedure_Call_Statement |
11694 N_Accept_Statement
11696 declare
11697 Proc : Entity_Id;
11698 Form : Entity_Id;
11699 Act : Node_Id;
11701 begin
11702 Proc := Get_Subprogram_Entity (P);
11704 if No (Proc) then
11705 return False;
11706 end if;
11708 -- If we are not a list member, something is strange, so
11709 -- be conservative and return False.
11711 if not Is_List_Member (N) then
11712 return False;
11713 end if;
11715 -- We are going to find the right formal by stepping forward
11716 -- through the formals, as we step backwards in the actuals.
11718 Form := First_Formal (Proc);
11719 Act := N;
11720 loop
11721 -- If no formal, something is weird, so be conservative
11722 -- and return False.
11724 if No (Form) then
11725 return False;
11726 end if;
11728 Prev (Act);
11729 exit when No (Act);
11730 Next_Formal (Form);
11731 end loop;
11733 return Ekind (Form) /= E_In_Parameter;
11734 end;
11736 -- Named parameter for procedure or accept call
11738 when N_Parameter_Association =>
11739 declare
11740 Proc : Entity_Id;
11741 Form : Entity_Id;
11743 begin
11744 Proc := Get_Subprogram_Entity (Parent (P));
11746 if No (Proc) then
11747 return False;
11748 end if;
11750 -- Loop through formals to find the one that matches
11752 Form := First_Formal (Proc);
11753 loop
11754 -- If no matching formal, that's peculiar, some kind of
11755 -- previous error, so return False to be conservative.
11756 -- Actually this also happens in legal code in the case
11757 -- where P is a parameter association for an Extra_Formal???
11759 if No (Form) then
11760 return False;
11761 end if;
11763 -- Else test for match
11765 if Chars (Form) = Chars (Selector_Name (P)) then
11766 return Ekind (Form) /= E_In_Parameter;
11767 end if;
11769 Next_Formal (Form);
11770 end loop;
11771 end;
11773 -- Test for appearing in a conversion that itself appears
11774 -- in an lvalue context, since this should be an lvalue.
11776 when N_Type_Conversion =>
11777 return Known_To_Be_Assigned (P);
11779 -- All other references are definitely not known to be modifications
11781 when others =>
11782 return False;
11784 end case;
11785 end Known_To_Be_Assigned;
11787 ---------------------------
11788 -- Last_Source_Statement --
11789 ---------------------------
11791 function Last_Source_Statement (HSS : Node_Id) return Node_Id is
11792 N : Node_Id;
11794 begin
11795 N := Last (Statements (HSS));
11796 while Present (N) loop
11797 exit when Comes_From_Source (N);
11798 Prev (N);
11799 end loop;
11801 return N;
11802 end Last_Source_Statement;
11804 ----------------------------------
11805 -- Matching_Static_Array_Bounds --
11806 ----------------------------------
11808 function Matching_Static_Array_Bounds
11809 (L_Typ : Node_Id;
11810 R_Typ : Node_Id) return Boolean
11812 L_Ndims : constant Nat := Number_Dimensions (L_Typ);
11813 R_Ndims : constant Nat := Number_Dimensions (R_Typ);
11815 L_Index : Node_Id;
11816 R_Index : Node_Id;
11817 L_Low : Node_Id;
11818 L_High : Node_Id;
11819 L_Len : Uint;
11820 R_Low : Node_Id;
11821 R_High : Node_Id;
11822 R_Len : Uint;
11824 begin
11825 if L_Ndims /= R_Ndims then
11826 return False;
11827 end if;
11829 -- Unconstrained types do not have static bounds
11831 if not Is_Constrained (L_Typ) or else not Is_Constrained (R_Typ) then
11832 return False;
11833 end if;
11835 -- First treat specially the first dimension, as the lower bound and
11836 -- length of string literals are not stored like those of arrays.
11838 if Ekind (L_Typ) = E_String_Literal_Subtype then
11839 L_Low := String_Literal_Low_Bound (L_Typ);
11840 L_Len := String_Literal_Length (L_Typ);
11841 else
11842 L_Index := First_Index (L_Typ);
11843 Get_Index_Bounds (L_Index, L_Low, L_High);
11845 if Is_OK_Static_Expression (L_Low)
11846 and then Is_OK_Static_Expression (L_High)
11847 then
11848 if Expr_Value (L_High) < Expr_Value (L_Low) then
11849 L_Len := Uint_0;
11850 else
11851 L_Len := (Expr_Value (L_High) - Expr_Value (L_Low)) + 1;
11852 end if;
11853 else
11854 return False;
11855 end if;
11856 end if;
11858 if Ekind (R_Typ) = E_String_Literal_Subtype then
11859 R_Low := String_Literal_Low_Bound (R_Typ);
11860 R_Len := String_Literal_Length (R_Typ);
11861 else
11862 R_Index := First_Index (R_Typ);
11863 Get_Index_Bounds (R_Index, R_Low, R_High);
11865 if Is_OK_Static_Expression (R_Low)
11866 and then Is_OK_Static_Expression (R_High)
11867 then
11868 if Expr_Value (R_High) < Expr_Value (R_Low) then
11869 R_Len := Uint_0;
11870 else
11871 R_Len := (Expr_Value (R_High) - Expr_Value (R_Low)) + 1;
11872 end if;
11873 else
11874 return False;
11875 end if;
11876 end if;
11878 if Is_OK_Static_Expression (L_Low)
11879 and then Is_OK_Static_Expression (R_Low)
11880 and then Expr_Value (L_Low) = Expr_Value (R_Low)
11881 and then L_Len = R_Len
11882 then
11883 null;
11884 else
11885 return False;
11886 end if;
11888 -- Then treat all other dimensions
11890 for Indx in 2 .. L_Ndims loop
11891 Next (L_Index);
11892 Next (R_Index);
11894 Get_Index_Bounds (L_Index, L_Low, L_High);
11895 Get_Index_Bounds (R_Index, R_Low, R_High);
11897 if Is_OK_Static_Expression (L_Low)
11898 and then Is_OK_Static_Expression (L_High)
11899 and then Is_OK_Static_Expression (R_Low)
11900 and then Is_OK_Static_Expression (R_High)
11901 and then Expr_Value (L_Low) = Expr_Value (R_Low)
11902 and then Expr_Value (L_High) = Expr_Value (R_High)
11903 then
11904 null;
11905 else
11906 return False;
11907 end if;
11908 end loop;
11910 -- If we fall through the loop, all indexes matched
11912 return True;
11913 end Matching_Static_Array_Bounds;
11915 -------------------
11916 -- May_Be_Lvalue --
11917 -------------------
11919 function May_Be_Lvalue (N : Node_Id) return Boolean is
11920 P : constant Node_Id := Parent (N);
11922 begin
11923 case Nkind (P) is
11925 -- Test left side of assignment
11927 when N_Assignment_Statement =>
11928 return N = Name (P);
11930 -- Test prefix of component or attribute. Note that the prefix of an
11931 -- explicit or implicit dereference cannot be an l-value.
11933 when N_Attribute_Reference =>
11934 return N = Prefix (P)
11935 and then Name_Implies_Lvalue_Prefix (Attribute_Name (P));
11937 -- For an expanded name, the name is an lvalue if the expanded name
11938 -- is an lvalue, but the prefix is never an lvalue, since it is just
11939 -- the scope where the name is found.
11941 when N_Expanded_Name =>
11942 if N = Prefix (P) then
11943 return May_Be_Lvalue (P);
11944 else
11945 return False;
11946 end if;
11948 -- For a selected component A.B, A is certainly an lvalue if A.B is.
11949 -- B is a little interesting, if we have A.B := 3, there is some
11950 -- discussion as to whether B is an lvalue or not, we choose to say
11951 -- it is. Note however that A is not an lvalue if it is of an access
11952 -- type since this is an implicit dereference.
11954 when N_Selected_Component =>
11955 if N = Prefix (P)
11956 and then Present (Etype (N))
11957 and then Is_Access_Type (Etype (N))
11958 then
11959 return False;
11960 else
11961 return May_Be_Lvalue (P);
11962 end if;
11964 -- For an indexed component or slice, the index or slice bounds is
11965 -- never an lvalue. The prefix is an lvalue if the indexed component
11966 -- or slice is an lvalue, except if it is an access type, where we
11967 -- have an implicit dereference.
11969 when N_Indexed_Component | N_Slice =>
11970 if N /= Prefix (P)
11971 or else (Present (Etype (N)) and then Is_Access_Type (Etype (N)))
11972 then
11973 return False;
11974 else
11975 return May_Be_Lvalue (P);
11976 end if;
11978 -- Prefix of a reference is an lvalue if the reference is an lvalue
11980 when N_Reference =>
11981 return May_Be_Lvalue (P);
11983 -- Prefix of explicit dereference is never an lvalue
11985 when N_Explicit_Dereference =>
11986 return False;
11988 -- Positional parameter for subprogram, entry, or accept call.
11989 -- In older versions of Ada function call arguments are never
11990 -- lvalues. In Ada 2012 functions can have in-out parameters.
11992 when N_Subprogram_Call |
11993 N_Entry_Call_Statement |
11994 N_Accept_Statement
11996 if Nkind (P) = N_Function_Call and then Ada_Version < Ada_2012 then
11997 return False;
11998 end if;
12000 -- The following mechanism is clumsy and fragile. A single flag
12001 -- set in Resolve_Actuals would be preferable ???
12003 declare
12004 Proc : Entity_Id;
12005 Form : Entity_Id;
12006 Act : Node_Id;
12008 begin
12009 Proc := Get_Subprogram_Entity (P);
12011 if No (Proc) then
12012 return True;
12013 end if;
12015 -- If we are not a list member, something is strange, so be
12016 -- conservative and return True.
12018 if not Is_List_Member (N) then
12019 return True;
12020 end if;
12022 -- We are going to find the right formal by stepping forward
12023 -- through the formals, as we step backwards in the actuals.
12025 Form := First_Formal (Proc);
12026 Act := N;
12027 loop
12028 -- If no formal, something is weird, so be conservative and
12029 -- return True.
12031 if No (Form) then
12032 return True;
12033 end if;
12035 Prev (Act);
12036 exit when No (Act);
12037 Next_Formal (Form);
12038 end loop;
12040 return Ekind (Form) /= E_In_Parameter;
12041 end;
12043 -- Named parameter for procedure or accept call
12045 when N_Parameter_Association =>
12046 declare
12047 Proc : Entity_Id;
12048 Form : Entity_Id;
12050 begin
12051 Proc := Get_Subprogram_Entity (Parent (P));
12053 if No (Proc) then
12054 return True;
12055 end if;
12057 -- Loop through formals to find the one that matches
12059 Form := First_Formal (Proc);
12060 loop
12061 -- If no matching formal, that's peculiar, some kind of
12062 -- previous error, so return True to be conservative.
12063 -- Actually happens with legal code for an unresolved call
12064 -- where we may get the wrong homonym???
12066 if No (Form) then
12067 return True;
12068 end if;
12070 -- Else test for match
12072 if Chars (Form) = Chars (Selector_Name (P)) then
12073 return Ekind (Form) /= E_In_Parameter;
12074 end if;
12076 Next_Formal (Form);
12077 end loop;
12078 end;
12080 -- Test for appearing in a conversion that itself appears in an
12081 -- lvalue context, since this should be an lvalue.
12083 when N_Type_Conversion =>
12084 return May_Be_Lvalue (P);
12086 -- Test for appearance in object renaming declaration
12088 when N_Object_Renaming_Declaration =>
12089 return True;
12091 -- All other references are definitely not lvalues
12093 when others =>
12094 return False;
12096 end case;
12097 end May_Be_Lvalue;
12099 -----------------------
12100 -- Mark_Coextensions --
12101 -----------------------
12103 procedure Mark_Coextensions (Context_Nod : Node_Id; Root_Nod : Node_Id) is
12104 Is_Dynamic : Boolean;
12105 -- Indicates whether the context causes nested coextensions to be
12106 -- dynamic or static
12108 function Mark_Allocator (N : Node_Id) return Traverse_Result;
12109 -- Recognize an allocator node and label it as a dynamic coextension
12111 --------------------
12112 -- Mark_Allocator --
12113 --------------------
12115 function Mark_Allocator (N : Node_Id) return Traverse_Result is
12116 begin
12117 if Nkind (N) = N_Allocator then
12118 if Is_Dynamic then
12119 Set_Is_Dynamic_Coextension (N);
12121 -- If the allocator expression is potentially dynamic, it may
12122 -- be expanded out of order and require dynamic allocation
12123 -- anyway, so we treat the coextension itself as dynamic.
12124 -- Potential optimization ???
12126 elsif Nkind (Expression (N)) = N_Qualified_Expression
12127 and then Nkind (Expression (Expression (N))) = N_Op_Concat
12128 then
12129 Set_Is_Dynamic_Coextension (N);
12130 else
12131 Set_Is_Static_Coextension (N);
12132 end if;
12133 end if;
12135 return OK;
12136 end Mark_Allocator;
12138 procedure Mark_Allocators is new Traverse_Proc (Mark_Allocator);
12140 -- Start of processing Mark_Coextensions
12142 begin
12143 case Nkind (Context_Nod) is
12145 -- Comment here ???
12147 when N_Assignment_Statement =>
12148 Is_Dynamic := Nkind (Expression (Context_Nod)) = N_Allocator;
12150 -- An allocator that is a component of a returned aggregate
12151 -- must be dynamic.
12153 when N_Simple_Return_Statement =>
12154 declare
12155 Expr : constant Node_Id := Expression (Context_Nod);
12156 begin
12157 Is_Dynamic :=
12158 Nkind (Expr) = N_Allocator
12159 or else
12160 (Nkind (Expr) = N_Qualified_Expression
12161 and then Nkind (Expression (Expr)) = N_Aggregate);
12162 end;
12164 -- An alloctor within an object declaration in an extended return
12165 -- statement is of necessity dynamic.
12167 when N_Object_Declaration =>
12168 Is_Dynamic := Nkind (Root_Nod) = N_Allocator
12169 or else
12170 Nkind (Parent (Context_Nod)) = N_Extended_Return_Statement;
12172 -- This routine should not be called for constructs which may not
12173 -- contain coextensions.
12175 when others =>
12176 raise Program_Error;
12177 end case;
12179 Mark_Allocators (Root_Nod);
12180 end Mark_Coextensions;
12182 -----------------
12183 -- Must_Inline --
12184 -----------------
12186 function Must_Inline (Subp : Entity_Id) return Boolean is
12187 begin
12188 return
12189 (Optimization_Level = 0
12191 -- AAMP and VM targets have no support for inlining in the backend.
12192 -- Hence we do as much inlining as possible in the front end.
12194 or else AAMP_On_Target
12195 or else VM_Target /= No_VM)
12196 and then Has_Pragma_Inline (Subp)
12197 and then (Has_Pragma_Inline_Always (Subp) or else Front_End_Inlining);
12198 end Must_Inline;
12200 ----------------------
12201 -- Needs_One_Actual --
12202 ----------------------
12204 function Needs_One_Actual (E : Entity_Id) return Boolean is
12205 Formal : Entity_Id;
12207 begin
12208 -- Ada 2005 or later, and formals present
12210 if Ada_Version >= Ada_2005 and then Present (First_Formal (E)) then
12211 Formal := Next_Formal (First_Formal (E));
12212 while Present (Formal) loop
12213 if No (Default_Value (Formal)) then
12214 return False;
12215 end if;
12217 Next_Formal (Formal);
12218 end loop;
12220 return True;
12222 -- Ada 83/95 or no formals
12224 else
12225 return False;
12226 end if;
12227 end Needs_One_Actual;
12229 ------------------------
12230 -- New_Copy_List_Tree --
12231 ------------------------
12233 function New_Copy_List_Tree (List : List_Id) return List_Id is
12234 NL : List_Id;
12235 E : Node_Id;
12237 begin
12238 if List = No_List then
12239 return No_List;
12241 else
12242 NL := New_List;
12243 E := First (List);
12245 while Present (E) loop
12246 Append (New_Copy_Tree (E), NL);
12247 E := Next (E);
12248 end loop;
12250 return NL;
12251 end if;
12252 end New_Copy_List_Tree;
12254 -------------------
12255 -- New_Copy_Tree --
12256 -------------------
12258 use Atree.Unchecked_Access;
12259 use Atree_Private_Part;
12261 -- Our approach here requires a two pass traversal of the tree. The
12262 -- first pass visits all nodes that eventually will be copied looking
12263 -- for defining Itypes. If any defining Itypes are found, then they are
12264 -- copied, and an entry is added to the replacement map. In the second
12265 -- phase, the tree is copied, using the replacement map to replace any
12266 -- Itype references within the copied tree.
12268 -- The following hash tables are used if the Map supplied has more
12269 -- than hash threshold entries to speed up access to the map. If
12270 -- there are fewer entries, then the map is searched sequentially
12271 -- (because setting up a hash table for only a few entries takes
12272 -- more time than it saves.
12274 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num;
12275 -- Hash function used for hash operations
12277 -------------------
12278 -- New_Copy_Hash --
12279 -------------------
12281 function New_Copy_Hash (E : Entity_Id) return NCT_Header_Num is
12282 begin
12283 return Nat (E) mod (NCT_Header_Num'Last + 1);
12284 end New_Copy_Hash;
12286 ---------------
12287 -- NCT_Assoc --
12288 ---------------
12290 -- The hash table NCT_Assoc associates old entities in the table
12291 -- with their corresponding new entities (i.e. the pairs of entries
12292 -- presented in the original Map argument are Key-Element pairs).
12294 package NCT_Assoc is new Simple_HTable (
12295 Header_Num => NCT_Header_Num,
12296 Element => Entity_Id,
12297 No_Element => Empty,
12298 Key => Entity_Id,
12299 Hash => New_Copy_Hash,
12300 Equal => Types."=");
12302 ---------------------
12303 -- NCT_Itype_Assoc --
12304 ---------------------
12306 -- The hash table NCT_Itype_Assoc contains entries only for those
12307 -- old nodes which have a non-empty Associated_Node_For_Itype set.
12308 -- The key is the associated node, and the element is the new node
12309 -- itself (NOT the associated node for the new node).
12311 package NCT_Itype_Assoc is new Simple_HTable (
12312 Header_Num => NCT_Header_Num,
12313 Element => Entity_Id,
12314 No_Element => Empty,
12315 Key => Entity_Id,
12316 Hash => New_Copy_Hash,
12317 Equal => Types."=");
12319 -- Start of processing for New_Copy_Tree function
12321 function New_Copy_Tree
12322 (Source : Node_Id;
12323 Map : Elist_Id := No_Elist;
12324 New_Sloc : Source_Ptr := No_Location;
12325 New_Scope : Entity_Id := Empty) return Node_Id
12327 Actual_Map : Elist_Id := Map;
12328 -- This is the actual map for the copy. It is initialized with the
12329 -- given elements, and then enlarged as required for Itypes that are
12330 -- copied during the first phase of the copy operation. The visit
12331 -- procedures add elements to this map as Itypes are encountered.
12332 -- The reason we cannot use Map directly, is that it may well be
12333 -- (and normally is) initialized to No_Elist, and if we have mapped
12334 -- entities, we have to reset it to point to a real Elist.
12336 function Assoc (N : Node_Or_Entity_Id) return Node_Id;
12337 -- Called during second phase to map entities into their corresponding
12338 -- copies using Actual_Map. If the argument is not an entity, or is not
12339 -- in Actual_Map, then it is returned unchanged.
12341 procedure Build_NCT_Hash_Tables;
12342 -- Builds hash tables (number of elements >= threshold value)
12344 function Copy_Elist_With_Replacement
12345 (Old_Elist : Elist_Id) return Elist_Id;
12346 -- Called during second phase to copy element list doing replacements
12348 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id);
12349 -- Called during the second phase to process a copied Itype. The actual
12350 -- copy happened during the first phase (so that we could make the entry
12351 -- in the mapping), but we still have to deal with the descendents of
12352 -- the copied Itype and copy them where necessary.
12354 function Copy_List_With_Replacement (Old_List : List_Id) return List_Id;
12355 -- Called during second phase to copy list doing replacements
12357 function Copy_Node_With_Replacement (Old_Node : Node_Id) return Node_Id;
12358 -- Called during second phase to copy node doing replacements
12360 procedure Visit_Elist (E : Elist_Id);
12361 -- Called during first phase to visit all elements of an Elist
12363 procedure Visit_Field (F : Union_Id; N : Node_Id);
12364 -- Visit a single field, recursing to call Visit_Node or Visit_List
12365 -- if the field is a syntactic descendent of the current node (i.e.
12366 -- its parent is Node N).
12368 procedure Visit_Itype (Old_Itype : Entity_Id);
12369 -- Called during first phase to visit subsidiary fields of a defining
12370 -- Itype, and also create a copy and make an entry in the replacement
12371 -- map for the new copy.
12373 procedure Visit_List (L : List_Id);
12374 -- Called during first phase to visit all elements of a List
12376 procedure Visit_Node (N : Node_Or_Entity_Id);
12377 -- Called during first phase to visit a node and all its subtrees
12379 -----------
12380 -- Assoc --
12381 -----------
12383 function Assoc (N : Node_Or_Entity_Id) return Node_Id is
12384 E : Elmt_Id;
12385 Ent : Entity_Id;
12387 begin
12388 if not Has_Extension (N) or else No (Actual_Map) then
12389 return N;
12391 elsif NCT_Hash_Tables_Used then
12392 Ent := NCT_Assoc.Get (Entity_Id (N));
12394 if Present (Ent) then
12395 return Ent;
12396 else
12397 return N;
12398 end if;
12400 -- No hash table used, do serial search
12402 else
12403 E := First_Elmt (Actual_Map);
12404 while Present (E) loop
12405 if Node (E) = N then
12406 return Node (Next_Elmt (E));
12407 else
12408 E := Next_Elmt (Next_Elmt (E));
12409 end if;
12410 end loop;
12411 end if;
12413 return N;
12414 end Assoc;
12416 ---------------------------
12417 -- Build_NCT_Hash_Tables --
12418 ---------------------------
12420 procedure Build_NCT_Hash_Tables is
12421 Elmt : Elmt_Id;
12422 Ent : Entity_Id;
12423 begin
12424 if NCT_Hash_Table_Setup then
12425 NCT_Assoc.Reset;
12426 NCT_Itype_Assoc.Reset;
12427 end if;
12429 Elmt := First_Elmt (Actual_Map);
12430 while Present (Elmt) loop
12431 Ent := Node (Elmt);
12433 -- Get new entity, and associate old and new
12435 Next_Elmt (Elmt);
12436 NCT_Assoc.Set (Ent, Node (Elmt));
12438 if Is_Type (Ent) then
12439 declare
12440 Anode : constant Entity_Id :=
12441 Associated_Node_For_Itype (Ent);
12443 begin
12444 if Present (Anode) then
12446 -- Enter a link between the associated node of the
12447 -- old Itype and the new Itype, for updating later
12448 -- when node is copied.
12450 NCT_Itype_Assoc.Set (Anode, Node (Elmt));
12451 end if;
12452 end;
12453 end if;
12455 Next_Elmt (Elmt);
12456 end loop;
12458 NCT_Hash_Tables_Used := True;
12459 NCT_Hash_Table_Setup := True;
12460 end Build_NCT_Hash_Tables;
12462 ---------------------------------
12463 -- Copy_Elist_With_Replacement --
12464 ---------------------------------
12466 function Copy_Elist_With_Replacement
12467 (Old_Elist : Elist_Id) return Elist_Id
12469 M : Elmt_Id;
12470 New_Elist : Elist_Id;
12472 begin
12473 if No (Old_Elist) then
12474 return No_Elist;
12476 else
12477 New_Elist := New_Elmt_List;
12479 M := First_Elmt (Old_Elist);
12480 while Present (M) loop
12481 Append_Elmt (Copy_Node_With_Replacement (Node (M)), New_Elist);
12482 Next_Elmt (M);
12483 end loop;
12484 end if;
12486 return New_Elist;
12487 end Copy_Elist_With_Replacement;
12489 ---------------------------------
12490 -- Copy_Itype_With_Replacement --
12491 ---------------------------------
12493 -- This routine exactly parallels its phase one analog Visit_Itype,
12495 procedure Copy_Itype_With_Replacement (New_Itype : Entity_Id) is
12496 begin
12497 -- Translate Next_Entity, Scope and Etype fields, in case they
12498 -- reference entities that have been mapped into copies.
12500 Set_Next_Entity (New_Itype, Assoc (Next_Entity (New_Itype)));
12501 Set_Etype (New_Itype, Assoc (Etype (New_Itype)));
12503 if Present (New_Scope) then
12504 Set_Scope (New_Itype, New_Scope);
12505 else
12506 Set_Scope (New_Itype, Assoc (Scope (New_Itype)));
12507 end if;
12509 -- Copy referenced fields
12511 if Is_Discrete_Type (New_Itype) then
12512 Set_Scalar_Range (New_Itype,
12513 Copy_Node_With_Replacement (Scalar_Range (New_Itype)));
12515 elsif Has_Discriminants (Base_Type (New_Itype)) then
12516 Set_Discriminant_Constraint (New_Itype,
12517 Copy_Elist_With_Replacement
12518 (Discriminant_Constraint (New_Itype)));
12520 elsif Is_Array_Type (New_Itype) then
12521 if Present (First_Index (New_Itype)) then
12522 Set_First_Index (New_Itype,
12523 First (Copy_List_With_Replacement
12524 (List_Containing (First_Index (New_Itype)))));
12525 end if;
12527 if Is_Packed (New_Itype) then
12528 Set_Packed_Array_Type (New_Itype,
12529 Copy_Node_With_Replacement
12530 (Packed_Array_Type (New_Itype)));
12531 end if;
12532 end if;
12533 end Copy_Itype_With_Replacement;
12535 --------------------------------
12536 -- Copy_List_With_Replacement --
12537 --------------------------------
12539 function Copy_List_With_Replacement
12540 (Old_List : List_Id) return List_Id
12542 New_List : List_Id;
12543 E : Node_Id;
12545 begin
12546 if Old_List = No_List then
12547 return No_List;
12549 else
12550 New_List := Empty_List;
12552 E := First (Old_List);
12553 while Present (E) loop
12554 Append (Copy_Node_With_Replacement (E), New_List);
12555 Next (E);
12556 end loop;
12558 return New_List;
12559 end if;
12560 end Copy_List_With_Replacement;
12562 --------------------------------
12563 -- Copy_Node_With_Replacement --
12564 --------------------------------
12566 function Copy_Node_With_Replacement
12567 (Old_Node : Node_Id) return Node_Id
12569 New_Node : Node_Id;
12571 procedure Adjust_Named_Associations
12572 (Old_Node : Node_Id;
12573 New_Node : Node_Id);
12574 -- If a call node has named associations, these are chained through
12575 -- the First_Named_Actual, Next_Named_Actual links. These must be
12576 -- propagated separately to the new parameter list, because these
12577 -- are not syntactic fields.
12579 function Copy_Field_With_Replacement
12580 (Field : Union_Id) return Union_Id;
12581 -- Given Field, which is a field of Old_Node, return a copy of it
12582 -- if it is a syntactic field (i.e. its parent is Node), setting
12583 -- the parent of the copy to poit to New_Node. Otherwise returns
12584 -- the field (possibly mapped if it is an entity).
12586 -------------------------------
12587 -- Adjust_Named_Associations --
12588 -------------------------------
12590 procedure Adjust_Named_Associations
12591 (Old_Node : Node_Id;
12592 New_Node : Node_Id)
12594 Old_E : Node_Id;
12595 New_E : Node_Id;
12597 Old_Next : Node_Id;
12598 New_Next : Node_Id;
12600 begin
12601 Old_E := First (Parameter_Associations (Old_Node));
12602 New_E := First (Parameter_Associations (New_Node));
12603 while Present (Old_E) loop
12604 if Nkind (Old_E) = N_Parameter_Association
12605 and then Present (Next_Named_Actual (Old_E))
12606 then
12607 if First_Named_Actual (Old_Node)
12608 = Explicit_Actual_Parameter (Old_E)
12609 then
12610 Set_First_Named_Actual
12611 (New_Node, Explicit_Actual_Parameter (New_E));
12612 end if;
12614 -- Now scan parameter list from the beginning,to locate
12615 -- next named actual, which can be out of order.
12617 Old_Next := First (Parameter_Associations (Old_Node));
12618 New_Next := First (Parameter_Associations (New_Node));
12620 while Nkind (Old_Next) /= N_Parameter_Association
12621 or else Explicit_Actual_Parameter (Old_Next)
12622 /= Next_Named_Actual (Old_E)
12623 loop
12624 Next (Old_Next);
12625 Next (New_Next);
12626 end loop;
12628 Set_Next_Named_Actual
12629 (New_E, Explicit_Actual_Parameter (New_Next));
12630 end if;
12632 Next (Old_E);
12633 Next (New_E);
12634 end loop;
12635 end Adjust_Named_Associations;
12637 ---------------------------------
12638 -- Copy_Field_With_Replacement --
12639 ---------------------------------
12641 function Copy_Field_With_Replacement
12642 (Field : Union_Id) return Union_Id
12644 begin
12645 if Field = Union_Id (Empty) then
12646 return Field;
12648 elsif Field in Node_Range then
12649 declare
12650 Old_N : constant Node_Id := Node_Id (Field);
12651 New_N : Node_Id;
12653 begin
12654 -- If syntactic field, as indicated by the parent pointer
12655 -- being set, then copy the referenced node recursively.
12657 if Parent (Old_N) = Old_Node then
12658 New_N := Copy_Node_With_Replacement (Old_N);
12660 if New_N /= Old_N then
12661 Set_Parent (New_N, New_Node);
12662 end if;
12664 -- For semantic fields, update possible entity reference
12665 -- from the replacement map.
12667 else
12668 New_N := Assoc (Old_N);
12669 end if;
12671 return Union_Id (New_N);
12672 end;
12674 elsif Field in List_Range then
12675 declare
12676 Old_L : constant List_Id := List_Id (Field);
12677 New_L : List_Id;
12679 begin
12680 -- If syntactic field, as indicated by the parent pointer,
12681 -- then recursively copy the entire referenced list.
12683 if Parent (Old_L) = Old_Node then
12684 New_L := Copy_List_With_Replacement (Old_L);
12685 Set_Parent (New_L, New_Node);
12687 -- For semantic list, just returned unchanged
12689 else
12690 New_L := Old_L;
12691 end if;
12693 return Union_Id (New_L);
12694 end;
12696 -- Anything other than a list or a node is returned unchanged
12698 else
12699 return Field;
12700 end if;
12701 end Copy_Field_With_Replacement;
12703 -- Start of processing for Copy_Node_With_Replacement
12705 begin
12706 if Old_Node <= Empty_Or_Error then
12707 return Old_Node;
12709 elsif Has_Extension (Old_Node) then
12710 return Assoc (Old_Node);
12712 else
12713 New_Node := New_Copy (Old_Node);
12715 -- If the node we are copying is the associated node of a
12716 -- previously copied Itype, then adjust the associated node
12717 -- of the copy of that Itype accordingly.
12719 if Present (Actual_Map) then
12720 declare
12721 E : Elmt_Id;
12722 Ent : Entity_Id;
12724 begin
12725 -- Case of hash table used
12727 if NCT_Hash_Tables_Used then
12728 Ent := NCT_Itype_Assoc.Get (Old_Node);
12730 if Present (Ent) then
12731 Set_Associated_Node_For_Itype (Ent, New_Node);
12732 end if;
12734 -- Case of no hash table used
12736 else
12737 E := First_Elmt (Actual_Map);
12738 while Present (E) loop
12739 if Is_Itype (Node (E))
12740 and then
12741 Old_Node = Associated_Node_For_Itype (Node (E))
12742 then
12743 Set_Associated_Node_For_Itype
12744 (Node (Next_Elmt (E)), New_Node);
12745 end if;
12747 E := Next_Elmt (Next_Elmt (E));
12748 end loop;
12749 end if;
12750 end;
12751 end if;
12753 -- Recursively copy descendents
12755 Set_Field1
12756 (New_Node, Copy_Field_With_Replacement (Field1 (New_Node)));
12757 Set_Field2
12758 (New_Node, Copy_Field_With_Replacement (Field2 (New_Node)));
12759 Set_Field3
12760 (New_Node, Copy_Field_With_Replacement (Field3 (New_Node)));
12761 Set_Field4
12762 (New_Node, Copy_Field_With_Replacement (Field4 (New_Node)));
12763 Set_Field5
12764 (New_Node, Copy_Field_With_Replacement (Field5 (New_Node)));
12766 -- Adjust Sloc of new node if necessary
12768 if New_Sloc /= No_Location then
12769 Set_Sloc (New_Node, New_Sloc);
12771 -- If we adjust the Sloc, then we are essentially making
12772 -- a completely new node, so the Comes_From_Source flag
12773 -- should be reset to the proper default value.
12775 Nodes.Table (New_Node).Comes_From_Source :=
12776 Default_Node.Comes_From_Source;
12777 end if;
12779 -- If the node is call and has named associations,
12780 -- set the corresponding links in the copy.
12782 if (Nkind (Old_Node) = N_Function_Call
12783 or else Nkind (Old_Node) = N_Entry_Call_Statement
12784 or else
12785 Nkind (Old_Node) = N_Procedure_Call_Statement)
12786 and then Present (First_Named_Actual (Old_Node))
12787 then
12788 Adjust_Named_Associations (Old_Node, New_Node);
12789 end if;
12791 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
12792 -- The replacement mechanism applies to entities, and is not used
12793 -- here. Eventually we may need a more general graph-copying
12794 -- routine. For now, do a sequential search to find desired node.
12796 if Nkind (Old_Node) = N_Handled_Sequence_Of_Statements
12797 and then Present (First_Real_Statement (Old_Node))
12798 then
12799 declare
12800 Old_F : constant Node_Id := First_Real_Statement (Old_Node);
12801 N1, N2 : Node_Id;
12803 begin
12804 N1 := First (Statements (Old_Node));
12805 N2 := First (Statements (New_Node));
12807 while N1 /= Old_F loop
12808 Next (N1);
12809 Next (N2);
12810 end loop;
12812 Set_First_Real_Statement (New_Node, N2);
12813 end;
12814 end if;
12815 end if;
12817 -- All done, return copied node
12819 return New_Node;
12820 end Copy_Node_With_Replacement;
12822 -----------------
12823 -- Visit_Elist --
12824 -----------------
12826 procedure Visit_Elist (E : Elist_Id) is
12827 Elmt : Elmt_Id;
12828 begin
12829 if Present (E) then
12830 Elmt := First_Elmt (E);
12832 while Elmt /= No_Elmt loop
12833 Visit_Node (Node (Elmt));
12834 Next_Elmt (Elmt);
12835 end loop;
12836 end if;
12837 end Visit_Elist;
12839 -----------------
12840 -- Visit_Field --
12841 -----------------
12843 procedure Visit_Field (F : Union_Id; N : Node_Id) is
12844 begin
12845 if F = Union_Id (Empty) then
12846 return;
12848 elsif F in Node_Range then
12850 -- Copy node if it is syntactic, i.e. its parent pointer is
12851 -- set to point to the field that referenced it (certain
12852 -- Itypes will also meet this criterion, which is fine, since
12853 -- these are clearly Itypes that do need to be copied, since
12854 -- we are copying their parent.)
12856 if Parent (Node_Id (F)) = N then
12857 Visit_Node (Node_Id (F));
12858 return;
12860 -- Another case, if we are pointing to an Itype, then we want
12861 -- to copy it if its associated node is somewhere in the tree
12862 -- being copied.
12864 -- Note: the exclusion of self-referential copies is just an
12865 -- optimization, since the search of the already copied list
12866 -- would catch it, but it is a common case (Etype pointing
12867 -- to itself for an Itype that is a base type).
12869 elsif Has_Extension (Node_Id (F))
12870 and then Is_Itype (Entity_Id (F))
12871 and then Node_Id (F) /= N
12872 then
12873 declare
12874 P : Node_Id;
12876 begin
12877 P := Associated_Node_For_Itype (Node_Id (F));
12878 while Present (P) loop
12879 if P = Source then
12880 Visit_Node (Node_Id (F));
12881 return;
12882 else
12883 P := Parent (P);
12884 end if;
12885 end loop;
12887 -- An Itype whose parent is not being copied definitely
12888 -- should NOT be copied, since it does not belong in any
12889 -- sense to the copied subtree.
12891 return;
12892 end;
12893 end if;
12895 elsif F in List_Range
12896 and then Parent (List_Id (F)) = N
12897 then
12898 Visit_List (List_Id (F));
12899 return;
12900 end if;
12901 end Visit_Field;
12903 -----------------
12904 -- Visit_Itype --
12905 -----------------
12907 procedure Visit_Itype (Old_Itype : Entity_Id) is
12908 New_Itype : Entity_Id;
12909 E : Elmt_Id;
12910 Ent : Entity_Id;
12912 begin
12913 -- Itypes that describe the designated type of access to subprograms
12914 -- have the structure of subprogram declarations, with signatures,
12915 -- etc. Either we duplicate the signatures completely, or choose to
12916 -- share such itypes, which is fine because their elaboration will
12917 -- have no side effects.
12919 if Ekind (Old_Itype) = E_Subprogram_Type then
12920 return;
12921 end if;
12923 New_Itype := New_Copy (Old_Itype);
12925 -- The new Itype has all the attributes of the old one, and
12926 -- we just copy the contents of the entity. However, the back-end
12927 -- needs different names for debugging purposes, so we create a
12928 -- new internal name for it in all cases.
12930 Set_Chars (New_Itype, New_Internal_Name ('T'));
12932 -- If our associated node is an entity that has already been copied,
12933 -- then set the associated node of the copy to point to the right
12934 -- copy. If we have copied an Itype that is itself the associated
12935 -- node of some previously copied Itype, then we set the right
12936 -- pointer in the other direction.
12938 if Present (Actual_Map) then
12940 -- Case of hash tables used
12942 if NCT_Hash_Tables_Used then
12944 Ent := NCT_Assoc.Get (Associated_Node_For_Itype (Old_Itype));
12946 if Present (Ent) then
12947 Set_Associated_Node_For_Itype (New_Itype, Ent);
12948 end if;
12950 Ent := NCT_Itype_Assoc.Get (Old_Itype);
12951 if Present (Ent) then
12952 Set_Associated_Node_For_Itype (Ent, New_Itype);
12954 -- If the hash table has no association for this Itype and
12955 -- its associated node, enter one now.
12957 else
12958 NCT_Itype_Assoc.Set
12959 (Associated_Node_For_Itype (Old_Itype), New_Itype);
12960 end if;
12962 -- Case of hash tables not used
12964 else
12965 E := First_Elmt (Actual_Map);
12966 while Present (E) loop
12967 if Associated_Node_For_Itype (Old_Itype) = Node (E) then
12968 Set_Associated_Node_For_Itype
12969 (New_Itype, Node (Next_Elmt (E)));
12970 end if;
12972 if Is_Type (Node (E))
12973 and then
12974 Old_Itype = Associated_Node_For_Itype (Node (E))
12975 then
12976 Set_Associated_Node_For_Itype
12977 (Node (Next_Elmt (E)), New_Itype);
12978 end if;
12980 E := Next_Elmt (Next_Elmt (E));
12981 end loop;
12982 end if;
12983 end if;
12985 if Present (Freeze_Node (New_Itype)) then
12986 Set_Is_Frozen (New_Itype, False);
12987 Set_Freeze_Node (New_Itype, Empty);
12988 end if;
12990 -- Add new association to map
12992 if No (Actual_Map) then
12993 Actual_Map := New_Elmt_List;
12994 end if;
12996 Append_Elmt (Old_Itype, Actual_Map);
12997 Append_Elmt (New_Itype, Actual_Map);
12999 if NCT_Hash_Tables_Used then
13000 NCT_Assoc.Set (Old_Itype, New_Itype);
13002 else
13003 NCT_Table_Entries := NCT_Table_Entries + 1;
13005 if NCT_Table_Entries > NCT_Hash_Threshold then
13006 Build_NCT_Hash_Tables;
13007 end if;
13008 end if;
13010 -- If a record subtype is simply copied, the entity list will be
13011 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
13013 if Ekind_In (Old_Itype, E_Record_Subtype, E_Class_Wide_Subtype) then
13014 Set_Cloned_Subtype (New_Itype, Old_Itype);
13015 end if;
13017 -- Visit descendents that eventually get copied
13019 Visit_Field (Union_Id (Etype (Old_Itype)), Old_Itype);
13021 if Is_Discrete_Type (Old_Itype) then
13022 Visit_Field (Union_Id (Scalar_Range (Old_Itype)), Old_Itype);
13024 elsif Has_Discriminants (Base_Type (Old_Itype)) then
13025 -- ??? This should involve call to Visit_Field
13026 Visit_Elist (Discriminant_Constraint (Old_Itype));
13028 elsif Is_Array_Type (Old_Itype) then
13029 if Present (First_Index (Old_Itype)) then
13030 Visit_Field (Union_Id (List_Containing
13031 (First_Index (Old_Itype))),
13032 Old_Itype);
13033 end if;
13035 if Is_Packed (Old_Itype) then
13036 Visit_Field (Union_Id (Packed_Array_Type (Old_Itype)),
13037 Old_Itype);
13038 end if;
13039 end if;
13040 end Visit_Itype;
13042 ----------------
13043 -- Visit_List --
13044 ----------------
13046 procedure Visit_List (L : List_Id) is
13047 N : Node_Id;
13048 begin
13049 if L /= No_List then
13050 N := First (L);
13052 while Present (N) loop
13053 Visit_Node (N);
13054 Next (N);
13055 end loop;
13056 end if;
13057 end Visit_List;
13059 ----------------
13060 -- Visit_Node --
13061 ----------------
13063 procedure Visit_Node (N : Node_Or_Entity_Id) is
13065 -- Start of processing for Visit_Node
13067 begin
13068 -- Handle case of an Itype, which must be copied
13070 if Has_Extension (N)
13071 and then Is_Itype (N)
13072 then
13073 -- Nothing to do if already in the list. This can happen with an
13074 -- Itype entity that appears more than once in the tree.
13075 -- Note that we do not want to visit descendents in this case.
13077 -- Test for already in list when hash table is used
13079 if NCT_Hash_Tables_Used then
13080 if Present (NCT_Assoc.Get (Entity_Id (N))) then
13081 return;
13082 end if;
13084 -- Test for already in list when hash table not used
13086 else
13087 declare
13088 E : Elmt_Id;
13089 begin
13090 if Present (Actual_Map) then
13091 E := First_Elmt (Actual_Map);
13092 while Present (E) loop
13093 if Node (E) = N then
13094 return;
13095 else
13096 E := Next_Elmt (Next_Elmt (E));
13097 end if;
13098 end loop;
13099 end if;
13100 end;
13101 end if;
13103 Visit_Itype (N);
13104 end if;
13106 -- Visit descendents
13108 Visit_Field (Field1 (N), N);
13109 Visit_Field (Field2 (N), N);
13110 Visit_Field (Field3 (N), N);
13111 Visit_Field (Field4 (N), N);
13112 Visit_Field (Field5 (N), N);
13113 end Visit_Node;
13115 -- Start of processing for New_Copy_Tree
13117 begin
13118 Actual_Map := Map;
13120 -- See if we should use hash table
13122 if No (Actual_Map) then
13123 NCT_Hash_Tables_Used := False;
13125 else
13126 declare
13127 Elmt : Elmt_Id;
13129 begin
13130 NCT_Table_Entries := 0;
13132 Elmt := First_Elmt (Actual_Map);
13133 while Present (Elmt) loop
13134 NCT_Table_Entries := NCT_Table_Entries + 1;
13135 Next_Elmt (Elmt);
13136 Next_Elmt (Elmt);
13137 end loop;
13139 if NCT_Table_Entries > NCT_Hash_Threshold then
13140 Build_NCT_Hash_Tables;
13141 else
13142 NCT_Hash_Tables_Used := False;
13143 end if;
13144 end;
13145 end if;
13147 -- Hash table set up if required, now start phase one by visiting
13148 -- top node (we will recursively visit the descendents).
13150 Visit_Node (Source);
13152 -- Now the second phase of the copy can start. First we process
13153 -- all the mapped entities, copying their descendents.
13155 if Present (Actual_Map) then
13156 declare
13157 Elmt : Elmt_Id;
13158 New_Itype : Entity_Id;
13159 begin
13160 Elmt := First_Elmt (Actual_Map);
13161 while Present (Elmt) loop
13162 Next_Elmt (Elmt);
13163 New_Itype := Node (Elmt);
13164 Copy_Itype_With_Replacement (New_Itype);
13165 Next_Elmt (Elmt);
13166 end loop;
13167 end;
13168 end if;
13170 -- Now we can copy the actual tree
13172 return Copy_Node_With_Replacement (Source);
13173 end New_Copy_Tree;
13175 -------------------------
13176 -- New_External_Entity --
13177 -------------------------
13179 function New_External_Entity
13180 (Kind : Entity_Kind;
13181 Scope_Id : Entity_Id;
13182 Sloc_Value : Source_Ptr;
13183 Related_Id : Entity_Id;
13184 Suffix : Character;
13185 Suffix_Index : Nat := 0;
13186 Prefix : Character := ' ') return Entity_Id
13188 N : constant Entity_Id :=
13189 Make_Defining_Identifier (Sloc_Value,
13190 New_External_Name
13191 (Chars (Related_Id), Suffix, Suffix_Index, Prefix));
13193 begin
13194 Set_Ekind (N, Kind);
13195 Set_Is_Internal (N, True);
13196 Append_Entity (N, Scope_Id);
13197 Set_Public_Status (N);
13199 if Kind in Type_Kind then
13200 Init_Size_Align (N);
13201 end if;
13203 return N;
13204 end New_External_Entity;
13206 -------------------------
13207 -- New_Internal_Entity --
13208 -------------------------
13210 function New_Internal_Entity
13211 (Kind : Entity_Kind;
13212 Scope_Id : Entity_Id;
13213 Sloc_Value : Source_Ptr;
13214 Id_Char : Character) return Entity_Id
13216 N : constant Entity_Id := Make_Temporary (Sloc_Value, Id_Char);
13218 begin
13219 Set_Ekind (N, Kind);
13220 Set_Is_Internal (N, True);
13221 Append_Entity (N, Scope_Id);
13223 if Kind in Type_Kind then
13224 Init_Size_Align (N);
13225 end if;
13227 return N;
13228 end New_Internal_Entity;
13230 -----------------
13231 -- Next_Actual --
13232 -----------------
13234 function Next_Actual (Actual_Id : Node_Id) return Node_Id is
13235 N : Node_Id;
13237 begin
13238 -- If we are pointing at a positional parameter, it is a member of a
13239 -- node list (the list of parameters), and the next parameter is the
13240 -- next node on the list, unless we hit a parameter association, then
13241 -- we shift to using the chain whose head is the First_Named_Actual in
13242 -- the parent, and then is threaded using the Next_Named_Actual of the
13243 -- Parameter_Association. All this fiddling is because the original node
13244 -- list is in the textual call order, and what we need is the
13245 -- declaration order.
13247 if Is_List_Member (Actual_Id) then
13248 N := Next (Actual_Id);
13250 if Nkind (N) = N_Parameter_Association then
13251 return First_Named_Actual (Parent (Actual_Id));
13252 else
13253 return N;
13254 end if;
13256 else
13257 return Next_Named_Actual (Parent (Actual_Id));
13258 end if;
13259 end Next_Actual;
13261 procedure Next_Actual (Actual_Id : in out Node_Id) is
13262 begin
13263 Actual_Id := Next_Actual (Actual_Id);
13264 end Next_Actual;
13266 ---------------------
13267 -- No_Scalar_Parts --
13268 ---------------------
13270 function No_Scalar_Parts (T : Entity_Id) return Boolean is
13271 C : Entity_Id;
13273 begin
13274 if Is_Scalar_Type (T) then
13275 return False;
13277 elsif Is_Array_Type (T) then
13278 return No_Scalar_Parts (Component_Type (T));
13280 elsif Is_Record_Type (T) or else Has_Discriminants (T) then
13281 C := First_Component_Or_Discriminant (T);
13282 while Present (C) loop
13283 if not No_Scalar_Parts (Etype (C)) then
13284 return False;
13285 else
13286 Next_Component_Or_Discriminant (C);
13287 end if;
13288 end loop;
13289 end if;
13291 return True;
13292 end No_Scalar_Parts;
13294 -----------------------
13295 -- Normalize_Actuals --
13296 -----------------------
13298 -- Chain actuals according to formals of subprogram. If there are no named
13299 -- associations, the chain is simply the list of Parameter Associations,
13300 -- since the order is the same as the declaration order. If there are named
13301 -- associations, then the First_Named_Actual field in the N_Function_Call
13302 -- or N_Procedure_Call_Statement node points to the Parameter_Association
13303 -- node for the parameter that comes first in declaration order. The
13304 -- remaining named parameters are then chained in declaration order using
13305 -- Next_Named_Actual.
13307 -- This routine also verifies that the number of actuals is compatible with
13308 -- the number and default values of formals, but performs no type checking
13309 -- (type checking is done by the caller).
13311 -- If the matching succeeds, Success is set to True and the caller proceeds
13312 -- with type-checking. If the match is unsuccessful, then Success is set to
13313 -- False, and the caller attempts a different interpretation, if there is
13314 -- one.
13316 -- If the flag Report is on, the call is not overloaded, and a failure to
13317 -- match can be reported here, rather than in the caller.
13319 procedure Normalize_Actuals
13320 (N : Node_Id;
13321 S : Entity_Id;
13322 Report : Boolean;
13323 Success : out Boolean)
13325 Actuals : constant List_Id := Parameter_Associations (N);
13326 Actual : Node_Id := Empty;
13327 Formal : Entity_Id;
13328 Last : Node_Id := Empty;
13329 First_Named : Node_Id := Empty;
13330 Found : Boolean;
13332 Formals_To_Match : Integer := 0;
13333 Actuals_To_Match : Integer := 0;
13335 procedure Chain (A : Node_Id);
13336 -- Add named actual at the proper place in the list, using the
13337 -- Next_Named_Actual link.
13339 function Reporting return Boolean;
13340 -- Determines if an error is to be reported. To report an error, we
13341 -- need Report to be True, and also we do not report errors caused
13342 -- by calls to init procs that occur within other init procs. Such
13343 -- errors must always be cascaded errors, since if all the types are
13344 -- declared correctly, the compiler will certainly build decent calls.
13346 -----------
13347 -- Chain --
13348 -----------
13350 procedure Chain (A : Node_Id) is
13351 begin
13352 if No (Last) then
13354 -- Call node points to first actual in list
13356 Set_First_Named_Actual (N, Explicit_Actual_Parameter (A));
13358 else
13359 Set_Next_Named_Actual (Last, Explicit_Actual_Parameter (A));
13360 end if;
13362 Last := A;
13363 Set_Next_Named_Actual (Last, Empty);
13364 end Chain;
13366 ---------------
13367 -- Reporting --
13368 ---------------
13370 function Reporting return Boolean is
13371 begin
13372 if not Report then
13373 return False;
13375 elsif not Within_Init_Proc then
13376 return True;
13378 elsif Is_Init_Proc (Entity (Name (N))) then
13379 return False;
13381 else
13382 return True;
13383 end if;
13384 end Reporting;
13386 -- Start of processing for Normalize_Actuals
13388 begin
13389 if Is_Access_Type (S) then
13391 -- The name in the call is a function call that returns an access
13392 -- to subprogram. The designated type has the list of formals.
13394 Formal := First_Formal (Designated_Type (S));
13395 else
13396 Formal := First_Formal (S);
13397 end if;
13399 while Present (Formal) loop
13400 Formals_To_Match := Formals_To_Match + 1;
13401 Next_Formal (Formal);
13402 end loop;
13404 -- Find if there is a named association, and verify that no positional
13405 -- associations appear after named ones.
13407 if Present (Actuals) then
13408 Actual := First (Actuals);
13409 end if;
13411 while Present (Actual)
13412 and then Nkind (Actual) /= N_Parameter_Association
13413 loop
13414 Actuals_To_Match := Actuals_To_Match + 1;
13415 Next (Actual);
13416 end loop;
13418 if No (Actual) and Actuals_To_Match = Formals_To_Match then
13420 -- Most common case: positional notation, no defaults
13422 Success := True;
13423 return;
13425 elsif Actuals_To_Match > Formals_To_Match then
13427 -- Too many actuals: will not work
13429 if Reporting then
13430 if Is_Entity_Name (Name (N)) then
13431 Error_Msg_N ("too many arguments in call to&", Name (N));
13432 else
13433 Error_Msg_N ("too many arguments in call", N);
13434 end if;
13435 end if;
13437 Success := False;
13438 return;
13439 end if;
13441 First_Named := Actual;
13443 while Present (Actual) loop
13444 if Nkind (Actual) /= N_Parameter_Association then
13445 Error_Msg_N
13446 ("positional parameters not allowed after named ones", Actual);
13447 Success := False;
13448 return;
13450 else
13451 Actuals_To_Match := Actuals_To_Match + 1;
13452 end if;
13454 Next (Actual);
13455 end loop;
13457 if Present (Actuals) then
13458 Actual := First (Actuals);
13459 end if;
13461 Formal := First_Formal (S);
13462 while Present (Formal) loop
13464 -- Match the formals in order. If the corresponding actual is
13465 -- positional, nothing to do. Else scan the list of named actuals
13466 -- to find the one with the right name.
13468 if Present (Actual)
13469 and then Nkind (Actual) /= N_Parameter_Association
13470 then
13471 Next (Actual);
13472 Actuals_To_Match := Actuals_To_Match - 1;
13473 Formals_To_Match := Formals_To_Match - 1;
13475 else
13476 -- For named parameters, search the list of actuals to find
13477 -- one that matches the next formal name.
13479 Actual := First_Named;
13480 Found := False;
13481 while Present (Actual) loop
13482 if Chars (Selector_Name (Actual)) = Chars (Formal) then
13483 Found := True;
13484 Chain (Actual);
13485 Actuals_To_Match := Actuals_To_Match - 1;
13486 Formals_To_Match := Formals_To_Match - 1;
13487 exit;
13488 end if;
13490 Next (Actual);
13491 end loop;
13493 if not Found then
13494 if Ekind (Formal) /= E_In_Parameter
13495 or else No (Default_Value (Formal))
13496 then
13497 if Reporting then
13498 if (Comes_From_Source (S)
13499 or else Sloc (S) = Standard_Location)
13500 and then Is_Overloadable (S)
13501 then
13502 if No (Actuals)
13503 and then
13504 (Nkind (Parent (N)) = N_Procedure_Call_Statement
13505 or else
13506 (Nkind (Parent (N)) = N_Function_Call
13507 or else
13508 Nkind (Parent (N)) = N_Parameter_Association))
13509 and then Ekind (S) /= E_Function
13510 then
13511 Set_Etype (N, Etype (S));
13512 else
13513 Error_Msg_Name_1 := Chars (S);
13514 Error_Msg_Sloc := Sloc (S);
13515 Error_Msg_NE
13516 ("missing argument for parameter & " &
13517 "in call to % declared #", N, Formal);
13518 end if;
13520 elsif Is_Overloadable (S) then
13521 Error_Msg_Name_1 := Chars (S);
13523 -- Point to type derivation that generated the
13524 -- operation.
13526 Error_Msg_Sloc := Sloc (Parent (S));
13528 Error_Msg_NE
13529 ("missing argument for parameter & " &
13530 "in call to % (inherited) #", N, Formal);
13532 else
13533 Error_Msg_NE
13534 ("missing argument for parameter &", N, Formal);
13535 end if;
13536 end if;
13538 Success := False;
13539 return;
13541 else
13542 Formals_To_Match := Formals_To_Match - 1;
13543 end if;
13544 end if;
13545 end if;
13547 Next_Formal (Formal);
13548 end loop;
13550 if Formals_To_Match = 0 and then Actuals_To_Match = 0 then
13551 Success := True;
13552 return;
13554 else
13555 if Reporting then
13557 -- Find some superfluous named actual that did not get
13558 -- attached to the list of associations.
13560 Actual := First (Actuals);
13561 while Present (Actual) loop
13562 if Nkind (Actual) = N_Parameter_Association
13563 and then Actual /= Last
13564 and then No (Next_Named_Actual (Actual))
13565 then
13566 Error_Msg_N ("unmatched actual & in call",
13567 Selector_Name (Actual));
13568 exit;
13569 end if;
13571 Next (Actual);
13572 end loop;
13573 end if;
13575 Success := False;
13576 return;
13577 end if;
13578 end Normalize_Actuals;
13580 --------------------------------
13581 -- Note_Possible_Modification --
13582 --------------------------------
13584 procedure Note_Possible_Modification (N : Node_Id; Sure : Boolean) is
13585 Modification_Comes_From_Source : constant Boolean :=
13586 Comes_From_Source (Parent (N));
13588 Ent : Entity_Id;
13589 Exp : Node_Id;
13591 begin
13592 -- Loop to find referenced entity, if there is one
13594 Exp := N;
13595 loop
13596 Ent := Empty;
13598 if Is_Entity_Name (Exp) then
13599 Ent := Entity (Exp);
13601 -- If the entity is missing, it is an undeclared identifier,
13602 -- and there is nothing to annotate.
13604 if No (Ent) then
13605 return;
13606 end if;
13608 elsif Nkind (Exp) = N_Explicit_Dereference then
13609 declare
13610 P : constant Node_Id := Prefix (Exp);
13612 begin
13613 -- In formal verification mode, keep track of all reads and
13614 -- writes through explicit dereferences.
13616 if GNATprove_Mode then
13617 SPARK_Specific.Generate_Dereference (N, 'm');
13618 end if;
13620 if Nkind (P) = N_Selected_Component
13621 and then Present (Entry_Formal (Entity (Selector_Name (P))))
13622 then
13623 -- Case of a reference to an entry formal
13625 Ent := Entry_Formal (Entity (Selector_Name (P)));
13627 elsif Nkind (P) = N_Identifier
13628 and then Nkind (Parent (Entity (P))) = N_Object_Declaration
13629 and then Present (Expression (Parent (Entity (P))))
13630 and then Nkind (Expression (Parent (Entity (P)))) =
13631 N_Reference
13632 then
13633 -- Case of a reference to a value on which side effects have
13634 -- been removed.
13636 Exp := Prefix (Expression (Parent (Entity (P))));
13637 goto Continue;
13639 else
13640 return;
13641 end if;
13642 end;
13644 elsif Nkind_In (Exp, N_Type_Conversion,
13645 N_Unchecked_Type_Conversion)
13646 then
13647 Exp := Expression (Exp);
13648 goto Continue;
13650 elsif Nkind_In (Exp, N_Slice,
13651 N_Indexed_Component,
13652 N_Selected_Component)
13653 then
13654 -- Special check, if the prefix is an access type, then return
13655 -- since we are modifying the thing pointed to, not the prefix.
13656 -- When we are expanding, most usually the prefix is replaced
13657 -- by an explicit dereference, and this test is not needed, but
13658 -- in some cases (notably -gnatc mode and generics) when we do
13659 -- not do full expansion, we need this special test.
13661 if Is_Access_Type (Etype (Prefix (Exp))) then
13662 return;
13664 -- Otherwise go to prefix and keep going
13666 else
13667 Exp := Prefix (Exp);
13668 goto Continue;
13669 end if;
13671 -- All other cases, not a modification
13673 else
13674 return;
13675 end if;
13677 -- Now look for entity being referenced
13679 if Present (Ent) then
13680 if Is_Object (Ent) then
13681 if Comes_From_Source (Exp)
13682 or else Modification_Comes_From_Source
13683 then
13684 -- Give warning if pragma unmodified given and we are
13685 -- sure this is a modification.
13687 if Has_Pragma_Unmodified (Ent) and then Sure then
13688 Error_Msg_NE
13689 ("??pragma Unmodified given for &!", N, Ent);
13690 end if;
13692 Set_Never_Set_In_Source (Ent, False);
13693 end if;
13695 Set_Is_True_Constant (Ent, False);
13696 Set_Current_Value (Ent, Empty);
13697 Set_Is_Known_Null (Ent, False);
13699 if not Can_Never_Be_Null (Ent) then
13700 Set_Is_Known_Non_Null (Ent, False);
13701 end if;
13703 -- Follow renaming chain
13705 if (Ekind (Ent) = E_Variable or else Ekind (Ent) = E_Constant)
13706 and then Present (Renamed_Object (Ent))
13707 then
13708 Exp := Renamed_Object (Ent);
13710 -- If the entity is the loop variable in an iteration over
13711 -- a container, retrieve container expression to indicate
13712 -- possible modificastion.
13714 if Present (Related_Expression (Ent))
13715 and then Nkind (Parent (Related_Expression (Ent))) =
13716 N_Iterator_Specification
13717 then
13718 Exp := Original_Node (Related_Expression (Ent));
13719 end if;
13721 goto Continue;
13723 -- The expression may be the renaming of a subcomponent of an
13724 -- array or container. The assignment to the subcomponent is
13725 -- a modification of the container.
13727 elsif Comes_From_Source (Original_Node (Exp))
13728 and then Nkind_In (Original_Node (Exp), N_Selected_Component,
13729 N_Indexed_Component)
13730 then
13731 Exp := Prefix (Original_Node (Exp));
13732 goto Continue;
13733 end if;
13735 -- Generate a reference only if the assignment comes from
13736 -- source. This excludes, for example, calls to a dispatching
13737 -- assignment operation when the left-hand side is tagged. In
13738 -- GNATprove mode, we need those references also on generated
13739 -- code, as these are used to compute the local effects of
13740 -- subprograms.
13742 if Modification_Comes_From_Source or GNATprove_Mode then
13743 Generate_Reference (Ent, Exp, 'm');
13745 -- If the target of the assignment is the bound variable
13746 -- in an iterator, indicate that the corresponding array
13747 -- or container is also modified.
13749 if Ada_Version >= Ada_2012
13750 and then
13751 Nkind (Parent (Ent)) = N_Iterator_Specification
13752 then
13753 declare
13754 Domain : constant Node_Id := Name (Parent (Ent));
13756 begin
13757 -- TBD : in the full version of the construct, the
13758 -- domain of iteration can be given by an expression.
13760 if Is_Entity_Name (Domain) then
13761 Generate_Reference (Entity (Domain), Exp, 'm');
13762 Set_Is_True_Constant (Entity (Domain), False);
13763 Set_Never_Set_In_Source (Entity (Domain), False);
13764 end if;
13765 end;
13766 end if;
13767 end if;
13769 Check_Nested_Access (Ent);
13770 end if;
13772 Kill_Checks (Ent);
13774 -- If we are sure this is a modification from source, and we know
13775 -- this modifies a constant, then give an appropriate warning.
13777 if Overlays_Constant (Ent)
13778 and then Modification_Comes_From_Source
13779 and then Sure
13780 then
13781 declare
13782 A : constant Node_Id := Address_Clause (Ent);
13783 begin
13784 if Present (A) then
13785 declare
13786 Exp : constant Node_Id := Expression (A);
13787 begin
13788 if Nkind (Exp) = N_Attribute_Reference
13789 and then Attribute_Name (Exp) = Name_Address
13790 and then Is_Entity_Name (Prefix (Exp))
13791 then
13792 Error_Msg_Sloc := Sloc (A);
13793 Error_Msg_NE
13794 ("constant& may be modified via address "
13795 & "clause#??", N, Entity (Prefix (Exp)));
13796 end if;
13797 end;
13798 end if;
13799 end;
13800 end if;
13802 return;
13803 end if;
13805 <<Continue>>
13806 null;
13807 end loop;
13808 end Note_Possible_Modification;
13810 -------------------------
13811 -- Object_Access_Level --
13812 -------------------------
13814 -- Returns the static accessibility level of the view denoted by Obj. Note
13815 -- that the value returned is the result of a call to Scope_Depth. Only
13816 -- scope depths associated with dynamic scopes can actually be returned.
13817 -- Since only relative levels matter for accessibility checking, the fact
13818 -- that the distance between successive levels of accessibility is not
13819 -- always one is immaterial (invariant: if level(E2) is deeper than
13820 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
13822 function Object_Access_Level (Obj : Node_Id) return Uint is
13823 function Is_Interface_Conversion (N : Node_Id) return Boolean;
13824 -- Determine whether N is a construct of the form
13825 -- Some_Type (Operand._tag'Address)
13826 -- This construct appears in the context of dispatching calls.
13828 function Reference_To (Obj : Node_Id) return Node_Id;
13829 -- An explicit dereference is created when removing side-effects from
13830 -- expressions for constraint checking purposes. In this case a local
13831 -- access type is created for it. The correct access level is that of
13832 -- the original source node. We detect this case by noting that the
13833 -- prefix of the dereference is created by an object declaration whose
13834 -- initial expression is a reference.
13836 -----------------------------
13837 -- Is_Interface_Conversion --
13838 -----------------------------
13840 function Is_Interface_Conversion (N : Node_Id) return Boolean is
13841 begin
13842 return
13843 Nkind (N) = N_Unchecked_Type_Conversion
13844 and then Nkind (Expression (N)) = N_Attribute_Reference
13845 and then Attribute_Name (Expression (N)) = Name_Address;
13846 end Is_Interface_Conversion;
13848 ------------------
13849 -- Reference_To --
13850 ------------------
13852 function Reference_To (Obj : Node_Id) return Node_Id is
13853 Pref : constant Node_Id := Prefix (Obj);
13854 begin
13855 if Is_Entity_Name (Pref)
13856 and then Nkind (Parent (Entity (Pref))) = N_Object_Declaration
13857 and then Present (Expression (Parent (Entity (Pref))))
13858 and then Nkind (Expression (Parent (Entity (Pref)))) = N_Reference
13859 then
13860 return (Prefix (Expression (Parent (Entity (Pref)))));
13861 else
13862 return Empty;
13863 end if;
13864 end Reference_To;
13866 -- Local variables
13868 E : Entity_Id;
13870 -- Start of processing for Object_Access_Level
13872 begin
13873 if Nkind (Obj) = N_Defining_Identifier
13874 or else Is_Entity_Name (Obj)
13875 then
13876 if Nkind (Obj) = N_Defining_Identifier then
13877 E := Obj;
13878 else
13879 E := Entity (Obj);
13880 end if;
13882 if Is_Prival (E) then
13883 E := Prival_Link (E);
13884 end if;
13886 -- If E is a type then it denotes a current instance. For this case
13887 -- we add one to the normal accessibility level of the type to ensure
13888 -- that current instances are treated as always being deeper than
13889 -- than the level of any visible named access type (see 3.10.2(21)).
13891 if Is_Type (E) then
13892 return Type_Access_Level (E) + 1;
13894 elsif Present (Renamed_Object (E)) then
13895 return Object_Access_Level (Renamed_Object (E));
13897 -- Similarly, if E is a component of the current instance of a
13898 -- protected type, any instance of it is assumed to be at a deeper
13899 -- level than the type. For a protected object (whose type is an
13900 -- anonymous protected type) its components are at the same level
13901 -- as the type itself.
13903 elsif not Is_Overloadable (E)
13904 and then Ekind (Scope (E)) = E_Protected_Type
13905 and then Comes_From_Source (Scope (E))
13906 then
13907 return Type_Access_Level (Scope (E)) + 1;
13909 else
13910 return Scope_Depth (Enclosing_Dynamic_Scope (E));
13911 end if;
13913 elsif Nkind (Obj) = N_Selected_Component then
13914 if Is_Access_Type (Etype (Prefix (Obj))) then
13915 return Type_Access_Level (Etype (Prefix (Obj)));
13916 else
13917 return Object_Access_Level (Prefix (Obj));
13918 end if;
13920 elsif Nkind (Obj) = N_Indexed_Component then
13921 if Is_Access_Type (Etype (Prefix (Obj))) then
13922 return Type_Access_Level (Etype (Prefix (Obj)));
13923 else
13924 return Object_Access_Level (Prefix (Obj));
13925 end if;
13927 elsif Nkind (Obj) = N_Explicit_Dereference then
13929 -- If the prefix is a selected access discriminant then we make a
13930 -- recursive call on the prefix, which will in turn check the level
13931 -- of the prefix object of the selected discriminant.
13933 if Nkind (Prefix (Obj)) = N_Selected_Component
13934 and then Ekind (Etype (Prefix (Obj))) = E_Anonymous_Access_Type
13935 and then
13936 Ekind (Entity (Selector_Name (Prefix (Obj)))) = E_Discriminant
13937 then
13938 return Object_Access_Level (Prefix (Obj));
13940 -- Detect an interface conversion in the context of a dispatching
13941 -- call. Use the original form of the conversion to find the access
13942 -- level of the operand.
13944 elsif Is_Interface (Etype (Obj))
13945 and then Is_Interface_Conversion (Prefix (Obj))
13946 and then Nkind (Original_Node (Obj)) = N_Type_Conversion
13947 then
13948 return Object_Access_Level (Original_Node (Obj));
13950 elsif not Comes_From_Source (Obj) then
13951 declare
13952 Ref : constant Node_Id := Reference_To (Obj);
13953 begin
13954 if Present (Ref) then
13955 return Object_Access_Level (Ref);
13956 else
13957 return Type_Access_Level (Etype (Prefix (Obj)));
13958 end if;
13959 end;
13961 else
13962 return Type_Access_Level (Etype (Prefix (Obj)));
13963 end if;
13965 elsif Nkind_In (Obj, N_Type_Conversion, N_Unchecked_Type_Conversion) then
13966 return Object_Access_Level (Expression (Obj));
13968 elsif Nkind (Obj) = N_Function_Call then
13970 -- Function results are objects, so we get either the access level of
13971 -- the function or, in the case of an indirect call, the level of the
13972 -- access-to-subprogram type. (This code is used for Ada 95, but it
13973 -- looks wrong, because it seems that we should be checking the level
13974 -- of the call itself, even for Ada 95. However, using the Ada 2005
13975 -- version of the code causes regressions in several tests that are
13976 -- compiled with -gnat95. ???)
13978 if Ada_Version < Ada_2005 then
13979 if Is_Entity_Name (Name (Obj)) then
13980 return Subprogram_Access_Level (Entity (Name (Obj)));
13981 else
13982 return Type_Access_Level (Etype (Prefix (Name (Obj))));
13983 end if;
13985 -- For Ada 2005, the level of the result object of a function call is
13986 -- defined to be the level of the call's innermost enclosing master.
13987 -- We determine that by querying the depth of the innermost enclosing
13988 -- dynamic scope.
13990 else
13991 Return_Master_Scope_Depth_Of_Call : declare
13993 function Innermost_Master_Scope_Depth
13994 (N : Node_Id) return Uint;
13995 -- Returns the scope depth of the given node's innermost
13996 -- enclosing dynamic scope (effectively the accessibility
13997 -- level of the innermost enclosing master).
13999 ----------------------------------
14000 -- Innermost_Master_Scope_Depth --
14001 ----------------------------------
14003 function Innermost_Master_Scope_Depth
14004 (N : Node_Id) return Uint
14006 Node_Par : Node_Id := Parent (N);
14008 begin
14009 -- Locate the nearest enclosing node (by traversing Parents)
14010 -- that Defining_Entity can be applied to, and return the
14011 -- depth of that entity's nearest enclosing dynamic scope.
14013 while Present (Node_Par) loop
14014 case Nkind (Node_Par) is
14015 when N_Component_Declaration |
14016 N_Entry_Declaration |
14017 N_Formal_Object_Declaration |
14018 N_Formal_Type_Declaration |
14019 N_Full_Type_Declaration |
14020 N_Incomplete_Type_Declaration |
14021 N_Loop_Parameter_Specification |
14022 N_Object_Declaration |
14023 N_Protected_Type_Declaration |
14024 N_Private_Extension_Declaration |
14025 N_Private_Type_Declaration |
14026 N_Subtype_Declaration |
14027 N_Function_Specification |
14028 N_Procedure_Specification |
14029 N_Task_Type_Declaration |
14030 N_Body_Stub |
14031 N_Generic_Instantiation |
14032 N_Proper_Body |
14033 N_Implicit_Label_Declaration |
14034 N_Package_Declaration |
14035 N_Single_Task_Declaration |
14036 N_Subprogram_Declaration |
14037 N_Generic_Declaration |
14038 N_Renaming_Declaration |
14039 N_Block_Statement |
14040 N_Formal_Subprogram_Declaration |
14041 N_Abstract_Subprogram_Declaration |
14042 N_Entry_Body |
14043 N_Exception_Declaration |
14044 N_Formal_Package_Declaration |
14045 N_Number_Declaration |
14046 N_Package_Specification |
14047 N_Parameter_Specification |
14048 N_Single_Protected_Declaration |
14049 N_Subunit =>
14051 return Scope_Depth
14052 (Nearest_Dynamic_Scope
14053 (Defining_Entity (Node_Par)));
14055 when others =>
14056 null;
14057 end case;
14059 Node_Par := Parent (Node_Par);
14060 end loop;
14062 pragma Assert (False);
14064 -- Should never reach the following return
14066 return Scope_Depth (Current_Scope) + 1;
14067 end Innermost_Master_Scope_Depth;
14069 -- Start of processing for Return_Master_Scope_Depth_Of_Call
14071 begin
14072 return Innermost_Master_Scope_Depth (Obj);
14073 end Return_Master_Scope_Depth_Of_Call;
14074 end if;
14076 -- For convenience we handle qualified expressions, even though they
14077 -- aren't technically object names.
14079 elsif Nkind (Obj) = N_Qualified_Expression then
14080 return Object_Access_Level (Expression (Obj));
14082 -- Otherwise return the scope level of Standard. (If there are cases
14083 -- that fall through to this point they will be treated as having
14084 -- global accessibility for now. ???)
14086 else
14087 return Scope_Depth (Standard_Standard);
14088 end if;
14089 end Object_Access_Level;
14091 --------------------------
14092 -- Original_Aspect_Name --
14093 --------------------------
14095 function Original_Aspect_Name (N : Node_Id) return Name_Id is
14096 Pras : Node_Id;
14097 Name : Name_Id;
14099 begin
14100 pragma Assert (Nkind_In (N, N_Aspect_Specification, N_Pragma));
14101 Pras := N;
14103 if Is_Rewrite_Substitution (Pras)
14104 and then Nkind (Original_Node (Pras)) = N_Pragma
14105 then
14106 Pras := Original_Node (Pras);
14107 end if;
14109 -- Case where we came from aspect specication
14111 if Nkind (Pras) = N_Pragma and then From_Aspect_Specification (Pras) then
14112 Pras := Corresponding_Aspect (Pras);
14113 end if;
14115 -- Get name from aspect or pragma
14117 if Nkind (Pras) = N_Pragma then
14118 Name := Pragma_Name (Pras);
14119 else
14120 Name := Chars (Identifier (Pras));
14121 end if;
14123 -- Deal with 'Class
14125 if Class_Present (Pras) then
14126 case Name is
14128 -- Names that need converting to special _xxx form
14130 when Name_Pre |
14131 Name_Pre_Class =>
14132 Name := Name_uPre;
14134 when Name_Post |
14135 Name_Post_Class =>
14136 Name := Name_uPost;
14138 when Name_Invariant =>
14139 Name := Name_uInvariant;
14141 when Name_Type_Invariant |
14142 Name_Type_Invariant_Class =>
14143 Name := Name_uType_Invariant;
14145 -- Nothing to do for other cases (e.g. a Check that derived
14146 -- from Pre_Class and has the flag set). Also we do nothing
14147 -- if the name is already in special _xxx form.
14149 when others =>
14150 null;
14151 end case;
14152 end if;
14154 return Name;
14155 end Original_Aspect_Name;
14156 --------------------------------------
14157 -- Original_Corresponding_Operation --
14158 --------------------------------------
14160 function Original_Corresponding_Operation (S : Entity_Id) return Entity_Id
14162 Typ : constant Entity_Id := Find_Dispatching_Type (S);
14164 begin
14165 -- If S is an inherited primitive S2 the original corresponding
14166 -- operation of S is the original corresponding operation of S2
14168 if Present (Alias (S))
14169 and then Find_Dispatching_Type (Alias (S)) /= Typ
14170 then
14171 return Original_Corresponding_Operation (Alias (S));
14173 -- If S overrides an inherited subprogram S2 the original corresponding
14174 -- operation of S is the original corresponding operation of S2
14176 elsif Present (Overridden_Operation (S)) then
14177 return Original_Corresponding_Operation (Overridden_Operation (S));
14179 -- otherwise it is S itself
14181 else
14182 return S;
14183 end if;
14184 end Original_Corresponding_Operation;
14186 -----------------------
14187 -- Private_Component --
14188 -----------------------
14190 function Private_Component (Type_Id : Entity_Id) return Entity_Id is
14191 Ancestor : constant Entity_Id := Base_Type (Type_Id);
14193 function Trace_Components
14194 (T : Entity_Id;
14195 Check : Boolean) return Entity_Id;
14196 -- Recursive function that does the work, and checks against circular
14197 -- definition for each subcomponent type.
14199 ----------------------
14200 -- Trace_Components --
14201 ----------------------
14203 function Trace_Components
14204 (T : Entity_Id;
14205 Check : Boolean) return Entity_Id
14207 Btype : constant Entity_Id := Base_Type (T);
14208 Component : Entity_Id;
14209 P : Entity_Id;
14210 Candidate : Entity_Id := Empty;
14212 begin
14213 if Check and then Btype = Ancestor then
14214 Error_Msg_N ("circular type definition", Type_Id);
14215 return Any_Type;
14216 end if;
14218 if Is_Private_Type (Btype)
14219 and then not Is_Generic_Type (Btype)
14220 then
14221 if Present (Full_View (Btype))
14222 and then Is_Record_Type (Full_View (Btype))
14223 and then not Is_Frozen (Btype)
14224 then
14225 -- To indicate that the ancestor depends on a private type, the
14226 -- current Btype is sufficient. However, to check for circular
14227 -- definition we must recurse on the full view.
14229 Candidate := Trace_Components (Full_View (Btype), True);
14231 if Candidate = Any_Type then
14232 return Any_Type;
14233 else
14234 return Btype;
14235 end if;
14237 else
14238 return Btype;
14239 end if;
14241 elsif Is_Array_Type (Btype) then
14242 return Trace_Components (Component_Type (Btype), True);
14244 elsif Is_Record_Type (Btype) then
14245 Component := First_Entity (Btype);
14246 while Present (Component)
14247 and then Comes_From_Source (Component)
14248 loop
14249 -- Skip anonymous types generated by constrained components
14251 if not Is_Type (Component) then
14252 P := Trace_Components (Etype (Component), True);
14254 if Present (P) then
14255 if P = Any_Type then
14256 return P;
14257 else
14258 Candidate := P;
14259 end if;
14260 end if;
14261 end if;
14263 Next_Entity (Component);
14264 end loop;
14266 return Candidate;
14268 else
14269 return Empty;
14270 end if;
14271 end Trace_Components;
14273 -- Start of processing for Private_Component
14275 begin
14276 return Trace_Components (Type_Id, False);
14277 end Private_Component;
14279 ---------------------------
14280 -- Primitive_Names_Match --
14281 ---------------------------
14283 function Primitive_Names_Match (E1, E2 : Entity_Id) return Boolean is
14285 function Non_Internal_Name (E : Entity_Id) return Name_Id;
14286 -- Given an internal name, returns the corresponding non-internal name
14288 ------------------------
14289 -- Non_Internal_Name --
14290 ------------------------
14292 function Non_Internal_Name (E : Entity_Id) return Name_Id is
14293 begin
14294 Get_Name_String (Chars (E));
14295 Name_Len := Name_Len - 1;
14296 return Name_Find;
14297 end Non_Internal_Name;
14299 -- Start of processing for Primitive_Names_Match
14301 begin
14302 pragma Assert (Present (E1) and then Present (E2));
14304 return Chars (E1) = Chars (E2)
14305 or else
14306 (not Is_Internal_Name (Chars (E1))
14307 and then Is_Internal_Name (Chars (E2))
14308 and then Non_Internal_Name (E2) = Chars (E1))
14309 or else
14310 (not Is_Internal_Name (Chars (E2))
14311 and then Is_Internal_Name (Chars (E1))
14312 and then Non_Internal_Name (E1) = Chars (E2))
14313 or else
14314 (Is_Predefined_Dispatching_Operation (E1)
14315 and then Is_Predefined_Dispatching_Operation (E2)
14316 and then Same_TSS (E1, E2))
14317 or else
14318 (Is_Init_Proc (E1) and then Is_Init_Proc (E2));
14319 end Primitive_Names_Match;
14321 -----------------------
14322 -- Process_End_Label --
14323 -----------------------
14325 procedure Process_End_Label
14326 (N : Node_Id;
14327 Typ : Character;
14328 Ent : Entity_Id)
14330 Loc : Source_Ptr;
14331 Nam : Node_Id;
14332 Scop : Entity_Id;
14334 Label_Ref : Boolean;
14335 -- Set True if reference to end label itself is required
14337 Endl : Node_Id;
14338 -- Gets set to the operator symbol or identifier that references the
14339 -- entity Ent. For the child unit case, this is the identifier from the
14340 -- designator. For other cases, this is simply Endl.
14342 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id);
14343 -- N is an identifier node that appears as a parent unit reference in
14344 -- the case where Ent is a child unit. This procedure generates an
14345 -- appropriate cross-reference entry. E is the corresponding entity.
14347 -------------------------
14348 -- Generate_Parent_Ref --
14349 -------------------------
14351 procedure Generate_Parent_Ref (N : Node_Id; E : Entity_Id) is
14352 begin
14353 -- If names do not match, something weird, skip reference
14355 if Chars (E) = Chars (N) then
14357 -- Generate the reference. We do NOT consider this as a reference
14358 -- for unreferenced symbol purposes.
14360 Generate_Reference (E, N, 'r', Set_Ref => False, Force => True);
14362 if Style_Check then
14363 Style.Check_Identifier (N, E);
14364 end if;
14365 end if;
14366 end Generate_Parent_Ref;
14368 -- Start of processing for Process_End_Label
14370 begin
14371 -- If no node, ignore. This happens in some error situations, and
14372 -- also for some internally generated structures where no end label
14373 -- references are required in any case.
14375 if No (N) then
14376 return;
14377 end if;
14379 -- Nothing to do if no End_Label, happens for internally generated
14380 -- constructs where we don't want an end label reference anyway. Also
14381 -- nothing to do if Endl is a string literal, which means there was
14382 -- some prior error (bad operator symbol)
14384 Endl := End_Label (N);
14386 if No (Endl) or else Nkind (Endl) = N_String_Literal then
14387 return;
14388 end if;
14390 -- Reference node is not in extended main source unit
14392 if not In_Extended_Main_Source_Unit (N) then
14394 -- Generally we do not collect references except for the extended
14395 -- main source unit. The one exception is the 'e' entry for a
14396 -- package spec, where it is useful for a client to have the
14397 -- ending information to define scopes.
14399 if Typ /= 'e' then
14400 return;
14402 else
14403 Label_Ref := False;
14405 -- For this case, we can ignore any parent references, but we
14406 -- need the package name itself for the 'e' entry.
14408 if Nkind (Endl) = N_Designator then
14409 Endl := Identifier (Endl);
14410 end if;
14411 end if;
14413 -- Reference is in extended main source unit
14415 else
14416 Label_Ref := True;
14418 -- For designator, generate references for the parent entries
14420 if Nkind (Endl) = N_Designator then
14422 -- Generate references for the prefix if the END line comes from
14423 -- source (otherwise we do not need these references) We climb the
14424 -- scope stack to find the expected entities.
14426 if Comes_From_Source (Endl) then
14427 Nam := Name (Endl);
14428 Scop := Current_Scope;
14429 while Nkind (Nam) = N_Selected_Component loop
14430 Scop := Scope (Scop);
14431 exit when No (Scop);
14432 Generate_Parent_Ref (Selector_Name (Nam), Scop);
14433 Nam := Prefix (Nam);
14434 end loop;
14436 if Present (Scop) then
14437 Generate_Parent_Ref (Nam, Scope (Scop));
14438 end if;
14439 end if;
14441 Endl := Identifier (Endl);
14442 end if;
14443 end if;
14445 -- If the end label is not for the given entity, then either we have
14446 -- some previous error, or this is a generic instantiation for which
14447 -- we do not need to make a cross-reference in this case anyway. In
14448 -- either case we simply ignore the call.
14450 if Chars (Ent) /= Chars (Endl) then
14451 return;
14452 end if;
14454 -- If label was really there, then generate a normal reference and then
14455 -- adjust the location in the end label to point past the name (which
14456 -- should almost always be the semicolon).
14458 Loc := Sloc (Endl);
14460 if Comes_From_Source (Endl) then
14462 -- If a label reference is required, then do the style check and
14463 -- generate an l-type cross-reference entry for the label
14465 if Label_Ref then
14466 if Style_Check then
14467 Style.Check_Identifier (Endl, Ent);
14468 end if;
14470 Generate_Reference (Ent, Endl, 'l', Set_Ref => False);
14471 end if;
14473 -- Set the location to point past the label (normally this will
14474 -- mean the semicolon immediately following the label). This is
14475 -- done for the sake of the 'e' or 't' entry generated below.
14477 Get_Decoded_Name_String (Chars (Endl));
14478 Set_Sloc (Endl, Sloc (Endl) + Source_Ptr (Name_Len));
14480 else
14481 -- In SPARK mode, no missing label is allowed for packages and
14482 -- subprogram bodies. Detect those cases by testing whether
14483 -- Process_End_Label was called for a body (Typ = 't') or a package.
14485 if Restriction_Check_Required (SPARK_05)
14486 and then (Typ = 't' or else Ekind (Ent) = E_Package)
14487 then
14488 Error_Msg_Node_1 := Endl;
14489 Check_SPARK_Restriction ("`END &` required", Endl, Force => True);
14490 end if;
14491 end if;
14493 -- Now generate the e/t reference
14495 Generate_Reference (Ent, Endl, Typ, Set_Ref => False, Force => True);
14497 -- Restore Sloc, in case modified above, since we have an identifier
14498 -- and the normal Sloc should be left set in the tree.
14500 Set_Sloc (Endl, Loc);
14501 end Process_End_Label;
14503 ----------------
14504 -- Referenced --
14505 ----------------
14507 function Referenced (Id : Entity_Id; Expr : Node_Id) return Boolean is
14508 Seen : Boolean := False;
14510 function Is_Reference (N : Node_Id) return Traverse_Result;
14511 -- Determine whether node N denotes a reference to Id. If this is the
14512 -- case, set global flag Seen to True and stop the traversal.
14514 ------------------
14515 -- Is_Reference --
14516 ------------------
14518 function Is_Reference (N : Node_Id) return Traverse_Result is
14519 begin
14520 if Is_Entity_Name (N)
14521 and then Present (Entity (N))
14522 and then Entity (N) = Id
14523 then
14524 Seen := True;
14525 return Abandon;
14526 else
14527 return OK;
14528 end if;
14529 end Is_Reference;
14531 procedure Inspect_Expression is new Traverse_Proc (Is_Reference);
14533 -- Start of processing for Referenced
14535 begin
14536 Inspect_Expression (Expr);
14537 return Seen;
14538 end Referenced;
14540 ------------------------------------
14541 -- References_Generic_Formal_Type --
14542 ------------------------------------
14544 function References_Generic_Formal_Type (N : Node_Id) return Boolean is
14546 function Process (N : Node_Id) return Traverse_Result;
14547 -- Process one node in search for generic formal type
14549 -------------
14550 -- Process --
14551 -------------
14553 function Process (N : Node_Id) return Traverse_Result is
14554 begin
14555 if Nkind (N) in N_Has_Entity then
14556 declare
14557 E : constant Entity_Id := Entity (N);
14558 begin
14559 if Present (E) then
14560 if Is_Generic_Type (E) then
14561 return Abandon;
14562 elsif Present (Etype (E))
14563 and then Is_Generic_Type (Etype (E))
14564 then
14565 return Abandon;
14566 end if;
14567 end if;
14568 end;
14569 end if;
14571 return Atree.OK;
14572 end Process;
14574 function Traverse is new Traverse_Func (Process);
14575 -- Traverse tree to look for generic type
14577 begin
14578 if Inside_A_Generic then
14579 return Traverse (N) = Abandon;
14580 else
14581 return False;
14582 end if;
14583 end References_Generic_Formal_Type;
14585 --------------------
14586 -- Remove_Homonym --
14587 --------------------
14589 procedure Remove_Homonym (E : Entity_Id) is
14590 Prev : Entity_Id := Empty;
14591 H : Entity_Id;
14593 begin
14594 if E = Current_Entity (E) then
14595 if Present (Homonym (E)) then
14596 Set_Current_Entity (Homonym (E));
14597 else
14598 Set_Name_Entity_Id (Chars (E), Empty);
14599 end if;
14601 else
14602 H := Current_Entity (E);
14603 while Present (H) and then H /= E loop
14604 Prev := H;
14605 H := Homonym (H);
14606 end loop;
14608 -- If E is not on the homonym chain, nothing to do
14610 if Present (H) then
14611 Set_Homonym (Prev, Homonym (E));
14612 end if;
14613 end if;
14614 end Remove_Homonym;
14616 ---------------------
14617 -- Rep_To_Pos_Flag --
14618 ---------------------
14620 function Rep_To_Pos_Flag (E : Entity_Id; Loc : Source_Ptr) return Node_Id is
14621 begin
14622 return New_Occurrence_Of
14623 (Boolean_Literals (not Range_Checks_Suppressed (E)), Loc);
14624 end Rep_To_Pos_Flag;
14626 --------------------
14627 -- Require_Entity --
14628 --------------------
14630 procedure Require_Entity (N : Node_Id) is
14631 begin
14632 if Is_Entity_Name (N) and then No (Entity (N)) then
14633 if Total_Errors_Detected /= 0 then
14634 Set_Entity (N, Any_Id);
14635 else
14636 raise Program_Error;
14637 end if;
14638 end if;
14639 end Require_Entity;
14641 -------------------------------
14642 -- Requires_State_Refinement --
14643 -------------------------------
14645 function Requires_State_Refinement
14646 (Spec_Id : Entity_Id;
14647 Body_Id : Entity_Id) return Boolean
14649 function Mode_Is_Off (Prag : Node_Id) return Boolean;
14650 -- Given pragma SPARK_Mode, determine whether the mode is Off
14652 -----------------
14653 -- Mode_Is_Off --
14654 -----------------
14656 function Mode_Is_Off (Prag : Node_Id) return Boolean is
14657 Mode : Node_Id;
14659 begin
14660 -- The default SPARK mode is On
14662 if No (Prag) then
14663 return False;
14664 end if;
14666 Mode := Get_Pragma_Arg (First (Pragma_Argument_Associations (Prag)));
14668 -- Then the pragma lacks an argument, the default mode is On
14670 if No (Mode) then
14671 return False;
14672 else
14673 return Chars (Mode) = Name_Off;
14674 end if;
14675 end Mode_Is_Off;
14677 -- Start of processing for Requires_State_Refinement
14679 begin
14680 -- A package that does not define at least one abstract state cannot
14681 -- possibly require refinement.
14683 if No (Abstract_States (Spec_Id)) then
14684 return False;
14686 -- The package instroduces a single null state which does not merit
14687 -- refinement.
14689 elsif Has_Null_Abstract_State (Spec_Id) then
14690 return False;
14692 -- Check whether the package body is subject to pragma SPARK_Mode. If
14693 -- it is and the mode is Off, the package body is considered to be in
14694 -- regular Ada and does not require refinement.
14696 elsif Mode_Is_Off (SPARK_Pragma (Body_Id)) then
14697 return False;
14699 -- The body's SPARK_Mode may be inherited from a similar pragma that
14700 -- appears in the private declarations of the spec. The pragma we are
14701 -- interested appears as the second entry in SPARK_Pragma.
14703 elsif Present (SPARK_Pragma (Spec_Id))
14704 and then Mode_Is_Off (Next_Pragma (SPARK_Pragma (Spec_Id)))
14705 then
14706 return False;
14708 -- The spec defines at least one abstract state and the body has no way
14709 -- of circumventing the refinement.
14711 else
14712 return True;
14713 end if;
14714 end Requires_State_Refinement;
14716 ------------------------------
14717 -- Requires_Transient_Scope --
14718 ------------------------------
14720 -- A transient scope is required when variable-sized temporaries are
14721 -- allocated in the primary or secondary stack, or when finalization
14722 -- actions must be generated before the next instruction.
14724 function Requires_Transient_Scope (Id : Entity_Id) return Boolean is
14725 Typ : constant Entity_Id := Underlying_Type (Id);
14727 -- Start of processing for Requires_Transient_Scope
14729 begin
14730 -- This is a private type which is not completed yet. This can only
14731 -- happen in a default expression (of a formal parameter or of a
14732 -- record component). Do not expand transient scope in this case
14734 if No (Typ) then
14735 return False;
14737 -- Do not expand transient scope for non-existent procedure return
14739 elsif Typ = Standard_Void_Type then
14740 return False;
14742 -- Elementary types do not require a transient scope
14744 elsif Is_Elementary_Type (Typ) then
14745 return False;
14747 -- Generally, indefinite subtypes require a transient scope, since the
14748 -- back end cannot generate temporaries, since this is not a valid type
14749 -- for declaring an object. It might be possible to relax this in the
14750 -- future, e.g. by declaring the maximum possible space for the type.
14752 elsif Is_Indefinite_Subtype (Typ) then
14753 return True;
14755 -- Functions returning tagged types may dispatch on result so their
14756 -- returned value is allocated on the secondary stack. Controlled
14757 -- type temporaries need finalization.
14759 elsif Is_Tagged_Type (Typ)
14760 or else Has_Controlled_Component (Typ)
14761 then
14762 return not Is_Value_Type (Typ);
14764 -- Record type
14766 elsif Is_Record_Type (Typ) then
14767 declare
14768 Comp : Entity_Id;
14769 begin
14770 Comp := First_Entity (Typ);
14771 while Present (Comp) loop
14772 if Ekind (Comp) = E_Component
14773 and then Requires_Transient_Scope (Etype (Comp))
14774 then
14775 return True;
14776 else
14777 Next_Entity (Comp);
14778 end if;
14779 end loop;
14780 end;
14782 return False;
14784 -- String literal types never require transient scope
14786 elsif Ekind (Typ) = E_String_Literal_Subtype then
14787 return False;
14789 -- Array type. Note that we already know that this is a constrained
14790 -- array, since unconstrained arrays will fail the indefinite test.
14792 elsif Is_Array_Type (Typ) then
14794 -- If component type requires a transient scope, the array does too
14796 if Requires_Transient_Scope (Component_Type (Typ)) then
14797 return True;
14799 -- Otherwise, we only need a transient scope if the size depends on
14800 -- the value of one or more discriminants.
14802 else
14803 return Size_Depends_On_Discriminant (Typ);
14804 end if;
14806 -- All other cases do not require a transient scope
14808 else
14809 return False;
14810 end if;
14811 end Requires_Transient_Scope;
14813 --------------------------
14814 -- Reset_Analyzed_Flags --
14815 --------------------------
14817 procedure Reset_Analyzed_Flags (N : Node_Id) is
14819 function Clear_Analyzed (N : Node_Id) return Traverse_Result;
14820 -- Function used to reset Analyzed flags in tree. Note that we do
14821 -- not reset Analyzed flags in entities, since there is no need to
14822 -- reanalyze entities, and indeed, it is wrong to do so, since it
14823 -- can result in generating auxiliary stuff more than once.
14825 --------------------
14826 -- Clear_Analyzed --
14827 --------------------
14829 function Clear_Analyzed (N : Node_Id) return Traverse_Result is
14830 begin
14831 if not Has_Extension (N) then
14832 Set_Analyzed (N, False);
14833 end if;
14835 return OK;
14836 end Clear_Analyzed;
14838 procedure Reset_Analyzed is new Traverse_Proc (Clear_Analyzed);
14840 -- Start of processing for Reset_Analyzed_Flags
14842 begin
14843 Reset_Analyzed (N);
14844 end Reset_Analyzed_Flags;
14846 --------------------------------
14847 -- Returns_Unconstrained_Type --
14848 --------------------------------
14850 function Returns_Unconstrained_Type (Subp : Entity_Id) return Boolean is
14851 begin
14852 return Ekind (Subp) = E_Function
14853 and then not Is_Scalar_Type (Etype (Subp))
14854 and then not Is_Access_Type (Etype (Subp))
14855 and then not Is_Constrained (Etype (Subp));
14856 end Returns_Unconstrained_Type;
14858 ---------------------------
14859 -- Safe_To_Capture_Value --
14860 ---------------------------
14862 function Safe_To_Capture_Value
14863 (N : Node_Id;
14864 Ent : Entity_Id;
14865 Cond : Boolean := False) return Boolean
14867 begin
14868 -- The only entities for which we track constant values are variables
14869 -- which are not renamings, constants, out parameters, and in out
14870 -- parameters, so check if we have this case.
14872 -- Note: it may seem odd to track constant values for constants, but in
14873 -- fact this routine is used for other purposes than simply capturing
14874 -- the value. In particular, the setting of Known[_Non]_Null.
14876 if (Ekind (Ent) = E_Variable and then No (Renamed_Object (Ent)))
14877 or else
14878 Ekind (Ent) = E_Constant
14879 or else
14880 Ekind (Ent) = E_Out_Parameter
14881 or else
14882 Ekind (Ent) = E_In_Out_Parameter
14883 then
14884 null;
14886 -- For conditionals, we also allow loop parameters and all formals,
14887 -- including in parameters.
14889 elsif Cond
14890 and then
14891 (Ekind (Ent) = E_Loop_Parameter
14892 or else
14893 Ekind (Ent) = E_In_Parameter)
14894 then
14895 null;
14897 -- For all other cases, not just unsafe, but impossible to capture
14898 -- Current_Value, since the above are the only entities which have
14899 -- Current_Value fields.
14901 else
14902 return False;
14903 end if;
14905 -- Skip if volatile or aliased, since funny things might be going on in
14906 -- these cases which we cannot necessarily track. Also skip any variable
14907 -- for which an address clause is given, or whose address is taken. Also
14908 -- never capture value of library level variables (an attempt to do so
14909 -- can occur in the case of package elaboration code).
14911 if Treat_As_Volatile (Ent)
14912 or else Is_Aliased (Ent)
14913 or else Present (Address_Clause (Ent))
14914 or else Address_Taken (Ent)
14915 or else (Is_Library_Level_Entity (Ent)
14916 and then Ekind (Ent) = E_Variable)
14917 then
14918 return False;
14919 end if;
14921 -- OK, all above conditions are met. We also require that the scope of
14922 -- the reference be the same as the scope of the entity, not counting
14923 -- packages and blocks and loops.
14925 declare
14926 E_Scope : constant Entity_Id := Scope (Ent);
14927 R_Scope : Entity_Id;
14929 begin
14930 R_Scope := Current_Scope;
14931 while R_Scope /= Standard_Standard loop
14932 exit when R_Scope = E_Scope;
14934 if not Ekind_In (R_Scope, E_Package, E_Block, E_Loop) then
14935 return False;
14936 else
14937 R_Scope := Scope (R_Scope);
14938 end if;
14939 end loop;
14940 end;
14942 -- We also require that the reference does not appear in a context
14943 -- where it is not sure to be executed (i.e. a conditional context
14944 -- or an exception handler). We skip this if Cond is True, since the
14945 -- capturing of values from conditional tests handles this ok.
14947 if Cond then
14948 return True;
14949 end if;
14951 declare
14952 Desc : Node_Id;
14953 P : Node_Id;
14955 begin
14956 Desc := N;
14958 -- Seems dubious that case expressions are not handled here ???
14960 P := Parent (N);
14961 while Present (P) loop
14962 if Nkind (P) = N_If_Statement
14963 or else Nkind (P) = N_Case_Statement
14964 or else (Nkind (P) in N_Short_Circuit
14965 and then Desc = Right_Opnd (P))
14966 or else (Nkind (P) = N_If_Expression
14967 and then Desc /= First (Expressions (P)))
14968 or else Nkind (P) = N_Exception_Handler
14969 or else Nkind (P) = N_Selective_Accept
14970 or else Nkind (P) = N_Conditional_Entry_Call
14971 or else Nkind (P) = N_Timed_Entry_Call
14972 or else Nkind (P) = N_Asynchronous_Select
14973 then
14974 return False;
14975 else
14976 Desc := P;
14977 P := Parent (P);
14979 -- A special Ada 2012 case: the original node may be part
14980 -- of the else_actions of a conditional expression, in which
14981 -- case it might not have been expanded yet, and appears in
14982 -- a non-syntactic list of actions. In that case it is clearly
14983 -- not safe to save a value.
14985 if No (P)
14986 and then Is_List_Member (Desc)
14987 and then No (Parent (List_Containing (Desc)))
14988 then
14989 return False;
14990 end if;
14991 end if;
14992 end loop;
14993 end;
14995 -- OK, looks safe to set value
14997 return True;
14998 end Safe_To_Capture_Value;
15000 ---------------
15001 -- Same_Name --
15002 ---------------
15004 function Same_Name (N1, N2 : Node_Id) return Boolean is
15005 K1 : constant Node_Kind := Nkind (N1);
15006 K2 : constant Node_Kind := Nkind (N2);
15008 begin
15009 if (K1 = N_Identifier or else K1 = N_Defining_Identifier)
15010 and then (K2 = N_Identifier or else K2 = N_Defining_Identifier)
15011 then
15012 return Chars (N1) = Chars (N2);
15014 elsif (K1 = N_Selected_Component or else K1 = N_Expanded_Name)
15015 and then (K2 = N_Selected_Component or else K2 = N_Expanded_Name)
15016 then
15017 return Same_Name (Selector_Name (N1), Selector_Name (N2))
15018 and then Same_Name (Prefix (N1), Prefix (N2));
15020 else
15021 return False;
15022 end if;
15023 end Same_Name;
15025 -----------------
15026 -- Same_Object --
15027 -----------------
15029 function Same_Object (Node1, Node2 : Node_Id) return Boolean is
15030 N1 : constant Node_Id := Original_Node (Node1);
15031 N2 : constant Node_Id := Original_Node (Node2);
15032 -- We do the tests on original nodes, since we are most interested
15033 -- in the original source, not any expansion that got in the way.
15035 K1 : constant Node_Kind := Nkind (N1);
15036 K2 : constant Node_Kind := Nkind (N2);
15038 begin
15039 -- First case, both are entities with same entity
15041 if K1 in N_Has_Entity and then K2 in N_Has_Entity then
15042 declare
15043 EN1 : constant Entity_Id := Entity (N1);
15044 EN2 : constant Entity_Id := Entity (N2);
15045 begin
15046 if Present (EN1) and then Present (EN2)
15047 and then (Ekind_In (EN1, E_Variable, E_Constant)
15048 or else Is_Formal (EN1))
15049 and then EN1 = EN2
15050 then
15051 return True;
15052 end if;
15053 end;
15054 end if;
15056 -- Second case, selected component with same selector, same record
15058 if K1 = N_Selected_Component
15059 and then K2 = N_Selected_Component
15060 and then Chars (Selector_Name (N1)) = Chars (Selector_Name (N2))
15061 then
15062 return Same_Object (Prefix (N1), Prefix (N2));
15064 -- Third case, indexed component with same subscripts, same array
15066 elsif K1 = N_Indexed_Component
15067 and then K2 = N_Indexed_Component
15068 and then Same_Object (Prefix (N1), Prefix (N2))
15069 then
15070 declare
15071 E1, E2 : Node_Id;
15072 begin
15073 E1 := First (Expressions (N1));
15074 E2 := First (Expressions (N2));
15075 while Present (E1) loop
15076 if not Same_Value (E1, E2) then
15077 return False;
15078 else
15079 Next (E1);
15080 Next (E2);
15081 end if;
15082 end loop;
15084 return True;
15085 end;
15087 -- Fourth case, slice of same array with same bounds
15089 elsif K1 = N_Slice
15090 and then K2 = N_Slice
15091 and then Nkind (Discrete_Range (N1)) = N_Range
15092 and then Nkind (Discrete_Range (N2)) = N_Range
15093 and then Same_Value (Low_Bound (Discrete_Range (N1)),
15094 Low_Bound (Discrete_Range (N2)))
15095 and then Same_Value (High_Bound (Discrete_Range (N1)),
15096 High_Bound (Discrete_Range (N2)))
15097 then
15098 return Same_Name (Prefix (N1), Prefix (N2));
15100 -- All other cases, not clearly the same object
15102 else
15103 return False;
15104 end if;
15105 end Same_Object;
15107 ---------------
15108 -- Same_Type --
15109 ---------------
15111 function Same_Type (T1, T2 : Entity_Id) return Boolean is
15112 begin
15113 if T1 = T2 then
15114 return True;
15116 elsif not Is_Constrained (T1)
15117 and then not Is_Constrained (T2)
15118 and then Base_Type (T1) = Base_Type (T2)
15119 then
15120 return True;
15122 -- For now don't bother with case of identical constraints, to be
15123 -- fiddled with later on perhaps (this is only used for optimization
15124 -- purposes, so it is not critical to do a best possible job)
15126 else
15127 return False;
15128 end if;
15129 end Same_Type;
15131 ----------------
15132 -- Same_Value --
15133 ----------------
15135 function Same_Value (Node1, Node2 : Node_Id) return Boolean is
15136 begin
15137 if Compile_Time_Known_Value (Node1)
15138 and then Compile_Time_Known_Value (Node2)
15139 and then Expr_Value (Node1) = Expr_Value (Node2)
15140 then
15141 return True;
15142 elsif Same_Object (Node1, Node2) then
15143 return True;
15144 else
15145 return False;
15146 end if;
15147 end Same_Value;
15149 ------------------------
15150 -- Scope_Is_Transient --
15151 ------------------------
15153 function Scope_Is_Transient return Boolean is
15154 begin
15155 return Scope_Stack.Table (Scope_Stack.Last).Is_Transient;
15156 end Scope_Is_Transient;
15158 ------------------
15159 -- Scope_Within --
15160 ------------------
15162 function Scope_Within (Scope1, Scope2 : Entity_Id) return Boolean is
15163 Scop : Entity_Id;
15165 begin
15166 Scop := Scope1;
15167 while Scop /= Standard_Standard loop
15168 Scop := Scope (Scop);
15170 if Scop = Scope2 then
15171 return True;
15172 end if;
15173 end loop;
15175 return False;
15176 end Scope_Within;
15178 --------------------------
15179 -- Scope_Within_Or_Same --
15180 --------------------------
15182 function Scope_Within_Or_Same (Scope1, Scope2 : Entity_Id) return Boolean is
15183 Scop : Entity_Id;
15185 begin
15186 Scop := Scope1;
15187 while Scop /= Standard_Standard loop
15188 if Scop = Scope2 then
15189 return True;
15190 else
15191 Scop := Scope (Scop);
15192 end if;
15193 end loop;
15195 return False;
15196 end Scope_Within_Or_Same;
15198 --------------------
15199 -- Set_Convention --
15200 --------------------
15202 procedure Set_Convention (E : Entity_Id; Val : Snames.Convention_Id) is
15203 begin
15204 Basic_Set_Convention (E, Val);
15206 if Is_Type (E)
15207 and then Is_Access_Subprogram_Type (Base_Type (E))
15208 and then Has_Foreign_Convention (E)
15209 then
15210 Set_Can_Use_Internal_Rep (E, False);
15211 end if;
15212 end Set_Convention;
15214 ------------------------
15215 -- Set_Current_Entity --
15216 ------------------------
15218 -- The given entity is to be set as the currently visible definition of its
15219 -- associated name (i.e. the Node_Id associated with its name). All we have
15220 -- to do is to get the name from the identifier, and then set the
15221 -- associated Node_Id to point to the given entity.
15223 procedure Set_Current_Entity (E : Entity_Id) is
15224 begin
15225 Set_Name_Entity_Id (Chars (E), E);
15226 end Set_Current_Entity;
15228 ---------------------------
15229 -- Set_Debug_Info_Needed --
15230 ---------------------------
15232 procedure Set_Debug_Info_Needed (T : Entity_Id) is
15234 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id);
15235 pragma Inline (Set_Debug_Info_Needed_If_Not_Set);
15236 -- Used to set debug info in a related node if not set already
15238 --------------------------------------
15239 -- Set_Debug_Info_Needed_If_Not_Set --
15240 --------------------------------------
15242 procedure Set_Debug_Info_Needed_If_Not_Set (E : Entity_Id) is
15243 begin
15244 if Present (E)
15245 and then not Needs_Debug_Info (E)
15246 then
15247 Set_Debug_Info_Needed (E);
15249 -- For a private type, indicate that the full view also needs
15250 -- debug information.
15252 if Is_Type (E)
15253 and then Is_Private_Type (E)
15254 and then Present (Full_View (E))
15255 then
15256 Set_Debug_Info_Needed (Full_View (E));
15257 end if;
15258 end if;
15259 end Set_Debug_Info_Needed_If_Not_Set;
15261 -- Start of processing for Set_Debug_Info_Needed
15263 begin
15264 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
15265 -- indicates that Debug_Info_Needed is never required for the entity.
15267 if No (T)
15268 or else Debug_Info_Off (T)
15269 then
15270 return;
15271 end if;
15273 -- Set flag in entity itself. Note that we will go through the following
15274 -- circuitry even if the flag is already set on T. That's intentional,
15275 -- it makes sure that the flag will be set in subsidiary entities.
15277 Set_Needs_Debug_Info (T);
15279 -- Set flag on subsidiary entities if not set already
15281 if Is_Object (T) then
15282 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
15284 elsif Is_Type (T) then
15285 Set_Debug_Info_Needed_If_Not_Set (Etype (T));
15287 if Is_Record_Type (T) then
15288 declare
15289 Ent : Entity_Id := First_Entity (T);
15290 begin
15291 while Present (Ent) loop
15292 Set_Debug_Info_Needed_If_Not_Set (Ent);
15293 Next_Entity (Ent);
15294 end loop;
15295 end;
15297 -- For a class wide subtype, we also need debug information
15298 -- for the equivalent type.
15300 if Ekind (T) = E_Class_Wide_Subtype then
15301 Set_Debug_Info_Needed_If_Not_Set (Equivalent_Type (T));
15302 end if;
15304 elsif Is_Array_Type (T) then
15305 Set_Debug_Info_Needed_If_Not_Set (Component_Type (T));
15307 declare
15308 Indx : Node_Id := First_Index (T);
15309 begin
15310 while Present (Indx) loop
15311 Set_Debug_Info_Needed_If_Not_Set (Etype (Indx));
15312 Indx := Next_Index (Indx);
15313 end loop;
15314 end;
15316 -- For a packed array type, we also need debug information for
15317 -- the type used to represent the packed array. Conversely, we
15318 -- also need it for the former if we need it for the latter.
15320 if Is_Packed (T) then
15321 Set_Debug_Info_Needed_If_Not_Set (Packed_Array_Type (T));
15322 end if;
15324 if Is_Packed_Array_Type (T) then
15325 Set_Debug_Info_Needed_If_Not_Set (Original_Array_Type (T));
15326 end if;
15328 elsif Is_Access_Type (T) then
15329 Set_Debug_Info_Needed_If_Not_Set (Directly_Designated_Type (T));
15331 elsif Is_Private_Type (T) then
15332 Set_Debug_Info_Needed_If_Not_Set (Full_View (T));
15334 elsif Is_Protected_Type (T) then
15335 Set_Debug_Info_Needed_If_Not_Set (Corresponding_Record_Type (T));
15336 end if;
15337 end if;
15338 end Set_Debug_Info_Needed;
15340 ---------------------------------
15341 -- Set_Entity_With_Style_Check --
15342 ---------------------------------
15344 procedure Set_Entity_With_Style_Check (N : Node_Id; Val : Entity_Id) is
15345 Val_Actual : Entity_Id;
15346 Nod : Node_Id;
15348 begin
15349 -- Unconditionally set the entity
15351 Set_Entity (N, Val);
15353 -- Check for No_Implementation_Identifiers
15355 if Restriction_Check_Required (No_Implementation_Identifiers) then
15357 -- We have an implementation defined entity if it is marked as
15358 -- implementation defined, or is defined in a package marked as
15359 -- implementation defined. However, library packages themselves
15360 -- are excluded (we don't want to flag Interfaces itself, just
15361 -- the entities within it).
15363 if (Is_Implementation_Defined (Val)
15364 or else
15365 Is_Implementation_Defined (Scope (Val)))
15366 and then not (Ekind_In (Val, E_Package, E_Generic_Package)
15367 and then Is_Library_Level_Entity (Val))
15368 then
15369 Check_Restriction (No_Implementation_Identifiers, N);
15370 end if;
15371 end if;
15373 -- Do the style check
15375 if Style_Check
15376 and then not Suppress_Style_Checks (Val)
15377 and then not In_Instance
15378 then
15379 if Nkind (N) = N_Identifier then
15380 Nod := N;
15381 elsif Nkind (N) = N_Expanded_Name then
15382 Nod := Selector_Name (N);
15383 else
15384 return;
15385 end if;
15387 -- A special situation arises for derived operations, where we want
15388 -- to do the check against the parent (since the Sloc of the derived
15389 -- operation points to the derived type declaration itself).
15391 Val_Actual := Val;
15392 while not Comes_From_Source (Val_Actual)
15393 and then Nkind (Val_Actual) in N_Entity
15394 and then (Ekind (Val_Actual) = E_Enumeration_Literal
15395 or else Is_Subprogram (Val_Actual)
15396 or else Is_Generic_Subprogram (Val_Actual))
15397 and then Present (Alias (Val_Actual))
15398 loop
15399 Val_Actual := Alias (Val_Actual);
15400 end loop;
15402 -- Renaming declarations for generic actuals do not come from source,
15403 -- and have a different name from that of the entity they rename, so
15404 -- there is no style check to perform here.
15406 if Chars (Nod) = Chars (Val_Actual) then
15407 Style.Check_Identifier (Nod, Val_Actual);
15408 end if;
15409 end if;
15411 Set_Entity (N, Val);
15412 end Set_Entity_With_Style_Check;
15414 ------------------------
15415 -- Set_Name_Entity_Id --
15416 ------------------------
15418 procedure Set_Name_Entity_Id (Id : Name_Id; Val : Entity_Id) is
15419 begin
15420 Set_Name_Table_Info (Id, Int (Val));
15421 end Set_Name_Entity_Id;
15423 ---------------------
15424 -- Set_Next_Actual --
15425 ---------------------
15427 procedure Set_Next_Actual (Ass1_Id : Node_Id; Ass2_Id : Node_Id) is
15428 begin
15429 if Nkind (Parent (Ass1_Id)) = N_Parameter_Association then
15430 Set_First_Named_Actual (Parent (Ass1_Id), Ass2_Id);
15431 end if;
15432 end Set_Next_Actual;
15434 ----------------------------------
15435 -- Set_Optimize_Alignment_Flags --
15436 ----------------------------------
15438 procedure Set_Optimize_Alignment_Flags (E : Entity_Id) is
15439 begin
15440 if Optimize_Alignment = 'S' then
15441 Set_Optimize_Alignment_Space (E);
15442 elsif Optimize_Alignment = 'T' then
15443 Set_Optimize_Alignment_Time (E);
15444 end if;
15445 end Set_Optimize_Alignment_Flags;
15447 -----------------------
15448 -- Set_Public_Status --
15449 -----------------------
15451 procedure Set_Public_Status (Id : Entity_Id) is
15452 S : constant Entity_Id := Current_Scope;
15454 function Within_HSS_Or_If (E : Entity_Id) return Boolean;
15455 -- Determines if E is defined within handled statement sequence or
15456 -- an if statement, returns True if so, False otherwise.
15458 ----------------------
15459 -- Within_HSS_Or_If --
15460 ----------------------
15462 function Within_HSS_Or_If (E : Entity_Id) return Boolean is
15463 N : Node_Id;
15464 begin
15465 N := Declaration_Node (E);
15466 loop
15467 N := Parent (N);
15469 if No (N) then
15470 return False;
15472 elsif Nkind_In (N, N_Handled_Sequence_Of_Statements,
15473 N_If_Statement)
15474 then
15475 return True;
15476 end if;
15477 end loop;
15478 end Within_HSS_Or_If;
15480 -- Start of processing for Set_Public_Status
15482 begin
15483 -- Everything in the scope of Standard is public
15485 if S = Standard_Standard then
15486 Set_Is_Public (Id);
15488 -- Entity is definitely not public if enclosing scope is not public
15490 elsif not Is_Public (S) then
15491 return;
15493 -- An object or function declaration that occurs in a handled sequence
15494 -- of statements or within an if statement is the declaration for a
15495 -- temporary object or local subprogram generated by the expander. It
15496 -- never needs to be made public and furthermore, making it public can
15497 -- cause back end problems.
15499 elsif Nkind_In (Parent (Id), N_Object_Declaration,
15500 N_Function_Specification)
15501 and then Within_HSS_Or_If (Id)
15502 then
15503 return;
15505 -- Entities in public packages or records are public
15507 elsif Ekind (S) = E_Package or Is_Record_Type (S) then
15508 Set_Is_Public (Id);
15510 -- The bounds of an entry family declaration can generate object
15511 -- declarations that are visible to the back-end, e.g. in the
15512 -- the declaration of a composite type that contains tasks.
15514 elsif Is_Concurrent_Type (S)
15515 and then not Has_Completion (S)
15516 and then Nkind (Parent (Id)) = N_Object_Declaration
15517 then
15518 Set_Is_Public (Id);
15519 end if;
15520 end Set_Public_Status;
15522 -----------------------------
15523 -- Set_Referenced_Modified --
15524 -----------------------------
15526 procedure Set_Referenced_Modified (N : Node_Id; Out_Param : Boolean) is
15527 Pref : Node_Id;
15529 begin
15530 -- Deal with indexed or selected component where prefix is modified
15532 if Nkind_In (N, N_Indexed_Component, N_Selected_Component) then
15533 Pref := Prefix (N);
15535 -- If prefix is access type, then it is the designated object that is
15536 -- being modified, which means we have no entity to set the flag on.
15538 if No (Etype (Pref)) or else Is_Access_Type (Etype (Pref)) then
15539 return;
15541 -- Otherwise chase the prefix
15543 else
15544 Set_Referenced_Modified (Pref, Out_Param);
15545 end if;
15547 -- Otherwise see if we have an entity name (only other case to process)
15549 elsif Is_Entity_Name (N) and then Present (Entity (N)) then
15550 Set_Referenced_As_LHS (Entity (N), not Out_Param);
15551 Set_Referenced_As_Out_Parameter (Entity (N), Out_Param);
15552 end if;
15553 end Set_Referenced_Modified;
15555 ----------------------------
15556 -- Set_Scope_Is_Transient --
15557 ----------------------------
15559 procedure Set_Scope_Is_Transient (V : Boolean := True) is
15560 begin
15561 Scope_Stack.Table (Scope_Stack.Last).Is_Transient := V;
15562 end Set_Scope_Is_Transient;
15564 -------------------
15565 -- Set_Size_Info --
15566 -------------------
15568 procedure Set_Size_Info (T1, T2 : Entity_Id) is
15569 begin
15570 -- We copy Esize, but not RM_Size, since in general RM_Size is
15571 -- subtype specific and does not get inherited by all subtypes.
15573 Set_Esize (T1, Esize (T2));
15574 Set_Has_Biased_Representation (T1, Has_Biased_Representation (T2));
15576 if Is_Discrete_Or_Fixed_Point_Type (T1)
15577 and then
15578 Is_Discrete_Or_Fixed_Point_Type (T2)
15579 then
15580 Set_Is_Unsigned_Type (T1, Is_Unsigned_Type (T2));
15581 end if;
15583 Set_Alignment (T1, Alignment (T2));
15584 end Set_Size_Info;
15586 --------------------
15587 -- Static_Boolean --
15588 --------------------
15590 function Static_Boolean (N : Node_Id) return Uint is
15591 begin
15592 Analyze_And_Resolve (N, Standard_Boolean);
15594 if N = Error
15595 or else Error_Posted (N)
15596 or else Etype (N) = Any_Type
15597 then
15598 return No_Uint;
15599 end if;
15601 if Is_Static_Expression (N) then
15602 if not Raises_Constraint_Error (N) then
15603 return Expr_Value (N);
15604 else
15605 return No_Uint;
15606 end if;
15608 elsif Etype (N) = Any_Type then
15609 return No_Uint;
15611 else
15612 Flag_Non_Static_Expr
15613 ("static boolean expression required here", N);
15614 return No_Uint;
15615 end if;
15616 end Static_Boolean;
15618 --------------------
15619 -- Static_Integer --
15620 --------------------
15622 function Static_Integer (N : Node_Id) return Uint is
15623 begin
15624 Analyze_And_Resolve (N, Any_Integer);
15626 if N = Error
15627 or else Error_Posted (N)
15628 or else Etype (N) = Any_Type
15629 then
15630 return No_Uint;
15631 end if;
15633 if Is_Static_Expression (N) then
15634 if not Raises_Constraint_Error (N) then
15635 return Expr_Value (N);
15636 else
15637 return No_Uint;
15638 end if;
15640 elsif Etype (N) = Any_Type then
15641 return No_Uint;
15643 else
15644 Flag_Non_Static_Expr
15645 ("static integer expression required here", N);
15646 return No_Uint;
15647 end if;
15648 end Static_Integer;
15650 --------------------------
15651 -- Statically_Different --
15652 --------------------------
15654 function Statically_Different (E1, E2 : Node_Id) return Boolean is
15655 R1 : constant Node_Id := Get_Referenced_Object (E1);
15656 R2 : constant Node_Id := Get_Referenced_Object (E2);
15657 begin
15658 return Is_Entity_Name (R1)
15659 and then Is_Entity_Name (R2)
15660 and then Entity (R1) /= Entity (R2)
15661 and then not Is_Formal (Entity (R1))
15662 and then not Is_Formal (Entity (R2));
15663 end Statically_Different;
15665 --------------------------------------
15666 -- Subject_To_Loop_Entry_Attributes --
15667 --------------------------------------
15669 function Subject_To_Loop_Entry_Attributes (N : Node_Id) return Boolean is
15670 Stmt : Node_Id;
15672 begin
15673 Stmt := N;
15675 -- The expansion mechanism transform a loop subject to at least one
15676 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
15677 -- the conditional part.
15679 if Nkind_In (Stmt, N_Block_Statement, N_If_Statement)
15680 and then Nkind (Original_Node (N)) = N_Loop_Statement
15681 then
15682 Stmt := Original_Node (N);
15683 end if;
15685 return
15686 Nkind (Stmt) = N_Loop_Statement
15687 and then Present (Identifier (Stmt))
15688 and then Present (Entity (Identifier (Stmt)))
15689 and then Has_Loop_Entry_Attributes (Entity (Identifier (Stmt)));
15690 end Subject_To_Loop_Entry_Attributes;
15692 -----------------------------
15693 -- Subprogram_Access_Level --
15694 -----------------------------
15696 function Subprogram_Access_Level (Subp : Entity_Id) return Uint is
15697 begin
15698 if Present (Alias (Subp)) then
15699 return Subprogram_Access_Level (Alias (Subp));
15700 else
15701 return Scope_Depth (Enclosing_Dynamic_Scope (Subp));
15702 end if;
15703 end Subprogram_Access_Level;
15705 -------------------------------
15706 -- Support_Atomic_Primitives --
15707 -------------------------------
15709 function Support_Atomic_Primitives (Typ : Entity_Id) return Boolean is
15710 Size : Int;
15712 begin
15713 -- Verify the alignment of Typ is known
15715 if not Known_Alignment (Typ) then
15716 return False;
15717 end if;
15719 if Known_Static_Esize (Typ) then
15720 Size := UI_To_Int (Esize (Typ));
15722 -- If the Esize (Object_Size) is unknown at compile time, look at the
15723 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
15725 elsif Known_Static_RM_Size (Typ) then
15726 Size := UI_To_Int (RM_Size (Typ));
15728 -- Otherwise, the size is considered to be unknown.
15730 else
15731 return False;
15732 end if;
15734 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
15735 -- Typ is properly aligned.
15737 case Size is
15738 when 8 | 16 | 32 | 64 =>
15739 return Size = UI_To_Int (Alignment (Typ)) * 8;
15740 when others =>
15741 return False;
15742 end case;
15743 end Support_Atomic_Primitives;
15745 -----------------
15746 -- Trace_Scope --
15747 -----------------
15749 procedure Trace_Scope (N : Node_Id; E : Entity_Id; Msg : String) is
15750 begin
15751 if Debug_Flag_W then
15752 for J in 0 .. Scope_Stack.Last loop
15753 Write_Str (" ");
15754 end loop;
15756 Write_Str (Msg);
15757 Write_Name (Chars (E));
15758 Write_Str (" from ");
15759 Write_Location (Sloc (N));
15760 Write_Eol;
15761 end if;
15762 end Trace_Scope;
15764 -----------------------
15765 -- Transfer_Entities --
15766 -----------------------
15768 procedure Transfer_Entities (From : Entity_Id; To : Entity_Id) is
15769 Ent : Entity_Id := First_Entity (From);
15771 begin
15772 if No (Ent) then
15773 return;
15774 end if;
15776 if (Last_Entity (To)) = Empty then
15777 Set_First_Entity (To, Ent);
15778 else
15779 Set_Next_Entity (Last_Entity (To), Ent);
15780 end if;
15782 Set_Last_Entity (To, Last_Entity (From));
15784 while Present (Ent) loop
15785 Set_Scope (Ent, To);
15787 if not Is_Public (Ent) then
15788 Set_Public_Status (Ent);
15790 if Is_Public (Ent)
15791 and then Ekind (Ent) = E_Record_Subtype
15793 then
15794 -- The components of the propagated Itype must be public
15795 -- as well.
15797 declare
15798 Comp : Entity_Id;
15799 begin
15800 Comp := First_Entity (Ent);
15801 while Present (Comp) loop
15802 Set_Is_Public (Comp);
15803 Next_Entity (Comp);
15804 end loop;
15805 end;
15806 end if;
15807 end if;
15809 Next_Entity (Ent);
15810 end loop;
15812 Set_First_Entity (From, Empty);
15813 Set_Last_Entity (From, Empty);
15814 end Transfer_Entities;
15816 -----------------------
15817 -- Type_Access_Level --
15818 -----------------------
15820 function Type_Access_Level (Typ : Entity_Id) return Uint is
15821 Btyp : Entity_Id;
15823 begin
15824 Btyp := Base_Type (Typ);
15826 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
15827 -- simply use the level where the type is declared. This is true for
15828 -- stand-alone object declarations, and for anonymous access types
15829 -- associated with components the level is the same as that of the
15830 -- enclosing composite type. However, special treatment is needed for
15831 -- the cases of access parameters, return objects of an anonymous access
15832 -- type, and, in Ada 95, access discriminants of limited types.
15834 if Ekind (Btyp) in Access_Kind then
15835 if Ekind (Btyp) = E_Anonymous_Access_Type then
15837 -- If the type is a nonlocal anonymous access type (such as for
15838 -- an access parameter) we treat it as being declared at the
15839 -- library level to ensure that names such as X.all'access don't
15840 -- fail static accessibility checks.
15842 if not Is_Local_Anonymous_Access (Typ) then
15843 return Scope_Depth (Standard_Standard);
15845 -- If this is a return object, the accessibility level is that of
15846 -- the result subtype of the enclosing function. The test here is
15847 -- little complicated, because we have to account for extended
15848 -- return statements that have been rewritten as blocks, in which
15849 -- case we have to find and the Is_Return_Object attribute of the
15850 -- itype's associated object. It would be nice to find a way to
15851 -- simplify this test, but it doesn't seem worthwhile to add a new
15852 -- flag just for purposes of this test. ???
15854 elsif Ekind (Scope (Btyp)) = E_Return_Statement
15855 or else
15856 (Is_Itype (Btyp)
15857 and then Nkind (Associated_Node_For_Itype (Btyp)) =
15858 N_Object_Declaration
15859 and then Is_Return_Object
15860 (Defining_Identifier
15861 (Associated_Node_For_Itype (Btyp))))
15862 then
15863 declare
15864 Scop : Entity_Id;
15866 begin
15867 Scop := Scope (Scope (Btyp));
15868 while Present (Scop) loop
15869 exit when Ekind (Scop) = E_Function;
15870 Scop := Scope (Scop);
15871 end loop;
15873 -- Treat the return object's type as having the level of the
15874 -- function's result subtype (as per RM05-6.5(5.3/2)).
15876 return Type_Access_Level (Etype (Scop));
15877 end;
15878 end if;
15879 end if;
15881 Btyp := Root_Type (Btyp);
15883 -- The accessibility level of anonymous access types associated with
15884 -- discriminants is that of the current instance of the type, and
15885 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
15887 -- AI-402: access discriminants have accessibility based on the
15888 -- object rather than the type in Ada 2005, so the above paragraph
15889 -- doesn't apply.
15891 -- ??? Needs completion with rules from AI-416
15893 if Ada_Version <= Ada_95
15894 and then Ekind (Typ) = E_Anonymous_Access_Type
15895 and then Present (Associated_Node_For_Itype (Typ))
15896 and then Nkind (Associated_Node_For_Itype (Typ)) =
15897 N_Discriminant_Specification
15898 then
15899 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp)) + 1;
15900 end if;
15901 end if;
15903 -- Return library level for a generic formal type. This is done because
15904 -- RM(10.3.2) says that "The statically deeper relationship does not
15905 -- apply to ... a descendant of a generic formal type". Rather than
15906 -- checking at each point where a static accessibility check is
15907 -- performed to see if we are dealing with a formal type, this rule is
15908 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
15909 -- return extreme values for a formal type; Deepest_Type_Access_Level
15910 -- returns Int'Last. By calling the appropriate function from among the
15911 -- two, we ensure that the static accessibility check will pass if we
15912 -- happen to run into a formal type. More specifically, we should call
15913 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
15914 -- call occurs as part of a static accessibility check and the error
15915 -- case is the case where the type's level is too shallow (as opposed
15916 -- to too deep).
15918 if Is_Generic_Type (Root_Type (Btyp)) then
15919 return Scope_Depth (Standard_Standard);
15920 end if;
15922 return Scope_Depth (Enclosing_Dynamic_Scope (Btyp));
15923 end Type_Access_Level;
15925 ------------------------------------
15926 -- Type_Without_Stream_Operation --
15927 ------------------------------------
15929 function Type_Without_Stream_Operation
15930 (T : Entity_Id;
15931 Op : TSS_Name_Type := TSS_Null) return Entity_Id
15933 BT : constant Entity_Id := Base_Type (T);
15934 Op_Missing : Boolean;
15936 begin
15937 if not Restriction_Active (No_Default_Stream_Attributes) then
15938 return Empty;
15939 end if;
15941 if Is_Elementary_Type (T) then
15942 if Op = TSS_Null then
15943 Op_Missing :=
15944 No (TSS (BT, TSS_Stream_Read))
15945 or else No (TSS (BT, TSS_Stream_Write));
15947 else
15948 Op_Missing := No (TSS (BT, Op));
15949 end if;
15951 if Op_Missing then
15952 return T;
15953 else
15954 return Empty;
15955 end if;
15957 elsif Is_Array_Type (T) then
15958 return Type_Without_Stream_Operation (Component_Type (T), Op);
15960 elsif Is_Record_Type (T) then
15961 declare
15962 Comp : Entity_Id;
15963 C_Typ : Entity_Id;
15965 begin
15966 Comp := First_Component (T);
15967 while Present (Comp) loop
15968 C_Typ := Type_Without_Stream_Operation (Etype (Comp), Op);
15970 if Present (C_Typ) then
15971 return C_Typ;
15972 end if;
15974 Next_Component (Comp);
15975 end loop;
15977 return Empty;
15978 end;
15980 elsif Is_Private_Type (T)
15981 and then Present (Full_View (T))
15982 then
15983 return Type_Without_Stream_Operation (Full_View (T), Op);
15984 else
15985 return Empty;
15986 end if;
15987 end Type_Without_Stream_Operation;
15989 ----------------------------
15990 -- Unique_Defining_Entity --
15991 ----------------------------
15993 function Unique_Defining_Entity (N : Node_Id) return Entity_Id is
15994 begin
15995 return Unique_Entity (Defining_Entity (N));
15996 end Unique_Defining_Entity;
15998 -------------------
15999 -- Unique_Entity --
16000 -------------------
16002 function Unique_Entity (E : Entity_Id) return Entity_Id is
16003 U : Entity_Id := E;
16004 P : Node_Id;
16006 begin
16007 case Ekind (E) is
16008 when E_Constant =>
16009 if Present (Full_View (E)) then
16010 U := Full_View (E);
16011 end if;
16013 when Type_Kind =>
16014 if Present (Full_View (E)) then
16015 U := Full_View (E);
16016 end if;
16018 when E_Package_Body =>
16019 P := Parent (E);
16021 if Nkind (P) = N_Defining_Program_Unit_Name then
16022 P := Parent (P);
16023 end if;
16025 U := Corresponding_Spec (P);
16027 when E_Subprogram_Body =>
16028 P := Parent (E);
16030 if Nkind (P) = N_Defining_Program_Unit_Name then
16031 P := Parent (P);
16032 end if;
16034 P := Parent (P);
16036 if Nkind (P) = N_Subprogram_Body_Stub then
16037 if Present (Library_Unit (P)) then
16039 -- Get to the function or procedure (generic) entity through
16040 -- the body entity.
16042 U :=
16043 Unique_Entity (Defining_Entity (Get_Body_From_Stub (P)));
16044 end if;
16045 else
16046 U := Corresponding_Spec (P);
16047 end if;
16049 when Formal_Kind =>
16050 if Present (Spec_Entity (E)) then
16051 U := Spec_Entity (E);
16052 end if;
16054 when others =>
16055 null;
16056 end case;
16058 return U;
16059 end Unique_Entity;
16061 -----------------
16062 -- Unique_Name --
16063 -----------------
16065 function Unique_Name (E : Entity_Id) return String is
16067 -- Names of E_Subprogram_Body or E_Package_Body entities are not
16068 -- reliable, as they may not include the overloading suffix. Instead,
16069 -- when looking for the name of E or one of its enclosing scope, we get
16070 -- the name of the corresponding Unique_Entity.
16072 function Get_Scoped_Name (E : Entity_Id) return String;
16073 -- Return the name of E prefixed by all the names of the scopes to which
16074 -- E belongs, except for Standard.
16076 ---------------------
16077 -- Get_Scoped_Name --
16078 ---------------------
16080 function Get_Scoped_Name (E : Entity_Id) return String is
16081 Name : constant String := Get_Name_String (Chars (E));
16082 begin
16083 if Has_Fully_Qualified_Name (E)
16084 or else Scope (E) = Standard_Standard
16085 then
16086 return Name;
16087 else
16088 return Get_Scoped_Name (Unique_Entity (Scope (E))) & "__" & Name;
16089 end if;
16090 end Get_Scoped_Name;
16092 -- Start of processing for Unique_Name
16094 begin
16095 if E = Standard_Standard then
16096 return Get_Name_String (Name_Standard);
16098 elsif Scope (E) = Standard_Standard
16099 and then not (Ekind (E) = E_Package or else Is_Subprogram (E))
16100 then
16101 return Get_Name_String (Name_Standard) & "__" &
16102 Get_Name_String (Chars (E));
16104 elsif Ekind (E) = E_Enumeration_Literal then
16105 return Unique_Name (Etype (E)) & "__" & Get_Name_String (Chars (E));
16107 else
16108 return Get_Scoped_Name (Unique_Entity (E));
16109 end if;
16110 end Unique_Name;
16112 ---------------------
16113 -- Unit_Is_Visible --
16114 ---------------------
16116 function Unit_Is_Visible (U : Entity_Id) return Boolean is
16117 Curr : constant Node_Id := Cunit (Current_Sem_Unit);
16118 Curr_Entity : constant Entity_Id := Cunit_Entity (Current_Sem_Unit);
16120 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean;
16121 -- For a child unit, check whether unit appears in a with_clause
16122 -- of a parent.
16124 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean;
16125 -- Scan the context clause of one compilation unit looking for a
16126 -- with_clause for the unit in question.
16128 ----------------------------
16129 -- Unit_In_Parent_Context --
16130 ----------------------------
16132 function Unit_In_Parent_Context (Par_Unit : Node_Id) return Boolean is
16133 begin
16134 if Unit_In_Context (Par_Unit) then
16135 return True;
16137 elsif Is_Child_Unit (Defining_Entity (Unit (Par_Unit))) then
16138 return Unit_In_Parent_Context (Parent_Spec (Unit (Par_Unit)));
16140 else
16141 return False;
16142 end if;
16143 end Unit_In_Parent_Context;
16145 ---------------------
16146 -- Unit_In_Context --
16147 ---------------------
16149 function Unit_In_Context (Comp_Unit : Node_Id) return Boolean is
16150 Clause : Node_Id;
16152 begin
16153 Clause := First (Context_Items (Comp_Unit));
16154 while Present (Clause) loop
16155 if Nkind (Clause) = N_With_Clause then
16156 if Library_Unit (Clause) = U then
16157 return True;
16159 -- The with_clause may denote a renaming of the unit we are
16160 -- looking for, eg. Text_IO which renames Ada.Text_IO.
16162 elsif
16163 Renamed_Entity (Entity (Name (Clause))) =
16164 Defining_Entity (Unit (U))
16165 then
16166 return True;
16167 end if;
16168 end if;
16170 Next (Clause);
16171 end loop;
16173 return False;
16174 end Unit_In_Context;
16176 -- Start of processing for Unit_Is_Visible
16178 begin
16179 -- The currrent unit is directly visible
16181 if Curr = U then
16182 return True;
16184 elsif Unit_In_Context (Curr) then
16185 return True;
16187 -- If the current unit is a body, check the context of the spec
16189 elsif Nkind (Unit (Curr)) = N_Package_Body
16190 or else
16191 (Nkind (Unit (Curr)) = N_Subprogram_Body
16192 and then not Acts_As_Spec (Unit (Curr)))
16193 then
16194 if Unit_In_Context (Library_Unit (Curr)) then
16195 return True;
16196 end if;
16197 end if;
16199 -- If the spec is a child unit, examine the parents
16201 if Is_Child_Unit (Curr_Entity) then
16202 if Nkind (Unit (Curr)) in N_Unit_Body then
16203 return
16204 Unit_In_Parent_Context
16205 (Parent_Spec (Unit (Library_Unit (Curr))));
16206 else
16207 return Unit_In_Parent_Context (Parent_Spec (Unit (Curr)));
16208 end if;
16210 else
16211 return False;
16212 end if;
16213 end Unit_Is_Visible;
16215 ------------------------------
16216 -- Universal_Interpretation --
16217 ------------------------------
16219 function Universal_Interpretation (Opnd : Node_Id) return Entity_Id is
16220 Index : Interp_Index;
16221 It : Interp;
16223 begin
16224 -- The argument may be a formal parameter of an operator or subprogram
16225 -- with multiple interpretations, or else an expression for an actual.
16227 if Nkind (Opnd) = N_Defining_Identifier
16228 or else not Is_Overloaded (Opnd)
16229 then
16230 if Etype (Opnd) = Universal_Integer
16231 or else Etype (Opnd) = Universal_Real
16232 then
16233 return Etype (Opnd);
16234 else
16235 return Empty;
16236 end if;
16238 else
16239 Get_First_Interp (Opnd, Index, It);
16240 while Present (It.Typ) loop
16241 if It.Typ = Universal_Integer
16242 or else It.Typ = Universal_Real
16243 then
16244 return It.Typ;
16245 end if;
16247 Get_Next_Interp (Index, It);
16248 end loop;
16250 return Empty;
16251 end if;
16252 end Universal_Interpretation;
16254 ---------------
16255 -- Unqualify --
16256 ---------------
16258 function Unqualify (Expr : Node_Id) return Node_Id is
16259 begin
16260 -- Recurse to handle unlikely case of multiple levels of qualification
16262 if Nkind (Expr) = N_Qualified_Expression then
16263 return Unqualify (Expression (Expr));
16265 -- Normal case, not a qualified expression
16267 else
16268 return Expr;
16269 end if;
16270 end Unqualify;
16272 -----------------------
16273 -- Visible_Ancestors --
16274 -----------------------
16276 function Visible_Ancestors (Typ : Entity_Id) return Elist_Id is
16277 List_1 : Elist_Id;
16278 List_2 : Elist_Id;
16279 Elmt : Elmt_Id;
16281 begin
16282 pragma Assert (Is_Record_Type (Typ)
16283 and then Is_Tagged_Type (Typ));
16285 -- Collect all the parents and progenitors of Typ. If the full-view of
16286 -- private parents and progenitors is available then it is used to
16287 -- generate the list of visible ancestors; otherwise their partial
16288 -- view is added to the resulting list.
16290 Collect_Parents
16291 (T => Typ,
16292 List => List_1,
16293 Use_Full_View => True);
16295 Collect_Interfaces
16296 (T => Typ,
16297 Ifaces_List => List_2,
16298 Exclude_Parents => True,
16299 Use_Full_View => True);
16301 -- Join the two lists. Avoid duplications because an interface may
16302 -- simultaneously be parent and progenitor of a type.
16304 Elmt := First_Elmt (List_2);
16305 while Present (Elmt) loop
16306 Append_Unique_Elmt (Node (Elmt), List_1);
16307 Next_Elmt (Elmt);
16308 end loop;
16310 return List_1;
16311 end Visible_Ancestors;
16313 ----------------------
16314 -- Within_Init_Proc --
16315 ----------------------
16317 function Within_Init_Proc return Boolean is
16318 S : Entity_Id;
16320 begin
16321 S := Current_Scope;
16322 while not Is_Overloadable (S) loop
16323 if S = Standard_Standard then
16324 return False;
16325 else
16326 S := Scope (S);
16327 end if;
16328 end loop;
16330 return Is_Init_Proc (S);
16331 end Within_Init_Proc;
16333 ------------------
16334 -- Within_Scope --
16335 ------------------
16337 function Within_Scope (E : Entity_Id; S : Entity_Id) return Boolean is
16338 SE : Entity_Id;
16339 begin
16340 SE := Scope (E);
16341 loop
16342 if SE = S then
16343 return True;
16344 elsif SE = Standard_Standard then
16345 return False;
16346 else
16347 SE := Scope (SE);
16348 end if;
16349 end loop;
16350 end Within_Scope;
16352 ----------------
16353 -- Wrong_Type --
16354 ----------------
16356 procedure Wrong_Type (Expr : Node_Id; Expected_Type : Entity_Id) is
16357 Found_Type : constant Entity_Id := First_Subtype (Etype (Expr));
16358 Expec_Type : constant Entity_Id := First_Subtype (Expected_Type);
16360 Matching_Field : Entity_Id;
16361 -- Entity to give a more precise suggestion on how to write a one-
16362 -- element positional aggregate.
16364 function Has_One_Matching_Field return Boolean;
16365 -- Determines if Expec_Type is a record type with a single component or
16366 -- discriminant whose type matches the found type or is one dimensional
16367 -- array whose component type matches the found type. In the case of
16368 -- one discriminant, we ignore the variant parts. That's not accurate,
16369 -- but good enough for the warning.
16371 ----------------------------
16372 -- Has_One_Matching_Field --
16373 ----------------------------
16375 function Has_One_Matching_Field return Boolean is
16376 E : Entity_Id;
16378 begin
16379 Matching_Field := Empty;
16381 if Is_Array_Type (Expec_Type)
16382 and then Number_Dimensions (Expec_Type) = 1
16383 and then
16384 Covers (Etype (Component_Type (Expec_Type)), Found_Type)
16385 then
16386 -- Use type name if available. This excludes multidimensional
16387 -- arrays and anonymous arrays.
16389 if Comes_From_Source (Expec_Type) then
16390 Matching_Field := Expec_Type;
16392 -- For an assignment, use name of target
16394 elsif Nkind (Parent (Expr)) = N_Assignment_Statement
16395 and then Is_Entity_Name (Name (Parent (Expr)))
16396 then
16397 Matching_Field := Entity (Name (Parent (Expr)));
16398 end if;
16400 return True;
16402 elsif not Is_Record_Type (Expec_Type) then
16403 return False;
16405 else
16406 E := First_Entity (Expec_Type);
16407 loop
16408 if No (E) then
16409 return False;
16411 elsif not Ekind_In (E, E_Discriminant, E_Component)
16412 or else Nam_In (Chars (E), Name_uTag, Name_uParent)
16413 then
16414 Next_Entity (E);
16416 else
16417 exit;
16418 end if;
16419 end loop;
16421 if not Covers (Etype (E), Found_Type) then
16422 return False;
16424 elsif Present (Next_Entity (E))
16425 and then (Ekind (E) = E_Component
16426 or else Ekind (Next_Entity (E)) = E_Discriminant)
16427 then
16428 return False;
16430 else
16431 Matching_Field := E;
16432 return True;
16433 end if;
16434 end if;
16435 end Has_One_Matching_Field;
16437 -- Start of processing for Wrong_Type
16439 begin
16440 -- Don't output message if either type is Any_Type, or if a message
16441 -- has already been posted for this node. We need to do the latter
16442 -- check explicitly (it is ordinarily done in Errout), because we
16443 -- are using ! to force the output of the error messages.
16445 if Expec_Type = Any_Type
16446 or else Found_Type = Any_Type
16447 or else Error_Posted (Expr)
16448 then
16449 return;
16451 -- If one of the types is a Taft-Amendment type and the other it its
16452 -- completion, it must be an illegal use of a TAT in the spec, for
16453 -- which an error was already emitted. Avoid cascaded errors.
16455 elsif Is_Incomplete_Type (Expec_Type)
16456 and then Has_Completion_In_Body (Expec_Type)
16457 and then Full_View (Expec_Type) = Etype (Expr)
16458 then
16459 return;
16461 elsif Is_Incomplete_Type (Etype (Expr))
16462 and then Has_Completion_In_Body (Etype (Expr))
16463 and then Full_View (Etype (Expr)) = Expec_Type
16464 then
16465 return;
16467 -- In an instance, there is an ongoing problem with completion of
16468 -- type derived from private types. Their structure is what Gigi
16469 -- expects, but the Etype is the parent type rather than the
16470 -- derived private type itself. Do not flag error in this case. The
16471 -- private completion is an entity without a parent, like an Itype.
16472 -- Similarly, full and partial views may be incorrect in the instance.
16473 -- There is no simple way to insure that it is consistent ???
16475 elsif In_Instance then
16476 if Etype (Etype (Expr)) = Etype (Expected_Type)
16477 and then
16478 (Has_Private_Declaration (Expected_Type)
16479 or else Has_Private_Declaration (Etype (Expr)))
16480 and then No (Parent (Expected_Type))
16481 then
16482 return;
16483 end if;
16484 end if;
16486 -- An interesting special check. If the expression is parenthesized
16487 -- and its type corresponds to the type of the sole component of the
16488 -- expected record type, or to the component type of the expected one
16489 -- dimensional array type, then assume we have a bad aggregate attempt.
16491 if Nkind (Expr) in N_Subexpr
16492 and then Paren_Count (Expr) /= 0
16493 and then Has_One_Matching_Field
16494 then
16495 Error_Msg_N ("positional aggregate cannot have one component", Expr);
16496 if Present (Matching_Field) then
16497 if Is_Array_Type (Expec_Type) then
16498 Error_Msg_NE
16499 ("\write instead `&''First ='> ...`", Expr, Matching_Field);
16501 else
16502 Error_Msg_NE
16503 ("\write instead `& ='> ...`", Expr, Matching_Field);
16504 end if;
16505 end if;
16507 -- Another special check, if we are looking for a pool-specific access
16508 -- type and we found an E_Access_Attribute_Type, then we have the case
16509 -- of an Access attribute being used in a context which needs a pool-
16510 -- specific type, which is never allowed. The one extra check we make
16511 -- is that the expected designated type covers the Found_Type.
16513 elsif Is_Access_Type (Expec_Type)
16514 and then Ekind (Found_Type) = E_Access_Attribute_Type
16515 and then Ekind (Base_Type (Expec_Type)) /= E_General_Access_Type
16516 and then Ekind (Base_Type (Expec_Type)) /= E_Anonymous_Access_Type
16517 and then Covers
16518 (Designated_Type (Expec_Type), Designated_Type (Found_Type))
16519 then
16520 Error_Msg_N -- CODEFIX
16521 ("result must be general access type!", Expr);
16522 Error_Msg_NE -- CODEFIX
16523 ("add ALL to }!", Expr, Expec_Type);
16525 -- Another special check, if the expected type is an integer type,
16526 -- but the expression is of type System.Address, and the parent is
16527 -- an addition or subtraction operation whose left operand is the
16528 -- expression in question and whose right operand is of an integral
16529 -- type, then this is an attempt at address arithmetic, so give
16530 -- appropriate message.
16532 elsif Is_Integer_Type (Expec_Type)
16533 and then Is_RTE (Found_Type, RE_Address)
16534 and then (Nkind (Parent (Expr)) = N_Op_Add
16535 or else
16536 Nkind (Parent (Expr)) = N_Op_Subtract)
16537 and then Expr = Left_Opnd (Parent (Expr))
16538 and then Is_Integer_Type (Etype (Right_Opnd (Parent (Expr))))
16539 then
16540 Error_Msg_N
16541 ("address arithmetic not predefined in package System",
16542 Parent (Expr));
16543 Error_Msg_N
16544 ("\possible missing with/use of System.Storage_Elements",
16545 Parent (Expr));
16546 return;
16548 -- If the expected type is an anonymous access type, as for access
16549 -- parameters and discriminants, the error is on the designated types.
16551 elsif Ekind (Expec_Type) = E_Anonymous_Access_Type then
16552 if Comes_From_Source (Expec_Type) then
16553 Error_Msg_NE ("expected}!", Expr, Expec_Type);
16554 else
16555 Error_Msg_NE
16556 ("expected an access type with designated}",
16557 Expr, Designated_Type (Expec_Type));
16558 end if;
16560 if Is_Access_Type (Found_Type)
16561 and then not Comes_From_Source (Found_Type)
16562 then
16563 Error_Msg_NE
16564 ("\\found an access type with designated}!",
16565 Expr, Designated_Type (Found_Type));
16566 else
16567 if From_Limited_With (Found_Type) then
16568 Error_Msg_NE ("\\found incomplete}!", Expr, Found_Type);
16569 Error_Msg_Qual_Level := 99;
16570 Error_Msg_NE -- CODEFIX
16571 ("\\missing `WITH &;", Expr, Scope (Found_Type));
16572 Error_Msg_Qual_Level := 0;
16573 else
16574 Error_Msg_NE ("found}!", Expr, Found_Type);
16575 end if;
16576 end if;
16578 -- Normal case of one type found, some other type expected
16580 else
16581 -- If the names of the two types are the same, see if some number
16582 -- of levels of qualification will help. Don't try more than three
16583 -- levels, and if we get to standard, it's no use (and probably
16584 -- represents an error in the compiler) Also do not bother with
16585 -- internal scope names.
16587 declare
16588 Expec_Scope : Entity_Id;
16589 Found_Scope : Entity_Id;
16591 begin
16592 Expec_Scope := Expec_Type;
16593 Found_Scope := Found_Type;
16595 for Levels in Int range 0 .. 3 loop
16596 if Chars (Expec_Scope) /= Chars (Found_Scope) then
16597 Error_Msg_Qual_Level := Levels;
16598 exit;
16599 end if;
16601 Expec_Scope := Scope (Expec_Scope);
16602 Found_Scope := Scope (Found_Scope);
16604 exit when Expec_Scope = Standard_Standard
16605 or else Found_Scope = Standard_Standard
16606 or else not Comes_From_Source (Expec_Scope)
16607 or else not Comes_From_Source (Found_Scope);
16608 end loop;
16609 end;
16611 if Is_Record_Type (Expec_Type)
16612 and then Present (Corresponding_Remote_Type (Expec_Type))
16613 then
16614 Error_Msg_NE ("expected}!", Expr,
16615 Corresponding_Remote_Type (Expec_Type));
16616 else
16617 Error_Msg_NE ("expected}!", Expr, Expec_Type);
16618 end if;
16620 if Is_Entity_Name (Expr)
16621 and then Is_Package_Or_Generic_Package (Entity (Expr))
16622 then
16623 Error_Msg_N ("\\found package name!", Expr);
16625 elsif Is_Entity_Name (Expr)
16626 and then
16627 (Ekind (Entity (Expr)) = E_Procedure
16628 or else
16629 Ekind (Entity (Expr)) = E_Generic_Procedure)
16630 then
16631 if Ekind (Expec_Type) = E_Access_Subprogram_Type then
16632 Error_Msg_N
16633 ("found procedure name, possibly missing Access attribute!",
16634 Expr);
16635 else
16636 Error_Msg_N
16637 ("\\found procedure name instead of function!", Expr);
16638 end if;
16640 elsif Nkind (Expr) = N_Function_Call
16641 and then Ekind (Expec_Type) = E_Access_Subprogram_Type
16642 and then Etype (Designated_Type (Expec_Type)) = Etype (Expr)
16643 and then No (Parameter_Associations (Expr))
16644 then
16645 Error_Msg_N
16646 ("found function name, possibly missing Access attribute!",
16647 Expr);
16649 -- Catch common error: a prefix or infix operator which is not
16650 -- directly visible because the type isn't.
16652 elsif Nkind (Expr) in N_Op
16653 and then Is_Overloaded (Expr)
16654 and then not Is_Immediately_Visible (Expec_Type)
16655 and then not Is_Potentially_Use_Visible (Expec_Type)
16656 and then not In_Use (Expec_Type)
16657 and then Has_Compatible_Type (Right_Opnd (Expr), Expec_Type)
16658 then
16659 Error_Msg_N
16660 ("operator of the type is not directly visible!", Expr);
16662 elsif Ekind (Found_Type) = E_Void
16663 and then Present (Parent (Found_Type))
16664 and then Nkind (Parent (Found_Type)) = N_Full_Type_Declaration
16665 then
16666 Error_Msg_NE ("\\found premature usage of}!", Expr, Found_Type);
16668 else
16669 Error_Msg_NE ("\\found}!", Expr, Found_Type);
16670 end if;
16672 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
16673 -- of the same modular type, and (M1 and M2) = 0 was intended.
16675 if Expec_Type = Standard_Boolean
16676 and then Is_Modular_Integer_Type (Found_Type)
16677 and then Nkind_In (Parent (Expr), N_Op_And, N_Op_Or, N_Op_Xor)
16678 and then Nkind (Right_Opnd (Parent (Expr))) in N_Op_Compare
16679 then
16680 declare
16681 Op : constant Node_Id := Right_Opnd (Parent (Expr));
16682 L : constant Node_Id := Left_Opnd (Op);
16683 R : constant Node_Id := Right_Opnd (Op);
16684 begin
16685 -- The case for the message is when the left operand of the
16686 -- comparison is the same modular type, or when it is an
16687 -- integer literal (or other universal integer expression),
16688 -- which would have been typed as the modular type if the
16689 -- parens had been there.
16691 if (Etype (L) = Found_Type
16692 or else
16693 Etype (L) = Universal_Integer)
16694 and then Is_Integer_Type (Etype (R))
16695 then
16696 Error_Msg_N
16697 ("\\possible missing parens for modular operation", Expr);
16698 end if;
16699 end;
16700 end if;
16702 -- Reset error message qualification indication
16704 Error_Msg_Qual_Level := 0;
16705 end if;
16706 end Wrong_Type;
16708 end Sem_Util;