1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
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. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Util
; use Exp_Util
;
36 with Fname
; use Fname
;
37 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
.Sp
; use Namet
.Sp
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
43 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Attr
; use Sem_Attr
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Ch13
; use Sem_Ch13
;
52 with Sem_Disp
; use Sem_Disp
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Prag
; use Sem_Prag
;
55 with Sem_Res
; use Sem_Res
;
56 with Sem_Warn
; use Sem_Warn
;
57 with Sem_Type
; use Sem_Type
;
58 with Sinfo
; use Sinfo
;
59 with Sinput
; use Sinput
;
60 with Stand
; use Stand
;
62 with Stringt
; use Stringt
;
63 with Targparm
; use Targparm
;
64 with Tbuild
; use Tbuild
;
65 with Ttypes
; use Ttypes
;
66 with Uname
; use Uname
;
68 with GNAT
.HTable
; use GNAT
.HTable
;
70 package body Sem_Util
is
72 ----------------------------------------
73 -- Global_Variables for New_Copy_Tree --
74 ----------------------------------------
76 -- These global variables are used by New_Copy_Tree. See description of the
77 -- body of this subprogram for details. Global variables can be safely used
78 -- by New_Copy_Tree, since there is no case of a recursive call from the
79 -- processing inside New_Copy_Tree.
81 NCT_Hash_Threshold
: constant := 20;
82 -- If there are more than this number of pairs of entries in the map, then
83 -- Hash_Tables_Used will be set, and the hash tables will be initialized
84 -- and used for the searches.
86 NCT_Hash_Tables_Used
: Boolean := False;
87 -- Set to True if hash tables are in use
89 NCT_Table_Entries
: Nat
:= 0;
90 -- Count entries in table to see if threshold is reached
92 NCT_Hash_Table_Setup
: Boolean := False;
93 -- Set to True if hash table contains data. We set this True if we setup
94 -- the hash table with data, and leave it set permanently from then on,
95 -- this is a signal that second and subsequent users of the hash table
96 -- must clear the old entries before reuse.
98 subtype NCT_Header_Num
is Int
range 0 .. 511;
99 -- Defines range of headers in hash tables (512 headers)
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 function Build_Component_Subtype
108 T
: Entity_Id
) return Node_Id
;
109 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
110 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
111 -- Loc is the source location, T is the original subtype.
113 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
114 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
115 -- with discriminants whose default values are static, examine only the
116 -- components in the selected variant to determine whether all of them
119 function Has_Enabled_Property
120 (Item_Id
: Entity_Id
;
121 Property
: Name_Id
) return Boolean;
122 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
123 -- Determine whether an abstract state or a variable denoted by entity
124 -- Item_Id has enabled property Property.
126 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
127 -- T is a derived tagged type. Check whether the type extension is null.
128 -- If the parent type is fully initialized, T can be treated as such.
130 ------------------------------
131 -- Abstract_Interface_List --
132 ------------------------------
134 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
138 if Is_Concurrent_Type
(Typ
) then
140 -- If we are dealing with a synchronized subtype, go to the base
141 -- type, whose declaration has the interface list.
143 -- Shouldn't this be Declaration_Node???
145 Nod
:= Parent
(Base_Type
(Typ
));
147 if Nkind
(Nod
) = N_Full_Type_Declaration
then
151 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
152 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
153 Nod
:= Type_Definition
(Parent
(Typ
));
155 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
156 if Present
(Full_View
(Typ
))
158 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
160 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
162 -- If the full-view is not available we cannot do anything else
163 -- here (the source has errors).
169 -- Support for generic formals with interfaces is still missing ???
171 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
176 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
180 elsif Ekind
(Typ
) = E_Record_Subtype
then
181 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
183 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
185 -- Recurse, because parent may still be a private extension. Also
186 -- note that the full view of the subtype or the full view of its
187 -- base type may (both) be unavailable.
189 return Abstract_Interface_List
(Etype
(Typ
));
191 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
192 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
193 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
195 Nod
:= Type_Definition
(Parent
(Typ
));
199 return Interface_List
(Nod
);
200 end Abstract_Interface_List
;
202 --------------------------------
203 -- Add_Access_Type_To_Process --
204 --------------------------------
206 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
210 Ensure_Freeze_Node
(E
);
211 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
215 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
219 end Add_Access_Type_To_Process
;
221 --------------------------
222 -- Add_Block_Identifier --
223 --------------------------
225 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
226 Loc
: constant Source_Ptr
:= Sloc
(N
);
229 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
231 -- The block already has a label, return its entity
233 if Present
(Identifier
(N
)) then
234 Id
:= Entity
(Identifier
(N
));
236 -- Create a new block label and set its attributes
239 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
240 Set_Etype
(Id
, Standard_Void_Type
);
243 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
244 Set_Block_Node
(Id
, Identifier
(N
));
246 end Add_Block_Identifier
;
248 -----------------------
249 -- Add_Contract_Item --
250 -----------------------
252 procedure Add_Contract_Item
(Prag
: Node_Id
; Id
: Entity_Id
) is
253 Items
: constant Node_Id
:= Contract
(Id
);
258 -- The related context must have a contract and the item to be added
261 pragma Assert
(Present
(Items
));
262 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
264 Nam
:= Original_Aspect_Name
(Prag
);
266 -- Contract items related to [generic] packages or instantiations. The
267 -- applicable pragmas are:
271 -- Part_Of (instantiation only)
273 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
274 if Nam_In
(Nam
, Name_Abstract_State
,
275 Name_Initial_Condition
,
278 Set_Next_Pragma
(Prag
, Classifications
(Items
));
279 Set_Classifications
(Items
, Prag
);
281 -- Indicator Part_Of must be associated with a package instantiation
283 elsif Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) then
284 Set_Next_Pragma
(Prag
, Classifications
(Items
));
285 Set_Classifications
(Items
, Prag
);
287 -- The pragma is not a proper contract item
293 -- Contract items related to package bodies. The applicable pragmas are:
296 elsif Ekind
(Id
) = E_Package_Body
then
297 if Nam
= Name_Refined_State
then
298 Set_Next_Pragma
(Prag
, Classifications
(Items
));
299 Set_Classifications
(Items
, Prag
);
301 -- The pragma is not a proper contract item
307 -- Contract items related to subprogram or entry declarations. The
308 -- applicable pragmas are:
318 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
319 or else Is_Generic_Subprogram
(Id
)
320 or else Is_Subprogram
(Id
)
322 if Nam_In
(Nam
, Name_Precondition
,
329 -- Before we add a precondition or postcondition to the list,
330 -- make sure we do not have a disallowed duplicate, which can
331 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
332 -- instead of the corresponding aspect.
334 if not From_Aspect_Specification
(Prag
)
335 and then Nam_In
(Nam
, Name_Pre_Class
,
342 N
:= Pre_Post_Conditions
(Items
);
343 while Present
(N
) loop
345 and then Original_Aspect_Name
(N
) = Nam
347 Error_Msg_Sloc
:= Sloc
(N
);
349 ("duplication of aspect for & given#", Prag
, Id
);
352 N
:= Next_Pragma
(N
);
357 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
358 Set_Pre_Post_Conditions
(Items
, Prag
);
360 elsif Nam_In
(Nam
, Name_Contract_Cases
, Name_Test_Case
) then
361 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
362 Set_Contract_Test_Cases
(Items
, Prag
);
364 elsif Nam_In
(Nam
, Name_Depends
, Name_Global
) then
365 Set_Next_Pragma
(Prag
, Classifications
(Items
));
366 Set_Classifications
(Items
, Prag
);
368 -- The pragma is not a proper contract item
374 -- Contract items related to subprogram bodies. The applicable pragmas
380 elsif Ekind
(Id
) = E_Subprogram_Body
then
381 if Nam
= Name_Refined_Post
then
382 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
383 Set_Pre_Post_Conditions
(Items
, Prag
);
385 elsif Nam_In
(Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
386 Set_Next_Pragma
(Prag
, Classifications
(Items
));
387 Set_Classifications
(Items
, Prag
);
389 -- The pragma is not a proper contract item
395 -- Contract items related to variables. The applicable pragmas are:
402 elsif Ekind
(Id
) = E_Variable
then
403 if Nam_In
(Nam
, Name_Async_Readers
,
405 Name_Effective_Reads
,
406 Name_Effective_Writes
,
409 Set_Next_Pragma
(Prag
, Classifications
(Items
));
410 Set_Classifications
(Items
, Prag
);
412 -- The pragma is not a proper contract item
418 end Add_Contract_Item
;
420 ----------------------------
421 -- Add_Global_Declaration --
422 ----------------------------
424 procedure Add_Global_Declaration
(N
: Node_Id
) is
425 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
428 if No
(Declarations
(Aux_Node
)) then
429 Set_Declarations
(Aux_Node
, New_List
);
432 Append_To
(Declarations
(Aux_Node
), N
);
434 end Add_Global_Declaration
;
436 --------------------------------
437 -- Address_Integer_Convert_OK --
438 --------------------------------
440 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
442 if Allow_Integer_Address
443 and then ((Is_Descendent_Of_Address
(T1
)
444 and then Is_Private_Type
(T1
)
445 and then Is_Integer_Type
(T2
))
447 (Is_Descendent_Of_Address
(T2
)
448 and then Is_Private_Type
(T2
)
449 and then Is_Integer_Type
(T1
)))
455 end Address_Integer_Convert_OK
;
461 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
463 function Addressable
(V
: Uint
) return Boolean is
465 return V
= Uint_8
or else
471 function Addressable
(V
: Int
) return Boolean is
479 ---------------------------------
480 -- Aggregate_Constraint_Checks --
481 ---------------------------------
483 procedure Aggregate_Constraint_Checks
485 Check_Typ
: Entity_Id
)
487 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
490 if Raises_Constraint_Error
(Exp
) then
494 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
495 -- component's type to force the appropriate accessibility checks.
497 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
498 -- type to force the corresponding run-time check
500 if Is_Access_Type
(Check_Typ
)
501 and then ((Is_Local_Anonymous_Access
(Check_Typ
))
502 or else (Can_Never_Be_Null
(Check_Typ
)
503 and then not Can_Never_Be_Null
(Exp_Typ
)))
505 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
506 Analyze_And_Resolve
(Exp
, Check_Typ
);
507 Check_Unset_Reference
(Exp
);
510 -- This is really expansion activity, so make sure that expansion is
511 -- on and is allowed. In GNATprove mode, we also want check flags to
512 -- be added in the tree, so that the formal verification can rely on
513 -- those to be present. In GNATprove mode for formal verification, some
514 -- treatment typically only done during expansion needs to be performed
515 -- on the tree, but it should not be applied inside generics. Otherwise,
516 -- this breaks the name resolution mechanism for generic instances.
518 if not Expander_Active
519 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
524 -- First check if we have to insert discriminant checks
526 if Has_Discriminants
(Exp_Typ
) then
527 Apply_Discriminant_Check
(Exp
, Check_Typ
);
529 -- Next emit length checks for array aggregates
531 elsif Is_Array_Type
(Exp_Typ
) then
532 Apply_Length_Check
(Exp
, Check_Typ
);
534 -- Finally emit scalar and string checks. If we are dealing with a
535 -- scalar literal we need to check by hand because the Etype of
536 -- literals is not necessarily correct.
538 elsif Is_Scalar_Type
(Exp_Typ
)
539 and then Compile_Time_Known_Value
(Exp
)
541 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
542 Apply_Compile_Time_Constraint_Error
543 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
544 Ent
=> Base_Type
(Check_Typ
),
545 Typ
=> Base_Type
(Check_Typ
));
547 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
548 Apply_Compile_Time_Constraint_Error
549 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
553 elsif not Range_Checks_Suppressed
(Check_Typ
) then
554 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
557 -- Verify that target type is also scalar, to prevent view anomalies
558 -- in instantiations.
560 elsif (Is_Scalar_Type
(Exp_Typ
)
561 or else Nkind
(Exp
) = N_String_Literal
)
562 and then Is_Scalar_Type
(Check_Typ
)
563 and then Exp_Typ
/= Check_Typ
565 if Is_Entity_Name
(Exp
)
566 and then Ekind
(Entity
(Exp
)) = E_Constant
568 -- If expression is a constant, it is worthwhile checking whether
569 -- it is a bound of the type.
571 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
572 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
574 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
575 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
580 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
581 Analyze_And_Resolve
(Exp
, Check_Typ
);
582 Check_Unset_Reference
(Exp
);
585 -- Could use a comment on this case ???
588 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
589 Analyze_And_Resolve
(Exp
, Check_Typ
);
590 Check_Unset_Reference
(Exp
);
594 end Aggregate_Constraint_Checks
;
596 -----------------------
597 -- Alignment_In_Bits --
598 -----------------------
600 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
602 return Alignment
(E
) * System_Storage_Unit
;
603 end Alignment_In_Bits
;
605 ---------------------------------
606 -- Append_Inherited_Subprogram --
607 ---------------------------------
609 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
610 Par
: constant Entity_Id
:= Alias
(S
);
611 -- The parent subprogram
613 Scop
: constant Entity_Id
:= Scope
(Par
);
614 -- The scope of definition of the parent subprogram
616 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
617 -- The derived type of which S is a primitive operation
623 if Ekind
(Current_Scope
) = E_Package
624 and then In_Private_Part
(Current_Scope
)
625 and then Has_Private_Declaration
(Typ
)
626 and then Is_Tagged_Type
(Typ
)
627 and then Scop
= Current_Scope
629 -- The inherited operation is available at the earliest place after
630 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
631 -- relevant for type extensions. If the parent operation appears
632 -- after the type extension, the operation is not visible.
635 (Visible_Declarations
636 (Package_Specification
(Current_Scope
)));
637 while Present
(Decl
) loop
638 if Nkind
(Decl
) = N_Private_Extension_Declaration
639 and then Defining_Entity
(Decl
) = Typ
641 if Sloc
(Decl
) > Sloc
(Par
) then
642 Next_E
:= Next_Entity
(Par
);
643 Set_Next_Entity
(Par
, S
);
644 Set_Next_Entity
(S
, Next_E
);
656 -- If partial view is not a type extension, or it appears before the
657 -- subprogram declaration, insert normally at end of entity list.
659 Append_Entity
(S
, Current_Scope
);
660 end Append_Inherited_Subprogram
;
662 -----------------------------------------
663 -- Apply_Compile_Time_Constraint_Error --
664 -----------------------------------------
666 procedure Apply_Compile_Time_Constraint_Error
669 Reason
: RT_Exception_Code
;
670 Ent
: Entity_Id
:= Empty
;
671 Typ
: Entity_Id
:= Empty
;
672 Loc
: Source_Ptr
:= No_Location
;
673 Rep
: Boolean := True;
674 Warn
: Boolean := False)
676 Stat
: constant Boolean := Is_Static_Expression
(N
);
677 R_Stat
: constant Node_Id
:=
678 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
689 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
695 -- Now we replace the node by an N_Raise_Constraint_Error node
696 -- This does not need reanalyzing, so set it as analyzed now.
699 Set_Analyzed
(N
, True);
702 Set_Raises_Constraint_Error
(N
);
704 -- Now deal with possible local raise handling
706 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
708 -- If the original expression was marked as static, the result is
709 -- still marked as static, but the Raises_Constraint_Error flag is
710 -- always set so that further static evaluation is not attempted.
713 Set_Is_Static_Expression
(N
);
715 end Apply_Compile_Time_Constraint_Error
;
717 ---------------------------
718 -- Async_Readers_Enabled --
719 ---------------------------
721 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
723 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
724 end Async_Readers_Enabled
;
726 ---------------------------
727 -- Async_Writers_Enabled --
728 ---------------------------
730 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
732 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
733 end Async_Writers_Enabled
;
735 --------------------------------------
736 -- Available_Full_View_Of_Component --
737 --------------------------------------
739 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
740 ST
: constant Entity_Id
:= Scope
(T
);
741 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
743 return In_Open_Scopes
(ST
)
744 and then In_Open_Scopes
(SCT
)
745 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
746 end Available_Full_View_Of_Component
;
752 procedure Bad_Attribute
755 Warn
: Boolean := False)
758 Error_Msg_Warn
:= Warn
;
759 Error_Msg_N
("unrecognized attribute&<<", N
);
761 -- Check for possible misspelling
763 Error_Msg_Name_1
:= First_Attribute_Name
;
764 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
765 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
766 Error_Msg_N
-- CODEFIX
767 ("\possible misspelling of %<<", N
);
771 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
775 --------------------------------
776 -- Bad_Predicated_Subtype_Use --
777 --------------------------------
779 procedure Bad_Predicated_Subtype_Use
783 Suggest_Static
: Boolean := False)
788 -- Avoid cascaded errors
790 if Error_Posted
(N
) then
794 if Inside_A_Generic
then
795 Gen
:= Current_Scope
;
796 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
804 if Is_Generic_Formal
(Typ
)
805 and then Is_Discrete_Type
(Typ
)
807 Set_No_Predicate_On_Actual
(Typ
);
810 elsif Has_Predicates
(Typ
) then
811 if Is_Generic_Actual_Type
(Typ
) then
813 -- The restriction on loop parameters is only that the type
814 -- should have no dynamic predicates.
816 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
817 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
818 and then Is_OK_Static_Subtype
(Typ
)
823 Gen
:= Current_Scope
;
824 while not Is_Generic_Instance
(Gen
) loop
828 pragma Assert
(Present
(Gen
));
830 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
831 Error_Msg_Warn
:= SPARK_Mode
/= On
;
832 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
833 Error_Msg_F
("\Program_Error [<<", N
);
836 Make_Raise_Program_Error
(Sloc
(N
),
837 Reason
=> PE_Bad_Predicated_Generic_Type
));
840 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
844 Error_Msg_FE
(Msg
, N
, Typ
);
847 -- Emit an optional suggestion on how to remedy the error if the
848 -- context warrants it.
850 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
851 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
854 end Bad_Predicated_Subtype_Use
;
856 -----------------------------------------
857 -- Bad_Unordered_Enumeration_Reference --
858 -----------------------------------------
860 function Bad_Unordered_Enumeration_Reference
862 T
: Entity_Id
) return Boolean
865 return Is_Enumeration_Type
(T
)
866 and then Comes_From_Source
(N
)
867 and then Warn_On_Unordered_Enumeration_Type
868 and then not Has_Pragma_Ordered
(T
)
869 and then not In_Same_Extended_Unit
(N
, T
);
870 end Bad_Unordered_Enumeration_Reference
;
872 --------------------------
873 -- Build_Actual_Subtype --
874 --------------------------
876 function Build_Actual_Subtype
878 N
: Node_Or_Entity_Id
) return Node_Id
881 -- Normally Sloc (N), but may point to corresponding body in some cases
883 Constraints
: List_Id
;
889 Disc_Type
: Entity_Id
;
895 if Nkind
(N
) = N_Defining_Identifier
then
896 Obj
:= New_Occurrence_Of
(N
, Loc
);
898 -- If this is a formal parameter of a subprogram declaration, and
899 -- we are compiling the body, we want the declaration for the
900 -- actual subtype to carry the source position of the body, to
901 -- prevent anomalies in gdb when stepping through the code.
903 if Is_Formal
(N
) then
905 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
907 if Nkind
(Decl
) = N_Subprogram_Declaration
908 and then Present
(Corresponding_Body
(Decl
))
910 Loc
:= Sloc
(Corresponding_Body
(Decl
));
919 if Is_Array_Type
(T
) then
920 Constraints
:= New_List
;
921 for J
in 1 .. Number_Dimensions
(T
) loop
923 -- Build an array subtype declaration with the nominal subtype and
924 -- the bounds of the actual. Add the declaration in front of the
925 -- local declarations for the subprogram, for analysis before any
926 -- reference to the formal in the body.
929 Make_Attribute_Reference
(Loc
,
931 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
932 Attribute_Name
=> Name_First
,
933 Expressions
=> New_List
(
934 Make_Integer_Literal
(Loc
, J
)));
937 Make_Attribute_Reference
(Loc
,
939 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
940 Attribute_Name
=> Name_Last
,
941 Expressions
=> New_List
(
942 Make_Integer_Literal
(Loc
, J
)));
944 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
947 -- If the type has unknown discriminants there is no constrained
948 -- subtype to build. This is never called for a formal or for a
949 -- lhs, so returning the type is ok ???
951 elsif Has_Unknown_Discriminants
(T
) then
955 Constraints
:= New_List
;
957 -- Type T is a generic derived type, inherit the discriminants from
960 if Is_Private_Type
(T
)
961 and then No
(Full_View
(T
))
963 -- T was flagged as an error if it was declared as a formal
964 -- derived type with known discriminants. In this case there
965 -- is no need to look at the parent type since T already carries
966 -- its own discriminants.
968 and then not Error_Posted
(T
)
970 Disc_Type
:= Etype
(Base_Type
(T
));
975 Discr
:= First_Discriminant
(Disc_Type
);
976 while Present
(Discr
) loop
977 Append_To
(Constraints
,
978 Make_Selected_Component
(Loc
,
980 Duplicate_Subexpr_No_Checks
(Obj
),
981 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
982 Next_Discriminant
(Discr
);
986 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
987 Set_Is_Internal
(Subt
);
990 Make_Subtype_Declaration
(Loc
,
991 Defining_Identifier
=> Subt
,
992 Subtype_Indication
=>
993 Make_Subtype_Indication
(Loc
,
994 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
996 Make_Index_Or_Discriminant_Constraint
(Loc
,
997 Constraints
=> Constraints
)));
999 Mark_Rewrite_Insertion
(Decl
);
1001 end Build_Actual_Subtype
;
1003 ---------------------------------------
1004 -- Build_Actual_Subtype_Of_Component --
1005 ---------------------------------------
1007 function Build_Actual_Subtype_Of_Component
1009 N
: Node_Id
) return Node_Id
1011 Loc
: constant Source_Ptr
:= Sloc
(N
);
1012 P
: constant Node_Id
:= Prefix
(N
);
1015 Index_Typ
: Entity_Id
;
1017 Desig_Typ
: Entity_Id
;
1018 -- This is either a copy of T, or if T is an access type, then it is
1019 -- the directly designated type of this access type.
1021 function Build_Actual_Array_Constraint
return List_Id
;
1022 -- If one or more of the bounds of the component depends on
1023 -- discriminants, build actual constraint using the discriminants
1026 function Build_Actual_Record_Constraint
return List_Id
;
1027 -- Similar to previous one, for discriminated components constrained
1028 -- by the discriminant of the enclosing object.
1030 -----------------------------------
1031 -- Build_Actual_Array_Constraint --
1032 -----------------------------------
1034 function Build_Actual_Array_Constraint
return List_Id
is
1035 Constraints
: constant List_Id
:= New_List
;
1043 Indx
:= First_Index
(Desig_Typ
);
1044 while Present
(Indx
) loop
1045 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1046 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1048 if Denotes_Discriminant
(Old_Lo
) then
1050 Make_Selected_Component
(Loc
,
1051 Prefix
=> New_Copy_Tree
(P
),
1052 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1055 Lo
:= New_Copy_Tree
(Old_Lo
);
1057 -- The new bound will be reanalyzed in the enclosing
1058 -- declaration. For literal bounds that come from a type
1059 -- declaration, the type of the context must be imposed, so
1060 -- insure that analysis will take place. For non-universal
1061 -- types this is not strictly necessary.
1063 Set_Analyzed
(Lo
, False);
1066 if Denotes_Discriminant
(Old_Hi
) then
1068 Make_Selected_Component
(Loc
,
1069 Prefix
=> New_Copy_Tree
(P
),
1070 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1073 Hi
:= New_Copy_Tree
(Old_Hi
);
1074 Set_Analyzed
(Hi
, False);
1077 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1082 end Build_Actual_Array_Constraint
;
1084 ------------------------------------
1085 -- Build_Actual_Record_Constraint --
1086 ------------------------------------
1088 function Build_Actual_Record_Constraint
return List_Id
is
1089 Constraints
: constant List_Id
:= New_List
;
1094 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1095 while Present
(D
) loop
1096 if Denotes_Discriminant
(Node
(D
)) then
1097 D_Val
:= Make_Selected_Component
(Loc
,
1098 Prefix
=> New_Copy_Tree
(P
),
1099 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1102 D_Val
:= New_Copy_Tree
(Node
(D
));
1105 Append
(D_Val
, Constraints
);
1110 end Build_Actual_Record_Constraint
;
1112 -- Start of processing for Build_Actual_Subtype_Of_Component
1115 -- Why the test for Spec_Expression mode here???
1117 if In_Spec_Expression
then
1120 -- More comments for the rest of this body would be good ???
1122 elsif Nkind
(N
) = N_Explicit_Dereference
then
1123 if Is_Composite_Type
(T
)
1124 and then not Is_Constrained
(T
)
1125 and then not (Is_Class_Wide_Type
(T
)
1126 and then Is_Constrained
(Root_Type
(T
)))
1127 and then not Has_Unknown_Discriminants
(T
)
1129 -- If the type of the dereference is already constrained, it is an
1132 if Is_Array_Type
(Etype
(N
))
1133 and then Is_Constrained
(Etype
(N
))
1137 Remove_Side_Effects
(P
);
1138 return Build_Actual_Subtype
(T
, N
);
1145 if Ekind
(T
) = E_Access_Subtype
then
1146 Desig_Typ
:= Designated_Type
(T
);
1151 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1152 Id
:= First_Index
(Desig_Typ
);
1153 while Present
(Id
) loop
1154 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1156 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1158 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1160 Remove_Side_Effects
(P
);
1162 Build_Component_Subtype
1163 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1169 elsif Is_Composite_Type
(Desig_Typ
)
1170 and then Has_Discriminants
(Desig_Typ
)
1171 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1173 if Is_Private_Type
(Desig_Typ
)
1174 and then No
(Discriminant_Constraint
(Desig_Typ
))
1176 Desig_Typ
:= Full_View
(Desig_Typ
);
1179 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1180 while Present
(D
) loop
1181 if Denotes_Discriminant
(Node
(D
)) then
1182 Remove_Side_Effects
(P
);
1184 Build_Component_Subtype
(
1185 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1192 -- If none of the above, the actual and nominal subtypes are the same
1195 end Build_Actual_Subtype_Of_Component
;
1197 -----------------------------
1198 -- Build_Component_Subtype --
1199 -----------------------------
1201 function Build_Component_Subtype
1204 T
: Entity_Id
) return Node_Id
1210 -- Unchecked_Union components do not require component subtypes
1212 if Is_Unchecked_Union
(T
) then
1216 Subt
:= Make_Temporary
(Loc
, 'S');
1217 Set_Is_Internal
(Subt
);
1220 Make_Subtype_Declaration
(Loc
,
1221 Defining_Identifier
=> Subt
,
1222 Subtype_Indication
=>
1223 Make_Subtype_Indication
(Loc
,
1224 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1226 Make_Index_Or_Discriminant_Constraint
(Loc
,
1227 Constraints
=> C
)));
1229 Mark_Rewrite_Insertion
(Decl
);
1231 end Build_Component_Subtype
;
1233 ----------------------------------
1234 -- Build_Default_Init_Cond_Call --
1235 ----------------------------------
1237 function Build_Default_Init_Cond_Call
1240 Typ
: Entity_Id
) return Node_Id
1242 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1243 Formal_Typ
: constant Entity_Id
:= Etype
(First_Formal
(Proc_Id
));
1247 Make_Procedure_Call_Statement
(Loc
,
1248 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
1249 Parameter_Associations
=> New_List
(
1250 Make_Type_Conversion
(Loc
,
1251 Subtype_Mark
=> New_Occurrence_Of
(Formal_Typ
, Loc
),
1252 Expression
=> New_Occurrence_Of
(Obj_Id
, Loc
))));
1253 end Build_Default_Init_Cond_Call
;
1255 ----------------------------------------------
1256 -- Build_Default_Init_Cond_Procedure_Bodies --
1257 ----------------------------------------------
1259 procedure Build_Default_Init_Cond_Procedure_Bodies
(Priv_Decls
: List_Id
) is
1260 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
);
1261 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1262 -- body of the procedure which verifies the assumption of the pragma at
1263 -- run time. The generated body is added after the type declaration.
1265 --------------------------------------------
1266 -- Build_Default_Init_Cond_Procedure_Body --
1267 --------------------------------------------
1269 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
) is
1270 Param_Id
: Entity_Id
;
1271 -- The entity of the sole formal parameter of the default initial
1272 -- condition procedure.
1274 procedure Replace_Type_Reference
(N
: Node_Id
);
1275 -- Replace a single reference to type Typ with a reference to formal
1276 -- parameter Param_Id.
1278 ----------------------------
1279 -- Replace_Type_Reference --
1280 ----------------------------
1282 procedure Replace_Type_Reference
(N
: Node_Id
) is
1284 Rewrite
(N
, New_Occurrence_Of
(Param_Id
, Sloc
(N
)));
1285 end Replace_Type_Reference
;
1287 procedure Replace_Type_References
is
1288 new Replace_Type_References_Generic
(Replace_Type_Reference
);
1292 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1293 Prag
: constant Node_Id
:=
1294 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1295 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1296 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Proc_Id
);
1297 Body_Decl
: Node_Id
;
1301 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1304 -- The procedure should be generated only for [sub]types subject to
1305 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1306 -- not get this specialized procedure.
1308 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1309 pragma Assert
(Present
(Prag
));
1310 pragma Assert
(Present
(Proc_Id
));
1312 -- Nothing to do if the body was already built
1314 if Present
(Corresponding_Body
(Spec_Decl
)) then
1318 Param_Id
:= First_Formal
(Proc_Id
);
1320 -- The pragma has an argument. Note that the argument is analyzed
1321 -- after all references to the current instance of the type are
1324 if Present
(Pragma_Argument_Associations
(Prag
)) then
1326 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
1328 if Nkind
(Expr
) = N_Null
then
1329 Stmt
:= Make_Null_Statement
(Loc
);
1331 -- Preserve the original argument of the pragma by replicating it.
1332 -- Replace all references to the current instance of the type with
1333 -- references to the formal parameter.
1336 Expr
:= New_Copy_Tree
(Expr
);
1337 Replace_Type_References
(Expr
, Typ
);
1340 -- pragma Check (Default_Initial_Condition, <Expr>);
1344 Pragma_Identifier
=>
1345 Make_Identifier
(Loc
, Name_Check
),
1347 Pragma_Argument_Associations
=> New_List
(
1348 Make_Pragma_Argument_Association
(Loc
,
1350 Make_Identifier
(Loc
,
1351 Chars
=> Name_Default_Initial_Condition
)),
1352 Make_Pragma_Argument_Association
(Loc
,
1353 Expression
=> Expr
)));
1356 -- Otherwise the pragma appears without an argument
1359 Stmt
:= Make_Null_Statement
(Loc
);
1363 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1366 -- end <Typ>Default_Init_Cond;
1369 Make_Subprogram_Body
(Loc
,
1371 Copy_Separate_Tree
(Specification
(Spec_Decl
)),
1372 Declarations
=> Empty_List
,
1373 Handled_Statement_Sequence
=>
1374 Make_Handled_Sequence_Of_Statements
(Loc
,
1375 Statements
=> New_List
(Stmt
)));
1377 -- Link the spec and body of the default initial condition procedure
1378 -- to prevent the generation of a duplicate body.
1380 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
1381 Set_Corresponding_Spec
(Body_Decl
, Proc_Id
);
1383 Insert_After_And_Analyze
(Declaration_Node
(Typ
), Body_Decl
);
1384 end Build_Default_Init_Cond_Procedure_Body
;
1391 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1394 -- Inspect the private declarations looking for [sub]type declarations
1396 Decl
:= First
(Priv_Decls
);
1397 while Present
(Decl
) loop
1398 if Nkind_In
(Decl
, N_Full_Type_Declaration
,
1399 N_Subtype_Declaration
)
1401 Typ
:= Defining_Entity
(Decl
);
1403 -- Guard against partially decorate types due to previous errors
1405 if Is_Type
(Typ
) then
1407 -- If the type is subject to pragma Default_Initial_Condition,
1408 -- generate the body of the internal procedure which verifies
1409 -- the assertion of the pragma at run time.
1411 if Has_Default_Init_Cond
(Typ
) then
1412 Build_Default_Init_Cond_Procedure_Body
(Typ
);
1414 -- A derived type inherits the default initial condition
1415 -- procedure from its parent type.
1417 elsif Has_Inherited_Default_Init_Cond
(Typ
) then
1418 Inherit_Default_Init_Cond_Procedure
(Typ
);
1425 end Build_Default_Init_Cond_Procedure_Bodies
;
1427 ---------------------------------------------------
1428 -- Build_Default_Init_Cond_Procedure_Declaration --
1429 ---------------------------------------------------
1431 procedure Build_Default_Init_Cond_Procedure_Declaration
(Typ
: Entity_Id
) is
1432 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1433 Prag
: constant Node_Id
:=
1434 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1435 Proc_Id
: Entity_Id
;
1438 -- The procedure should be generated only for types subject to pragma
1439 -- Default_Initial_Condition. Types that inherit the pragma do not get
1440 -- this specialized procedure.
1442 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1443 pragma Assert
(Present
(Prag
));
1446 Make_Defining_Identifier
(Loc
,
1447 Chars
=> New_External_Name
(Chars
(Typ
), "Default_Init_Cond"));
1449 -- Associate default initial condition procedure with the private type
1451 Set_Ekind
(Proc_Id
, E_Procedure
);
1452 Set_Is_Default_Init_Cond_Procedure
(Proc_Id
);
1453 Set_Default_Init_Cond_Procedure
(Typ
, Proc_Id
);
1456 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1458 Insert_After_And_Analyze
(Prag
,
1459 Make_Subprogram_Declaration
(Loc
,
1461 Make_Procedure_Specification
(Loc
,
1462 Defining_Unit_Name
=> Proc_Id
,
1463 Parameter_Specifications
=> New_List
(
1464 Make_Parameter_Specification
(Loc
,
1465 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
1466 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))))));
1467 end Build_Default_Init_Cond_Procedure_Declaration
;
1469 ---------------------------
1470 -- Build_Default_Subtype --
1471 ---------------------------
1473 function Build_Default_Subtype
1475 N
: Node_Id
) return Entity_Id
1477 Loc
: constant Source_Ptr
:= Sloc
(N
);
1481 -- The base type that is to be constrained by the defaults
1484 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1488 Bas
:= Base_Type
(T
);
1490 -- If T is non-private but its base type is private, this is the
1491 -- completion of a subtype declaration whose parent type is private
1492 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1493 -- are to be found in the full view of the base. Check that the private
1494 -- status of T and its base differ.
1496 if Is_Private_Type
(Bas
)
1497 and then not Is_Private_Type
(T
)
1498 and then Present
(Full_View
(Bas
))
1500 Bas
:= Full_View
(Bas
);
1503 Disc
:= First_Discriminant
(T
);
1505 if No
(Discriminant_Default_Value
(Disc
)) then
1510 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1511 Constraints
: constant List_Id
:= New_List
;
1515 while Present
(Disc
) loop
1516 Append_To
(Constraints
,
1517 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1518 Next_Discriminant
(Disc
);
1522 Make_Subtype_Declaration
(Loc
,
1523 Defining_Identifier
=> Act
,
1524 Subtype_Indication
=>
1525 Make_Subtype_Indication
(Loc
,
1526 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1528 Make_Index_Or_Discriminant_Constraint
(Loc
,
1529 Constraints
=> Constraints
)));
1531 Insert_Action
(N
, Decl
);
1535 end Build_Default_Subtype
;
1537 --------------------------------------------
1538 -- Build_Discriminal_Subtype_Of_Component --
1539 --------------------------------------------
1541 function Build_Discriminal_Subtype_Of_Component
1542 (T
: Entity_Id
) return Node_Id
1544 Loc
: constant Source_Ptr
:= Sloc
(T
);
1548 function Build_Discriminal_Array_Constraint
return List_Id
;
1549 -- If one or more of the bounds of the component depends on
1550 -- discriminants, build actual constraint using the discriminants
1553 function Build_Discriminal_Record_Constraint
return List_Id
;
1554 -- Similar to previous one, for discriminated components constrained by
1555 -- the discriminant of the enclosing object.
1557 ----------------------------------------
1558 -- Build_Discriminal_Array_Constraint --
1559 ----------------------------------------
1561 function Build_Discriminal_Array_Constraint
return List_Id
is
1562 Constraints
: constant List_Id
:= New_List
;
1570 Indx
:= First_Index
(T
);
1571 while Present
(Indx
) loop
1572 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1573 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1575 if Denotes_Discriminant
(Old_Lo
) then
1576 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1579 Lo
:= New_Copy_Tree
(Old_Lo
);
1582 if Denotes_Discriminant
(Old_Hi
) then
1583 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1586 Hi
:= New_Copy_Tree
(Old_Hi
);
1589 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1594 end Build_Discriminal_Array_Constraint
;
1596 -----------------------------------------
1597 -- Build_Discriminal_Record_Constraint --
1598 -----------------------------------------
1600 function Build_Discriminal_Record_Constraint
return List_Id
is
1601 Constraints
: constant List_Id
:= New_List
;
1606 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1607 while Present
(D
) loop
1608 if Denotes_Discriminant
(Node
(D
)) then
1610 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1612 D_Val
:= New_Copy_Tree
(Node
(D
));
1615 Append
(D_Val
, Constraints
);
1620 end Build_Discriminal_Record_Constraint
;
1622 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1625 if Ekind
(T
) = E_Array_Subtype
then
1626 Id
:= First_Index
(T
);
1627 while Present
(Id
) loop
1628 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1630 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1632 return Build_Component_Subtype
1633 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1639 elsif Ekind
(T
) = E_Record_Subtype
1640 and then Has_Discriminants
(T
)
1641 and then not Has_Unknown_Discriminants
(T
)
1643 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1644 while Present
(D
) loop
1645 if Denotes_Discriminant
(Node
(D
)) then
1646 return Build_Component_Subtype
1647 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1654 -- If none of the above, the actual and nominal subtypes are the same
1657 end Build_Discriminal_Subtype_Of_Component
;
1659 ------------------------------
1660 -- Build_Elaboration_Entity --
1661 ------------------------------
1663 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1664 Loc
: constant Source_Ptr
:= Sloc
(N
);
1666 Elab_Ent
: Entity_Id
;
1668 procedure Set_Package_Name
(Ent
: Entity_Id
);
1669 -- Given an entity, sets the fully qualified name of the entity in
1670 -- Name_Buffer, with components separated by double underscores. This
1671 -- is a recursive routine that climbs the scope chain to Standard.
1673 ----------------------
1674 -- Set_Package_Name --
1675 ----------------------
1677 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1679 if Scope
(Ent
) /= Standard_Standard
then
1680 Set_Package_Name
(Scope
(Ent
));
1683 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1685 Name_Buffer
(Name_Len
+ 1) := '_';
1686 Name_Buffer
(Name_Len
+ 2) := '_';
1687 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1688 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1692 Get_Name_String
(Chars
(Ent
));
1694 end Set_Package_Name
;
1696 -- Start of processing for Build_Elaboration_Entity
1699 -- Ignore call if already constructed
1701 if Present
(Elaboration_Entity
(Spec_Id
)) then
1704 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1705 -- no role in analysis.
1707 elsif ASIS_Mode
then
1710 -- See if we need elaboration entity. We always need it for the dynamic
1711 -- elaboration model, since it is needed to properly generate the PE
1712 -- exception for access before elaboration.
1714 elsif Dynamic_Elaboration_Checks
then
1717 -- For the static model, we don't need the elaboration counter if this
1718 -- unit is sure to have no elaboration code, since that means there
1719 -- is no elaboration unit to be called. Note that we can't just decide
1720 -- after the fact by looking to see whether there was elaboration code,
1721 -- because that's too late to make this decision.
1723 elsif Restriction_Active
(No_Elaboration_Code
) then
1726 -- Similarly, for the static model, we can skip the elaboration counter
1727 -- if we have the No_Multiple_Elaboration restriction, since for the
1728 -- static model, that's the only purpose of the counter (to avoid
1729 -- multiple elaboration).
1731 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1735 -- Here we need the elaboration entity
1737 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1738 -- name with dots replaced by double underscore. We have to manually
1739 -- construct this name, since it will be elaborated in the outer scope,
1740 -- and thus will not have the unit name automatically prepended.
1742 Set_Package_Name
(Spec_Id
);
1743 Add_Str_To_Name_Buffer
("_E");
1745 -- Create elaboration counter
1747 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1748 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1751 Make_Object_Declaration
(Loc
,
1752 Defining_Identifier
=> Elab_Ent
,
1753 Object_Definition
=>
1754 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1755 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1757 Push_Scope
(Standard_Standard
);
1758 Add_Global_Declaration
(Decl
);
1761 -- Reset True_Constant indication, since we will indeed assign a value
1762 -- to the variable in the binder main. We also kill the Current_Value
1763 -- and Last_Assignment fields for the same reason.
1765 Set_Is_True_Constant
(Elab_Ent
, False);
1766 Set_Current_Value
(Elab_Ent
, Empty
);
1767 Set_Last_Assignment
(Elab_Ent
, Empty
);
1769 -- We do not want any further qualification of the name (if we did not
1770 -- do this, we would pick up the name of the generic package in the case
1771 -- of a library level generic instantiation).
1773 Set_Has_Qualified_Name
(Elab_Ent
);
1774 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1775 end Build_Elaboration_Entity
;
1777 --------------------------------
1778 -- Build_Explicit_Dereference --
1779 --------------------------------
1781 procedure Build_Explicit_Dereference
1785 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1788 -- An entity of a type with a reference aspect is overloaded with
1789 -- both interpretations: with and without the dereference. Now that
1790 -- the dereference is made explicit, set the type of the node properly,
1791 -- to prevent anomalies in the backend. Same if the expression is an
1792 -- overloaded function call whose return type has a reference aspect.
1794 if Is_Entity_Name
(Expr
) then
1795 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1797 elsif Nkind
(Expr
) = N_Function_Call
then
1798 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1801 Set_Is_Overloaded
(Expr
, False);
1803 -- The expression will often be a generalized indexing that yields a
1804 -- container element that is then dereferenced, in which case the
1805 -- generalized indexing call is also non-overloaded.
1807 if Nkind
(Expr
) = N_Indexed_Component
1808 and then Present
(Generalized_Indexing
(Expr
))
1810 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1814 Make_Explicit_Dereference
(Loc
,
1816 Make_Selected_Component
(Loc
,
1817 Prefix
=> Relocate_Node
(Expr
),
1818 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1819 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1820 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1821 end Build_Explicit_Dereference
;
1823 -----------------------------------
1824 -- Cannot_Raise_Constraint_Error --
1825 -----------------------------------
1827 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1829 if Compile_Time_Known_Value
(Expr
) then
1832 elsif Do_Range_Check
(Expr
) then
1835 elsif Raises_Constraint_Error
(Expr
) then
1839 case Nkind
(Expr
) is
1840 when N_Identifier
=>
1843 when N_Expanded_Name
=>
1846 when N_Selected_Component
=>
1847 return not Do_Discriminant_Check
(Expr
);
1849 when N_Attribute_Reference
=>
1850 if Do_Overflow_Check
(Expr
) then
1853 elsif No
(Expressions
(Expr
)) then
1861 N
:= First
(Expressions
(Expr
));
1862 while Present
(N
) loop
1863 if Cannot_Raise_Constraint_Error
(N
) then
1874 when N_Type_Conversion
=>
1875 if Do_Overflow_Check
(Expr
)
1876 or else Do_Length_Check
(Expr
)
1877 or else Do_Tag_Check
(Expr
)
1881 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1884 when N_Unchecked_Type_Conversion
=>
1885 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1888 if Do_Overflow_Check
(Expr
) then
1891 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1898 if Do_Division_Check
(Expr
)
1900 Do_Overflow_Check
(Expr
)
1905 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1907 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1926 N_Op_Shift_Right_Arithmetic |
1930 if Do_Overflow_Check
(Expr
) then
1934 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1936 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1943 end Cannot_Raise_Constraint_Error
;
1945 -----------------------------------------
1946 -- Check_Dynamically_Tagged_Expression --
1947 -----------------------------------------
1949 procedure Check_Dynamically_Tagged_Expression
1952 Related_Nod
: Node_Id
)
1955 pragma Assert
(Is_Tagged_Type
(Typ
));
1957 -- In order to avoid spurious errors when analyzing the expanded code,
1958 -- this check is done only for nodes that come from source and for
1959 -- actuals of generic instantiations.
1961 if (Comes_From_Source
(Related_Nod
)
1962 or else In_Generic_Actual
(Expr
))
1963 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1964 or else Is_Dynamically_Tagged
(Expr
))
1965 and then Is_Tagged_Type
(Typ
)
1966 and then not Is_Class_Wide_Type
(Typ
)
1968 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1970 end Check_Dynamically_Tagged_Expression
;
1972 --------------------------
1973 -- Check_Fully_Declared --
1974 --------------------------
1976 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1978 if Ekind
(T
) = E_Incomplete_Type
then
1980 -- Ada 2005 (AI-50217): If the type is available through a limited
1981 -- with_clause, verify that its full view has been analyzed.
1983 if From_Limited_With
(T
)
1984 and then Present
(Non_Limited_View
(T
))
1985 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1987 -- The non-limited view is fully declared
1992 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1995 -- Need comments for these tests ???
1997 elsif Has_Private_Component
(T
)
1998 and then not Is_Generic_Type
(Root_Type
(T
))
1999 and then not In_Spec_Expression
2001 -- Special case: if T is the anonymous type created for a single
2002 -- task or protected object, use the name of the source object.
2004 if Is_Concurrent_Type
(T
)
2005 and then not Comes_From_Source
(T
)
2006 and then Nkind
(N
) = N_Object_Declaration
2009 ("type of& has incomplete component",
2010 N
, Defining_Identifier
(N
));
2013 ("premature usage of incomplete}",
2014 N
, First_Subtype
(T
));
2017 end Check_Fully_Declared
;
2019 -------------------------------------
2020 -- Check_Function_Writable_Actuals --
2021 -------------------------------------
2023 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2024 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2025 Identifiers_List
: Elist_Id
:= No_Elist
;
2026 Error_Node
: Node_Id
:= Empty
;
2028 procedure Collect_Identifiers
(N
: Node_Id
);
2029 -- In a single traversal of subtree N collect in Writable_Actuals_List
2030 -- all the actuals of functions with writable actuals, and in the list
2031 -- Identifiers_List collect all the identifiers that are not actuals of
2032 -- functions with writable actuals. If a writable actual is referenced
2033 -- twice as writable actual then Error_Node is set to reference its
2034 -- second occurrence, the error is reported, and the tree traversal
2037 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
2038 -- Return the entity associated with the function call
2040 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2041 -- Preanalyze N without reporting errors. Very dubious, you can't just
2042 -- go analyzing things more than once???
2044 -------------------------
2045 -- Collect_Identifiers --
2046 -------------------------
2048 procedure Collect_Identifiers
(N
: Node_Id
) is
2050 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2051 -- Process a single node during the tree traversal to collect the
2052 -- writable actuals of functions and all the identifiers which are
2053 -- not writable actuals of functions.
2055 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2056 -- Returns True if List has a node whose Entity is Entity (N)
2058 -------------------------
2059 -- Check_Function_Call --
2060 -------------------------
2062 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2063 Is_Writable_Actual
: Boolean := False;
2067 if Nkind
(N
) = N_Identifier
then
2069 -- No analysis possible if the entity is not decorated
2071 if No
(Entity
(N
)) then
2074 -- Don't collect identifiers of packages, called functions, etc
2076 elsif Ekind_In
(Entity
(N
), E_Package
,
2083 -- Analyze if N is a writable actual of a function
2085 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2087 Call
: constant Node_Id
:= Parent
(N
);
2092 Id
:= Get_Function_Id
(Call
);
2094 Formal
:= First_Formal
(Id
);
2095 Actual
:= First_Actual
(Call
);
2096 while Present
(Actual
) and then Present
(Formal
) loop
2098 if Ekind_In
(Formal
, E_Out_Parameter
,
2101 Is_Writable_Actual
:= True;
2107 Next_Formal
(Formal
);
2108 Next_Actual
(Actual
);
2113 if Is_Writable_Actual
then
2114 if Contains
(Writable_Actuals_List
, N
) then
2116 ("value may be affected by call to& "
2117 & "because order of evaluation is arbitrary", N
, Id
);
2122 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2125 if Identifiers_List
= No_Elist
then
2126 Identifiers_List
:= New_Elmt_List
;
2129 Append_Unique_Elmt
(N
, Identifiers_List
);
2142 N
: Node_Id
) return Boolean
2144 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2149 if List
= No_Elist
then
2153 Elmt
:= First_Elmt
(List
);
2154 while Present
(Elmt
) loop
2155 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2169 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2170 -- The traversal procedure
2172 -- Start of processing for Collect_Identifiers
2175 if Present
(Error_Node
) then
2179 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2184 end Collect_Identifiers
;
2186 ---------------------
2187 -- Get_Function_Id --
2188 ---------------------
2190 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
2191 Nam
: constant Node_Id
:= Name
(Call
);
2195 if Nkind
(Nam
) = N_Explicit_Dereference
then
2197 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
2199 elsif Nkind
(Nam
) = N_Selected_Component
then
2200 Id
:= Entity
(Selector_Name
(Nam
));
2202 elsif Nkind
(Nam
) = N_Indexed_Component
then
2203 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
2210 end Get_Function_Id
;
2212 ---------------------------
2213 -- Preanalyze_Expression --
2214 ---------------------------
2216 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2217 Status
: constant Boolean := Get_Ignore_Errors
;
2219 Set_Ignore_Errors
(True);
2221 Set_Ignore_Errors
(Status
);
2222 end Preanalyze_Without_Errors
;
2224 -- Start of processing for Check_Function_Writable_Actuals
2227 -- The check only applies to Ada 2012 code, and only to constructs that
2228 -- have multiple constituents whose order of evaluation is not specified
2231 if Ada_Version
< Ada_2012
2232 or else (not (Nkind
(N
) in N_Op
)
2233 and then not (Nkind
(N
) in N_Membership_Test
)
2234 and then not Nkind_In
(N
, N_Range
,
2236 N_Extension_Aggregate
,
2237 N_Full_Type_Declaration
,
2239 N_Procedure_Call_Statement
,
2240 N_Entry_Call_Statement
))
2241 or else (Nkind
(N
) = N_Full_Type_Declaration
2242 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2244 -- In addition, this check only applies to source code, not to code
2245 -- generated by constraint checks.
2247 or else not Comes_From_Source
(N
)
2252 -- If a construct C has two or more direct constituents that are names
2253 -- or expressions whose evaluation may occur in an arbitrary order, at
2254 -- least one of which contains a function call with an in out or out
2255 -- parameter, then the construct is legal only if: for each name N that
2256 -- is passed as a parameter of mode in out or out to some inner function
2257 -- call C2 (not including the construct C itself), there is no other
2258 -- name anywhere within a direct constituent of the construct C other
2259 -- than the one containing C2, that is known to refer to the same
2260 -- object (RM 6.4.1(6.17/3)).
2264 Collect_Identifiers
(Low_Bound
(N
));
2265 Collect_Identifiers
(High_Bound
(N
));
2267 when N_Op | N_Membership_Test
=>
2272 Collect_Identifiers
(Left_Opnd
(N
));
2274 if Present
(Right_Opnd
(N
)) then
2275 Collect_Identifiers
(Right_Opnd
(N
));
2278 if Nkind_In
(N
, N_In
, N_Not_In
)
2279 and then Present
(Alternatives
(N
))
2281 Expr
:= First
(Alternatives
(N
));
2282 while Present
(Expr
) loop
2283 Collect_Identifiers
(Expr
);
2290 when N_Full_Type_Declaration
=>
2292 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2293 -- Return the record part of this record type definition
2295 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2296 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2298 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2299 return Record_Extension_Part
(Type_Def
);
2303 end Get_Record_Part
;
2306 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2307 Rec
: Node_Id
:= Get_Record_Part
(N
);
2310 -- No need to perform any analysis if the record has no
2313 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2317 -- Collect the identifiers starting from the deepest
2318 -- derivation. Done to report the error in the deepest
2322 if Present
(Component_List
(Rec
)) then
2323 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2324 while Present
(Comp
) loop
2325 if Nkind
(Comp
) = N_Component_Declaration
2326 and then Present
(Expression
(Comp
))
2328 Collect_Identifiers
(Expression
(Comp
));
2335 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2336 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2339 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2340 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2344 when N_Subprogram_Call |
2345 N_Entry_Call_Statement
=>
2347 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
2352 Formal
:= First_Formal
(Id
);
2353 Actual
:= First_Actual
(N
);
2354 while Present
(Actual
) and then Present
(Formal
) loop
2355 if Ekind_In
(Formal
, E_Out_Parameter
,
2358 Collect_Identifiers
(Actual
);
2361 Next_Formal
(Formal
);
2362 Next_Actual
(Actual
);
2367 N_Extension_Aggregate
=>
2371 Comp_Expr
: Node_Id
;
2374 -- Handle the N_Others_Choice of array aggregates with static
2375 -- bounds. There is no need to perform this analysis in
2376 -- aggregates without static bounds since we cannot evaluate
2377 -- if the N_Others_Choice covers several elements. There is
2378 -- no need to handle the N_Others choice of record aggregates
2379 -- since at this stage it has been already expanded by
2380 -- Resolve_Record_Aggregate.
2382 if Is_Array_Type
(Etype
(N
))
2383 and then Nkind
(N
) = N_Aggregate
2384 and then Present
(Aggregate_Bounds
(N
))
2385 and then Compile_Time_Known_Bounds
(Etype
(N
))
2386 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2388 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2391 Count_Components
: Uint
:= Uint_0
;
2392 Num_Components
: Uint
;
2393 Others_Assoc
: Node_Id
;
2394 Others_Choice
: Node_Id
:= Empty
;
2395 Others_Box_Present
: Boolean := False;
2398 -- Count positional associations
2400 if Present
(Expressions
(N
)) then
2401 Comp_Expr
:= First
(Expressions
(N
));
2402 while Present
(Comp_Expr
) loop
2403 Count_Components
:= Count_Components
+ 1;
2408 -- Count the rest of elements and locate the N_Others
2411 Assoc
:= First
(Component_Associations
(N
));
2412 while Present
(Assoc
) loop
2413 Choice
:= First
(Choices
(Assoc
));
2414 while Present
(Choice
) loop
2415 if Nkind
(Choice
) = N_Others_Choice
then
2416 Others_Assoc
:= Assoc
;
2417 Others_Choice
:= Choice
;
2418 Others_Box_Present
:= Box_Present
(Assoc
);
2420 -- Count several components
2422 elsif Nkind_In
(Choice
, N_Range
,
2423 N_Subtype_Indication
)
2424 or else (Is_Entity_Name
(Choice
)
2425 and then Is_Type
(Entity
(Choice
)))
2430 Get_Index_Bounds
(Choice
, L
, H
);
2432 (Compile_Time_Known_Value
(L
)
2433 and then Compile_Time_Known_Value
(H
));
2436 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2439 -- Count single component. No other case available
2440 -- since we are handling an aggregate with static
2444 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2445 or else Nkind
(Choice
) = N_Identifier
2446 or else Nkind
(Choice
) = N_Integer_Literal
);
2448 Count_Components
:= Count_Components
+ 1;
2458 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2459 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2461 pragma Assert
(Count_Components
<= Num_Components
);
2463 -- Handle the N_Others choice if it covers several
2466 if Present
(Others_Choice
)
2467 and then (Num_Components
- Count_Components
) > 1
2469 if not Others_Box_Present
then
2471 -- At this stage, if expansion is active, the
2472 -- expression of the others choice has not been
2473 -- analyzed. Hence we generate a duplicate and
2474 -- we analyze it silently to have available the
2475 -- minimum decoration required to collect the
2478 if not Expander_Active
then
2479 Comp_Expr
:= Expression
(Others_Assoc
);
2482 New_Copy_Tree
(Expression
(Others_Assoc
));
2483 Preanalyze_Without_Errors
(Comp_Expr
);
2486 Collect_Identifiers
(Comp_Expr
);
2488 if Writable_Actuals_List
/= No_Elist
then
2490 -- As suggested by Robert, at current stage we
2491 -- report occurrences of this case as warnings.
2494 ("writable function parameter may affect "
2495 & "value in other component because order "
2496 & "of evaluation is unspecified??",
2497 Node
(First_Elmt
(Writable_Actuals_List
)));
2504 -- Handle ancestor part of extension aggregates
2506 if Nkind
(N
) = N_Extension_Aggregate
then
2507 Collect_Identifiers
(Ancestor_Part
(N
));
2510 -- Handle positional associations
2512 if Present
(Expressions
(N
)) then
2513 Comp_Expr
:= First
(Expressions
(N
));
2514 while Present
(Comp_Expr
) loop
2515 if not Is_OK_Static_Expression
(Comp_Expr
) then
2516 Collect_Identifiers
(Comp_Expr
);
2523 -- Handle discrete associations
2525 if Present
(Component_Associations
(N
)) then
2526 Assoc
:= First
(Component_Associations
(N
));
2527 while Present
(Assoc
) loop
2529 if not Box_Present
(Assoc
) then
2530 Choice
:= First
(Choices
(Assoc
));
2531 while Present
(Choice
) loop
2533 -- For now we skip discriminants since it requires
2534 -- performing the analysis in two phases: first one
2535 -- analyzing discriminants and second one analyzing
2536 -- the rest of components since discriminants are
2537 -- evaluated prior to components: too much extra
2538 -- work to detect a corner case???
2540 if Nkind
(Choice
) in N_Has_Entity
2541 and then Present
(Entity
(Choice
))
2542 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2546 elsif Box_Present
(Assoc
) then
2550 if not Analyzed
(Expression
(Assoc
)) then
2552 New_Copy_Tree
(Expression
(Assoc
));
2553 Set_Parent
(Comp_Expr
, Parent
(N
));
2554 Preanalyze_Without_Errors
(Comp_Expr
);
2556 Comp_Expr
:= Expression
(Assoc
);
2559 Collect_Identifiers
(Comp_Expr
);
2575 -- No further action needed if we already reported an error
2577 if Present
(Error_Node
) then
2581 -- Check if some writable argument of a function is referenced
2583 if Writable_Actuals_List
/= No_Elist
2584 and then Identifiers_List
/= No_Elist
2591 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2592 while Present
(Elmt_1
) loop
2593 Elmt_2
:= First_Elmt
(Identifiers_List
);
2594 while Present
(Elmt_2
) loop
2595 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2596 case Nkind
(Parent
(Node
(Elmt_2
))) is
2598 N_Component_Association |
2599 N_Component_Declaration
=>
2601 ("value may be affected by call in other "
2602 & "component because they are evaluated "
2603 & "in unspecified order",
2606 when N_In | N_Not_In
=>
2608 ("value may be affected by call in other "
2609 & "alternative because they are evaluated "
2610 & "in unspecified order",
2615 ("value of actual may be affected by call in "
2616 & "other actual because they are evaluated "
2617 & "in unspecified order",
2629 end Check_Function_Writable_Actuals
;
2631 --------------------------------
2632 -- Check_Implicit_Dereference --
2633 --------------------------------
2635 procedure Check_Implicit_Dereference
(Nam
: Node_Id
; Typ
: Entity_Id
) is
2640 if Ada_Version
< Ada_2012
2641 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2645 elsif not Comes_From_Source
(Nam
) then
2648 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2652 Disc
:= First_Discriminant
(Typ
);
2653 while Present
(Disc
) loop
2654 if Has_Implicit_Dereference
(Disc
) then
2655 Desig
:= Designated_Type
(Etype
(Disc
));
2656 Add_One_Interp
(Nam
, Disc
, Desig
);
2660 Next_Discriminant
(Disc
);
2663 end Check_Implicit_Dereference
;
2665 ----------------------------------
2666 -- Check_Internal_Protected_Use --
2667 ----------------------------------
2669 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2675 while Present
(S
) loop
2676 if S
= Standard_Standard
then
2679 elsif Ekind
(S
) = E_Function
2680 and then Ekind
(Scope
(S
)) = E_Protected_Type
2689 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2691 -- An indirect function call (e.g. a callback within a protected
2692 -- function body) is not statically illegal. If the access type is
2693 -- anonymous and is the type of an access parameter, the scope of Nam
2694 -- will be the protected type, but it is not a protected operation.
2696 if Ekind
(Nam
) = E_Subprogram_Type
2698 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2702 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2704 ("within protected function cannot use protected "
2705 & "procedure in renaming or as generic actual", N
);
2707 elsif Nkind
(N
) = N_Attribute_Reference
then
2709 ("within protected function cannot take access of "
2710 & " protected procedure", N
);
2714 ("within protected function, protected object is constant", N
);
2716 ("\cannot call operation that may modify it", N
);
2719 end Check_Internal_Protected_Use
;
2721 ---------------------------------------
2722 -- Check_Later_Vs_Basic_Declarations --
2723 ---------------------------------------
2725 procedure Check_Later_Vs_Basic_Declarations
2727 During_Parsing
: Boolean)
2729 Body_Sloc
: Source_Ptr
;
2732 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2733 -- Return whether Decl is considered as a declarative item.
2734 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2735 -- When During_Parsing is False, the semantics of SPARK is followed.
2737 -------------------------------
2738 -- Is_Later_Declarative_Item --
2739 -------------------------------
2741 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2743 if Nkind
(Decl
) in N_Later_Decl_Item
then
2746 elsif Nkind
(Decl
) = N_Pragma
then
2749 elsif During_Parsing
then
2752 -- In SPARK, a package declaration is not considered as a later
2753 -- declarative item.
2755 elsif Nkind
(Decl
) = N_Package_Declaration
then
2758 -- In SPARK, a renaming is considered as a later declarative item
2760 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2766 end Is_Later_Declarative_Item
;
2768 -- Start of Check_Later_Vs_Basic_Declarations
2771 Decl
:= First
(Decls
);
2773 -- Loop through sequence of basic declarative items
2775 Outer
: while Present
(Decl
) loop
2776 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2777 and then Nkind
(Decl
) not in N_Body_Stub
2781 -- Once a body is encountered, we only allow later declarative
2782 -- items. The inner loop checks the rest of the list.
2785 Body_Sloc
:= Sloc
(Decl
);
2787 Inner
: while Present
(Decl
) loop
2788 if not Is_Later_Declarative_Item
(Decl
) then
2789 if During_Parsing
then
2790 if Ada_Version
= Ada_83
then
2791 Error_Msg_Sloc
:= Body_Sloc
;
2793 ("(Ada 83) decl cannot appear after body#", Decl
);
2796 Error_Msg_Sloc
:= Body_Sloc
;
2797 Check_SPARK_05_Restriction
2798 ("decl cannot appear after body#", Decl
);
2806 end Check_Later_Vs_Basic_Declarations
;
2808 -------------------------
2809 -- Check_Nested_Access --
2810 -------------------------
2812 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2813 Scop
: constant Entity_Id
:= Current_Scope
;
2814 Current_Subp
: Entity_Id
;
2815 Enclosing
: Entity_Id
;
2818 -- Currently only enabled for VM back-ends for efficiency, should we
2819 -- enable it more systematically ???
2821 -- Check for Is_Imported needs commenting below ???
2823 if VM_Target
/= No_VM
2824 and then Ekind_In
(Ent
, E_Variable
, E_Constant
, E_Loop_Parameter
)
2825 and then Scope
(Ent
) /= Empty
2826 and then not Is_Library_Level_Entity
(Ent
)
2827 and then not Is_Imported
(Ent
)
2829 if Is_Subprogram
(Scop
)
2830 or else Is_Generic_Subprogram
(Scop
)
2831 or else Is_Entry
(Scop
)
2833 Current_Subp
:= Scop
;
2835 Current_Subp
:= Current_Subprogram
;
2838 Enclosing
:= Enclosing_Subprogram
(Ent
);
2840 if Enclosing
/= Empty
and then Enclosing
/= Current_Subp
then
2841 Set_Has_Up_Level_Access
(Ent
, True);
2844 end Check_Nested_Access
;
2846 ---------------------------
2847 -- Check_No_Hidden_State --
2848 ---------------------------
2850 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2851 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2852 -- Determine whether the entity of a package denoted by Pkg has a null
2855 -----------------------------
2856 -- Has_Null_Abstract_State --
2857 -----------------------------
2859 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2860 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2863 -- Check first available state of related package. A null abstract
2864 -- state always appears as the sole element of the state list.
2868 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2869 end Has_Null_Abstract_State
;
2873 Context
: Entity_Id
:= Empty
;
2874 Not_Visible
: Boolean := False;
2877 -- Start of processing for Check_No_Hidden_State
2880 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2882 -- Find the proper context where the object or state appears
2885 while Present
(Scop
) loop
2888 -- Keep track of the context's visibility
2890 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2892 -- Prevent the search from going too far
2894 if Context
= Standard_Standard
then
2897 -- Objects and states that appear immediately within a subprogram or
2898 -- inside a construct nested within a subprogram do not introduce a
2899 -- hidden state. They behave as local variable declarations.
2901 elsif Is_Subprogram
(Context
) then
2904 -- When examining a package body, use the entity of the spec as it
2905 -- carries the abstract state declarations.
2907 elsif Ekind
(Context
) = E_Package_Body
then
2908 Context
:= Spec_Entity
(Context
);
2911 -- Stop the traversal when a package subject to a null abstract state
2914 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2915 and then Has_Null_Abstract_State
(Context
)
2920 Scop
:= Scope
(Scop
);
2923 -- At this point we know that there is at least one package with a null
2924 -- abstract state in visibility. Emit an error message unconditionally
2925 -- if the entity being processed is a state because the placement of the
2926 -- related package is irrelevant. This is not the case for objects as
2927 -- the intermediate context matters.
2929 if Present
(Context
)
2930 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
2932 Error_Msg_N
("cannot introduce hidden state &", Id
);
2933 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
2935 end Check_No_Hidden_State
;
2937 ------------------------------------------
2938 -- Check_Potentially_Blocking_Operation --
2939 ------------------------------------------
2941 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2945 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2946 -- When pragma Detect_Blocking is active, the run time will raise
2947 -- Program_Error. Here we only issue a warning, since we generally
2948 -- support the use of potentially blocking operations in the absence
2951 -- Indirect blocking through a subprogram call cannot be diagnosed
2952 -- statically without interprocedural analysis, so we do not attempt
2955 S
:= Scope
(Current_Scope
);
2956 while Present
(S
) and then S
/= Standard_Standard
loop
2957 if Is_Protected_Type
(S
) then
2959 ("potentially blocking operation in protected operation??", N
);
2965 end Check_Potentially_Blocking_Operation
;
2967 ---------------------------------
2968 -- Check_Result_And_Post_State --
2969 ---------------------------------
2971 procedure Check_Result_And_Post_State
2973 Result_Seen
: in out Boolean)
2975 procedure Check_Expression
(Expr
: Node_Id
);
2976 -- Perform the 'Result and post-state checks on a given expression
2978 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
2979 -- Attempt to find attribute 'Result in a subtree denoted by N
2981 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
2982 -- Determine whether source node N denotes "True" or "False"
2984 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
2985 -- Determine whether a subtree denoted by N mentions any construct that
2986 -- denotes a post-state.
2988 procedure Check_Function_Result
is
2989 new Traverse_Proc
(Is_Function_Result
);
2991 ----------------------
2992 -- Check_Expression --
2993 ----------------------
2995 procedure Check_Expression
(Expr
: Node_Id
) is
2997 if not Is_Trivial_Boolean
(Expr
) then
2998 Check_Function_Result
(Expr
);
3000 if not Mentions_Post_State
(Expr
) then
3001 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3003 ("contract case refers only to pre-state?T?", Expr
);
3005 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3007 ("refined postcondition refers only to pre-state?T?",
3012 ("postcondition refers only to pre-state?T?", Prag
);
3016 end Check_Expression
;
3018 ------------------------
3019 -- Is_Function_Result --
3020 ------------------------
3022 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3024 if Is_Attribute_Result
(N
) then
3025 Result_Seen
:= True;
3028 -- Continue the traversal
3033 end Is_Function_Result
;
3035 ------------------------
3036 -- Is_Trivial_Boolean --
3037 ------------------------
3039 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3042 Comes_From_Source
(N
)
3043 and then Is_Entity_Name
(N
)
3044 and then (Entity
(N
) = Standard_True
3045 or else Entity
(N
) = Standard_False
);
3046 end Is_Trivial_Boolean
;
3048 -------------------------
3049 -- Mentions_Post_State --
3050 -------------------------
3052 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3053 Post_State_Seen
: Boolean := False;
3055 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3056 -- Attempt to find a construct that denotes a post-state. If this is
3057 -- the case, set flag Post_State_Seen.
3063 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3067 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3068 Post_State_Seen
:= True;
3071 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3074 -- The entity may be modifiable through an implicit dereference
3077 or else Ekind
(Ent
) in Assignable_Kind
3078 or else (Is_Access_Type
(Etype
(Ent
))
3079 and then Nkind
(Parent
(N
)) = N_Selected_Component
)
3081 Post_State_Seen
:= True;
3085 elsif Nkind
(N
) = N_Attribute_Reference
then
3086 if Attribute_Name
(N
) = Name_Old
then
3089 elsif Attribute_Name
(N
) = Name_Result
then
3090 Post_State_Seen
:= True;
3098 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3100 -- Start of processing for Mentions_Post_State
3103 Find_Post_State
(N
);
3105 return Post_State_Seen
;
3106 end Mentions_Post_State
;
3110 Expr
: constant Node_Id
:=
3111 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
3112 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3115 -- Start of processing for Check_Result_And_Post_State
3118 -- Examine all consequences
3120 if Nam
= Name_Contract_Cases
then
3121 CCase
:= First
(Component_Associations
(Expr
));
3122 while Present
(CCase
) loop
3123 Check_Expression
(Expression
(CCase
));
3128 -- Examine the expression of a postcondition
3130 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
, Name_Refined_Post
));
3131 Check_Expression
(Expr
);
3133 end Check_Result_And_Post_State
;
3135 ------------------------------
3136 -- Check_Unprotected_Access --
3137 ------------------------------
3139 procedure Check_Unprotected_Access
3143 Cont_Encl_Typ
: Entity_Id
;
3144 Pref_Encl_Typ
: Entity_Id
;
3146 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
3147 -- Check whether Obj is a private component of a protected object.
3148 -- Return the protected type where the component resides, Empty
3151 function Is_Public_Operation
return Boolean;
3152 -- Verify that the enclosing operation is callable from outside the
3153 -- protected object, to minimize false positives.
3155 ------------------------------
3156 -- Enclosing_Protected_Type --
3157 ------------------------------
3159 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
3161 if Is_Entity_Name
(Obj
) then
3163 Ent
: Entity_Id
:= Entity
(Obj
);
3166 -- The object can be a renaming of a private component, use
3167 -- the original record component.
3169 if Is_Prival
(Ent
) then
3170 Ent
:= Prival_Link
(Ent
);
3173 if Is_Protected_Type
(Scope
(Ent
)) then
3179 -- For indexed and selected components, recursively check the prefix
3181 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
3182 return Enclosing_Protected_Type
(Prefix
(Obj
));
3184 -- The object does not denote a protected component
3189 end Enclosing_Protected_Type
;
3191 -------------------------
3192 -- Is_Public_Operation --
3193 -------------------------
3195 function Is_Public_Operation
return Boolean is
3201 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
3202 if Scope
(S
) = Pref_Encl_Typ
then
3203 E
:= First_Entity
(Pref_Encl_Typ
);
3205 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
3219 end Is_Public_Operation
;
3221 -- Start of processing for Check_Unprotected_Access
3224 if Nkind
(Expr
) = N_Attribute_Reference
3225 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
3227 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
3228 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
3230 -- Check whether we are trying to export a protected component to a
3231 -- context with an equal or lower access level.
3233 if Present
(Pref_Encl_Typ
)
3234 and then No
(Cont_Encl_Typ
)
3235 and then Is_Public_Operation
3236 and then Scope_Depth
(Pref_Encl_Typ
) >=
3237 Object_Access_Level
(Context
)
3240 ("??possible unprotected access to protected data", Expr
);
3243 end Check_Unprotected_Access
;
3245 ------------------------
3246 -- Collect_Interfaces --
3247 ------------------------
3249 procedure Collect_Interfaces
3251 Ifaces_List
: out Elist_Id
;
3252 Exclude_Parents
: Boolean := False;
3253 Use_Full_View
: Boolean := True)
3255 procedure Collect
(Typ
: Entity_Id
);
3256 -- Subsidiary subprogram used to traverse the whole list
3257 -- of directly and indirectly implemented interfaces
3263 procedure Collect
(Typ
: Entity_Id
) is
3264 Ancestor
: Entity_Id
;
3272 -- Handle private types
3275 and then Is_Private_Type
(Typ
)
3276 and then Present
(Full_View
(Typ
))
3278 Full_T
:= Full_View
(Typ
);
3281 -- Include the ancestor if we are generating the whole list of
3282 -- abstract interfaces.
3284 if Etype
(Full_T
) /= Typ
3286 -- Protect the frontend against wrong sources. For example:
3289 -- type A is tagged null record;
3290 -- type B is new A with private;
3291 -- type C is new A with private;
3293 -- type B is new C with null record;
3294 -- type C is new B with null record;
3297 and then Etype
(Full_T
) /= T
3299 Ancestor
:= Etype
(Full_T
);
3302 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
3303 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
3307 -- Traverse the graph of ancestor interfaces
3309 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
3310 Id
:= First
(Abstract_Interface_List
(Full_T
));
3311 while Present
(Id
) loop
3312 Iface
:= Etype
(Id
);
3314 -- Protect against wrong uses. For example:
3315 -- type I is interface;
3316 -- type O is tagged null record;
3317 -- type Wrong is new I and O with null record; -- ERROR
3319 if Is_Interface
(Iface
) then
3321 and then Etype
(T
) /= T
3322 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
3327 Append_Unique_Elmt
(Iface
, Ifaces_List
);
3336 -- Start of processing for Collect_Interfaces
3339 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
3340 Ifaces_List
:= New_Elmt_List
;
3342 end Collect_Interfaces
;
3344 ----------------------------------
3345 -- Collect_Interface_Components --
3346 ----------------------------------
3348 procedure Collect_Interface_Components
3349 (Tagged_Type
: Entity_Id
;
3350 Components_List
: out Elist_Id
)
3352 procedure Collect
(Typ
: Entity_Id
);
3353 -- Subsidiary subprogram used to climb to the parents
3359 procedure Collect
(Typ
: Entity_Id
) is
3360 Tag_Comp
: Entity_Id
;
3361 Parent_Typ
: Entity_Id
;
3364 -- Handle private types
3366 if Present
(Full_View
(Etype
(Typ
))) then
3367 Parent_Typ
:= Full_View
(Etype
(Typ
));
3369 Parent_Typ
:= Etype
(Typ
);
3372 if Parent_Typ
/= Typ
3374 -- Protect the frontend against wrong sources. For example:
3377 -- type A is tagged null record;
3378 -- type B is new A with private;
3379 -- type C is new A with private;
3381 -- type B is new C with null record;
3382 -- type C is new B with null record;
3385 and then Parent_Typ
/= Tagged_Type
3387 Collect
(Parent_Typ
);
3390 -- Collect the components containing tags of secondary dispatch
3393 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
3394 while Present
(Tag_Comp
) loop
3395 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
3396 Append_Elmt
(Tag_Comp
, Components_List
);
3398 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
3402 -- Start of processing for Collect_Interface_Components
3405 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
3406 and then Is_Tagged_Type
(Tagged_Type
));
3408 Components_List
:= New_Elmt_List
;
3409 Collect
(Tagged_Type
);
3410 end Collect_Interface_Components
;
3412 -----------------------------
3413 -- Collect_Interfaces_Info --
3414 -----------------------------
3416 procedure Collect_Interfaces_Info
3418 Ifaces_List
: out Elist_Id
;
3419 Components_List
: out Elist_Id
;
3420 Tags_List
: out Elist_Id
)
3422 Comps_List
: Elist_Id
;
3423 Comp_Elmt
: Elmt_Id
;
3424 Comp_Iface
: Entity_Id
;
3425 Iface_Elmt
: Elmt_Id
;
3428 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3429 -- Search for the secondary tag associated with the interface type
3430 -- Iface that is implemented by T.
3436 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3439 if not Is_CPP_Class
(T
) then
3440 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3442 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3446 and then Is_Tag
(Node
(ADT
))
3447 and then Related_Type
(Node
(ADT
)) /= Iface
3449 -- Skip secondary dispatch table referencing thunks to user
3450 -- defined primitives covered by this interface.
3452 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3455 -- Skip secondary dispatch tables of Ada types
3457 if not Is_CPP_Class
(T
) then
3459 -- Skip secondary dispatch table referencing thunks to
3460 -- predefined primitives.
3462 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3465 -- Skip secondary dispatch table referencing user-defined
3466 -- primitives covered by this interface.
3468 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3471 -- Skip secondary dispatch table referencing predefined
3474 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3479 pragma Assert
(Is_Tag
(Node
(ADT
)));
3483 -- Start of processing for Collect_Interfaces_Info
3486 Collect_Interfaces
(T
, Ifaces_List
);
3487 Collect_Interface_Components
(T
, Comps_List
);
3489 -- Search for the record component and tag associated with each
3490 -- interface type of T.
3492 Components_List
:= New_Elmt_List
;
3493 Tags_List
:= New_Elmt_List
;
3495 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3496 while Present
(Iface_Elmt
) loop
3497 Iface
:= Node
(Iface_Elmt
);
3499 -- Associate the primary tag component and the primary dispatch table
3500 -- with all the interfaces that are parents of T
3502 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3503 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3504 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3506 -- Otherwise search for the tag component and secondary dispatch
3510 Comp_Elmt
:= First_Elmt
(Comps_List
);
3511 while Present
(Comp_Elmt
) loop
3512 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3514 if Comp_Iface
= Iface
3515 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3517 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3518 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3522 Next_Elmt
(Comp_Elmt
);
3524 pragma Assert
(Present
(Comp_Elmt
));
3527 Next_Elmt
(Iface_Elmt
);
3529 end Collect_Interfaces_Info
;
3531 ---------------------
3532 -- Collect_Parents --
3533 ---------------------
3535 procedure Collect_Parents
3537 List
: out Elist_Id
;
3538 Use_Full_View
: Boolean := True)
3540 Current_Typ
: Entity_Id
:= T
;
3541 Parent_Typ
: Entity_Id
;
3544 List
:= New_Elmt_List
;
3546 -- No action if the if the type has no parents
3548 if T
= Etype
(T
) then
3553 Parent_Typ
:= Etype
(Current_Typ
);
3555 if Is_Private_Type
(Parent_Typ
)
3556 and then Present
(Full_View
(Parent_Typ
))
3557 and then Use_Full_View
3559 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3562 Append_Elmt
(Parent_Typ
, List
);
3564 exit when Parent_Typ
= Current_Typ
;
3565 Current_Typ
:= Parent_Typ
;
3567 end Collect_Parents
;
3569 ----------------------------------
3570 -- Collect_Primitive_Operations --
3571 ----------------------------------
3573 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3574 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3575 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3576 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3580 Is_Type_In_Pkg
: Boolean;
3581 Formal_Derived
: Boolean := False;
3584 function Match
(E
: Entity_Id
) return Boolean;
3585 -- True if E's base type is B_Type, or E is of an anonymous access type
3586 -- and the base type of its designated type is B_Type.
3592 function Match
(E
: Entity_Id
) return Boolean is
3593 Etyp
: Entity_Id
:= Etype
(E
);
3596 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
3597 Etyp
:= Designated_Type
(Etyp
);
3600 -- In Ada 2012 a primitive operation may have a formal of an
3601 -- incomplete view of the parent type.
3603 return Base_Type
(Etyp
) = B_Type
3605 (Ada_Version
>= Ada_2012
3606 and then Ekind
(Etyp
) = E_Incomplete_Type
3607 and then Full_View
(Etyp
) = B_Type
);
3610 -- Start of processing for Collect_Primitive_Operations
3613 -- For tagged types, the primitive operations are collected as they
3614 -- are declared, and held in an explicit list which is simply returned.
3616 if Is_Tagged_Type
(B_Type
) then
3617 return Primitive_Operations
(B_Type
);
3619 -- An untagged generic type that is a derived type inherits the
3620 -- primitive operations of its parent type. Other formal types only
3621 -- have predefined operators, which are not explicitly represented.
3623 elsif Is_Generic_Type
(B_Type
) then
3624 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
3625 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
3626 N_Formal_Derived_Type_Definition
3628 Formal_Derived
:= True;
3630 return New_Elmt_List
;
3634 Op_List
:= New_Elmt_List
;
3636 if B_Scope
= Standard_Standard
then
3637 if B_Type
= Standard_String
then
3638 Append_Elmt
(Standard_Op_Concat
, Op_List
);
3640 elsif B_Type
= Standard_Wide_String
then
3641 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
3647 -- Locate the primitive subprograms of the type
3650 -- The primitive operations appear after the base type, except
3651 -- if the derivation happens within the private part of B_Scope
3652 -- and the type is a private type, in which case both the type
3653 -- and some primitive operations may appear before the base
3654 -- type, and the list of candidates starts after the type.
3656 if In_Open_Scopes
(B_Scope
)
3657 and then Scope
(T
) = B_Scope
3658 and then In_Private_Part
(B_Scope
)
3660 Id
:= Next_Entity
(T
);
3662 -- In Ada 2012, If the type has an incomplete partial view, there
3663 -- may be primitive operations declared before the full view, so
3664 -- we need to start scanning from the incomplete view, which is
3665 -- earlier on the entity chain.
3667 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
3668 and then Present
(Incomplete_View
(Parent
(B_Type
)))
3670 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
3673 Id
:= Next_Entity
(B_Type
);
3676 -- Set flag if this is a type in a package spec
3679 Is_Package_Or_Generic_Package
(B_Scope
)
3681 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
3684 while Present
(Id
) loop
3686 -- Test whether the result type or any of the parameter types of
3687 -- each subprogram following the type match that type when the
3688 -- type is declared in a package spec, is a derived type, or the
3689 -- subprogram is marked as primitive. (The Is_Primitive test is
3690 -- needed to find primitives of nonderived types in declarative
3691 -- parts that happen to override the predefined "=" operator.)
3693 -- Note that generic formal subprograms are not considered to be
3694 -- primitive operations and thus are never inherited.
3696 if Is_Overloadable
(Id
)
3697 and then (Is_Type_In_Pkg
3698 or else Is_Derived_Type
(B_Type
)
3699 or else Is_Primitive
(Id
))
3700 and then Nkind
(Parent
(Parent
(Id
)))
3701 not in N_Formal_Subprogram_Declaration
3709 Formal
:= First_Formal
(Id
);
3710 while Present
(Formal
) loop
3711 if Match
(Formal
) then
3716 Next_Formal
(Formal
);
3720 -- For a formal derived type, the only primitives are the ones
3721 -- inherited from the parent type. Operations appearing in the
3722 -- package declaration are not primitive for it.
3725 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
3727 -- In the special case of an equality operator aliased to
3728 -- an overriding dispatching equality belonging to the same
3729 -- type, we don't include it in the list of primitives.
3730 -- This avoids inheriting multiple equality operators when
3731 -- deriving from untagged private types whose full type is
3732 -- tagged, which can otherwise cause ambiguities. Note that
3733 -- this should only happen for this kind of untagged parent
3734 -- type, since normally dispatching operations are inherited
3735 -- using the type's Primitive_Operations list.
3737 if Chars
(Id
) = Name_Op_Eq
3738 and then Is_Dispatching_Operation
(Id
)
3739 and then Present
(Alias
(Id
))
3740 and then Present
(Overridden_Operation
(Alias
(Id
)))
3741 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3742 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3746 -- Include the subprogram in the list of primitives
3749 Append_Elmt
(Id
, Op_List
);
3756 -- For a type declared in System, some of its operations may
3757 -- appear in the target-specific extension to System.
3760 and then B_Scope
= RTU_Entity
(System
)
3761 and then Present_System_Aux
3763 B_Scope
:= System_Aux_Id
;
3764 Id
:= First_Entity
(System_Aux_Id
);
3770 end Collect_Primitive_Operations
;
3772 -----------------------------------
3773 -- Compile_Time_Constraint_Error --
3774 -----------------------------------
3776 function Compile_Time_Constraint_Error
3779 Ent
: Entity_Id
:= Empty
;
3780 Loc
: Source_Ptr
:= No_Location
;
3781 Warn
: Boolean := False) return Node_Id
3783 Msgc
: String (1 .. Msg
'Length + 3);
3784 -- Copy of message, with room for possible ?? or << and ! at end
3790 -- Start of processing for Compile_Time_Constraint_Error
3793 -- If this is a warning, convert it into an error if we are in code
3794 -- subject to SPARK_Mode being set ON.
3796 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3798 -- A static constraint error in an instance body is not a fatal error.
3799 -- we choose to inhibit the message altogether, because there is no
3800 -- obvious node (for now) on which to post it. On the other hand the
3801 -- offending node must be replaced with a constraint_error in any case.
3803 -- No messages are generated if we already posted an error on this node
3805 if not Error_Posted
(N
) then
3806 if Loc
/= No_Location
then
3812 -- Copy message to Msgc, converting any ? in the message into
3813 -- < instead, so that we have an error in GNATprove mode.
3817 for J
in 1 .. Msgl
loop
3818 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
3821 Msgc
(J
) := Msg
(J
);
3825 -- Message is a warning, even in Ada 95 case
3827 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
3830 -- In Ada 83, all messages are warnings. In the private part and
3831 -- the body of an instance, constraint_checks are only warnings.
3832 -- We also make this a warning if the Warn parameter is set.
3835 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
3843 elsif In_Instance_Not_Visible
then
3850 -- Otherwise we have a real error message (Ada 95 static case)
3851 -- and we make this an unconditional message. Note that in the
3852 -- warning case we do not make the message unconditional, it seems
3853 -- quite reasonable to delete messages like this (about exceptions
3854 -- that will be raised) in dead code.
3862 -- One more test, skip the warning if the related expression is
3863 -- statically unevaluated, since we don't want to warn about what
3864 -- will happen when something is evaluated if it never will be
3867 if not Is_Statically_Unevaluated
(N
) then
3868 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3870 if Present
(Ent
) then
3871 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
3873 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
3878 -- Check whether the context is an Init_Proc
3880 if Inside_Init_Proc
then
3882 Conc_Typ
: constant Entity_Id
:=
3883 Corresponding_Concurrent_Type
3884 (Entity
(Parameter_Type
(First
3885 (Parameter_Specifications
3886 (Parent
(Current_Scope
))))));
3889 -- Don't complain if the corresponding concurrent type
3890 -- doesn't come from source (i.e. a single task/protected
3893 if Present
(Conc_Typ
)
3894 and then not Comes_From_Source
(Conc_Typ
)
3897 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3900 if GNATprove_Mode
then
3902 ("\& would have been raised for objects of this "
3903 & "type", N
, Standard_Constraint_Error
, Eloc
);
3906 ("\& will be raised for objects of this type??",
3907 N
, Standard_Constraint_Error
, Eloc
);
3913 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3917 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
3918 Set_Error_Posted
(N
);
3924 end Compile_Time_Constraint_Error
;
3926 -----------------------
3927 -- Conditional_Delay --
3928 -----------------------
3930 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
3932 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
3933 Set_Has_Delayed_Freeze
(New_Ent
);
3935 end Conditional_Delay
;
3937 ----------------------------
3938 -- Contains_Refined_State --
3939 ----------------------------
3941 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
3942 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
3943 -- Determine whether a dependency list mentions a state with a visible
3946 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
3947 -- Determine whether a global list mentions a state with a visible
3950 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
3951 -- Determine whether Item is a reference to an abstract state with a
3952 -- visible refinement.
3954 -----------------------------
3955 -- Has_State_In_Dependency --
3956 -----------------------------
3958 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
3963 -- A null dependency list does not mention any states
3965 if Nkind
(List
) = N_Null
then
3968 -- Dependency clauses appear as component associations of an
3971 elsif Nkind
(List
) = N_Aggregate
3972 and then Present
(Component_Associations
(List
))
3974 Clause
:= First
(Component_Associations
(List
));
3975 while Present
(Clause
) loop
3977 -- Inspect the outputs of a dependency clause
3979 Output
:= First
(Choices
(Clause
));
3980 while Present
(Output
) loop
3981 if Is_Refined_State
(Output
) then
3988 -- Inspect the outputs of a dependency clause
3990 if Is_Refined_State
(Expression
(Clause
)) then
3997 -- If we get here, then none of the dependency clauses mention a
3998 -- state with visible refinement.
4002 -- An illegal pragma managed to sneak in
4005 raise Program_Error
;
4007 end Has_State_In_Dependency
;
4009 -------------------------
4010 -- Has_State_In_Global --
4011 -------------------------
4013 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
4017 -- A null global list does not mention any states
4019 if Nkind
(List
) = N_Null
then
4022 -- Simple global list or moded global list declaration
4024 elsif Nkind
(List
) = N_Aggregate
then
4026 -- The declaration of a simple global list appear as a collection
4029 if Present
(Expressions
(List
)) then
4030 Item
:= First
(Expressions
(List
));
4031 while Present
(Item
) loop
4032 if Is_Refined_State
(Item
) then
4039 -- The declaration of a moded global list appears as a collection
4040 -- of component associations where individual choices denote
4044 Item
:= First
(Component_Associations
(List
));
4045 while Present
(Item
) loop
4046 if Has_State_In_Global
(Expression
(Item
)) then
4054 -- If we get here, then the simple/moded global list did not
4055 -- mention any states with a visible refinement.
4059 -- Single global item declaration
4061 elsif Is_Entity_Name
(List
) then
4062 return Is_Refined_State
(List
);
4064 -- An illegal pragma managed to sneak in
4067 raise Program_Error
;
4069 end Has_State_In_Global
;
4071 ----------------------
4072 -- Is_Refined_State --
4073 ----------------------
4075 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
4077 Item_Id
: Entity_Id
;
4080 if Nkind
(Item
) = N_Null
then
4083 -- States cannot be subject to attribute 'Result. This case arises
4084 -- in dependency relations.
4086 elsif Nkind
(Item
) = N_Attribute_Reference
4087 and then Attribute_Name
(Item
) = Name_Result
4091 -- Multiple items appear as an aggregate. This case arises in
4092 -- dependency relations.
4094 elsif Nkind
(Item
) = N_Aggregate
4095 and then Present
(Expressions
(Item
))
4097 Elmt
:= First
(Expressions
(Item
));
4098 while Present
(Elmt
) loop
4099 if Is_Refined_State
(Elmt
) then
4106 -- If we get here, then none of the inputs or outputs reference a
4107 -- state with visible refinement.
4114 Item_Id
:= Entity_Of
(Item
);
4118 and then Ekind
(Item_Id
) = E_Abstract_State
4119 and then Has_Visible_Refinement
(Item_Id
);
4121 end Is_Refined_State
;
4125 Arg
: constant Node_Id
:=
4126 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
4127 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4129 -- Start of processing for Contains_Refined_State
4132 if Nam
= Name_Depends
then
4133 return Has_State_In_Dependency
(Arg
);
4135 else pragma Assert
(Nam
= Name_Global
);
4136 return Has_State_In_Global
(Arg
);
4138 end Contains_Refined_State
;
4140 -------------------------
4141 -- Copy_Component_List --
4142 -------------------------
4144 function Copy_Component_List
4146 Loc
: Source_Ptr
) return List_Id
4149 Comps
: constant List_Id
:= New_List
;
4152 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
4153 while Present
(Comp
) loop
4154 if Comes_From_Source
(Comp
) then
4156 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
4159 Make_Component_Declaration
(Loc
,
4160 Defining_Identifier
=>
4161 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
4162 Component_Definition
=>
4164 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
4168 Next_Component
(Comp
);
4172 end Copy_Component_List
;
4174 -------------------------
4175 -- Copy_Parameter_List --
4176 -------------------------
4178 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
4179 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
4184 if No
(First_Formal
(Subp_Id
)) then
4188 Formal
:= First_Formal
(Subp_Id
);
4189 while Present
(Formal
) loop
4191 (Make_Parameter_Specification
(Loc
,
4192 Defining_Identifier
=>
4193 Make_Defining_Identifier
(Sloc
(Formal
),
4194 Chars
=> Chars
(Formal
)),
4195 In_Present
=> In_Present
(Parent
(Formal
)),
4196 Out_Present
=> Out_Present
(Parent
(Formal
)),
4198 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4200 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
4203 Next_Formal
(Formal
);
4208 end Copy_Parameter_List
;
4210 --------------------------------
4211 -- Corresponding_Generic_Type --
4212 --------------------------------
4214 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
4220 if not Is_Generic_Actual_Type
(T
) then
4223 -- If the actual is the actual of an enclosing instance, resolution
4224 -- was correct in the generic.
4226 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
4227 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
4229 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
4236 if Is_Wrapper_Package
(Inst
) then
4237 Inst
:= Related_Instance
(Inst
);
4242 (Specification
(Unit_Declaration_Node
(Inst
)));
4244 -- Generic actual has the same name as the corresponding formal
4246 Typ
:= First_Entity
(Gen
);
4247 while Present
(Typ
) loop
4248 if Chars
(Typ
) = Chars
(T
) then
4257 end Corresponding_Generic_Type
;
4259 --------------------
4260 -- Current_Entity --
4261 --------------------
4263 -- The currently visible definition for a given identifier is the
4264 -- one most chained at the start of the visibility chain, i.e. the
4265 -- one that is referenced by the Node_Id value of the name of the
4266 -- given identifier.
4268 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
4270 return Get_Name_Entity_Id
(Chars
(N
));
4273 -----------------------------
4274 -- Current_Entity_In_Scope --
4275 -----------------------------
4277 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
4279 CS
: constant Entity_Id
:= Current_Scope
;
4281 Transient_Case
: constant Boolean := Scope_Is_Transient
;
4284 E
:= Get_Name_Entity_Id
(Chars
(N
));
4286 and then Scope
(E
) /= CS
4287 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
4293 end Current_Entity_In_Scope
;
4299 function Current_Scope
return Entity_Id
is
4301 if Scope_Stack
.Last
= -1 then
4302 return Standard_Standard
;
4305 C
: constant Entity_Id
:=
4306 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
4311 return Standard_Standard
;
4317 ------------------------
4318 -- Current_Subprogram --
4319 ------------------------
4321 function Current_Subprogram
return Entity_Id
is
4322 Scop
: constant Entity_Id
:= Current_Scope
;
4324 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
4327 return Enclosing_Subprogram
(Scop
);
4329 end Current_Subprogram
;
4331 ----------------------------------
4332 -- Deepest_Type_Access_Level --
4333 ----------------------------------
4335 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
4337 if Ekind
(Typ
) = E_Anonymous_Access_Type
4338 and then not Is_Local_Anonymous_Access
(Typ
)
4339 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
4341 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4345 Scope_Depth
(Enclosing_Dynamic_Scope
4346 (Defining_Identifier
4347 (Associated_Node_For_Itype
(Typ
))));
4349 -- For generic formal type, return Int'Last (infinite).
4350 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4352 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
4353 return UI_From_Int
(Int
'Last);
4356 return Type_Access_Level
(Typ
);
4358 end Deepest_Type_Access_Level
;
4360 ---------------------
4361 -- Defining_Entity --
4362 ---------------------
4364 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4365 K
: constant Node_Kind
:= Nkind
(N
);
4366 Err
: Entity_Id
:= Empty
;
4371 N_Subprogram_Declaration |
4372 N_Abstract_Subprogram_Declaration |
4374 N_Package_Declaration |
4375 N_Subprogram_Renaming_Declaration |
4376 N_Subprogram_Body_Stub |
4377 N_Generic_Subprogram_Declaration |
4378 N_Generic_Package_Declaration |
4379 N_Formal_Subprogram_Declaration |
4380 N_Expression_Function
4382 return Defining_Entity
(Specification
(N
));
4385 N_Component_Declaration |
4386 N_Defining_Program_Unit_Name |
4387 N_Discriminant_Specification |
4389 N_Entry_Declaration |
4390 N_Entry_Index_Specification |
4391 N_Exception_Declaration |
4392 N_Exception_Renaming_Declaration |
4393 N_Formal_Object_Declaration |
4394 N_Formal_Package_Declaration |
4395 N_Formal_Type_Declaration |
4396 N_Full_Type_Declaration |
4397 N_Implicit_Label_Declaration |
4398 N_Incomplete_Type_Declaration |
4399 N_Loop_Parameter_Specification |
4400 N_Number_Declaration |
4401 N_Object_Declaration |
4402 N_Object_Renaming_Declaration |
4403 N_Package_Body_Stub |
4404 N_Parameter_Specification |
4405 N_Private_Extension_Declaration |
4406 N_Private_Type_Declaration |
4408 N_Protected_Body_Stub |
4409 N_Protected_Type_Declaration |
4410 N_Single_Protected_Declaration |
4411 N_Single_Task_Declaration |
4412 N_Subtype_Declaration |
4415 N_Task_Type_Declaration
4417 return Defining_Identifier
(N
);
4420 return Defining_Entity
(Proper_Body
(N
));
4423 N_Function_Instantiation |
4424 N_Function_Specification |
4425 N_Generic_Function_Renaming_Declaration |
4426 N_Generic_Package_Renaming_Declaration |
4427 N_Generic_Procedure_Renaming_Declaration |
4429 N_Package_Instantiation |
4430 N_Package_Renaming_Declaration |
4431 N_Package_Specification |
4432 N_Procedure_Instantiation |
4433 N_Procedure_Specification
4436 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
4439 if Nkind
(Nam
) in N_Entity
then
4442 -- For Error, make up a name and attach to declaration
4443 -- so we can continue semantic analysis
4445 elsif Nam
= Error
then
4446 Err
:= Make_Temporary
(Sloc
(N
), 'T');
4447 Set_Defining_Unit_Name
(N
, Err
);
4451 -- If not an entity, get defining identifier
4454 return Defining_Identifier
(Nam
);
4462 return Entity
(Identifier
(N
));
4465 raise Program_Error
;
4468 end Defining_Entity
;
4470 --------------------------
4471 -- Denotes_Discriminant --
4472 --------------------------
4474 function Denotes_Discriminant
4476 Check_Concurrent
: Boolean := False) return Boolean
4481 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
4487 -- If we are checking for a protected type, the discriminant may have
4488 -- been rewritten as the corresponding discriminal of the original type
4489 -- or of the corresponding concurrent record, depending on whether we
4490 -- are in the spec or body of the protected type.
4492 return Ekind
(E
) = E_Discriminant
4495 and then Ekind
(E
) = E_In_Parameter
4496 and then Present
(Discriminal_Link
(E
))
4498 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
4500 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
4502 end Denotes_Discriminant
;
4504 -------------------------
4505 -- Denotes_Same_Object --
4506 -------------------------
4508 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
4509 Obj1
: Node_Id
:= A1
;
4510 Obj2
: Node_Id
:= A2
;
4512 function Has_Prefix
(N
: Node_Id
) return Boolean;
4513 -- Return True if N has attribute Prefix
4515 function Is_Renaming
(N
: Node_Id
) return Boolean;
4516 -- Return true if N names a renaming entity
4518 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
4519 -- For renamings, return False if the prefix of any dereference within
4520 -- the renamed object_name is a variable, or any expression within the
4521 -- renamed object_name contains references to variables or calls on
4522 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4528 function Has_Prefix
(N
: Node_Id
) return Boolean is
4532 N_Attribute_Reference
,
4534 N_Explicit_Dereference
,
4535 N_Indexed_Component
,
4537 N_Selected_Component
,
4545 function Is_Renaming
(N
: Node_Id
) return Boolean is
4547 return Is_Entity_Name
(N
)
4548 and then Present
(Renamed_Entity
(Entity
(N
)));
4551 -----------------------
4552 -- Is_Valid_Renaming --
4553 -----------------------
4555 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
4557 function Check_Renaming
(N
: Node_Id
) return Boolean;
4558 -- Recursive function used to traverse all the prefixes of N
4560 function Check_Renaming
(N
: Node_Id
) return Boolean is
4563 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
4568 if Nkind
(N
) = N_Indexed_Component
then
4573 Indx
:= First
(Expressions
(N
));
4574 while Present
(Indx
) loop
4575 if not Is_OK_Static_Expression
(Indx
) then
4584 if Has_Prefix
(N
) then
4586 P
: constant Node_Id
:= Prefix
(N
);
4589 if Nkind
(N
) = N_Explicit_Dereference
4590 and then Is_Variable
(P
)
4594 elsif Is_Entity_Name
(P
)
4595 and then Ekind
(Entity
(P
)) = E_Function
4599 elsif Nkind
(P
) = N_Function_Call
then
4603 -- Recursion to continue traversing the prefix of the
4604 -- renaming expression
4606 return Check_Renaming
(P
);
4613 -- Start of processing for Is_Valid_Renaming
4616 return Check_Renaming
(N
);
4617 end Is_Valid_Renaming
;
4619 -- Start of processing for Denotes_Same_Object
4622 -- Both names statically denote the same stand-alone object or parameter
4623 -- (RM 6.4.1(6.5/3))
4625 if Is_Entity_Name
(Obj1
)
4626 and then Is_Entity_Name
(Obj2
)
4627 and then Entity
(Obj1
) = Entity
(Obj2
)
4632 -- For renamings, the prefix of any dereference within the renamed
4633 -- object_name is not a variable, and any expression within the
4634 -- renamed object_name contains no references to variables nor
4635 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4637 if Is_Renaming
(Obj1
) then
4638 if Is_Valid_Renaming
(Obj1
) then
4639 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
4645 if Is_Renaming
(Obj2
) then
4646 if Is_Valid_Renaming
(Obj2
) then
4647 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
4653 -- No match if not same node kind (such cases are handled by
4654 -- Denotes_Same_Prefix)
4656 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
4659 -- After handling valid renamings, one of the two names statically
4660 -- denoted a renaming declaration whose renamed object_name is known
4661 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4663 elsif Is_Entity_Name
(Obj1
) then
4664 if Is_Entity_Name
(Obj2
) then
4665 return Entity
(Obj1
) = Entity
(Obj2
);
4670 -- Both names are selected_components, their prefixes are known to
4671 -- denote the same object, and their selector_names denote the same
4672 -- component (RM 6.4.1(6.6/3)
4674 elsif Nkind
(Obj1
) = N_Selected_Component
then
4675 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4677 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
4679 -- Both names are dereferences and the dereferenced names are known to
4680 -- denote the same object (RM 6.4.1(6.7/3))
4682 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
4683 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
4685 -- Both names are indexed_components, their prefixes are known to denote
4686 -- the same object, and each of the pairs of corresponding index values
4687 -- are either both static expressions with the same static value or both
4688 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4690 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4691 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4699 Indx1
:= First
(Expressions
(Obj1
));
4700 Indx2
:= First
(Expressions
(Obj2
));
4701 while Present
(Indx1
) loop
4703 -- Indexes must denote the same static value or same object
4705 if Is_OK_Static_Expression
(Indx1
) then
4706 if not Is_OK_Static_Expression
(Indx2
) then
4709 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4713 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4725 -- Both names are slices, their prefixes are known to denote the same
4726 -- object, and the two slices have statically matching index constraints
4727 -- (RM 6.4.1(6.9/3))
4729 elsif Nkind
(Obj1
) = N_Slice
4730 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4733 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4736 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4737 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4739 -- Check whether bounds are statically identical. There is no
4740 -- attempt to detect partial overlap of slices.
4742 return Denotes_Same_Object
(Lo1
, Lo2
)
4743 and then Denotes_Same_Object
(Hi1
, Hi2
);
4746 -- In the recursion, literals appear as indexes
4748 elsif Nkind
(Obj1
) = N_Integer_Literal
4750 Nkind
(Obj2
) = N_Integer_Literal
4752 return Intval
(Obj1
) = Intval
(Obj2
);
4757 end Denotes_Same_Object
;
4759 -------------------------
4760 -- Denotes_Same_Prefix --
4761 -------------------------
4763 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
4766 if Is_Entity_Name
(A1
) then
4767 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
4768 and then not Is_Access_Type
(Etype
(A1
))
4770 return Denotes_Same_Object
(A1
, Prefix
(A2
))
4771 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
4776 elsif Is_Entity_Name
(A2
) then
4777 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
4779 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4781 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4784 Root1
, Root2
: Node_Id
;
4785 Depth1
, Depth2
: Int
:= 0;
4788 Root1
:= Prefix
(A1
);
4789 while not Is_Entity_Name
(Root1
) loop
4791 (Root1
, N_Selected_Component
, N_Indexed_Component
)
4795 Root1
:= Prefix
(Root1
);
4798 Depth1
:= Depth1
+ 1;
4801 Root2
:= Prefix
(A2
);
4802 while not Is_Entity_Name
(Root2
) loop
4804 (Root2
, N_Selected_Component
, N_Indexed_Component
)
4808 Root2
:= Prefix
(Root2
);
4811 Depth2
:= Depth2
+ 1;
4814 -- If both have the same depth and they do not denote the same
4815 -- object, they are disjoint and no warning is needed.
4817 if Depth1
= Depth2
then
4820 elsif Depth1
> Depth2
then
4821 Root1
:= Prefix
(A1
);
4822 for I
in 1 .. Depth1
- Depth2
- 1 loop
4823 Root1
:= Prefix
(Root1
);
4826 return Denotes_Same_Object
(Root1
, A2
);
4829 Root2
:= Prefix
(A2
);
4830 for I
in 1 .. Depth2
- Depth1
- 1 loop
4831 Root2
:= Prefix
(Root2
);
4834 return Denotes_Same_Object
(A1
, Root2
);
4841 end Denotes_Same_Prefix
;
4843 ----------------------
4844 -- Denotes_Variable --
4845 ----------------------
4847 function Denotes_Variable
(N
: Node_Id
) return Boolean is
4849 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
4850 end Denotes_Variable
;
4852 -----------------------------
4853 -- Depends_On_Discriminant --
4854 -----------------------------
4856 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
4861 Get_Index_Bounds
(N
, L
, H
);
4862 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
4863 end Depends_On_Discriminant
;
4865 -------------------------
4866 -- Designate_Same_Unit --
4867 -------------------------
4869 function Designate_Same_Unit
4871 Name2
: Node_Id
) return Boolean
4873 K1
: constant Node_Kind
:= Nkind
(Name1
);
4874 K2
: constant Node_Kind
:= Nkind
(Name2
);
4876 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
4877 -- Returns the parent unit name node of a defining program unit name
4878 -- or the prefix if N is a selected component or an expanded name.
4880 function Select_Node
(N
: Node_Id
) return Node_Id
;
4881 -- Returns the defining identifier node of a defining program unit
4882 -- name or the selector node if N is a selected component or an
4889 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
4891 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4903 function Select_Node
(N
: Node_Id
) return Node_Id
is
4905 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4906 return Defining_Identifier
(N
);
4909 return Selector_Name
(N
);
4913 -- Start of processing for Designate_Next_Unit
4916 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
4918 (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
4920 return Chars
(Name1
) = Chars
(Name2
);
4923 (K1
= N_Expanded_Name
or else
4924 K1
= N_Selected_Component
or else
4925 K1
= N_Defining_Program_Unit_Name
)
4927 (K2
= N_Expanded_Name
or else
4928 K2
= N_Selected_Component
or else
4929 K2
= N_Defining_Program_Unit_Name
)
4932 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
4934 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
4939 end Designate_Same_Unit
;
4941 ------------------------------------------
4942 -- function Dynamic_Accessibility_Level --
4943 ------------------------------------------
4945 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
4947 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
4949 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
4950 -- Construct an integer literal representing an accessibility level
4951 -- with its type set to Natural.
4953 ------------------------
4954 -- Make_Level_Literal --
4955 ------------------------
4957 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
4958 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
4960 Set_Etype
(Result
, Standard_Natural
);
4962 end Make_Level_Literal
;
4964 -- Start of processing for Dynamic_Accessibility_Level
4967 if Is_Entity_Name
(Expr
) then
4970 if Present
(Renamed_Object
(E
)) then
4971 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
4974 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
4975 if Present
(Extra_Accessibility
(E
)) then
4976 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
4981 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4983 case Nkind
(Expr
) is
4985 -- For access discriminant, the level of the enclosing object
4987 when N_Selected_Component
=>
4988 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
4989 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
4990 E_Anonymous_Access_Type
4992 return Make_Level_Literal
(Object_Access_Level
(Expr
));
4995 when N_Attribute_Reference
=>
4996 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
4998 -- For X'Access, the level of the prefix X
5000 when Attribute_Access
=>
5001 return Make_Level_Literal
5002 (Object_Access_Level
(Prefix
(Expr
)));
5004 -- Treat the unchecked attributes as library-level
5006 when Attribute_Unchecked_Access |
5007 Attribute_Unrestricted_Access
=>
5008 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
5010 -- No other access-valued attributes
5013 raise Program_Error
;
5018 -- Unimplemented: depends on context. As an actual parameter where
5019 -- formal type is anonymous, use
5020 -- Scope_Depth (Current_Scope) + 1.
5021 -- For other cases, see 3.10.2(14/3) and following. ???
5025 when N_Type_Conversion
=>
5026 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
5028 -- Handle type conversions introduced for a rename of an
5029 -- Ada 2012 stand-alone object of an anonymous access type.
5031 return Dynamic_Accessibility_Level
(Expression
(Expr
));
5038 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
5039 end Dynamic_Accessibility_Level
;
5041 -----------------------------------
5042 -- Effective_Extra_Accessibility --
5043 -----------------------------------
5045 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
5047 if Present
(Renamed_Object
(Id
))
5048 and then Is_Entity_Name
(Renamed_Object
(Id
))
5050 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
5052 return Extra_Accessibility
(Id
);
5054 end Effective_Extra_Accessibility
;
5056 -----------------------------
5057 -- Effective_Reads_Enabled --
5058 -----------------------------
5060 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
5062 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
5063 end Effective_Reads_Enabled
;
5065 ------------------------------
5066 -- Effective_Writes_Enabled --
5067 ------------------------------
5069 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
5071 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
5072 end Effective_Writes_Enabled
;
5074 ------------------------------
5075 -- Enclosing_Comp_Unit_Node --
5076 ------------------------------
5078 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
5079 Current_Node
: Node_Id
;
5083 while Present
(Current_Node
)
5084 and then Nkind
(Current_Node
) /= N_Compilation_Unit
5086 Current_Node
:= Parent
(Current_Node
);
5089 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
5092 return Current_Node
;
5094 end Enclosing_Comp_Unit_Node
;
5096 --------------------------
5097 -- Enclosing_CPP_Parent --
5098 --------------------------
5100 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
5101 Parent_Typ
: Entity_Id
:= Typ
;
5104 while not Is_CPP_Class
(Parent_Typ
)
5105 and then Etype
(Parent_Typ
) /= Parent_Typ
5107 Parent_Typ
:= Etype
(Parent_Typ
);
5109 if Is_Private_Type
(Parent_Typ
) then
5110 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5114 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
5116 end Enclosing_CPP_Parent
;
5118 ----------------------------
5119 -- Enclosing_Generic_Body --
5120 ----------------------------
5122 function Enclosing_Generic_Body
5123 (N
: Node_Id
) return Node_Id
5131 while Present
(P
) loop
5132 if Nkind
(P
) = N_Package_Body
5133 or else Nkind
(P
) = N_Subprogram_Body
5135 Spec
:= Corresponding_Spec
(P
);
5137 if Present
(Spec
) then
5138 Decl
:= Unit_Declaration_Node
(Spec
);
5140 if Nkind
(Decl
) = N_Generic_Package_Declaration
5141 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5152 end Enclosing_Generic_Body
;
5154 ----------------------------
5155 -- Enclosing_Generic_Unit --
5156 ----------------------------
5158 function Enclosing_Generic_Unit
5159 (N
: Node_Id
) return Node_Id
5167 while Present
(P
) loop
5168 if Nkind
(P
) = N_Generic_Package_Declaration
5169 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
5173 elsif Nkind
(P
) = N_Package_Body
5174 or else Nkind
(P
) = N_Subprogram_Body
5176 Spec
:= Corresponding_Spec
(P
);
5178 if Present
(Spec
) then
5179 Decl
:= Unit_Declaration_Node
(Spec
);
5181 if Nkind
(Decl
) = N_Generic_Package_Declaration
5182 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5193 end Enclosing_Generic_Unit
;
5195 -------------------------------
5196 -- Enclosing_Lib_Unit_Entity --
5197 -------------------------------
5199 function Enclosing_Lib_Unit_Entity
5200 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
5202 Unit_Entity
: Entity_Id
;
5205 -- Look for enclosing library unit entity by following scope links.
5206 -- Equivalent to, but faster than indexing through the scope stack.
5209 while (Present
(Scope
(Unit_Entity
))
5210 and then Scope
(Unit_Entity
) /= Standard_Standard
)
5211 and not Is_Child_Unit
(Unit_Entity
)
5213 Unit_Entity
:= Scope
(Unit_Entity
);
5217 end Enclosing_Lib_Unit_Entity
;
5219 -----------------------
5220 -- Enclosing_Package --
5221 -----------------------
5223 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
5224 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5227 if Dynamic_Scope
= Standard_Standard
then
5228 return Standard_Standard
;
5230 elsif Dynamic_Scope
= Empty
then
5233 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
5236 return Dynamic_Scope
;
5239 return Enclosing_Package
(Dynamic_Scope
);
5241 end Enclosing_Package
;
5243 --------------------------
5244 -- Enclosing_Subprogram --
5245 --------------------------
5247 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5248 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5251 if Dynamic_Scope
= Standard_Standard
then
5254 elsif Dynamic_Scope
= Empty
then
5257 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
5258 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
5260 elsif Ekind
(Dynamic_Scope
) = E_Block
5261 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
5263 return Enclosing_Subprogram
(Dynamic_Scope
);
5265 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
5266 return Get_Task_Body_Procedure
(Dynamic_Scope
);
5268 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
5269 and then Present
(Full_View
(Dynamic_Scope
))
5270 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
5272 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
5274 -- No body is generated if the protected operation is eliminated
5276 elsif Convention
(Dynamic_Scope
) = Convention_Protected
5277 and then not Is_Eliminated
(Dynamic_Scope
)
5278 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
5280 return Protected_Body_Subprogram
(Dynamic_Scope
);
5283 return Dynamic_Scope
;
5285 end Enclosing_Subprogram
;
5287 ------------------------
5288 -- Ensure_Freeze_Node --
5289 ------------------------
5291 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
5294 if No
(Freeze_Node
(E
)) then
5295 FN
:= Make_Freeze_Entity
(Sloc
(E
));
5296 Set_Has_Delayed_Freeze
(E
);
5297 Set_Freeze_Node
(E
, FN
);
5298 Set_Access_Types_To_Process
(FN
, No_Elist
);
5299 Set_TSS_Elist
(FN
, No_Elist
);
5302 end Ensure_Freeze_Node
;
5308 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5309 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5310 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5311 S
: constant Entity_Id
:= Current_Scope
;
5314 Generate_Definition
(Def_Id
);
5316 -- Add new name to current scope declarations. Check for duplicate
5317 -- declaration, which may or may not be a genuine error.
5321 -- Case of previous entity entered because of a missing declaration
5322 -- or else a bad subtype indication. Best is to use the new entity,
5323 -- and make the previous one invisible.
5325 if Etype
(E
) = Any_Type
then
5326 Set_Is_Immediately_Visible
(E
, False);
5328 -- Case of renaming declaration constructed for package instances.
5329 -- if there is an explicit declaration with the same identifier,
5330 -- the renaming is not immediately visible any longer, but remains
5331 -- visible through selected component notation.
5333 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
5334 and then not Comes_From_Source
(E
)
5336 Set_Is_Immediately_Visible
(E
, False);
5338 -- The new entity may be the package renaming, which has the same
5339 -- same name as a generic formal which has been seen already.
5341 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
5342 and then not Comes_From_Source
(Def_Id
)
5344 Set_Is_Immediately_Visible
(E
, False);
5346 -- For a fat pointer corresponding to a remote access to subprogram,
5347 -- we use the same identifier as the RAS type, so that the proper
5348 -- name appears in the stub. This type is only retrieved through
5349 -- the RAS type and never by visibility, and is not added to the
5350 -- visibility list (see below).
5352 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
5353 and then Ekind
(Def_Id
) = E_Record_Type
5354 and then Present
(Corresponding_Remote_Type
(Def_Id
))
5358 -- Case of an implicit operation or derived literal. The new entity
5359 -- hides the implicit one, which is removed from all visibility,
5360 -- i.e. the entity list of its scope, and homonym chain of its name.
5362 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
5363 or else Is_Internal
(E
)
5367 Prev_Vis
: Entity_Id
;
5368 Decl
: constant Node_Id
:= Parent
(E
);
5371 -- If E is an implicit declaration, it cannot be the first
5372 -- entity in the scope.
5374 Prev
:= First_Entity
(Current_Scope
);
5375 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
5381 -- If E is not on the entity chain of the current scope,
5382 -- it is an implicit declaration in the generic formal
5383 -- part of a generic subprogram. When analyzing the body,
5384 -- the generic formals are visible but not on the entity
5385 -- chain of the subprogram. The new entity will become
5386 -- the visible one in the body.
5389 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
5393 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5395 if No
(Next_Entity
(Prev
)) then
5396 Set_Last_Entity
(Current_Scope
, Prev
);
5399 if E
= Current_Entity
(E
) then
5403 Prev_Vis
:= Current_Entity
(E
);
5404 while Homonym
(Prev_Vis
) /= E
loop
5405 Prev_Vis
:= Homonym
(Prev_Vis
);
5409 if Present
(Prev_Vis
) then
5411 -- Skip E in the visibility chain
5413 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5416 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5421 -- This section of code could use a comment ???
5423 elsif Present
(Etype
(E
))
5424 and then Is_Concurrent_Type
(Etype
(E
))
5429 -- If the homograph is a protected component renaming, it should not
5430 -- be hiding the current entity. Such renamings are treated as weak
5433 elsif Is_Prival
(E
) then
5434 Set_Is_Immediately_Visible
(E
, False);
5436 -- In this case the current entity is a protected component renaming.
5437 -- Perform minimal decoration by setting the scope and return since
5438 -- the prival should not be hiding other visible entities.
5440 elsif Is_Prival
(Def_Id
) then
5441 Set_Scope
(Def_Id
, Current_Scope
);
5444 -- Analogous to privals, the discriminal generated for an entry index
5445 -- parameter acts as a weak declaration. Perform minimal decoration
5446 -- to avoid bogus errors.
5448 elsif Is_Discriminal
(Def_Id
)
5449 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
5451 Set_Scope
(Def_Id
, Current_Scope
);
5454 -- In the body or private part of an instance, a type extension may
5455 -- introduce a component with the same name as that of an actual. The
5456 -- legality rule is not enforced, but the semantics of the full type
5457 -- with two components of same name are not clear at this point???
5459 elsif In_Instance_Not_Visible
then
5462 -- When compiling a package body, some child units may have become
5463 -- visible. They cannot conflict with local entities that hide them.
5465 elsif Is_Child_Unit
(E
)
5466 and then In_Open_Scopes
(Scope
(E
))
5467 and then not Is_Immediately_Visible
(E
)
5471 -- Conversely, with front-end inlining we may compile the parent body
5472 -- first, and a child unit subsequently. The context is now the
5473 -- parent spec, and body entities are not visible.
5475 elsif Is_Child_Unit
(Def_Id
)
5476 and then Is_Package_Body_Entity
(E
)
5477 and then not In_Package_Body
(Current_Scope
)
5481 -- Case of genuine duplicate declaration
5484 Error_Msg_Sloc
:= Sloc
(E
);
5486 -- If the previous declaration is an incomplete type declaration
5487 -- this may be an attempt to complete it with a private type. The
5488 -- following avoids confusing cascaded errors.
5490 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
5491 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
5494 ("incomplete type cannot be completed with a private " &
5495 "declaration", Parent
(Def_Id
));
5496 Set_Is_Immediately_Visible
(E
, False);
5497 Set_Full_View
(E
, Def_Id
);
5499 -- An inherited component of a record conflicts with a new
5500 -- discriminant. The discriminant is inserted first in the scope,
5501 -- but the error should be posted on it, not on the component.
5503 elsif Ekind
(E
) = E_Discriminant
5504 and then Present
(Scope
(Def_Id
))
5505 and then Scope
(Def_Id
) /= Current_Scope
5507 Error_Msg_Sloc
:= Sloc
(Def_Id
);
5508 Error_Msg_N
("& conflicts with declaration#", E
);
5511 -- If the name of the unit appears in its own context clause, a
5512 -- dummy package with the name has already been created, and the
5513 -- error emitted. Try to continue quietly.
5515 elsif Error_Posted
(E
)
5516 and then Sloc
(E
) = No_Location
5517 and then Nkind
(Parent
(E
)) = N_Package_Specification
5518 and then Current_Scope
= Standard_Standard
5520 Set_Scope
(Def_Id
, Current_Scope
);
5524 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
5526 -- Avoid cascaded messages with duplicate components in
5529 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
5534 if Nkind
(Parent
(Parent
(Def_Id
))) =
5535 N_Generic_Subprogram_Declaration
5537 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
5539 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
5542 -- If entity is in standard, then we are in trouble, because it
5543 -- means that we have a library package with a duplicated name.
5544 -- That's hard to recover from, so abort.
5546 if S
= Standard_Standard
then
5547 raise Unrecoverable_Error
;
5549 -- Otherwise we continue with the declaration. Having two
5550 -- identical declarations should not cause us too much trouble.
5558 -- If we fall through, declaration is OK, at least OK enough to continue
5560 -- If Def_Id is a discriminant or a record component we are in the midst
5561 -- of inheriting components in a derived record definition. Preserve
5562 -- their Ekind and Etype.
5564 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
5567 -- If a type is already set, leave it alone (happens when a type
5568 -- declaration is reanalyzed following a call to the optimizer).
5570 elsif Present
(Etype
(Def_Id
)) then
5573 -- Otherwise, the kind E_Void insures that premature uses of the entity
5574 -- will be detected. Any_Type insures that no cascaded errors will occur
5577 Set_Ekind
(Def_Id
, E_Void
);
5578 Set_Etype
(Def_Id
, Any_Type
);
5581 -- Inherited discriminants and components in derived record types are
5582 -- immediately visible. Itypes are not.
5584 -- Unless the Itype is for a record type with a corresponding remote
5585 -- type (what is that about, it was not commented ???)
5587 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
5589 ((not Is_Record_Type
(Def_Id
)
5590 or else No
(Corresponding_Remote_Type
(Def_Id
)))
5591 and then not Is_Itype
(Def_Id
))
5593 Set_Is_Immediately_Visible
(Def_Id
);
5594 Set_Current_Entity
(Def_Id
);
5597 Set_Homonym
(Def_Id
, C
);
5598 Append_Entity
(Def_Id
, S
);
5599 Set_Public_Status
(Def_Id
);
5601 -- Declaring a homonym is not allowed in SPARK ...
5603 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
5605 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
5606 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
5607 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
5610 -- ... unless the new declaration is in a subprogram, and the
5611 -- visible declaration is a variable declaration or a parameter
5612 -- specification outside that subprogram.
5614 if Present
(Enclosing_Subp
)
5615 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
5616 N_Parameter_Specification
)
5617 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
5621 -- ... or the new declaration is in a package, and the visible
5622 -- declaration occurs outside that package.
5624 elsif Present
(Enclosing_Pack
)
5625 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
5629 -- ... or the new declaration is a component declaration in a
5630 -- record type definition.
5632 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
5635 -- Don't issue error for non-source entities
5637 elsif Comes_From_Source
(Def_Id
)
5638 and then Comes_From_Source
(C
)
5640 Error_Msg_Sloc
:= Sloc
(C
);
5641 Check_SPARK_05_Restriction
5642 ("redeclaration of identifier &#", Def_Id
);
5647 -- Warn if new entity hides an old one
5649 if Warn_On_Hiding
and then Present
(C
)
5651 -- Don't warn for record components since they always have a well
5652 -- defined scope which does not confuse other uses. Note that in
5653 -- some cases, Ekind has not been set yet.
5655 and then Ekind
(C
) /= E_Component
5656 and then Ekind
(C
) /= E_Discriminant
5657 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
5658 and then Ekind
(Def_Id
) /= E_Component
5659 and then Ekind
(Def_Id
) /= E_Discriminant
5660 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
5662 -- Don't warn for one character variables. It is too common to use
5663 -- such variables as locals and will just cause too many false hits.
5665 and then Length_Of_Name
(Chars
(C
)) /= 1
5667 -- Don't warn for non-source entities
5669 and then Comes_From_Source
(C
)
5670 and then Comes_From_Source
(Def_Id
)
5672 -- Don't warn unless entity in question is in extended main source
5674 and then In_Extended_Main_Source_Unit
(Def_Id
)
5676 -- Finally, the hidden entity must be either immediately visible or
5677 -- use visible (i.e. from a used package).
5680 (Is_Immediately_Visible
(C
)
5682 Is_Potentially_Use_Visible
(C
))
5684 Error_Msg_Sloc
:= Sloc
(C
);
5685 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
5693 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
5699 if Is_Entity_Name
(N
) then
5702 -- Follow a possible chain of renamings to reach the root renamed
5705 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5706 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5707 Id
:= Entity
(Renamed_Object
(Id
));
5718 --------------------------
5719 -- Explain_Limited_Type --
5720 --------------------------
5722 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5726 -- For array, component type must be limited
5728 if Is_Array_Type
(T
) then
5729 Error_Msg_Node_2
:= T
;
5731 ("\component type& of type& is limited", N
, Component_Type
(T
));
5732 Explain_Limited_Type
(Component_Type
(T
), N
);
5734 elsif Is_Record_Type
(T
) then
5736 -- No need for extra messages if explicit limited record
5738 if Is_Limited_Record
(Base_Type
(T
)) then
5742 -- Otherwise find a limited component. Check only components that
5743 -- come from source, or inherited components that appear in the
5744 -- source of the ancestor.
5746 C
:= First_Component
(T
);
5747 while Present
(C
) loop
5748 if Is_Limited_Type
(Etype
(C
))
5750 (Comes_From_Source
(C
)
5752 (Present
(Original_Record_Component
(C
))
5754 Comes_From_Source
(Original_Record_Component
(C
))))
5756 Error_Msg_Node_2
:= T
;
5757 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
5758 Explain_Limited_Type
(Etype
(C
), N
);
5765 -- The type may be declared explicitly limited, even if no component
5766 -- of it is limited, in which case we fall out of the loop.
5769 end Explain_Limited_Type
;
5775 procedure Find_Actual
5777 Formal
: out Entity_Id
;
5780 Parnt
: constant Node_Id
:= Parent
(N
);
5784 if Nkind_In
(Parnt
, N_Indexed_Component
, N_Selected_Component
)
5785 and then N
= Prefix
(Parnt
)
5787 Find_Actual
(Parnt
, Formal
, Call
);
5790 elsif Nkind
(Parnt
) = N_Parameter_Association
5791 and then N
= Explicit_Actual_Parameter
(Parnt
)
5793 Call
:= Parent
(Parnt
);
5795 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
5804 -- If we have a call to a subprogram look for the parameter. Note that
5805 -- we exclude overloaded calls, since we don't know enough to be sure
5806 -- of giving the right answer in this case.
5808 if Nkind_In
(Call
, N_Function_Call
, N_Procedure_Call_Statement
)
5809 and then Is_Entity_Name
(Name
(Call
))
5810 and then Present
(Entity
(Name
(Call
)))
5811 and then Is_Overloadable
(Entity
(Name
(Call
)))
5812 and then not Is_Overloaded
(Name
(Call
))
5814 -- Fall here if we are definitely a parameter
5816 Actual
:= First_Actual
(Call
);
5817 Formal
:= First_Formal
(Entity
(Name
(Call
)));
5818 while Present
(Formal
) and then Present
(Actual
) loop
5822 -- An actual that is the prefix in a prefixed call may have
5823 -- been rewritten in the call, after the deferred reference
5824 -- was collected. Check if sloc and kinds and names match.
5826 elsif Sloc
(Actual
) = Sloc
(N
)
5827 and then Nkind
(Actual
) = N_Identifier
5828 and then Nkind
(Actual
) = Nkind
(N
)
5829 and then Chars
(Actual
) = Chars
(N
)
5834 Actual
:= Next_Actual
(Actual
);
5835 Formal
:= Next_Formal
(Formal
);
5840 -- Fall through here if we did not find matching actual
5846 ---------------------------
5847 -- Find_Body_Discriminal --
5848 ---------------------------
5850 function Find_Body_Discriminal
5851 (Spec_Discriminant
: Entity_Id
) return Entity_Id
5857 -- If expansion is suppressed, then the scope can be the concurrent type
5858 -- itself rather than a corresponding concurrent record type.
5860 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
5861 Tsk
:= Scope
(Spec_Discriminant
);
5864 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
5866 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
5869 -- Find discriminant of original concurrent type, and use its current
5870 -- discriminal, which is the renaming within the task/protected body.
5872 Disc
:= First_Discriminant
(Tsk
);
5873 while Present
(Disc
) loop
5874 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
5875 return Discriminal
(Disc
);
5878 Next_Discriminant
(Disc
);
5881 -- That loop should always succeed in finding a matching entry and
5882 -- returning. Fatal error if not.
5884 raise Program_Error
;
5885 end Find_Body_Discriminal
;
5887 -------------------------------------
5888 -- Find_Corresponding_Discriminant --
5889 -------------------------------------
5891 function Find_Corresponding_Discriminant
5893 Typ
: Entity_Id
) return Entity_Id
5895 Par_Disc
: Entity_Id
;
5896 Old_Disc
: Entity_Id
;
5897 New_Disc
: Entity_Id
;
5900 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
5902 -- The original type may currently be private, and the discriminant
5903 -- only appear on its full view.
5905 if Is_Private_Type
(Scope
(Par_Disc
))
5906 and then not Has_Discriminants
(Scope
(Par_Disc
))
5907 and then Present
(Full_View
(Scope
(Par_Disc
)))
5909 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
5911 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
5914 if Is_Class_Wide_Type
(Typ
) then
5915 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
5917 New_Disc
:= First_Discriminant
(Typ
);
5920 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
5921 if Old_Disc
= Par_Disc
then
5925 Next_Discriminant
(Old_Disc
);
5926 Next_Discriminant
(New_Disc
);
5929 -- Should always find it
5931 raise Program_Error
;
5932 end Find_Corresponding_Discriminant
;
5934 ----------------------------------
5935 -- Find_Enclosing_Iterator_Loop --
5936 ----------------------------------
5938 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
5943 -- Traverse the scope chain looking for an iterator loop. Such loops are
5944 -- usually transformed into blocks, hence the use of Original_Node.
5947 while Present
(S
) and then S
/= Standard_Standard
loop
5948 if Ekind
(S
) = E_Loop
5949 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
5951 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
5953 if Nkind
(Constr
) = N_Loop_Statement
5954 and then Present
(Iteration_Scheme
(Constr
))
5955 and then Nkind
(Iterator_Specification
5956 (Iteration_Scheme
(Constr
))) =
5957 N_Iterator_Specification
5967 end Find_Enclosing_Iterator_Loop
;
5969 ------------------------------------
5970 -- Find_Loop_In_Conditional_Block --
5971 ------------------------------------
5973 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
5979 if Nkind
(Stmt
) = N_If_Statement
then
5980 Stmt
:= First
(Then_Statements
(Stmt
));
5983 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
5985 -- Inspect the statements of the conditional block. In general the loop
5986 -- should be the first statement in the statement sequence of the block,
5987 -- but the finalization machinery may have introduced extra object
5990 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
5991 while Present
(Stmt
) loop
5992 if Nkind
(Stmt
) = N_Loop_Statement
then
5999 -- The expansion of attribute 'Loop_Entry produced a malformed block
6001 raise Program_Error
;
6002 end Find_Loop_In_Conditional_Block
;
6004 --------------------------
6005 -- Find_Overlaid_Entity --
6006 --------------------------
6008 procedure Find_Overlaid_Entity
6010 Ent
: out Entity_Id
;
6016 -- We are looking for one of the two following forms:
6018 -- for X'Address use Y'Address
6022 -- Const : constant Address := expr;
6024 -- for X'Address use Const;
6026 -- In the second case, the expr is either Y'Address, or recursively a
6027 -- constant that eventually references Y'Address.
6032 if Nkind
(N
) = N_Attribute_Definition_Clause
6033 and then Chars
(N
) = Name_Address
6035 Expr
:= Expression
(N
);
6037 -- This loop checks the form of the expression for Y'Address,
6038 -- using recursion to deal with intermediate constants.
6041 -- Check for Y'Address
6043 if Nkind
(Expr
) = N_Attribute_Reference
6044 and then Attribute_Name
(Expr
) = Name_Address
6046 Expr
:= Prefix
(Expr
);
6049 -- Check for Const where Const is a constant entity
6051 elsif Is_Entity_Name
(Expr
)
6052 and then Ekind
(Entity
(Expr
)) = E_Constant
6054 Expr
:= Constant_Value
(Entity
(Expr
));
6056 -- Anything else does not need checking
6063 -- This loop checks the form of the prefix for an entity, using
6064 -- recursion to deal with intermediate components.
6067 -- Check for Y where Y is an entity
6069 if Is_Entity_Name
(Expr
) then
6070 Ent
:= Entity
(Expr
);
6073 -- Check for components
6076 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
6078 Expr
:= Prefix
(Expr
);
6081 -- Anything else does not need checking
6088 end Find_Overlaid_Entity
;
6090 -------------------------
6091 -- Find_Parameter_Type --
6092 -------------------------
6094 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
6096 if Nkind
(Param
) /= N_Parameter_Specification
then
6099 -- For an access parameter, obtain the type from the formal entity
6100 -- itself, because access to subprogram nodes do not carry a type.
6101 -- Shouldn't we always use the formal entity ???
6103 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
6104 return Etype
(Defining_Identifier
(Param
));
6107 return Etype
(Parameter_Type
(Param
));
6109 end Find_Parameter_Type
;
6111 -----------------------------------
6112 -- Find_Placement_In_State_Space --
6113 -----------------------------------
6115 procedure Find_Placement_In_State_Space
6116 (Item_Id
: Entity_Id
;
6117 Placement
: out State_Space_Kind
;
6118 Pack_Id
: out Entity_Id
)
6120 Context
: Entity_Id
;
6123 -- Assume that the item does not appear in the state space of a package
6125 Placement
:= Not_In_Package
;
6128 -- Climb the scope stack and examine the enclosing context
6130 Context
:= Scope
(Item_Id
);
6131 while Present
(Context
) and then Context
/= Standard_Standard
loop
6132 if Ekind
(Context
) = E_Package
then
6135 -- A package body is a cut off point for the traversal as the item
6136 -- cannot be visible to the outside from this point on. Note that
6137 -- this test must be done first as a body is also classified as a
6140 if In_Package_Body
(Context
) then
6141 Placement
:= Body_State_Space
;
6144 -- The private part of a package is a cut off point for the
6145 -- traversal as the item cannot be visible to the outside from
6148 elsif In_Private_Part
(Context
) then
6149 Placement
:= Private_State_Space
;
6152 -- When the item appears in the visible state space of a package,
6153 -- continue to climb the scope stack as this may not be the final
6157 Placement
:= Visible_State_Space
;
6159 -- The visible state space of a child unit acts as the proper
6160 -- placement of an item.
6162 if Is_Child_Unit
(Context
) then
6167 -- The item or its enclosing package appear in a construct that has
6171 Placement
:= Not_In_Package
;
6175 Context
:= Scope
(Context
);
6177 end Find_Placement_In_State_Space
;
6179 ------------------------
6180 -- Find_Specific_Type --
6181 ------------------------
6183 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
6184 Typ
: Entity_Id
:= Root_Type
(CW
);
6187 if Ekind
(Typ
) = E_Incomplete_Type
then
6188 if From_Limited_With
(Typ
) then
6189 Typ
:= Non_Limited_View
(Typ
);
6191 Typ
:= Full_View
(Typ
);
6195 if Is_Private_Type
(Typ
)
6196 and then not Is_Tagged_Type
(Typ
)
6197 and then Present
(Full_View
(Typ
))
6199 return Full_View
(Typ
);
6203 end Find_Specific_Type
;
6205 -----------------------------
6206 -- Find_Static_Alternative --
6207 -----------------------------
6209 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
6210 Expr
: constant Node_Id
:= Expression
(N
);
6211 Val
: constant Uint
:= Expr_Value
(Expr
);
6216 Alt
:= First
(Alternatives
(N
));
6219 if Nkind
(Alt
) /= N_Pragma
then
6220 Choice
:= First
(Discrete_Choices
(Alt
));
6221 while Present
(Choice
) loop
6223 -- Others choice, always matches
6225 if Nkind
(Choice
) = N_Others_Choice
then
6228 -- Range, check if value is in the range
6230 elsif Nkind
(Choice
) = N_Range
then
6232 Val
>= Expr_Value
(Low_Bound
(Choice
))
6234 Val
<= Expr_Value
(High_Bound
(Choice
));
6236 -- Choice is a subtype name. Note that we know it must
6237 -- be a static subtype, since otherwise it would have
6238 -- been diagnosed as illegal.
6240 elsif Is_Entity_Name
(Choice
) and then Is_Type
(Entity
(Choice
))
6242 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
6243 Assume_Valid
=> False);
6245 -- Choice is a subtype indication
6247 elsif Nkind
(Choice
) = N_Subtype_Indication
then
6249 C
: constant Node_Id
:= Constraint
(Choice
);
6250 R
: constant Node_Id
:= Range_Expression
(C
);
6254 Val
>= Expr_Value
(Low_Bound
(R
))
6256 Val
<= Expr_Value
(High_Bound
(R
));
6259 -- Choice is a simple expression
6262 exit Search
when Val
= Expr_Value
(Choice
);
6270 pragma Assert
(Present
(Alt
));
6273 -- The above loop *must* terminate by finding a match, since
6274 -- we know the case statement is valid, and the value of the
6275 -- expression is known at compile time. When we fall out of
6276 -- the loop, Alt points to the alternative that we know will
6277 -- be selected at run time.
6280 end Find_Static_Alternative
;
6286 function First_Actual
(Node
: Node_Id
) return Node_Id
is
6290 if No
(Parameter_Associations
(Node
)) then
6294 N
:= First
(Parameter_Associations
(Node
));
6296 if Nkind
(N
) = N_Parameter_Association
then
6297 return First_Named_Actual
(Node
);
6303 -----------------------
6304 -- Gather_Components --
6305 -----------------------
6307 procedure Gather_Components
6309 Comp_List
: Node_Id
;
6310 Governed_By
: List_Id
;
6312 Report_Errors
: out Boolean)
6316 Discrete_Choice
: Node_Id
;
6317 Comp_Item
: Node_Id
;
6319 Discrim
: Entity_Id
;
6320 Discrim_Name
: Node_Id
;
6321 Discrim_Value
: Node_Id
;
6324 Report_Errors
:= False;
6326 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
6329 elsif Present
(Component_Items
(Comp_List
)) then
6330 Comp_Item
:= First
(Component_Items
(Comp_List
));
6336 while Present
(Comp_Item
) loop
6338 -- Skip the tag of a tagged record, the interface tags, as well
6339 -- as all items that are not user components (anonymous types,
6340 -- rep clauses, Parent field, controller field).
6342 if Nkind
(Comp_Item
) = N_Component_Declaration
then
6344 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
6346 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
6347 Append_Elmt
(Comp
, Into
);
6355 if No
(Variant_Part
(Comp_List
)) then
6358 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
6359 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
6362 -- Look for the discriminant that governs this variant part.
6363 -- The discriminant *must* be in the Governed_By List
6365 Assoc
:= First
(Governed_By
);
6366 Find_Constraint
: loop
6367 Discrim
:= First
(Choices
(Assoc
));
6368 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
6369 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
6371 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
6372 Chars
(Discrim_Name
))
6373 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
6374 = Chars
(Discrim_Name
);
6376 if No
(Next
(Assoc
)) then
6377 if not Is_Constrained
(Typ
)
6378 and then Is_Derived_Type
(Typ
)
6379 and then Present
(Stored_Constraint
(Typ
))
6381 -- If the type is a tagged type with inherited discriminants,
6382 -- use the stored constraint on the parent in order to find
6383 -- the values of discriminants that are otherwise hidden by an
6384 -- explicit constraint. Renamed discriminants are handled in
6387 -- If several parent discriminants are renamed by a single
6388 -- discriminant of the derived type, the call to obtain the
6389 -- Corresponding_Discriminant field only retrieves the last
6390 -- of them. We recover the constraint on the others from the
6391 -- Stored_Constraint as well.
6398 D
:= First_Discriminant
(Etype
(Typ
));
6399 C
:= First_Elmt
(Stored_Constraint
(Typ
));
6400 while Present
(D
) and then Present
(C
) loop
6401 if Chars
(Discrim_Name
) = Chars
(D
) then
6402 if Is_Entity_Name
(Node
(C
))
6403 and then Entity
(Node
(C
)) = Entity
(Discrim
)
6405 -- D is renamed by Discrim, whose value is given in
6412 Make_Component_Association
(Sloc
(Typ
),
6414 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
6415 Duplicate_Subexpr_No_Checks
(Node
(C
)));
6417 exit Find_Constraint
;
6420 Next_Discriminant
(D
);
6427 if No
(Next
(Assoc
)) then
6428 Error_Msg_NE
(" missing value for discriminant&",
6429 First
(Governed_By
), Discrim_Name
);
6430 Report_Errors
:= True;
6435 end loop Find_Constraint
;
6437 Discrim_Value
:= Expression
(Assoc
);
6439 if not Is_OK_Static_Expression
(Discrim_Value
) then
6441 ("value for discriminant & must be static!",
6442 Discrim_Value
, Discrim
);
6443 Why_Not_Static
(Discrim_Value
);
6444 Report_Errors
:= True;
6448 Search_For_Discriminant_Value
: declare
6454 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
6457 Find_Discrete_Value
: while Present
(Variant
) loop
6458 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
6459 while Present
(Discrete_Choice
) loop
6460 exit Find_Discrete_Value
when
6461 Nkind
(Discrete_Choice
) = N_Others_Choice
;
6463 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
6465 UI_Low
:= Expr_Value
(Low
);
6466 UI_High
:= Expr_Value
(High
);
6468 exit Find_Discrete_Value
when
6469 UI_Low
<= UI_Discrim_Value
6471 UI_High
>= UI_Discrim_Value
;
6473 Next
(Discrete_Choice
);
6476 Next_Non_Pragma
(Variant
);
6477 end loop Find_Discrete_Value
;
6478 end Search_For_Discriminant_Value
;
6480 if No
(Variant
) then
6482 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
6483 Report_Errors
:= True;
6487 -- If we have found the corresponding choice, recursively add its
6488 -- components to the Into list.
6491 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
6492 end Gather_Components
;
6494 ------------------------
6495 -- Get_Actual_Subtype --
6496 ------------------------
6498 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
6499 Typ
: constant Entity_Id
:= Etype
(N
);
6500 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
6509 -- If what we have is an identifier that references a subprogram
6510 -- formal, or a variable or constant object, then we get the actual
6511 -- subtype from the referenced entity if one has been built.
6513 if Nkind
(N
) = N_Identifier
6515 (Is_Formal
(Entity
(N
))
6516 or else Ekind
(Entity
(N
)) = E_Constant
6517 or else Ekind
(Entity
(N
)) = E_Variable
)
6518 and then Present
(Actual_Subtype
(Entity
(N
)))
6520 return Actual_Subtype
(Entity
(N
));
6522 -- Actual subtype of unchecked union is always itself. We never need
6523 -- the "real" actual subtype. If we did, we couldn't get it anyway
6524 -- because the discriminant is not available. The restrictions on
6525 -- Unchecked_Union are designed to make sure that this is OK.
6527 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
6530 -- Here for the unconstrained case, we must find actual subtype
6531 -- No actual subtype is available, so we must build it on the fly.
6533 -- Checking the type, not the underlying type, for constrainedness
6534 -- seems to be necessary. Maybe all the tests should be on the type???
6536 elsif (not Is_Constrained
(Typ
))
6537 and then (Is_Array_Type
(Utyp
)
6538 or else (Is_Record_Type
(Utyp
)
6539 and then Has_Discriminants
(Utyp
)))
6540 and then not Has_Unknown_Discriminants
(Utyp
)
6541 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
6543 -- Nothing to do if in spec expression (why not???)
6545 if In_Spec_Expression
then
6548 elsif Is_Private_Type
(Typ
)
6549 and then not Has_Discriminants
(Typ
)
6551 -- If the type has no discriminants, there is no subtype to
6552 -- build, even if the underlying type is discriminated.
6556 -- Else build the actual subtype
6559 Decl
:= Build_Actual_Subtype
(Typ
, N
);
6560 Atyp
:= Defining_Identifier
(Decl
);
6562 -- If Build_Actual_Subtype generated a new declaration then use it
6566 -- The actual subtype is an Itype, so analyze the declaration,
6567 -- but do not attach it to the tree, to get the type defined.
6569 Set_Parent
(Decl
, N
);
6570 Set_Is_Itype
(Atyp
);
6571 Analyze
(Decl
, Suppress
=> All_Checks
);
6572 Set_Associated_Node_For_Itype
(Atyp
, N
);
6573 Set_Has_Delayed_Freeze
(Atyp
, False);
6575 -- We need to freeze the actual subtype immediately. This is
6576 -- needed, because otherwise this Itype will not get frozen
6577 -- at all, and it is always safe to freeze on creation because
6578 -- any associated types must be frozen at this point.
6580 Freeze_Itype
(Atyp
, N
);
6583 -- Otherwise we did not build a declaration, so return original
6590 -- For all remaining cases, the actual subtype is the same as
6591 -- the nominal type.
6596 end Get_Actual_Subtype
;
6598 -------------------------------------
6599 -- Get_Actual_Subtype_If_Available --
6600 -------------------------------------
6602 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
6603 Typ
: constant Entity_Id
:= Etype
(N
);
6606 -- If what we have is an identifier that references a subprogram
6607 -- formal, or a variable or constant object, then we get the actual
6608 -- subtype from the referenced entity if one has been built.
6610 if Nkind
(N
) = N_Identifier
6612 (Is_Formal
(Entity
(N
))
6613 or else Ekind
(Entity
(N
)) = E_Constant
6614 or else Ekind
(Entity
(N
)) = E_Variable
)
6615 and then Present
(Actual_Subtype
(Entity
(N
)))
6617 return Actual_Subtype
(Entity
(N
));
6619 -- Otherwise the Etype of N is returned unchanged
6624 end Get_Actual_Subtype_If_Available
;
6626 ------------------------
6627 -- Get_Body_From_Stub --
6628 ------------------------
6630 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
6632 return Proper_Body
(Unit
(Library_Unit
(N
)));
6633 end Get_Body_From_Stub
;
6635 ---------------------
6636 -- Get_Cursor_Type --
6637 ---------------------
6639 function Get_Cursor_Type
6641 Typ
: Entity_Id
) return Entity_Id
6645 First_Op
: Entity_Id
;
6649 -- If error already detected, return
6651 if Error_Posted
(Aspect
) then
6655 -- The cursor type for an Iterable aspect is the return type of a
6656 -- non-overloaded First primitive operation. Locate association for
6659 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
6661 while Present
(Assoc
) loop
6662 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
6663 First_Op
:= Expression
(Assoc
);
6670 if First_Op
= Any_Id
then
6671 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
6677 -- Locate function with desired name and profile in scope of type
6679 Func
:= First_Entity
(Scope
(Typ
));
6680 while Present
(Func
) loop
6681 if Chars
(Func
) = Chars
(First_Op
)
6682 and then Ekind
(Func
) = E_Function
6683 and then Present
(First_Formal
(Func
))
6684 and then Etype
(First_Formal
(Func
)) = Typ
6685 and then No
(Next_Formal
(First_Formal
(Func
)))
6687 if Cursor
/= Any_Type
then
6689 ("Operation First for iterable type must be unique", Aspect
);
6692 Cursor
:= Etype
(Func
);
6699 -- If not found, no way to resolve remaining primitives.
6701 if Cursor
= Any_Type
then
6703 ("No legal primitive operation First for Iterable type", Aspect
);
6707 end Get_Cursor_Type
;
6709 -------------------------------
6710 -- Get_Default_External_Name --
6711 -------------------------------
6713 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
6715 Get_Decoded_Name_String
(Chars
(E
));
6717 if Opt
.External_Name_Imp_Casing
= Uppercase
then
6718 Set_Casing
(All_Upper_Case
);
6720 Set_Casing
(All_Lower_Case
);
6724 Make_String_Literal
(Sloc
(E
),
6725 Strval
=> String_From_Name_Buffer
);
6726 end Get_Default_External_Name
;
6728 --------------------------
6729 -- Get_Enclosing_Object --
6730 --------------------------
6732 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
6734 if Is_Entity_Name
(N
) then
6738 when N_Indexed_Component |
6740 N_Selected_Component
=>
6742 -- If not generating code, a dereference may be left implicit.
6743 -- In thoses cases, return Empty.
6745 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6748 return Get_Enclosing_Object
(Prefix
(N
));
6751 when N_Type_Conversion
=>
6752 return Get_Enclosing_Object
(Expression
(N
));
6758 end Get_Enclosing_Object
;
6760 ---------------------------
6761 -- Get_Enum_Lit_From_Pos --
6762 ---------------------------
6764 function Get_Enum_Lit_From_Pos
6767 Loc
: Source_Ptr
) return Node_Id
6769 Btyp
: Entity_Id
:= Base_Type
(T
);
6773 -- In the case where the literal is of type Character, Wide_Character
6774 -- or Wide_Wide_Character or of a type derived from them, there needs
6775 -- to be some special handling since there is no explicit chain of
6776 -- literals to search. Instead, an N_Character_Literal node is created
6777 -- with the appropriate Char_Code and Chars fields.
6779 if Is_Standard_Character_Type
(T
) then
6780 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
6782 Make_Character_Literal
(Loc
,
6784 Char_Literal_Value
=> Pos
);
6786 -- For all other cases, we have a complete table of literals, and
6787 -- we simply iterate through the chain of literal until the one
6788 -- with the desired position value is found.
6792 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
6793 Btyp
:= Full_View
(Btyp
);
6796 Lit
:= First_Literal
(Btyp
);
6797 for J
in 1 .. UI_To_Int
(Pos
) loop
6801 return New_Occurrence_Of
(Lit
, Loc
);
6803 end Get_Enum_Lit_From_Pos
;
6805 ---------------------------------
6806 -- Get_Ensures_From_CTC_Pragma --
6807 ---------------------------------
6809 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
6810 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
6814 if List_Length
(Args
) = 4 then
6815 Res
:= Pick
(Args
, 4);
6817 elsif List_Length
(Args
) = 3 then
6818 Res
:= Pick
(Args
, 3);
6820 if Chars
(Res
) /= Name_Ensures
then
6829 end Get_Ensures_From_CTC_Pragma
;
6831 ------------------------
6832 -- Get_Generic_Entity --
6833 ------------------------
6835 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
6836 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
6838 if Present
(Renamed_Object
(Ent
)) then
6839 return Renamed_Object
(Ent
);
6843 end Get_Generic_Entity
;
6845 -------------------------------------
6846 -- Get_Incomplete_View_Of_Ancestor --
6847 -------------------------------------
6849 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
6850 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
6851 Par_Scope
: Entity_Id
;
6852 Par_Type
: Entity_Id
;
6855 -- The incomplete view of an ancestor is only relevant for private
6856 -- derived types in child units.
6858 if not Is_Derived_Type
(E
)
6859 or else not Is_Child_Unit
(Cur_Unit
)
6864 Par_Scope
:= Scope
(Cur_Unit
);
6865 if No
(Par_Scope
) then
6869 Par_Type
:= Etype
(Base_Type
(E
));
6871 -- Traverse list of ancestor types until we find one declared in
6872 -- a parent or grandparent unit (two levels seem sufficient).
6874 while Present
(Par_Type
) loop
6875 if Scope
(Par_Type
) = Par_Scope
6876 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
6880 elsif not Is_Derived_Type
(Par_Type
) then
6884 Par_Type
:= Etype
(Base_Type
(Par_Type
));
6888 -- If none found, there is no relevant ancestor type.
6892 end Get_Incomplete_View_Of_Ancestor
;
6894 ----------------------
6895 -- Get_Index_Bounds --
6896 ----------------------
6898 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
6899 Kind
: constant Node_Kind
:= Nkind
(N
);
6903 if Kind
= N_Range
then
6905 H
:= High_Bound
(N
);
6907 elsif Kind
= N_Subtype_Indication
then
6908 R
:= Range_Expression
(Constraint
(N
));
6916 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
6917 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
6920 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
6921 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
6925 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
6926 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
6929 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
6930 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
6934 -- N is an expression, indicating a range with one value
6939 end Get_Index_Bounds
;
6941 ---------------------------------
6942 -- Get_Iterable_Type_Primitive --
6943 ---------------------------------
6945 function Get_Iterable_Type_Primitive
6947 Nam
: Name_Id
) return Entity_Id
6949 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
6957 Assoc
:= First
(Component_Associations
(Funcs
));
6958 while Present
(Assoc
) loop
6959 if Chars
(First
(Choices
(Assoc
))) = Nam
then
6960 return Entity
(Expression
(Assoc
));
6963 Assoc
:= Next
(Assoc
);
6968 end Get_Iterable_Type_Primitive
;
6970 ----------------------------------
6971 -- Get_Library_Unit_Name_string --
6972 ----------------------------------
6974 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
6975 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
6978 Get_Unit_Name_String
(Unit_Name_Id
);
6980 -- Remove seven last character (" (spec)" or " (body)")
6982 Name_Len
:= Name_Len
- 7;
6983 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
6984 end Get_Library_Unit_Name_String
;
6986 ------------------------
6987 -- Get_Name_Entity_Id --
6988 ------------------------
6990 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
6992 return Entity_Id
(Get_Name_Table_Info
(Id
));
6993 end Get_Name_Entity_Id
;
6995 ------------------------------
6996 -- Get_Name_From_CTC_Pragma --
6997 ------------------------------
6999 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
7000 Arg
: constant Node_Id
:=
7001 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
7003 return Strval
(Expr_Value_S
(Arg
));
7004 end Get_Name_From_CTC_Pragma
;
7006 -----------------------
7007 -- Get_Parent_Entity --
7008 -----------------------
7010 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
7012 if Nkind
(Unit
) = N_Package_Body
7013 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
7015 return Defining_Entity
7016 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
7017 elsif Nkind
(Unit
) = N_Package_Instantiation
then
7018 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
7020 return Defining_Entity
(Unit
);
7022 end Get_Parent_Entity
;
7027 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
7029 return Get_Pragma_Id
(Pragma_Name
(N
));
7032 -----------------------
7033 -- Get_Reason_String --
7034 -----------------------
7036 procedure Get_Reason_String
(N
: Node_Id
) is
7038 if Nkind
(N
) = N_String_Literal
then
7039 Store_String_Chars
(Strval
(N
));
7041 elsif Nkind
(N
) = N_Op_Concat
then
7042 Get_Reason_String
(Left_Opnd
(N
));
7043 Get_Reason_String
(Right_Opnd
(N
));
7045 -- If not of required form, error
7049 ("Reason for pragma Warnings has wrong form", N
);
7051 ("\must be string literal or concatenation of string literals", N
);
7054 end Get_Reason_String
;
7056 ---------------------------
7057 -- Get_Referenced_Object --
7058 ---------------------------
7060 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
7065 while Is_Entity_Name
(R
)
7066 and then Present
(Renamed_Object
(Entity
(R
)))
7068 R
:= Renamed_Object
(Entity
(R
));
7072 end Get_Referenced_Object
;
7074 ------------------------
7075 -- Get_Renamed_Entity --
7076 ------------------------
7078 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
7083 while Present
(Renamed_Entity
(R
)) loop
7084 R
:= Renamed_Entity
(R
);
7088 end Get_Renamed_Entity
;
7090 ----------------------------------
7091 -- Get_Requires_From_CTC_Pragma --
7092 ----------------------------------
7094 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
7095 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
7099 if List_Length
(Args
) >= 3 then
7100 Res
:= Pick
(Args
, 3);
7102 if Chars
(Res
) /= Name_Requires
then
7111 end Get_Requires_From_CTC_Pragma
;
7113 -------------------------
7114 -- Get_Subprogram_Body --
7115 -------------------------
7117 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
7121 Decl
:= Unit_Declaration_Node
(E
);
7123 if Nkind
(Decl
) = N_Subprogram_Body
then
7126 -- The below comment is bad, because it is possible for
7127 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7129 else -- Nkind (Decl) = N_Subprogram_Declaration
7131 if Present
(Corresponding_Body
(Decl
)) then
7132 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
7134 -- Imported subprogram case
7140 end Get_Subprogram_Body
;
7142 ---------------------------
7143 -- Get_Subprogram_Entity --
7144 ---------------------------
7146 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
7148 Subp_Id
: Entity_Id
;
7151 if Nkind
(Nod
) = N_Accept_Statement
then
7152 Subp
:= Entry_Direct_Name
(Nod
);
7154 elsif Nkind
(Nod
) = N_Slice
then
7155 Subp
:= Prefix
(Nod
);
7161 -- Strip the subprogram call
7164 if Nkind_In
(Subp
, N_Explicit_Dereference
,
7165 N_Indexed_Component
,
7166 N_Selected_Component
)
7168 Subp
:= Prefix
(Subp
);
7170 elsif Nkind_In
(Subp
, N_Type_Conversion
,
7171 N_Unchecked_Type_Conversion
)
7173 Subp
:= Expression
(Subp
);
7180 -- Extract the entity of the subprogram call
7182 if Is_Entity_Name
(Subp
) then
7183 Subp_Id
:= Entity
(Subp
);
7185 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
7186 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
7189 if Is_Subprogram
(Subp_Id
) then
7195 -- The search did not find a construct that denotes a subprogram
7200 end Get_Subprogram_Entity
;
7202 -----------------------------
7203 -- Get_Task_Body_Procedure --
7204 -----------------------------
7206 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
7208 -- Note: A task type may be the completion of a private type with
7209 -- discriminants. When performing elaboration checks on a task
7210 -- declaration, the current view of the type may be the private one,
7211 -- and the procedure that holds the body of the task is held in its
7214 -- This is an odd function, why not have Task_Body_Procedure do
7215 -- the following digging???
7217 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
7218 end Get_Task_Body_Procedure
;
7220 -----------------------
7221 -- Has_Access_Values --
7222 -----------------------
7224 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
7225 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
7228 -- Case of a private type which is not completed yet. This can only
7229 -- happen in the case of a generic format type appearing directly, or
7230 -- as a component of the type to which this function is being applied
7231 -- at the top level. Return False in this case, since we certainly do
7232 -- not know that the type contains access types.
7237 elsif Is_Access_Type
(Typ
) then
7240 elsif Is_Array_Type
(Typ
) then
7241 return Has_Access_Values
(Component_Type
(Typ
));
7243 elsif Is_Record_Type
(Typ
) then
7248 -- Loop to Check components
7250 Comp
:= First_Component_Or_Discriminant
(Typ
);
7251 while Present
(Comp
) loop
7253 -- Check for access component, tag field does not count, even
7254 -- though it is implemented internally using an access type.
7256 if Has_Access_Values
(Etype
(Comp
))
7257 and then Chars
(Comp
) /= Name_uTag
7262 Next_Component_Or_Discriminant
(Comp
);
7271 end Has_Access_Values
;
7273 ------------------------------
7274 -- Has_Compatible_Alignment --
7275 ------------------------------
7277 function Has_Compatible_Alignment
7279 Expr
: Node_Id
) return Alignment_Result
7281 function Has_Compatible_Alignment_Internal
7284 Default
: Alignment_Result
) return Alignment_Result
;
7285 -- This is the internal recursive function that actually does the work.
7286 -- There is one additional parameter, which says what the result should
7287 -- be if no alignment information is found, and there is no definite
7288 -- indication of compatible alignments. At the outer level, this is set
7289 -- to Unknown, but for internal recursive calls in the case where types
7290 -- are known to be correct, it is set to Known_Compatible.
7292 ---------------------------------------
7293 -- Has_Compatible_Alignment_Internal --
7294 ---------------------------------------
7296 function Has_Compatible_Alignment_Internal
7299 Default
: Alignment_Result
) return Alignment_Result
7301 Result
: Alignment_Result
:= Known_Compatible
;
7302 -- Holds the current status of the result. Note that once a value of
7303 -- Known_Incompatible is set, it is sticky and does not get changed
7304 -- to Unknown (the value in Result only gets worse as we go along,
7307 Offs
: Uint
:= No_Uint
;
7308 -- Set to a factor of the offset from the base object when Expr is a
7309 -- selected or indexed component, based on Component_Bit_Offset and
7310 -- Component_Size respectively. A negative value is used to represent
7311 -- a value which is not known at compile time.
7313 procedure Check_Prefix
;
7314 -- Checks the prefix recursively in the case where the expression
7315 -- is an indexed or selected component.
7317 procedure Set_Result
(R
: Alignment_Result
);
7318 -- If R represents a worse outcome (unknown instead of known
7319 -- compatible, or known incompatible), then set Result to R.
7325 procedure Check_Prefix
is
7327 -- The subtlety here is that in doing a recursive call to check
7328 -- the prefix, we have to decide what to do in the case where we
7329 -- don't find any specific indication of an alignment problem.
7331 -- At the outer level, we normally set Unknown as the result in
7332 -- this case, since we can only set Known_Compatible if we really
7333 -- know that the alignment value is OK, but for the recursive
7334 -- call, in the case where the types match, and we have not
7335 -- specified a peculiar alignment for the object, we are only
7336 -- concerned about suspicious rep clauses, the default case does
7337 -- not affect us, since the compiler will, in the absence of such
7338 -- rep clauses, ensure that the alignment is correct.
7340 if Default
= Known_Compatible
7342 (Etype
(Obj
) = Etype
(Expr
)
7343 and then (Unknown_Alignment
(Obj
)
7345 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
7348 (Has_Compatible_Alignment_Internal
7349 (Obj
, Prefix
(Expr
), Known_Compatible
));
7351 -- In all other cases, we need a full check on the prefix
7355 (Has_Compatible_Alignment_Internal
7356 (Obj
, Prefix
(Expr
), Unknown
));
7364 procedure Set_Result
(R
: Alignment_Result
) is
7371 -- Start of processing for Has_Compatible_Alignment_Internal
7374 -- If Expr is a selected component, we must make sure there is no
7375 -- potentially troublesome component clause, and that the record is
7378 if Nkind
(Expr
) = N_Selected_Component
then
7380 -- Packed record always generate unknown alignment
7382 if Is_Packed
(Etype
(Prefix
(Expr
))) then
7383 Set_Result
(Unknown
);
7386 -- Check prefix and component offset
7389 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
7391 -- If Expr is an indexed component, we must make sure there is no
7392 -- potentially troublesome Component_Size clause and that the array
7393 -- is not bit-packed.
7395 elsif Nkind
(Expr
) = N_Indexed_Component
then
7397 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
7398 Ind
: constant Node_Id
:= First_Index
(Typ
);
7401 -- Bit packed array always generates unknown alignment
7403 if Is_Bit_Packed_Array
(Typ
) then
7404 Set_Result
(Unknown
);
7407 -- Check prefix and component offset
7410 Offs
:= Component_Size
(Typ
);
7412 -- Small optimization: compute the full offset when possible
7415 and then Offs
> Uint_0
7416 and then Present
(Ind
)
7417 and then Nkind
(Ind
) = N_Range
7418 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
7419 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
7421 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
7422 - Expr_Value
(Low_Bound
((Ind
))));
7427 -- If we have a null offset, the result is entirely determined by
7428 -- the base object and has already been computed recursively.
7430 if Offs
= Uint_0
then
7433 -- Case where we know the alignment of the object
7435 elsif Known_Alignment
(Obj
) then
7437 ObjA
: constant Uint
:= Alignment
(Obj
);
7438 ExpA
: Uint
:= No_Uint
;
7439 SizA
: Uint
:= No_Uint
;
7442 -- If alignment of Obj is 1, then we are always OK
7445 Set_Result
(Known_Compatible
);
7447 -- Alignment of Obj is greater than 1, so we need to check
7450 -- If we have an offset, see if it is compatible
7452 if Offs
/= No_Uint
and Offs
> Uint_0
then
7453 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
7454 Set_Result
(Known_Incompatible
);
7457 -- See if Expr is an object with known alignment
7459 elsif Is_Entity_Name
(Expr
)
7460 and then Known_Alignment
(Entity
(Expr
))
7462 ExpA
:= Alignment
(Entity
(Expr
));
7464 -- Otherwise, we can use the alignment of the type of
7465 -- Expr given that we already checked for
7466 -- discombobulating rep clauses for the cases of indexed
7467 -- and selected components above.
7469 elsif Known_Alignment
(Etype
(Expr
)) then
7470 ExpA
:= Alignment
(Etype
(Expr
));
7472 -- Otherwise the alignment is unknown
7475 Set_Result
(Default
);
7478 -- If we got an alignment, see if it is acceptable
7480 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
7481 Set_Result
(Known_Incompatible
);
7484 -- If Expr is not a piece of a larger object, see if size
7485 -- is given. If so, check that it is not too small for the
7486 -- required alignment.
7488 if Offs
/= No_Uint
then
7491 -- See if Expr is an object with known size
7493 elsif Is_Entity_Name
(Expr
)
7494 and then Known_Static_Esize
(Entity
(Expr
))
7496 SizA
:= Esize
(Entity
(Expr
));
7498 -- Otherwise, we check the object size of the Expr type
7500 elsif Known_Static_Esize
(Etype
(Expr
)) then
7501 SizA
:= Esize
(Etype
(Expr
));
7504 -- If we got a size, see if it is a multiple of the Obj
7505 -- alignment, if not, then the alignment cannot be
7506 -- acceptable, since the size is always a multiple of the
7509 if SizA
/= No_Uint
then
7510 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
7511 Set_Result
(Known_Incompatible
);
7517 -- If we do not know required alignment, any non-zero offset is a
7518 -- potential problem (but certainly may be OK, so result is unknown).
7520 elsif Offs
/= No_Uint
then
7521 Set_Result
(Unknown
);
7523 -- If we can't find the result by direct comparison of alignment
7524 -- values, then there is still one case that we can determine known
7525 -- result, and that is when we can determine that the types are the
7526 -- same, and no alignments are specified. Then we known that the
7527 -- alignments are compatible, even if we don't know the alignment
7528 -- value in the front end.
7530 elsif Etype
(Obj
) = Etype
(Expr
) then
7532 -- Types are the same, but we have to check for possible size
7533 -- and alignments on the Expr object that may make the alignment
7534 -- different, even though the types are the same.
7536 if Is_Entity_Name
(Expr
) then
7538 -- First check alignment of the Expr object. Any alignment less
7539 -- than Maximum_Alignment is worrisome since this is the case
7540 -- where we do not know the alignment of Obj.
7542 if Known_Alignment
(Entity
(Expr
))
7543 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
7544 Ttypes
.Maximum_Alignment
7546 Set_Result
(Unknown
);
7548 -- Now check size of Expr object. Any size that is not an
7549 -- even multiple of Maximum_Alignment is also worrisome
7550 -- since it may cause the alignment of the object to be less
7551 -- than the alignment of the type.
7553 elsif Known_Static_Esize
(Entity
(Expr
))
7555 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
7556 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
7559 Set_Result
(Unknown
);
7561 -- Otherwise same type is decisive
7564 Set_Result
(Known_Compatible
);
7568 -- Another case to deal with is when there is an explicit size or
7569 -- alignment clause when the types are not the same. If so, then the
7570 -- result is Unknown. We don't need to do this test if the Default is
7571 -- Unknown, since that result will be set in any case.
7573 elsif Default
/= Unknown
7574 and then (Has_Size_Clause
(Etype
(Expr
))
7576 Has_Alignment_Clause
(Etype
(Expr
)))
7578 Set_Result
(Unknown
);
7580 -- If no indication found, set default
7583 Set_Result
(Default
);
7586 -- Return worst result found
7589 end Has_Compatible_Alignment_Internal
;
7591 -- Start of processing for Has_Compatible_Alignment
7594 -- If Obj has no specified alignment, then set alignment from the type
7595 -- alignment. Perhaps we should always do this, but for sure we should
7596 -- do it when there is an address clause since we can do more if the
7597 -- alignment is known.
7599 if Unknown_Alignment
(Obj
) then
7600 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
7603 -- Now do the internal call that does all the work
7605 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
7606 end Has_Compatible_Alignment
;
7608 ----------------------
7609 -- Has_Declarations --
7610 ----------------------
7612 function Has_Declarations
(N
: Node_Id
) return Boolean is
7614 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
7616 N_Compilation_Unit_Aux
,
7622 N_Package_Specification
);
7623 end Has_Declarations
;
7625 ---------------------------------
7626 -- Has_Defaulted_Discriminants --
7627 ---------------------------------
7629 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
7631 return Has_Discriminants
(Typ
)
7632 and then Present
(First_Discriminant
(Typ
))
7633 and then Present
(Discriminant_Default_Value
7634 (First_Discriminant
(Typ
)));
7635 end Has_Defaulted_Discriminants
;
7641 function Has_Denormals
(E
: Entity_Id
) return Boolean is
7643 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
7646 -------------------------------------------
7647 -- Has_Discriminant_Dependent_Constraint --
7648 -------------------------------------------
7650 function Has_Discriminant_Dependent_Constraint
7651 (Comp
: Entity_Id
) return Boolean
7653 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7654 Subt_Indic
: Node_Id
;
7659 -- Discriminants can't depend on discriminants
7661 if Ekind
(Comp
) = E_Discriminant
then
7665 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
7667 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
7668 Constr
:= Constraint
(Subt_Indic
);
7670 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
7671 Assn
:= First
(Constraints
(Constr
));
7672 while Present
(Assn
) loop
7673 case Nkind
(Assn
) is
7674 when N_Subtype_Indication |
7678 if Depends_On_Discriminant
(Assn
) then
7682 when N_Discriminant_Association
=>
7683 if Depends_On_Discriminant
(Expression
(Assn
)) then
7698 end Has_Discriminant_Dependent_Constraint
;
7700 --------------------------
7701 -- Has_Enabled_Property --
7702 --------------------------
7704 function Has_Enabled_Property
7705 (Item_Id
: Entity_Id
;
7706 Property
: Name_Id
) return Boolean
7708 function State_Has_Enabled_Property
return Boolean;
7709 -- Determine whether a state denoted by Item_Id has the property enabled
7711 function Variable_Has_Enabled_Property
return Boolean;
7712 -- Determine whether a variable denoted by Item_Id has the property
7715 --------------------------------
7716 -- State_Has_Enabled_Property --
7717 --------------------------------
7719 function State_Has_Enabled_Property
return Boolean is
7720 Decl
: constant Node_Id
:= Parent
(Item_Id
);
7728 -- The declaration of an external abstract state appears as an
7729 -- extension aggregate. If this is not the case, properties can never
7732 if Nkind
(Decl
) /= N_Extension_Aggregate
then
7736 -- When External appears as a simple option, it automatically enables
7739 Opt
:= First
(Expressions
(Decl
));
7740 while Present
(Opt
) loop
7741 if Nkind
(Opt
) = N_Identifier
7742 and then Chars
(Opt
) = Name_External
7750 -- When External specifies particular properties, inspect those and
7751 -- find the desired one (if any).
7753 Opt
:= First
(Component_Associations
(Decl
));
7754 while Present
(Opt
) loop
7755 Opt_Nam
:= First
(Choices
(Opt
));
7757 if Nkind
(Opt_Nam
) = N_Identifier
7758 and then Chars
(Opt_Nam
) = Name_External
7760 Props
:= Expression
(Opt
);
7762 -- Multiple properties appear as an aggregate
7764 if Nkind
(Props
) = N_Aggregate
then
7766 -- Simple property form
7768 Prop
:= First
(Expressions
(Props
));
7769 while Present
(Prop
) loop
7770 if Chars
(Prop
) = Property
then
7777 -- Property with expression form
7779 Prop
:= First
(Component_Associations
(Props
));
7780 while Present
(Prop
) loop
7781 Prop_Nam
:= First
(Choices
(Prop
));
7783 -- The property can be represented in two ways:
7784 -- others => <value>
7785 -- <property> => <value>
7787 if Nkind
(Prop_Nam
) = N_Others_Choice
7788 or else (Nkind
(Prop_Nam
) = N_Identifier
7789 and then Chars
(Prop_Nam
) = Property
)
7791 return Is_True
(Expr_Value
(Expression
(Prop
)));
7800 return Chars
(Props
) = Property
;
7808 end State_Has_Enabled_Property
;
7810 -----------------------------------
7811 -- Variable_Has_Enabled_Property --
7812 -----------------------------------
7814 function Variable_Has_Enabled_Property
return Boolean is
7815 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
7816 -- Determine whether property pragma Prag (if present) denotes an
7817 -- enabled property.
7823 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
7827 if Present
(Prag
) then
7828 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
7830 -- The pragma has an optional Boolean expression, the related
7831 -- property is enabled only when the expression evaluates to
7834 if Present
(Arg2
) then
7835 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg2
)));
7837 -- Otherwise the lack of expression enables the property by
7844 -- The property was never set in the first place
7853 AR
: constant Node_Id
:=
7854 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
7855 AW
: constant Node_Id
:=
7856 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
7857 ER
: constant Node_Id
:=
7858 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
7859 EW
: constant Node_Id
:=
7860 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
7862 -- Start of processing for Variable_Has_Enabled_Property
7865 -- A non-effectively volatile object can never possess external
7868 if not Is_Effectively_Volatile
(Item_Id
) then
7871 -- External properties related to variables come in two flavors -
7872 -- explicit and implicit. The explicit case is characterized by the
7873 -- presence of a property pragma with an optional Boolean flag. The
7874 -- property is enabled when the flag evaluates to True or the flag is
7875 -- missing altogether.
7877 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
7880 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
7883 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
7886 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
7889 -- The implicit case lacks all property pragmas
7891 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
7897 end Variable_Has_Enabled_Property
;
7899 -- Start of processing for Has_Enabled_Property
7902 -- Abstract states and variables have a flexible scheme of specifying
7903 -- external properties.
7905 if Ekind
(Item_Id
) = E_Abstract_State
then
7906 return State_Has_Enabled_Property
;
7908 elsif Ekind
(Item_Id
) = E_Variable
then
7909 return Variable_Has_Enabled_Property
;
7911 -- Otherwise a property is enabled when the related item is effectively
7915 return Is_Effectively_Volatile
(Item_Id
);
7917 end Has_Enabled_Property
;
7919 --------------------
7920 -- Has_Infinities --
7921 --------------------
7923 function Has_Infinities
(E
: Entity_Id
) return Boolean is
7926 Is_Floating_Point_Type
(E
)
7927 and then Nkind
(Scalar_Range
(E
)) = N_Range
7928 and then Includes_Infinities
(Scalar_Range
(E
));
7931 --------------------
7932 -- Has_Interfaces --
7933 --------------------
7935 function Has_Interfaces
7937 Use_Full_View
: Boolean := True) return Boolean
7939 Typ
: Entity_Id
:= Base_Type
(T
);
7942 -- Handle concurrent types
7944 if Is_Concurrent_Type
(Typ
) then
7945 Typ
:= Corresponding_Record_Type
(Typ
);
7948 if not Present
(Typ
)
7949 or else not Is_Record_Type
(Typ
)
7950 or else not Is_Tagged_Type
(Typ
)
7955 -- Handle private types
7957 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
7958 Typ
:= Full_View
(Typ
);
7961 -- Handle concurrent record types
7963 if Is_Concurrent_Record_Type
(Typ
)
7964 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
7970 if Is_Interface
(Typ
)
7972 (Is_Record_Type
(Typ
)
7973 and then Present
(Interfaces
(Typ
))
7974 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
7979 exit when Etype
(Typ
) = Typ
7981 -- Handle private types
7983 or else (Present
(Full_View
(Etype
(Typ
)))
7984 and then Full_View
(Etype
(Typ
)) = Typ
)
7986 -- Protect frontend against wrong sources with cyclic derivations
7988 or else Etype
(Typ
) = T
;
7990 -- Climb to the ancestor type handling private types
7992 if Present
(Full_View
(Etype
(Typ
))) then
7993 Typ
:= Full_View
(Etype
(Typ
));
8002 ---------------------------------
8003 -- Has_No_Obvious_Side_Effects --
8004 ---------------------------------
8006 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
8008 -- For now, just handle literals, constants, and non-volatile
8009 -- variables and expressions combining these with operators or
8010 -- short circuit forms.
8012 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
8015 elsif Nkind
(N
) = N_Character_Literal
then
8018 elsif Nkind
(N
) in N_Unary_Op
then
8019 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8021 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
8022 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
8024 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8026 elsif Nkind
(N
) = N_Expression_With_Actions
8027 and then Is_Empty_List
(Actions
(N
))
8029 return Has_No_Obvious_Side_Effects
(Expression
(N
));
8031 elsif Nkind
(N
) in N_Has_Entity
then
8032 return Present
(Entity
(N
))
8033 and then Ekind_In
(Entity
(N
), E_Variable
,
8035 E_Enumeration_Literal
,
8039 and then not Is_Volatile
(Entity
(N
));
8044 end Has_No_Obvious_Side_Effects
;
8046 ------------------------
8047 -- Has_Null_Exclusion --
8048 ------------------------
8050 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
8053 when N_Access_Definition |
8054 N_Access_Function_Definition |
8055 N_Access_Procedure_Definition |
8056 N_Access_To_Object_Definition |
8058 N_Derived_Type_Definition |
8059 N_Function_Specification |
8060 N_Subtype_Declaration
=>
8061 return Null_Exclusion_Present
(N
);
8063 when N_Component_Definition |
8064 N_Formal_Object_Declaration |
8065 N_Object_Renaming_Declaration
=>
8066 if Present
(Subtype_Mark
(N
)) then
8067 return Null_Exclusion_Present
(N
);
8068 else pragma Assert
(Present
(Access_Definition
(N
)));
8069 return Null_Exclusion_Present
(Access_Definition
(N
));
8072 when N_Discriminant_Specification
=>
8073 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
8074 return Null_Exclusion_Present
(Discriminant_Type
(N
));
8076 return Null_Exclusion_Present
(N
);
8079 when N_Object_Declaration
=>
8080 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
8081 return Null_Exclusion_Present
(Object_Definition
(N
));
8083 return Null_Exclusion_Present
(N
);
8086 when N_Parameter_Specification
=>
8087 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
8088 return Null_Exclusion_Present
(Parameter_Type
(N
));
8090 return Null_Exclusion_Present
(N
);
8097 end Has_Null_Exclusion
;
8099 ------------------------
8100 -- Has_Null_Extension --
8101 ------------------------
8103 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
8104 B
: constant Entity_Id
:= Base_Type
(T
);
8109 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
8110 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
8112 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
8114 if Present
(Ext
) then
8115 if Null_Present
(Ext
) then
8118 Comps
:= Component_List
(Ext
);
8120 -- The null component list is rewritten during analysis to
8121 -- include the parent component. Any other component indicates
8122 -- that the extension was not originally null.
8124 return Null_Present
(Comps
)
8125 or else No
(Next
(First
(Component_Items
(Comps
))));
8134 end Has_Null_Extension
;
8136 -------------------------------
8137 -- Has_Overriding_Initialize --
8138 -------------------------------
8140 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
8141 BT
: constant Entity_Id
:= Base_Type
(T
);
8145 if Is_Controlled
(BT
) then
8146 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
8149 elsif Present
(Primitive_Operations
(BT
)) then
8150 P
:= First_Elmt
(Primitive_Operations
(BT
));
8151 while Present
(P
) loop
8153 Init
: constant Entity_Id
:= Node
(P
);
8154 Formal
: constant Entity_Id
:= First_Formal
(Init
);
8156 if Ekind
(Init
) = E_Procedure
8157 and then Chars
(Init
) = Name_Initialize
8158 and then Comes_From_Source
(Init
)
8159 and then Present
(Formal
)
8160 and then Etype
(Formal
) = BT
8161 and then No
(Next_Formal
(Formal
))
8162 and then (Ada_Version
< Ada_2012
8163 or else not Null_Present
(Parent
(Init
)))
8173 -- Here if type itself does not have a non-null Initialize operation:
8174 -- check immediate ancestor.
8176 if Is_Derived_Type
(BT
)
8177 and then Has_Overriding_Initialize
(Etype
(BT
))
8184 end Has_Overriding_Initialize
;
8186 --------------------------------------
8187 -- Has_Preelaborable_Initialization --
8188 --------------------------------------
8190 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
8193 procedure Check_Components
(E
: Entity_Id
);
8194 -- Check component/discriminant chain, sets Has_PE False if a component
8195 -- or discriminant does not meet the preelaborable initialization rules.
8197 ----------------------
8198 -- Check_Components --
8199 ----------------------
8201 procedure Check_Components
(E
: Entity_Id
) is
8205 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
8206 -- Returns True if and only if the expression denoted by N does not
8207 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8209 ---------------------------------
8210 -- Is_Preelaborable_Expression --
8211 ---------------------------------
8213 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
8217 Comp_Type
: Entity_Id
;
8218 Is_Array_Aggr
: Boolean;
8221 if Is_OK_Static_Expression
(N
) then
8224 elsif Nkind
(N
) = N_Null
then
8227 -- Attributes are allowed in general, even if their prefix is a
8228 -- formal type. (It seems that certain attributes known not to be
8229 -- static might not be allowed, but there are no rules to prevent
8232 elsif Nkind
(N
) = N_Attribute_Reference
then
8235 -- The name of a discriminant evaluated within its parent type is
8236 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8237 -- names that denote discriminals as well as discriminants to
8238 -- catch references occurring within init procs.
8240 elsif Is_Entity_Name
(N
)
8242 (Ekind
(Entity
(N
)) = E_Discriminant
8244 ((Ekind
(Entity
(N
)) = E_Constant
8245 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
8246 and then Present
(Discriminal_Link
(Entity
(N
)))))
8250 elsif Nkind
(N
) = N_Qualified_Expression
then
8251 return Is_Preelaborable_Expression
(Expression
(N
));
8253 -- For aggregates we have to check that each of the associations
8254 -- is preelaborable.
8256 elsif Nkind
(N
) = N_Aggregate
8257 or else Nkind
(N
) = N_Extension_Aggregate
8259 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
8261 if Is_Array_Aggr
then
8262 Comp_Type
:= Component_Type
(Etype
(N
));
8265 -- Check the ancestor part of extension aggregates, which must
8266 -- be either the name of a type that has preelaborable init or
8267 -- an expression that is preelaborable.
8269 if Nkind
(N
) = N_Extension_Aggregate
then
8271 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
8274 if Is_Entity_Name
(Anc_Part
)
8275 and then Is_Type
(Entity
(Anc_Part
))
8277 if not Has_Preelaborable_Initialization
8283 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
8289 -- Check positional associations
8291 Exp
:= First
(Expressions
(N
));
8292 while Present
(Exp
) loop
8293 if not Is_Preelaborable_Expression
(Exp
) then
8300 -- Check named associations
8302 Assn
:= First
(Component_Associations
(N
));
8303 while Present
(Assn
) loop
8304 Choice
:= First
(Choices
(Assn
));
8305 while Present
(Choice
) loop
8306 if Is_Array_Aggr
then
8307 if Nkind
(Choice
) = N_Others_Choice
then
8310 elsif Nkind
(Choice
) = N_Range
then
8311 if not Is_OK_Static_Range
(Choice
) then
8315 elsif not Is_OK_Static_Expression
(Choice
) then
8320 Comp_Type
:= Etype
(Choice
);
8326 -- If the association has a <> at this point, then we have
8327 -- to check whether the component's type has preelaborable
8328 -- initialization. Note that this only occurs when the
8329 -- association's corresponding component does not have a
8330 -- default expression, the latter case having already been
8331 -- expanded as an expression for the association.
8333 if Box_Present
(Assn
) then
8334 if not Has_Preelaborable_Initialization
(Comp_Type
) then
8338 -- In the expression case we check whether the expression
8339 -- is preelaborable.
8342 not Is_Preelaborable_Expression
(Expression
(Assn
))
8350 -- If we get here then aggregate as a whole is preelaborable
8354 -- All other cases are not preelaborable
8359 end Is_Preelaborable_Expression
;
8361 -- Start of processing for Check_Components
8364 -- Loop through entities of record or protected type
8367 while Present
(Ent
) loop
8369 -- We are interested only in components and discriminants
8376 -- Get default expression if any. If there is no declaration
8377 -- node, it means we have an internal entity. The parent and
8378 -- tag fields are examples of such entities. For such cases,
8379 -- we just test the type of the entity.
8381 if Present
(Declaration_Node
(Ent
)) then
8382 Exp
:= Expression
(Declaration_Node
(Ent
));
8385 when E_Discriminant
=>
8387 -- Note: for a renamed discriminant, the Declaration_Node
8388 -- may point to the one from the ancestor, and have a
8389 -- different expression, so use the proper attribute to
8390 -- retrieve the expression from the derived constraint.
8392 Exp
:= Discriminant_Default_Value
(Ent
);
8395 goto Check_Next_Entity
;
8398 -- A component has PI if it has no default expression and the
8399 -- component type has PI.
8402 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
8407 -- Require the default expression to be preelaborable
8409 elsif not Is_Preelaborable_Expression
(Exp
) then
8414 <<Check_Next_Entity
>>
8417 end Check_Components
;
8419 -- Start of processing for Has_Preelaborable_Initialization
8422 -- Immediate return if already marked as known preelaborable init. This
8423 -- covers types for which this function has already been called once
8424 -- and returned True (in which case the result is cached), and also
8425 -- types to which a pragma Preelaborable_Initialization applies.
8427 if Known_To_Have_Preelab_Init
(E
) then
8431 -- If the type is a subtype representing a generic actual type, then
8432 -- test whether its base type has preelaborable initialization since
8433 -- the subtype representing the actual does not inherit this attribute
8434 -- from the actual or formal. (but maybe it should???)
8436 if Is_Generic_Actual_Type
(E
) then
8437 return Has_Preelaborable_Initialization
(Base_Type
(E
));
8440 -- All elementary types have preelaborable initialization
8442 if Is_Elementary_Type
(E
) then
8445 -- Array types have PI if the component type has PI
8447 elsif Is_Array_Type
(E
) then
8448 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
8450 -- A derived type has preelaborable initialization if its parent type
8451 -- has preelaborable initialization and (in the case of a derived record
8452 -- extension) if the non-inherited components all have preelaborable
8453 -- initialization. However, a user-defined controlled type with an
8454 -- overriding Initialize procedure does not have preelaborable
8457 elsif Is_Derived_Type
(E
) then
8459 -- If the derived type is a private extension then it doesn't have
8460 -- preelaborable initialization.
8462 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
8466 -- First check whether ancestor type has preelaborable initialization
8468 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
8470 -- If OK, check extension components (if any)
8472 if Has_PE
and then Is_Record_Type
(E
) then
8473 Check_Components
(First_Entity
(E
));
8476 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8477 -- with a user defined Initialize procedure does not have PI. If
8478 -- the type is untagged, the control primitives come from a component
8479 -- that has already been checked.
8482 and then Is_Controlled
(E
)
8483 and then Is_Tagged_Type
(E
)
8484 and then Has_Overriding_Initialize
(E
)
8489 -- Private types not derived from a type having preelaborable init and
8490 -- that are not marked with pragma Preelaborable_Initialization do not
8491 -- have preelaborable initialization.
8493 elsif Is_Private_Type
(E
) then
8496 -- Record type has PI if it is non private and all components have PI
8498 elsif Is_Record_Type
(E
) then
8500 Check_Components
(First_Entity
(E
));
8502 -- Protected types must not have entries, and components must meet
8503 -- same set of rules as for record components.
8505 elsif Is_Protected_Type
(E
) then
8506 if Has_Entries
(E
) then
8510 Check_Components
(First_Entity
(E
));
8511 Check_Components
(First_Private_Entity
(E
));
8514 -- Type System.Address always has preelaborable initialization
8516 elsif Is_RTE
(E
, RE_Address
) then
8519 -- In all other cases, type does not have preelaborable initialization
8525 -- If type has preelaborable initialization, cache result
8528 Set_Known_To_Have_Preelab_Init
(E
);
8532 end Has_Preelaborable_Initialization
;
8534 ---------------------------
8535 -- Has_Private_Component --
8536 ---------------------------
8538 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
8539 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
8540 Component
: Entity_Id
;
8543 if Error_Posted
(Type_Id
)
8544 or else Error_Posted
(Btype
)
8549 if Is_Class_Wide_Type
(Btype
) then
8550 Btype
:= Root_Type
(Btype
);
8553 if Is_Private_Type
(Btype
) then
8555 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
8558 if No
(Full_View
(Btype
)) then
8559 return not Is_Generic_Type
(Btype
)
8560 and then not Is_Generic_Type
(Root_Type
(Btype
));
8562 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
8565 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
8569 elsif Is_Array_Type
(Btype
) then
8570 return Has_Private_Component
(Component_Type
(Btype
));
8572 elsif Is_Record_Type
(Btype
) then
8573 Component
:= First_Component
(Btype
);
8574 while Present
(Component
) loop
8575 if Has_Private_Component
(Etype
(Component
)) then
8579 Next_Component
(Component
);
8584 elsif Is_Protected_Type
(Btype
)
8585 and then Present
(Corresponding_Record_Type
(Btype
))
8587 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
8592 end Has_Private_Component
;
8594 ----------------------
8595 -- Has_Signed_Zeros --
8596 ----------------------
8598 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
8600 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
8601 end Has_Signed_Zeros
;
8603 -----------------------------
8604 -- Has_Static_Array_Bounds --
8605 -----------------------------
8607 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
8608 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
8615 -- Unconstrained types do not have static bounds
8617 if not Is_Constrained
(Typ
) then
8621 -- First treat string literals specially, as the lower bound and length
8622 -- of string literals are not stored like those of arrays.
8624 -- A string literal always has static bounds
8626 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8630 -- Treat all dimensions in turn
8632 Index
:= First_Index
(Typ
);
8633 for Indx
in 1 .. Ndims
loop
8635 -- In case of an illegal index which is not a discrete type, return
8636 -- that the type is not static.
8638 if not Is_Discrete_Type
(Etype
(Index
))
8639 or else Etype
(Index
) = Any_Type
8644 Get_Index_Bounds
(Index
, Low
, High
);
8646 if Error_Posted
(Low
) or else Error_Posted
(High
) then
8650 if Is_OK_Static_Expression
(Low
)
8652 Is_OK_Static_Expression
(High
)
8662 -- If we fall through the loop, all indexes matched
8665 end Has_Static_Array_Bounds
;
8671 function Has_Stream
(T
: Entity_Id
) return Boolean is
8678 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
8681 elsif Is_Array_Type
(T
) then
8682 return Has_Stream
(Component_Type
(T
));
8684 elsif Is_Record_Type
(T
) then
8685 E
:= First_Component
(T
);
8686 while Present
(E
) loop
8687 if Has_Stream
(Etype
(E
)) then
8696 elsif Is_Private_Type
(T
) then
8697 return Has_Stream
(Underlying_Type
(T
));
8708 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
8710 Get_Name_String
(Chars
(E
));
8711 return Name_Buffer
(Name_Len
) = Suffix
;
8718 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8720 Get_Name_String
(Chars
(E
));
8721 Add_Char_To_Name_Buffer
(Suffix
);
8729 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8731 pragma Assert
(Has_Suffix
(E
, Suffix
));
8732 Get_Name_String
(Chars
(E
));
8733 Name_Len
:= Name_Len
- 1;
8737 --------------------------
8738 -- Has_Tagged_Component --
8739 --------------------------
8741 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
8745 if Is_Private_Type
(Typ
)
8746 and then Present
(Underlying_Type
(Typ
))
8748 return Has_Tagged_Component
(Underlying_Type
(Typ
));
8750 elsif Is_Array_Type
(Typ
) then
8751 return Has_Tagged_Component
(Component_Type
(Typ
));
8753 elsif Is_Tagged_Type
(Typ
) then
8756 elsif Is_Record_Type
(Typ
) then
8757 Comp
:= First_Component
(Typ
);
8758 while Present
(Comp
) loop
8759 if Has_Tagged_Component
(Etype
(Comp
)) then
8763 Next_Component
(Comp
);
8771 end Has_Tagged_Component
;
8773 ----------------------------
8774 -- Has_Volatile_Component --
8775 ----------------------------
8777 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
8781 if Has_Volatile_Components
(Typ
) then
8784 elsif Is_Array_Type
(Typ
) then
8785 return Is_Volatile
(Component_Type
(Typ
));
8787 elsif Is_Record_Type
(Typ
) then
8788 Comp
:= First_Component
(Typ
);
8789 while Present
(Comp
) loop
8790 if Is_Volatile_Object
(Comp
) then
8794 Comp
:= Next_Component
(Comp
);
8799 end Has_Volatile_Component
;
8801 -------------------------
8802 -- Implementation_Kind --
8803 -------------------------
8805 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
8806 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
8809 pragma Assert
(Present
(Impl_Prag
));
8810 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
8811 return Chars
(Get_Pragma_Arg
(Arg
));
8812 end Implementation_Kind
;
8814 --------------------------
8815 -- Implements_Interface --
8816 --------------------------
8818 function Implements_Interface
8819 (Typ_Ent
: Entity_Id
;
8820 Iface_Ent
: Entity_Id
;
8821 Exclude_Parents
: Boolean := False) return Boolean
8823 Ifaces_List
: Elist_Id
;
8825 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
8826 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
8829 if Is_Class_Wide_Type
(Typ
) then
8830 Typ
:= Root_Type
(Typ
);
8833 if not Has_Interfaces
(Typ
) then
8837 if Is_Class_Wide_Type
(Iface
) then
8838 Iface
:= Root_Type
(Iface
);
8841 Collect_Interfaces
(Typ
, Ifaces_List
);
8843 Elmt
:= First_Elmt
(Ifaces_List
);
8844 while Present
(Elmt
) loop
8845 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
8846 and then Exclude_Parents
8850 elsif Node
(Elmt
) = Iface
then
8858 end Implements_Interface
;
8860 ------------------------------------
8861 -- In_Assertion_Expression_Pragma --
8862 ------------------------------------
8864 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
8866 Prag
: Node_Id
:= Empty
;
8869 -- Climb the parent chain looking for an enclosing pragma
8872 while Present
(Par
) loop
8873 if Nkind
(Par
) = N_Pragma
then
8877 -- Precondition-like pragmas are expanded into if statements, check
8878 -- the original node instead.
8880 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
8881 Prag
:= Original_Node
(Par
);
8884 -- The expansion of attribute 'Old generates a constant to capture
8885 -- the result of the prefix. If the parent traversal reaches
8886 -- one of these constants, then the node technically came from a
8887 -- postcondition-like pragma. Note that the Ekind is not tested here
8888 -- because N may be the expression of an object declaration which is
8889 -- currently being analyzed. Such objects carry Ekind of E_Void.
8891 elsif Nkind
(Par
) = N_Object_Declaration
8892 and then Constant_Present
(Par
)
8893 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
8897 -- Prevent the search from going too far
8899 elsif Is_Body_Or_Package_Declaration
(Par
) then
8903 Par
:= Parent
(Par
);
8908 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
8909 end In_Assertion_Expression_Pragma
;
8915 function In_Instance
return Boolean is
8916 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
8921 while Present
(S
) and then S
/= Standard_Standard
loop
8922 if (Ekind
(S
) = E_Function
8923 or else Ekind
(S
) = E_Package
8924 or else Ekind
(S
) = E_Procedure
)
8925 and then Is_Generic_Instance
(S
)
8927 -- A child instance is always compiled in the context of a parent
8928 -- instance. Nevertheless, the actuals are not analyzed in an
8929 -- instance context. We detect this case by examining the current
8930 -- compilation unit, which must be a child instance, and checking
8931 -- that it is not currently on the scope stack.
8933 if Is_Child_Unit
(Curr_Unit
)
8934 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
8935 N_Package_Instantiation
8936 and then not In_Open_Scopes
(Curr_Unit
)
8950 ----------------------
8951 -- In_Instance_Body --
8952 ----------------------
8954 function In_Instance_Body
return Boolean is
8959 while Present
(S
) and then S
/= Standard_Standard
loop
8960 if Ekind_In
(S
, E_Function
, E_Procedure
)
8961 and then Is_Generic_Instance
(S
)
8965 elsif Ekind
(S
) = E_Package
8966 and then In_Package_Body
(S
)
8967 and then Is_Generic_Instance
(S
)
8976 end In_Instance_Body
;
8978 -----------------------------
8979 -- In_Instance_Not_Visible --
8980 -----------------------------
8982 function In_Instance_Not_Visible
return Boolean is
8987 while Present
(S
) and then S
/= Standard_Standard
loop
8988 if Ekind_In
(S
, E_Function
, E_Procedure
)
8989 and then Is_Generic_Instance
(S
)
8993 elsif Ekind
(S
) = E_Package
8994 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
8995 and then Is_Generic_Instance
(S
)
9004 end In_Instance_Not_Visible
;
9006 ------------------------------
9007 -- In_Instance_Visible_Part --
9008 ------------------------------
9010 function In_Instance_Visible_Part
return Boolean is
9015 while Present
(S
) and then S
/= Standard_Standard
loop
9016 if Ekind
(S
) = E_Package
9017 and then Is_Generic_Instance
(S
)
9018 and then not In_Package_Body
(S
)
9019 and then not In_Private_Part
(S
)
9028 end In_Instance_Visible_Part
;
9030 ---------------------
9031 -- In_Package_Body --
9032 ---------------------
9034 function In_Package_Body
return Boolean is
9039 while Present
(S
) and then S
/= Standard_Standard
loop
9040 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
9048 end In_Package_Body
;
9050 --------------------------------
9051 -- In_Parameter_Specification --
9052 --------------------------------
9054 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
9059 while Present
(PN
) loop
9060 if Nkind
(PN
) = N_Parameter_Specification
then
9068 end In_Parameter_Specification
;
9070 --------------------------
9071 -- In_Pragma_Expression --
9072 --------------------------
9074 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
9081 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
9087 end In_Pragma_Expression
;
9089 -------------------------------------
9090 -- In_Reverse_Storage_Order_Object --
9091 -------------------------------------
9093 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
9095 Btyp
: Entity_Id
:= Empty
;
9098 -- Climb up indexed components
9102 case Nkind
(Pref
) is
9103 when N_Selected_Component
=>
9104 Pref
:= Prefix
(Pref
);
9107 when N_Indexed_Component
=>
9108 Pref
:= Prefix
(Pref
);
9116 if Present
(Pref
) then
9117 Btyp
:= Base_Type
(Etype
(Pref
));
9120 return Present
(Btyp
)
9121 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
9122 and then Reverse_Storage_Order
(Btyp
);
9123 end In_Reverse_Storage_Order_Object
;
9125 --------------------------------------
9126 -- In_Subprogram_Or_Concurrent_Unit --
9127 --------------------------------------
9129 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
9134 -- Use scope chain to check successively outer scopes
9140 if K
in Subprogram_Kind
9141 or else K
in Concurrent_Kind
9142 or else K
in Generic_Subprogram_Kind
9146 elsif E
= Standard_Standard
then
9152 end In_Subprogram_Or_Concurrent_Unit
;
9154 ---------------------
9155 -- In_Visible_Part --
9156 ---------------------
9158 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
9160 return Is_Package_Or_Generic_Package
(Scope_Id
)
9161 and then In_Open_Scopes
(Scope_Id
)
9162 and then not In_Package_Body
(Scope_Id
)
9163 and then not In_Private_Part
(Scope_Id
);
9164 end In_Visible_Part
;
9166 --------------------------------
9167 -- Incomplete_Or_Private_View --
9168 --------------------------------
9170 function Incomplete_Or_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
9171 function Inspect_Decls
9173 Taft
: Boolean := False) return Entity_Id
;
9174 -- Check whether a declarative region contains the incomplete or private
9181 function Inspect_Decls
9183 Taft
: Boolean := False) return Entity_Id
9189 Decl
:= First
(Decls
);
9190 while Present
(Decl
) loop
9194 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
9195 Match
:= Defining_Identifier
(Decl
);
9199 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
9200 N_Private_Type_Declaration
)
9202 Match
:= Defining_Identifier
(Decl
);
9207 and then Present
(Full_View
(Match
))
9208 and then Full_View
(Match
) = Typ
9223 -- Start of processing for Incomplete_Or_Partial_View
9226 -- Incomplete type case
9228 Prev
:= Current_Entity_In_Scope
(Typ
);
9231 and then Is_Incomplete_Type
(Prev
)
9232 and then Present
(Full_View
(Prev
))
9233 and then Full_View
(Prev
) = Typ
9238 -- Private or Taft amendment type case
9241 Pkg
: constant Entity_Id
:= Scope
(Typ
);
9242 Pkg_Decl
: Node_Id
:= Pkg
;
9245 if Ekind
(Pkg
) = E_Package
then
9246 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
9247 Pkg_Decl
:= Parent
(Pkg_Decl
);
9250 -- It is knows that Typ has a private view, look for it in the
9251 -- visible declarations of the enclosing scope. A special case
9252 -- of this is when the two views have been exchanged - the full
9253 -- appears earlier than the private.
9255 if Has_Private_Declaration
(Typ
) then
9256 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
9258 -- Exchanged view case, look in the private declarations
9261 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
9266 -- Otherwise if this is the package body, then Typ is a potential
9267 -- Taft amendment type. The incomplete view should be located in
9268 -- the private declarations of the enclosing scope.
9270 elsif In_Package_Body
(Pkg
) then
9271 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
9276 -- The type has no incomplete or private view
9279 end Incomplete_Or_Private_View
;
9281 -----------------------------------------
9282 -- Inherit_Default_Init_Cond_Procedure --
9283 -----------------------------------------
9285 procedure Inherit_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
9286 Par_Typ
: constant Entity_Id
:= Etype
(Typ
);
9289 -- A derived type inherits the default initial condition procedure of
9292 if No
(Default_Init_Cond_Procedure
(Typ
)) then
9293 Set_Default_Init_Cond_Procedure
9294 (Typ
, Default_Init_Cond_Procedure
(Par_Typ
));
9296 end Inherit_Default_Init_Cond_Procedure
;
9298 ---------------------------------
9299 -- Insert_Explicit_Dereference --
9300 ---------------------------------
9302 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
9303 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
9304 Ent
: Entity_Id
:= Empty
;
9311 Save_Interps
(N
, New_Prefix
);
9314 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
9315 Prefix
=> New_Prefix
));
9317 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
9319 if Is_Overloaded
(New_Prefix
) then
9321 -- The dereference is also overloaded, and its interpretations are
9322 -- the designated types of the interpretations of the original node.
9324 Set_Etype
(N
, Any_Type
);
9326 Get_First_Interp
(New_Prefix
, I
, It
);
9327 while Present
(It
.Nam
) loop
9330 if Is_Access_Type
(T
) then
9331 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
9334 Get_Next_Interp
(I
, It
);
9340 -- Prefix is unambiguous: mark the original prefix (which might
9341 -- Come_From_Source) as a reference, since the new (relocated) one
9342 -- won't be taken into account.
9344 if Is_Entity_Name
(New_Prefix
) then
9345 Ent
:= Entity
(New_Prefix
);
9348 -- For a retrieval of a subcomponent of some composite object,
9349 -- retrieve the ultimate entity if there is one.
9351 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
9352 N_Indexed_Component
)
9354 Pref
:= Prefix
(New_Prefix
);
9355 while Present
(Pref
)
9356 and then Nkind_In
(Pref
, N_Selected_Component
,
9357 N_Indexed_Component
)
9359 Pref
:= Prefix
(Pref
);
9362 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
9363 Ent
:= Entity
(Pref
);
9367 -- Place the reference on the entity node
9369 if Present
(Ent
) then
9370 Generate_Reference
(Ent
, Pref
);
9373 end Insert_Explicit_Dereference
;
9375 ------------------------------------------
9376 -- Inspect_Deferred_Constant_Completion --
9377 ------------------------------------------
9379 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
9383 Decl
:= First
(Decls
);
9384 while Present
(Decl
) loop
9386 -- Deferred constant signature
9388 if Nkind
(Decl
) = N_Object_Declaration
9389 and then Constant_Present
(Decl
)
9390 and then No
(Expression
(Decl
))
9392 -- No need to check internally generated constants
9394 and then Comes_From_Source
(Decl
)
9396 -- The constant is not completed. A full object declaration or a
9397 -- pragma Import complete a deferred constant.
9399 and then not Has_Completion
(Defining_Identifier
(Decl
))
9402 ("constant declaration requires initialization expression",
9403 Defining_Identifier
(Decl
));
9406 Decl
:= Next
(Decl
);
9408 end Inspect_Deferred_Constant_Completion
;
9410 -----------------------------
9411 -- Is_Actual_Out_Parameter --
9412 -----------------------------
9414 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
9418 Find_Actual
(N
, Formal
, Call
);
9419 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
9420 end Is_Actual_Out_Parameter
;
9422 -------------------------
9423 -- Is_Actual_Parameter --
9424 -------------------------
9426 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
9427 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
9431 when N_Parameter_Association
=>
9432 return N
= Explicit_Actual_Parameter
(Parent
(N
));
9434 when N_Subprogram_Call
=>
9435 return Is_List_Member
(N
)
9437 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
9442 end Is_Actual_Parameter
;
9444 --------------------------------
9445 -- Is_Actual_Tagged_Parameter --
9446 --------------------------------
9448 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
9452 Find_Actual
(N
, Formal
, Call
);
9453 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
9454 end Is_Actual_Tagged_Parameter
;
9456 ---------------------
9457 -- Is_Aliased_View --
9458 ---------------------
9460 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
9464 if Is_Entity_Name
(Obj
) then
9471 or else (Present
(Renamed_Object
(E
))
9472 and then Is_Aliased_View
(Renamed_Object
(E
)))))
9474 or else ((Is_Formal
(E
)
9475 or else Ekind
(E
) = E_Generic_In_Out_Parameter
9476 or else Ekind
(E
) = E_Generic_In_Parameter
)
9477 and then Is_Tagged_Type
(Etype
(E
)))
9479 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
9481 -- Current instance of type, either directly or as rewritten
9482 -- reference to the current object.
9484 or else (Is_Entity_Name
(Original_Node
(Obj
))
9485 and then Present
(Entity
(Original_Node
(Obj
)))
9486 and then Is_Type
(Entity
(Original_Node
(Obj
))))
9488 or else (Is_Type
(E
) and then E
= Current_Scope
)
9490 or else (Is_Incomplete_Or_Private_Type
(E
)
9491 and then Full_View
(E
) = Current_Scope
)
9493 -- Ada 2012 AI05-0053: the return object of an extended return
9494 -- statement is aliased if its type is immutably limited.
9496 or else (Is_Return_Object
(E
)
9497 and then Is_Limited_View
(Etype
(E
)));
9499 elsif Nkind
(Obj
) = N_Selected_Component
then
9500 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
9502 elsif Nkind
(Obj
) = N_Indexed_Component
then
9503 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
9505 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
9506 and then Has_Aliased_Components
9507 (Designated_Type
(Etype
(Prefix
(Obj
)))));
9509 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
9510 return Is_Tagged_Type
(Etype
(Obj
))
9511 and then Is_Aliased_View
(Expression
(Obj
));
9513 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
9514 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
9519 end Is_Aliased_View
;
9521 -------------------------
9522 -- Is_Ancestor_Package --
9523 -------------------------
9525 function Is_Ancestor_Package
9527 E2
: Entity_Id
) return Boolean
9533 while Present
(Par
) and then Par
/= Standard_Standard
loop
9542 end Is_Ancestor_Package
;
9544 ----------------------
9545 -- Is_Atomic_Object --
9546 ----------------------
9548 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
9550 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
9551 -- Determines if given object has atomic components
9553 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
9554 -- If prefix is an implicit dereference, examine designated type
9556 ----------------------
9557 -- Is_Atomic_Prefix --
9558 ----------------------
9560 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
9562 if Is_Access_Type
(Etype
(N
)) then
9564 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
9566 return Object_Has_Atomic_Components
(N
);
9568 end Is_Atomic_Prefix
;
9570 ----------------------------------
9571 -- Object_Has_Atomic_Components --
9572 ----------------------------------
9574 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
9576 if Has_Atomic_Components
(Etype
(N
))
9577 or else Is_Atomic
(Etype
(N
))
9581 elsif Is_Entity_Name
(N
)
9582 and then (Has_Atomic_Components
(Entity
(N
))
9583 or else Is_Atomic
(Entity
(N
)))
9587 elsif Nkind
(N
) = N_Selected_Component
9588 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9592 elsif Nkind
(N
) = N_Indexed_Component
9593 or else Nkind
(N
) = N_Selected_Component
9595 return Is_Atomic_Prefix
(Prefix
(N
));
9600 end Object_Has_Atomic_Components
;
9602 -- Start of processing for Is_Atomic_Object
9605 -- Predicate is not relevant to subprograms
9607 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
9610 elsif Is_Atomic
(Etype
(N
))
9611 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
9615 elsif Nkind
(N
) = N_Selected_Component
9616 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9620 elsif Nkind
(N
) = N_Indexed_Component
9621 or else Nkind
(N
) = N_Selected_Component
9623 return Is_Atomic_Prefix
(Prefix
(N
));
9628 end Is_Atomic_Object
;
9630 -------------------------
9631 -- Is_Attribute_Result --
9632 -------------------------
9634 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
9636 return Nkind
(N
) = N_Attribute_Reference
9637 and then Attribute_Name
(N
) = Name_Result
;
9638 end Is_Attribute_Result
;
9640 ------------------------------------
9641 -- Is_Body_Or_Package_Declaration --
9642 ------------------------------------
9644 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
9646 return Nkind_In
(N
, N_Entry_Body
,
9648 N_Package_Declaration
,
9652 end Is_Body_Or_Package_Declaration
;
9654 -----------------------
9655 -- Is_Bounded_String --
9656 -----------------------
9658 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
9659 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
9662 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9663 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9664 -- be True for all the Bounded_String types in instances of the
9665 -- Generic_Bounded_Length generics, and for types derived from those.
9667 return Present
(Under
)
9668 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
9669 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
9670 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
9671 end Is_Bounded_String
;
9673 -------------------------
9674 -- Is_Child_Or_Sibling --
9675 -------------------------
9677 function Is_Child_Or_Sibling
9678 (Pack_1
: Entity_Id
;
9679 Pack_2
: Entity_Id
) return Boolean
9681 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
9682 -- Given an arbitrary package, return the number of "climbs" necessary
9683 -- to reach scope Standard_Standard.
9685 procedure Equalize_Depths
9686 (Pack
: in out Entity_Id
;
9688 Depth_To_Reach
: Nat
);
9689 -- Given an arbitrary package, its depth and a target depth to reach,
9690 -- climb the scope chain until the said depth is reached. The pointer
9691 -- to the package and its depth a modified during the climb.
9693 ----------------------------
9694 -- Distance_From_Standard --
9695 ----------------------------
9697 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
9704 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
9706 Scop
:= Scope
(Scop
);
9710 end Distance_From_Standard
;
9712 ---------------------
9713 -- Equalize_Depths --
9714 ---------------------
9716 procedure Equalize_Depths
9717 (Pack
: in out Entity_Id
;
9719 Depth_To_Reach
: Nat
)
9722 -- The package must be at a greater or equal depth
9724 if Depth
< Depth_To_Reach
then
9725 raise Program_Error
;
9728 -- Climb the scope chain until the desired depth is reached
9730 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
9731 Pack
:= Scope
(Pack
);
9734 end Equalize_Depths
;
9738 P_1
: Entity_Id
:= Pack_1
;
9739 P_1_Child
: Boolean := False;
9740 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
9741 P_2
: Entity_Id
:= Pack_2
;
9742 P_2_Child
: Boolean := False;
9743 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
9745 -- Start of processing for Is_Child_Or_Sibling
9749 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
9751 -- Both packages denote the same entity, therefore they cannot be
9752 -- children or siblings.
9757 -- One of the packages is at a deeper level than the other. Note that
9758 -- both may still come from differen hierarchies.
9766 elsif P_1_Depth
> P_2_Depth
then
9770 Depth_To_Reach
=> P_2_Depth
);
9779 elsif P_2_Depth
> P_1_Depth
then
9783 Depth_To_Reach
=> P_1_Depth
);
9787 -- At this stage the package pointers have been elevated to the same
9788 -- depth. If the related entities are the same, then one package is a
9789 -- potential child of the other:
9793 -- X became P_1 P_2 or vica versa
9799 return Is_Child_Unit
(Pack_1
);
9801 else pragma Assert
(P_2_Child
);
9802 return Is_Child_Unit
(Pack_2
);
9805 -- The packages may come from the same package chain or from entirely
9806 -- different hierarcies. To determine this, climb the scope stack until
9807 -- a common root is found.
9809 -- (root) (root 1) (root 2)
9814 while Present
(P_1
) and then Present
(P_2
) loop
9816 -- The two packages may be siblings
9819 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
9828 end Is_Child_Or_Sibling
;
9830 -----------------------------
9831 -- Is_Concurrent_Interface --
9832 -----------------------------
9834 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
9836 return Is_Interface
(T
)
9838 (Is_Protected_Interface
(T
)
9839 or else Is_Synchronized_Interface
(T
)
9840 or else Is_Task_Interface
(T
));
9841 end Is_Concurrent_Interface
;
9843 ---------------------------
9844 -- Is_Container_Element --
9845 ---------------------------
9847 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
9848 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
9849 Pref
: constant Node_Id
:= Prefix
(Exp
);
9852 -- Call to an indexing aspect
9854 Cont_Typ
: Entity_Id
;
9855 -- The type of the container being accessed
9857 Elem_Typ
: Entity_Id
;
9860 Indexing
: Entity_Id
;
9862 -- Indicates that constant indexing is used, and the element is thus
9865 Ref_Typ
: Entity_Id
;
9866 -- The reference type returned by the indexing operation
9869 -- If C is a container, in a context that imposes the element type of
9870 -- that container, the indexing notation C (X) is rewritten as:
9872 -- Indexing (C, X).Discr.all
9874 -- where Indexing is one of the indexing aspects of the container.
9875 -- If the context does not require a reference, the construct can be
9880 -- First, verify that the construct has the proper form
9882 if not Expander_Active
then
9885 elsif Nkind
(Pref
) /= N_Selected_Component
then
9888 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
9892 Call
:= Prefix
(Pref
);
9893 Ref_Typ
:= Etype
(Call
);
9896 if not Has_Implicit_Dereference
(Ref_Typ
)
9897 or else No
(First
(Parameter_Associations
(Call
)))
9898 or else not Is_Entity_Name
(Name
(Call
))
9903 -- Retrieve type of container object, and its iterator aspects
9905 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
9906 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
9909 if No
(Indexing
) then
9911 -- Container should have at least one indexing operation
9915 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
9917 -- This may be a variable indexing operation
9919 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
9922 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
9931 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
9933 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
9937 -- Check that the expression is not the target of an assignment, in
9938 -- which case the rewriting is not possible.
9940 if not Is_Const
then
9948 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
9949 and then Par
= Name
(Parent
(Par
))
9953 -- A renaming produces a reference, and the transformation
9956 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
9960 (Nkind
(Parent
(Par
)), N_Function_Call
,
9961 N_Procedure_Call_Statement
,
9962 N_Entry_Call_Statement
)
9964 -- Check that the element is not part of an actual for an
9965 -- in-out parameter.
9972 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
9973 A
:= First
(Parameter_Associations
(Parent
(Par
)));
9974 while Present
(F
) loop
9975 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
9984 -- E_In_Parameter in a call: element is not modified.
9989 Par
:= Parent
(Par
);
9994 -- The expression has the proper form and the context requires the
9995 -- element type. Retrieve the Element function of the container and
9996 -- rewrite the construct as a call to it.
10002 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
10003 while Present
(Op
) loop
10004 exit when Chars
(Node
(Op
)) = Name_Element
;
10013 Make_Function_Call
(Loc
,
10014 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
10015 Parameter_Associations
=> Parameter_Associations
(Call
)));
10016 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
10020 end Is_Container_Element
;
10022 -----------------------
10023 -- Is_Constant_Bound --
10024 -----------------------
10026 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
10028 if Compile_Time_Known_Value
(Exp
) then
10031 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
10032 return Is_Constant_Object
(Entity
(Exp
))
10033 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
10035 elsif Nkind
(Exp
) in N_Binary_Op
then
10036 return Is_Constant_Bound
(Left_Opnd
(Exp
))
10037 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
10038 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
10043 end Is_Constant_Bound
;
10045 --------------------------------------
10046 -- Is_Controlling_Limited_Procedure --
10047 --------------------------------------
10049 function Is_Controlling_Limited_Procedure
10050 (Proc_Nam
: Entity_Id
) return Boolean
10052 Param_Typ
: Entity_Id
:= Empty
;
10055 if Ekind
(Proc_Nam
) = E_Procedure
10056 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
10058 Param_Typ
:= Etype
(Parameter_Type
(First
(
10059 Parameter_Specifications
(Parent
(Proc_Nam
)))));
10061 -- In this case where an Itype was created, the procedure call has been
10064 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
10065 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
10067 Present
(Parameter_Associations
10068 (Associated_Node_For_Itype
(Proc_Nam
)))
10071 Etype
(First
(Parameter_Associations
10072 (Associated_Node_For_Itype
(Proc_Nam
))));
10075 if Present
(Param_Typ
) then
10077 Is_Interface
(Param_Typ
)
10078 and then Is_Limited_Record
(Param_Typ
);
10082 end Is_Controlling_Limited_Procedure
;
10084 -----------------------------
10085 -- Is_CPP_Constructor_Call --
10086 -----------------------------
10088 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
10090 return Nkind
(N
) = N_Function_Call
10091 and then Is_CPP_Class
(Etype
(Etype
(N
)))
10092 and then Is_Constructor
(Entity
(Name
(N
)))
10093 and then Is_Imported
(Entity
(Name
(N
)));
10094 end Is_CPP_Constructor_Call
;
10100 function Is_Delegate
(T
: Entity_Id
) return Boolean is
10101 Desig_Type
: Entity_Id
;
10104 if VM_Target
/= CLI_Target
then
10108 -- Access-to-subprograms are delegates in CIL
10110 if Ekind
(T
) = E_Access_Subprogram_Type
then
10114 if not Is_Access_Type
(T
) then
10116 -- A delegate is a managed pointer. If no designated type is defined
10117 -- it means that it's not a delegate.
10122 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
10124 if not Is_Tagged_Type
(Desig_Type
) then
10128 -- Test if the type is inherited from [mscorlib]System.Delegate
10130 while Etype
(Desig_Type
) /= Desig_Type
loop
10131 if Chars
(Scope
(Desig_Type
)) /= No_Name
10132 and then Is_Imported
(Scope
(Desig_Type
))
10133 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
10138 Desig_Type
:= Etype
(Desig_Type
);
10144 ----------------------------------------------
10145 -- Is_Dependent_Component_Of_Mutable_Object --
10146 ----------------------------------------------
10148 function Is_Dependent_Component_Of_Mutable_Object
10149 (Object
: Node_Id
) return Boolean
10151 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
10152 -- Returns True if and only if Comp is declared within a variant part
10154 --------------------------------
10155 -- Is_Declared_Within_Variant --
10156 --------------------------------
10158 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
10159 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
10160 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
10162 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
10163 end Is_Declared_Within_Variant
;
10166 Prefix_Type
: Entity_Id
;
10167 P_Aliased
: Boolean := False;
10170 Deref
: Node_Id
:= Object
;
10171 -- Dereference node, in something like X.all.Y(2)
10173 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10176 -- Find the dereference node if any
10178 while Nkind_In
(Deref
, N_Indexed_Component
,
10179 N_Selected_Component
,
10182 Deref
:= Prefix
(Deref
);
10185 -- Ada 2005: If we have a component or slice of a dereference,
10186 -- something like X.all.Y (2), and the type of X is access-to-constant,
10187 -- Is_Variable will return False, because it is indeed a constant
10188 -- view. But it might be a view of a variable object, so we want the
10189 -- following condition to be True in that case.
10191 if Is_Variable
(Object
)
10192 or else (Ada_Version
>= Ada_2005
10193 and then Nkind
(Deref
) = N_Explicit_Dereference
)
10195 if Nkind
(Object
) = N_Selected_Component
then
10196 P
:= Prefix
(Object
);
10197 Prefix_Type
:= Etype
(P
);
10199 if Is_Entity_Name
(P
) then
10200 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
10201 Prefix_Type
:= Base_Type
(Prefix_Type
);
10204 if Is_Aliased
(Entity
(P
)) then
10208 -- A discriminant check on a selected component may be expanded
10209 -- into a dereference when removing side-effects. Recover the
10210 -- original node and its type, which may be unconstrained.
10212 elsif Nkind
(P
) = N_Explicit_Dereference
10213 and then not (Comes_From_Source
(P
))
10215 P
:= Original_Node
(P
);
10216 Prefix_Type
:= Etype
(P
);
10219 -- Check for prefix being an aliased component???
10225 -- A heap object is constrained by its initial value
10227 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10228 -- the dereferenced case, since the access value might denote an
10229 -- unconstrained aliased object, whereas in Ada 95 the designated
10230 -- object is guaranteed to be constrained. A worst-case assumption
10231 -- has to apply in Ada 2005 because we can't tell at compile
10232 -- time whether the object is "constrained by its initial value"
10233 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10234 -- rules (these rules are acknowledged to need fixing).
10236 if Ada_Version
< Ada_2005
then
10237 if Is_Access_Type
(Prefix_Type
)
10238 or else Nkind
(P
) = N_Explicit_Dereference
10243 else pragma Assert
(Ada_Version
>= Ada_2005
);
10244 if Is_Access_Type
(Prefix_Type
) then
10246 -- If the access type is pool-specific, and there is no
10247 -- constrained partial view of the designated type, then the
10248 -- designated object is known to be constrained.
10250 if Ekind
(Prefix_Type
) = E_Access_Type
10251 and then not Object_Type_Has_Constrained_Partial_View
10252 (Typ
=> Designated_Type
(Prefix_Type
),
10253 Scop
=> Current_Scope
)
10257 -- Otherwise (general access type, or there is a constrained
10258 -- partial view of the designated type), we need to check
10259 -- based on the designated type.
10262 Prefix_Type
:= Designated_Type
(Prefix_Type
);
10268 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
10270 -- As per AI-0017, the renaming is illegal in a generic body, even
10271 -- if the subtype is indefinite.
10273 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10275 if not Is_Constrained
(Prefix_Type
)
10276 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
10278 (Is_Generic_Type
(Prefix_Type
)
10279 and then Ekind
(Current_Scope
) = E_Generic_Package
10280 and then In_Package_Body
(Current_Scope
)))
10282 and then (Is_Declared_Within_Variant
(Comp
)
10283 or else Has_Discriminant_Dependent_Constraint
(Comp
))
10284 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
10288 -- If the prefix is of an access type at this point, then we want
10289 -- to return False, rather than calling this function recursively
10290 -- on the access object (which itself might be a discriminant-
10291 -- dependent component of some other object, but that isn't
10292 -- relevant to checking the object passed to us). This avoids
10293 -- issuing wrong errors when compiling with -gnatc, where there
10294 -- can be implicit dereferences that have not been expanded.
10296 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
10301 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10304 elsif Nkind
(Object
) = N_Indexed_Component
10305 or else Nkind
(Object
) = N_Slice
10307 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10309 -- A type conversion that Is_Variable is a view conversion:
10310 -- go back to the denoted object.
10312 elsif Nkind
(Object
) = N_Type_Conversion
then
10314 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
10319 end Is_Dependent_Component_Of_Mutable_Object
;
10321 ---------------------
10322 -- Is_Dereferenced --
10323 ---------------------
10325 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
10326 P
: constant Node_Id
:= Parent
(N
);
10328 return Nkind_In
(P
, N_Selected_Component
,
10329 N_Explicit_Dereference
,
10330 N_Indexed_Component
,
10332 and then Prefix
(P
) = N
;
10333 end Is_Dereferenced
;
10335 ----------------------
10336 -- Is_Descendent_Of --
10337 ----------------------
10339 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
10344 pragma Assert
(Nkind
(T1
) in N_Entity
);
10345 pragma Assert
(Nkind
(T2
) in N_Entity
);
10347 T
:= Base_Type
(T1
);
10349 -- Immediate return if the types match
10354 -- Comment needed here ???
10356 elsif Ekind
(T
) = E_Class_Wide_Type
then
10357 return Etype
(T
) = T2
;
10365 -- Done if we found the type we are looking for
10370 -- Done if no more derivations to check
10377 -- Following test catches error cases resulting from prev errors
10379 elsif No
(Etyp
) then
10382 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
10385 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
10389 T
:= Base_Type
(Etyp
);
10392 end Is_Descendent_Of
;
10394 -----------------------------
10395 -- Is_Effectively_Volatile --
10396 -----------------------------
10398 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
10400 if Is_Type
(Id
) then
10402 -- An arbitrary type is effectively volatile when it is subject to
10403 -- pragma Atomic or Volatile.
10405 if Is_Volatile
(Id
) then
10408 -- An array type is effectively volatile when it is subject to pragma
10409 -- Atomic_Components or Volatile_Components or its compolent type is
10410 -- effectively volatile.
10412 elsif Is_Array_Type
(Id
) then
10414 Has_Volatile_Components
(Id
)
10416 Is_Effectively_Volatile
(Component_Type
(Base_Type
(Id
)));
10422 -- Otherwise Id denotes an object
10427 or else Has_Volatile_Components
(Id
)
10428 or else Is_Effectively_Volatile
(Etype
(Id
));
10430 end Is_Effectively_Volatile
;
10432 ------------------------------------
10433 -- Is_Effectively_Volatile_Object --
10434 ------------------------------------
10436 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
10438 if Is_Entity_Name
(N
) then
10439 return Is_Effectively_Volatile
(Entity
(N
));
10441 elsif Nkind
(N
) = N_Expanded_Name
then
10442 return Is_Effectively_Volatile
(Entity
(N
));
10444 elsif Nkind
(N
) = N_Indexed_Component
then
10445 return Is_Effectively_Volatile_Object
(Prefix
(N
));
10447 elsif Nkind
(N
) = N_Selected_Component
then
10449 Is_Effectively_Volatile_Object
(Prefix
(N
))
10451 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
10456 end Is_Effectively_Volatile_Object
;
10458 ----------------------------
10459 -- Is_Expression_Function --
10460 ----------------------------
10462 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
10466 if Ekind
(Subp
) /= E_Function
then
10470 Decl
:= Unit_Declaration_Node
(Subp
);
10471 return Nkind
(Decl
) = N_Subprogram_Declaration
10473 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
10475 (Present
(Corresponding_Body
(Decl
))
10477 Nkind
(Original_Node
10478 (Unit_Declaration_Node
10479 (Corresponding_Body
(Decl
)))) =
10480 N_Expression_Function
));
10482 end Is_Expression_Function
;
10488 function Is_False
(U
: Uint
) return Boolean is
10493 ---------------------------
10494 -- Is_Fixed_Model_Number --
10495 ---------------------------
10497 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
10498 S
: constant Ureal
:= Small_Value
(T
);
10499 M
: Urealp
.Save_Mark
;
10503 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
10504 Urealp
.Release
(M
);
10506 end Is_Fixed_Model_Number
;
10508 -------------------------------
10509 -- Is_Fully_Initialized_Type --
10510 -------------------------------
10512 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
10514 -- In Ada2012, a scalar type with an aspect Default_Value
10515 -- is fully initialized.
10517 if Is_Scalar_Type
(Typ
) then
10518 return Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
);
10520 elsif Is_Access_Type
(Typ
) then
10523 elsif Is_Array_Type
(Typ
) then
10524 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
10525 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
10530 -- An interesting case, if we have a constrained type one of whose
10531 -- bounds is known to be null, then there are no elements to be
10532 -- initialized, so all the elements are initialized.
10534 if Is_Constrained
(Typ
) then
10537 Indx_Typ
: Entity_Id
;
10538 Lbd
, Hbd
: Node_Id
;
10541 Indx
:= First_Index
(Typ
);
10542 while Present
(Indx
) loop
10543 if Etype
(Indx
) = Any_Type
then
10546 -- If index is a range, use directly
10548 elsif Nkind
(Indx
) = N_Range
then
10549 Lbd
:= Low_Bound
(Indx
);
10550 Hbd
:= High_Bound
(Indx
);
10553 Indx_Typ
:= Etype
(Indx
);
10555 if Is_Private_Type
(Indx_Typ
) then
10556 Indx_Typ
:= Full_View
(Indx_Typ
);
10559 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
10562 Lbd
:= Type_Low_Bound
(Indx_Typ
);
10563 Hbd
:= Type_High_Bound
(Indx_Typ
);
10567 if Compile_Time_Known_Value
(Lbd
)
10569 Compile_Time_Known_Value
(Hbd
)
10571 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
10581 -- If no null indexes, then type is not fully initialized
10587 elsif Is_Record_Type
(Typ
) then
10588 if Has_Discriminants
(Typ
)
10590 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
10591 and then Is_Fully_Initialized_Variant
(Typ
)
10596 -- We consider bounded string types to be fully initialized, because
10597 -- otherwise we get false alarms when the Data component is not
10598 -- default-initialized.
10600 if Is_Bounded_String
(Typ
) then
10604 -- Controlled records are considered to be fully initialized if
10605 -- there is a user defined Initialize routine. This may not be
10606 -- entirely correct, but as the spec notes, we are guessing here
10607 -- what is best from the point of view of issuing warnings.
10609 if Is_Controlled
(Typ
) then
10611 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
10614 if Present
(Utyp
) then
10616 Init
: constant Entity_Id
:=
10618 (Underlying_Type
(Typ
), Name_Initialize
));
10622 and then Comes_From_Source
(Init
)
10624 Is_Predefined_File_Name
10625 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
10629 elsif Has_Null_Extension
(Typ
)
10631 Is_Fully_Initialized_Type
10632 (Etype
(Base_Type
(Typ
)))
10641 -- Otherwise see if all record components are initialized
10647 Ent
:= First_Entity
(Typ
);
10648 while Present
(Ent
) loop
10649 if Ekind
(Ent
) = E_Component
10650 and then (No
(Parent
(Ent
))
10651 or else No
(Expression
(Parent
(Ent
))))
10652 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
10654 -- Special VM case for tag components, which need to be
10655 -- defined in this case, but are never initialized as VMs
10656 -- are using other dispatching mechanisms. Ignore this
10657 -- uninitialized case. Note that this applies both to the
10658 -- uTag entry and the main vtable pointer (CPP_Class case).
10660 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
10669 -- No uninitialized components, so type is fully initialized.
10670 -- Note that this catches the case of no components as well.
10674 elsif Is_Concurrent_Type
(Typ
) then
10677 elsif Is_Private_Type
(Typ
) then
10679 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10685 return Is_Fully_Initialized_Type
(U
);
10692 end Is_Fully_Initialized_Type
;
10694 ----------------------------------
10695 -- Is_Fully_Initialized_Variant --
10696 ----------------------------------
10698 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
10699 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
10700 Constraints
: constant List_Id
:= New_List
;
10701 Components
: constant Elist_Id
:= New_Elmt_List
;
10702 Comp_Elmt
: Elmt_Id
;
10704 Comp_List
: Node_Id
;
10706 Discr_Val
: Node_Id
;
10708 Report_Errors
: Boolean;
10709 pragma Warnings
(Off
, Report_Errors
);
10712 if Serious_Errors_Detected
> 0 then
10716 if Is_Record_Type
(Typ
)
10717 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
10718 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
10720 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
10722 Discr
:= First_Discriminant
(Typ
);
10723 while Present
(Discr
) loop
10724 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
10725 Discr_Val
:= Expression
(Parent
(Discr
));
10727 if Present
(Discr_Val
)
10728 and then Is_OK_Static_Expression
(Discr_Val
)
10730 Append_To
(Constraints
,
10731 Make_Component_Association
(Loc
,
10732 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
10733 Expression
=> New_Copy
(Discr_Val
)));
10741 Next_Discriminant
(Discr
);
10746 Comp_List
=> Comp_List
,
10747 Governed_By
=> Constraints
,
10748 Into
=> Components
,
10749 Report_Errors
=> Report_Errors
);
10751 -- Check that each component present is fully initialized
10753 Comp_Elmt
:= First_Elmt
(Components
);
10754 while Present
(Comp_Elmt
) loop
10755 Comp_Id
:= Node
(Comp_Elmt
);
10757 if Ekind
(Comp_Id
) = E_Component
10758 and then (No
(Parent
(Comp_Id
))
10759 or else No
(Expression
(Parent
(Comp_Id
))))
10760 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
10765 Next_Elmt
(Comp_Elmt
);
10770 elsif Is_Private_Type
(Typ
) then
10772 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10778 return Is_Fully_Initialized_Variant
(U
);
10785 end Is_Fully_Initialized_Variant
;
10787 ----------------------------
10788 -- Is_Inherited_Operation --
10789 ----------------------------
10791 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
10792 pragma Assert
(Is_Overloadable
(E
));
10793 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
10795 return Kind
= N_Full_Type_Declaration
10796 or else Kind
= N_Private_Extension_Declaration
10797 or else Kind
= N_Subtype_Declaration
10798 or else (Ekind
(E
) = E_Enumeration_Literal
10799 and then Is_Derived_Type
(Etype
(E
)));
10800 end Is_Inherited_Operation
;
10802 -------------------------------------
10803 -- Is_Inherited_Operation_For_Type --
10804 -------------------------------------
10806 function Is_Inherited_Operation_For_Type
10808 Typ
: Entity_Id
) return Boolean
10811 -- Check that the operation has been created by the type declaration
10813 return Is_Inherited_Operation
(E
)
10814 and then Defining_Identifier
(Parent
(E
)) = Typ
;
10815 end Is_Inherited_Operation_For_Type
;
10821 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
10822 Ifaces_List
: Elist_Id
;
10823 Iface_Elmt
: Elmt_Id
;
10827 if Is_Class_Wide_Type
(Typ
)
10828 and then Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
10829 Name_Reversible_Iterator
)
10831 Is_Predefined_File_Name
10832 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
10836 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
10839 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
10843 Collect_Interfaces
(Typ
, Ifaces_List
);
10845 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
10846 while Present
(Iface_Elmt
) loop
10847 Iface
:= Node
(Iface_Elmt
);
10848 if Chars
(Iface
) = Name_Forward_Iterator
10850 Is_Predefined_File_Name
10851 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
10856 Next_Elmt
(Iface_Elmt
);
10867 -- We seem to have a lot of overlapping functions that do similar things
10868 -- (testing for left hand sides or lvalues???).
10870 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
10871 P
: constant Node_Id
:= Parent
(N
);
10874 -- Return True if we are the left hand side of an assignment statement
10876 if Nkind
(P
) = N_Assignment_Statement
then
10877 if Name
(P
) = N
then
10883 -- Case of prefix of indexed or selected component or slice
10885 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
10886 and then N
= Prefix
(P
)
10888 -- Here we have the case where the parent P is N.Q or N(Q .. R).
10889 -- If P is an LHS, then N is also effectively an LHS, but there
10890 -- is an important exception. If N is of an access type, then
10891 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
10892 -- case this makes N.all a left hand side but not N itself.
10894 -- If we don't know the type yet, this is the case where we return
10895 -- Unknown, since the answer depends on the type which is unknown.
10897 if No
(Etype
(N
)) then
10900 -- We have an Etype set, so we can check it
10902 elsif Is_Access_Type
(Etype
(N
)) then
10905 -- OK, not access type case, so just test whole expression
10911 -- All other cases are not left hand sides
10918 -----------------------------
10919 -- Is_Library_Level_Entity --
10920 -----------------------------
10922 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
10924 -- The following is a small optimization, and it also properly handles
10925 -- discriminals, which in task bodies might appear in expressions before
10926 -- the corresponding procedure has been created, and which therefore do
10927 -- not have an assigned scope.
10929 if Is_Formal
(E
) then
10933 -- Normal test is simply that the enclosing dynamic scope is Standard
10935 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
10936 end Is_Library_Level_Entity
;
10938 --------------------------------
10939 -- Is_Limited_Class_Wide_Type --
10940 --------------------------------
10942 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
10945 Is_Class_Wide_Type
(Typ
)
10946 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
10947 end Is_Limited_Class_Wide_Type
;
10949 ---------------------------------
10950 -- Is_Local_Variable_Reference --
10951 ---------------------------------
10953 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
10955 if not Is_Entity_Name
(Expr
) then
10960 Ent
: constant Entity_Id
:= Entity
(Expr
);
10961 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
10963 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
10966 return Present
(Sub
) and then Sub
= Current_Subprogram
;
10970 end Is_Local_Variable_Reference
;
10972 -------------------------
10973 -- Is_Object_Reference --
10974 -------------------------
10976 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
10978 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
10979 -- Determine whether N is the name of an internally-generated renaming
10981 --------------------------------------
10982 -- Is_Internally_Generated_Renaming --
10983 --------------------------------------
10985 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
10990 while Present
(P
) loop
10991 if Nkind
(P
) = N_Object_Renaming_Declaration
then
10992 return not Comes_From_Source
(P
);
10993 elsif Is_List_Member
(P
) then
11001 end Is_Internally_Generated_Renaming
;
11003 -- Start of processing for Is_Object_Reference
11006 if Is_Entity_Name
(N
) then
11007 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
11011 when N_Indexed_Component | N_Slice
=>
11013 Is_Object_Reference
(Prefix
(N
))
11014 or else Is_Access_Type
(Etype
(Prefix
(N
)));
11016 -- In Ada 95, a function call is a constant object; a procedure
11019 when N_Function_Call
=>
11020 return Etype
(N
) /= Standard_Void_Type
;
11022 -- Attributes 'Input, 'Old and 'Result produce objects
11024 when N_Attribute_Reference
=>
11027 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
11029 when N_Selected_Component
=>
11031 Is_Object_Reference
(Selector_Name
(N
))
11033 (Is_Object_Reference
(Prefix
(N
))
11034 or else Is_Access_Type
(Etype
(Prefix
(N
))));
11036 when N_Explicit_Dereference
=>
11039 -- A view conversion of a tagged object is an object reference
11041 when N_Type_Conversion
=>
11042 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
11043 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
11044 and then Is_Object_Reference
(Expression
(N
));
11046 -- An unchecked type conversion is considered to be an object if
11047 -- the operand is an object (this construction arises only as a
11048 -- result of expansion activities).
11050 when N_Unchecked_Type_Conversion
=>
11053 -- Allow string literals to act as objects as long as they appear
11054 -- in internally-generated renamings. The expansion of iterators
11055 -- may generate such renamings when the range involves a string
11058 when N_String_Literal
=>
11059 return Is_Internally_Generated_Renaming
(Parent
(N
));
11061 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11062 -- This allows disambiguation of function calls and the use
11063 -- of aggregates in more contexts.
11065 when N_Qualified_Expression
=>
11066 if Ada_Version
< Ada_2012
then
11069 return Is_Object_Reference
(Expression
(N
))
11070 or else Nkind
(Expression
(N
)) = N_Aggregate
;
11077 end Is_Object_Reference
;
11079 -----------------------------------
11080 -- Is_OK_Variable_For_Out_Formal --
11081 -----------------------------------
11083 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
11085 Note_Possible_Modification
(AV
, Sure
=> True);
11087 -- We must reject parenthesized variable names. Comes_From_Source is
11088 -- checked because there are currently cases where the compiler violates
11089 -- this rule (e.g. passing a task object to its controlled Initialize
11090 -- routine). This should be properly documented in sinfo???
11092 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
11095 -- A variable is always allowed
11097 elsif Is_Variable
(AV
) then
11100 -- Unchecked conversions are allowed only if they come from the
11101 -- generated code, which sometimes uses unchecked conversions for out
11102 -- parameters in cases where code generation is unaffected. We tell
11103 -- source unchecked conversions by seeing if they are rewrites of
11104 -- an original Unchecked_Conversion function call, or of an explicit
11105 -- conversion of a function call or an aggregate (as may happen in the
11106 -- expansion of a packed array aggregate).
11108 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
11109 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
11112 elsif Comes_From_Source
(AV
)
11113 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
11117 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
11118 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
11124 -- Normal type conversions are allowed if argument is a variable
11126 elsif Nkind
(AV
) = N_Type_Conversion
then
11127 if Is_Variable
(Expression
(AV
))
11128 and then Paren_Count
(Expression
(AV
)) = 0
11130 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
11133 -- We also allow a non-parenthesized expression that raises
11134 -- constraint error if it rewrites what used to be a variable
11136 elsif Raises_Constraint_Error
(Expression
(AV
))
11137 and then Paren_Count
(Expression
(AV
)) = 0
11138 and then Is_Variable
(Original_Node
(Expression
(AV
)))
11142 -- Type conversion of something other than a variable
11148 -- If this node is rewritten, then test the original form, if that is
11149 -- OK, then we consider the rewritten node OK (for example, if the
11150 -- original node is a conversion, then Is_Variable will not be true
11151 -- but we still want to allow the conversion if it converts a variable).
11153 elsif Original_Node
(AV
) /= AV
then
11155 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11156 -- Reference function.
11158 if Ada_Version
>= Ada_2012
11159 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
11161 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
11166 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
11169 -- All other non-variables are rejected
11174 end Is_OK_Variable_For_Out_Formal
;
11176 -----------------------------------
11177 -- Is_Partially_Initialized_Type --
11178 -----------------------------------
11180 function Is_Partially_Initialized_Type
11182 Include_Implicit
: Boolean := True) return Boolean
11185 if Is_Scalar_Type
(Typ
) then
11188 elsif Is_Access_Type
(Typ
) then
11189 return Include_Implicit
;
11191 elsif Is_Array_Type
(Typ
) then
11193 -- If component type is partially initialized, so is array type
11195 if Is_Partially_Initialized_Type
11196 (Component_Type
(Typ
), Include_Implicit
)
11200 -- Otherwise we are only partially initialized if we are fully
11201 -- initialized (this is the empty array case, no point in us
11202 -- duplicating that code here).
11205 return Is_Fully_Initialized_Type
(Typ
);
11208 elsif Is_Record_Type
(Typ
) then
11210 -- A discriminated type is always partially initialized if in
11213 if Has_Discriminants
(Typ
) and then Include_Implicit
then
11216 -- A tagged type is always partially initialized
11218 elsif Is_Tagged_Type
(Typ
) then
11221 -- Case of non-discriminated record
11227 Component_Present
: Boolean := False;
11228 -- Set True if at least one component is present. If no
11229 -- components are present, then record type is fully
11230 -- initialized (another odd case, like the null array).
11233 -- Loop through components
11235 Ent
:= First_Entity
(Typ
);
11236 while Present
(Ent
) loop
11237 if Ekind
(Ent
) = E_Component
then
11238 Component_Present
:= True;
11240 -- If a component has an initialization expression then
11241 -- the enclosing record type is partially initialized
11243 if Present
(Parent
(Ent
))
11244 and then Present
(Expression
(Parent
(Ent
)))
11248 -- If a component is of a type which is itself partially
11249 -- initialized, then the enclosing record type is also.
11251 elsif Is_Partially_Initialized_Type
11252 (Etype
(Ent
), Include_Implicit
)
11261 -- No initialized components found. If we found any components
11262 -- they were all uninitialized so the result is false.
11264 if Component_Present
then
11267 -- But if we found no components, then all the components are
11268 -- initialized so we consider the type to be initialized.
11276 -- Concurrent types are always fully initialized
11278 elsif Is_Concurrent_Type
(Typ
) then
11281 -- For a private type, go to underlying type. If there is no underlying
11282 -- type then just assume this partially initialized. Not clear if this
11283 -- can happen in a non-error case, but no harm in testing for this.
11285 elsif Is_Private_Type
(Typ
) then
11287 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11292 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
11296 -- For any other type (are there any?) assume partially initialized
11301 end Is_Partially_Initialized_Type
;
11303 ------------------------------------
11304 -- Is_Potentially_Persistent_Type --
11305 ------------------------------------
11307 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
11312 -- For private type, test corresponding full type
11314 if Is_Private_Type
(T
) then
11315 return Is_Potentially_Persistent_Type
(Full_View
(T
));
11317 -- Scalar types are potentially persistent
11319 elsif Is_Scalar_Type
(T
) then
11322 -- Record type is potentially persistent if not tagged and the types of
11323 -- all it components are potentially persistent, and no component has
11324 -- an initialization expression.
11326 elsif Is_Record_Type
(T
)
11327 and then not Is_Tagged_Type
(T
)
11328 and then not Is_Partially_Initialized_Type
(T
)
11330 Comp
:= First_Component
(T
);
11331 while Present
(Comp
) loop
11332 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
11335 Next_Entity
(Comp
);
11341 -- Array type is potentially persistent if its component type is
11342 -- potentially persistent and if all its constraints are static.
11344 elsif Is_Array_Type
(T
) then
11345 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
11349 Indx
:= First_Index
(T
);
11350 while Present
(Indx
) loop
11351 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
11360 -- All other types are not potentially persistent
11365 end Is_Potentially_Persistent_Type
;
11367 --------------------------------
11368 -- Is_Potentially_Unevaluated --
11369 --------------------------------
11371 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
11379 -- A postcondition whose expression is a short-circuit is broken down
11380 -- into individual aspects for better exception reporting. The original
11381 -- short-circuit expression is rewritten as the second operand, and an
11382 -- occurrence of 'Old in that operand is potentially unevaluated.
11383 -- See Sem_ch13.adb for details of this transformation.
11385 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
11389 while not Nkind_In
(Par
, N_If_Expression
,
11397 Par
:= Parent
(Par
);
11399 -- If the context is not an expression, or if is the result of
11400 -- expansion of an enclosing construct (such as another attribute)
11401 -- the predicate does not apply.
11403 if Nkind
(Par
) not in N_Subexpr
11404 or else not Comes_From_Source
(Par
)
11410 if Nkind
(Par
) = N_If_Expression
then
11411 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
11413 elsif Nkind
(Par
) = N_Case_Expression
then
11414 return Expr
/= Expression
(Par
);
11416 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
11417 return Expr
= Right_Opnd
(Par
);
11419 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
11420 return Expr
/= Left_Opnd
(Par
);
11425 end Is_Potentially_Unevaluated
;
11427 ---------------------------------
11428 -- Is_Protected_Self_Reference --
11429 ---------------------------------
11431 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
11433 function In_Access_Definition
(N
: Node_Id
) return Boolean;
11434 -- Returns true if N belongs to an access definition
11436 --------------------------
11437 -- In_Access_Definition --
11438 --------------------------
11440 function In_Access_Definition
(N
: Node_Id
) return Boolean is
11445 while Present
(P
) loop
11446 if Nkind
(P
) = N_Access_Definition
then
11454 end In_Access_Definition
;
11456 -- Start of processing for Is_Protected_Self_Reference
11459 -- Verify that prefix is analyzed and has the proper form. Note that
11460 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11461 -- which also produce the address of an entity, do not analyze their
11462 -- prefix because they denote entities that are not necessarily visible.
11463 -- Neither of them can apply to a protected type.
11465 return Ada_Version
>= Ada_2005
11466 and then Is_Entity_Name
(N
)
11467 and then Present
(Entity
(N
))
11468 and then Is_Protected_Type
(Entity
(N
))
11469 and then In_Open_Scopes
(Entity
(N
))
11470 and then not In_Access_Definition
(N
);
11471 end Is_Protected_Self_Reference
;
11473 -----------------------------
11474 -- Is_RCI_Pkg_Spec_Or_Body --
11475 -----------------------------
11477 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
11479 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
11480 -- Return True if the unit of Cunit is an RCI package declaration
11482 ---------------------------
11483 -- Is_RCI_Pkg_Decl_Cunit --
11484 ---------------------------
11486 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
11487 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
11490 if Nkind
(The_Unit
) /= N_Package_Declaration
then
11494 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
11495 end Is_RCI_Pkg_Decl_Cunit
;
11497 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11500 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
11502 (Nkind
(Unit
(Cunit
)) = N_Package_Body
11503 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
11504 end Is_RCI_Pkg_Spec_Or_Body
;
11506 -----------------------------------------
11507 -- Is_Remote_Access_To_Class_Wide_Type --
11508 -----------------------------------------
11510 function Is_Remote_Access_To_Class_Wide_Type
11511 (E
: Entity_Id
) return Boolean
11514 -- A remote access to class-wide type is a general access to object type
11515 -- declared in the visible part of a Remote_Types or Remote_Call_
11518 return Ekind
(E
) = E_General_Access_Type
11519 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11520 end Is_Remote_Access_To_Class_Wide_Type
;
11522 -----------------------------------------
11523 -- Is_Remote_Access_To_Subprogram_Type --
11524 -----------------------------------------
11526 function Is_Remote_Access_To_Subprogram_Type
11527 (E
: Entity_Id
) return Boolean
11530 return (Ekind
(E
) = E_Access_Subprogram_Type
11531 or else (Ekind
(E
) = E_Record_Type
11532 and then Present
(Corresponding_Remote_Type
(E
))))
11533 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11534 end Is_Remote_Access_To_Subprogram_Type
;
11536 --------------------
11537 -- Is_Remote_Call --
11538 --------------------
11540 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
11542 if Nkind
(N
) not in N_Subprogram_Call
then
11544 -- An entry call cannot be remote
11548 elsif Nkind
(Name
(N
)) in N_Has_Entity
11549 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
11551 -- A subprogram declared in the spec of a RCI package is remote
11555 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
11556 and then Is_Remote_Access_To_Subprogram_Type
11557 (Etype
(Prefix
(Name
(N
))))
11559 -- The dereference of a RAS is a remote call
11563 elsif Present
(Controlling_Argument
(N
))
11564 and then Is_Remote_Access_To_Class_Wide_Type
11565 (Etype
(Controlling_Argument
(N
)))
11567 -- Any primitive operation call with a controlling argument of
11568 -- a RACW type is a remote call.
11573 -- All other calls are local calls
11576 end Is_Remote_Call
;
11578 ----------------------
11579 -- Is_Renamed_Entry --
11580 ----------------------
11582 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
11583 Orig_Node
: Node_Id
:= Empty
;
11584 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
11586 function Is_Entry
(Nam
: Node_Id
) return Boolean;
11587 -- Determine whether Nam is an entry. Traverse selectors if there are
11588 -- nested selected components.
11594 function Is_Entry
(Nam
: Node_Id
) return Boolean is
11596 if Nkind
(Nam
) = N_Selected_Component
then
11597 return Is_Entry
(Selector_Name
(Nam
));
11600 return Ekind
(Entity
(Nam
)) = E_Entry
;
11603 -- Start of processing for Is_Renamed_Entry
11606 if Present
(Alias
(Proc_Nam
)) then
11607 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
11610 -- Look for a rewritten subprogram renaming declaration
11612 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11613 and then Present
(Original_Node
(Subp_Decl
))
11615 Orig_Node
:= Original_Node
(Subp_Decl
);
11618 -- The rewritten subprogram is actually an entry
11620 if Present
(Orig_Node
)
11621 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
11622 and then Is_Entry
(Name
(Orig_Node
))
11628 end Is_Renamed_Entry
;
11630 ----------------------------
11631 -- Is_Reversible_Iterator --
11632 ----------------------------
11634 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
11635 Ifaces_List
: Elist_Id
;
11636 Iface_Elmt
: Elmt_Id
;
11640 if Is_Class_Wide_Type
(Typ
)
11641 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
11642 and then Is_Predefined_File_Name
11643 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
11647 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
11651 Collect_Interfaces
(Typ
, Ifaces_List
);
11653 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
11654 while Present
(Iface_Elmt
) loop
11655 Iface
:= Node
(Iface_Elmt
);
11656 if Chars
(Iface
) = Name_Reversible_Iterator
11658 Is_Predefined_File_Name
11659 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
11664 Next_Elmt
(Iface_Elmt
);
11669 end Is_Reversible_Iterator
;
11671 ----------------------
11672 -- Is_Selector_Name --
11673 ----------------------
11675 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
11677 if not Is_List_Member
(N
) then
11679 P
: constant Node_Id
:= Parent
(N
);
11681 return Nkind_In
(P
, N_Expanded_Name
,
11682 N_Generic_Association
,
11683 N_Parameter_Association
,
11684 N_Selected_Component
)
11685 and then Selector_Name
(P
) = N
;
11690 L
: constant List_Id
:= List_Containing
(N
);
11691 P
: constant Node_Id
:= Parent
(L
);
11693 return (Nkind
(P
) = N_Discriminant_Association
11694 and then Selector_Names
(P
) = L
)
11696 (Nkind
(P
) = N_Component_Association
11697 and then Choices
(P
) = L
);
11700 end Is_Selector_Name
;
11702 -------------------------------------
11703 -- Is_SPARK_05_Initialization_Expr --
11704 -------------------------------------
11706 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
11709 Comp_Assn
: Node_Id
;
11710 Orig_N
: constant Node_Id
:= Original_Node
(N
);
11715 if not Comes_From_Source
(Orig_N
) then
11719 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
11721 case Nkind
(Orig_N
) is
11722 when N_Character_Literal |
11723 N_Integer_Literal |
11725 N_String_Literal
=>
11728 when N_Identifier |
11730 if Is_Entity_Name
(Orig_N
)
11731 and then Present
(Entity
(Orig_N
)) -- needed in some cases
11733 case Ekind
(Entity
(Orig_N
)) is
11735 E_Enumeration_Literal |
11740 if Is_Type
(Entity
(Orig_N
)) then
11748 when N_Qualified_Expression |
11749 N_Type_Conversion
=>
11750 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
11753 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
11757 N_Membership_Test
=>
11758 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
11760 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
11763 N_Extension_Aggregate
=>
11764 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
11766 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
11769 Expr
:= First
(Expressions
(Orig_N
));
11770 while Present
(Expr
) loop
11771 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
11779 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
11780 while Present
(Comp_Assn
) loop
11781 Expr
:= Expression
(Comp_Assn
);
11782 if Present
(Expr
) -- needed for box association
11783 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
11792 when N_Attribute_Reference
=>
11793 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
11794 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
11797 Expr
:= First
(Expressions
(Orig_N
));
11798 while Present
(Expr
) loop
11799 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
11807 -- Selected components might be expanded named not yet resolved, so
11808 -- default on the safe side. (Eg on sparklex.ads)
11810 when N_Selected_Component
=>
11819 end Is_SPARK_05_Initialization_Expr
;
11821 ----------------------------------
11822 -- Is_SPARK_05_Object_Reference --
11823 ----------------------------------
11825 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
11827 if Is_Entity_Name
(N
) then
11828 return Present
(Entity
(N
))
11830 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
11831 or else Ekind
(Entity
(N
)) in Formal_Kind
);
11835 when N_Selected_Component
=>
11836 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
11842 end Is_SPARK_05_Object_Reference
;
11848 function Is_Statement
(N
: Node_Id
) return Boolean is
11851 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
11852 or else Nkind
(N
) = N_Procedure_Call_Statement
;
11855 --------------------------------------------------
11856 -- Is_Subprogram_Stub_Without_Prior_Declaration --
11857 --------------------------------------------------
11859 function Is_Subprogram_Stub_Without_Prior_Declaration
11860 (N
: Node_Id
) return Boolean
11863 -- A subprogram stub without prior declaration serves as declaration for
11864 -- the actual subprogram body. As such, it has an attached defining
11865 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
11867 return Nkind
(N
) = N_Subprogram_Body_Stub
11868 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
11869 end Is_Subprogram_Stub_Without_Prior_Declaration
;
11871 ---------------------------------
11872 -- Is_Synchronized_Tagged_Type --
11873 ---------------------------------
11875 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
11876 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
11879 -- A task or protected type derived from an interface is a tagged type.
11880 -- Such a tagged type is called a synchronized tagged type, as are
11881 -- synchronized interfaces and private extensions whose declaration
11882 -- includes the reserved word synchronized.
11884 return (Is_Tagged_Type
(E
)
11885 and then (Kind
= E_Task_Type
11886 or else Kind
= E_Protected_Type
))
11889 and then Is_Synchronized_Interface
(E
))
11891 (Ekind
(E
) = E_Record_Type_With_Private
11892 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
11893 and then (Synchronized_Present
(Parent
(E
))
11894 or else Is_Synchronized_Interface
(Etype
(E
))));
11895 end Is_Synchronized_Tagged_Type
;
11901 function Is_Transfer
(N
: Node_Id
) return Boolean is
11902 Kind
: constant Node_Kind
:= Nkind
(N
);
11905 if Kind
= N_Simple_Return_Statement
11907 Kind
= N_Extended_Return_Statement
11909 Kind
= N_Goto_Statement
11911 Kind
= N_Raise_Statement
11913 Kind
= N_Requeue_Statement
11917 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
11918 and then No
(Condition
(N
))
11922 elsif Kind
= N_Procedure_Call_Statement
11923 and then Is_Entity_Name
(Name
(N
))
11924 and then Present
(Entity
(Name
(N
)))
11925 and then No_Return
(Entity
(Name
(N
)))
11929 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
11941 function Is_True
(U
: Uint
) return Boolean is
11946 --------------------------------------
11947 -- Is_Unchecked_Conversion_Instance --
11948 --------------------------------------
11950 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
11951 Gen_Par
: Entity_Id
;
11954 -- Look for a function whose generic parent is the predefined intrinsic
11955 -- function Unchecked_Conversion.
11957 if Ekind
(Id
) = E_Function
then
11958 Gen_Par
:= Generic_Parent
(Parent
(Id
));
11962 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
11963 and then Is_Intrinsic_Subprogram
(Gen_Par
)
11964 and then Is_Predefined_File_Name
11965 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
11969 end Is_Unchecked_Conversion_Instance
;
11971 -------------------------------
11972 -- Is_Universal_Numeric_Type --
11973 -------------------------------
11975 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
11977 return T
= Universal_Integer
or else T
= Universal_Real
;
11978 end Is_Universal_Numeric_Type
;
11980 -------------------
11981 -- Is_Value_Type --
11982 -------------------
11984 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
11986 return VM_Target
= CLI_Target
11987 and then Nkind
(T
) in N_Has_Chars
11988 and then Chars
(T
) /= No_Name
11989 and then Get_Name_String
(Chars
(T
)) = "valuetype";
11992 ----------------------------
11993 -- Is_Variable_Size_Array --
11994 ----------------------------
11996 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
12000 pragma Assert
(Is_Array_Type
(E
));
12002 -- Check if some index is initialized with a non-constant value
12004 Idx
:= First_Index
(E
);
12005 while Present
(Idx
) loop
12006 if Nkind
(Idx
) = N_Range
then
12007 if not Is_Constant_Bound
(Low_Bound
(Idx
))
12008 or else not Is_Constant_Bound
(High_Bound
(Idx
))
12014 Idx
:= Next_Index
(Idx
);
12018 end Is_Variable_Size_Array
;
12020 -----------------------------
12021 -- Is_Variable_Size_Record --
12022 -----------------------------
12024 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
12026 Comp_Typ
: Entity_Id
;
12029 pragma Assert
(Is_Record_Type
(E
));
12031 Comp
:= First_Entity
(E
);
12032 while Present
(Comp
) loop
12033 Comp_Typ
:= Etype
(Comp
);
12035 -- Recursive call if the record type has discriminants
12037 if Is_Record_Type
(Comp_Typ
)
12038 and then Has_Discriminants
(Comp_Typ
)
12039 and then Is_Variable_Size_Record
(Comp_Typ
)
12043 elsif Is_Array_Type
(Comp_Typ
)
12044 and then Is_Variable_Size_Array
(Comp_Typ
)
12049 Next_Entity
(Comp
);
12053 end Is_Variable_Size_Record
;
12059 function Is_Variable
12061 Use_Original_Node
: Boolean := True) return Boolean
12063 Orig_Node
: Node_Id
;
12065 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
12066 -- Within a protected function, the private components of the enclosing
12067 -- protected type are constants. A function nested within a (protected)
12068 -- procedure is not itself protected. Within the body of a protected
12069 -- function the current instance of the protected type is a constant.
12071 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
12072 -- Prefixes can involve implicit dereferences, in which case we must
12073 -- test for the case of a reference of a constant access type, which can
12074 -- can never be a variable.
12076 ---------------------------
12077 -- In_Protected_Function --
12078 ---------------------------
12080 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
12085 -- E is the current instance of a type
12087 if Is_Type
(E
) then
12096 if not Is_Protected_Type
(Prot
) then
12100 S
:= Current_Scope
;
12101 while Present
(S
) and then S
/= Prot
loop
12102 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
12111 end In_Protected_Function
;
12113 ------------------------
12114 -- Is_Variable_Prefix --
12115 ------------------------
12117 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
12119 if Is_Access_Type
(Etype
(P
)) then
12120 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
12122 -- For the case of an indexed component whose prefix has a packed
12123 -- array type, the prefix has been rewritten into a type conversion.
12124 -- Determine variable-ness from the converted expression.
12126 elsif Nkind
(P
) = N_Type_Conversion
12127 and then not Comes_From_Source
(P
)
12128 and then Is_Array_Type
(Etype
(P
))
12129 and then Is_Packed
(Etype
(P
))
12131 return Is_Variable
(Expression
(P
));
12134 return Is_Variable
(P
);
12136 end Is_Variable_Prefix
;
12138 -- Start of processing for Is_Variable
12141 -- Check if we perform the test on the original node since this may be a
12142 -- test of syntactic categories which must not be disturbed by whatever
12143 -- rewriting might have occurred. For example, an aggregate, which is
12144 -- certainly NOT a variable, could be turned into a variable by
12147 if Use_Original_Node
then
12148 Orig_Node
:= Original_Node
(N
);
12153 -- Definitely OK if Assignment_OK is set. Since this is something that
12154 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12156 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
12159 -- Normally we go to the original node, but there is one exception where
12160 -- we use the rewritten node, namely when it is an explicit dereference.
12161 -- The generated code may rewrite a prefix which is an access type with
12162 -- an explicit dereference. The dereference is a variable, even though
12163 -- the original node may not be (since it could be a constant of the
12166 -- In Ada 2005 we have a further case to consider: the prefix may be a
12167 -- function call given in prefix notation. The original node appears to
12168 -- be a selected component, but we need to examine the call.
12170 elsif Nkind
(N
) = N_Explicit_Dereference
12171 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
12172 and then Present
(Etype
(Orig_Node
))
12173 and then Is_Access_Type
(Etype
(Orig_Node
))
12175 -- Note that if the prefix is an explicit dereference that does not
12176 -- come from source, we must check for a rewritten function call in
12177 -- prefixed notation before other forms of rewriting, to prevent a
12181 (Nkind
(Orig_Node
) = N_Function_Call
12182 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
12184 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
12186 -- in Ada 2012, the dereference may have been added for a type with
12187 -- a declared implicit dereference aspect.
12189 elsif Nkind
(N
) = N_Explicit_Dereference
12190 and then Present
(Etype
(Orig_Node
))
12191 and then Ada_Version
>= Ada_2012
12192 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
12196 -- A function call is never a variable
12198 elsif Nkind
(N
) = N_Function_Call
then
12201 -- All remaining checks use the original node
12203 elsif Is_Entity_Name
(Orig_Node
)
12204 and then Present
(Entity
(Orig_Node
))
12207 E
: constant Entity_Id
:= Entity
(Orig_Node
);
12208 K
: constant Entity_Kind
:= Ekind
(E
);
12211 return (K
= E_Variable
12212 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
12213 or else (K
= E_Component
12214 and then not In_Protected_Function
(E
))
12215 or else K
= E_Out_Parameter
12216 or else K
= E_In_Out_Parameter
12217 or else K
= E_Generic_In_Out_Parameter
12219 -- Current instance of type. If this is a protected type, check
12220 -- we are not within the body of one of its protected functions.
12222 or else (Is_Type
(E
)
12223 and then In_Open_Scopes
(E
)
12224 and then not In_Protected_Function
(E
))
12226 or else (Is_Incomplete_Or_Private_Type
(E
)
12227 and then In_Open_Scopes
(Full_View
(E
)));
12231 case Nkind
(Orig_Node
) is
12232 when N_Indexed_Component | N_Slice
=>
12233 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
12235 when N_Selected_Component
=>
12236 return (Is_Variable
(Selector_Name
(Orig_Node
))
12237 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
12239 (Nkind
(N
) = N_Expanded_Name
12240 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
12242 -- For an explicit dereference, the type of the prefix cannot
12243 -- be an access to constant or an access to subprogram.
12245 when N_Explicit_Dereference
=>
12247 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
12249 return Is_Access_Type
(Typ
)
12250 and then not Is_Access_Constant
(Root_Type
(Typ
))
12251 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
12254 -- The type conversion is the case where we do not deal with the
12255 -- context dependent special case of an actual parameter. Thus
12256 -- the type conversion is only considered a variable for the
12257 -- purposes of this routine if the target type is tagged. However,
12258 -- a type conversion is considered to be a variable if it does not
12259 -- come from source (this deals for example with the conversions
12260 -- of expressions to their actual subtypes).
12262 when N_Type_Conversion
=>
12263 return Is_Variable
(Expression
(Orig_Node
))
12265 (not Comes_From_Source
(Orig_Node
)
12267 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
12269 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
12271 -- GNAT allows an unchecked type conversion as a variable. This
12272 -- only affects the generation of internal expanded code, since
12273 -- calls to instantiations of Unchecked_Conversion are never
12274 -- considered variables (since they are function calls).
12276 when N_Unchecked_Type_Conversion
=>
12277 return Is_Variable
(Expression
(Orig_Node
));
12285 ---------------------------
12286 -- Is_Visibly_Controlled --
12287 ---------------------------
12289 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
12290 Root
: constant Entity_Id
:= Root_Type
(T
);
12292 return Chars
(Scope
(Root
)) = Name_Finalization
12293 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
12294 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
12295 end Is_Visibly_Controlled
;
12297 ------------------------
12298 -- Is_Volatile_Object --
12299 ------------------------
12301 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
12303 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
12304 -- If prefix is an implicit dereference, examine designated type
12306 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
12307 -- Determines if given object has volatile components
12309 ------------------------
12310 -- Is_Volatile_Prefix --
12311 ------------------------
12313 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
12314 Typ
: constant Entity_Id
:= Etype
(N
);
12317 if Is_Access_Type
(Typ
) then
12319 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
12322 return Is_Volatile
(Dtyp
)
12323 or else Has_Volatile_Components
(Dtyp
);
12327 return Object_Has_Volatile_Components
(N
);
12329 end Is_Volatile_Prefix
;
12331 ------------------------------------
12332 -- Object_Has_Volatile_Components --
12333 ------------------------------------
12335 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
12336 Typ
: constant Entity_Id
:= Etype
(N
);
12339 if Is_Volatile
(Typ
)
12340 or else Has_Volatile_Components
(Typ
)
12344 elsif Is_Entity_Name
(N
)
12345 and then (Has_Volatile_Components
(Entity
(N
))
12346 or else Is_Volatile
(Entity
(N
)))
12350 elsif Nkind
(N
) = N_Indexed_Component
12351 or else Nkind
(N
) = N_Selected_Component
12353 return Is_Volatile_Prefix
(Prefix
(N
));
12358 end Object_Has_Volatile_Components
;
12360 -- Start of processing for Is_Volatile_Object
12363 if Nkind
(N
) = N_Defining_Identifier
then
12364 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
12366 elsif Nkind
(N
) = N_Expanded_Name
then
12367 return Is_Volatile_Object
(Entity
(N
));
12369 elsif Is_Volatile
(Etype
(N
))
12370 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
12374 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
12375 and then Is_Volatile_Prefix
(Prefix
(N
))
12379 elsif Nkind
(N
) = N_Selected_Component
12380 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
12387 end Is_Volatile_Object
;
12389 ---------------------------
12390 -- Itype_Has_Declaration --
12391 ---------------------------
12393 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
12395 pragma Assert
(Is_Itype
(Id
));
12396 return Present
(Parent
(Id
))
12397 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
12398 N_Subtype_Declaration
)
12399 and then Defining_Entity
(Parent
(Id
)) = Id
;
12400 end Itype_Has_Declaration
;
12402 -------------------------
12403 -- Kill_Current_Values --
12404 -------------------------
12406 procedure Kill_Current_Values
12408 Last_Assignment_Only
: Boolean := False)
12411 if Is_Assignable
(Ent
) then
12412 Set_Last_Assignment
(Ent
, Empty
);
12415 if Is_Object
(Ent
) then
12416 if not Last_Assignment_Only
then
12418 Set_Current_Value
(Ent
, Empty
);
12420 if not Can_Never_Be_Null
(Ent
) then
12421 Set_Is_Known_Non_Null
(Ent
, False);
12424 Set_Is_Known_Null
(Ent
, False);
12426 -- Reset Is_Known_Valid unless type is always valid, or if we have
12427 -- a loop parameter (loop parameters are always valid, since their
12428 -- bounds are defined by the bounds given in the loop header).
12430 if not Is_Known_Valid
(Etype
(Ent
))
12431 and then Ekind
(Ent
) /= E_Loop_Parameter
12433 Set_Is_Known_Valid
(Ent
, False);
12437 end Kill_Current_Values
;
12439 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
12442 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
12443 -- Clear current value for entity E and all entities chained to E
12445 ------------------------------------------
12446 -- Kill_Current_Values_For_Entity_Chain --
12447 ------------------------------------------
12449 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
12453 while Present
(Ent
) loop
12454 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
12457 end Kill_Current_Values_For_Entity_Chain
;
12459 -- Start of processing for Kill_Current_Values
12462 -- Kill all saved checks, a special case of killing saved values
12464 if not Last_Assignment_Only
then
12468 -- Loop through relevant scopes, which includes the current scope and
12469 -- any parent scopes if the current scope is a block or a package.
12471 S
:= Current_Scope
;
12474 -- Clear current values of all entities in current scope
12476 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
12478 -- If scope is a package, also clear current values of all private
12479 -- entities in the scope.
12481 if Is_Package_Or_Generic_Package
(S
)
12482 or else Is_Concurrent_Type
(S
)
12484 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
12487 -- If this is a not a subprogram, deal with parents
12489 if not Is_Subprogram
(S
) then
12491 exit Scope_Loop
when S
= Standard_Standard
;
12495 end loop Scope_Loop
;
12496 end Kill_Current_Values
;
12498 --------------------------
12499 -- Kill_Size_Check_Code --
12500 --------------------------
12502 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
12504 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
12505 and then Present
(Size_Check_Code
(E
))
12507 Remove
(Size_Check_Code
(E
));
12508 Set_Size_Check_Code
(E
, Empty
);
12510 end Kill_Size_Check_Code
;
12512 --------------------------
12513 -- Known_To_Be_Assigned --
12514 --------------------------
12516 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
12517 P
: constant Node_Id
:= Parent
(N
);
12522 -- Test left side of assignment
12524 when N_Assignment_Statement
=>
12525 return N
= Name
(P
);
12527 -- Function call arguments are never lvalues
12529 when N_Function_Call
=>
12532 -- Positional parameter for procedure or accept call
12534 when N_Procedure_Call_Statement |
12543 Proc
:= Get_Subprogram_Entity
(P
);
12549 -- If we are not a list member, something is strange, so
12550 -- be conservative and return False.
12552 if not Is_List_Member
(N
) then
12556 -- We are going to find the right formal by stepping forward
12557 -- through the formals, as we step backwards in the actuals.
12559 Form
:= First_Formal
(Proc
);
12562 -- If no formal, something is weird, so be conservative
12563 -- and return False.
12570 exit when No
(Act
);
12571 Next_Formal
(Form
);
12574 return Ekind
(Form
) /= E_In_Parameter
;
12577 -- Named parameter for procedure or accept call
12579 when N_Parameter_Association
=>
12585 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
12591 -- Loop through formals to find the one that matches
12593 Form
:= First_Formal
(Proc
);
12595 -- If no matching formal, that's peculiar, some kind of
12596 -- previous error, so return False to be conservative.
12597 -- Actually this also happens in legal code in the case
12598 -- where P is a parameter association for an Extra_Formal???
12604 -- Else test for match
12606 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
12607 return Ekind
(Form
) /= E_In_Parameter
;
12610 Next_Formal
(Form
);
12614 -- Test for appearing in a conversion that itself appears
12615 -- in an lvalue context, since this should be an lvalue.
12617 when N_Type_Conversion
=>
12618 return Known_To_Be_Assigned
(P
);
12620 -- All other references are definitely not known to be modifications
12626 end Known_To_Be_Assigned
;
12628 ---------------------------
12629 -- Last_Source_Statement --
12630 ---------------------------
12632 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
12636 N
:= Last
(Statements
(HSS
));
12637 while Present
(N
) loop
12638 exit when Comes_From_Source
(N
);
12643 end Last_Source_Statement
;
12645 ----------------------------------
12646 -- Matching_Static_Array_Bounds --
12647 ----------------------------------
12649 function Matching_Static_Array_Bounds
12651 R_Typ
: Node_Id
) return Boolean
12653 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
12654 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
12666 if L_Ndims
/= R_Ndims
then
12670 -- Unconstrained types do not have static bounds
12672 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
12676 -- First treat specially the first dimension, as the lower bound and
12677 -- length of string literals are not stored like those of arrays.
12679 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
12680 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
12681 L_Len
:= String_Literal_Length
(L_Typ
);
12683 L_Index
:= First_Index
(L_Typ
);
12684 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
12686 if Is_OK_Static_Expression
(L_Low
)
12688 Is_OK_Static_Expression
(L_High
)
12690 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
12693 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
12700 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
12701 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
12702 R_Len
:= String_Literal_Length
(R_Typ
);
12704 R_Index
:= First_Index
(R_Typ
);
12705 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
12707 if Is_OK_Static_Expression
(R_Low
)
12709 Is_OK_Static_Expression
(R_High
)
12711 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
12714 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
12721 if (Is_OK_Static_Expression
(L_Low
)
12723 Is_OK_Static_Expression
(R_Low
))
12724 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
12725 and then L_Len
= R_Len
12732 -- Then treat all other dimensions
12734 for Indx
in 2 .. L_Ndims
loop
12738 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
12739 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
12741 if (Is_OK_Static_Expression
(L_Low
) and then
12742 Is_OK_Static_Expression
(L_High
) and then
12743 Is_OK_Static_Expression
(R_Low
) and then
12744 Is_OK_Static_Expression
(R_High
))
12745 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
12747 Expr_Value
(L_High
) = Expr_Value
(R_High
))
12755 -- If we fall through the loop, all indexes matched
12758 end Matching_Static_Array_Bounds
;
12760 -------------------
12761 -- May_Be_Lvalue --
12762 -------------------
12764 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
12765 P
: constant Node_Id
:= Parent
(N
);
12770 -- Test left side of assignment
12772 when N_Assignment_Statement
=>
12773 return N
= Name
(P
);
12775 -- Test prefix of component or attribute. Note that the prefix of an
12776 -- explicit or implicit dereference cannot be an l-value.
12778 when N_Attribute_Reference
=>
12779 return N
= Prefix
(P
)
12780 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
12782 -- For an expanded name, the name is an lvalue if the expanded name
12783 -- is an lvalue, but the prefix is never an lvalue, since it is just
12784 -- the scope where the name is found.
12786 when N_Expanded_Name
=>
12787 if N
= Prefix
(P
) then
12788 return May_Be_Lvalue
(P
);
12793 -- For a selected component A.B, A is certainly an lvalue if A.B is.
12794 -- B is a little interesting, if we have A.B := 3, there is some
12795 -- discussion as to whether B is an lvalue or not, we choose to say
12796 -- it is. Note however that A is not an lvalue if it is of an access
12797 -- type since this is an implicit dereference.
12799 when N_Selected_Component
=>
12801 and then Present
(Etype
(N
))
12802 and then Is_Access_Type
(Etype
(N
))
12806 return May_Be_Lvalue
(P
);
12809 -- For an indexed component or slice, the index or slice bounds is
12810 -- never an lvalue. The prefix is an lvalue if the indexed component
12811 -- or slice is an lvalue, except if it is an access type, where we
12812 -- have an implicit dereference.
12814 when N_Indexed_Component | N_Slice
=>
12816 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
12820 return May_Be_Lvalue
(P
);
12823 -- Prefix of a reference is an lvalue if the reference is an lvalue
12825 when N_Reference
=>
12826 return May_Be_Lvalue
(P
);
12828 -- Prefix of explicit dereference is never an lvalue
12830 when N_Explicit_Dereference
=>
12833 -- Positional parameter for subprogram, entry, or accept call.
12834 -- In older versions of Ada function call arguments are never
12835 -- lvalues. In Ada 2012 functions can have in-out parameters.
12837 when N_Subprogram_Call |
12838 N_Entry_Call_Statement |
12841 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
12845 -- The following mechanism is clumsy and fragile. A single flag
12846 -- set in Resolve_Actuals would be preferable ???
12854 Proc
:= Get_Subprogram_Entity
(P
);
12860 -- If we are not a list member, something is strange, so be
12861 -- conservative and return True.
12863 if not Is_List_Member
(N
) then
12867 -- We are going to find the right formal by stepping forward
12868 -- through the formals, as we step backwards in the actuals.
12870 Form
:= First_Formal
(Proc
);
12873 -- If no formal, something is weird, so be conservative and
12881 exit when No
(Act
);
12882 Next_Formal
(Form
);
12885 return Ekind
(Form
) /= E_In_Parameter
;
12888 -- Named parameter for procedure or accept call
12890 when N_Parameter_Association
=>
12896 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
12902 -- Loop through formals to find the one that matches
12904 Form
:= First_Formal
(Proc
);
12906 -- If no matching formal, that's peculiar, some kind of
12907 -- previous error, so return True to be conservative.
12908 -- Actually happens with legal code for an unresolved call
12909 -- where we may get the wrong homonym???
12915 -- Else test for match
12917 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
12918 return Ekind
(Form
) /= E_In_Parameter
;
12921 Next_Formal
(Form
);
12925 -- Test for appearing in a conversion that itself appears in an
12926 -- lvalue context, since this should be an lvalue.
12928 when N_Type_Conversion
=>
12929 return May_Be_Lvalue
(P
);
12931 -- Test for appearance in object renaming declaration
12933 when N_Object_Renaming_Declaration
=>
12936 -- All other references are definitely not lvalues
12944 -----------------------
12945 -- Mark_Coextensions --
12946 -----------------------
12948 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
12949 Is_Dynamic
: Boolean;
12950 -- Indicates whether the context causes nested coextensions to be
12951 -- dynamic or static
12953 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
12954 -- Recognize an allocator node and label it as a dynamic coextension
12956 --------------------
12957 -- Mark_Allocator --
12958 --------------------
12960 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
12962 if Nkind
(N
) = N_Allocator
then
12964 Set_Is_Dynamic_Coextension
(N
);
12966 -- If the allocator expression is potentially dynamic, it may
12967 -- be expanded out of order and require dynamic allocation
12968 -- anyway, so we treat the coextension itself as dynamic.
12969 -- Potential optimization ???
12971 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
12972 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
12974 Set_Is_Dynamic_Coextension
(N
);
12976 Set_Is_Static_Coextension
(N
);
12981 end Mark_Allocator
;
12983 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
12985 -- Start of processing Mark_Coextensions
12988 case Nkind
(Context_Nod
) is
12990 -- Comment here ???
12992 when N_Assignment_Statement
=>
12993 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
12995 -- An allocator that is a component of a returned aggregate
12996 -- must be dynamic.
12998 when N_Simple_Return_Statement
=>
13000 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
13003 Nkind
(Expr
) = N_Allocator
13005 (Nkind
(Expr
) = N_Qualified_Expression
13006 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
13009 -- An alloctor within an object declaration in an extended return
13010 -- statement is of necessity dynamic.
13012 when N_Object_Declaration
=>
13013 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
13015 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
13017 -- This routine should not be called for constructs which may not
13018 -- contain coextensions.
13021 raise Program_Error
;
13024 Mark_Allocators
(Root_Nod
);
13025 end Mark_Coextensions
;
13031 function Must_Inline
(Subp
: Entity_Id
) return Boolean is
13034 (Optimization_Level
= 0
13036 -- AAMP and VM targets have no support for inlining in the backend.
13037 -- Hence we do as much inlining as possible in the front end.
13039 or else AAMP_On_Target
13040 or else VM_Target
/= No_VM
)
13041 and then Has_Pragma_Inline
(Subp
)
13042 and then (Has_Pragma_Inline_Always
(Subp
) or else Front_End_Inlining
);
13045 ----------------------
13046 -- Needs_One_Actual --
13047 ----------------------
13049 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
13050 Formal
: Entity_Id
;
13053 -- Ada 2005 or later, and formals present
13055 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
13056 Formal
:= Next_Formal
(First_Formal
(E
));
13057 while Present
(Formal
) loop
13058 if No
(Default_Value
(Formal
)) then
13062 Next_Formal
(Formal
);
13067 -- Ada 83/95 or no formals
13072 end Needs_One_Actual
;
13074 ------------------------
13075 -- New_Copy_List_Tree --
13076 ------------------------
13078 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
13083 if List
= No_List
then
13090 while Present
(E
) loop
13091 Append
(New_Copy_Tree
(E
), NL
);
13097 end New_Copy_List_Tree
;
13099 -------------------
13100 -- New_Copy_Tree --
13101 -------------------
13103 use Atree
.Unchecked_Access
;
13104 use Atree_Private_Part
;
13106 -- Our approach here requires a two pass traversal of the tree. The
13107 -- first pass visits all nodes that eventually will be copied looking
13108 -- for defining Itypes. If any defining Itypes are found, then they are
13109 -- copied, and an entry is added to the replacement map. In the second
13110 -- phase, the tree is copied, using the replacement map to replace any
13111 -- Itype references within the copied tree.
13113 -- The following hash tables are used if the Map supplied has more
13114 -- than hash threshold entries to speed up access to the map. If
13115 -- there are fewer entries, then the map is searched sequentially
13116 -- (because setting up a hash table for only a few entries takes
13117 -- more time than it saves.
13119 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
13120 -- Hash function used for hash operations
13122 -------------------
13123 -- New_Copy_Hash --
13124 -------------------
13126 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
13128 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
13135 -- The hash table NCT_Assoc associates old entities in the table
13136 -- with their corresponding new entities (i.e. the pairs of entries
13137 -- presented in the original Map argument are Key-Element pairs).
13139 package NCT_Assoc
is new Simple_HTable
(
13140 Header_Num
=> NCT_Header_Num
,
13141 Element
=> Entity_Id
,
13142 No_Element
=> Empty
,
13144 Hash
=> New_Copy_Hash
,
13145 Equal
=> Types
."=");
13147 ---------------------
13148 -- NCT_Itype_Assoc --
13149 ---------------------
13151 -- The hash table NCT_Itype_Assoc contains entries only for those
13152 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13153 -- The key is the associated node, and the element is the new node
13154 -- itself (NOT the associated node for the new node).
13156 package NCT_Itype_Assoc
is new Simple_HTable
(
13157 Header_Num
=> NCT_Header_Num
,
13158 Element
=> Entity_Id
,
13159 No_Element
=> Empty
,
13161 Hash
=> New_Copy_Hash
,
13162 Equal
=> Types
."=");
13164 -- Start of processing for New_Copy_Tree function
13166 function New_Copy_Tree
13168 Map
: Elist_Id
:= No_Elist
;
13169 New_Sloc
: Source_Ptr
:= No_Location
;
13170 New_Scope
: Entity_Id
:= Empty
) return Node_Id
13172 Actual_Map
: Elist_Id
:= Map
;
13173 -- This is the actual map for the copy. It is initialized with the
13174 -- given elements, and then enlarged as required for Itypes that are
13175 -- copied during the first phase of the copy operation. The visit
13176 -- procedures add elements to this map as Itypes are encountered.
13177 -- The reason we cannot use Map directly, is that it may well be
13178 -- (and normally is) initialized to No_Elist, and if we have mapped
13179 -- entities, we have to reset it to point to a real Elist.
13181 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
13182 -- Called during second phase to map entities into their corresponding
13183 -- copies using Actual_Map. If the argument is not an entity, or is not
13184 -- in Actual_Map, then it is returned unchanged.
13186 procedure Build_NCT_Hash_Tables
;
13187 -- Builds hash tables (number of elements >= threshold value)
13189 function Copy_Elist_With_Replacement
13190 (Old_Elist
: Elist_Id
) return Elist_Id
;
13191 -- Called during second phase to copy element list doing replacements
13193 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
13194 -- Called during the second phase to process a copied Itype. The actual
13195 -- copy happened during the first phase (so that we could make the entry
13196 -- in the mapping), but we still have to deal with the descendents of
13197 -- the copied Itype and copy them where necessary.
13199 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
13200 -- Called during second phase to copy list doing replacements
13202 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
13203 -- Called during second phase to copy node doing replacements
13205 procedure Visit_Elist
(E
: Elist_Id
);
13206 -- Called during first phase to visit all elements of an Elist
13208 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
13209 -- Visit a single field, recursing to call Visit_Node or Visit_List
13210 -- if the field is a syntactic descendent of the current node (i.e.
13211 -- its parent is Node N).
13213 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
13214 -- Called during first phase to visit subsidiary fields of a defining
13215 -- Itype, and also create a copy and make an entry in the replacement
13216 -- map for the new copy.
13218 procedure Visit_List
(L
: List_Id
);
13219 -- Called during first phase to visit all elements of a List
13221 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
13222 -- Called during first phase to visit a node and all its subtrees
13228 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
13233 if not Has_Extension
(N
) or else No
(Actual_Map
) then
13236 elsif NCT_Hash_Tables_Used
then
13237 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
13239 if Present
(Ent
) then
13245 -- No hash table used, do serial search
13248 E
:= First_Elmt
(Actual_Map
);
13249 while Present
(E
) loop
13250 if Node
(E
) = N
then
13251 return Node
(Next_Elmt
(E
));
13253 E
:= Next_Elmt
(Next_Elmt
(E
));
13261 ---------------------------
13262 -- Build_NCT_Hash_Tables --
13263 ---------------------------
13265 procedure Build_NCT_Hash_Tables
is
13269 if NCT_Hash_Table_Setup
then
13271 NCT_Itype_Assoc
.Reset
;
13274 Elmt
:= First_Elmt
(Actual_Map
);
13275 while Present
(Elmt
) loop
13276 Ent
:= Node
(Elmt
);
13278 -- Get new entity, and associate old and new
13281 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
13283 if Is_Type
(Ent
) then
13285 Anode
: constant Entity_Id
:=
13286 Associated_Node_For_Itype
(Ent
);
13289 if Present
(Anode
) then
13291 -- Enter a link between the associated node of the
13292 -- old Itype and the new Itype, for updating later
13293 -- when node is copied.
13295 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
13303 NCT_Hash_Tables_Used
:= True;
13304 NCT_Hash_Table_Setup
:= True;
13305 end Build_NCT_Hash_Tables
;
13307 ---------------------------------
13308 -- Copy_Elist_With_Replacement --
13309 ---------------------------------
13311 function Copy_Elist_With_Replacement
13312 (Old_Elist
: Elist_Id
) return Elist_Id
13315 New_Elist
: Elist_Id
;
13318 if No
(Old_Elist
) then
13322 New_Elist
:= New_Elmt_List
;
13324 M
:= First_Elmt
(Old_Elist
);
13325 while Present
(M
) loop
13326 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
13332 end Copy_Elist_With_Replacement
;
13334 ---------------------------------
13335 -- Copy_Itype_With_Replacement --
13336 ---------------------------------
13338 -- This routine exactly parallels its phase one analog Visit_Itype,
13340 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
13342 -- Translate Next_Entity, Scope and Etype fields, in case they
13343 -- reference entities that have been mapped into copies.
13345 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
13346 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
13348 if Present
(New_Scope
) then
13349 Set_Scope
(New_Itype
, New_Scope
);
13351 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
13354 -- Copy referenced fields
13356 if Is_Discrete_Type
(New_Itype
) then
13357 Set_Scalar_Range
(New_Itype
,
13358 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
13360 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
13361 Set_Discriminant_Constraint
(New_Itype
,
13362 Copy_Elist_With_Replacement
13363 (Discriminant_Constraint
(New_Itype
)));
13365 elsif Is_Array_Type
(New_Itype
) then
13366 if Present
(First_Index
(New_Itype
)) then
13367 Set_First_Index
(New_Itype
,
13368 First
(Copy_List_With_Replacement
13369 (List_Containing
(First_Index
(New_Itype
)))));
13372 if Is_Packed
(New_Itype
) then
13373 Set_Packed_Array_Impl_Type
(New_Itype
,
13374 Copy_Node_With_Replacement
13375 (Packed_Array_Impl_Type
(New_Itype
)));
13378 end Copy_Itype_With_Replacement
;
13380 --------------------------------
13381 -- Copy_List_With_Replacement --
13382 --------------------------------
13384 function Copy_List_With_Replacement
13385 (Old_List
: List_Id
) return List_Id
13387 New_List
: List_Id
;
13391 if Old_List
= No_List
then
13395 New_List
:= Empty_List
;
13397 E
:= First
(Old_List
);
13398 while Present
(E
) loop
13399 Append
(Copy_Node_With_Replacement
(E
), New_List
);
13405 end Copy_List_With_Replacement
;
13407 --------------------------------
13408 -- Copy_Node_With_Replacement --
13409 --------------------------------
13411 function Copy_Node_With_Replacement
13412 (Old_Node
: Node_Id
) return Node_Id
13414 New_Node
: Node_Id
;
13416 procedure Adjust_Named_Associations
13417 (Old_Node
: Node_Id
;
13418 New_Node
: Node_Id
);
13419 -- If a call node has named associations, these are chained through
13420 -- the First_Named_Actual, Next_Named_Actual links. These must be
13421 -- propagated separately to the new parameter list, because these
13422 -- are not syntactic fields.
13424 function Copy_Field_With_Replacement
13425 (Field
: Union_Id
) return Union_Id
;
13426 -- Given Field, which is a field of Old_Node, return a copy of it
13427 -- if it is a syntactic field (i.e. its parent is Node), setting
13428 -- the parent of the copy to poit to New_Node. Otherwise returns
13429 -- the field (possibly mapped if it is an entity).
13431 -------------------------------
13432 -- Adjust_Named_Associations --
13433 -------------------------------
13435 procedure Adjust_Named_Associations
13436 (Old_Node
: Node_Id
;
13437 New_Node
: Node_Id
)
13442 Old_Next
: Node_Id
;
13443 New_Next
: Node_Id
;
13446 Old_E
:= First
(Parameter_Associations
(Old_Node
));
13447 New_E
:= First
(Parameter_Associations
(New_Node
));
13448 while Present
(Old_E
) loop
13449 if Nkind
(Old_E
) = N_Parameter_Association
13450 and then Present
(Next_Named_Actual
(Old_E
))
13452 if First_Named_Actual
(Old_Node
)
13453 = Explicit_Actual_Parameter
(Old_E
)
13455 Set_First_Named_Actual
13456 (New_Node
, Explicit_Actual_Parameter
(New_E
));
13459 -- Now scan parameter list from the beginning,to locate
13460 -- next named actual, which can be out of order.
13462 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
13463 New_Next
:= First
(Parameter_Associations
(New_Node
));
13465 while Nkind
(Old_Next
) /= N_Parameter_Association
13466 or else Explicit_Actual_Parameter
(Old_Next
)
13467 /= Next_Named_Actual
(Old_E
)
13473 Set_Next_Named_Actual
13474 (New_E
, Explicit_Actual_Parameter
(New_Next
));
13480 end Adjust_Named_Associations
;
13482 ---------------------------------
13483 -- Copy_Field_With_Replacement --
13484 ---------------------------------
13486 function Copy_Field_With_Replacement
13487 (Field
: Union_Id
) return Union_Id
13490 if Field
= Union_Id
(Empty
) then
13493 elsif Field
in Node_Range
then
13495 Old_N
: constant Node_Id
:= Node_Id
(Field
);
13499 -- If syntactic field, as indicated by the parent pointer
13500 -- being set, then copy the referenced node recursively.
13502 if Parent
(Old_N
) = Old_Node
then
13503 New_N
:= Copy_Node_With_Replacement
(Old_N
);
13505 if New_N
/= Old_N
then
13506 Set_Parent
(New_N
, New_Node
);
13509 -- For semantic fields, update possible entity reference
13510 -- from the replacement map.
13513 New_N
:= Assoc
(Old_N
);
13516 return Union_Id
(New_N
);
13519 elsif Field
in List_Range
then
13521 Old_L
: constant List_Id
:= List_Id
(Field
);
13525 -- If syntactic field, as indicated by the parent pointer,
13526 -- then recursively copy the entire referenced list.
13528 if Parent
(Old_L
) = Old_Node
then
13529 New_L
:= Copy_List_With_Replacement
(Old_L
);
13530 Set_Parent
(New_L
, New_Node
);
13532 -- For semantic list, just returned unchanged
13538 return Union_Id
(New_L
);
13541 -- Anything other than a list or a node is returned unchanged
13546 end Copy_Field_With_Replacement
;
13548 -- Start of processing for Copy_Node_With_Replacement
13551 if Old_Node
<= Empty_Or_Error
then
13554 elsif Has_Extension
(Old_Node
) then
13555 return Assoc
(Old_Node
);
13558 New_Node
:= New_Copy
(Old_Node
);
13560 -- If the node we are copying is the associated node of a
13561 -- previously copied Itype, then adjust the associated node
13562 -- of the copy of that Itype accordingly.
13564 if Present
(Actual_Map
) then
13570 -- Case of hash table used
13572 if NCT_Hash_Tables_Used
then
13573 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
13575 if Present
(Ent
) then
13576 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
13579 -- Case of no hash table used
13582 E
:= First_Elmt
(Actual_Map
);
13583 while Present
(E
) loop
13584 if Is_Itype
(Node
(E
))
13586 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
13588 Set_Associated_Node_For_Itype
13589 (Node
(Next_Elmt
(E
)), New_Node
);
13592 E
:= Next_Elmt
(Next_Elmt
(E
));
13598 -- Recursively copy descendents
13601 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
13603 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
13605 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
13607 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
13609 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
13611 -- Adjust Sloc of new node if necessary
13613 if New_Sloc
/= No_Location
then
13614 Set_Sloc
(New_Node
, New_Sloc
);
13616 -- If we adjust the Sloc, then we are essentially making
13617 -- a completely new node, so the Comes_From_Source flag
13618 -- should be reset to the proper default value.
13620 Nodes
.Table
(New_Node
).Comes_From_Source
:=
13621 Default_Node
.Comes_From_Source
;
13624 -- If the node is call and has named associations,
13625 -- set the corresponding links in the copy.
13627 if (Nkind
(Old_Node
) = N_Function_Call
13628 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
13630 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
13631 and then Present
(First_Named_Actual
(Old_Node
))
13633 Adjust_Named_Associations
(Old_Node
, New_Node
);
13636 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
13637 -- The replacement mechanism applies to entities, and is not used
13638 -- here. Eventually we may need a more general graph-copying
13639 -- routine. For now, do a sequential search to find desired node.
13641 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
13642 and then Present
(First_Real_Statement
(Old_Node
))
13645 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
13649 N1
:= First
(Statements
(Old_Node
));
13650 N2
:= First
(Statements
(New_Node
));
13652 while N1
/= Old_F
loop
13657 Set_First_Real_Statement
(New_Node
, N2
);
13662 -- All done, return copied node
13665 end Copy_Node_With_Replacement
;
13671 procedure Visit_Elist
(E
: Elist_Id
) is
13674 if Present
(E
) then
13675 Elmt
:= First_Elmt
(E
);
13677 while Elmt
/= No_Elmt
loop
13678 Visit_Node
(Node
(Elmt
));
13688 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
13690 if F
= Union_Id
(Empty
) then
13693 elsif F
in Node_Range
then
13695 -- Copy node if it is syntactic, i.e. its parent pointer is
13696 -- set to point to the field that referenced it (certain
13697 -- Itypes will also meet this criterion, which is fine, since
13698 -- these are clearly Itypes that do need to be copied, since
13699 -- we are copying their parent.)
13701 if Parent
(Node_Id
(F
)) = N
then
13702 Visit_Node
(Node_Id
(F
));
13705 -- Another case, if we are pointing to an Itype, then we want
13706 -- to copy it if its associated node is somewhere in the tree
13709 -- Note: the exclusion of self-referential copies is just an
13710 -- optimization, since the search of the already copied list
13711 -- would catch it, but it is a common case (Etype pointing
13712 -- to itself for an Itype that is a base type).
13714 elsif Has_Extension
(Node_Id
(F
))
13715 and then Is_Itype
(Entity_Id
(F
))
13716 and then Node_Id
(F
) /= N
13722 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
13723 while Present
(P
) loop
13725 Visit_Node
(Node_Id
(F
));
13732 -- An Itype whose parent is not being copied definitely
13733 -- should NOT be copied, since it does not belong in any
13734 -- sense to the copied subtree.
13740 elsif F
in List_Range
and then Parent
(List_Id
(F
)) = N
then
13741 Visit_List
(List_Id
(F
));
13750 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
13751 New_Itype
: Entity_Id
;
13756 -- Itypes that describe the designated type of access to subprograms
13757 -- have the structure of subprogram declarations, with signatures,
13758 -- etc. Either we duplicate the signatures completely, or choose to
13759 -- share such itypes, which is fine because their elaboration will
13760 -- have no side effects.
13762 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
13766 New_Itype
:= New_Copy
(Old_Itype
);
13768 -- The new Itype has all the attributes of the old one, and
13769 -- we just copy the contents of the entity. However, the back-end
13770 -- needs different names for debugging purposes, so we create a
13771 -- new internal name for it in all cases.
13773 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
13775 -- If our associated node is an entity that has already been copied,
13776 -- then set the associated node of the copy to point to the right
13777 -- copy. If we have copied an Itype that is itself the associated
13778 -- node of some previously copied Itype, then we set the right
13779 -- pointer in the other direction.
13781 if Present
(Actual_Map
) then
13783 -- Case of hash tables used
13785 if NCT_Hash_Tables_Used
then
13787 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
13789 if Present
(Ent
) then
13790 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
13793 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
13794 if Present
(Ent
) then
13795 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
13797 -- If the hash table has no association for this Itype and
13798 -- its associated node, enter one now.
13801 NCT_Itype_Assoc
.Set
13802 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
13805 -- Case of hash tables not used
13808 E
:= First_Elmt
(Actual_Map
);
13809 while Present
(E
) loop
13810 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
13811 Set_Associated_Node_For_Itype
13812 (New_Itype
, Node
(Next_Elmt
(E
)));
13815 if Is_Type
(Node
(E
))
13816 and then Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
13818 Set_Associated_Node_For_Itype
13819 (Node
(Next_Elmt
(E
)), New_Itype
);
13822 E
:= Next_Elmt
(Next_Elmt
(E
));
13827 if Present
(Freeze_Node
(New_Itype
)) then
13828 Set_Is_Frozen
(New_Itype
, False);
13829 Set_Freeze_Node
(New_Itype
, Empty
);
13832 -- Add new association to map
13834 if No
(Actual_Map
) then
13835 Actual_Map
:= New_Elmt_List
;
13838 Append_Elmt
(Old_Itype
, Actual_Map
);
13839 Append_Elmt
(New_Itype
, Actual_Map
);
13841 if NCT_Hash_Tables_Used
then
13842 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
13845 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13847 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13848 Build_NCT_Hash_Tables
;
13852 -- If a record subtype is simply copied, the entity list will be
13853 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
13855 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
13856 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
13859 -- Visit descendents that eventually get copied
13861 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
13863 if Is_Discrete_Type
(Old_Itype
) then
13864 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
13866 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
13867 -- ??? This should involve call to Visit_Field
13868 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
13870 elsif Is_Array_Type
(Old_Itype
) then
13871 if Present
(First_Index
(Old_Itype
)) then
13872 Visit_Field
(Union_Id
(List_Containing
13873 (First_Index
(Old_Itype
))),
13877 if Is_Packed
(Old_Itype
) then
13878 Visit_Field
(Union_Id
(Packed_Array_Impl_Type
(Old_Itype
)),
13888 procedure Visit_List
(L
: List_Id
) is
13891 if L
/= No_List
then
13894 while Present
(N
) loop
13905 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
13907 -- Start of processing for Visit_Node
13910 -- Handle case of an Itype, which must be copied
13912 if Has_Extension
(N
) and then Is_Itype
(N
) then
13914 -- Nothing to do if already in the list. This can happen with an
13915 -- Itype entity that appears more than once in the tree.
13916 -- Note that we do not want to visit descendents in this case.
13918 -- Test for already in list when hash table is used
13920 if NCT_Hash_Tables_Used
then
13921 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
13925 -- Test for already in list when hash table not used
13931 if Present
(Actual_Map
) then
13932 E
:= First_Elmt
(Actual_Map
);
13933 while Present
(E
) loop
13934 if Node
(E
) = N
then
13937 E
:= Next_Elmt
(Next_Elmt
(E
));
13947 -- Visit descendents
13949 Visit_Field
(Field1
(N
), N
);
13950 Visit_Field
(Field2
(N
), N
);
13951 Visit_Field
(Field3
(N
), N
);
13952 Visit_Field
(Field4
(N
), N
);
13953 Visit_Field
(Field5
(N
), N
);
13956 -- Start of processing for New_Copy_Tree
13961 -- See if we should use hash table
13963 if No
(Actual_Map
) then
13964 NCT_Hash_Tables_Used
:= False;
13971 NCT_Table_Entries
:= 0;
13973 Elmt
:= First_Elmt
(Actual_Map
);
13974 while Present
(Elmt
) loop
13975 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13980 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13981 Build_NCT_Hash_Tables
;
13983 NCT_Hash_Tables_Used
:= False;
13988 -- Hash table set up if required, now start phase one by visiting
13989 -- top node (we will recursively visit the descendents).
13991 Visit_Node
(Source
);
13993 -- Now the second phase of the copy can start. First we process
13994 -- all the mapped entities, copying their descendents.
13996 if Present
(Actual_Map
) then
13999 New_Itype
: Entity_Id
;
14001 Elmt
:= First_Elmt
(Actual_Map
);
14002 while Present
(Elmt
) loop
14004 New_Itype
:= Node
(Elmt
);
14005 Copy_Itype_With_Replacement
(New_Itype
);
14011 -- Now we can copy the actual tree
14013 return Copy_Node_With_Replacement
(Source
);
14016 -------------------------
14017 -- New_External_Entity --
14018 -------------------------
14020 function New_External_Entity
14021 (Kind
: Entity_Kind
;
14022 Scope_Id
: Entity_Id
;
14023 Sloc_Value
: Source_Ptr
;
14024 Related_Id
: Entity_Id
;
14025 Suffix
: Character;
14026 Suffix_Index
: Nat
:= 0;
14027 Prefix
: Character := ' ') return Entity_Id
14029 N
: constant Entity_Id
:=
14030 Make_Defining_Identifier
(Sloc_Value
,
14032 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
14035 Set_Ekind
(N
, Kind
);
14036 Set_Is_Internal
(N
, True);
14037 Append_Entity
(N
, Scope_Id
);
14038 Set_Public_Status
(N
);
14040 if Kind
in Type_Kind
then
14041 Init_Size_Align
(N
);
14045 end New_External_Entity
;
14047 -------------------------
14048 -- New_Internal_Entity --
14049 -------------------------
14051 function New_Internal_Entity
14052 (Kind
: Entity_Kind
;
14053 Scope_Id
: Entity_Id
;
14054 Sloc_Value
: Source_Ptr
;
14055 Id_Char
: Character) return Entity_Id
14057 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
14060 Set_Ekind
(N
, Kind
);
14061 Set_Is_Internal
(N
, True);
14062 Append_Entity
(N
, Scope_Id
);
14064 if Kind
in Type_Kind
then
14065 Init_Size_Align
(N
);
14069 end New_Internal_Entity
;
14075 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
14079 -- If we are pointing at a positional parameter, it is a member of a
14080 -- node list (the list of parameters), and the next parameter is the
14081 -- next node on the list, unless we hit a parameter association, then
14082 -- we shift to using the chain whose head is the First_Named_Actual in
14083 -- the parent, and then is threaded using the Next_Named_Actual of the
14084 -- Parameter_Association. All this fiddling is because the original node
14085 -- list is in the textual call order, and what we need is the
14086 -- declaration order.
14088 if Is_List_Member
(Actual_Id
) then
14089 N
:= Next
(Actual_Id
);
14091 if Nkind
(N
) = N_Parameter_Association
then
14092 return First_Named_Actual
(Parent
(Actual_Id
));
14098 return Next_Named_Actual
(Parent
(Actual_Id
));
14102 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
14104 Actual_Id
:= Next_Actual
(Actual_Id
);
14107 -----------------------
14108 -- Normalize_Actuals --
14109 -----------------------
14111 -- Chain actuals according to formals of subprogram. If there are no named
14112 -- associations, the chain is simply the list of Parameter Associations,
14113 -- since the order is the same as the declaration order. If there are named
14114 -- associations, then the First_Named_Actual field in the N_Function_Call
14115 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14116 -- node for the parameter that comes first in declaration order. The
14117 -- remaining named parameters are then chained in declaration order using
14118 -- Next_Named_Actual.
14120 -- This routine also verifies that the number of actuals is compatible with
14121 -- the number and default values of formals, but performs no type checking
14122 -- (type checking is done by the caller).
14124 -- If the matching succeeds, Success is set to True and the caller proceeds
14125 -- with type-checking. If the match is unsuccessful, then Success is set to
14126 -- False, and the caller attempts a different interpretation, if there is
14129 -- If the flag Report is on, the call is not overloaded, and a failure to
14130 -- match can be reported here, rather than in the caller.
14132 procedure Normalize_Actuals
14136 Success
: out Boolean)
14138 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
14139 Actual
: Node_Id
:= Empty
;
14140 Formal
: Entity_Id
;
14141 Last
: Node_Id
:= Empty
;
14142 First_Named
: Node_Id
:= Empty
;
14145 Formals_To_Match
: Integer := 0;
14146 Actuals_To_Match
: Integer := 0;
14148 procedure Chain
(A
: Node_Id
);
14149 -- Add named actual at the proper place in the list, using the
14150 -- Next_Named_Actual link.
14152 function Reporting
return Boolean;
14153 -- Determines if an error is to be reported. To report an error, we
14154 -- need Report to be True, and also we do not report errors caused
14155 -- by calls to init procs that occur within other init procs. Such
14156 -- errors must always be cascaded errors, since if all the types are
14157 -- declared correctly, the compiler will certainly build decent calls.
14163 procedure Chain
(A
: Node_Id
) is
14167 -- Call node points to first actual in list
14169 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
14172 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
14176 Set_Next_Named_Actual
(Last
, Empty
);
14183 function Reporting
return Boolean is
14188 elsif not Within_Init_Proc
then
14191 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
14199 -- Start of processing for Normalize_Actuals
14202 if Is_Access_Type
(S
) then
14204 -- The name in the call is a function call that returns an access
14205 -- to subprogram. The designated type has the list of formals.
14207 Formal
:= First_Formal
(Designated_Type
(S
));
14209 Formal
:= First_Formal
(S
);
14212 while Present
(Formal
) loop
14213 Formals_To_Match
:= Formals_To_Match
+ 1;
14214 Next_Formal
(Formal
);
14217 -- Find if there is a named association, and verify that no positional
14218 -- associations appear after named ones.
14220 if Present
(Actuals
) then
14221 Actual
:= First
(Actuals
);
14224 while Present
(Actual
)
14225 and then Nkind
(Actual
) /= N_Parameter_Association
14227 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14231 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
14233 -- Most common case: positional notation, no defaults
14238 elsif Actuals_To_Match
> Formals_To_Match
then
14240 -- Too many actuals: will not work
14243 if Is_Entity_Name
(Name
(N
)) then
14244 Error_Msg_N
("too many arguments in call to&", Name
(N
));
14246 Error_Msg_N
("too many arguments in call", N
);
14254 First_Named
:= Actual
;
14256 while Present
(Actual
) loop
14257 if Nkind
(Actual
) /= N_Parameter_Association
then
14259 ("positional parameters not allowed after named ones", Actual
);
14264 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14270 if Present
(Actuals
) then
14271 Actual
:= First
(Actuals
);
14274 Formal
:= First_Formal
(S
);
14275 while Present
(Formal
) loop
14277 -- Match the formals in order. If the corresponding actual is
14278 -- positional, nothing to do. Else scan the list of named actuals
14279 -- to find the one with the right name.
14281 if Present
(Actual
)
14282 and then Nkind
(Actual
) /= N_Parameter_Association
14285 Actuals_To_Match
:= Actuals_To_Match
- 1;
14286 Formals_To_Match
:= Formals_To_Match
- 1;
14289 -- For named parameters, search the list of actuals to find
14290 -- one that matches the next formal name.
14292 Actual
:= First_Named
;
14294 while Present
(Actual
) loop
14295 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
14298 Actuals_To_Match
:= Actuals_To_Match
- 1;
14299 Formals_To_Match
:= Formals_To_Match
- 1;
14307 if Ekind
(Formal
) /= E_In_Parameter
14308 or else No
(Default_Value
(Formal
))
14311 if (Comes_From_Source
(S
)
14312 or else Sloc
(S
) = Standard_Location
)
14313 and then Is_Overloadable
(S
)
14317 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
14319 N_Parameter_Association
)
14320 and then Ekind
(S
) /= E_Function
14322 Set_Etype
(N
, Etype
(S
));
14325 Error_Msg_Name_1
:= Chars
(S
);
14326 Error_Msg_Sloc
:= Sloc
(S
);
14328 ("missing argument for parameter & " &
14329 "in call to % declared #", N
, Formal
);
14332 elsif Is_Overloadable
(S
) then
14333 Error_Msg_Name_1
:= Chars
(S
);
14335 -- Point to type derivation that generated the
14338 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
14341 ("missing argument for parameter & " &
14342 "in call to % (inherited) #", N
, Formal
);
14346 ("missing argument for parameter &", N
, Formal
);
14354 Formals_To_Match
:= Formals_To_Match
- 1;
14359 Next_Formal
(Formal
);
14362 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
14369 -- Find some superfluous named actual that did not get
14370 -- attached to the list of associations.
14372 Actual
:= First
(Actuals
);
14373 while Present
(Actual
) loop
14374 if Nkind
(Actual
) = N_Parameter_Association
14375 and then Actual
/= Last
14376 and then No
(Next_Named_Actual
(Actual
))
14378 Error_Msg_N
("unmatched actual & in call",
14379 Selector_Name
(Actual
));
14390 end Normalize_Actuals
;
14392 --------------------------------
14393 -- Note_Possible_Modification --
14394 --------------------------------
14396 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
14397 Modification_Comes_From_Source
: constant Boolean :=
14398 Comes_From_Source
(Parent
(N
));
14404 -- Loop to find referenced entity, if there is one
14410 if Is_Entity_Name
(Exp
) then
14411 Ent
:= Entity
(Exp
);
14413 -- If the entity is missing, it is an undeclared identifier,
14414 -- and there is nothing to annotate.
14420 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
14422 P
: constant Node_Id
:= Prefix
(Exp
);
14425 -- In formal verification mode, keep track of all reads and
14426 -- writes through explicit dereferences.
14428 if GNATprove_Mode
then
14429 SPARK_Specific
.Generate_Dereference
(N
, 'm');
14432 if Nkind
(P
) = N_Selected_Component
14433 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
14435 -- Case of a reference to an entry formal
14437 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
14439 elsif Nkind
(P
) = N_Identifier
14440 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
14441 and then Present
(Expression
(Parent
(Entity
(P
))))
14442 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
14445 -- Case of a reference to a value on which side effects have
14448 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
14456 elsif Nkind_In
(Exp
, N_Type_Conversion
,
14457 N_Unchecked_Type_Conversion
)
14459 Exp
:= Expression
(Exp
);
14462 elsif Nkind_In
(Exp
, N_Slice
,
14463 N_Indexed_Component
,
14464 N_Selected_Component
)
14466 -- Special check, if the prefix is an access type, then return
14467 -- since we are modifying the thing pointed to, not the prefix.
14468 -- When we are expanding, most usually the prefix is replaced
14469 -- by an explicit dereference, and this test is not needed, but
14470 -- in some cases (notably -gnatc mode and generics) when we do
14471 -- not do full expansion, we need this special test.
14473 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
14476 -- Otherwise go to prefix and keep going
14479 Exp
:= Prefix
(Exp
);
14483 -- All other cases, not a modification
14489 -- Now look for entity being referenced
14491 if Present
(Ent
) then
14492 if Is_Object
(Ent
) then
14493 if Comes_From_Source
(Exp
)
14494 or else Modification_Comes_From_Source
14496 -- Give warning if pragma unmodified given and we are
14497 -- sure this is a modification.
14499 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
14501 ("??pragma Unmodified given for &!", N
, Ent
);
14504 Set_Never_Set_In_Source
(Ent
, False);
14507 Set_Is_True_Constant
(Ent
, False);
14508 Set_Current_Value
(Ent
, Empty
);
14509 Set_Is_Known_Null
(Ent
, False);
14511 if not Can_Never_Be_Null
(Ent
) then
14512 Set_Is_Known_Non_Null
(Ent
, False);
14515 -- Follow renaming chain
14517 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
14518 and then Present
(Renamed_Object
(Ent
))
14520 Exp
:= Renamed_Object
(Ent
);
14522 -- If the entity is the loop variable in an iteration over
14523 -- a container, retrieve container expression to indicate
14524 -- possible modificastion.
14526 if Present
(Related_Expression
(Ent
))
14527 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
14528 N_Iterator_Specification
14530 Exp
:= Original_Node
(Related_Expression
(Ent
));
14535 -- The expression may be the renaming of a subcomponent of an
14536 -- array or container. The assignment to the subcomponent is
14537 -- a modification of the container.
14539 elsif Comes_From_Source
(Original_Node
(Exp
))
14540 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
14541 N_Indexed_Component
)
14543 Exp
:= Prefix
(Original_Node
(Exp
));
14547 -- Generate a reference only if the assignment comes from
14548 -- source. This excludes, for example, calls to a dispatching
14549 -- assignment operation when the left-hand side is tagged. In
14550 -- GNATprove mode, we need those references also on generated
14551 -- code, as these are used to compute the local effects of
14554 if Modification_Comes_From_Source
or GNATprove_Mode
then
14555 Generate_Reference
(Ent
, Exp
, 'm');
14557 -- If the target of the assignment is the bound variable
14558 -- in an iterator, indicate that the corresponding array
14559 -- or container is also modified.
14561 if Ada_Version
>= Ada_2012
14562 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
14565 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
14568 -- TBD : in the full version of the construct, the
14569 -- domain of iteration can be given by an expression.
14571 if Is_Entity_Name
(Domain
) then
14572 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
14573 Set_Is_True_Constant
(Entity
(Domain
), False);
14574 Set_Never_Set_In_Source
(Entity
(Domain
), False);
14580 Check_Nested_Access
(Ent
);
14585 -- If we are sure this is a modification from source, and we know
14586 -- this modifies a constant, then give an appropriate warning.
14588 if Overlays_Constant
(Ent
)
14589 and then (Modification_Comes_From_Source
and Sure
)
14592 A
: constant Node_Id
:= Address_Clause
(Ent
);
14594 if Present
(A
) then
14596 Exp
: constant Node_Id
:= Expression
(A
);
14598 if Nkind
(Exp
) = N_Attribute_Reference
14599 and then Attribute_Name
(Exp
) = Name_Address
14600 and then Is_Entity_Name
(Prefix
(Exp
))
14602 Error_Msg_Sloc
:= Sloc
(A
);
14604 ("constant& may be modified via address "
14605 & "clause#??", N
, Entity
(Prefix
(Exp
)));
14618 end Note_Possible_Modification
;
14620 -------------------------
14621 -- Object_Access_Level --
14622 -------------------------
14624 -- Returns the static accessibility level of the view denoted by Obj. Note
14625 -- that the value returned is the result of a call to Scope_Depth. Only
14626 -- scope depths associated with dynamic scopes can actually be returned.
14627 -- Since only relative levels matter for accessibility checking, the fact
14628 -- that the distance between successive levels of accessibility is not
14629 -- always one is immaterial (invariant: if level(E2) is deeper than
14630 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
14632 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
14633 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
14634 -- Determine whether N is a construct of the form
14635 -- Some_Type (Operand._tag'Address)
14636 -- This construct appears in the context of dispatching calls.
14638 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
14639 -- An explicit dereference is created when removing side-effects from
14640 -- expressions for constraint checking purposes. In this case a local
14641 -- access type is created for it. The correct access level is that of
14642 -- the original source node. We detect this case by noting that the
14643 -- prefix of the dereference is created by an object declaration whose
14644 -- initial expression is a reference.
14646 -----------------------------
14647 -- Is_Interface_Conversion --
14648 -----------------------------
14650 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
14652 return Nkind
(N
) = N_Unchecked_Type_Conversion
14653 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
14654 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
14655 end Is_Interface_Conversion
;
14661 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
14662 Pref
: constant Node_Id
:= Prefix
(Obj
);
14664 if Is_Entity_Name
(Pref
)
14665 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
14666 and then Present
(Expression
(Parent
(Entity
(Pref
))))
14667 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
14669 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
14679 -- Start of processing for Object_Access_Level
14682 if Nkind
(Obj
) = N_Defining_Identifier
14683 or else Is_Entity_Name
(Obj
)
14685 if Nkind
(Obj
) = N_Defining_Identifier
then
14691 if Is_Prival
(E
) then
14692 E
:= Prival_Link
(E
);
14695 -- If E is a type then it denotes a current instance. For this case
14696 -- we add one to the normal accessibility level of the type to ensure
14697 -- that current instances are treated as always being deeper than
14698 -- than the level of any visible named access type (see 3.10.2(21)).
14700 if Is_Type
(E
) then
14701 return Type_Access_Level
(E
) + 1;
14703 elsif Present
(Renamed_Object
(E
)) then
14704 return Object_Access_Level
(Renamed_Object
(E
));
14706 -- Similarly, if E is a component of the current instance of a
14707 -- protected type, any instance of it is assumed to be at a deeper
14708 -- level than the type. For a protected object (whose type is an
14709 -- anonymous protected type) its components are at the same level
14710 -- as the type itself.
14712 elsif not Is_Overloadable
(E
)
14713 and then Ekind
(Scope
(E
)) = E_Protected_Type
14714 and then Comes_From_Source
(Scope
(E
))
14716 return Type_Access_Level
(Scope
(E
)) + 1;
14719 -- Aliased formals take their access level from the point of call.
14720 -- This is smaller than the level of the subprogram itself.
14722 if Is_Formal
(E
) and then Is_Aliased
(E
) then
14723 return Type_Access_Level
(Etype
(E
));
14726 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
14730 elsif Nkind
(Obj
) = N_Selected_Component
then
14731 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
14732 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14734 return Object_Access_Level
(Prefix
(Obj
));
14737 elsif Nkind
(Obj
) = N_Indexed_Component
then
14738 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
14739 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14741 return Object_Access_Level
(Prefix
(Obj
));
14744 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
14746 -- If the prefix is a selected access discriminant then we make a
14747 -- recursive call on the prefix, which will in turn check the level
14748 -- of the prefix object of the selected discriminant.
14750 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
14751 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
14753 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
14755 return Object_Access_Level
(Prefix
(Obj
));
14757 -- Detect an interface conversion in the context of a dispatching
14758 -- call. Use the original form of the conversion to find the access
14759 -- level of the operand.
14761 elsif Is_Interface
(Etype
(Obj
))
14762 and then Is_Interface_Conversion
(Prefix
(Obj
))
14763 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
14765 return Object_Access_Level
(Original_Node
(Obj
));
14767 elsif not Comes_From_Source
(Obj
) then
14769 Ref
: constant Node_Id
:= Reference_To
(Obj
);
14771 if Present
(Ref
) then
14772 return Object_Access_Level
(Ref
);
14774 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14779 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14782 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
14783 return Object_Access_Level
(Expression
(Obj
));
14785 elsif Nkind
(Obj
) = N_Function_Call
then
14787 -- Function results are objects, so we get either the access level of
14788 -- the function or, in the case of an indirect call, the level of the
14789 -- access-to-subprogram type. (This code is used for Ada 95, but it
14790 -- looks wrong, because it seems that we should be checking the level
14791 -- of the call itself, even for Ada 95. However, using the Ada 2005
14792 -- version of the code causes regressions in several tests that are
14793 -- compiled with -gnat95. ???)
14795 if Ada_Version
< Ada_2005
then
14796 if Is_Entity_Name
(Name
(Obj
)) then
14797 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
14799 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
14802 -- For Ada 2005, the level of the result object of a function call is
14803 -- defined to be the level of the call's innermost enclosing master.
14804 -- We determine that by querying the depth of the innermost enclosing
14808 Return_Master_Scope_Depth_Of_Call
: declare
14810 function Innermost_Master_Scope_Depth
14811 (N
: Node_Id
) return Uint
;
14812 -- Returns the scope depth of the given node's innermost
14813 -- enclosing dynamic scope (effectively the accessibility
14814 -- level of the innermost enclosing master).
14816 ----------------------------------
14817 -- Innermost_Master_Scope_Depth --
14818 ----------------------------------
14820 function Innermost_Master_Scope_Depth
14821 (N
: Node_Id
) return Uint
14823 Node_Par
: Node_Id
:= Parent
(N
);
14826 -- Locate the nearest enclosing node (by traversing Parents)
14827 -- that Defining_Entity can be applied to, and return the
14828 -- depth of that entity's nearest enclosing dynamic scope.
14830 while Present
(Node_Par
) loop
14831 case Nkind
(Node_Par
) is
14832 when N_Component_Declaration |
14833 N_Entry_Declaration |
14834 N_Formal_Object_Declaration |
14835 N_Formal_Type_Declaration |
14836 N_Full_Type_Declaration |
14837 N_Incomplete_Type_Declaration |
14838 N_Loop_Parameter_Specification |
14839 N_Object_Declaration |
14840 N_Protected_Type_Declaration |
14841 N_Private_Extension_Declaration |
14842 N_Private_Type_Declaration |
14843 N_Subtype_Declaration |
14844 N_Function_Specification |
14845 N_Procedure_Specification |
14846 N_Task_Type_Declaration |
14848 N_Generic_Instantiation |
14850 N_Implicit_Label_Declaration |
14851 N_Package_Declaration |
14852 N_Single_Task_Declaration |
14853 N_Subprogram_Declaration |
14854 N_Generic_Declaration |
14855 N_Renaming_Declaration |
14856 N_Block_Statement |
14857 N_Formal_Subprogram_Declaration |
14858 N_Abstract_Subprogram_Declaration |
14860 N_Exception_Declaration |
14861 N_Formal_Package_Declaration |
14862 N_Number_Declaration |
14863 N_Package_Specification |
14864 N_Parameter_Specification |
14865 N_Single_Protected_Declaration |
14869 (Nearest_Dynamic_Scope
14870 (Defining_Entity
(Node_Par
)));
14876 Node_Par
:= Parent
(Node_Par
);
14879 pragma Assert
(False);
14881 -- Should never reach the following return
14883 return Scope_Depth
(Current_Scope
) + 1;
14884 end Innermost_Master_Scope_Depth
;
14886 -- Start of processing for Return_Master_Scope_Depth_Of_Call
14889 return Innermost_Master_Scope_Depth
(Obj
);
14890 end Return_Master_Scope_Depth_Of_Call
;
14893 -- For convenience we handle qualified expressions, even though they
14894 -- aren't technically object names.
14896 elsif Nkind
(Obj
) = N_Qualified_Expression
then
14897 return Object_Access_Level
(Expression
(Obj
));
14899 -- Ditto for aggregates. They have the level of the temporary that
14900 -- will hold their value.
14902 elsif Nkind
(Obj
) = N_Aggregate
then
14903 return Object_Access_Level
(Current_Scope
);
14905 -- Otherwise return the scope level of Standard. (If there are cases
14906 -- that fall through to this point they will be treated as having
14907 -- global accessibility for now. ???)
14910 return Scope_Depth
(Standard_Standard
);
14912 end Object_Access_Level
;
14914 --------------------------
14915 -- Original_Aspect_Name --
14916 --------------------------
14918 function Original_Aspect_Name
(N
: Node_Id
) return Name_Id
is
14923 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
14926 if Is_Rewrite_Substitution
(Pras
)
14927 and then Nkind
(Original_Node
(Pras
)) = N_Pragma
14929 Pras
:= Original_Node
(Pras
);
14932 -- Case where we came from aspect specication
14934 if Nkind
(Pras
) = N_Pragma
and then From_Aspect_Specification
(Pras
) then
14935 Pras
:= Corresponding_Aspect
(Pras
);
14938 -- Get name from aspect or pragma
14940 if Nkind
(Pras
) = N_Pragma
then
14941 Name
:= Pragma_Name
(Pras
);
14943 Name
:= Chars
(Identifier
(Pras
));
14946 -- Deal with 'Class
14948 if Class_Present
(Pras
) then
14951 -- Names that need converting to special _xxx form
14959 Name
:= Name_uPost
;
14961 when Name_Invariant
=>
14962 Name
:= Name_uInvariant
;
14964 when Name_Type_Invariant |
14965 Name_Type_Invariant_Class
=>
14966 Name
:= Name_uType_Invariant
;
14968 -- Nothing to do for other cases (e.g. a Check that derived
14969 -- from Pre_Class and has the flag set). Also we do nothing
14970 -- if the name is already in special _xxx form.
14978 end Original_Aspect_Name
;
14980 --------------------------------------
14981 -- Original_Corresponding_Operation --
14982 --------------------------------------
14984 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
14986 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
14989 -- If S is an inherited primitive S2 the original corresponding
14990 -- operation of S is the original corresponding operation of S2
14992 if Present
(Alias
(S
))
14993 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
14995 return Original_Corresponding_Operation
(Alias
(S
));
14997 -- If S overrides an inherited subprogram S2 the original corresponding
14998 -- operation of S is the original corresponding operation of S2
15000 elsif Present
(Overridden_Operation
(S
)) then
15001 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
15003 -- otherwise it is S itself
15008 end Original_Corresponding_Operation
;
15010 ----------------------------------
15011 -- Predicate_Tests_On_Arguments --
15012 ----------------------------------
15014 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
15016 -- Always test predicates on indirect call
15018 if Ekind
(Subp
) = E_Subprogram_Type
then
15021 -- Do not test predicates on call to generated default Finalize, since
15022 -- we are not interested in whether something we are finalizing (and
15023 -- typically destroying) satisfies its predicates.
15025 elsif Chars
(Subp
) = Name_Finalize
15026 and then not Comes_From_Source
(Subp
)
15030 -- Do not test predicates on any internally generated routines
15032 elsif Is_Internal_Name
(Chars
(Subp
)) then
15035 -- Do not test predicates on call to Init_Proc, since if needed the
15036 -- predicate test will occur at some other point.
15038 elsif Is_Init_Proc
(Subp
) then
15041 -- Do not test predicates on call to predicate function, since this
15042 -- would cause infinite recursion.
15044 elsif Ekind
(Subp
) = E_Function
15045 and then (Is_Predicate_Function
(Subp
)
15047 Is_Predicate_Function_M
(Subp
))
15051 -- For now, no other exceptions
15056 end Predicate_Tests_On_Arguments
;
15058 -----------------------
15059 -- Private_Component --
15060 -----------------------
15062 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
15063 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
15065 function Trace_Components
15067 Check
: Boolean) return Entity_Id
;
15068 -- Recursive function that does the work, and checks against circular
15069 -- definition for each subcomponent type.
15071 ----------------------
15072 -- Trace_Components --
15073 ----------------------
15075 function Trace_Components
15077 Check
: Boolean) return Entity_Id
15079 Btype
: constant Entity_Id
:= Base_Type
(T
);
15080 Component
: Entity_Id
;
15082 Candidate
: Entity_Id
:= Empty
;
15085 if Check
and then Btype
= Ancestor
then
15086 Error_Msg_N
("circular type definition", Type_Id
);
15090 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
15091 if Present
(Full_View
(Btype
))
15092 and then Is_Record_Type
(Full_View
(Btype
))
15093 and then not Is_Frozen
(Btype
)
15095 -- To indicate that the ancestor depends on a private type, the
15096 -- current Btype is sufficient. However, to check for circular
15097 -- definition we must recurse on the full view.
15099 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
15101 if Candidate
= Any_Type
then
15111 elsif Is_Array_Type
(Btype
) then
15112 return Trace_Components
(Component_Type
(Btype
), True);
15114 elsif Is_Record_Type
(Btype
) then
15115 Component
:= First_Entity
(Btype
);
15116 while Present
(Component
)
15117 and then Comes_From_Source
(Component
)
15119 -- Skip anonymous types generated by constrained components
15121 if not Is_Type
(Component
) then
15122 P
:= Trace_Components
(Etype
(Component
), True);
15124 if Present
(P
) then
15125 if P
= Any_Type
then
15133 Next_Entity
(Component
);
15141 end Trace_Components
;
15143 -- Start of processing for Private_Component
15146 return Trace_Components
(Type_Id
, False);
15147 end Private_Component
;
15149 ---------------------------
15150 -- Primitive_Names_Match --
15151 ---------------------------
15153 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
15155 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
15156 -- Given an internal name, returns the corresponding non-internal name
15158 ------------------------
15159 -- Non_Internal_Name --
15160 ------------------------
15162 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
15164 Get_Name_String
(Chars
(E
));
15165 Name_Len
:= Name_Len
- 1;
15167 end Non_Internal_Name
;
15169 -- Start of processing for Primitive_Names_Match
15172 pragma Assert
(Present
(E1
) and then Present
(E2
));
15174 return Chars
(E1
) = Chars
(E2
)
15176 (not Is_Internal_Name
(Chars
(E1
))
15177 and then Is_Internal_Name
(Chars
(E2
))
15178 and then Non_Internal_Name
(E2
) = Chars
(E1
))
15180 (not Is_Internal_Name
(Chars
(E2
))
15181 and then Is_Internal_Name
(Chars
(E1
))
15182 and then Non_Internal_Name
(E1
) = Chars
(E2
))
15184 (Is_Predefined_Dispatching_Operation
(E1
)
15185 and then Is_Predefined_Dispatching_Operation
(E2
)
15186 and then Same_TSS
(E1
, E2
))
15188 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
15189 end Primitive_Names_Match
;
15191 -----------------------
15192 -- Process_End_Label --
15193 -----------------------
15195 procedure Process_End_Label
15204 Label_Ref
: Boolean;
15205 -- Set True if reference to end label itself is required
15208 -- Gets set to the operator symbol or identifier that references the
15209 -- entity Ent. For the child unit case, this is the identifier from the
15210 -- designator. For other cases, this is simply Endl.
15212 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
15213 -- N is an identifier node that appears as a parent unit reference in
15214 -- the case where Ent is a child unit. This procedure generates an
15215 -- appropriate cross-reference entry. E is the corresponding entity.
15217 -------------------------
15218 -- Generate_Parent_Ref --
15219 -------------------------
15221 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
15223 -- If names do not match, something weird, skip reference
15225 if Chars
(E
) = Chars
(N
) then
15227 -- Generate the reference. We do NOT consider this as a reference
15228 -- for unreferenced symbol purposes.
15230 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
15232 if Style_Check
then
15233 Style
.Check_Identifier
(N
, E
);
15236 end Generate_Parent_Ref
;
15238 -- Start of processing for Process_End_Label
15241 -- If no node, ignore. This happens in some error situations, and
15242 -- also for some internally generated structures where no end label
15243 -- references are required in any case.
15249 -- Nothing to do if no End_Label, happens for internally generated
15250 -- constructs where we don't want an end label reference anyway. Also
15251 -- nothing to do if Endl is a string literal, which means there was
15252 -- some prior error (bad operator symbol)
15254 Endl
:= End_Label
(N
);
15256 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
15260 -- Reference node is not in extended main source unit
15262 if not In_Extended_Main_Source_Unit
(N
) then
15264 -- Generally we do not collect references except for the extended
15265 -- main source unit. The one exception is the 'e' entry for a
15266 -- package spec, where it is useful for a client to have the
15267 -- ending information to define scopes.
15273 Label_Ref
:= False;
15275 -- For this case, we can ignore any parent references, but we
15276 -- need the package name itself for the 'e' entry.
15278 if Nkind
(Endl
) = N_Designator
then
15279 Endl
:= Identifier
(Endl
);
15283 -- Reference is in extended main source unit
15288 -- For designator, generate references for the parent entries
15290 if Nkind
(Endl
) = N_Designator
then
15292 -- Generate references for the prefix if the END line comes from
15293 -- source (otherwise we do not need these references) We climb the
15294 -- scope stack to find the expected entities.
15296 if Comes_From_Source
(Endl
) then
15297 Nam
:= Name
(Endl
);
15298 Scop
:= Current_Scope
;
15299 while Nkind
(Nam
) = N_Selected_Component
loop
15300 Scop
:= Scope
(Scop
);
15301 exit when No
(Scop
);
15302 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
15303 Nam
:= Prefix
(Nam
);
15306 if Present
(Scop
) then
15307 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
15311 Endl
:= Identifier
(Endl
);
15315 -- If the end label is not for the given entity, then either we have
15316 -- some previous error, or this is a generic instantiation for which
15317 -- we do not need to make a cross-reference in this case anyway. In
15318 -- either case we simply ignore the call.
15320 if Chars
(Ent
) /= Chars
(Endl
) then
15324 -- If label was really there, then generate a normal reference and then
15325 -- adjust the location in the end label to point past the name (which
15326 -- should almost always be the semicolon).
15328 Loc
:= Sloc
(Endl
);
15330 if Comes_From_Source
(Endl
) then
15332 -- If a label reference is required, then do the style check and
15333 -- generate an l-type cross-reference entry for the label
15336 if Style_Check
then
15337 Style
.Check_Identifier
(Endl
, Ent
);
15340 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
15343 -- Set the location to point past the label (normally this will
15344 -- mean the semicolon immediately following the label). This is
15345 -- done for the sake of the 'e' or 't' entry generated below.
15347 Get_Decoded_Name_String
(Chars
(Endl
));
15348 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
15351 -- In SPARK mode, no missing label is allowed for packages and
15352 -- subprogram bodies. Detect those cases by testing whether
15353 -- Process_End_Label was called for a body (Typ = 't') or a package.
15355 if Restriction_Check_Required
(SPARK_05
)
15356 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
15358 Error_Msg_Node_1
:= Endl
;
15359 Check_SPARK_05_Restriction
15360 ("`END &` required", Endl
, Force
=> True);
15364 -- Now generate the e/t reference
15366 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
15368 -- Restore Sloc, in case modified above, since we have an identifier
15369 -- and the normal Sloc should be left set in the tree.
15371 Set_Sloc
(Endl
, Loc
);
15372 end Process_End_Label
;
15378 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
15379 Seen
: Boolean := False;
15381 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
15382 -- Determine whether node N denotes a reference to Id. If this is the
15383 -- case, set global flag Seen to True and stop the traversal.
15389 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
15391 if Is_Entity_Name
(N
)
15392 and then Present
(Entity
(N
))
15393 and then Entity
(N
) = Id
15402 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
15404 -- Start of processing for Referenced
15407 Inspect_Expression
(Expr
);
15411 ------------------------------------
15412 -- References_Generic_Formal_Type --
15413 ------------------------------------
15415 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
15417 function Process
(N
: Node_Id
) return Traverse_Result
;
15418 -- Process one node in search for generic formal type
15424 function Process
(N
: Node_Id
) return Traverse_Result
is
15426 if Nkind
(N
) in N_Has_Entity
then
15428 E
: constant Entity_Id
:= Entity
(N
);
15430 if Present
(E
) then
15431 if Is_Generic_Type
(E
) then
15433 elsif Present
(Etype
(E
))
15434 and then Is_Generic_Type
(Etype
(E
))
15445 function Traverse
is new Traverse_Func
(Process
);
15446 -- Traverse tree to look for generic type
15449 if Inside_A_Generic
then
15450 return Traverse
(N
) = Abandon
;
15454 end References_Generic_Formal_Type
;
15456 --------------------
15457 -- Remove_Homonym --
15458 --------------------
15460 procedure Remove_Homonym
(E
: Entity_Id
) is
15461 Prev
: Entity_Id
:= Empty
;
15465 if E
= Current_Entity
(E
) then
15466 if Present
(Homonym
(E
)) then
15467 Set_Current_Entity
(Homonym
(E
));
15469 Set_Name_Entity_Id
(Chars
(E
), Empty
);
15473 H
:= Current_Entity
(E
);
15474 while Present
(H
) and then H
/= E
loop
15479 -- If E is not on the homonym chain, nothing to do
15481 if Present
(H
) then
15482 Set_Homonym
(Prev
, Homonym
(E
));
15485 end Remove_Homonym
;
15487 ---------------------
15488 -- Rep_To_Pos_Flag --
15489 ---------------------
15491 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
15493 return New_Occurrence_Of
15494 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
15495 end Rep_To_Pos_Flag
;
15497 --------------------
15498 -- Require_Entity --
15499 --------------------
15501 procedure Require_Entity
(N
: Node_Id
) is
15503 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
15504 if Total_Errors_Detected
/= 0 then
15505 Set_Entity
(N
, Any_Id
);
15507 raise Program_Error
;
15510 end Require_Entity
;
15512 -------------------------------
15513 -- Requires_State_Refinement --
15514 -------------------------------
15516 function Requires_State_Refinement
15517 (Spec_Id
: Entity_Id
;
15518 Body_Id
: Entity_Id
) return Boolean
15520 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
15521 -- Given pragma SPARK_Mode, determine whether the mode is Off
15527 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
15531 -- The default SPARK mode is On
15537 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
15539 -- Then the pragma lacks an argument, the default mode is On
15544 return Chars
(Mode
) = Name_Off
;
15548 -- Start of processing for Requires_State_Refinement
15551 -- A package that does not define at least one abstract state cannot
15552 -- possibly require refinement.
15554 if No
(Abstract_States
(Spec_Id
)) then
15557 -- The package instroduces a single null state which does not merit
15560 elsif Has_Null_Abstract_State
(Spec_Id
) then
15563 -- Check whether the package body is subject to pragma SPARK_Mode. If
15564 -- it is and the mode is Off, the package body is considered to be in
15565 -- regular Ada and does not require refinement.
15567 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
15570 -- The body's SPARK_Mode may be inherited from a similar pragma that
15571 -- appears in the private declarations of the spec. The pragma we are
15572 -- interested appears as the second entry in SPARK_Pragma.
15574 elsif Present
(SPARK_Pragma
(Spec_Id
))
15575 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
15579 -- The spec defines at least one abstract state and the body has no way
15580 -- of circumventing the refinement.
15585 end Requires_State_Refinement
;
15587 ------------------------------
15588 -- Requires_Transient_Scope --
15589 ------------------------------
15591 -- A transient scope is required when variable-sized temporaries are
15592 -- allocated in the primary or secondary stack, or when finalization
15593 -- actions must be generated before the next instruction.
15595 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
15596 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
15598 -- Start of processing for Requires_Transient_Scope
15601 -- This is a private type which is not completed yet. This can only
15602 -- happen in a default expression (of a formal parameter or of a
15603 -- record component). Do not expand transient scope in this case
15608 -- Do not expand transient scope for non-existent procedure return
15610 elsif Typ
= Standard_Void_Type
then
15613 -- Elementary types do not require a transient scope
15615 elsif Is_Elementary_Type
(Typ
) then
15618 -- Generally, indefinite subtypes require a transient scope, since the
15619 -- back end cannot generate temporaries, since this is not a valid type
15620 -- for declaring an object. It might be possible to relax this in the
15621 -- future, e.g. by declaring the maximum possible space for the type.
15623 elsif Is_Indefinite_Subtype
(Typ
) then
15626 -- Functions returning tagged types may dispatch on result so their
15627 -- returned value is allocated on the secondary stack. Controlled
15628 -- type temporaries need finalization.
15630 elsif Is_Tagged_Type
(Typ
)
15631 or else Has_Controlled_Component
(Typ
)
15633 return not Is_Value_Type
(Typ
);
15637 elsif Is_Record_Type
(Typ
) then
15641 Comp
:= First_Entity
(Typ
);
15642 while Present
(Comp
) loop
15643 if Ekind
(Comp
) = E_Component
15644 and then Requires_Transient_Scope
(Etype
(Comp
))
15648 Next_Entity
(Comp
);
15655 -- String literal types never require transient scope
15657 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
15660 -- Array type. Note that we already know that this is a constrained
15661 -- array, since unconstrained arrays will fail the indefinite test.
15663 elsif Is_Array_Type
(Typ
) then
15665 -- If component type requires a transient scope, the array does too
15667 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
15670 -- Otherwise, we only need a transient scope if the size depends on
15671 -- the value of one or more discriminants.
15674 return Size_Depends_On_Discriminant
(Typ
);
15677 -- All other cases do not require a transient scope
15682 end Requires_Transient_Scope
;
15684 --------------------------
15685 -- Reset_Analyzed_Flags --
15686 --------------------------
15688 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
15690 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
15691 -- Function used to reset Analyzed flags in tree. Note that we do
15692 -- not reset Analyzed flags in entities, since there is no need to
15693 -- reanalyze entities, and indeed, it is wrong to do so, since it
15694 -- can result in generating auxiliary stuff more than once.
15696 --------------------
15697 -- Clear_Analyzed --
15698 --------------------
15700 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
15702 if not Has_Extension
(N
) then
15703 Set_Analyzed
(N
, False);
15707 end Clear_Analyzed
;
15709 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
15711 -- Start of processing for Reset_Analyzed_Flags
15714 Reset_Analyzed
(N
);
15715 end Reset_Analyzed_Flags
;
15717 ------------------------
15718 -- Restore_SPARK_Mode --
15719 ------------------------
15721 procedure Restore_SPARK_Mode
(Mode
: SPARK_Mode_Type
) is
15723 SPARK_Mode
:= Mode
;
15724 end Restore_SPARK_Mode
;
15726 --------------------------------
15727 -- Returns_Unconstrained_Type --
15728 --------------------------------
15730 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
15732 return Ekind
(Subp
) = E_Function
15733 and then not Is_Scalar_Type
(Etype
(Subp
))
15734 and then not Is_Access_Type
(Etype
(Subp
))
15735 and then not Is_Constrained
(Etype
(Subp
));
15736 end Returns_Unconstrained_Type
;
15738 ----------------------------
15739 -- Root_Type_Of_Full_View --
15740 ----------------------------
15742 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
15743 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
15746 -- The root type of the full view may itself be a private type. Keep
15747 -- looking for the ultimate derivation parent.
15749 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
15750 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
15754 end Root_Type_Of_Full_View
;
15756 ---------------------------
15757 -- Safe_To_Capture_Value --
15758 ---------------------------
15760 function Safe_To_Capture_Value
15763 Cond
: Boolean := False) return Boolean
15766 -- The only entities for which we track constant values are variables
15767 -- which are not renamings, constants, out parameters, and in out
15768 -- parameters, so check if we have this case.
15770 -- Note: it may seem odd to track constant values for constants, but in
15771 -- fact this routine is used for other purposes than simply capturing
15772 -- the value. In particular, the setting of Known[_Non]_Null.
15774 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
15776 Ekind
(Ent
) = E_Constant
15778 Ekind
(Ent
) = E_Out_Parameter
15780 Ekind
(Ent
) = E_In_Out_Parameter
15784 -- For conditionals, we also allow loop parameters and all formals,
15785 -- including in parameters.
15787 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
15790 -- For all other cases, not just unsafe, but impossible to capture
15791 -- Current_Value, since the above are the only entities which have
15792 -- Current_Value fields.
15798 -- Skip if volatile or aliased, since funny things might be going on in
15799 -- these cases which we cannot necessarily track. Also skip any variable
15800 -- for which an address clause is given, or whose address is taken. Also
15801 -- never capture value of library level variables (an attempt to do so
15802 -- can occur in the case of package elaboration code).
15804 if Treat_As_Volatile
(Ent
)
15805 or else Is_Aliased
(Ent
)
15806 or else Present
(Address_Clause
(Ent
))
15807 or else Address_Taken
(Ent
)
15808 or else (Is_Library_Level_Entity
(Ent
)
15809 and then Ekind
(Ent
) = E_Variable
)
15814 -- OK, all above conditions are met. We also require that the scope of
15815 -- the reference be the same as the scope of the entity, not counting
15816 -- packages and blocks and loops.
15819 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
15820 R_Scope
: Entity_Id
;
15823 R_Scope
:= Current_Scope
;
15824 while R_Scope
/= Standard_Standard
loop
15825 exit when R_Scope
= E_Scope
;
15827 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
15830 R_Scope
:= Scope
(R_Scope
);
15835 -- We also require that the reference does not appear in a context
15836 -- where it is not sure to be executed (i.e. a conditional context
15837 -- or an exception handler). We skip this if Cond is True, since the
15838 -- capturing of values from conditional tests handles this ok.
15851 -- Seems dubious that case expressions are not handled here ???
15854 while Present
(P
) loop
15855 if Nkind
(P
) = N_If_Statement
15856 or else Nkind
(P
) = N_Case_Statement
15857 or else (Nkind
(P
) in N_Short_Circuit
15858 and then Desc
= Right_Opnd
(P
))
15859 or else (Nkind
(P
) = N_If_Expression
15860 and then Desc
/= First
(Expressions
(P
)))
15861 or else Nkind
(P
) = N_Exception_Handler
15862 or else Nkind
(P
) = N_Selective_Accept
15863 or else Nkind
(P
) = N_Conditional_Entry_Call
15864 or else Nkind
(P
) = N_Timed_Entry_Call
15865 or else Nkind
(P
) = N_Asynchronous_Select
15873 -- A special Ada 2012 case: the original node may be part
15874 -- of the else_actions of a conditional expression, in which
15875 -- case it might not have been expanded yet, and appears in
15876 -- a non-syntactic list of actions. In that case it is clearly
15877 -- not safe to save a value.
15880 and then Is_List_Member
(Desc
)
15881 and then No
(Parent
(List_Containing
(Desc
)))
15889 -- OK, looks safe to set value
15892 end Safe_To_Capture_Value
;
15898 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
15899 K1
: constant Node_Kind
:= Nkind
(N1
);
15900 K2
: constant Node_Kind
:= Nkind
(N2
);
15903 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
15904 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
15906 return Chars
(N1
) = Chars
(N2
);
15908 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
15909 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
15911 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
15912 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
15923 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
15924 N1
: constant Node_Id
:= Original_Node
(Node1
);
15925 N2
: constant Node_Id
:= Original_Node
(Node2
);
15926 -- We do the tests on original nodes, since we are most interested
15927 -- in the original source, not any expansion that got in the way.
15929 K1
: constant Node_Kind
:= Nkind
(N1
);
15930 K2
: constant Node_Kind
:= Nkind
(N2
);
15933 -- First case, both are entities with same entity
15935 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
15937 EN1
: constant Entity_Id
:= Entity
(N1
);
15938 EN2
: constant Entity_Id
:= Entity
(N2
);
15940 if Present
(EN1
) and then Present
(EN2
)
15941 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
15942 or else Is_Formal
(EN1
))
15950 -- Second case, selected component with same selector, same record
15952 if K1
= N_Selected_Component
15953 and then K2
= N_Selected_Component
15954 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
15956 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
15958 -- Third case, indexed component with same subscripts, same array
15960 elsif K1
= N_Indexed_Component
15961 and then K2
= N_Indexed_Component
15962 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
15967 E1
:= First
(Expressions
(N1
));
15968 E2
:= First
(Expressions
(N2
));
15969 while Present
(E1
) loop
15970 if not Same_Value
(E1
, E2
) then
15981 -- Fourth case, slice of same array with same bounds
15984 and then K2
= N_Slice
15985 and then Nkind
(Discrete_Range
(N1
)) = N_Range
15986 and then Nkind
(Discrete_Range
(N2
)) = N_Range
15987 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
15988 Low_Bound
(Discrete_Range
(N2
)))
15989 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
15990 High_Bound
(Discrete_Range
(N2
)))
15992 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
15994 -- All other cases, not clearly the same object
16005 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
16010 elsif not Is_Constrained
(T1
)
16011 and then not Is_Constrained
(T2
)
16012 and then Base_Type
(T1
) = Base_Type
(T2
)
16016 -- For now don't bother with case of identical constraints, to be
16017 -- fiddled with later on perhaps (this is only used for optimization
16018 -- purposes, so it is not critical to do a best possible job)
16029 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
16031 if Compile_Time_Known_Value
(Node1
)
16032 and then Compile_Time_Known_Value
(Node2
)
16033 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
16036 elsif Same_Object
(Node1
, Node2
) then
16043 -----------------------------
16044 -- Save_SPARK_Mode_And_Set --
16045 -----------------------------
16047 procedure Save_SPARK_Mode_And_Set
16048 (Context
: Entity_Id
;
16049 Mode
: out SPARK_Mode_Type
)
16052 -- Save the current mode in effect
16054 Mode
:= SPARK_Mode
;
16056 -- Do not consider illegal or partially decorated constructs
16058 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
16061 elsif Present
(SPARK_Pragma
(Context
)) then
16062 SPARK_Mode
:= Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Context
));
16064 end Save_SPARK_Mode_And_Set
;
16066 -------------------------
16067 -- Scalar_Part_Present --
16068 -------------------------
16070 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
16074 if Is_Scalar_Type
(T
) then
16077 elsif Is_Array_Type
(T
) then
16078 return Scalar_Part_Present
(Component_Type
(T
));
16080 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
16081 C
:= First_Component_Or_Discriminant
(T
);
16082 while Present
(C
) loop
16083 if Scalar_Part_Present
(Etype
(C
)) then
16086 Next_Component_Or_Discriminant
(C
);
16092 end Scalar_Part_Present
;
16094 ------------------------
16095 -- Scope_Is_Transient --
16096 ------------------------
16098 function Scope_Is_Transient
return Boolean is
16100 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
16101 end Scope_Is_Transient
;
16107 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16112 while Scop
/= Standard_Standard
loop
16113 Scop
:= Scope
(Scop
);
16115 if Scop
= Scope2
then
16123 --------------------------
16124 -- Scope_Within_Or_Same --
16125 --------------------------
16127 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16132 while Scop
/= Standard_Standard
loop
16133 if Scop
= Scope2
then
16136 Scop
:= Scope
(Scop
);
16141 end Scope_Within_Or_Same
;
16143 --------------------
16144 -- Set_Convention --
16145 --------------------
16147 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
16149 Basic_Set_Convention
(E
, Val
);
16152 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
16153 and then Has_Foreign_Convention
(E
)
16155 Set_Can_Use_Internal_Rep
(E
, False);
16158 -- If E is an object or component, and the type of E is an anonymous
16159 -- access type with no convention set, then also set the convention of
16160 -- the anonymous access type. We do not do this for anonymous protected
16161 -- types, since protected types always have the default convention.
16163 if Present
(Etype
(E
))
16164 and then (Is_Object
(E
)
16165 or else Ekind
(E
) = E_Component
16167 -- Allow E_Void (happens for pragma Convention appearing
16168 -- in the middle of a record applying to a component)
16170 or else Ekind
(E
) = E_Void
)
16173 Typ
: constant Entity_Id
:= Etype
(E
);
16176 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
16177 E_Anonymous_Access_Subprogram_Type
)
16178 and then not Has_Convention_Pragma
(Typ
)
16180 Basic_Set_Convention
(Typ
, Val
);
16181 Set_Has_Convention_Pragma
(Typ
);
16183 -- And for the access subprogram type, deal similarly with the
16184 -- designated E_Subprogram_Type if it is also internal (which
16187 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
16189 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
16191 if Ekind
(Dtype
) = E_Subprogram_Type
16192 and then Is_Itype
(Dtype
)
16193 and then not Has_Convention_Pragma
(Dtype
)
16195 Basic_Set_Convention
(Dtype
, Val
);
16196 Set_Has_Convention_Pragma
(Dtype
);
16203 end Set_Convention
;
16205 ------------------------
16206 -- Set_Current_Entity --
16207 ------------------------
16209 -- The given entity is to be set as the currently visible definition of its
16210 -- associated name (i.e. the Node_Id associated with its name). All we have
16211 -- to do is to get the name from the identifier, and then set the
16212 -- associated Node_Id to point to the given entity.
16214 procedure Set_Current_Entity
(E
: Entity_Id
) is
16216 Set_Name_Entity_Id
(Chars
(E
), E
);
16217 end Set_Current_Entity
;
16219 ---------------------------
16220 -- Set_Debug_Info_Needed --
16221 ---------------------------
16223 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
16225 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
16226 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
16227 -- Used to set debug info in a related node if not set already
16229 --------------------------------------
16230 -- Set_Debug_Info_Needed_If_Not_Set --
16231 --------------------------------------
16233 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
16235 if Present
(E
) and then not Needs_Debug_Info
(E
) then
16236 Set_Debug_Info_Needed
(E
);
16238 -- For a private type, indicate that the full view also needs
16239 -- debug information.
16242 and then Is_Private_Type
(E
)
16243 and then Present
(Full_View
(E
))
16245 Set_Debug_Info_Needed
(Full_View
(E
));
16248 end Set_Debug_Info_Needed_If_Not_Set
;
16250 -- Start of processing for Set_Debug_Info_Needed
16253 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16254 -- indicates that Debug_Info_Needed is never required for the entity.
16257 or else Debug_Info_Off
(T
)
16262 -- Set flag in entity itself. Note that we will go through the following
16263 -- circuitry even if the flag is already set on T. That's intentional,
16264 -- it makes sure that the flag will be set in subsidiary entities.
16266 Set_Needs_Debug_Info
(T
);
16268 -- Set flag on subsidiary entities if not set already
16270 if Is_Object
(T
) then
16271 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16273 elsif Is_Type
(T
) then
16274 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16276 if Is_Record_Type
(T
) then
16278 Ent
: Entity_Id
:= First_Entity
(T
);
16280 while Present
(Ent
) loop
16281 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
16286 -- For a class wide subtype, we also need debug information
16287 -- for the equivalent type.
16289 if Ekind
(T
) = E_Class_Wide_Subtype
then
16290 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
16293 elsif Is_Array_Type
(T
) then
16294 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
16297 Indx
: Node_Id
:= First_Index
(T
);
16299 while Present
(Indx
) loop
16300 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
16301 Indx
:= Next_Index
(Indx
);
16305 -- For a packed array type, we also need debug information for
16306 -- the type used to represent the packed array. Conversely, we
16307 -- also need it for the former if we need it for the latter.
16309 if Is_Packed
(T
) then
16310 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
16313 if Is_Packed_Array_Impl_Type
(T
) then
16314 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
16317 elsif Is_Access_Type
(T
) then
16318 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
16320 elsif Is_Private_Type
(T
) then
16321 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
16323 elsif Is_Protected_Type
(T
) then
16324 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
16326 elsif Is_Scalar_Type
(T
) then
16328 -- If the subrange bounds are materialized by dedicated constant
16329 -- objects, also include them in the debug info to make sure the
16330 -- debugger can properly use them.
16332 if Present
(Scalar_Range
(T
))
16333 and then Nkind
(Scalar_Range
(T
)) = N_Range
16336 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
16337 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
16340 if Is_Entity_Name
(Low_Bnd
) then
16341 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
16344 if Is_Entity_Name
(High_Bnd
) then
16345 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
16351 end Set_Debug_Info_Needed
;
16353 ----------------------------
16354 -- Set_Entity_With_Checks --
16355 ----------------------------
16357 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
16358 Val_Actual
: Entity_Id
;
16360 Post_Node
: Node_Id
;
16363 -- Unconditionally set the entity
16365 Set_Entity
(N
, Val
);
16367 -- The node to post on is the selector in the case of an expanded name,
16368 -- and otherwise the node itself.
16370 if Nkind
(N
) = N_Expanded_Name
then
16371 Post_Node
:= Selector_Name
(N
);
16376 -- Check for violation of No_Fixed_IO
16378 if Restriction_Check_Required
(No_Fixed_IO
)
16380 ((RTU_Loaded
(Ada_Text_IO
)
16381 and then (Is_RTE
(Val
, RE_Decimal_IO
)
16383 Is_RTE
(Val
, RE_Fixed_IO
)))
16386 (RTU_Loaded
(Ada_Wide_Text_IO
)
16387 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
16389 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
16392 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
16393 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
16395 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
16397 -- A special extra check, don't complain about a reference from within
16398 -- the Ada.Interrupts package itself!
16400 and then not In_Same_Extended_Unit
(N
, Val
)
16402 Check_Restriction
(No_Fixed_IO
, Post_Node
);
16405 -- Remaining checks are only done on source nodes. Note that we test
16406 -- for violation of No_Fixed_IO even on non-source nodes, because the
16407 -- cases for checking violations of this restriction are instantiations
16408 -- where the reference in the instance has Comes_From_Source False.
16410 if not Comes_From_Source
(N
) then
16414 -- Check for violation of No_Abort_Statements, which is triggered by
16415 -- call to Ada.Task_Identification.Abort_Task.
16417 if Restriction_Check_Required
(No_Abort_Statements
)
16418 and then (Is_RTE
(Val
, RE_Abort_Task
))
16420 -- A special extra check, don't complain about a reference from within
16421 -- the Ada.Task_Identification package itself!
16423 and then not In_Same_Extended_Unit
(N
, Val
)
16425 Check_Restriction
(No_Abort_Statements
, Post_Node
);
16428 if Val
= Standard_Long_Long_Integer
then
16429 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
16432 -- Check for violation of No_Dynamic_Attachment
16434 if Restriction_Check_Required
(No_Dynamic_Attachment
)
16435 and then RTU_Loaded
(Ada_Interrupts
)
16436 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
16437 Is_RTE
(Val
, RE_Is_Attached
) or else
16438 Is_RTE
(Val
, RE_Current_Handler
) or else
16439 Is_RTE
(Val
, RE_Attach_Handler
) or else
16440 Is_RTE
(Val
, RE_Exchange_Handler
) or else
16441 Is_RTE
(Val
, RE_Detach_Handler
) or else
16442 Is_RTE
(Val
, RE_Reference
))
16444 -- A special extra check, don't complain about a reference from within
16445 -- the Ada.Interrupts package itself!
16447 and then not In_Same_Extended_Unit
(N
, Val
)
16449 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
16452 -- Check for No_Implementation_Identifiers
16454 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
16456 -- We have an implementation defined entity if it is marked as
16457 -- implementation defined, or is defined in a package marked as
16458 -- implementation defined. However, library packages themselves
16459 -- are excluded (we don't want to flag Interfaces itself, just
16460 -- the entities within it).
16462 if (Is_Implementation_Defined
(Val
)
16464 Is_Implementation_Defined
(Scope
(Val
)))
16465 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
16466 and then Is_Library_Level_Entity
(Val
))
16468 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
16472 -- Do the style check
16475 and then not Suppress_Style_Checks
(Val
)
16476 and then not In_Instance
16478 if Nkind
(N
) = N_Identifier
then
16480 elsif Nkind
(N
) = N_Expanded_Name
then
16481 Nod
:= Selector_Name
(N
);
16486 -- A special situation arises for derived operations, where we want
16487 -- to do the check against the parent (since the Sloc of the derived
16488 -- operation points to the derived type declaration itself).
16491 while not Comes_From_Source
(Val_Actual
)
16492 and then Nkind
(Val_Actual
) in N_Entity
16493 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
16494 or else Is_Subprogram
(Val_Actual
)
16495 or else Is_Generic_Subprogram
(Val_Actual
))
16496 and then Present
(Alias
(Val_Actual
))
16498 Val_Actual
:= Alias
(Val_Actual
);
16501 -- Renaming declarations for generic actuals do not come from source,
16502 -- and have a different name from that of the entity they rename, so
16503 -- there is no style check to perform here.
16505 if Chars
(Nod
) = Chars
(Val_Actual
) then
16506 Style
.Check_Identifier
(Nod
, Val_Actual
);
16510 Set_Entity
(N
, Val
);
16511 end Set_Entity_With_Checks
;
16513 ------------------------
16514 -- Set_Name_Entity_Id --
16515 ------------------------
16517 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
16519 Set_Name_Table_Info
(Id
, Int
(Val
));
16520 end Set_Name_Entity_Id
;
16522 ---------------------
16523 -- Set_Next_Actual --
16524 ---------------------
16526 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
16528 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
16529 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
16531 end Set_Next_Actual
;
16533 ----------------------------------
16534 -- Set_Optimize_Alignment_Flags --
16535 ----------------------------------
16537 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
16539 if Optimize_Alignment
= 'S' then
16540 Set_Optimize_Alignment_Space
(E
);
16541 elsif Optimize_Alignment
= 'T' then
16542 Set_Optimize_Alignment_Time
(E
);
16544 end Set_Optimize_Alignment_Flags
;
16546 -----------------------
16547 -- Set_Public_Status --
16548 -----------------------
16550 procedure Set_Public_Status
(Id
: Entity_Id
) is
16551 S
: constant Entity_Id
:= Current_Scope
;
16553 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
16554 -- Determines if E is defined within handled statement sequence or
16555 -- an if statement, returns True if so, False otherwise.
16557 ----------------------
16558 -- Within_HSS_Or_If --
16559 ----------------------
16561 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
16564 N
:= Declaration_Node
(E
);
16571 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
16577 end Within_HSS_Or_If
;
16579 -- Start of processing for Set_Public_Status
16582 -- Everything in the scope of Standard is public
16584 if S
= Standard_Standard
then
16585 Set_Is_Public
(Id
);
16587 -- Entity is definitely not public if enclosing scope is not public
16589 elsif not Is_Public
(S
) then
16592 -- An object or function declaration that occurs in a handled sequence
16593 -- of statements or within an if statement is the declaration for a
16594 -- temporary object or local subprogram generated by the expander. It
16595 -- never needs to be made public and furthermore, making it public can
16596 -- cause back end problems.
16598 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
16599 N_Function_Specification
)
16600 and then Within_HSS_Or_If
(Id
)
16604 -- Entities in public packages or records are public
16606 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
16607 Set_Is_Public
(Id
);
16609 -- The bounds of an entry family declaration can generate object
16610 -- declarations that are visible to the back-end, e.g. in the
16611 -- the declaration of a composite type that contains tasks.
16613 elsif Is_Concurrent_Type
(S
)
16614 and then not Has_Completion
(S
)
16615 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
16617 Set_Is_Public
(Id
);
16619 end Set_Public_Status
;
16621 -----------------------------
16622 -- Set_Referenced_Modified --
16623 -----------------------------
16625 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
16629 -- Deal with indexed or selected component where prefix is modified
16631 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
16632 Pref
:= Prefix
(N
);
16634 -- If prefix is access type, then it is the designated object that is
16635 -- being modified, which means we have no entity to set the flag on.
16637 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
16640 -- Otherwise chase the prefix
16643 Set_Referenced_Modified
(Pref
, Out_Param
);
16646 -- Otherwise see if we have an entity name (only other case to process)
16648 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
16649 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
16650 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
16652 end Set_Referenced_Modified
;
16654 ----------------------------
16655 -- Set_Scope_Is_Transient --
16656 ----------------------------
16658 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
16660 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
16661 end Set_Scope_Is_Transient
;
16663 -------------------
16664 -- Set_Size_Info --
16665 -------------------
16667 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
16669 -- We copy Esize, but not RM_Size, since in general RM_Size is
16670 -- subtype specific and does not get inherited by all subtypes.
16672 Set_Esize
(T1
, Esize
(T2
));
16673 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
16675 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
16677 Is_Discrete_Or_Fixed_Point_Type
(T2
)
16679 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
16682 Set_Alignment
(T1
, Alignment
(T2
));
16685 --------------------
16686 -- Static_Boolean --
16687 --------------------
16689 function Static_Boolean
(N
: Node_Id
) return Uint
is
16691 Analyze_And_Resolve
(N
, Standard_Boolean
);
16694 or else Error_Posted
(N
)
16695 or else Etype
(N
) = Any_Type
16700 if Is_OK_Static_Expression
(N
) then
16701 if not Raises_Constraint_Error
(N
) then
16702 return Expr_Value
(N
);
16707 elsif Etype
(N
) = Any_Type
then
16711 Flag_Non_Static_Expr
16712 ("static boolean expression required here", N
);
16715 end Static_Boolean
;
16717 --------------------
16718 -- Static_Integer --
16719 --------------------
16721 function Static_Integer
(N
: Node_Id
) return Uint
is
16723 Analyze_And_Resolve
(N
, Any_Integer
);
16726 or else Error_Posted
(N
)
16727 or else Etype
(N
) = Any_Type
16732 if Is_OK_Static_Expression
(N
) then
16733 if not Raises_Constraint_Error
(N
) then
16734 return Expr_Value
(N
);
16739 elsif Etype
(N
) = Any_Type
then
16743 Flag_Non_Static_Expr
16744 ("static integer expression required here", N
);
16747 end Static_Integer
;
16749 --------------------------
16750 -- Statically_Different --
16751 --------------------------
16753 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
16754 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
16755 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
16757 return Is_Entity_Name
(R1
)
16758 and then Is_Entity_Name
(R2
)
16759 and then Entity
(R1
) /= Entity
(R2
)
16760 and then not Is_Formal
(Entity
(R1
))
16761 and then not Is_Formal
(Entity
(R2
));
16762 end Statically_Different
;
16764 --------------------------------------
16765 -- Subject_To_Loop_Entry_Attributes --
16766 --------------------------------------
16768 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
16774 -- The expansion mechanism transform a loop subject to at least one
16775 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
16776 -- the conditional part.
16778 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
16779 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
16781 Stmt
:= Original_Node
(N
);
16785 Nkind
(Stmt
) = N_Loop_Statement
16786 and then Present
(Identifier
(Stmt
))
16787 and then Present
(Entity
(Identifier
(Stmt
)))
16788 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
16789 end Subject_To_Loop_Entry_Attributes
;
16791 -----------------------------
16792 -- Subprogram_Access_Level --
16793 -----------------------------
16795 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
16797 if Present
(Alias
(Subp
)) then
16798 return Subprogram_Access_Level
(Alias
(Subp
));
16800 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
16802 end Subprogram_Access_Level
;
16804 -------------------------------
16805 -- Support_Atomic_Primitives --
16806 -------------------------------
16808 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
16812 -- Verify the alignment of Typ is known
16814 if not Known_Alignment
(Typ
) then
16818 if Known_Static_Esize
(Typ
) then
16819 Size
:= UI_To_Int
(Esize
(Typ
));
16821 -- If the Esize (Object_Size) is unknown at compile time, look at the
16822 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
16824 elsif Known_Static_RM_Size
(Typ
) then
16825 Size
:= UI_To_Int
(RM_Size
(Typ
));
16827 -- Otherwise, the size is considered to be unknown.
16833 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
16834 -- Typ is properly aligned.
16837 when 8 |
16 |
32 |
64 =>
16838 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
16842 end Support_Atomic_Primitives
;
16848 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
16850 if Debug_Flag_W
then
16851 for J
in 0 .. Scope_Stack
.Last
loop
16856 Write_Name
(Chars
(E
));
16857 Write_Str
(" from ");
16858 Write_Location
(Sloc
(N
));
16863 -----------------------
16864 -- Transfer_Entities --
16865 -----------------------
16867 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
16868 Ent
: Entity_Id
:= First_Entity
(From
);
16875 if (Last_Entity
(To
)) = Empty
then
16876 Set_First_Entity
(To
, Ent
);
16878 Set_Next_Entity
(Last_Entity
(To
), Ent
);
16881 Set_Last_Entity
(To
, Last_Entity
(From
));
16883 while Present
(Ent
) loop
16884 Set_Scope
(Ent
, To
);
16886 if not Is_Public
(Ent
) then
16887 Set_Public_Status
(Ent
);
16889 if Is_Public
(Ent
) and then Ekind
(Ent
) = E_Record_Subtype
then
16891 -- The components of the propagated Itype must also be public
16896 Comp
:= First_Entity
(Ent
);
16897 while Present
(Comp
) loop
16898 Set_Is_Public
(Comp
);
16899 Next_Entity
(Comp
);
16908 Set_First_Entity
(From
, Empty
);
16909 Set_Last_Entity
(From
, Empty
);
16910 end Transfer_Entities
;
16912 -----------------------
16913 -- Type_Access_Level --
16914 -----------------------
16916 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
16920 Btyp
:= Base_Type
(Typ
);
16922 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
16923 -- simply use the level where the type is declared. This is true for
16924 -- stand-alone object declarations, and for anonymous access types
16925 -- associated with components the level is the same as that of the
16926 -- enclosing composite type. However, special treatment is needed for
16927 -- the cases of access parameters, return objects of an anonymous access
16928 -- type, and, in Ada 95, access discriminants of limited types.
16930 if Is_Access_Type
(Btyp
) then
16931 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
16933 -- If the type is a nonlocal anonymous access type (such as for
16934 -- an access parameter) we treat it as being declared at the
16935 -- library level to ensure that names such as X.all'access don't
16936 -- fail static accessibility checks.
16938 if not Is_Local_Anonymous_Access
(Typ
) then
16939 return Scope_Depth
(Standard_Standard
);
16941 -- If this is a return object, the accessibility level is that of
16942 -- the result subtype of the enclosing function. The test here is
16943 -- little complicated, because we have to account for extended
16944 -- return statements that have been rewritten as blocks, in which
16945 -- case we have to find and the Is_Return_Object attribute of the
16946 -- itype's associated object. It would be nice to find a way to
16947 -- simplify this test, but it doesn't seem worthwhile to add a new
16948 -- flag just for purposes of this test. ???
16950 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
16953 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
16954 N_Object_Declaration
16955 and then Is_Return_Object
16956 (Defining_Identifier
16957 (Associated_Node_For_Itype
(Btyp
))))
16963 Scop
:= Scope
(Scope
(Btyp
));
16964 while Present
(Scop
) loop
16965 exit when Ekind
(Scop
) = E_Function
;
16966 Scop
:= Scope
(Scop
);
16969 -- Treat the return object's type as having the level of the
16970 -- function's result subtype (as per RM05-6.5(5.3/2)).
16972 return Type_Access_Level
(Etype
(Scop
));
16977 Btyp
:= Root_Type
(Btyp
);
16979 -- The accessibility level of anonymous access types associated with
16980 -- discriminants is that of the current instance of the type, and
16981 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
16983 -- AI-402: access discriminants have accessibility based on the
16984 -- object rather than the type in Ada 2005, so the above paragraph
16987 -- ??? Needs completion with rules from AI-416
16989 if Ada_Version
<= Ada_95
16990 and then Ekind
(Typ
) = E_Anonymous_Access_Type
16991 and then Present
(Associated_Node_For_Itype
(Typ
))
16992 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
16993 N_Discriminant_Specification
16995 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
16999 -- Return library level for a generic formal type. This is done because
17000 -- RM(10.3.2) says that "The statically deeper relationship does not
17001 -- apply to ... a descendant of a generic formal type". Rather than
17002 -- checking at each point where a static accessibility check is
17003 -- performed to see if we are dealing with a formal type, this rule is
17004 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17005 -- return extreme values for a formal type; Deepest_Type_Access_Level
17006 -- returns Int'Last. By calling the appropriate function from among the
17007 -- two, we ensure that the static accessibility check will pass if we
17008 -- happen to run into a formal type. More specifically, we should call
17009 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17010 -- call occurs as part of a static accessibility check and the error
17011 -- case is the case where the type's level is too shallow (as opposed
17014 if Is_Generic_Type
(Root_Type
(Btyp
)) then
17015 return Scope_Depth
(Standard_Standard
);
17018 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
17019 end Type_Access_Level
;
17021 ------------------------------------
17022 -- Type_Without_Stream_Operation --
17023 ------------------------------------
17025 function Type_Without_Stream_Operation
17027 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
17029 BT
: constant Entity_Id
:= Base_Type
(T
);
17030 Op_Missing
: Boolean;
17033 if not Restriction_Active
(No_Default_Stream_Attributes
) then
17037 if Is_Elementary_Type
(T
) then
17038 if Op
= TSS_Null
then
17040 No
(TSS
(BT
, TSS_Stream_Read
))
17041 or else No
(TSS
(BT
, TSS_Stream_Write
));
17044 Op_Missing
:= No
(TSS
(BT
, Op
));
17053 elsif Is_Array_Type
(T
) then
17054 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
17056 elsif Is_Record_Type
(T
) then
17062 Comp
:= First_Component
(T
);
17063 while Present
(Comp
) loop
17064 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
17066 if Present
(C_Typ
) then
17070 Next_Component
(Comp
);
17076 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
17077 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
17081 end Type_Without_Stream_Operation
;
17083 ----------------------------
17084 -- Unique_Defining_Entity --
17085 ----------------------------
17087 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
17089 return Unique_Entity
(Defining_Entity
(N
));
17090 end Unique_Defining_Entity
;
17092 -------------------
17093 -- Unique_Entity --
17094 -------------------
17096 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
17097 U
: Entity_Id
:= E
;
17103 if Present
(Full_View
(E
)) then
17104 U
:= Full_View
(E
);
17108 if Present
(Full_View
(E
)) then
17109 U
:= Full_View
(E
);
17112 when E_Package_Body
=>
17115 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17119 U
:= Corresponding_Spec
(P
);
17121 when E_Subprogram_Body
=>
17124 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17130 if Nkind
(P
) = N_Subprogram_Body_Stub
then
17131 if Present
(Library_Unit
(P
)) then
17133 -- Get to the function or procedure (generic) entity through
17134 -- the body entity.
17137 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
17140 U
:= Corresponding_Spec
(P
);
17143 when Formal_Kind
=>
17144 if Present
(Spec_Entity
(E
)) then
17145 U
:= Spec_Entity
(E
);
17159 function Unique_Name
(E
: Entity_Id
) return String is
17161 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17162 -- reliable, as they may not include the overloading suffix. Instead,
17163 -- when looking for the name of E or one of its enclosing scope, we get
17164 -- the name of the corresponding Unique_Entity.
17166 function Get_Scoped_Name
(E
: Entity_Id
) return String;
17167 -- Return the name of E prefixed by all the names of the scopes to which
17168 -- E belongs, except for Standard.
17170 ---------------------
17171 -- Get_Scoped_Name --
17172 ---------------------
17174 function Get_Scoped_Name
(E
: Entity_Id
) return String is
17175 Name
: constant String := Get_Name_String
(Chars
(E
));
17177 if Has_Fully_Qualified_Name
(E
)
17178 or else Scope
(E
) = Standard_Standard
17182 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
17184 end Get_Scoped_Name
;
17186 -- Start of processing for Unique_Name
17189 if E
= Standard_Standard
then
17190 return Get_Name_String
(Name_Standard
);
17192 elsif Scope
(E
) = Standard_Standard
17193 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
17195 return Get_Name_String
(Name_Standard
) & "__" &
17196 Get_Name_String
(Chars
(E
));
17198 elsif Ekind
(E
) = E_Enumeration_Literal
then
17199 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
17202 return Get_Scoped_Name
(Unique_Entity
(E
));
17206 ---------------------
17207 -- Unit_Is_Visible --
17208 ---------------------
17210 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
17211 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
17212 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
17214 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
17215 -- For a child unit, check whether unit appears in a with_clause
17218 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
17219 -- Scan the context clause of one compilation unit looking for a
17220 -- with_clause for the unit in question.
17222 ----------------------------
17223 -- Unit_In_Parent_Context --
17224 ----------------------------
17226 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
17228 if Unit_In_Context
(Par_Unit
) then
17231 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
17232 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
17237 end Unit_In_Parent_Context
;
17239 ---------------------
17240 -- Unit_In_Context --
17241 ---------------------
17243 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
17247 Clause
:= First
(Context_Items
(Comp_Unit
));
17248 while Present
(Clause
) loop
17249 if Nkind
(Clause
) = N_With_Clause
then
17250 if Library_Unit
(Clause
) = U
then
17253 -- The with_clause may denote a renaming of the unit we are
17254 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17257 Renamed_Entity
(Entity
(Name
(Clause
))) =
17258 Defining_Entity
(Unit
(U
))
17268 end Unit_In_Context
;
17270 -- Start of processing for Unit_Is_Visible
17273 -- The currrent unit is directly visible
17278 elsif Unit_In_Context
(Curr
) then
17281 -- If the current unit is a body, check the context of the spec
17283 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
17285 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
17286 and then not Acts_As_Spec
(Unit
(Curr
)))
17288 if Unit_In_Context
(Library_Unit
(Curr
)) then
17293 -- If the spec is a child unit, examine the parents
17295 if Is_Child_Unit
(Curr_Entity
) then
17296 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
17298 Unit_In_Parent_Context
17299 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
17301 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
17307 end Unit_Is_Visible
;
17309 ------------------------------
17310 -- Universal_Interpretation --
17311 ------------------------------
17313 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
17314 Index
: Interp_Index
;
17318 -- The argument may be a formal parameter of an operator or subprogram
17319 -- with multiple interpretations, or else an expression for an actual.
17321 if Nkind
(Opnd
) = N_Defining_Identifier
17322 or else not Is_Overloaded
(Opnd
)
17324 if Etype
(Opnd
) = Universal_Integer
17325 or else Etype
(Opnd
) = Universal_Real
17327 return Etype
(Opnd
);
17333 Get_First_Interp
(Opnd
, Index
, It
);
17334 while Present
(It
.Typ
) loop
17335 if It
.Typ
= Universal_Integer
17336 or else It
.Typ
= Universal_Real
17341 Get_Next_Interp
(Index
, It
);
17346 end Universal_Interpretation
;
17352 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
17354 -- Recurse to handle unlikely case of multiple levels of qualification
17356 if Nkind
(Expr
) = N_Qualified_Expression
then
17357 return Unqualify
(Expression
(Expr
));
17359 -- Normal case, not a qualified expression
17366 -----------------------
17367 -- Visible_Ancestors --
17368 -----------------------
17370 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
17376 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
17378 -- Collect all the parents and progenitors of Typ. If the full-view of
17379 -- private parents and progenitors is available then it is used to
17380 -- generate the list of visible ancestors; otherwise their partial
17381 -- view is added to the resulting list.
17386 Use_Full_View
=> True);
17390 Ifaces_List
=> List_2
,
17391 Exclude_Parents
=> True,
17392 Use_Full_View
=> True);
17394 -- Join the two lists. Avoid duplications because an interface may
17395 -- simultaneously be parent and progenitor of a type.
17397 Elmt
:= First_Elmt
(List_2
);
17398 while Present
(Elmt
) loop
17399 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
17404 end Visible_Ancestors
;
17406 ----------------------
17407 -- Within_Init_Proc --
17408 ----------------------
17410 function Within_Init_Proc
return Boolean is
17414 S
:= Current_Scope
;
17415 while not Is_Overloadable
(S
) loop
17416 if S
= Standard_Standard
then
17423 return Is_Init_Proc
(S
);
17424 end Within_Init_Proc
;
17430 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
17437 elsif SE
= Standard_Standard
then
17449 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
17450 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
17451 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
17453 Matching_Field
: Entity_Id
;
17454 -- Entity to give a more precise suggestion on how to write a one-
17455 -- element positional aggregate.
17457 function Has_One_Matching_Field
return Boolean;
17458 -- Determines if Expec_Type is a record type with a single component or
17459 -- discriminant whose type matches the found type or is one dimensional
17460 -- array whose component type matches the found type. In the case of
17461 -- one discriminant, we ignore the variant parts. That's not accurate,
17462 -- but good enough for the warning.
17464 ----------------------------
17465 -- Has_One_Matching_Field --
17466 ----------------------------
17468 function Has_One_Matching_Field
return Boolean is
17472 Matching_Field
:= Empty
;
17474 if Is_Array_Type
(Expec_Type
)
17475 and then Number_Dimensions
(Expec_Type
) = 1
17476 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
17478 -- Use type name if available. This excludes multidimensional
17479 -- arrays and anonymous arrays.
17481 if Comes_From_Source
(Expec_Type
) then
17482 Matching_Field
:= Expec_Type
;
17484 -- For an assignment, use name of target
17486 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
17487 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
17489 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
17494 elsif not Is_Record_Type
(Expec_Type
) then
17498 E
:= First_Entity
(Expec_Type
);
17503 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
17504 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
17513 if not Covers
(Etype
(E
), Found_Type
) then
17516 elsif Present
(Next_Entity
(E
))
17517 and then (Ekind
(E
) = E_Component
17518 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
17523 Matching_Field
:= E
;
17527 end Has_One_Matching_Field
;
17529 -- Start of processing for Wrong_Type
17532 -- Don't output message if either type is Any_Type, or if a message
17533 -- has already been posted for this node. We need to do the latter
17534 -- check explicitly (it is ordinarily done in Errout), because we
17535 -- are using ! to force the output of the error messages.
17537 if Expec_Type
= Any_Type
17538 or else Found_Type
= Any_Type
17539 or else Error_Posted
(Expr
)
17543 -- If one of the types is a Taft-Amendment type and the other it its
17544 -- completion, it must be an illegal use of a TAT in the spec, for
17545 -- which an error was already emitted. Avoid cascaded errors.
17547 elsif Is_Incomplete_Type
(Expec_Type
)
17548 and then Has_Completion_In_Body
(Expec_Type
)
17549 and then Full_View
(Expec_Type
) = Etype
(Expr
)
17553 elsif Is_Incomplete_Type
(Etype
(Expr
))
17554 and then Has_Completion_In_Body
(Etype
(Expr
))
17555 and then Full_View
(Etype
(Expr
)) = Expec_Type
17559 -- In an instance, there is an ongoing problem with completion of
17560 -- type derived from private types. Their structure is what Gigi
17561 -- expects, but the Etype is the parent type rather than the
17562 -- derived private type itself. Do not flag error in this case. The
17563 -- private completion is an entity without a parent, like an Itype.
17564 -- Similarly, full and partial views may be incorrect in the instance.
17565 -- There is no simple way to insure that it is consistent ???
17567 -- A similar view discrepancy can happen in an inlined body, for the
17568 -- same reason: inserted body may be outside of the original package
17569 -- and only partial views are visible at the point of insertion.
17571 elsif In_Instance
or else In_Inlined_Body
then
17572 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
17574 (Has_Private_Declaration
(Expected_Type
)
17575 or else Has_Private_Declaration
(Etype
(Expr
)))
17576 and then No
(Parent
(Expected_Type
))
17580 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
17581 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
17585 elsif Is_Private_Type
(Expected_Type
)
17586 and then Present
(Full_View
(Expected_Type
))
17587 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
17593 -- An interesting special check. If the expression is parenthesized
17594 -- and its type corresponds to the type of the sole component of the
17595 -- expected record type, or to the component type of the expected one
17596 -- dimensional array type, then assume we have a bad aggregate attempt.
17598 if Nkind
(Expr
) in N_Subexpr
17599 and then Paren_Count
(Expr
) /= 0
17600 and then Has_One_Matching_Field
17602 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
17603 if Present
(Matching_Field
) then
17604 if Is_Array_Type
(Expec_Type
) then
17606 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
17610 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
17614 -- Another special check, if we are looking for a pool-specific access
17615 -- type and we found an E_Access_Attribute_Type, then we have the case
17616 -- of an Access attribute being used in a context which needs a pool-
17617 -- specific type, which is never allowed. The one extra check we make
17618 -- is that the expected designated type covers the Found_Type.
17620 elsif Is_Access_Type
(Expec_Type
)
17621 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
17622 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
17623 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
17625 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
17627 Error_Msg_N
-- CODEFIX
17628 ("result must be general access type!", Expr
);
17629 Error_Msg_NE
-- CODEFIX
17630 ("add ALL to }!", Expr
, Expec_Type
);
17632 -- Another special check, if the expected type is an integer type,
17633 -- but the expression is of type System.Address, and the parent is
17634 -- an addition or subtraction operation whose left operand is the
17635 -- expression in question and whose right operand is of an integral
17636 -- type, then this is an attempt at address arithmetic, so give
17637 -- appropriate message.
17639 elsif Is_Integer_Type
(Expec_Type
)
17640 and then Is_RTE
(Found_Type
, RE_Address
)
17641 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
17642 and then Expr
= Left_Opnd
(Parent
(Expr
))
17643 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
17646 ("address arithmetic not predefined in package System",
17649 ("\possible missing with/use of System.Storage_Elements",
17653 -- If the expected type is an anonymous access type, as for access
17654 -- parameters and discriminants, the error is on the designated types.
17656 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
17657 if Comes_From_Source
(Expec_Type
) then
17658 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
17661 ("expected an access type with designated}",
17662 Expr
, Designated_Type
(Expec_Type
));
17665 if Is_Access_Type
(Found_Type
)
17666 and then not Comes_From_Source
(Found_Type
)
17669 ("\\found an access type with designated}!",
17670 Expr
, Designated_Type
(Found_Type
));
17672 if From_Limited_With
(Found_Type
) then
17673 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
17674 Error_Msg_Qual_Level
:= 99;
17675 Error_Msg_NE
-- CODEFIX
17676 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
17677 Error_Msg_Qual_Level
:= 0;
17679 Error_Msg_NE
("found}!", Expr
, Found_Type
);
17683 -- Normal case of one type found, some other type expected
17686 -- If the names of the two types are the same, see if some number
17687 -- of levels of qualification will help. Don't try more than three
17688 -- levels, and if we get to standard, it's no use (and probably
17689 -- represents an error in the compiler) Also do not bother with
17690 -- internal scope names.
17693 Expec_Scope
: Entity_Id
;
17694 Found_Scope
: Entity_Id
;
17697 Expec_Scope
:= Expec_Type
;
17698 Found_Scope
:= Found_Type
;
17700 for Levels
in Int
range 0 .. 3 loop
17701 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
17702 Error_Msg_Qual_Level
:= Levels
;
17706 Expec_Scope
:= Scope
(Expec_Scope
);
17707 Found_Scope
:= Scope
(Found_Scope
);
17709 exit when Expec_Scope
= Standard_Standard
17710 or else Found_Scope
= Standard_Standard
17711 or else not Comes_From_Source
(Expec_Scope
)
17712 or else not Comes_From_Source
(Found_Scope
);
17716 if Is_Record_Type
(Expec_Type
)
17717 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
17719 Error_Msg_NE
("expected}!", Expr
,
17720 Corresponding_Remote_Type
(Expec_Type
));
17722 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
17725 if Is_Entity_Name
(Expr
)
17726 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
17728 Error_Msg_N
("\\found package name!", Expr
);
17730 elsif Is_Entity_Name
(Expr
)
17731 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
17733 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
17735 ("found procedure name, possibly missing Access attribute!",
17739 ("\\found procedure name instead of function!", Expr
);
17742 elsif Nkind
(Expr
) = N_Function_Call
17743 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
17744 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
17745 and then No
(Parameter_Associations
(Expr
))
17748 ("found function name, possibly missing Access attribute!",
17751 -- Catch common error: a prefix or infix operator which is not
17752 -- directly visible because the type isn't.
17754 elsif Nkind
(Expr
) in N_Op
17755 and then Is_Overloaded
(Expr
)
17756 and then not Is_Immediately_Visible
(Expec_Type
)
17757 and then not Is_Potentially_Use_Visible
(Expec_Type
)
17758 and then not In_Use
(Expec_Type
)
17759 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
17762 ("operator of the type is not directly visible!", Expr
);
17764 elsif Ekind
(Found_Type
) = E_Void
17765 and then Present
(Parent
(Found_Type
))
17766 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
17768 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
17771 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
17774 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
17775 -- of the same modular type, and (M1 and M2) = 0 was intended.
17777 if Expec_Type
= Standard_Boolean
17778 and then Is_Modular_Integer_Type
(Found_Type
)
17779 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
17780 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
17783 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
17784 L
: constant Node_Id
:= Left_Opnd
(Op
);
17785 R
: constant Node_Id
:= Right_Opnd
(Op
);
17787 -- The case for the message is when the left operand of the
17788 -- comparison is the same modular type, or when it is an
17789 -- integer literal (or other universal integer expression),
17790 -- which would have been typed as the modular type if the
17791 -- parens had been there.
17793 if (Etype
(L
) = Found_Type
17795 Etype
(L
) = Universal_Integer
)
17796 and then Is_Integer_Type
(Etype
(R
))
17799 ("\\possible missing parens for modular operation", Expr
);
17804 -- Reset error message qualification indication
17806 Error_Msg_Qual_Level
:= 0;