1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, 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 Has_Enabled_Property
114 (Item_Id
: Entity_Id
;
115 Property
: Name_Id
) return Boolean;
116 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
117 -- Determine whether an abstract state or a variable denoted by entity
118 -- Item_Id has enabled property Property.
120 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
121 -- T is a derived tagged type. Check whether the type extension is null.
122 -- If the parent type is fully initialized, T can be treated as such.
124 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
125 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
126 -- with discriminants whose default values are static, examine only the
127 -- components in the selected variant to determine whether all of them
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
);
255 procedure Add_Classification
;
256 -- Prepend Prag to the list of classifications
258 procedure Add_Contract_Test_Case
;
259 -- Prepend Prag to the list of contract and test cases
261 procedure Add_Pre_Post_Condition
;
262 -- Prepend Prag to the list of pre- and postconditions
264 ------------------------
265 -- Add_Classification --
266 ------------------------
268 procedure Add_Classification
is
270 Set_Next_Pragma
(Prag
, Classifications
(Items
));
271 Set_Classifications
(Items
, Prag
);
272 end Add_Classification
;
274 ----------------------------
275 -- Add_Contract_Test_Case --
276 ----------------------------
278 procedure Add_Contract_Test_Case
is
280 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
281 Set_Contract_Test_Cases
(Items
, Prag
);
282 end Add_Contract_Test_Case
;
284 ----------------------------
285 -- Add_Pre_Post_Condition --
286 ----------------------------
288 procedure Add_Pre_Post_Condition
is
290 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
291 Set_Pre_Post_Conditions
(Items
, Prag
);
292 end Add_Pre_Post_Condition
;
299 -- Start of processing for Add_Contract_Item
302 -- The related context must have a contract and the item to be added
305 pragma Assert
(Present
(Items
));
306 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
308 Nam
:= Original_Aspect_Name
(Prag
);
310 -- Contract items related to [generic] packages or instantiations. The
311 -- applicable pragmas are:
315 -- Part_Of (instantiation only)
317 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
318 if Nam_In
(Nam
, Name_Abstract_State
,
319 Name_Initial_Condition
,
324 -- Indicator Part_Of must be associated with a package instantiation
326 elsif Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) then
329 -- The pragma is not a proper contract item
335 -- Contract items related to package bodies. The applicable pragmas are:
338 elsif Ekind
(Id
) = E_Package_Body
then
339 if Nam
= Name_Refined_State
then
342 -- The pragma is not a proper contract item
348 -- Contract items related to subprogram or entry declarations. The
349 -- applicable pragmas are:
352 -- Extensions_Visible
360 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
361 or else Is_Generic_Subprogram
(Id
)
362 or else Is_Subprogram
(Id
)
364 if Nam_In
(Nam
, Name_Pre
,
371 -- Before we add a precondition or postcondition to the list, make
372 -- sure we do not have a disallowed duplicate, which can happen if
373 -- we use a pragma for Pre[_Class] or Post[_Class] instead of the
374 -- corresponding aspect.
376 if not From_Aspect_Specification
(Prag
)
377 and then Nam_In
(Nam
, Name_Pre
,
382 PPC
:= Pre_Post_Conditions
(Items
);
383 while Present
(PPC
) loop
384 if not Split_PPC
(PPC
)
385 and then Original_Aspect_Name
(PPC
) = Nam
387 Error_Msg_Sloc
:= Sloc
(PPC
);
389 ("duplication of aspect for & given#", Prag
, Id
);
393 PPC
:= Next_Pragma
(PPC
);
397 Add_Pre_Post_Condition
;
399 elsif Nam_In
(Nam
, Name_Contract_Cases
, Name_Test_Case
) then
400 Add_Contract_Test_Case
;
402 elsif Nam_In
(Nam
, Name_Depends
,
403 Name_Extensions_Visible
,
408 -- The pragma is not a proper contract item
414 -- Contract items related to subprogram bodies. Applicable pragmas are:
419 elsif Ekind
(Id
) = E_Subprogram_Body
then
420 if Nam_In
(Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
423 elsif Nam
= Name_Refined_Post
then
424 Add_Pre_Post_Condition
;
426 -- The pragma is not a proper contract item
432 -- Contract items related to variables. Applicable pragmas are:
439 elsif Ekind
(Id
) = E_Variable
then
440 if Nam_In
(Nam
, Name_Async_Readers
,
442 Name_Effective_Reads
,
443 Name_Effective_Writes
,
448 -- The pragma is not a proper contract item
454 end Add_Contract_Item
;
456 ----------------------------
457 -- Add_Global_Declaration --
458 ----------------------------
460 procedure Add_Global_Declaration
(N
: Node_Id
) is
461 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
464 if No
(Declarations
(Aux_Node
)) then
465 Set_Declarations
(Aux_Node
, New_List
);
468 Append_To
(Declarations
(Aux_Node
), N
);
470 end Add_Global_Declaration
;
472 --------------------------------
473 -- Address_Integer_Convert_OK --
474 --------------------------------
476 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
478 if Allow_Integer_Address
479 and then ((Is_Descendent_Of_Address
(T1
)
480 and then Is_Private_Type
(T1
)
481 and then Is_Integer_Type
(T2
))
483 (Is_Descendent_Of_Address
(T2
)
484 and then Is_Private_Type
(T2
)
485 and then Is_Integer_Type
(T1
)))
491 end Address_Integer_Convert_OK
;
497 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
499 function Addressable
(V
: Uint
) return Boolean is
501 return V
= Uint_8
or else
507 function Addressable
(V
: Int
) return Boolean is
515 ---------------------------------
516 -- Aggregate_Constraint_Checks --
517 ---------------------------------
519 procedure Aggregate_Constraint_Checks
521 Check_Typ
: Entity_Id
)
523 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
526 if Raises_Constraint_Error
(Exp
) then
530 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
531 -- component's type to force the appropriate accessibility checks.
533 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
534 -- type to force the corresponding run-time check
536 if Is_Access_Type
(Check_Typ
)
537 and then ((Is_Local_Anonymous_Access
(Check_Typ
))
538 or else (Can_Never_Be_Null
(Check_Typ
)
539 and then not Can_Never_Be_Null
(Exp_Typ
)))
541 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
542 Analyze_And_Resolve
(Exp
, Check_Typ
);
543 Check_Unset_Reference
(Exp
);
546 -- This is really expansion activity, so make sure that expansion is
547 -- on and is allowed. In GNATprove mode, we also want check flags to
548 -- be added in the tree, so that the formal verification can rely on
549 -- those to be present. In GNATprove mode for formal verification, some
550 -- treatment typically only done during expansion needs to be performed
551 -- on the tree, but it should not be applied inside generics. Otherwise,
552 -- this breaks the name resolution mechanism for generic instances.
554 if not Expander_Active
555 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
560 -- First check if we have to insert discriminant checks
562 if Has_Discriminants
(Exp_Typ
) then
563 Apply_Discriminant_Check
(Exp
, Check_Typ
);
565 -- Next emit length checks for array aggregates
567 elsif Is_Array_Type
(Exp_Typ
) then
568 Apply_Length_Check
(Exp
, Check_Typ
);
570 -- Finally emit scalar and string checks. If we are dealing with a
571 -- scalar literal we need to check by hand because the Etype of
572 -- literals is not necessarily correct.
574 elsif Is_Scalar_Type
(Exp_Typ
)
575 and then Compile_Time_Known_Value
(Exp
)
577 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
578 Apply_Compile_Time_Constraint_Error
579 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
580 Ent
=> Base_Type
(Check_Typ
),
581 Typ
=> Base_Type
(Check_Typ
));
583 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
584 Apply_Compile_Time_Constraint_Error
585 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
589 elsif not Range_Checks_Suppressed
(Check_Typ
) then
590 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
593 -- Verify that target type is also scalar, to prevent view anomalies
594 -- in instantiations.
596 elsif (Is_Scalar_Type
(Exp_Typ
)
597 or else Nkind
(Exp
) = N_String_Literal
)
598 and then Is_Scalar_Type
(Check_Typ
)
599 and then Exp_Typ
/= Check_Typ
601 if Is_Entity_Name
(Exp
)
602 and then Ekind
(Entity
(Exp
)) = E_Constant
604 -- If expression is a constant, it is worthwhile checking whether
605 -- it is a bound of the type.
607 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
608 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
610 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
611 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
616 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
617 Analyze_And_Resolve
(Exp
, Check_Typ
);
618 Check_Unset_Reference
(Exp
);
621 -- Could use a comment on this case ???
624 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
625 Analyze_And_Resolve
(Exp
, Check_Typ
);
626 Check_Unset_Reference
(Exp
);
630 end Aggregate_Constraint_Checks
;
632 -----------------------
633 -- Alignment_In_Bits --
634 -----------------------
636 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
638 return Alignment
(E
) * System_Storage_Unit
;
639 end Alignment_In_Bits
;
641 ---------------------------------
642 -- Append_Inherited_Subprogram --
643 ---------------------------------
645 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
646 Par
: constant Entity_Id
:= Alias
(S
);
647 -- The parent subprogram
649 Scop
: constant Entity_Id
:= Scope
(Par
);
650 -- The scope of definition of the parent subprogram
652 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
653 -- The derived type of which S is a primitive operation
659 if Ekind
(Current_Scope
) = E_Package
660 and then In_Private_Part
(Current_Scope
)
661 and then Has_Private_Declaration
(Typ
)
662 and then Is_Tagged_Type
(Typ
)
663 and then Scop
= Current_Scope
665 -- The inherited operation is available at the earliest place after
666 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
667 -- relevant for type extensions. If the parent operation appears
668 -- after the type extension, the operation is not visible.
671 (Visible_Declarations
672 (Package_Specification
(Current_Scope
)));
673 while Present
(Decl
) loop
674 if Nkind
(Decl
) = N_Private_Extension_Declaration
675 and then Defining_Entity
(Decl
) = Typ
677 if Sloc
(Decl
) > Sloc
(Par
) then
678 Next_E
:= Next_Entity
(Par
);
679 Set_Next_Entity
(Par
, S
);
680 Set_Next_Entity
(S
, Next_E
);
692 -- If partial view is not a type extension, or it appears before the
693 -- subprogram declaration, insert normally at end of entity list.
695 Append_Entity
(S
, Current_Scope
);
696 end Append_Inherited_Subprogram
;
698 -----------------------------------------
699 -- Apply_Compile_Time_Constraint_Error --
700 -----------------------------------------
702 procedure Apply_Compile_Time_Constraint_Error
705 Reason
: RT_Exception_Code
;
706 Ent
: Entity_Id
:= Empty
;
707 Typ
: Entity_Id
:= Empty
;
708 Loc
: Source_Ptr
:= No_Location
;
709 Rep
: Boolean := True;
710 Warn
: Boolean := False)
712 Stat
: constant Boolean := Is_Static_Expression
(N
);
713 R_Stat
: constant Node_Id
:=
714 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
725 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
731 -- Now we replace the node by an N_Raise_Constraint_Error node
732 -- This does not need reanalyzing, so set it as analyzed now.
735 Set_Analyzed
(N
, True);
738 Set_Raises_Constraint_Error
(N
);
740 -- Now deal with possible local raise handling
742 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
744 -- If the original expression was marked as static, the result is
745 -- still marked as static, but the Raises_Constraint_Error flag is
746 -- always set so that further static evaluation is not attempted.
749 Set_Is_Static_Expression
(N
);
751 end Apply_Compile_Time_Constraint_Error
;
753 ---------------------------
754 -- Async_Readers_Enabled --
755 ---------------------------
757 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
759 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
760 end Async_Readers_Enabled
;
762 ---------------------------
763 -- Async_Writers_Enabled --
764 ---------------------------
766 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
768 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
769 end Async_Writers_Enabled
;
771 --------------------------------------
772 -- Available_Full_View_Of_Component --
773 --------------------------------------
775 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
776 ST
: constant Entity_Id
:= Scope
(T
);
777 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
779 return In_Open_Scopes
(ST
)
780 and then In_Open_Scopes
(SCT
)
781 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
782 end Available_Full_View_Of_Component
;
788 procedure Bad_Attribute
791 Warn
: Boolean := False)
794 Error_Msg_Warn
:= Warn
;
795 Error_Msg_N
("unrecognized attribute&<<", N
);
797 -- Check for possible misspelling
799 Error_Msg_Name_1
:= First_Attribute_Name
;
800 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
801 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
802 Error_Msg_N
-- CODEFIX
803 ("\possible misspelling of %<<", N
);
807 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
811 --------------------------------
812 -- Bad_Predicated_Subtype_Use --
813 --------------------------------
815 procedure Bad_Predicated_Subtype_Use
819 Suggest_Static
: Boolean := False)
824 -- Avoid cascaded errors
826 if Error_Posted
(N
) then
830 if Inside_A_Generic
then
831 Gen
:= Current_Scope
;
832 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
840 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
841 Set_No_Predicate_On_Actual
(Typ
);
844 elsif Has_Predicates
(Typ
) then
845 if Is_Generic_Actual_Type
(Typ
) then
847 -- The restriction on loop parameters is only that the type
848 -- should have no dynamic predicates.
850 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
851 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
852 and then Is_OK_Static_Subtype
(Typ
)
857 Gen
:= Current_Scope
;
858 while not Is_Generic_Instance
(Gen
) loop
862 pragma Assert
(Present
(Gen
));
864 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
865 Error_Msg_Warn
:= SPARK_Mode
/= On
;
866 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
867 Error_Msg_F
("\Program_Error [<<", N
);
870 Make_Raise_Program_Error
(Sloc
(N
),
871 Reason
=> PE_Bad_Predicated_Generic_Type
));
874 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
878 Error_Msg_FE
(Msg
, N
, Typ
);
881 -- Emit an optional suggestion on how to remedy the error if the
882 -- context warrants it.
884 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
885 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
888 end Bad_Predicated_Subtype_Use
;
890 -----------------------------------------
891 -- Bad_Unordered_Enumeration_Reference --
892 -----------------------------------------
894 function Bad_Unordered_Enumeration_Reference
896 T
: Entity_Id
) return Boolean
899 return Is_Enumeration_Type
(T
)
900 and then Warn_On_Unordered_Enumeration_Type
901 and then not Is_Generic_Type
(T
)
902 and then Comes_From_Source
(N
)
903 and then not Has_Pragma_Ordered
(T
)
904 and then not In_Same_Extended_Unit
(N
, T
);
905 end Bad_Unordered_Enumeration_Reference
;
907 --------------------------
908 -- Build_Actual_Subtype --
909 --------------------------
911 function Build_Actual_Subtype
913 N
: Node_Or_Entity_Id
) return Node_Id
916 -- Normally Sloc (N), but may point to corresponding body in some cases
918 Constraints
: List_Id
;
924 Disc_Type
: Entity_Id
;
930 if Nkind
(N
) = N_Defining_Identifier
then
931 Obj
:= New_Occurrence_Of
(N
, Loc
);
933 -- If this is a formal parameter of a subprogram declaration, and
934 -- we are compiling the body, we want the declaration for the
935 -- actual subtype to carry the source position of the body, to
936 -- prevent anomalies in gdb when stepping through the code.
938 if Is_Formal
(N
) then
940 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
942 if Nkind
(Decl
) = N_Subprogram_Declaration
943 and then Present
(Corresponding_Body
(Decl
))
945 Loc
:= Sloc
(Corresponding_Body
(Decl
));
954 if Is_Array_Type
(T
) then
955 Constraints
:= New_List
;
956 for J
in 1 .. Number_Dimensions
(T
) loop
958 -- Build an array subtype declaration with the nominal subtype and
959 -- the bounds of the actual. Add the declaration in front of the
960 -- local declarations for the subprogram, for analysis before any
961 -- reference to the formal in the body.
964 Make_Attribute_Reference
(Loc
,
966 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
967 Attribute_Name
=> Name_First
,
968 Expressions
=> New_List
(
969 Make_Integer_Literal
(Loc
, J
)));
972 Make_Attribute_Reference
(Loc
,
974 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
975 Attribute_Name
=> Name_Last
,
976 Expressions
=> New_List
(
977 Make_Integer_Literal
(Loc
, J
)));
979 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
982 -- If the type has unknown discriminants there is no constrained
983 -- subtype to build. This is never called for a formal or for a
984 -- lhs, so returning the type is ok ???
986 elsif Has_Unknown_Discriminants
(T
) then
990 Constraints
:= New_List
;
992 -- Type T is a generic derived type, inherit the discriminants from
995 if Is_Private_Type
(T
)
996 and then No
(Full_View
(T
))
998 -- T was flagged as an error if it was declared as a formal
999 -- derived type with known discriminants. In this case there
1000 -- is no need to look at the parent type since T already carries
1001 -- its own discriminants.
1003 and then not Error_Posted
(T
)
1005 Disc_Type
:= Etype
(Base_Type
(T
));
1010 Discr
:= First_Discriminant
(Disc_Type
);
1011 while Present
(Discr
) loop
1012 Append_To
(Constraints
,
1013 Make_Selected_Component
(Loc
,
1015 Duplicate_Subexpr_No_Checks
(Obj
),
1016 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
1017 Next_Discriminant
(Discr
);
1021 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
1022 Set_Is_Internal
(Subt
);
1025 Make_Subtype_Declaration
(Loc
,
1026 Defining_Identifier
=> Subt
,
1027 Subtype_Indication
=>
1028 Make_Subtype_Indication
(Loc
,
1029 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1031 Make_Index_Or_Discriminant_Constraint
(Loc
,
1032 Constraints
=> Constraints
)));
1034 Mark_Rewrite_Insertion
(Decl
);
1036 end Build_Actual_Subtype
;
1038 ---------------------------------------
1039 -- Build_Actual_Subtype_Of_Component --
1040 ---------------------------------------
1042 function Build_Actual_Subtype_Of_Component
1044 N
: Node_Id
) return Node_Id
1046 Loc
: constant Source_Ptr
:= Sloc
(N
);
1047 P
: constant Node_Id
:= Prefix
(N
);
1050 Index_Typ
: Entity_Id
;
1052 Desig_Typ
: Entity_Id
;
1053 -- This is either a copy of T, or if T is an access type, then it is
1054 -- the directly designated type of this access type.
1056 function Build_Actual_Array_Constraint
return List_Id
;
1057 -- If one or more of the bounds of the component depends on
1058 -- discriminants, build actual constraint using the discriminants
1061 function Build_Actual_Record_Constraint
return List_Id
;
1062 -- Similar to previous one, for discriminated components constrained
1063 -- by the discriminant of the enclosing object.
1065 -----------------------------------
1066 -- Build_Actual_Array_Constraint --
1067 -----------------------------------
1069 function Build_Actual_Array_Constraint
return List_Id
is
1070 Constraints
: constant List_Id
:= New_List
;
1078 Indx
:= First_Index
(Desig_Typ
);
1079 while Present
(Indx
) loop
1080 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1081 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1083 if Denotes_Discriminant
(Old_Lo
) then
1085 Make_Selected_Component
(Loc
,
1086 Prefix
=> New_Copy_Tree
(P
),
1087 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1090 Lo
:= New_Copy_Tree
(Old_Lo
);
1092 -- The new bound will be reanalyzed in the enclosing
1093 -- declaration. For literal bounds that come from a type
1094 -- declaration, the type of the context must be imposed, so
1095 -- insure that analysis will take place. For non-universal
1096 -- types this is not strictly necessary.
1098 Set_Analyzed
(Lo
, False);
1101 if Denotes_Discriminant
(Old_Hi
) then
1103 Make_Selected_Component
(Loc
,
1104 Prefix
=> New_Copy_Tree
(P
),
1105 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1108 Hi
:= New_Copy_Tree
(Old_Hi
);
1109 Set_Analyzed
(Hi
, False);
1112 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1117 end Build_Actual_Array_Constraint
;
1119 ------------------------------------
1120 -- Build_Actual_Record_Constraint --
1121 ------------------------------------
1123 function Build_Actual_Record_Constraint
return List_Id
is
1124 Constraints
: constant List_Id
:= New_List
;
1129 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1130 while Present
(D
) loop
1131 if Denotes_Discriminant
(Node
(D
)) then
1132 D_Val
:= Make_Selected_Component
(Loc
,
1133 Prefix
=> New_Copy_Tree
(P
),
1134 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1137 D_Val
:= New_Copy_Tree
(Node
(D
));
1140 Append
(D_Val
, Constraints
);
1145 end Build_Actual_Record_Constraint
;
1147 -- Start of processing for Build_Actual_Subtype_Of_Component
1150 -- Why the test for Spec_Expression mode here???
1152 if In_Spec_Expression
then
1155 -- More comments for the rest of this body would be good ???
1157 elsif Nkind
(N
) = N_Explicit_Dereference
then
1158 if Is_Composite_Type
(T
)
1159 and then not Is_Constrained
(T
)
1160 and then not (Is_Class_Wide_Type
(T
)
1161 and then Is_Constrained
(Root_Type
(T
)))
1162 and then not Has_Unknown_Discriminants
(T
)
1164 -- If the type of the dereference is already constrained, it is an
1167 if Is_Array_Type
(Etype
(N
))
1168 and then Is_Constrained
(Etype
(N
))
1172 Remove_Side_Effects
(P
);
1173 return Build_Actual_Subtype
(T
, N
);
1180 if Ekind
(T
) = E_Access_Subtype
then
1181 Desig_Typ
:= Designated_Type
(T
);
1186 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1187 Id
:= First_Index
(Desig_Typ
);
1188 while Present
(Id
) loop
1189 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1191 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1193 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1195 Remove_Side_Effects
(P
);
1197 Build_Component_Subtype
1198 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1204 elsif Is_Composite_Type
(Desig_Typ
)
1205 and then Has_Discriminants
(Desig_Typ
)
1206 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1208 if Is_Private_Type
(Desig_Typ
)
1209 and then No
(Discriminant_Constraint
(Desig_Typ
))
1211 Desig_Typ
:= Full_View
(Desig_Typ
);
1214 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1215 while Present
(D
) loop
1216 if Denotes_Discriminant
(Node
(D
)) then
1217 Remove_Side_Effects
(P
);
1219 Build_Component_Subtype
(
1220 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1227 -- If none of the above, the actual and nominal subtypes are the same
1230 end Build_Actual_Subtype_Of_Component
;
1232 -----------------------------
1233 -- Build_Component_Subtype --
1234 -----------------------------
1236 function Build_Component_Subtype
1239 T
: Entity_Id
) return Node_Id
1245 -- Unchecked_Union components do not require component subtypes
1247 if Is_Unchecked_Union
(T
) then
1251 Subt
:= Make_Temporary
(Loc
, 'S');
1252 Set_Is_Internal
(Subt
);
1255 Make_Subtype_Declaration
(Loc
,
1256 Defining_Identifier
=> Subt
,
1257 Subtype_Indication
=>
1258 Make_Subtype_Indication
(Loc
,
1259 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1261 Make_Index_Or_Discriminant_Constraint
(Loc
,
1262 Constraints
=> C
)));
1264 Mark_Rewrite_Insertion
(Decl
);
1266 end Build_Component_Subtype
;
1268 ----------------------------------
1269 -- Build_Default_Init_Cond_Call --
1270 ----------------------------------
1272 function Build_Default_Init_Cond_Call
1275 Typ
: Entity_Id
) return Node_Id
1277 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1278 Formal_Typ
: constant Entity_Id
:= Etype
(First_Formal
(Proc_Id
));
1282 Make_Procedure_Call_Statement
(Loc
,
1283 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
1284 Parameter_Associations
=> New_List
(
1285 Make_Unchecked_Type_Conversion
(Loc
,
1286 Subtype_Mark
=> New_Occurrence_Of
(Formal_Typ
, Loc
),
1287 Expression
=> New_Occurrence_Of
(Obj_Id
, Loc
))));
1288 end Build_Default_Init_Cond_Call
;
1290 ----------------------------------------------
1291 -- Build_Default_Init_Cond_Procedure_Bodies --
1292 ----------------------------------------------
1294 procedure Build_Default_Init_Cond_Procedure_Bodies
(Priv_Decls
: List_Id
) is
1295 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
);
1296 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1297 -- body of the procedure which verifies the assumption of the pragma at
1298 -- run time. The generated body is added after the type declaration.
1300 --------------------------------------------
1301 -- Build_Default_Init_Cond_Procedure_Body --
1302 --------------------------------------------
1304 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
) is
1305 Param_Id
: Entity_Id
;
1306 -- The entity of the sole formal parameter of the default initial
1307 -- condition procedure.
1309 procedure Replace_Type_Reference
(N
: Node_Id
);
1310 -- Replace a single reference to type Typ with a reference to formal
1311 -- parameter Param_Id.
1313 ----------------------------
1314 -- Replace_Type_Reference --
1315 ----------------------------
1317 procedure Replace_Type_Reference
(N
: Node_Id
) is
1319 Rewrite
(N
, New_Occurrence_Of
(Param_Id
, Sloc
(N
)));
1320 end Replace_Type_Reference
;
1322 procedure Replace_Type_References
is
1323 new Replace_Type_References_Generic
(Replace_Type_Reference
);
1327 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1328 Prag
: constant Node_Id
:=
1329 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1330 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1331 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Proc_Id
);
1332 Body_Decl
: Node_Id
;
1336 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1339 -- The procedure should be generated only for [sub]types subject to
1340 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1341 -- not get this specialized procedure.
1343 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1344 pragma Assert
(Present
(Prag
));
1345 pragma Assert
(Present
(Proc_Id
));
1347 -- Nothing to do if the body was already built
1349 if Present
(Corresponding_Body
(Spec_Decl
)) then
1353 Param_Id
:= First_Formal
(Proc_Id
);
1355 -- The pragma has an argument. Note that the argument is analyzed
1356 -- after all references to the current instance of the type are
1359 if Present
(Pragma_Argument_Associations
(Prag
)) then
1361 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
1363 if Nkind
(Expr
) = N_Null
then
1364 Stmt
:= Make_Null_Statement
(Loc
);
1366 -- Preserve the original argument of the pragma by replicating it.
1367 -- Replace all references to the current instance of the type with
1368 -- references to the formal parameter.
1371 Expr
:= New_Copy_Tree
(Expr
);
1372 Replace_Type_References
(Expr
, Typ
);
1375 -- pragma Check (Default_Initial_Condition, <Expr>);
1379 Pragma_Identifier
=>
1380 Make_Identifier
(Loc
, Name_Check
),
1382 Pragma_Argument_Associations
=> New_List
(
1383 Make_Pragma_Argument_Association
(Loc
,
1385 Make_Identifier
(Loc
,
1386 Chars
=> Name_Default_Initial_Condition
)),
1387 Make_Pragma_Argument_Association
(Loc
,
1388 Expression
=> Expr
)));
1391 -- Otherwise the pragma appears without an argument
1394 Stmt
:= Make_Null_Statement
(Loc
);
1398 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1401 -- end <Typ>Default_Init_Cond;
1404 Make_Subprogram_Body
(Loc
,
1406 Copy_Separate_Tree
(Specification
(Spec_Decl
)),
1407 Declarations
=> Empty_List
,
1408 Handled_Statement_Sequence
=>
1409 Make_Handled_Sequence_Of_Statements
(Loc
,
1410 Statements
=> New_List
(Stmt
)));
1412 -- Link the spec and body of the default initial condition procedure
1413 -- to prevent the generation of a duplicate body.
1415 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
1416 Set_Corresponding_Spec
(Body_Decl
, Proc_Id
);
1418 Insert_After_And_Analyze
(Declaration_Node
(Typ
), Body_Decl
);
1419 end Build_Default_Init_Cond_Procedure_Body
;
1426 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1429 -- Inspect the private declarations looking for [sub]type declarations
1431 Decl
:= First
(Priv_Decls
);
1432 while Present
(Decl
) loop
1433 if Nkind_In
(Decl
, N_Full_Type_Declaration
,
1434 N_Subtype_Declaration
)
1436 Typ
:= Defining_Entity
(Decl
);
1438 -- Guard against partially decorate types due to previous errors
1440 if Is_Type
(Typ
) then
1442 -- If the type is subject to pragma Default_Initial_Condition,
1443 -- generate the body of the internal procedure which verifies
1444 -- the assertion of the pragma at run time.
1446 if Has_Default_Init_Cond
(Typ
) then
1447 Build_Default_Init_Cond_Procedure_Body
(Typ
);
1449 -- A derived type inherits the default initial condition
1450 -- procedure from its parent type.
1452 elsif Has_Inherited_Default_Init_Cond
(Typ
) then
1453 Inherit_Default_Init_Cond_Procedure
(Typ
);
1460 end Build_Default_Init_Cond_Procedure_Bodies
;
1462 ---------------------------------------------------
1463 -- Build_Default_Init_Cond_Procedure_Declaration --
1464 ---------------------------------------------------
1466 procedure Build_Default_Init_Cond_Procedure_Declaration
(Typ
: Entity_Id
) is
1467 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1468 Prag
: constant Node_Id
:=
1469 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1470 Proc_Id
: Entity_Id
;
1473 -- The procedure should be generated only for types subject to pragma
1474 -- Default_Initial_Condition. Types that inherit the pragma do not get
1475 -- this specialized procedure.
1477 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1478 pragma Assert
(Present
(Prag
));
1480 -- Nothing to do if default initial condition procedure already built
1482 if Present
(Default_Init_Cond_Procedure
(Typ
)) then
1487 Make_Defining_Identifier
(Loc
,
1488 Chars
=> New_External_Name
(Chars
(Typ
), "Default_Init_Cond"));
1490 -- Associate default initial condition procedure with the private type
1492 Set_Ekind
(Proc_Id
, E_Procedure
);
1493 Set_Is_Default_Init_Cond_Procedure
(Proc_Id
);
1494 Set_Default_Init_Cond_Procedure
(Typ
, Proc_Id
);
1497 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1499 Insert_After_And_Analyze
(Prag
,
1500 Make_Subprogram_Declaration
(Loc
,
1502 Make_Procedure_Specification
(Loc
,
1503 Defining_Unit_Name
=> Proc_Id
,
1504 Parameter_Specifications
=> New_List
(
1505 Make_Parameter_Specification
(Loc
,
1506 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
1507 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))))));
1508 end Build_Default_Init_Cond_Procedure_Declaration
;
1510 ---------------------------
1511 -- Build_Default_Subtype --
1512 ---------------------------
1514 function Build_Default_Subtype
1516 N
: Node_Id
) return Entity_Id
1518 Loc
: constant Source_Ptr
:= Sloc
(N
);
1522 -- The base type that is to be constrained by the defaults
1525 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1529 Bas
:= Base_Type
(T
);
1531 -- If T is non-private but its base type is private, this is the
1532 -- completion of a subtype declaration whose parent type is private
1533 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1534 -- are to be found in the full view of the base. Check that the private
1535 -- status of T and its base differ.
1537 if Is_Private_Type
(Bas
)
1538 and then not Is_Private_Type
(T
)
1539 and then Present
(Full_View
(Bas
))
1541 Bas
:= Full_View
(Bas
);
1544 Disc
:= First_Discriminant
(T
);
1546 if No
(Discriminant_Default_Value
(Disc
)) then
1551 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1552 Constraints
: constant List_Id
:= New_List
;
1556 while Present
(Disc
) loop
1557 Append_To
(Constraints
,
1558 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1559 Next_Discriminant
(Disc
);
1563 Make_Subtype_Declaration
(Loc
,
1564 Defining_Identifier
=> Act
,
1565 Subtype_Indication
=>
1566 Make_Subtype_Indication
(Loc
,
1567 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1569 Make_Index_Or_Discriminant_Constraint
(Loc
,
1570 Constraints
=> Constraints
)));
1572 Insert_Action
(N
, Decl
);
1576 end Build_Default_Subtype
;
1578 --------------------------------------------
1579 -- Build_Discriminal_Subtype_Of_Component --
1580 --------------------------------------------
1582 function Build_Discriminal_Subtype_Of_Component
1583 (T
: Entity_Id
) return Node_Id
1585 Loc
: constant Source_Ptr
:= Sloc
(T
);
1589 function Build_Discriminal_Array_Constraint
return List_Id
;
1590 -- If one or more of the bounds of the component depends on
1591 -- discriminants, build actual constraint using the discriminants
1594 function Build_Discriminal_Record_Constraint
return List_Id
;
1595 -- Similar to previous one, for discriminated components constrained by
1596 -- the discriminant of the enclosing object.
1598 ----------------------------------------
1599 -- Build_Discriminal_Array_Constraint --
1600 ----------------------------------------
1602 function Build_Discriminal_Array_Constraint
return List_Id
is
1603 Constraints
: constant List_Id
:= New_List
;
1611 Indx
:= First_Index
(T
);
1612 while Present
(Indx
) loop
1613 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1614 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1616 if Denotes_Discriminant
(Old_Lo
) then
1617 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1620 Lo
:= New_Copy_Tree
(Old_Lo
);
1623 if Denotes_Discriminant
(Old_Hi
) then
1624 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1627 Hi
:= New_Copy_Tree
(Old_Hi
);
1630 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1635 end Build_Discriminal_Array_Constraint
;
1637 -----------------------------------------
1638 -- Build_Discriminal_Record_Constraint --
1639 -----------------------------------------
1641 function Build_Discriminal_Record_Constraint
return List_Id
is
1642 Constraints
: constant List_Id
:= New_List
;
1647 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1648 while Present
(D
) loop
1649 if Denotes_Discriminant
(Node
(D
)) then
1651 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1653 D_Val
:= New_Copy_Tree
(Node
(D
));
1656 Append
(D_Val
, Constraints
);
1661 end Build_Discriminal_Record_Constraint
;
1663 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1666 if Ekind
(T
) = E_Array_Subtype
then
1667 Id
:= First_Index
(T
);
1668 while Present
(Id
) loop
1669 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1671 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1673 return Build_Component_Subtype
1674 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1680 elsif Ekind
(T
) = E_Record_Subtype
1681 and then Has_Discriminants
(T
)
1682 and then not Has_Unknown_Discriminants
(T
)
1684 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1685 while Present
(D
) loop
1686 if Denotes_Discriminant
(Node
(D
)) then
1687 return Build_Component_Subtype
1688 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1695 -- If none of the above, the actual and nominal subtypes are the same
1698 end Build_Discriminal_Subtype_Of_Component
;
1700 ------------------------------
1701 -- Build_Elaboration_Entity --
1702 ------------------------------
1704 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1705 Loc
: constant Source_Ptr
:= Sloc
(N
);
1707 Elab_Ent
: Entity_Id
;
1709 procedure Set_Package_Name
(Ent
: Entity_Id
);
1710 -- Given an entity, sets the fully qualified name of the entity in
1711 -- Name_Buffer, with components separated by double underscores. This
1712 -- is a recursive routine that climbs the scope chain to Standard.
1714 ----------------------
1715 -- Set_Package_Name --
1716 ----------------------
1718 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1720 if Scope
(Ent
) /= Standard_Standard
then
1721 Set_Package_Name
(Scope
(Ent
));
1724 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1726 Name_Buffer
(Name_Len
+ 1) := '_';
1727 Name_Buffer
(Name_Len
+ 2) := '_';
1728 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1729 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1733 Get_Name_String
(Chars
(Ent
));
1735 end Set_Package_Name
;
1737 -- Start of processing for Build_Elaboration_Entity
1740 -- Ignore call if already constructed
1742 if Present
(Elaboration_Entity
(Spec_Id
)) then
1745 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1746 -- no role in analysis.
1748 elsif ASIS_Mode
then
1751 -- See if we need elaboration entity. We always need it for the dynamic
1752 -- elaboration model, since it is needed to properly generate the PE
1753 -- exception for access before elaboration.
1755 elsif Dynamic_Elaboration_Checks
then
1758 -- For the static model, we don't need the elaboration counter if this
1759 -- unit is sure to have no elaboration code, since that means there
1760 -- is no elaboration unit to be called. Note that we can't just decide
1761 -- after the fact by looking to see whether there was elaboration code,
1762 -- because that's too late to make this decision.
1764 elsif Restriction_Active
(No_Elaboration_Code
) then
1767 -- Similarly, for the static model, we can skip the elaboration counter
1768 -- if we have the No_Multiple_Elaboration restriction, since for the
1769 -- static model, that's the only purpose of the counter (to avoid
1770 -- multiple elaboration).
1772 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1776 -- Here we need the elaboration entity
1778 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1779 -- name with dots replaced by double underscore. We have to manually
1780 -- construct this name, since it will be elaborated in the outer scope,
1781 -- and thus will not have the unit name automatically prepended.
1783 Set_Package_Name
(Spec_Id
);
1784 Add_Str_To_Name_Buffer
("_E");
1786 -- Create elaboration counter
1788 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1789 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1792 Make_Object_Declaration
(Loc
,
1793 Defining_Identifier
=> Elab_Ent
,
1794 Object_Definition
=>
1795 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1796 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1798 Push_Scope
(Standard_Standard
);
1799 Add_Global_Declaration
(Decl
);
1802 -- Reset True_Constant indication, since we will indeed assign a value
1803 -- to the variable in the binder main. We also kill the Current_Value
1804 -- and Last_Assignment fields for the same reason.
1806 Set_Is_True_Constant
(Elab_Ent
, False);
1807 Set_Current_Value
(Elab_Ent
, Empty
);
1808 Set_Last_Assignment
(Elab_Ent
, Empty
);
1810 -- We do not want any further qualification of the name (if we did not
1811 -- do this, we would pick up the name of the generic package in the case
1812 -- of a library level generic instantiation).
1814 Set_Has_Qualified_Name
(Elab_Ent
);
1815 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1816 end Build_Elaboration_Entity
;
1818 --------------------------------
1819 -- Build_Explicit_Dereference --
1820 --------------------------------
1822 procedure Build_Explicit_Dereference
1826 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1829 -- An entity of a type with a reference aspect is overloaded with
1830 -- both interpretations: with and without the dereference. Now that
1831 -- the dereference is made explicit, set the type of the node properly,
1832 -- to prevent anomalies in the backend. Same if the expression is an
1833 -- overloaded function call whose return type has a reference aspect.
1835 if Is_Entity_Name
(Expr
) then
1836 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1838 elsif Nkind
(Expr
) = N_Function_Call
then
1839 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1842 Set_Is_Overloaded
(Expr
, False);
1844 -- The expression will often be a generalized indexing that yields a
1845 -- container element that is then dereferenced, in which case the
1846 -- generalized indexing call is also non-overloaded.
1848 if Nkind
(Expr
) = N_Indexed_Component
1849 and then Present
(Generalized_Indexing
(Expr
))
1851 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1855 Make_Explicit_Dereference
(Loc
,
1857 Make_Selected_Component
(Loc
,
1858 Prefix
=> Relocate_Node
(Expr
),
1859 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1860 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1861 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1862 end Build_Explicit_Dereference
;
1864 -----------------------------------
1865 -- Cannot_Raise_Constraint_Error --
1866 -----------------------------------
1868 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1870 if Compile_Time_Known_Value
(Expr
) then
1873 elsif Do_Range_Check
(Expr
) then
1876 elsif Raises_Constraint_Error
(Expr
) then
1880 case Nkind
(Expr
) is
1881 when N_Identifier
=>
1884 when N_Expanded_Name
=>
1887 when N_Selected_Component
=>
1888 return not Do_Discriminant_Check
(Expr
);
1890 when N_Attribute_Reference
=>
1891 if Do_Overflow_Check
(Expr
) then
1894 elsif No
(Expressions
(Expr
)) then
1902 N
:= First
(Expressions
(Expr
));
1903 while Present
(N
) loop
1904 if Cannot_Raise_Constraint_Error
(N
) then
1915 when N_Type_Conversion
=>
1916 if Do_Overflow_Check
(Expr
)
1917 or else Do_Length_Check
(Expr
)
1918 or else Do_Tag_Check
(Expr
)
1922 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1925 when N_Unchecked_Type_Conversion
=>
1926 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1929 if Do_Overflow_Check
(Expr
) then
1932 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1939 if Do_Division_Check
(Expr
)
1941 Do_Overflow_Check
(Expr
)
1946 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1948 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1967 N_Op_Shift_Right_Arithmetic |
1971 if Do_Overflow_Check
(Expr
) then
1975 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1977 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1984 end Cannot_Raise_Constraint_Error
;
1986 -----------------------------------------
1987 -- Check_Dynamically_Tagged_Expression --
1988 -----------------------------------------
1990 procedure Check_Dynamically_Tagged_Expression
1993 Related_Nod
: Node_Id
)
1996 pragma Assert
(Is_Tagged_Type
(Typ
));
1998 -- In order to avoid spurious errors when analyzing the expanded code,
1999 -- this check is done only for nodes that come from source and for
2000 -- actuals of generic instantiations.
2002 if (Comes_From_Source
(Related_Nod
)
2003 or else In_Generic_Actual
(Expr
))
2004 and then (Is_Class_Wide_Type
(Etype
(Expr
))
2005 or else Is_Dynamically_Tagged
(Expr
))
2006 and then Is_Tagged_Type
(Typ
)
2007 and then not Is_Class_Wide_Type
(Typ
)
2009 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
2011 end Check_Dynamically_Tagged_Expression
;
2013 --------------------------
2014 -- Check_Fully_Declared --
2015 --------------------------
2017 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
2019 if Ekind
(T
) = E_Incomplete_Type
then
2021 -- Ada 2005 (AI-50217): If the type is available through a limited
2022 -- with_clause, verify that its full view has been analyzed.
2024 if From_Limited_With
(T
)
2025 and then Present
(Non_Limited_View
(T
))
2026 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2028 -- The non-limited view is fully declared
2034 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2037 -- Need comments for these tests ???
2039 elsif Has_Private_Component
(T
)
2040 and then not Is_Generic_Type
(Root_Type
(T
))
2041 and then not In_Spec_Expression
2043 -- Special case: if T is the anonymous type created for a single
2044 -- task or protected object, use the name of the source object.
2046 if Is_Concurrent_Type
(T
)
2047 and then not Comes_From_Source
(T
)
2048 and then Nkind
(N
) = N_Object_Declaration
2051 ("type of& has incomplete component",
2052 N
, Defining_Identifier
(N
));
2055 ("premature usage of incomplete}",
2056 N
, First_Subtype
(T
));
2059 end Check_Fully_Declared
;
2061 -------------------------------------
2062 -- Check_Function_Writable_Actuals --
2063 -------------------------------------
2065 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2066 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2067 Identifiers_List
: Elist_Id
:= No_Elist
;
2068 Error_Node
: Node_Id
:= Empty
;
2070 procedure Collect_Identifiers
(N
: Node_Id
);
2071 -- In a single traversal of subtree N collect in Writable_Actuals_List
2072 -- all the actuals of functions with writable actuals, and in the list
2073 -- Identifiers_List collect all the identifiers that are not actuals of
2074 -- functions with writable actuals. If a writable actual is referenced
2075 -- twice as writable actual then Error_Node is set to reference its
2076 -- second occurrence, the error is reported, and the tree traversal
2079 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
2080 -- Return the entity associated with the function call
2082 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2083 -- Preanalyze N without reporting errors. Very dubious, you can't just
2084 -- go analyzing things more than once???
2086 -------------------------
2087 -- Collect_Identifiers --
2088 -------------------------
2090 procedure Collect_Identifiers
(N
: Node_Id
) is
2092 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2093 -- Process a single node during the tree traversal to collect the
2094 -- writable actuals of functions and all the identifiers which are
2095 -- not writable actuals of functions.
2097 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2098 -- Returns True if List has a node whose Entity is Entity (N)
2100 -------------------------
2101 -- Check_Function_Call --
2102 -------------------------
2104 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2105 Is_Writable_Actual
: Boolean := False;
2109 if Nkind
(N
) = N_Identifier
then
2111 -- No analysis possible if the entity is not decorated
2113 if No
(Entity
(N
)) then
2116 -- Don't collect identifiers of packages, called functions, etc
2118 elsif Ekind_In
(Entity
(N
), E_Package
,
2125 -- Analyze if N is a writable actual of a function
2127 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2129 Call
: constant Node_Id
:= Parent
(N
);
2134 Id
:= Get_Function_Id
(Call
);
2136 -- In case of previous error, no check is possible
2142 Formal
:= First_Formal
(Id
);
2143 Actual
:= First_Actual
(Call
);
2144 while Present
(Actual
) and then Present
(Formal
) loop
2146 if Ekind_In
(Formal
, E_Out_Parameter
,
2149 Is_Writable_Actual
:= True;
2155 Next_Formal
(Formal
);
2156 Next_Actual
(Actual
);
2161 if Is_Writable_Actual
then
2162 if Contains
(Writable_Actuals_List
, N
) then
2164 ("value may be affected by call to& "
2165 & "because order of evaluation is arbitrary", N
, Id
);
2170 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2173 if Identifiers_List
= No_Elist
then
2174 Identifiers_List
:= New_Elmt_List
;
2177 Append_Unique_Elmt
(N
, Identifiers_List
);
2190 N
: Node_Id
) return Boolean
2192 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2197 if List
= No_Elist
then
2201 Elmt
:= First_Elmt
(List
);
2202 while Present
(Elmt
) loop
2203 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2217 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2218 -- The traversal procedure
2220 -- Start of processing for Collect_Identifiers
2223 if Present
(Error_Node
) then
2227 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2232 end Collect_Identifiers
;
2234 ---------------------
2235 -- Get_Function_Id --
2236 ---------------------
2238 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
2239 Nam
: constant Node_Id
:= Name
(Call
);
2243 if Nkind
(Nam
) = N_Explicit_Dereference
then
2245 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
2247 elsif Nkind
(Nam
) = N_Selected_Component
then
2248 Id
:= Entity
(Selector_Name
(Nam
));
2250 elsif Nkind
(Nam
) = N_Indexed_Component
then
2251 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
2258 end Get_Function_Id
;
2260 ---------------------------
2261 -- Preanalyze_Expression --
2262 ---------------------------
2264 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2265 Status
: constant Boolean := Get_Ignore_Errors
;
2267 Set_Ignore_Errors
(True);
2269 Set_Ignore_Errors
(Status
);
2270 end Preanalyze_Without_Errors
;
2272 -- Start of processing for Check_Function_Writable_Actuals
2275 -- The check only applies to Ada 2012 code, and only to constructs that
2276 -- have multiple constituents whose order of evaluation is not specified
2279 if Ada_Version
< Ada_2012
2280 or else (not (Nkind
(N
) in N_Op
)
2281 and then not (Nkind
(N
) in N_Membership_Test
)
2282 and then not Nkind_In
(N
, N_Range
,
2284 N_Extension_Aggregate
,
2285 N_Full_Type_Declaration
,
2287 N_Procedure_Call_Statement
,
2288 N_Entry_Call_Statement
))
2289 or else (Nkind
(N
) = N_Full_Type_Declaration
2290 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2292 -- In addition, this check only applies to source code, not to code
2293 -- generated by constraint checks.
2295 or else not Comes_From_Source
(N
)
2300 -- If a construct C has two or more direct constituents that are names
2301 -- or expressions whose evaluation may occur in an arbitrary order, at
2302 -- least one of which contains a function call with an in out or out
2303 -- parameter, then the construct is legal only if: for each name N that
2304 -- is passed as a parameter of mode in out or out to some inner function
2305 -- call C2 (not including the construct C itself), there is no other
2306 -- name anywhere within a direct constituent of the construct C other
2307 -- than the one containing C2, that is known to refer to the same
2308 -- object (RM 6.4.1(6.17/3)).
2312 Collect_Identifiers
(Low_Bound
(N
));
2313 Collect_Identifiers
(High_Bound
(N
));
2315 when N_Op | N_Membership_Test
=>
2320 Collect_Identifiers
(Left_Opnd
(N
));
2322 if Present
(Right_Opnd
(N
)) then
2323 Collect_Identifiers
(Right_Opnd
(N
));
2326 if Nkind_In
(N
, N_In
, N_Not_In
)
2327 and then Present
(Alternatives
(N
))
2329 Expr
:= First
(Alternatives
(N
));
2330 while Present
(Expr
) loop
2331 Collect_Identifiers
(Expr
);
2338 when N_Full_Type_Declaration
=>
2340 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2341 -- Return the record part of this record type definition
2343 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2344 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2346 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2347 return Record_Extension_Part
(Type_Def
);
2351 end Get_Record_Part
;
2354 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2355 Rec
: Node_Id
:= Get_Record_Part
(N
);
2358 -- No need to perform any analysis if the record has no
2361 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2365 -- Collect the identifiers starting from the deepest
2366 -- derivation. Done to report the error in the deepest
2370 if Present
(Component_List
(Rec
)) then
2371 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2372 while Present
(Comp
) loop
2373 if Nkind
(Comp
) = N_Component_Declaration
2374 and then Present
(Expression
(Comp
))
2376 Collect_Identifiers
(Expression
(Comp
));
2383 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2384 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2387 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2388 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2392 when N_Subprogram_Call |
2393 N_Entry_Call_Statement
=>
2395 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
2400 Formal
:= First_Formal
(Id
);
2401 Actual
:= First_Actual
(N
);
2402 while Present
(Actual
) and then Present
(Formal
) loop
2403 if Ekind_In
(Formal
, E_Out_Parameter
,
2406 Collect_Identifiers
(Actual
);
2409 Next_Formal
(Formal
);
2410 Next_Actual
(Actual
);
2415 N_Extension_Aggregate
=>
2419 Comp_Expr
: Node_Id
;
2422 -- Handle the N_Others_Choice of array aggregates with static
2423 -- bounds. There is no need to perform this analysis in
2424 -- aggregates without static bounds since we cannot evaluate
2425 -- if the N_Others_Choice covers several elements. There is
2426 -- no need to handle the N_Others choice of record aggregates
2427 -- since at this stage it has been already expanded by
2428 -- Resolve_Record_Aggregate.
2430 if Is_Array_Type
(Etype
(N
))
2431 and then Nkind
(N
) = N_Aggregate
2432 and then Present
(Aggregate_Bounds
(N
))
2433 and then Compile_Time_Known_Bounds
(Etype
(N
))
2434 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2436 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2439 Count_Components
: Uint
:= Uint_0
;
2440 Num_Components
: Uint
;
2441 Others_Assoc
: Node_Id
;
2442 Others_Choice
: Node_Id
:= Empty
;
2443 Others_Box_Present
: Boolean := False;
2446 -- Count positional associations
2448 if Present
(Expressions
(N
)) then
2449 Comp_Expr
:= First
(Expressions
(N
));
2450 while Present
(Comp_Expr
) loop
2451 Count_Components
:= Count_Components
+ 1;
2456 -- Count the rest of elements and locate the N_Others
2459 Assoc
:= First
(Component_Associations
(N
));
2460 while Present
(Assoc
) loop
2461 Choice
:= First
(Choices
(Assoc
));
2462 while Present
(Choice
) loop
2463 if Nkind
(Choice
) = N_Others_Choice
then
2464 Others_Assoc
:= Assoc
;
2465 Others_Choice
:= Choice
;
2466 Others_Box_Present
:= Box_Present
(Assoc
);
2468 -- Count several components
2470 elsif Nkind_In
(Choice
, N_Range
,
2471 N_Subtype_Indication
)
2472 or else (Is_Entity_Name
(Choice
)
2473 and then Is_Type
(Entity
(Choice
)))
2478 Get_Index_Bounds
(Choice
, L
, H
);
2480 (Compile_Time_Known_Value
(L
)
2481 and then Compile_Time_Known_Value
(H
));
2484 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2487 -- Count single component. No other case available
2488 -- since we are handling an aggregate with static
2492 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2493 or else Nkind
(Choice
) = N_Identifier
2494 or else Nkind
(Choice
) = N_Integer_Literal
);
2496 Count_Components
:= Count_Components
+ 1;
2506 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2507 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2509 pragma Assert
(Count_Components
<= Num_Components
);
2511 -- Handle the N_Others choice if it covers several
2514 if Present
(Others_Choice
)
2515 and then (Num_Components
- Count_Components
) > 1
2517 if not Others_Box_Present
then
2519 -- At this stage, if expansion is active, the
2520 -- expression of the others choice has not been
2521 -- analyzed. Hence we generate a duplicate and
2522 -- we analyze it silently to have available the
2523 -- minimum decoration required to collect the
2526 if not Expander_Active
then
2527 Comp_Expr
:= Expression
(Others_Assoc
);
2530 New_Copy_Tree
(Expression
(Others_Assoc
));
2531 Preanalyze_Without_Errors
(Comp_Expr
);
2534 Collect_Identifiers
(Comp_Expr
);
2536 if Writable_Actuals_List
/= No_Elist
then
2538 -- As suggested by Robert, at current stage we
2539 -- report occurrences of this case as warnings.
2542 ("writable function parameter may affect "
2543 & "value in other component because order "
2544 & "of evaluation is unspecified??",
2545 Node
(First_Elmt
(Writable_Actuals_List
)));
2552 -- Handle ancestor part of extension aggregates
2554 if Nkind
(N
) = N_Extension_Aggregate
then
2555 Collect_Identifiers
(Ancestor_Part
(N
));
2558 -- Handle positional associations
2560 if Present
(Expressions
(N
)) then
2561 Comp_Expr
:= First
(Expressions
(N
));
2562 while Present
(Comp_Expr
) loop
2563 if not Is_OK_Static_Expression
(Comp_Expr
) then
2564 Collect_Identifiers
(Comp_Expr
);
2571 -- Handle discrete associations
2573 if Present
(Component_Associations
(N
)) then
2574 Assoc
:= First
(Component_Associations
(N
));
2575 while Present
(Assoc
) loop
2577 if not Box_Present
(Assoc
) then
2578 Choice
:= First
(Choices
(Assoc
));
2579 while Present
(Choice
) loop
2581 -- For now we skip discriminants since it requires
2582 -- performing the analysis in two phases: first one
2583 -- analyzing discriminants and second one analyzing
2584 -- the rest of components since discriminants are
2585 -- evaluated prior to components: too much extra
2586 -- work to detect a corner case???
2588 if Nkind
(Choice
) in N_Has_Entity
2589 and then Present
(Entity
(Choice
))
2590 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2594 elsif Box_Present
(Assoc
) then
2598 if not Analyzed
(Expression
(Assoc
)) then
2600 New_Copy_Tree
(Expression
(Assoc
));
2601 Set_Parent
(Comp_Expr
, Parent
(N
));
2602 Preanalyze_Without_Errors
(Comp_Expr
);
2604 Comp_Expr
:= Expression
(Assoc
);
2607 Collect_Identifiers
(Comp_Expr
);
2623 -- No further action needed if we already reported an error
2625 if Present
(Error_Node
) then
2629 -- Check if some writable argument of a function is referenced
2631 if Writable_Actuals_List
/= No_Elist
2632 and then Identifiers_List
/= No_Elist
2639 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2640 while Present
(Elmt_1
) loop
2641 Elmt_2
:= First_Elmt
(Identifiers_List
);
2642 while Present
(Elmt_2
) loop
2643 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2644 case Nkind
(Parent
(Node
(Elmt_2
))) is
2646 N_Component_Association |
2647 N_Component_Declaration
=>
2649 ("value may be affected by call in other "
2650 & "component because they are evaluated "
2651 & "in unspecified order",
2654 when N_In | N_Not_In
=>
2656 ("value may be affected by call in other "
2657 & "alternative because they are evaluated "
2658 & "in unspecified order",
2663 ("value of actual may be affected by call in "
2664 & "other actual because they are evaluated "
2665 & "in unspecified order",
2677 end Check_Function_Writable_Actuals
;
2679 --------------------------------
2680 -- Check_Implicit_Dereference --
2681 --------------------------------
2683 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
2689 if Nkind
(N
) = N_Indexed_Component
2690 and then Present
(Generalized_Indexing
(N
))
2692 Nam
:= Generalized_Indexing
(N
);
2697 if Ada_Version
< Ada_2012
2698 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2702 elsif not Comes_From_Source
(N
)
2703 and then Nkind
(N
) /= N_Indexed_Component
2707 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2711 Disc
:= First_Discriminant
(Typ
);
2712 while Present
(Disc
) loop
2713 if Has_Implicit_Dereference
(Disc
) then
2714 Desig
:= Designated_Type
(Etype
(Disc
));
2715 Add_One_Interp
(Nam
, Disc
, Desig
);
2717 -- If the node is a generalized indexing, add interpretation
2718 -- to that node as well, for subsequent resolution.
2720 if Nkind
(N
) = N_Indexed_Component
then
2721 Add_One_Interp
(N
, Disc
, Desig
);
2724 -- If the operation comes from a generic unit and the context
2725 -- is a selected component, the selector name may be global
2726 -- and set in the instance already. Remove the entity to
2727 -- force resolution of the selected component, and the
2728 -- generation of an explicit dereference if needed.
2731 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
2733 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
2739 Next_Discriminant
(Disc
);
2742 end Check_Implicit_Dereference
;
2744 ----------------------------------
2745 -- Check_Internal_Protected_Use --
2746 ----------------------------------
2748 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2754 while Present
(S
) loop
2755 if S
= Standard_Standard
then
2758 elsif Ekind
(S
) = E_Function
2759 and then Ekind
(Scope
(S
)) = E_Protected_Type
2768 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2770 -- An indirect function call (e.g. a callback within a protected
2771 -- function body) is not statically illegal. If the access type is
2772 -- anonymous and is the type of an access parameter, the scope of Nam
2773 -- will be the protected type, but it is not a protected operation.
2775 if Ekind
(Nam
) = E_Subprogram_Type
2777 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2781 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2783 ("within protected function cannot use protected "
2784 & "procedure in renaming or as generic actual", N
);
2786 elsif Nkind
(N
) = N_Attribute_Reference
then
2788 ("within protected function cannot take access of "
2789 & " protected procedure", N
);
2793 ("within protected function, protected object is constant", N
);
2795 ("\cannot call operation that may modify it", N
);
2798 end Check_Internal_Protected_Use
;
2800 ---------------------------------------
2801 -- Check_Later_Vs_Basic_Declarations --
2802 ---------------------------------------
2804 procedure Check_Later_Vs_Basic_Declarations
2806 During_Parsing
: Boolean)
2808 Body_Sloc
: Source_Ptr
;
2811 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2812 -- Return whether Decl is considered as a declarative item.
2813 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2814 -- When During_Parsing is False, the semantics of SPARK is followed.
2816 -------------------------------
2817 -- Is_Later_Declarative_Item --
2818 -------------------------------
2820 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2822 if Nkind
(Decl
) in N_Later_Decl_Item
then
2825 elsif Nkind
(Decl
) = N_Pragma
then
2828 elsif During_Parsing
then
2831 -- In SPARK, a package declaration is not considered as a later
2832 -- declarative item.
2834 elsif Nkind
(Decl
) = N_Package_Declaration
then
2837 -- In SPARK, a renaming is considered as a later declarative item
2839 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2845 end Is_Later_Declarative_Item
;
2847 -- Start of Check_Later_Vs_Basic_Declarations
2850 Decl
:= First
(Decls
);
2852 -- Loop through sequence of basic declarative items
2854 Outer
: while Present
(Decl
) loop
2855 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2856 and then Nkind
(Decl
) not in N_Body_Stub
2860 -- Once a body is encountered, we only allow later declarative
2861 -- items. The inner loop checks the rest of the list.
2864 Body_Sloc
:= Sloc
(Decl
);
2866 Inner
: while Present
(Decl
) loop
2867 if not Is_Later_Declarative_Item
(Decl
) then
2868 if During_Parsing
then
2869 if Ada_Version
= Ada_83
then
2870 Error_Msg_Sloc
:= Body_Sloc
;
2872 ("(Ada 83) decl cannot appear after body#", Decl
);
2875 Error_Msg_Sloc
:= Body_Sloc
;
2876 Check_SPARK_05_Restriction
2877 ("decl cannot appear after body#", Decl
);
2885 end Check_Later_Vs_Basic_Declarations
;
2887 -------------------------
2888 -- Check_Nested_Access --
2889 -------------------------
2891 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2892 Scop
: constant Entity_Id
:= Current_Scope
;
2893 Current_Subp
: Entity_Id
;
2894 Enclosing
: Entity_Id
;
2897 -- Currently only enabled for VM back-ends for efficiency, should we
2898 -- enable it more systematically ???
2900 -- Check for Is_Imported needs commenting below ???
2902 if VM_Target
/= No_VM
2903 and then Ekind_In
(Ent
, E_Variable
, E_Constant
, E_Loop_Parameter
)
2904 and then Scope
(Ent
) /= Empty
2905 and then not Is_Library_Level_Entity
(Ent
)
2906 and then not Is_Imported
(Ent
)
2908 if Is_Subprogram
(Scop
)
2909 or else Is_Generic_Subprogram
(Scop
)
2910 or else Is_Entry
(Scop
)
2912 Current_Subp
:= Scop
;
2914 Current_Subp
:= Current_Subprogram
;
2917 Enclosing
:= Enclosing_Subprogram
(Ent
);
2919 if Enclosing
/= Empty
and then Enclosing
/= Current_Subp
then
2920 Set_Has_Up_Level_Access
(Ent
, True);
2923 end Check_Nested_Access
;
2925 ---------------------------
2926 -- Check_No_Hidden_State --
2927 ---------------------------
2929 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2930 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2931 -- Determine whether the entity of a package denoted by Pkg has a null
2934 -----------------------------
2935 -- Has_Null_Abstract_State --
2936 -----------------------------
2938 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2939 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2942 -- Check first available state of related package. A null abstract
2943 -- state always appears as the sole element of the state list.
2947 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2948 end Has_Null_Abstract_State
;
2952 Context
: Entity_Id
:= Empty
;
2953 Not_Visible
: Boolean := False;
2956 -- Start of processing for Check_No_Hidden_State
2959 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2961 -- Find the proper context where the object or state appears
2964 while Present
(Scop
) loop
2967 -- Keep track of the context's visibility
2969 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2971 -- Prevent the search from going too far
2973 if Context
= Standard_Standard
then
2976 -- Objects and states that appear immediately within a subprogram or
2977 -- inside a construct nested within a subprogram do not introduce a
2978 -- hidden state. They behave as local variable declarations.
2980 elsif Is_Subprogram
(Context
) then
2983 -- When examining a package body, use the entity of the spec as it
2984 -- carries the abstract state declarations.
2986 elsif Ekind
(Context
) = E_Package_Body
then
2987 Context
:= Spec_Entity
(Context
);
2990 -- Stop the traversal when a package subject to a null abstract state
2993 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2994 and then Has_Null_Abstract_State
(Context
)
2999 Scop
:= Scope
(Scop
);
3002 -- At this point we know that there is at least one package with a null
3003 -- abstract state in visibility. Emit an error message unconditionally
3004 -- if the entity being processed is a state because the placement of the
3005 -- related package is irrelevant. This is not the case for objects as
3006 -- the intermediate context matters.
3008 if Present
(Context
)
3009 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
3011 Error_Msg_N
("cannot introduce hidden state &", Id
);
3012 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
3014 end Check_No_Hidden_State
;
3016 ------------------------------------------
3017 -- Check_Potentially_Blocking_Operation --
3018 ------------------------------------------
3020 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
3024 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3025 -- When pragma Detect_Blocking is active, the run time will raise
3026 -- Program_Error. Here we only issue a warning, since we generally
3027 -- support the use of potentially blocking operations in the absence
3030 -- Indirect blocking through a subprogram call cannot be diagnosed
3031 -- statically without interprocedural analysis, so we do not attempt
3034 S
:= Scope
(Current_Scope
);
3035 while Present
(S
) and then S
/= Standard_Standard
loop
3036 if Is_Protected_Type
(S
) then
3038 ("potentially blocking operation in protected operation??", N
);
3044 end Check_Potentially_Blocking_Operation
;
3046 ---------------------------------
3047 -- Check_Result_And_Post_State --
3048 ---------------------------------
3050 procedure Check_Result_And_Post_State
3052 Result_Seen
: in out Boolean)
3054 procedure Check_Expression
(Expr
: Node_Id
);
3055 -- Perform the 'Result and post-state checks on a given expression
3057 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
3058 -- Attempt to find attribute 'Result in a subtree denoted by N
3060 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
3061 -- Determine whether source node N denotes "True" or "False"
3063 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
3064 -- Determine whether a subtree denoted by N mentions any construct that
3065 -- denotes a post-state.
3067 procedure Check_Function_Result
is
3068 new Traverse_Proc
(Is_Function_Result
);
3070 ----------------------
3071 -- Check_Expression --
3072 ----------------------
3074 procedure Check_Expression
(Expr
: Node_Id
) is
3076 if not Is_Trivial_Boolean
(Expr
) then
3077 Check_Function_Result
(Expr
);
3079 if not Mentions_Post_State
(Expr
) then
3080 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3082 ("contract case refers only to pre-state?T?", Expr
);
3084 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3086 ("refined postcondition refers only to pre-state?T?",
3091 ("postcondition refers only to pre-state?T?", Prag
);
3095 end Check_Expression
;
3097 ------------------------
3098 -- Is_Function_Result --
3099 ------------------------
3101 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3103 if Is_Attribute_Result
(N
) then
3104 Result_Seen
:= True;
3107 -- Continue the traversal
3112 end Is_Function_Result
;
3114 ------------------------
3115 -- Is_Trivial_Boolean --
3116 ------------------------
3118 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3121 Comes_From_Source
(N
)
3122 and then Is_Entity_Name
(N
)
3123 and then (Entity
(N
) = Standard_True
3125 Entity
(N
) = Standard_False
);
3126 end Is_Trivial_Boolean
;
3128 -------------------------
3129 -- Mentions_Post_State --
3130 -------------------------
3132 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3133 Post_State_Seen
: Boolean := False;
3135 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3136 -- Attempt to find a construct that denotes a post-state. If this is
3137 -- the case, set flag Post_State_Seen.
3143 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3147 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3148 Post_State_Seen
:= True;
3151 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3154 -- The entity may be modifiable through an implicit dereference
3157 or else Ekind
(Ent
) in Assignable_Kind
3158 or else (Is_Access_Type
(Etype
(Ent
))
3159 and then Nkind
(Parent
(N
)) = N_Selected_Component
)
3161 Post_State_Seen
:= True;
3165 elsif Nkind
(N
) = N_Attribute_Reference
then
3166 if Attribute_Name
(N
) = Name_Old
then
3169 elsif Attribute_Name
(N
) = Name_Result
then
3170 Post_State_Seen
:= True;
3178 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3180 -- Start of processing for Mentions_Post_State
3183 Find_Post_State
(N
);
3185 return Post_State_Seen
;
3186 end Mentions_Post_State
;
3190 Expr
: constant Node_Id
:=
3191 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
3192 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3195 -- Start of processing for Check_Result_And_Post_State
3198 -- Examine all consequences
3200 if Nam
= Name_Contract_Cases
then
3201 CCase
:= First
(Component_Associations
(Expr
));
3202 while Present
(CCase
) loop
3203 Check_Expression
(Expression
(CCase
));
3208 -- Examine the expression of a postcondition
3210 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
, Name_Refined_Post
));
3211 Check_Expression
(Expr
);
3213 end Check_Result_And_Post_State
;
3215 ------------------------------
3216 -- Check_Unprotected_Access --
3217 ------------------------------
3219 procedure Check_Unprotected_Access
3223 Cont_Encl_Typ
: Entity_Id
;
3224 Pref_Encl_Typ
: Entity_Id
;
3226 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
3227 -- Check whether Obj is a private component of a protected object.
3228 -- Return the protected type where the component resides, Empty
3231 function Is_Public_Operation
return Boolean;
3232 -- Verify that the enclosing operation is callable from outside the
3233 -- protected object, to minimize false positives.
3235 ------------------------------
3236 -- Enclosing_Protected_Type --
3237 ------------------------------
3239 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
3241 if Is_Entity_Name
(Obj
) then
3243 Ent
: Entity_Id
:= Entity
(Obj
);
3246 -- The object can be a renaming of a private component, use
3247 -- the original record component.
3249 if Is_Prival
(Ent
) then
3250 Ent
:= Prival_Link
(Ent
);
3253 if Is_Protected_Type
(Scope
(Ent
)) then
3259 -- For indexed and selected components, recursively check the prefix
3261 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
3262 return Enclosing_Protected_Type
(Prefix
(Obj
));
3264 -- The object does not denote a protected component
3269 end Enclosing_Protected_Type
;
3271 -------------------------
3272 -- Is_Public_Operation --
3273 -------------------------
3275 function Is_Public_Operation
return Boolean is
3281 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
3282 if Scope
(S
) = Pref_Encl_Typ
then
3283 E
:= First_Entity
(Pref_Encl_Typ
);
3285 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
3299 end Is_Public_Operation
;
3301 -- Start of processing for Check_Unprotected_Access
3304 if Nkind
(Expr
) = N_Attribute_Reference
3305 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
3307 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
3308 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
3310 -- Check whether we are trying to export a protected component to a
3311 -- context with an equal or lower access level.
3313 if Present
(Pref_Encl_Typ
)
3314 and then No
(Cont_Encl_Typ
)
3315 and then Is_Public_Operation
3316 and then Scope_Depth
(Pref_Encl_Typ
) >=
3317 Object_Access_Level
(Context
)
3320 ("??possible unprotected access to protected data", Expr
);
3323 end Check_Unprotected_Access
;
3325 ------------------------
3326 -- Collect_Interfaces --
3327 ------------------------
3329 procedure Collect_Interfaces
3331 Ifaces_List
: out Elist_Id
;
3332 Exclude_Parents
: Boolean := False;
3333 Use_Full_View
: Boolean := True)
3335 procedure Collect
(Typ
: Entity_Id
);
3336 -- Subsidiary subprogram used to traverse the whole list
3337 -- of directly and indirectly implemented interfaces
3343 procedure Collect
(Typ
: Entity_Id
) is
3344 Ancestor
: Entity_Id
;
3352 -- Handle private types
3355 and then Is_Private_Type
(Typ
)
3356 and then Present
(Full_View
(Typ
))
3358 Full_T
:= Full_View
(Typ
);
3361 -- Include the ancestor if we are generating the whole list of
3362 -- abstract interfaces.
3364 if Etype
(Full_T
) /= Typ
3366 -- Protect the frontend against wrong sources. For example:
3369 -- type A is tagged null record;
3370 -- type B is new A with private;
3371 -- type C is new A with private;
3373 -- type B is new C with null record;
3374 -- type C is new B with null record;
3377 and then Etype
(Full_T
) /= T
3379 Ancestor
:= Etype
(Full_T
);
3382 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
3383 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
3387 -- Traverse the graph of ancestor interfaces
3389 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
3390 Id
:= First
(Abstract_Interface_List
(Full_T
));
3391 while Present
(Id
) loop
3392 Iface
:= Etype
(Id
);
3394 -- Protect against wrong uses. For example:
3395 -- type I is interface;
3396 -- type O is tagged null record;
3397 -- type Wrong is new I and O with null record; -- ERROR
3399 if Is_Interface
(Iface
) then
3401 and then Etype
(T
) /= T
3402 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
3407 Append_Unique_Elmt
(Iface
, Ifaces_List
);
3416 -- Start of processing for Collect_Interfaces
3419 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
3420 Ifaces_List
:= New_Elmt_List
;
3422 end Collect_Interfaces
;
3424 ----------------------------------
3425 -- Collect_Interface_Components --
3426 ----------------------------------
3428 procedure Collect_Interface_Components
3429 (Tagged_Type
: Entity_Id
;
3430 Components_List
: out Elist_Id
)
3432 procedure Collect
(Typ
: Entity_Id
);
3433 -- Subsidiary subprogram used to climb to the parents
3439 procedure Collect
(Typ
: Entity_Id
) is
3440 Tag_Comp
: Entity_Id
;
3441 Parent_Typ
: Entity_Id
;
3444 -- Handle private types
3446 if Present
(Full_View
(Etype
(Typ
))) then
3447 Parent_Typ
:= Full_View
(Etype
(Typ
));
3449 Parent_Typ
:= Etype
(Typ
);
3452 if Parent_Typ
/= Typ
3454 -- Protect the frontend against wrong sources. For example:
3457 -- type A is tagged null record;
3458 -- type B is new A with private;
3459 -- type C is new A with private;
3461 -- type B is new C with null record;
3462 -- type C is new B with null record;
3465 and then Parent_Typ
/= Tagged_Type
3467 Collect
(Parent_Typ
);
3470 -- Collect the components containing tags of secondary dispatch
3473 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
3474 while Present
(Tag_Comp
) loop
3475 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
3476 Append_Elmt
(Tag_Comp
, Components_List
);
3478 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
3482 -- Start of processing for Collect_Interface_Components
3485 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
3486 and then Is_Tagged_Type
(Tagged_Type
));
3488 Components_List
:= New_Elmt_List
;
3489 Collect
(Tagged_Type
);
3490 end Collect_Interface_Components
;
3492 -----------------------------
3493 -- Collect_Interfaces_Info --
3494 -----------------------------
3496 procedure Collect_Interfaces_Info
3498 Ifaces_List
: out Elist_Id
;
3499 Components_List
: out Elist_Id
;
3500 Tags_List
: out Elist_Id
)
3502 Comps_List
: Elist_Id
;
3503 Comp_Elmt
: Elmt_Id
;
3504 Comp_Iface
: Entity_Id
;
3505 Iface_Elmt
: Elmt_Id
;
3508 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3509 -- Search for the secondary tag associated with the interface type
3510 -- Iface that is implemented by T.
3516 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3519 if not Is_CPP_Class
(T
) then
3520 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3522 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3526 and then Is_Tag
(Node
(ADT
))
3527 and then Related_Type
(Node
(ADT
)) /= Iface
3529 -- Skip secondary dispatch table referencing thunks to user
3530 -- defined primitives covered by this interface.
3532 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3535 -- Skip secondary dispatch tables of Ada types
3537 if not Is_CPP_Class
(T
) then
3539 -- Skip secondary dispatch table referencing thunks to
3540 -- predefined primitives.
3542 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3545 -- Skip secondary dispatch table referencing user-defined
3546 -- primitives covered by this interface.
3548 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3551 -- Skip secondary dispatch table referencing predefined
3554 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3559 pragma Assert
(Is_Tag
(Node
(ADT
)));
3563 -- Start of processing for Collect_Interfaces_Info
3566 Collect_Interfaces
(T
, Ifaces_List
);
3567 Collect_Interface_Components
(T
, Comps_List
);
3569 -- Search for the record component and tag associated with each
3570 -- interface type of T.
3572 Components_List
:= New_Elmt_List
;
3573 Tags_List
:= New_Elmt_List
;
3575 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3576 while Present
(Iface_Elmt
) loop
3577 Iface
:= Node
(Iface_Elmt
);
3579 -- Associate the primary tag component and the primary dispatch table
3580 -- with all the interfaces that are parents of T
3582 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3583 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3584 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3586 -- Otherwise search for the tag component and secondary dispatch
3590 Comp_Elmt
:= First_Elmt
(Comps_List
);
3591 while Present
(Comp_Elmt
) loop
3592 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3594 if Comp_Iface
= Iface
3595 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3597 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3598 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3602 Next_Elmt
(Comp_Elmt
);
3604 pragma Assert
(Present
(Comp_Elmt
));
3607 Next_Elmt
(Iface_Elmt
);
3609 end Collect_Interfaces_Info
;
3611 ---------------------
3612 -- Collect_Parents --
3613 ---------------------
3615 procedure Collect_Parents
3617 List
: out Elist_Id
;
3618 Use_Full_View
: Boolean := True)
3620 Current_Typ
: Entity_Id
:= T
;
3621 Parent_Typ
: Entity_Id
;
3624 List
:= New_Elmt_List
;
3626 -- No action if the if the type has no parents
3628 if T
= Etype
(T
) then
3633 Parent_Typ
:= Etype
(Current_Typ
);
3635 if Is_Private_Type
(Parent_Typ
)
3636 and then Present
(Full_View
(Parent_Typ
))
3637 and then Use_Full_View
3639 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3642 Append_Elmt
(Parent_Typ
, List
);
3644 exit when Parent_Typ
= Current_Typ
;
3645 Current_Typ
:= Parent_Typ
;
3647 end Collect_Parents
;
3649 ----------------------------------
3650 -- Collect_Primitive_Operations --
3651 ----------------------------------
3653 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3654 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3655 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3656 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3660 Is_Type_In_Pkg
: Boolean;
3661 Formal_Derived
: Boolean := False;
3664 function Match
(E
: Entity_Id
) return Boolean;
3665 -- True if E's base type is B_Type, or E is of an anonymous access type
3666 -- and the base type of its designated type is B_Type.
3672 function Match
(E
: Entity_Id
) return Boolean is
3673 Etyp
: Entity_Id
:= Etype
(E
);
3676 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
3677 Etyp
:= Designated_Type
(Etyp
);
3680 -- In Ada 2012 a primitive operation may have a formal of an
3681 -- incomplete view of the parent type.
3683 return Base_Type
(Etyp
) = B_Type
3685 (Ada_Version
>= Ada_2012
3686 and then Ekind
(Etyp
) = E_Incomplete_Type
3687 and then Full_View
(Etyp
) = B_Type
);
3690 -- Start of processing for Collect_Primitive_Operations
3693 -- For tagged types, the primitive operations are collected as they
3694 -- are declared, and held in an explicit list which is simply returned.
3696 if Is_Tagged_Type
(B_Type
) then
3697 return Primitive_Operations
(B_Type
);
3699 -- An untagged generic type that is a derived type inherits the
3700 -- primitive operations of its parent type. Other formal types only
3701 -- have predefined operators, which are not explicitly represented.
3703 elsif Is_Generic_Type
(B_Type
) then
3704 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
3705 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
3706 N_Formal_Derived_Type_Definition
3708 Formal_Derived
:= True;
3710 return New_Elmt_List
;
3714 Op_List
:= New_Elmt_List
;
3716 if B_Scope
= Standard_Standard
then
3717 if B_Type
= Standard_String
then
3718 Append_Elmt
(Standard_Op_Concat
, Op_List
);
3720 elsif B_Type
= Standard_Wide_String
then
3721 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
3727 -- Locate the primitive subprograms of the type
3730 -- The primitive operations appear after the base type, except
3731 -- if the derivation happens within the private part of B_Scope
3732 -- and the type is a private type, in which case both the type
3733 -- and some primitive operations may appear before the base
3734 -- type, and the list of candidates starts after the type.
3736 if In_Open_Scopes
(B_Scope
)
3737 and then Scope
(T
) = B_Scope
3738 and then In_Private_Part
(B_Scope
)
3740 Id
:= Next_Entity
(T
);
3742 -- In Ada 2012, If the type has an incomplete partial view, there
3743 -- may be primitive operations declared before the full view, so
3744 -- we need to start scanning from the incomplete view, which is
3745 -- earlier on the entity chain.
3747 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
3748 and then Present
(Incomplete_View
(Parent
(B_Type
)))
3750 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
3753 Id
:= Next_Entity
(B_Type
);
3756 -- Set flag if this is a type in a package spec
3759 Is_Package_Or_Generic_Package
(B_Scope
)
3761 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
3764 while Present
(Id
) loop
3766 -- Test whether the result type or any of the parameter types of
3767 -- each subprogram following the type match that type when the
3768 -- type is declared in a package spec, is a derived type, or the
3769 -- subprogram is marked as primitive. (The Is_Primitive test is
3770 -- needed to find primitives of nonderived types in declarative
3771 -- parts that happen to override the predefined "=" operator.)
3773 -- Note that generic formal subprograms are not considered to be
3774 -- primitive operations and thus are never inherited.
3776 if Is_Overloadable
(Id
)
3777 and then (Is_Type_In_Pkg
3778 or else Is_Derived_Type
(B_Type
)
3779 or else Is_Primitive
(Id
))
3780 and then Nkind
(Parent
(Parent
(Id
)))
3781 not in N_Formal_Subprogram_Declaration
3789 Formal
:= First_Formal
(Id
);
3790 while Present
(Formal
) loop
3791 if Match
(Formal
) then
3796 Next_Formal
(Formal
);
3800 -- For a formal derived type, the only primitives are the ones
3801 -- inherited from the parent type. Operations appearing in the
3802 -- package declaration are not primitive for it.
3805 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
3807 -- In the special case of an equality operator aliased to
3808 -- an overriding dispatching equality belonging to the same
3809 -- type, we don't include it in the list of primitives.
3810 -- This avoids inheriting multiple equality operators when
3811 -- deriving from untagged private types whose full type is
3812 -- tagged, which can otherwise cause ambiguities. Note that
3813 -- this should only happen for this kind of untagged parent
3814 -- type, since normally dispatching operations are inherited
3815 -- using the type's Primitive_Operations list.
3817 if Chars
(Id
) = Name_Op_Eq
3818 and then Is_Dispatching_Operation
(Id
)
3819 and then Present
(Alias
(Id
))
3820 and then Present
(Overridden_Operation
(Alias
(Id
)))
3821 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3822 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3826 -- Include the subprogram in the list of primitives
3829 Append_Elmt
(Id
, Op_List
);
3836 -- For a type declared in System, some of its operations may
3837 -- appear in the target-specific extension to System.
3840 and then B_Scope
= RTU_Entity
(System
)
3841 and then Present_System_Aux
3843 B_Scope
:= System_Aux_Id
;
3844 Id
:= First_Entity
(System_Aux_Id
);
3850 end Collect_Primitive_Operations
;
3852 -----------------------------------
3853 -- Compile_Time_Constraint_Error --
3854 -----------------------------------
3856 function Compile_Time_Constraint_Error
3859 Ent
: Entity_Id
:= Empty
;
3860 Loc
: Source_Ptr
:= No_Location
;
3861 Warn
: Boolean := False) return Node_Id
3863 Msgc
: String (1 .. Msg
'Length + 3);
3864 -- Copy of message, with room for possible ?? or << and ! at end
3870 -- Start of processing for Compile_Time_Constraint_Error
3873 -- If this is a warning, convert it into an error if we are in code
3874 -- subject to SPARK_Mode being set ON.
3876 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3878 -- A static constraint error in an instance body is not a fatal error.
3879 -- we choose to inhibit the message altogether, because there is no
3880 -- obvious node (for now) on which to post it. On the other hand the
3881 -- offending node must be replaced with a constraint_error in any case.
3883 -- No messages are generated if we already posted an error on this node
3885 if not Error_Posted
(N
) then
3886 if Loc
/= No_Location
then
3892 -- Copy message to Msgc, converting any ? in the message into
3893 -- < instead, so that we have an error in GNATprove mode.
3897 for J
in 1 .. Msgl
loop
3898 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
3901 Msgc
(J
) := Msg
(J
);
3905 -- Message is a warning, even in Ada 95 case
3907 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
3910 -- In Ada 83, all messages are warnings. In the private part and
3911 -- the body of an instance, constraint_checks are only warnings.
3912 -- We also make this a warning if the Warn parameter is set.
3915 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
3923 elsif In_Instance_Not_Visible
then
3930 -- Otherwise we have a real error message (Ada 95 static case)
3931 -- and we make this an unconditional message. Note that in the
3932 -- warning case we do not make the message unconditional, it seems
3933 -- quite reasonable to delete messages like this (about exceptions
3934 -- that will be raised) in dead code.
3942 -- One more test, skip the warning if the related expression is
3943 -- statically unevaluated, since we don't want to warn about what
3944 -- will happen when something is evaluated if it never will be
3947 if not Is_Statically_Unevaluated
(N
) then
3948 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3950 if Present
(Ent
) then
3951 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
3953 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
3958 -- Check whether the context is an Init_Proc
3960 if Inside_Init_Proc
then
3962 Conc_Typ
: constant Entity_Id
:=
3963 Corresponding_Concurrent_Type
3964 (Entity
(Parameter_Type
(First
3965 (Parameter_Specifications
3966 (Parent
(Current_Scope
))))));
3969 -- Don't complain if the corresponding concurrent type
3970 -- doesn't come from source (i.e. a single task/protected
3973 if Present
(Conc_Typ
)
3974 and then not Comes_From_Source
(Conc_Typ
)
3977 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3980 if GNATprove_Mode
then
3982 ("\& would have been raised for objects of this "
3983 & "type", N
, Standard_Constraint_Error
, Eloc
);
3986 ("\& will be raised for objects of this type??",
3987 N
, Standard_Constraint_Error
, Eloc
);
3993 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3997 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
3998 Set_Error_Posted
(N
);
4004 end Compile_Time_Constraint_Error
;
4006 -----------------------
4007 -- Conditional_Delay --
4008 -----------------------
4010 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
4012 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
4013 Set_Has_Delayed_Freeze
(New_Ent
);
4015 end Conditional_Delay
;
4017 ----------------------------
4018 -- Contains_Refined_State --
4019 ----------------------------
4021 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
4022 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
4023 -- Determine whether a dependency list mentions a state with a visible
4026 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
4027 -- Determine whether a global list mentions a state with a visible
4030 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
4031 -- Determine whether Item is a reference to an abstract state with a
4032 -- visible refinement.
4034 -----------------------------
4035 -- Has_State_In_Dependency --
4036 -----------------------------
4038 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
4043 -- A null dependency list does not mention any states
4045 if Nkind
(List
) = N_Null
then
4048 -- Dependency clauses appear as component associations of an
4051 elsif Nkind
(List
) = N_Aggregate
4052 and then Present
(Component_Associations
(List
))
4054 Clause
:= First
(Component_Associations
(List
));
4055 while Present
(Clause
) loop
4057 -- Inspect the outputs of a dependency clause
4059 Output
:= First
(Choices
(Clause
));
4060 while Present
(Output
) loop
4061 if Is_Refined_State
(Output
) then
4068 -- Inspect the outputs of a dependency clause
4070 if Is_Refined_State
(Expression
(Clause
)) then
4077 -- If we get here, then none of the dependency clauses mention a
4078 -- state with visible refinement.
4082 -- An illegal pragma managed to sneak in
4085 raise Program_Error
;
4087 end Has_State_In_Dependency
;
4089 -------------------------
4090 -- Has_State_In_Global --
4091 -------------------------
4093 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
4097 -- A null global list does not mention any states
4099 if Nkind
(List
) = N_Null
then
4102 -- Simple global list or moded global list declaration
4104 elsif Nkind
(List
) = N_Aggregate
then
4106 -- The declaration of a simple global list appear as a collection
4109 if Present
(Expressions
(List
)) then
4110 Item
:= First
(Expressions
(List
));
4111 while Present
(Item
) loop
4112 if Is_Refined_State
(Item
) then
4119 -- The declaration of a moded global list appears as a collection
4120 -- of component associations where individual choices denote
4124 Item
:= First
(Component_Associations
(List
));
4125 while Present
(Item
) loop
4126 if Has_State_In_Global
(Expression
(Item
)) then
4134 -- If we get here, then the simple/moded global list did not
4135 -- mention any states with a visible refinement.
4139 -- Single global item declaration
4141 elsif Is_Entity_Name
(List
) then
4142 return Is_Refined_State
(List
);
4144 -- An illegal pragma managed to sneak in
4147 raise Program_Error
;
4149 end Has_State_In_Global
;
4151 ----------------------
4152 -- Is_Refined_State --
4153 ----------------------
4155 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
4157 Item_Id
: Entity_Id
;
4160 if Nkind
(Item
) = N_Null
then
4163 -- States cannot be subject to attribute 'Result. This case arises
4164 -- in dependency relations.
4166 elsif Nkind
(Item
) = N_Attribute_Reference
4167 and then Attribute_Name
(Item
) = Name_Result
4171 -- Multiple items appear as an aggregate. This case arises in
4172 -- dependency relations.
4174 elsif Nkind
(Item
) = N_Aggregate
4175 and then Present
(Expressions
(Item
))
4177 Elmt
:= First
(Expressions
(Item
));
4178 while Present
(Elmt
) loop
4179 if Is_Refined_State
(Elmt
) then
4186 -- If we get here, then none of the inputs or outputs reference a
4187 -- state with visible refinement.
4194 Item_Id
:= Entity_Of
(Item
);
4198 and then Ekind
(Item_Id
) = E_Abstract_State
4199 and then Has_Visible_Refinement
(Item_Id
);
4201 end Is_Refined_State
;
4205 Arg
: constant Node_Id
:=
4206 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
4207 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4209 -- Start of processing for Contains_Refined_State
4212 if Nam
= Name_Depends
then
4213 return Has_State_In_Dependency
(Arg
);
4215 else pragma Assert
(Nam
= Name_Global
);
4216 return Has_State_In_Global
(Arg
);
4218 end Contains_Refined_State
;
4220 -------------------------
4221 -- Copy_Component_List --
4222 -------------------------
4224 function Copy_Component_List
4226 Loc
: Source_Ptr
) return List_Id
4229 Comps
: constant List_Id
:= New_List
;
4232 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
4233 while Present
(Comp
) loop
4234 if Comes_From_Source
(Comp
) then
4236 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
4239 Make_Component_Declaration
(Loc
,
4240 Defining_Identifier
=>
4241 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
4242 Component_Definition
=>
4244 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
4248 Next_Component
(Comp
);
4252 end Copy_Component_List
;
4254 -------------------------
4255 -- Copy_Parameter_List --
4256 -------------------------
4258 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
4259 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
4264 if No
(First_Formal
(Subp_Id
)) then
4268 Formal
:= First_Formal
(Subp_Id
);
4269 while Present
(Formal
) loop
4271 (Make_Parameter_Specification
(Loc
,
4272 Defining_Identifier
=>
4273 Make_Defining_Identifier
(Sloc
(Formal
),
4274 Chars
=> Chars
(Formal
)),
4275 In_Present
=> In_Present
(Parent
(Formal
)),
4276 Out_Present
=> Out_Present
(Parent
(Formal
)),
4278 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4280 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
4283 Next_Formal
(Formal
);
4288 end Copy_Parameter_List
;
4290 --------------------------------
4291 -- Corresponding_Generic_Type --
4292 --------------------------------
4294 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
4300 if not Is_Generic_Actual_Type
(T
) then
4303 -- If the actual is the actual of an enclosing instance, resolution
4304 -- was correct in the generic.
4306 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
4307 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
4309 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
4316 if Is_Wrapper_Package
(Inst
) then
4317 Inst
:= Related_Instance
(Inst
);
4322 (Specification
(Unit_Declaration_Node
(Inst
)));
4324 -- Generic actual has the same name as the corresponding formal
4326 Typ
:= First_Entity
(Gen
);
4327 while Present
(Typ
) loop
4328 if Chars
(Typ
) = Chars
(T
) then
4337 end Corresponding_Generic_Type
;
4339 --------------------
4340 -- Current_Entity --
4341 --------------------
4343 -- The currently visible definition for a given identifier is the
4344 -- one most chained at the start of the visibility chain, i.e. the
4345 -- one that is referenced by the Node_Id value of the name of the
4346 -- given identifier.
4348 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
4350 return Get_Name_Entity_Id
(Chars
(N
));
4353 -----------------------------
4354 -- Current_Entity_In_Scope --
4355 -----------------------------
4357 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
4359 CS
: constant Entity_Id
:= Current_Scope
;
4361 Transient_Case
: constant Boolean := Scope_Is_Transient
;
4364 E
:= Get_Name_Entity_Id
(Chars
(N
));
4366 and then Scope
(E
) /= CS
4367 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
4373 end Current_Entity_In_Scope
;
4379 function Current_Scope
return Entity_Id
is
4381 if Scope_Stack
.Last
= -1 then
4382 return Standard_Standard
;
4385 C
: constant Entity_Id
:=
4386 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
4391 return Standard_Standard
;
4397 ------------------------
4398 -- Current_Subprogram --
4399 ------------------------
4401 function Current_Subprogram
return Entity_Id
is
4402 Scop
: constant Entity_Id
:= Current_Scope
;
4404 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
4407 return Enclosing_Subprogram
(Scop
);
4409 end Current_Subprogram
;
4411 ----------------------------------
4412 -- Deepest_Type_Access_Level --
4413 ----------------------------------
4415 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
4417 if Ekind
(Typ
) = E_Anonymous_Access_Type
4418 and then not Is_Local_Anonymous_Access
(Typ
)
4419 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
4421 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4425 Scope_Depth
(Enclosing_Dynamic_Scope
4426 (Defining_Identifier
4427 (Associated_Node_For_Itype
(Typ
))));
4429 -- For generic formal type, return Int'Last (infinite).
4430 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4432 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
4433 return UI_From_Int
(Int
'Last);
4436 return Type_Access_Level
(Typ
);
4438 end Deepest_Type_Access_Level
;
4440 ---------------------
4441 -- Defining_Entity --
4442 ---------------------
4444 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4445 K
: constant Node_Kind
:= Nkind
(N
);
4446 Err
: Entity_Id
:= Empty
;
4451 N_Subprogram_Declaration |
4452 N_Abstract_Subprogram_Declaration |
4454 N_Package_Declaration |
4455 N_Subprogram_Renaming_Declaration |
4456 N_Subprogram_Body_Stub |
4457 N_Generic_Subprogram_Declaration |
4458 N_Generic_Package_Declaration |
4459 N_Formal_Subprogram_Declaration |
4460 N_Expression_Function
4462 return Defining_Entity
(Specification
(N
));
4465 N_Component_Declaration |
4466 N_Defining_Program_Unit_Name |
4467 N_Discriminant_Specification |
4469 N_Entry_Declaration |
4470 N_Entry_Index_Specification |
4471 N_Exception_Declaration |
4472 N_Exception_Renaming_Declaration |
4473 N_Formal_Object_Declaration |
4474 N_Formal_Package_Declaration |
4475 N_Formal_Type_Declaration |
4476 N_Full_Type_Declaration |
4477 N_Implicit_Label_Declaration |
4478 N_Incomplete_Type_Declaration |
4479 N_Loop_Parameter_Specification |
4480 N_Number_Declaration |
4481 N_Object_Declaration |
4482 N_Object_Renaming_Declaration |
4483 N_Package_Body_Stub |
4484 N_Parameter_Specification |
4485 N_Private_Extension_Declaration |
4486 N_Private_Type_Declaration |
4488 N_Protected_Body_Stub |
4489 N_Protected_Type_Declaration |
4490 N_Single_Protected_Declaration |
4491 N_Single_Task_Declaration |
4492 N_Subtype_Declaration |
4495 N_Task_Type_Declaration
4497 return Defining_Identifier
(N
);
4500 return Defining_Entity
(Proper_Body
(N
));
4503 N_Function_Instantiation |
4504 N_Function_Specification |
4505 N_Generic_Function_Renaming_Declaration |
4506 N_Generic_Package_Renaming_Declaration |
4507 N_Generic_Procedure_Renaming_Declaration |
4509 N_Package_Instantiation |
4510 N_Package_Renaming_Declaration |
4511 N_Package_Specification |
4512 N_Procedure_Instantiation |
4513 N_Procedure_Specification
4516 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
4519 if Nkind
(Nam
) in N_Entity
then
4522 -- For Error, make up a name and attach to declaration
4523 -- so we can continue semantic analysis
4525 elsif Nam
= Error
then
4526 Err
:= Make_Temporary
(Sloc
(N
), 'T');
4527 Set_Defining_Unit_Name
(N
, Err
);
4531 -- If not an entity, get defining identifier
4534 return Defining_Identifier
(Nam
);
4542 return Entity
(Identifier
(N
));
4545 raise Program_Error
;
4548 end Defining_Entity
;
4550 --------------------------
4551 -- Denotes_Discriminant --
4552 --------------------------
4554 function Denotes_Discriminant
4556 Check_Concurrent
: Boolean := False) return Boolean
4561 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
4567 -- If we are checking for a protected type, the discriminant may have
4568 -- been rewritten as the corresponding discriminal of the original type
4569 -- or of the corresponding concurrent record, depending on whether we
4570 -- are in the spec or body of the protected type.
4572 return Ekind
(E
) = E_Discriminant
4575 and then Ekind
(E
) = E_In_Parameter
4576 and then Present
(Discriminal_Link
(E
))
4578 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
4580 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
4582 end Denotes_Discriminant
;
4584 -------------------------
4585 -- Denotes_Same_Object --
4586 -------------------------
4588 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
4589 Obj1
: Node_Id
:= A1
;
4590 Obj2
: Node_Id
:= A2
;
4592 function Has_Prefix
(N
: Node_Id
) return Boolean;
4593 -- Return True if N has attribute Prefix
4595 function Is_Renaming
(N
: Node_Id
) return Boolean;
4596 -- Return true if N names a renaming entity
4598 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
4599 -- For renamings, return False if the prefix of any dereference within
4600 -- the renamed object_name is a variable, or any expression within the
4601 -- renamed object_name contains references to variables or calls on
4602 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4608 function Has_Prefix
(N
: Node_Id
) return Boolean is
4612 N_Attribute_Reference
,
4614 N_Explicit_Dereference
,
4615 N_Indexed_Component
,
4617 N_Selected_Component
,
4625 function Is_Renaming
(N
: Node_Id
) return Boolean is
4627 return Is_Entity_Name
(N
)
4628 and then Present
(Renamed_Entity
(Entity
(N
)));
4631 -----------------------
4632 -- Is_Valid_Renaming --
4633 -----------------------
4635 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
4637 function Check_Renaming
(N
: Node_Id
) return Boolean;
4638 -- Recursive function used to traverse all the prefixes of N
4640 function Check_Renaming
(N
: Node_Id
) return Boolean is
4643 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
4648 if Nkind
(N
) = N_Indexed_Component
then
4653 Indx
:= First
(Expressions
(N
));
4654 while Present
(Indx
) loop
4655 if not Is_OK_Static_Expression
(Indx
) then
4664 if Has_Prefix
(N
) then
4666 P
: constant Node_Id
:= Prefix
(N
);
4669 if Nkind
(N
) = N_Explicit_Dereference
4670 and then Is_Variable
(P
)
4674 elsif Is_Entity_Name
(P
)
4675 and then Ekind
(Entity
(P
)) = E_Function
4679 elsif Nkind
(P
) = N_Function_Call
then
4683 -- Recursion to continue traversing the prefix of the
4684 -- renaming expression
4686 return Check_Renaming
(P
);
4693 -- Start of processing for Is_Valid_Renaming
4696 return Check_Renaming
(N
);
4697 end Is_Valid_Renaming
;
4699 -- Start of processing for Denotes_Same_Object
4702 -- Both names statically denote the same stand-alone object or parameter
4703 -- (RM 6.4.1(6.5/3))
4705 if Is_Entity_Name
(Obj1
)
4706 and then Is_Entity_Name
(Obj2
)
4707 and then Entity
(Obj1
) = Entity
(Obj2
)
4712 -- For renamings, the prefix of any dereference within the renamed
4713 -- object_name is not a variable, and any expression within the
4714 -- renamed object_name contains no references to variables nor
4715 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4717 if Is_Renaming
(Obj1
) then
4718 if Is_Valid_Renaming
(Obj1
) then
4719 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
4725 if Is_Renaming
(Obj2
) then
4726 if Is_Valid_Renaming
(Obj2
) then
4727 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
4733 -- No match if not same node kind (such cases are handled by
4734 -- Denotes_Same_Prefix)
4736 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
4739 -- After handling valid renamings, one of the two names statically
4740 -- denoted a renaming declaration whose renamed object_name is known
4741 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4743 elsif Is_Entity_Name
(Obj1
) then
4744 if Is_Entity_Name
(Obj2
) then
4745 return Entity
(Obj1
) = Entity
(Obj2
);
4750 -- Both names are selected_components, their prefixes are known to
4751 -- denote the same object, and their selector_names denote the same
4752 -- component (RM 6.4.1(6.6/3)
4754 elsif Nkind
(Obj1
) = N_Selected_Component
then
4755 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4757 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
4759 -- Both names are dereferences and the dereferenced names are known to
4760 -- denote the same object (RM 6.4.1(6.7/3))
4762 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
4763 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
4765 -- Both names are indexed_components, their prefixes are known to denote
4766 -- the same object, and each of the pairs of corresponding index values
4767 -- are either both static expressions with the same static value or both
4768 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4770 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4771 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4779 Indx1
:= First
(Expressions
(Obj1
));
4780 Indx2
:= First
(Expressions
(Obj2
));
4781 while Present
(Indx1
) loop
4783 -- Indexes must denote the same static value or same object
4785 if Is_OK_Static_Expression
(Indx1
) then
4786 if not Is_OK_Static_Expression
(Indx2
) then
4789 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4793 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4805 -- Both names are slices, their prefixes are known to denote the same
4806 -- object, and the two slices have statically matching index constraints
4807 -- (RM 6.4.1(6.9/3))
4809 elsif Nkind
(Obj1
) = N_Slice
4810 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4813 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4816 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4817 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4819 -- Check whether bounds are statically identical. There is no
4820 -- attempt to detect partial overlap of slices.
4822 return Denotes_Same_Object
(Lo1
, Lo2
)
4824 Denotes_Same_Object
(Hi1
, Hi2
);
4827 -- In the recursion, literals appear as indexes
4829 elsif Nkind
(Obj1
) = N_Integer_Literal
4831 Nkind
(Obj2
) = N_Integer_Literal
4833 return Intval
(Obj1
) = Intval
(Obj2
);
4838 end Denotes_Same_Object
;
4840 -------------------------
4841 -- Denotes_Same_Prefix --
4842 -------------------------
4844 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
4847 if Is_Entity_Name
(A1
) then
4848 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
4849 and then not Is_Access_Type
(Etype
(A1
))
4851 return Denotes_Same_Object
(A1
, Prefix
(A2
))
4852 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
4857 elsif Is_Entity_Name
(A2
) then
4858 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
4860 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4862 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4865 Root1
, Root2
: Node_Id
;
4866 Depth1
, Depth2
: Int
:= 0;
4869 Root1
:= Prefix
(A1
);
4870 while not Is_Entity_Name
(Root1
) loop
4872 (Root1
, N_Selected_Component
, N_Indexed_Component
)
4876 Root1
:= Prefix
(Root1
);
4879 Depth1
:= Depth1
+ 1;
4882 Root2
:= Prefix
(A2
);
4883 while not Is_Entity_Name
(Root2
) loop
4884 if not Nkind_In
(Root2
, N_Selected_Component
,
4885 N_Indexed_Component
)
4889 Root2
:= Prefix
(Root2
);
4892 Depth2
:= Depth2
+ 1;
4895 -- If both have the same depth and they do not denote the same
4896 -- object, they are disjoint and no warning is needed.
4898 if Depth1
= Depth2
then
4901 elsif Depth1
> Depth2
then
4902 Root1
:= Prefix
(A1
);
4903 for J
in 1 .. Depth1
- Depth2
- 1 loop
4904 Root1
:= Prefix
(Root1
);
4907 return Denotes_Same_Object
(Root1
, A2
);
4910 Root2
:= Prefix
(A2
);
4911 for J
in 1 .. Depth2
- Depth1
- 1 loop
4912 Root2
:= Prefix
(Root2
);
4915 return Denotes_Same_Object
(A1
, Root2
);
4922 end Denotes_Same_Prefix
;
4924 ----------------------
4925 -- Denotes_Variable --
4926 ----------------------
4928 function Denotes_Variable
(N
: Node_Id
) return Boolean is
4930 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
4931 end Denotes_Variable
;
4933 -----------------------------
4934 -- Depends_On_Discriminant --
4935 -----------------------------
4937 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
4942 Get_Index_Bounds
(N
, L
, H
);
4943 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
4944 end Depends_On_Discriminant
;
4946 -------------------------
4947 -- Designate_Same_Unit --
4948 -------------------------
4950 function Designate_Same_Unit
4952 Name2
: Node_Id
) return Boolean
4954 K1
: constant Node_Kind
:= Nkind
(Name1
);
4955 K2
: constant Node_Kind
:= Nkind
(Name2
);
4957 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
4958 -- Returns the parent unit name node of a defining program unit name
4959 -- or the prefix if N is a selected component or an expanded name.
4961 function Select_Node
(N
: Node_Id
) return Node_Id
;
4962 -- Returns the defining identifier node of a defining program unit
4963 -- name or the selector node if N is a selected component or an
4970 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
4972 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4983 function Select_Node
(N
: Node_Id
) return Node_Id
is
4985 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4986 return Defining_Identifier
(N
);
4988 return Selector_Name
(N
);
4992 -- Start of processing for Designate_Same_Unit
4995 if Nkind_In
(K1
, N_Identifier
, N_Defining_Identifier
)
4997 Nkind_In
(K2
, N_Identifier
, N_Defining_Identifier
)
4999 return Chars
(Name1
) = Chars
(Name2
);
5001 elsif Nkind_In
(K1
, N_Expanded_Name
,
5002 N_Selected_Component
,
5003 N_Defining_Program_Unit_Name
)
5005 Nkind_In
(K2
, N_Expanded_Name
,
5006 N_Selected_Component
,
5007 N_Defining_Program_Unit_Name
)
5010 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
5012 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
5017 end Designate_Same_Unit
;
5019 ------------------------------------------
5020 -- function Dynamic_Accessibility_Level --
5021 ------------------------------------------
5023 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
5025 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5027 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
5028 -- Construct an integer literal representing an accessibility level
5029 -- with its type set to Natural.
5031 ------------------------
5032 -- Make_Level_Literal --
5033 ------------------------
5035 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
5036 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
5038 Set_Etype
(Result
, Standard_Natural
);
5040 end Make_Level_Literal
;
5042 -- Start of processing for Dynamic_Accessibility_Level
5045 if Is_Entity_Name
(Expr
) then
5048 if Present
(Renamed_Object
(E
)) then
5049 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
5052 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
5053 if Present
(Extra_Accessibility
(E
)) then
5054 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
5059 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5061 case Nkind
(Expr
) is
5063 -- For access discriminant, the level of the enclosing object
5065 when N_Selected_Component
=>
5066 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
5067 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
5068 E_Anonymous_Access_Type
5070 return Make_Level_Literal
(Object_Access_Level
(Expr
));
5073 when N_Attribute_Reference
=>
5074 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
5076 -- For X'Access, the level of the prefix X
5078 when Attribute_Access
=>
5079 return Make_Level_Literal
5080 (Object_Access_Level
(Prefix
(Expr
)));
5082 -- Treat the unchecked attributes as library-level
5084 when Attribute_Unchecked_Access |
5085 Attribute_Unrestricted_Access
=>
5086 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
5088 -- No other access-valued attributes
5091 raise Program_Error
;
5096 -- Unimplemented: depends on context. As an actual parameter where
5097 -- formal type is anonymous, use
5098 -- Scope_Depth (Current_Scope) + 1.
5099 -- For other cases, see 3.10.2(14/3) and following. ???
5103 when N_Type_Conversion
=>
5104 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
5106 -- Handle type conversions introduced for a rename of an
5107 -- Ada 2012 stand-alone object of an anonymous access type.
5109 return Dynamic_Accessibility_Level
(Expression
(Expr
));
5116 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
5117 end Dynamic_Accessibility_Level
;
5119 -----------------------------------
5120 -- Effective_Extra_Accessibility --
5121 -----------------------------------
5123 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
5125 if Present
(Renamed_Object
(Id
))
5126 and then Is_Entity_Name
(Renamed_Object
(Id
))
5128 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
5130 return Extra_Accessibility
(Id
);
5132 end Effective_Extra_Accessibility
;
5134 -----------------------------
5135 -- Effective_Reads_Enabled --
5136 -----------------------------
5138 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
5140 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
5141 end Effective_Reads_Enabled
;
5143 ------------------------------
5144 -- Effective_Writes_Enabled --
5145 ------------------------------
5147 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
5149 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
5150 end Effective_Writes_Enabled
;
5152 ------------------------------
5153 -- Enclosing_Comp_Unit_Node --
5154 ------------------------------
5156 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
5157 Current_Node
: Node_Id
;
5161 while Present
(Current_Node
)
5162 and then Nkind
(Current_Node
) /= N_Compilation_Unit
5164 Current_Node
:= Parent
(Current_Node
);
5167 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
5170 return Current_Node
;
5172 end Enclosing_Comp_Unit_Node
;
5174 --------------------------
5175 -- Enclosing_CPP_Parent --
5176 --------------------------
5178 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
5179 Parent_Typ
: Entity_Id
:= Typ
;
5182 while not Is_CPP_Class
(Parent_Typ
)
5183 and then Etype
(Parent_Typ
) /= Parent_Typ
5185 Parent_Typ
:= Etype
(Parent_Typ
);
5187 if Is_Private_Type
(Parent_Typ
) then
5188 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5192 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
5194 end Enclosing_CPP_Parent
;
5196 ----------------------------
5197 -- Enclosing_Generic_Body --
5198 ----------------------------
5200 function Enclosing_Generic_Body
5201 (N
: Node_Id
) return Node_Id
5209 while Present
(P
) loop
5210 if Nkind
(P
) = N_Package_Body
5211 or else Nkind
(P
) = N_Subprogram_Body
5213 Spec
:= Corresponding_Spec
(P
);
5215 if Present
(Spec
) then
5216 Decl
:= Unit_Declaration_Node
(Spec
);
5218 if Nkind
(Decl
) = N_Generic_Package_Declaration
5219 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5230 end Enclosing_Generic_Body
;
5232 ----------------------------
5233 -- Enclosing_Generic_Unit --
5234 ----------------------------
5236 function Enclosing_Generic_Unit
5237 (N
: Node_Id
) return Node_Id
5245 while Present
(P
) loop
5246 if Nkind
(P
) = N_Generic_Package_Declaration
5247 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
5251 elsif Nkind
(P
) = N_Package_Body
5252 or else Nkind
(P
) = N_Subprogram_Body
5254 Spec
:= Corresponding_Spec
(P
);
5256 if Present
(Spec
) then
5257 Decl
:= Unit_Declaration_Node
(Spec
);
5259 if Nkind
(Decl
) = N_Generic_Package_Declaration
5260 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5271 end Enclosing_Generic_Unit
;
5273 -------------------------------
5274 -- Enclosing_Lib_Unit_Entity --
5275 -------------------------------
5277 function Enclosing_Lib_Unit_Entity
5278 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
5280 Unit_Entity
: Entity_Id
;
5283 -- Look for enclosing library unit entity by following scope links.
5284 -- Equivalent to, but faster than indexing through the scope stack.
5287 while (Present
(Scope
(Unit_Entity
))
5288 and then Scope
(Unit_Entity
) /= Standard_Standard
)
5289 and not Is_Child_Unit
(Unit_Entity
)
5291 Unit_Entity
:= Scope
(Unit_Entity
);
5295 end Enclosing_Lib_Unit_Entity
;
5297 -----------------------
5298 -- Enclosing_Package --
5299 -----------------------
5301 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
5302 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5305 if Dynamic_Scope
= Standard_Standard
then
5306 return Standard_Standard
;
5308 elsif Dynamic_Scope
= Empty
then
5311 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
5314 return Dynamic_Scope
;
5317 return Enclosing_Package
(Dynamic_Scope
);
5319 end Enclosing_Package
;
5321 --------------------------
5322 -- Enclosing_Subprogram --
5323 --------------------------
5325 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5326 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5329 if Dynamic_Scope
= Standard_Standard
then
5332 elsif Dynamic_Scope
= Empty
then
5335 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
5336 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
5338 elsif Ekind
(Dynamic_Scope
) = E_Block
5339 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
5341 return Enclosing_Subprogram
(Dynamic_Scope
);
5343 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
5344 return Get_Task_Body_Procedure
(Dynamic_Scope
);
5346 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
5347 and then Present
(Full_View
(Dynamic_Scope
))
5348 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
5350 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
5352 -- No body is generated if the protected operation is eliminated
5354 elsif Convention
(Dynamic_Scope
) = Convention_Protected
5355 and then not Is_Eliminated
(Dynamic_Scope
)
5356 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
5358 return Protected_Body_Subprogram
(Dynamic_Scope
);
5361 return Dynamic_Scope
;
5363 end Enclosing_Subprogram
;
5365 ------------------------
5366 -- Ensure_Freeze_Node --
5367 ------------------------
5369 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
5372 if No
(Freeze_Node
(E
)) then
5373 FN
:= Make_Freeze_Entity
(Sloc
(E
));
5374 Set_Has_Delayed_Freeze
(E
);
5375 Set_Freeze_Node
(E
, FN
);
5376 Set_Access_Types_To_Process
(FN
, No_Elist
);
5377 Set_TSS_Elist
(FN
, No_Elist
);
5380 end Ensure_Freeze_Node
;
5386 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5387 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5388 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5389 S
: constant Entity_Id
:= Current_Scope
;
5392 Generate_Definition
(Def_Id
);
5394 -- Add new name to current scope declarations. Check for duplicate
5395 -- declaration, which may or may not be a genuine error.
5399 -- Case of previous entity entered because of a missing declaration
5400 -- or else a bad subtype indication. Best is to use the new entity,
5401 -- and make the previous one invisible.
5403 if Etype
(E
) = Any_Type
then
5404 Set_Is_Immediately_Visible
(E
, False);
5406 -- Case of renaming declaration constructed for package instances.
5407 -- if there is an explicit declaration with the same identifier,
5408 -- the renaming is not immediately visible any longer, but remains
5409 -- visible through selected component notation.
5411 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
5412 and then not Comes_From_Source
(E
)
5414 Set_Is_Immediately_Visible
(E
, False);
5416 -- The new entity may be the package renaming, which has the same
5417 -- same name as a generic formal which has been seen already.
5419 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
5420 and then not Comes_From_Source
(Def_Id
)
5422 Set_Is_Immediately_Visible
(E
, False);
5424 -- For a fat pointer corresponding to a remote access to subprogram,
5425 -- we use the same identifier as the RAS type, so that the proper
5426 -- name appears in the stub. This type is only retrieved through
5427 -- the RAS type and never by visibility, and is not added to the
5428 -- visibility list (see below).
5430 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
5431 and then Ekind
(Def_Id
) = E_Record_Type
5432 and then Present
(Corresponding_Remote_Type
(Def_Id
))
5436 -- Case of an implicit operation or derived literal. The new entity
5437 -- hides the implicit one, which is removed from all visibility,
5438 -- i.e. the entity list of its scope, and homonym chain of its name.
5440 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
5441 or else Is_Internal
(E
)
5445 Prev_Vis
: Entity_Id
;
5446 Decl
: constant Node_Id
:= Parent
(E
);
5449 -- If E is an implicit declaration, it cannot be the first
5450 -- entity in the scope.
5452 Prev
:= First_Entity
(Current_Scope
);
5453 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
5459 -- If E is not on the entity chain of the current scope,
5460 -- it is an implicit declaration in the generic formal
5461 -- part of a generic subprogram. When analyzing the body,
5462 -- the generic formals are visible but not on the entity
5463 -- chain of the subprogram. The new entity will become
5464 -- the visible one in the body.
5467 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
5471 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5473 if No
(Next_Entity
(Prev
)) then
5474 Set_Last_Entity
(Current_Scope
, Prev
);
5477 if E
= Current_Entity
(E
) then
5481 Prev_Vis
:= Current_Entity
(E
);
5482 while Homonym
(Prev_Vis
) /= E
loop
5483 Prev_Vis
:= Homonym
(Prev_Vis
);
5487 if Present
(Prev_Vis
) then
5489 -- Skip E in the visibility chain
5491 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5494 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5499 -- This section of code could use a comment ???
5501 elsif Present
(Etype
(E
))
5502 and then Is_Concurrent_Type
(Etype
(E
))
5507 -- If the homograph is a protected component renaming, it should not
5508 -- be hiding the current entity. Such renamings are treated as weak
5511 elsif Is_Prival
(E
) then
5512 Set_Is_Immediately_Visible
(E
, False);
5514 -- In this case the current entity is a protected component renaming.
5515 -- Perform minimal decoration by setting the scope and return since
5516 -- the prival should not be hiding other visible entities.
5518 elsif Is_Prival
(Def_Id
) then
5519 Set_Scope
(Def_Id
, Current_Scope
);
5522 -- Analogous to privals, the discriminal generated for an entry index
5523 -- parameter acts as a weak declaration. Perform minimal decoration
5524 -- to avoid bogus errors.
5526 elsif Is_Discriminal
(Def_Id
)
5527 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
5529 Set_Scope
(Def_Id
, Current_Scope
);
5532 -- In the body or private part of an instance, a type extension may
5533 -- introduce a component with the same name as that of an actual. The
5534 -- legality rule is not enforced, but the semantics of the full type
5535 -- with two components of same name are not clear at this point???
5537 elsif In_Instance_Not_Visible
then
5540 -- When compiling a package body, some child units may have become
5541 -- visible. They cannot conflict with local entities that hide them.
5543 elsif Is_Child_Unit
(E
)
5544 and then In_Open_Scopes
(Scope
(E
))
5545 and then not Is_Immediately_Visible
(E
)
5549 -- Conversely, with front-end inlining we may compile the parent body
5550 -- first, and a child unit subsequently. The context is now the
5551 -- parent spec, and body entities are not visible.
5553 elsif Is_Child_Unit
(Def_Id
)
5554 and then Is_Package_Body_Entity
(E
)
5555 and then not In_Package_Body
(Current_Scope
)
5559 -- Case of genuine duplicate declaration
5562 Error_Msg_Sloc
:= Sloc
(E
);
5564 -- If the previous declaration is an incomplete type declaration
5565 -- this may be an attempt to complete it with a private type. The
5566 -- following avoids confusing cascaded errors.
5568 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
5569 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
5572 ("incomplete type cannot be completed with a private " &
5573 "declaration", Parent
(Def_Id
));
5574 Set_Is_Immediately_Visible
(E
, False);
5575 Set_Full_View
(E
, Def_Id
);
5577 -- An inherited component of a record conflicts with a new
5578 -- discriminant. The discriminant is inserted first in the scope,
5579 -- but the error should be posted on it, not on the component.
5581 elsif Ekind
(E
) = E_Discriminant
5582 and then Present
(Scope
(Def_Id
))
5583 and then Scope
(Def_Id
) /= Current_Scope
5585 Error_Msg_Sloc
:= Sloc
(Def_Id
);
5586 Error_Msg_N
("& conflicts with declaration#", E
);
5589 -- If the name of the unit appears in its own context clause, a
5590 -- dummy package with the name has already been created, and the
5591 -- error emitted. Try to continue quietly.
5593 elsif Error_Posted
(E
)
5594 and then Sloc
(E
) = No_Location
5595 and then Nkind
(Parent
(E
)) = N_Package_Specification
5596 and then Current_Scope
= Standard_Standard
5598 Set_Scope
(Def_Id
, Current_Scope
);
5602 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
5604 -- Avoid cascaded messages with duplicate components in
5607 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
5612 if Nkind
(Parent
(Parent
(Def_Id
))) =
5613 N_Generic_Subprogram_Declaration
5615 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
5617 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
5620 -- If entity is in standard, then we are in trouble, because it
5621 -- means that we have a library package with a duplicated name.
5622 -- That's hard to recover from, so abort.
5624 if S
= Standard_Standard
then
5625 raise Unrecoverable_Error
;
5627 -- Otherwise we continue with the declaration. Having two
5628 -- identical declarations should not cause us too much trouble.
5636 -- If we fall through, declaration is OK, at least OK enough to continue
5638 -- If Def_Id is a discriminant or a record component we are in the midst
5639 -- of inheriting components in a derived record definition. Preserve
5640 -- their Ekind and Etype.
5642 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
5645 -- If a type is already set, leave it alone (happens when a type
5646 -- declaration is reanalyzed following a call to the optimizer).
5648 elsif Present
(Etype
(Def_Id
)) then
5651 -- Otherwise, the kind E_Void insures that premature uses of the entity
5652 -- will be detected. Any_Type insures that no cascaded errors will occur
5655 Set_Ekind
(Def_Id
, E_Void
);
5656 Set_Etype
(Def_Id
, Any_Type
);
5659 -- Inherited discriminants and components in derived record types are
5660 -- immediately visible. Itypes are not.
5662 -- Unless the Itype is for a record type with a corresponding remote
5663 -- type (what is that about, it was not commented ???)
5665 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
5667 ((not Is_Record_Type
(Def_Id
)
5668 or else No
(Corresponding_Remote_Type
(Def_Id
)))
5669 and then not Is_Itype
(Def_Id
))
5671 Set_Is_Immediately_Visible
(Def_Id
);
5672 Set_Current_Entity
(Def_Id
);
5675 Set_Homonym
(Def_Id
, C
);
5676 Append_Entity
(Def_Id
, S
);
5677 Set_Public_Status
(Def_Id
);
5679 -- Declaring a homonym is not allowed in SPARK ...
5681 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
5683 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
5684 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
5685 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
5688 -- ... unless the new declaration is in a subprogram, and the
5689 -- visible declaration is a variable declaration or a parameter
5690 -- specification outside that subprogram.
5692 if Present
(Enclosing_Subp
)
5693 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
5694 N_Parameter_Specification
)
5695 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
5699 -- ... or the new declaration is in a package, and the visible
5700 -- declaration occurs outside that package.
5702 elsif Present
(Enclosing_Pack
)
5703 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
5707 -- ... or the new declaration is a component declaration in a
5708 -- record type definition.
5710 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
5713 -- Don't issue error for non-source entities
5715 elsif Comes_From_Source
(Def_Id
)
5716 and then Comes_From_Source
(C
)
5718 Error_Msg_Sloc
:= Sloc
(C
);
5719 Check_SPARK_05_Restriction
5720 ("redeclaration of identifier &#", Def_Id
);
5725 -- Warn if new entity hides an old one
5727 if Warn_On_Hiding
and then Present
(C
)
5729 -- Don't warn for record components since they always have a well
5730 -- defined scope which does not confuse other uses. Note that in
5731 -- some cases, Ekind has not been set yet.
5733 and then Ekind
(C
) /= E_Component
5734 and then Ekind
(C
) /= E_Discriminant
5735 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
5736 and then Ekind
(Def_Id
) /= E_Component
5737 and then Ekind
(Def_Id
) /= E_Discriminant
5738 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
5740 -- Don't warn for one character variables. It is too common to use
5741 -- such variables as locals and will just cause too many false hits.
5743 and then Length_Of_Name
(Chars
(C
)) /= 1
5745 -- Don't warn for non-source entities
5747 and then Comes_From_Source
(C
)
5748 and then Comes_From_Source
(Def_Id
)
5750 -- Don't warn unless entity in question is in extended main source
5752 and then In_Extended_Main_Source_Unit
(Def_Id
)
5754 -- Finally, the hidden entity must be either immediately visible or
5755 -- use visible (i.e. from a used package).
5758 (Is_Immediately_Visible
(C
)
5760 Is_Potentially_Use_Visible
(C
))
5762 Error_Msg_Sloc
:= Sloc
(C
);
5763 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
5771 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
5777 if Is_Entity_Name
(N
) then
5780 -- Follow a possible chain of renamings to reach the root renamed
5783 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5784 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5785 Id
:= Entity
(Renamed_Object
(Id
));
5796 --------------------------
5797 -- Explain_Limited_Type --
5798 --------------------------
5800 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5804 -- For array, component type must be limited
5806 if Is_Array_Type
(T
) then
5807 Error_Msg_Node_2
:= T
;
5809 ("\component type& of type& is limited", N
, Component_Type
(T
));
5810 Explain_Limited_Type
(Component_Type
(T
), N
);
5812 elsif Is_Record_Type
(T
) then
5814 -- No need for extra messages if explicit limited record
5816 if Is_Limited_Record
(Base_Type
(T
)) then
5820 -- Otherwise find a limited component. Check only components that
5821 -- come from source, or inherited components that appear in the
5822 -- source of the ancestor.
5824 C
:= First_Component
(T
);
5825 while Present
(C
) loop
5826 if Is_Limited_Type
(Etype
(C
))
5828 (Comes_From_Source
(C
)
5830 (Present
(Original_Record_Component
(C
))
5832 Comes_From_Source
(Original_Record_Component
(C
))))
5834 Error_Msg_Node_2
:= T
;
5835 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
5836 Explain_Limited_Type
(Etype
(C
), N
);
5843 -- The type may be declared explicitly limited, even if no component
5844 -- of it is limited, in which case we fall out of the loop.
5847 end Explain_Limited_Type
;
5849 -------------------------------
5850 -- Extensions_Visible_Status --
5851 -------------------------------
5853 function Extensions_Visible_Status
5854 (Id
: Entity_Id
) return Extensions_Visible_Mode
5863 -- When a formal parameter is subject to Extensions_Visible, the pragma
5864 -- is stored in the contract of related subprogram.
5866 if Is_Formal
(Id
) then
5869 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
5872 -- No other construct carries this pragma
5875 return Extensions_Visible_None
;
5878 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
5880 -- In certain cases analysis may request the Extensions_Visible status
5881 -- of an expression function before the pragma has been analyzed yet.
5882 -- Inspect the declarative items after the expression function looking
5883 -- for the pragma (if any).
5885 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
5886 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
5887 while Present
(Decl
) loop
5888 if Nkind
(Decl
) = N_Pragma
5889 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
5894 -- A source construct ends the region where Extensions_Visible may
5895 -- appear, stop the traversal. An expanded expression function is
5896 -- no longer a source construct, but it must still be recognized.
5898 elsif Comes_From_Source
(Decl
)
5900 (Nkind_In
(Decl
, N_Subprogram_Body
,
5901 N_Subprogram_Declaration
)
5902 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
5911 -- Extract the value from the Boolean expression (if any)
5913 if Present
(Prag
) then
5914 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
5916 if Present
(Arg
) then
5917 Expr
:= Get_Pragma_Arg
(Arg
);
5919 -- When the associated subprogram is an expression function, the
5920 -- argument of the pragma may not have been analyzed.
5922 if not Analyzed
(Expr
) then
5923 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
5926 -- Guard against cascading errors when the argument of pragma
5927 -- Extensions_Visible is not a valid static Boolean expression.
5929 if Error_Posted
(Expr
) then
5930 return Extensions_Visible_None
;
5932 elsif Is_True
(Expr_Value
(Expr
)) then
5933 return Extensions_Visible_True
;
5936 return Extensions_Visible_False
;
5939 -- Otherwise the aspect or pragma defaults to True
5942 return Extensions_Visible_True
;
5945 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
5946 -- directly specified. In SPARK code, its value defaults to "False".
5948 elsif SPARK_Mode
= On
then
5949 return Extensions_Visible_False
;
5951 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
5955 return Extensions_Visible_True
;
5957 end Extensions_Visible_Status
;
5963 procedure Find_Actual
5965 Formal
: out Entity_Id
;
5968 Parnt
: constant Node_Id
:= Parent
(N
);
5972 if Nkind_In
(Parnt
, N_Indexed_Component
, N_Selected_Component
)
5973 and then N
= Prefix
(Parnt
)
5975 Find_Actual
(Parnt
, Formal
, Call
);
5978 elsif Nkind
(Parnt
) = N_Parameter_Association
5979 and then N
= Explicit_Actual_Parameter
(Parnt
)
5981 Call
:= Parent
(Parnt
);
5983 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
5992 -- If we have a call to a subprogram look for the parameter. Note that
5993 -- we exclude overloaded calls, since we don't know enough to be sure
5994 -- of giving the right answer in this case.
5996 if Nkind_In
(Call
, N_Function_Call
, N_Procedure_Call_Statement
)
5997 and then Is_Entity_Name
(Name
(Call
))
5998 and then Present
(Entity
(Name
(Call
)))
5999 and then Is_Overloadable
(Entity
(Name
(Call
)))
6000 and then not Is_Overloaded
(Name
(Call
))
6002 -- If node is name in call it is not an actual
6004 if N
= Name
(Call
) then
6010 -- Fall here if we are definitely a parameter
6012 Actual
:= First_Actual
(Call
);
6013 Formal
:= First_Formal
(Entity
(Name
(Call
)));
6014 while Present
(Formal
) and then Present
(Actual
) loop
6018 -- An actual that is the prefix in a prefixed call may have
6019 -- been rewritten in the call, after the deferred reference
6020 -- was collected. Check if sloc and kinds and names match.
6022 elsif Sloc
(Actual
) = Sloc
(N
)
6023 and then Nkind
(Actual
) = N_Identifier
6024 and then Nkind
(Actual
) = Nkind
(N
)
6025 and then Chars
(Actual
) = Chars
(N
)
6030 Actual
:= Next_Actual
(Actual
);
6031 Formal
:= Next_Formal
(Formal
);
6036 -- Fall through here if we did not find matching actual
6042 ---------------------------
6043 -- Find_Body_Discriminal --
6044 ---------------------------
6046 function Find_Body_Discriminal
6047 (Spec_Discriminant
: Entity_Id
) return Entity_Id
6053 -- If expansion is suppressed, then the scope can be the concurrent type
6054 -- itself rather than a corresponding concurrent record type.
6056 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
6057 Tsk
:= Scope
(Spec_Discriminant
);
6060 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
6062 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
6065 -- Find discriminant of original concurrent type, and use its current
6066 -- discriminal, which is the renaming within the task/protected body.
6068 Disc
:= First_Discriminant
(Tsk
);
6069 while Present
(Disc
) loop
6070 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
6071 return Discriminal
(Disc
);
6074 Next_Discriminant
(Disc
);
6077 -- That loop should always succeed in finding a matching entry and
6078 -- returning. Fatal error if not.
6080 raise Program_Error
;
6081 end Find_Body_Discriminal
;
6083 -------------------------------------
6084 -- Find_Corresponding_Discriminant --
6085 -------------------------------------
6087 function Find_Corresponding_Discriminant
6089 Typ
: Entity_Id
) return Entity_Id
6091 Par_Disc
: Entity_Id
;
6092 Old_Disc
: Entity_Id
;
6093 New_Disc
: Entity_Id
;
6096 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
6098 -- The original type may currently be private, and the discriminant
6099 -- only appear on its full view.
6101 if Is_Private_Type
(Scope
(Par_Disc
))
6102 and then not Has_Discriminants
(Scope
(Par_Disc
))
6103 and then Present
(Full_View
(Scope
(Par_Disc
)))
6105 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
6107 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
6110 if Is_Class_Wide_Type
(Typ
) then
6111 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
6113 New_Disc
:= First_Discriminant
(Typ
);
6116 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
6117 if Old_Disc
= Par_Disc
then
6121 Next_Discriminant
(Old_Disc
);
6122 Next_Discriminant
(New_Disc
);
6125 -- Should always find it
6127 raise Program_Error
;
6128 end Find_Corresponding_Discriminant
;
6130 ----------------------------------
6131 -- Find_Enclosing_Iterator_Loop --
6132 ----------------------------------
6134 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
6139 -- Traverse the scope chain looking for an iterator loop. Such loops are
6140 -- usually transformed into blocks, hence the use of Original_Node.
6143 while Present
(S
) and then S
/= Standard_Standard
loop
6144 if Ekind
(S
) = E_Loop
6145 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
6147 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
6149 if Nkind
(Constr
) = N_Loop_Statement
6150 and then Present
(Iteration_Scheme
(Constr
))
6151 and then Nkind
(Iterator_Specification
6152 (Iteration_Scheme
(Constr
))) =
6153 N_Iterator_Specification
6163 end Find_Enclosing_Iterator_Loop
;
6165 ------------------------------------
6166 -- Find_Loop_In_Conditional_Block --
6167 ------------------------------------
6169 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
6175 if Nkind
(Stmt
) = N_If_Statement
then
6176 Stmt
:= First
(Then_Statements
(Stmt
));
6179 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
6181 -- Inspect the statements of the conditional block. In general the loop
6182 -- should be the first statement in the statement sequence of the block,
6183 -- but the finalization machinery may have introduced extra object
6186 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
6187 while Present
(Stmt
) loop
6188 if Nkind
(Stmt
) = N_Loop_Statement
then
6195 -- The expansion of attribute 'Loop_Entry produced a malformed block
6197 raise Program_Error
;
6198 end Find_Loop_In_Conditional_Block
;
6200 --------------------------
6201 -- Find_Overlaid_Entity --
6202 --------------------------
6204 procedure Find_Overlaid_Entity
6206 Ent
: out Entity_Id
;
6212 -- We are looking for one of the two following forms:
6214 -- for X'Address use Y'Address
6218 -- Const : constant Address := expr;
6220 -- for X'Address use Const;
6222 -- In the second case, the expr is either Y'Address, or recursively a
6223 -- constant that eventually references Y'Address.
6228 if Nkind
(N
) = N_Attribute_Definition_Clause
6229 and then Chars
(N
) = Name_Address
6231 Expr
:= Expression
(N
);
6233 -- This loop checks the form of the expression for Y'Address,
6234 -- using recursion to deal with intermediate constants.
6237 -- Check for Y'Address
6239 if Nkind
(Expr
) = N_Attribute_Reference
6240 and then Attribute_Name
(Expr
) = Name_Address
6242 Expr
:= Prefix
(Expr
);
6245 -- Check for Const where Const is a constant entity
6247 elsif Is_Entity_Name
(Expr
)
6248 and then Ekind
(Entity
(Expr
)) = E_Constant
6250 Expr
:= Constant_Value
(Entity
(Expr
));
6252 -- Anything else does not need checking
6259 -- This loop checks the form of the prefix for an entity, using
6260 -- recursion to deal with intermediate components.
6263 -- Check for Y where Y is an entity
6265 if Is_Entity_Name
(Expr
) then
6266 Ent
:= Entity
(Expr
);
6269 -- Check for components
6272 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
6274 Expr
:= Prefix
(Expr
);
6277 -- Anything else does not need checking
6284 end Find_Overlaid_Entity
;
6286 -------------------------
6287 -- Find_Parameter_Type --
6288 -------------------------
6290 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
6292 if Nkind
(Param
) /= N_Parameter_Specification
then
6295 -- For an access parameter, obtain the type from the formal entity
6296 -- itself, because access to subprogram nodes do not carry a type.
6297 -- Shouldn't we always use the formal entity ???
6299 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
6300 return Etype
(Defining_Identifier
(Param
));
6303 return Etype
(Parameter_Type
(Param
));
6305 end Find_Parameter_Type
;
6307 -----------------------------------
6308 -- Find_Placement_In_State_Space --
6309 -----------------------------------
6311 procedure Find_Placement_In_State_Space
6312 (Item_Id
: Entity_Id
;
6313 Placement
: out State_Space_Kind
;
6314 Pack_Id
: out Entity_Id
)
6316 Context
: Entity_Id
;
6319 -- Assume that the item does not appear in the state space of a package
6321 Placement
:= Not_In_Package
;
6324 -- Climb the scope stack and examine the enclosing context
6326 Context
:= Scope
(Item_Id
);
6327 while Present
(Context
) and then Context
/= Standard_Standard
loop
6328 if Ekind
(Context
) = E_Package
then
6331 -- A package body is a cut off point for the traversal as the item
6332 -- cannot be visible to the outside from this point on. Note that
6333 -- this test must be done first as a body is also classified as a
6336 if In_Package_Body
(Context
) then
6337 Placement
:= Body_State_Space
;
6340 -- The private part of a package is a cut off point for the
6341 -- traversal as the item cannot be visible to the outside from
6344 elsif In_Private_Part
(Context
) then
6345 Placement
:= Private_State_Space
;
6348 -- When the item appears in the visible state space of a package,
6349 -- continue to climb the scope stack as this may not be the final
6353 Placement
:= Visible_State_Space
;
6355 -- The visible state space of a child unit acts as the proper
6356 -- placement of an item.
6358 if Is_Child_Unit
(Context
) then
6363 -- The item or its enclosing package appear in a construct that has
6367 Placement
:= Not_In_Package
;
6371 Context
:= Scope
(Context
);
6373 end Find_Placement_In_State_Space
;
6375 ------------------------
6376 -- Find_Specific_Type --
6377 ------------------------
6379 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
6380 Typ
: Entity_Id
:= Root_Type
(CW
);
6383 if Ekind
(Typ
) = E_Incomplete_Type
then
6384 if From_Limited_With
(Typ
) then
6385 Typ
:= Non_Limited_View
(Typ
);
6387 Typ
:= Full_View
(Typ
);
6391 if Is_Private_Type
(Typ
)
6392 and then not Is_Tagged_Type
(Typ
)
6393 and then Present
(Full_View
(Typ
))
6395 return Full_View
(Typ
);
6399 end Find_Specific_Type
;
6401 -----------------------------
6402 -- Find_Static_Alternative --
6403 -----------------------------
6405 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
6406 Expr
: constant Node_Id
:= Expression
(N
);
6407 Val
: constant Uint
:= Expr_Value
(Expr
);
6412 Alt
:= First
(Alternatives
(N
));
6415 if Nkind
(Alt
) /= N_Pragma
then
6416 Choice
:= First
(Discrete_Choices
(Alt
));
6417 while Present
(Choice
) loop
6419 -- Others choice, always matches
6421 if Nkind
(Choice
) = N_Others_Choice
then
6424 -- Range, check if value is in the range
6426 elsif Nkind
(Choice
) = N_Range
then
6428 Val
>= Expr_Value
(Low_Bound
(Choice
))
6430 Val
<= Expr_Value
(High_Bound
(Choice
));
6432 -- Choice is a subtype name. Note that we know it must
6433 -- be a static subtype, since otherwise it would have
6434 -- been diagnosed as illegal.
6436 elsif Is_Entity_Name
(Choice
)
6437 and then Is_Type
(Entity
(Choice
))
6439 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
6440 Assume_Valid
=> False);
6442 -- Choice is a subtype indication
6444 elsif Nkind
(Choice
) = N_Subtype_Indication
then
6446 C
: constant Node_Id
:= Constraint
(Choice
);
6447 R
: constant Node_Id
:= Range_Expression
(C
);
6451 Val
>= Expr_Value
(Low_Bound
(R
))
6453 Val
<= Expr_Value
(High_Bound
(R
));
6456 -- Choice is a simple expression
6459 exit Search
when Val
= Expr_Value
(Choice
);
6467 pragma Assert
(Present
(Alt
));
6470 -- The above loop *must* terminate by finding a match, since
6471 -- we know the case statement is valid, and the value of the
6472 -- expression is known at compile time. When we fall out of
6473 -- the loop, Alt points to the alternative that we know will
6474 -- be selected at run time.
6477 end Find_Static_Alternative
;
6483 function First_Actual
(Node
: Node_Id
) return Node_Id
is
6487 if No
(Parameter_Associations
(Node
)) then
6491 N
:= First
(Parameter_Associations
(Node
));
6493 if Nkind
(N
) = N_Parameter_Association
then
6494 return First_Named_Actual
(Node
);
6500 -----------------------
6501 -- Gather_Components --
6502 -----------------------
6504 procedure Gather_Components
6506 Comp_List
: Node_Id
;
6507 Governed_By
: List_Id
;
6509 Report_Errors
: out Boolean)
6513 Discrete_Choice
: Node_Id
;
6514 Comp_Item
: Node_Id
;
6516 Discrim
: Entity_Id
;
6517 Discrim_Name
: Node_Id
;
6518 Discrim_Value
: Node_Id
;
6521 Report_Errors
:= False;
6523 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
6526 elsif Present
(Component_Items
(Comp_List
)) then
6527 Comp_Item
:= First
(Component_Items
(Comp_List
));
6533 while Present
(Comp_Item
) loop
6535 -- Skip the tag of a tagged record, the interface tags, as well
6536 -- as all items that are not user components (anonymous types,
6537 -- rep clauses, Parent field, controller field).
6539 if Nkind
(Comp_Item
) = N_Component_Declaration
then
6541 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
6543 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
6544 Append_Elmt
(Comp
, Into
);
6552 if No
(Variant_Part
(Comp_List
)) then
6555 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
6556 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
6559 -- Look for the discriminant that governs this variant part.
6560 -- The discriminant *must* be in the Governed_By List
6562 Assoc
:= First
(Governed_By
);
6563 Find_Constraint
: loop
6564 Discrim
:= First
(Choices
(Assoc
));
6565 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
6566 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
6568 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
6569 Chars
(Discrim_Name
))
6570 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
6571 = Chars
(Discrim_Name
);
6573 if No
(Next
(Assoc
)) then
6574 if not Is_Constrained
(Typ
)
6575 and then Is_Derived_Type
(Typ
)
6576 and then Present
(Stored_Constraint
(Typ
))
6578 -- If the type is a tagged type with inherited discriminants,
6579 -- use the stored constraint on the parent in order to find
6580 -- the values of discriminants that are otherwise hidden by an
6581 -- explicit constraint. Renamed discriminants are handled in
6584 -- If several parent discriminants are renamed by a single
6585 -- discriminant of the derived type, the call to obtain the
6586 -- Corresponding_Discriminant field only retrieves the last
6587 -- of them. We recover the constraint on the others from the
6588 -- Stored_Constraint as well.
6595 D
:= First_Discriminant
(Etype
(Typ
));
6596 C
:= First_Elmt
(Stored_Constraint
(Typ
));
6597 while Present
(D
) and then Present
(C
) loop
6598 if Chars
(Discrim_Name
) = Chars
(D
) then
6599 if Is_Entity_Name
(Node
(C
))
6600 and then Entity
(Node
(C
)) = Entity
(Discrim
)
6602 -- D is renamed by Discrim, whose value is given in
6609 Make_Component_Association
(Sloc
(Typ
),
6611 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
6612 Duplicate_Subexpr_No_Checks
(Node
(C
)));
6614 exit Find_Constraint
;
6617 Next_Discriminant
(D
);
6624 if No
(Next
(Assoc
)) then
6625 Error_Msg_NE
(" missing value for discriminant&",
6626 First
(Governed_By
), Discrim_Name
);
6627 Report_Errors
:= True;
6632 end loop Find_Constraint
;
6634 Discrim_Value
:= Expression
(Assoc
);
6636 if not Is_OK_Static_Expression
(Discrim_Value
) then
6638 -- If the variant part is governed by a discriminant of the type
6639 -- this is an error. If the variant part and the discriminant are
6640 -- inherited from an ancestor this is legal (AI05-120) unless the
6641 -- components are being gathered for an aggregate, in which case
6642 -- the caller must check Report_Errors.
6644 if Scope
(Original_Record_Component
6645 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
6648 ("value for discriminant & must be static!",
6649 Discrim_Value
, Discrim
);
6650 Why_Not_Static
(Discrim_Value
);
6653 Report_Errors
:= True;
6657 Search_For_Discriminant_Value
: declare
6663 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
6666 Find_Discrete_Value
: while Present
(Variant
) loop
6667 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
6668 while Present
(Discrete_Choice
) loop
6669 exit Find_Discrete_Value
when
6670 Nkind
(Discrete_Choice
) = N_Others_Choice
;
6672 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
6674 UI_Low
:= Expr_Value
(Low
);
6675 UI_High
:= Expr_Value
(High
);
6677 exit Find_Discrete_Value
when
6678 UI_Low
<= UI_Discrim_Value
6680 UI_High
>= UI_Discrim_Value
;
6682 Next
(Discrete_Choice
);
6685 Next_Non_Pragma
(Variant
);
6686 end loop Find_Discrete_Value
;
6687 end Search_For_Discriminant_Value
;
6689 if No
(Variant
) then
6691 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
6692 Report_Errors
:= True;
6696 -- If we have found the corresponding choice, recursively add its
6697 -- components to the Into list.
6700 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
6701 end Gather_Components
;
6703 ------------------------
6704 -- Get_Actual_Subtype --
6705 ------------------------
6707 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
6708 Typ
: constant Entity_Id
:= Etype
(N
);
6709 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
6718 -- If what we have is an identifier that references a subprogram
6719 -- formal, or a variable or constant object, then we get the actual
6720 -- subtype from the referenced entity if one has been built.
6722 if Nkind
(N
) = N_Identifier
6724 (Is_Formal
(Entity
(N
))
6725 or else Ekind
(Entity
(N
)) = E_Constant
6726 or else Ekind
(Entity
(N
)) = E_Variable
)
6727 and then Present
(Actual_Subtype
(Entity
(N
)))
6729 return Actual_Subtype
(Entity
(N
));
6731 -- Actual subtype of unchecked union is always itself. We never need
6732 -- the "real" actual subtype. If we did, we couldn't get it anyway
6733 -- because the discriminant is not available. The restrictions on
6734 -- Unchecked_Union are designed to make sure that this is OK.
6736 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
6739 -- Here for the unconstrained case, we must find actual subtype
6740 -- No actual subtype is available, so we must build it on the fly.
6742 -- Checking the type, not the underlying type, for constrainedness
6743 -- seems to be necessary. Maybe all the tests should be on the type???
6745 elsif (not Is_Constrained
(Typ
))
6746 and then (Is_Array_Type
(Utyp
)
6747 or else (Is_Record_Type
(Utyp
)
6748 and then Has_Discriminants
(Utyp
)))
6749 and then not Has_Unknown_Discriminants
(Utyp
)
6750 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
6752 -- Nothing to do if in spec expression (why not???)
6754 if In_Spec_Expression
then
6757 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
6759 -- If the type has no discriminants, there is no subtype to
6760 -- build, even if the underlying type is discriminated.
6764 -- Else build the actual subtype
6767 Decl
:= Build_Actual_Subtype
(Typ
, N
);
6768 Atyp
:= Defining_Identifier
(Decl
);
6770 -- If Build_Actual_Subtype generated a new declaration then use it
6774 -- The actual subtype is an Itype, so analyze the declaration,
6775 -- but do not attach it to the tree, to get the type defined.
6777 Set_Parent
(Decl
, N
);
6778 Set_Is_Itype
(Atyp
);
6779 Analyze
(Decl
, Suppress
=> All_Checks
);
6780 Set_Associated_Node_For_Itype
(Atyp
, N
);
6781 Set_Has_Delayed_Freeze
(Atyp
, False);
6783 -- We need to freeze the actual subtype immediately. This is
6784 -- needed, because otherwise this Itype will not get frozen
6785 -- at all, and it is always safe to freeze on creation because
6786 -- any associated types must be frozen at this point.
6788 Freeze_Itype
(Atyp
, N
);
6791 -- Otherwise we did not build a declaration, so return original
6798 -- For all remaining cases, the actual subtype is the same as
6799 -- the nominal type.
6804 end Get_Actual_Subtype
;
6806 -------------------------------------
6807 -- Get_Actual_Subtype_If_Available --
6808 -------------------------------------
6810 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
6811 Typ
: constant Entity_Id
:= Etype
(N
);
6814 -- If what we have is an identifier that references a subprogram
6815 -- formal, or a variable or constant object, then we get the actual
6816 -- subtype from the referenced entity if one has been built.
6818 if Nkind
(N
) = N_Identifier
6820 (Is_Formal
(Entity
(N
))
6821 or else Ekind
(Entity
(N
)) = E_Constant
6822 or else Ekind
(Entity
(N
)) = E_Variable
)
6823 and then Present
(Actual_Subtype
(Entity
(N
)))
6825 return Actual_Subtype
(Entity
(N
));
6827 -- Otherwise the Etype of N is returned unchanged
6832 end Get_Actual_Subtype_If_Available
;
6834 ------------------------
6835 -- Get_Body_From_Stub --
6836 ------------------------
6838 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
6840 return Proper_Body
(Unit
(Library_Unit
(N
)));
6841 end Get_Body_From_Stub
;
6843 ---------------------
6844 -- Get_Cursor_Type --
6845 ---------------------
6847 function Get_Cursor_Type
6849 Typ
: Entity_Id
) return Entity_Id
6853 First_Op
: Entity_Id
;
6857 -- If error already detected, return
6859 if Error_Posted
(Aspect
) then
6863 -- The cursor type for an Iterable aspect is the return type of a
6864 -- non-overloaded First primitive operation. Locate association for
6867 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
6869 while Present
(Assoc
) loop
6870 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
6871 First_Op
:= Expression
(Assoc
);
6878 if First_Op
= Any_Id
then
6879 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
6885 -- Locate function with desired name and profile in scope of type
6887 Func
:= First_Entity
(Scope
(Typ
));
6888 while Present
(Func
) loop
6889 if Chars
(Func
) = Chars
(First_Op
)
6890 and then Ekind
(Func
) = E_Function
6891 and then Present
(First_Formal
(Func
))
6892 and then Etype
(First_Formal
(Func
)) = Typ
6893 and then No
(Next_Formal
(First_Formal
(Func
)))
6895 if Cursor
/= Any_Type
then
6897 ("Operation First for iterable type must be unique", Aspect
);
6900 Cursor
:= Etype
(Func
);
6907 -- If not found, no way to resolve remaining primitives.
6909 if Cursor
= Any_Type
then
6911 ("No legal primitive operation First for Iterable type", Aspect
);
6915 end Get_Cursor_Type
;
6917 -------------------------------
6918 -- Get_Default_External_Name --
6919 -------------------------------
6921 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
6923 Get_Decoded_Name_String
(Chars
(E
));
6925 if Opt
.External_Name_Imp_Casing
= Uppercase
then
6926 Set_Casing
(All_Upper_Case
);
6928 Set_Casing
(All_Lower_Case
);
6932 Make_String_Literal
(Sloc
(E
),
6933 Strval
=> String_From_Name_Buffer
);
6934 end Get_Default_External_Name
;
6936 --------------------------
6937 -- Get_Enclosing_Object --
6938 --------------------------
6940 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
6942 if Is_Entity_Name
(N
) then
6946 when N_Indexed_Component |
6948 N_Selected_Component
=>
6950 -- If not generating code, a dereference may be left implicit.
6951 -- In thoses cases, return Empty.
6953 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6956 return Get_Enclosing_Object
(Prefix
(N
));
6959 when N_Type_Conversion
=>
6960 return Get_Enclosing_Object
(Expression
(N
));
6966 end Get_Enclosing_Object
;
6968 ---------------------------
6969 -- Get_Enum_Lit_From_Pos --
6970 ---------------------------
6972 function Get_Enum_Lit_From_Pos
6975 Loc
: Source_Ptr
) return Node_Id
6977 Btyp
: Entity_Id
:= Base_Type
(T
);
6981 -- In the case where the literal is of type Character, Wide_Character
6982 -- or Wide_Wide_Character or of a type derived from them, there needs
6983 -- to be some special handling since there is no explicit chain of
6984 -- literals to search. Instead, an N_Character_Literal node is created
6985 -- with the appropriate Char_Code and Chars fields.
6987 if Is_Standard_Character_Type
(T
) then
6988 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
6990 Make_Character_Literal
(Loc
,
6992 Char_Literal_Value
=> Pos
);
6994 -- For all other cases, we have a complete table of literals, and
6995 -- we simply iterate through the chain of literal until the one
6996 -- with the desired position value is found.
6999 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
7000 Btyp
:= Full_View
(Btyp
);
7003 Lit
:= First_Literal
(Btyp
);
7004 for J
in 1 .. UI_To_Int
(Pos
) loop
7008 return New_Occurrence_Of
(Lit
, Loc
);
7010 end Get_Enum_Lit_From_Pos
;
7012 ---------------------------------
7013 -- Get_Ensures_From_CTC_Pragma --
7014 ---------------------------------
7016 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
7017 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
7021 if List_Length
(Args
) = 4 then
7022 Res
:= Pick
(Args
, 4);
7024 elsif List_Length
(Args
) = 3 then
7025 Res
:= Pick
(Args
, 3);
7027 if Chars
(Res
) /= Name_Ensures
then
7036 end Get_Ensures_From_CTC_Pragma
;
7038 ------------------------
7039 -- Get_Generic_Entity --
7040 ------------------------
7042 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
7043 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
7045 if Present
(Renamed_Object
(Ent
)) then
7046 return Renamed_Object
(Ent
);
7050 end Get_Generic_Entity
;
7052 -------------------------------------
7053 -- Get_Incomplete_View_Of_Ancestor --
7054 -------------------------------------
7056 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
7057 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
7058 Par_Scope
: Entity_Id
;
7059 Par_Type
: Entity_Id
;
7062 -- The incomplete view of an ancestor is only relevant for private
7063 -- derived types in child units.
7065 if not Is_Derived_Type
(E
)
7066 or else not Is_Child_Unit
(Cur_Unit
)
7071 Par_Scope
:= Scope
(Cur_Unit
);
7072 if No
(Par_Scope
) then
7076 Par_Type
:= Etype
(Base_Type
(E
));
7078 -- Traverse list of ancestor types until we find one declared in
7079 -- a parent or grandparent unit (two levels seem sufficient).
7081 while Present
(Par_Type
) loop
7082 if Scope
(Par_Type
) = Par_Scope
7083 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
7087 elsif not Is_Derived_Type
(Par_Type
) then
7091 Par_Type
:= Etype
(Base_Type
(Par_Type
));
7095 -- If none found, there is no relevant ancestor type.
7099 end Get_Incomplete_View_Of_Ancestor
;
7101 ----------------------
7102 -- Get_Index_Bounds --
7103 ----------------------
7105 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
7106 Kind
: constant Node_Kind
:= Nkind
(N
);
7110 if Kind
= N_Range
then
7112 H
:= High_Bound
(N
);
7114 elsif Kind
= N_Subtype_Indication
then
7115 R
:= Range_Expression
(Constraint
(N
));
7123 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
7124 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
7127 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
7128 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
7132 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
7133 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
7136 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
7137 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
7141 -- N is an expression, indicating a range with one value
7146 end Get_Index_Bounds
;
7148 ---------------------------------
7149 -- Get_Iterable_Type_Primitive --
7150 ---------------------------------
7152 function Get_Iterable_Type_Primitive
7154 Nam
: Name_Id
) return Entity_Id
7156 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
7164 Assoc
:= First
(Component_Associations
(Funcs
));
7165 while Present
(Assoc
) loop
7166 if Chars
(First
(Choices
(Assoc
))) = Nam
then
7167 return Entity
(Expression
(Assoc
));
7170 Assoc
:= Next
(Assoc
);
7175 end Get_Iterable_Type_Primitive
;
7177 ----------------------------------
7178 -- Get_Library_Unit_Name_string --
7179 ----------------------------------
7181 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
7182 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
7185 Get_Unit_Name_String
(Unit_Name_Id
);
7187 -- Remove seven last character (" (spec)" or " (body)")
7189 Name_Len
:= Name_Len
- 7;
7190 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
7191 end Get_Library_Unit_Name_String
;
7193 ------------------------
7194 -- Get_Name_Entity_Id --
7195 ------------------------
7197 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
7199 return Entity_Id
(Get_Name_Table_Int
(Id
));
7200 end Get_Name_Entity_Id
;
7202 ------------------------------
7203 -- Get_Name_From_CTC_Pragma --
7204 ------------------------------
7206 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
7207 Arg
: constant Node_Id
:=
7208 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
7210 return Strval
(Expr_Value_S
(Arg
));
7211 end Get_Name_From_CTC_Pragma
;
7213 -----------------------
7214 -- Get_Parent_Entity --
7215 -----------------------
7217 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
7219 if Nkind
(Unit
) = N_Package_Body
7220 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
7222 return Defining_Entity
7223 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
7224 elsif Nkind
(Unit
) = N_Package_Instantiation
then
7225 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
7227 return Defining_Entity
(Unit
);
7229 end Get_Parent_Entity
;
7234 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
7236 return Get_Pragma_Id
(Pragma_Name
(N
));
7239 -----------------------
7240 -- Get_Reason_String --
7241 -----------------------
7243 procedure Get_Reason_String
(N
: Node_Id
) is
7245 if Nkind
(N
) = N_String_Literal
then
7246 Store_String_Chars
(Strval
(N
));
7248 elsif Nkind
(N
) = N_Op_Concat
then
7249 Get_Reason_String
(Left_Opnd
(N
));
7250 Get_Reason_String
(Right_Opnd
(N
));
7252 -- If not of required form, error
7256 ("Reason for pragma Warnings has wrong form", N
);
7258 ("\must be string literal or concatenation of string literals", N
);
7261 end Get_Reason_String
;
7263 ---------------------------
7264 -- Get_Referenced_Object --
7265 ---------------------------
7267 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
7272 while Is_Entity_Name
(R
)
7273 and then Present
(Renamed_Object
(Entity
(R
)))
7275 R
:= Renamed_Object
(Entity
(R
));
7279 end Get_Referenced_Object
;
7281 ------------------------
7282 -- Get_Renamed_Entity --
7283 ------------------------
7285 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
7290 while Present
(Renamed_Entity
(R
)) loop
7291 R
:= Renamed_Entity
(R
);
7295 end Get_Renamed_Entity
;
7297 ----------------------------------
7298 -- Get_Requires_From_CTC_Pragma --
7299 ----------------------------------
7301 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
7302 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
7306 if List_Length
(Args
) >= 3 then
7307 Res
:= Pick
(Args
, 3);
7309 if Chars
(Res
) /= Name_Requires
then
7318 end Get_Requires_From_CTC_Pragma
;
7320 -------------------------
7321 -- Get_Subprogram_Body --
7322 -------------------------
7324 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
7328 Decl
:= Unit_Declaration_Node
(E
);
7330 if Nkind
(Decl
) = N_Subprogram_Body
then
7333 -- The below comment is bad, because it is possible for
7334 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7336 else -- Nkind (Decl) = N_Subprogram_Declaration
7338 if Present
(Corresponding_Body
(Decl
)) then
7339 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
7341 -- Imported subprogram case
7347 end Get_Subprogram_Body
;
7349 ---------------------------
7350 -- Get_Subprogram_Entity --
7351 ---------------------------
7353 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
7355 Subp_Id
: Entity_Id
;
7358 if Nkind
(Nod
) = N_Accept_Statement
then
7359 Subp
:= Entry_Direct_Name
(Nod
);
7361 elsif Nkind
(Nod
) = N_Slice
then
7362 Subp
:= Prefix
(Nod
);
7368 -- Strip the subprogram call
7371 if Nkind_In
(Subp
, N_Explicit_Dereference
,
7372 N_Indexed_Component
,
7373 N_Selected_Component
)
7375 Subp
:= Prefix
(Subp
);
7377 elsif Nkind_In
(Subp
, N_Type_Conversion
,
7378 N_Unchecked_Type_Conversion
)
7380 Subp
:= Expression
(Subp
);
7387 -- Extract the entity of the subprogram call
7389 if Is_Entity_Name
(Subp
) then
7390 Subp_Id
:= Entity
(Subp
);
7392 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
7393 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
7396 if Is_Subprogram
(Subp_Id
) then
7402 -- The search did not find a construct that denotes a subprogram
7407 end Get_Subprogram_Entity
;
7409 -----------------------------
7410 -- Get_Task_Body_Procedure --
7411 -----------------------------
7413 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
7415 -- Note: A task type may be the completion of a private type with
7416 -- discriminants. When performing elaboration checks on a task
7417 -- declaration, the current view of the type may be the private one,
7418 -- and the procedure that holds the body of the task is held in its
7421 -- This is an odd function, why not have Task_Body_Procedure do
7422 -- the following digging???
7424 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
7425 end Get_Task_Body_Procedure
;
7427 -----------------------
7428 -- Has_Access_Values --
7429 -----------------------
7431 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
7432 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
7435 -- Case of a private type which is not completed yet. This can only
7436 -- happen in the case of a generic format type appearing directly, or
7437 -- as a component of the type to which this function is being applied
7438 -- at the top level. Return False in this case, since we certainly do
7439 -- not know that the type contains access types.
7444 elsif Is_Access_Type
(Typ
) then
7447 elsif Is_Array_Type
(Typ
) then
7448 return Has_Access_Values
(Component_Type
(Typ
));
7450 elsif Is_Record_Type
(Typ
) then
7455 -- Loop to Check components
7457 Comp
:= First_Component_Or_Discriminant
(Typ
);
7458 while Present
(Comp
) loop
7460 -- Check for access component, tag field does not count, even
7461 -- though it is implemented internally using an access type.
7463 if Has_Access_Values
(Etype
(Comp
))
7464 and then Chars
(Comp
) /= Name_uTag
7469 Next_Component_Or_Discriminant
(Comp
);
7478 end Has_Access_Values
;
7480 ------------------------------
7481 -- Has_Compatible_Alignment --
7482 ------------------------------
7484 function Has_Compatible_Alignment
7486 Expr
: Node_Id
) return Alignment_Result
7488 function Has_Compatible_Alignment_Internal
7491 Default
: Alignment_Result
) return Alignment_Result
;
7492 -- This is the internal recursive function that actually does the work.
7493 -- There is one additional parameter, which says what the result should
7494 -- be if no alignment information is found, and there is no definite
7495 -- indication of compatible alignments. At the outer level, this is set
7496 -- to Unknown, but for internal recursive calls in the case where types
7497 -- are known to be correct, it is set to Known_Compatible.
7499 ---------------------------------------
7500 -- Has_Compatible_Alignment_Internal --
7501 ---------------------------------------
7503 function Has_Compatible_Alignment_Internal
7506 Default
: Alignment_Result
) return Alignment_Result
7508 Result
: Alignment_Result
:= Known_Compatible
;
7509 -- Holds the current status of the result. Note that once a value of
7510 -- Known_Incompatible is set, it is sticky and does not get changed
7511 -- to Unknown (the value in Result only gets worse as we go along,
7514 Offs
: Uint
:= No_Uint
;
7515 -- Set to a factor of the offset from the base object when Expr is a
7516 -- selected or indexed component, based on Component_Bit_Offset and
7517 -- Component_Size respectively. A negative value is used to represent
7518 -- a value which is not known at compile time.
7520 procedure Check_Prefix
;
7521 -- Checks the prefix recursively in the case where the expression
7522 -- is an indexed or selected component.
7524 procedure Set_Result
(R
: Alignment_Result
);
7525 -- If R represents a worse outcome (unknown instead of known
7526 -- compatible, or known incompatible), then set Result to R.
7532 procedure Check_Prefix
is
7534 -- The subtlety here is that in doing a recursive call to check
7535 -- the prefix, we have to decide what to do in the case where we
7536 -- don't find any specific indication of an alignment problem.
7538 -- At the outer level, we normally set Unknown as the result in
7539 -- this case, since we can only set Known_Compatible if we really
7540 -- know that the alignment value is OK, but for the recursive
7541 -- call, in the case where the types match, and we have not
7542 -- specified a peculiar alignment for the object, we are only
7543 -- concerned about suspicious rep clauses, the default case does
7544 -- not affect us, since the compiler will, in the absence of such
7545 -- rep clauses, ensure that the alignment is correct.
7547 if Default
= Known_Compatible
7549 (Etype
(Obj
) = Etype
(Expr
)
7550 and then (Unknown_Alignment
(Obj
)
7552 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
7555 (Has_Compatible_Alignment_Internal
7556 (Obj
, Prefix
(Expr
), Known_Compatible
));
7558 -- In all other cases, we need a full check on the prefix
7562 (Has_Compatible_Alignment_Internal
7563 (Obj
, Prefix
(Expr
), Unknown
));
7571 procedure Set_Result
(R
: Alignment_Result
) is
7578 -- Start of processing for Has_Compatible_Alignment_Internal
7581 -- If Expr is a selected component, we must make sure there is no
7582 -- potentially troublesome component clause, and that the record is
7585 if Nkind
(Expr
) = N_Selected_Component
then
7587 -- Packed record always generate unknown alignment
7589 if Is_Packed
(Etype
(Prefix
(Expr
))) then
7590 Set_Result
(Unknown
);
7593 -- Check prefix and component offset
7596 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
7598 -- If Expr is an indexed component, we must make sure there is no
7599 -- potentially troublesome Component_Size clause and that the array
7600 -- is not bit-packed.
7602 elsif Nkind
(Expr
) = N_Indexed_Component
then
7604 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
7605 Ind
: constant Node_Id
:= First_Index
(Typ
);
7608 -- Bit packed array always generates unknown alignment
7610 if Is_Bit_Packed_Array
(Typ
) then
7611 Set_Result
(Unknown
);
7614 -- Check prefix and component offset
7617 Offs
:= Component_Size
(Typ
);
7619 -- Small optimization: compute the full offset when possible
7622 and then Offs
> Uint_0
7623 and then Present
(Ind
)
7624 and then Nkind
(Ind
) = N_Range
7625 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
7626 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
7628 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
7629 - Expr_Value
(Low_Bound
((Ind
))));
7634 -- If we have a null offset, the result is entirely determined by
7635 -- the base object and has already been computed recursively.
7637 if Offs
= Uint_0
then
7640 -- Case where we know the alignment of the object
7642 elsif Known_Alignment
(Obj
) then
7644 ObjA
: constant Uint
:= Alignment
(Obj
);
7645 ExpA
: Uint
:= No_Uint
;
7646 SizA
: Uint
:= No_Uint
;
7649 -- If alignment of Obj is 1, then we are always OK
7652 Set_Result
(Known_Compatible
);
7654 -- Alignment of Obj is greater than 1, so we need to check
7657 -- If we have an offset, see if it is compatible
7659 if Offs
/= No_Uint
and Offs
> Uint_0
then
7660 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
7661 Set_Result
(Known_Incompatible
);
7664 -- See if Expr is an object with known alignment
7666 elsif Is_Entity_Name
(Expr
)
7667 and then Known_Alignment
(Entity
(Expr
))
7669 ExpA
:= Alignment
(Entity
(Expr
));
7671 -- Otherwise, we can use the alignment of the type of
7672 -- Expr given that we already checked for
7673 -- discombobulating rep clauses for the cases of indexed
7674 -- and selected components above.
7676 elsif Known_Alignment
(Etype
(Expr
)) then
7677 ExpA
:= Alignment
(Etype
(Expr
));
7679 -- Otherwise the alignment is unknown
7682 Set_Result
(Default
);
7685 -- If we got an alignment, see if it is acceptable
7687 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
7688 Set_Result
(Known_Incompatible
);
7691 -- If Expr is not a piece of a larger object, see if size
7692 -- is given. If so, check that it is not too small for the
7693 -- required alignment.
7695 if Offs
/= No_Uint
then
7698 -- See if Expr is an object with known size
7700 elsif Is_Entity_Name
(Expr
)
7701 and then Known_Static_Esize
(Entity
(Expr
))
7703 SizA
:= Esize
(Entity
(Expr
));
7705 -- Otherwise, we check the object size of the Expr type
7707 elsif Known_Static_Esize
(Etype
(Expr
)) then
7708 SizA
:= Esize
(Etype
(Expr
));
7711 -- If we got a size, see if it is a multiple of the Obj
7712 -- alignment, if not, then the alignment cannot be
7713 -- acceptable, since the size is always a multiple of the
7716 if SizA
/= No_Uint
then
7717 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
7718 Set_Result
(Known_Incompatible
);
7724 -- If we do not know required alignment, any non-zero offset is a
7725 -- potential problem (but certainly may be OK, so result is unknown).
7727 elsif Offs
/= No_Uint
then
7728 Set_Result
(Unknown
);
7730 -- If we can't find the result by direct comparison of alignment
7731 -- values, then there is still one case that we can determine known
7732 -- result, and that is when we can determine that the types are the
7733 -- same, and no alignments are specified. Then we known that the
7734 -- alignments are compatible, even if we don't know the alignment
7735 -- value in the front end.
7737 elsif Etype
(Obj
) = Etype
(Expr
) then
7739 -- Types are the same, but we have to check for possible size
7740 -- and alignments on the Expr object that may make the alignment
7741 -- different, even though the types are the same.
7743 if Is_Entity_Name
(Expr
) then
7745 -- First check alignment of the Expr object. Any alignment less
7746 -- than Maximum_Alignment is worrisome since this is the case
7747 -- where we do not know the alignment of Obj.
7749 if Known_Alignment
(Entity
(Expr
))
7750 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
7751 Ttypes
.Maximum_Alignment
7753 Set_Result
(Unknown
);
7755 -- Now check size of Expr object. Any size that is not an
7756 -- even multiple of Maximum_Alignment is also worrisome
7757 -- since it may cause the alignment of the object to be less
7758 -- than the alignment of the type.
7760 elsif Known_Static_Esize
(Entity
(Expr
))
7762 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
7763 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
7766 Set_Result
(Unknown
);
7768 -- Otherwise same type is decisive
7771 Set_Result
(Known_Compatible
);
7775 -- Another case to deal with is when there is an explicit size or
7776 -- alignment clause when the types are not the same. If so, then the
7777 -- result is Unknown. We don't need to do this test if the Default is
7778 -- Unknown, since that result will be set in any case.
7780 elsif Default
/= Unknown
7781 and then (Has_Size_Clause
(Etype
(Expr
))
7783 Has_Alignment_Clause
(Etype
(Expr
)))
7785 Set_Result
(Unknown
);
7787 -- If no indication found, set default
7790 Set_Result
(Default
);
7793 -- Return worst result found
7796 end Has_Compatible_Alignment_Internal
;
7798 -- Start of processing for Has_Compatible_Alignment
7801 -- If Obj has no specified alignment, then set alignment from the type
7802 -- alignment. Perhaps we should always do this, but for sure we should
7803 -- do it when there is an address clause since we can do more if the
7804 -- alignment is known.
7806 if Unknown_Alignment
(Obj
) then
7807 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
7810 -- Now do the internal call that does all the work
7812 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
7813 end Has_Compatible_Alignment
;
7815 ----------------------
7816 -- Has_Declarations --
7817 ----------------------
7819 function Has_Declarations
(N
: Node_Id
) return Boolean is
7821 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
7823 N_Compilation_Unit_Aux
,
7829 N_Package_Specification
);
7830 end Has_Declarations
;
7832 ---------------------------------
7833 -- Has_Defaulted_Discriminants --
7834 ---------------------------------
7836 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
7838 return Has_Discriminants
(Typ
)
7839 and then Present
(First_Discriminant
(Typ
))
7840 and then Present
(Discriminant_Default_Value
7841 (First_Discriminant
(Typ
)));
7842 end Has_Defaulted_Discriminants
;
7848 function Has_Denormals
(E
: Entity_Id
) return Boolean is
7850 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
7853 -------------------------------------------
7854 -- Has_Discriminant_Dependent_Constraint --
7855 -------------------------------------------
7857 function Has_Discriminant_Dependent_Constraint
7858 (Comp
: Entity_Id
) return Boolean
7860 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7861 Subt_Indic
: Node_Id
;
7866 -- Discriminants can't depend on discriminants
7868 if Ekind
(Comp
) = E_Discriminant
then
7872 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
7874 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
7875 Constr
:= Constraint
(Subt_Indic
);
7877 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
7878 Assn
:= First
(Constraints
(Constr
));
7879 while Present
(Assn
) loop
7880 case Nkind
(Assn
) is
7881 when N_Subtype_Indication |
7885 if Depends_On_Discriminant
(Assn
) then
7889 when N_Discriminant_Association
=>
7890 if Depends_On_Discriminant
(Expression
(Assn
)) then
7905 end Has_Discriminant_Dependent_Constraint
;
7907 --------------------------
7908 -- Has_Enabled_Property --
7909 --------------------------
7911 function Has_Enabled_Property
7912 (Item_Id
: Entity_Id
;
7913 Property
: Name_Id
) return Boolean
7915 function State_Has_Enabled_Property
return Boolean;
7916 -- Determine whether a state denoted by Item_Id has the property enabled
7918 function Variable_Has_Enabled_Property
return Boolean;
7919 -- Determine whether a variable denoted by Item_Id has the property
7922 --------------------------------
7923 -- State_Has_Enabled_Property --
7924 --------------------------------
7926 function State_Has_Enabled_Property
return Boolean is
7927 Decl
: constant Node_Id
:= Parent
(Item_Id
);
7935 -- The declaration of an external abstract state appears as an
7936 -- extension aggregate. If this is not the case, properties can never
7939 if Nkind
(Decl
) /= N_Extension_Aggregate
then
7943 -- When External appears as a simple option, it automatically enables
7946 Opt
:= First
(Expressions
(Decl
));
7947 while Present
(Opt
) loop
7948 if Nkind
(Opt
) = N_Identifier
7949 and then Chars
(Opt
) = Name_External
7957 -- When External specifies particular properties, inspect those and
7958 -- find the desired one (if any).
7960 Opt
:= First
(Component_Associations
(Decl
));
7961 while Present
(Opt
) loop
7962 Opt_Nam
:= First
(Choices
(Opt
));
7964 if Nkind
(Opt_Nam
) = N_Identifier
7965 and then Chars
(Opt_Nam
) = Name_External
7967 Props
:= Expression
(Opt
);
7969 -- Multiple properties appear as an aggregate
7971 if Nkind
(Props
) = N_Aggregate
then
7973 -- Simple property form
7975 Prop
:= First
(Expressions
(Props
));
7976 while Present
(Prop
) loop
7977 if Chars
(Prop
) = Property
then
7984 -- Property with expression form
7986 Prop
:= First
(Component_Associations
(Props
));
7987 while Present
(Prop
) loop
7988 Prop_Nam
:= First
(Choices
(Prop
));
7990 -- The property can be represented in two ways:
7991 -- others => <value>
7992 -- <property> => <value>
7994 if Nkind
(Prop_Nam
) = N_Others_Choice
7995 or else (Nkind
(Prop_Nam
) = N_Identifier
7996 and then Chars
(Prop_Nam
) = Property
)
7998 return Is_True
(Expr_Value
(Expression
(Prop
)));
8007 return Chars
(Props
) = Property
;
8015 end State_Has_Enabled_Property
;
8017 -----------------------------------
8018 -- Variable_Has_Enabled_Property --
8019 -----------------------------------
8021 function Variable_Has_Enabled_Property
return Boolean is
8022 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
8023 -- Determine whether property pragma Prag (if present) denotes an
8024 -- enabled property.
8030 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
8034 if Present
(Prag
) then
8035 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
8037 -- The pragma has an optional Boolean expression, the related
8038 -- property is enabled only when the expression evaluates to
8041 if Present
(Arg2
) then
8042 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg2
)));
8044 -- Otherwise the lack of expression enables the property by
8051 -- The property was never set in the first place
8060 AR
: constant Node_Id
:=
8061 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
8062 AW
: constant Node_Id
:=
8063 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
8064 ER
: constant Node_Id
:=
8065 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
8066 EW
: constant Node_Id
:=
8067 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
8069 -- Start of processing for Variable_Has_Enabled_Property
8072 -- A non-effectively volatile object can never possess external
8075 if not Is_Effectively_Volatile
(Item_Id
) then
8078 -- External properties related to variables come in two flavors -
8079 -- explicit and implicit. The explicit case is characterized by the
8080 -- presence of a property pragma with an optional Boolean flag. The
8081 -- property is enabled when the flag evaluates to True or the flag is
8082 -- missing altogether.
8084 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
8087 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
8090 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
8093 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
8096 -- The implicit case lacks all property pragmas
8098 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
8104 end Variable_Has_Enabled_Property
;
8106 -- Start of processing for Has_Enabled_Property
8109 -- Abstract states and variables have a flexible scheme of specifying
8110 -- external properties.
8112 if Ekind
(Item_Id
) = E_Abstract_State
then
8113 return State_Has_Enabled_Property
;
8115 elsif Ekind
(Item_Id
) = E_Variable
then
8116 return Variable_Has_Enabled_Property
;
8118 -- Otherwise a property is enabled when the related item is effectively
8122 return Is_Effectively_Volatile
(Item_Id
);
8124 end Has_Enabled_Property
;
8126 --------------------
8127 -- Has_Infinities --
8128 --------------------
8130 function Has_Infinities
(E
: Entity_Id
) return Boolean is
8133 Is_Floating_Point_Type
(E
)
8134 and then Nkind
(Scalar_Range
(E
)) = N_Range
8135 and then Includes_Infinities
(Scalar_Range
(E
));
8138 --------------------
8139 -- Has_Interfaces --
8140 --------------------
8142 function Has_Interfaces
8144 Use_Full_View
: Boolean := True) return Boolean
8146 Typ
: Entity_Id
:= Base_Type
(T
);
8149 -- Handle concurrent types
8151 if Is_Concurrent_Type
(Typ
) then
8152 Typ
:= Corresponding_Record_Type
(Typ
);
8155 if not Present
(Typ
)
8156 or else not Is_Record_Type
(Typ
)
8157 or else not Is_Tagged_Type
(Typ
)
8162 -- Handle private types
8164 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
8165 Typ
:= Full_View
(Typ
);
8168 -- Handle concurrent record types
8170 if Is_Concurrent_Record_Type
(Typ
)
8171 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
8177 if Is_Interface
(Typ
)
8179 (Is_Record_Type
(Typ
)
8180 and then Present
(Interfaces
(Typ
))
8181 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
8186 exit when Etype
(Typ
) = Typ
8188 -- Handle private types
8190 or else (Present
(Full_View
(Etype
(Typ
)))
8191 and then Full_View
(Etype
(Typ
)) = Typ
)
8193 -- Protect frontend against wrong sources with cyclic derivations
8195 or else Etype
(Typ
) = T
;
8197 -- Climb to the ancestor type handling private types
8199 if Present
(Full_View
(Etype
(Typ
))) then
8200 Typ
:= Full_View
(Etype
(Typ
));
8209 ---------------------------------
8210 -- Has_No_Obvious_Side_Effects --
8211 ---------------------------------
8213 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
8215 -- For now, just handle literals, constants, and non-volatile
8216 -- variables and expressions combining these with operators or
8217 -- short circuit forms.
8219 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
8222 elsif Nkind
(N
) = N_Character_Literal
then
8225 elsif Nkind
(N
) in N_Unary_Op
then
8226 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8228 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
8229 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
8231 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8233 elsif Nkind
(N
) = N_Expression_With_Actions
8234 and then Is_Empty_List
(Actions
(N
))
8236 return Has_No_Obvious_Side_Effects
(Expression
(N
));
8238 elsif Nkind
(N
) in N_Has_Entity
then
8239 return Present
(Entity
(N
))
8240 and then Ekind_In
(Entity
(N
), E_Variable
,
8242 E_Enumeration_Literal
,
8246 and then not Is_Volatile
(Entity
(N
));
8251 end Has_No_Obvious_Side_Effects
;
8253 ------------------------
8254 -- Has_Null_Exclusion --
8255 ------------------------
8257 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
8260 when N_Access_Definition |
8261 N_Access_Function_Definition |
8262 N_Access_Procedure_Definition |
8263 N_Access_To_Object_Definition |
8265 N_Derived_Type_Definition |
8266 N_Function_Specification |
8267 N_Subtype_Declaration
=>
8268 return Null_Exclusion_Present
(N
);
8270 when N_Component_Definition |
8271 N_Formal_Object_Declaration |
8272 N_Object_Renaming_Declaration
=>
8273 if Present
(Subtype_Mark
(N
)) then
8274 return Null_Exclusion_Present
(N
);
8275 else pragma Assert
(Present
(Access_Definition
(N
)));
8276 return Null_Exclusion_Present
(Access_Definition
(N
));
8279 when N_Discriminant_Specification
=>
8280 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
8281 return Null_Exclusion_Present
(Discriminant_Type
(N
));
8283 return Null_Exclusion_Present
(N
);
8286 when N_Object_Declaration
=>
8287 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
8288 return Null_Exclusion_Present
(Object_Definition
(N
));
8290 return Null_Exclusion_Present
(N
);
8293 when N_Parameter_Specification
=>
8294 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
8295 return Null_Exclusion_Present
(Parameter_Type
(N
));
8297 return Null_Exclusion_Present
(N
);
8304 end Has_Null_Exclusion
;
8306 ------------------------
8307 -- Has_Null_Extension --
8308 ------------------------
8310 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
8311 B
: constant Entity_Id
:= Base_Type
(T
);
8316 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
8317 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
8319 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
8321 if Present
(Ext
) then
8322 if Null_Present
(Ext
) then
8325 Comps
:= Component_List
(Ext
);
8327 -- The null component list is rewritten during analysis to
8328 -- include the parent component. Any other component indicates
8329 -- that the extension was not originally null.
8331 return Null_Present
(Comps
)
8332 or else No
(Next
(First
(Component_Items
(Comps
))));
8341 end Has_Null_Extension
;
8343 -------------------------------
8344 -- Has_Overriding_Initialize --
8345 -------------------------------
8347 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
8348 BT
: constant Entity_Id
:= Base_Type
(T
);
8352 if Is_Controlled
(BT
) then
8353 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
8356 elsif Present
(Primitive_Operations
(BT
)) then
8357 P
:= First_Elmt
(Primitive_Operations
(BT
));
8358 while Present
(P
) loop
8360 Init
: constant Entity_Id
:= Node
(P
);
8361 Formal
: constant Entity_Id
:= First_Formal
(Init
);
8363 if Ekind
(Init
) = E_Procedure
8364 and then Chars
(Init
) = Name_Initialize
8365 and then Comes_From_Source
(Init
)
8366 and then Present
(Formal
)
8367 and then Etype
(Formal
) = BT
8368 and then No
(Next_Formal
(Formal
))
8369 and then (Ada_Version
< Ada_2012
8370 or else not Null_Present
(Parent
(Init
)))
8380 -- Here if type itself does not have a non-null Initialize operation:
8381 -- check immediate ancestor.
8383 if Is_Derived_Type
(BT
)
8384 and then Has_Overriding_Initialize
(Etype
(BT
))
8391 end Has_Overriding_Initialize
;
8393 --------------------------------------
8394 -- Has_Preelaborable_Initialization --
8395 --------------------------------------
8397 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
8400 procedure Check_Components
(E
: Entity_Id
);
8401 -- Check component/discriminant chain, sets Has_PE False if a component
8402 -- or discriminant does not meet the preelaborable initialization rules.
8404 ----------------------
8405 -- Check_Components --
8406 ----------------------
8408 procedure Check_Components
(E
: Entity_Id
) is
8412 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
8413 -- Returns True if and only if the expression denoted by N does not
8414 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8416 ---------------------------------
8417 -- Is_Preelaborable_Expression --
8418 ---------------------------------
8420 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
8424 Comp_Type
: Entity_Id
;
8425 Is_Array_Aggr
: Boolean;
8428 if Is_OK_Static_Expression
(N
) then
8431 elsif Nkind
(N
) = N_Null
then
8434 -- Attributes are allowed in general, even if their prefix is a
8435 -- formal type. (It seems that certain attributes known not to be
8436 -- static might not be allowed, but there are no rules to prevent
8439 elsif Nkind
(N
) = N_Attribute_Reference
then
8442 -- The name of a discriminant evaluated within its parent type is
8443 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8444 -- names that denote discriminals as well as discriminants to
8445 -- catch references occurring within init procs.
8447 elsif Is_Entity_Name
(N
)
8449 (Ekind
(Entity
(N
)) = E_Discriminant
8450 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
8451 and then Present
(Discriminal_Link
(Entity
(N
)))))
8455 elsif Nkind
(N
) = N_Qualified_Expression
then
8456 return Is_Preelaborable_Expression
(Expression
(N
));
8458 -- For aggregates we have to check that each of the associations
8459 -- is preelaborable.
8461 elsif Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
8462 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
8464 if Is_Array_Aggr
then
8465 Comp_Type
:= Component_Type
(Etype
(N
));
8468 -- Check the ancestor part of extension aggregates, which must
8469 -- be either the name of a type that has preelaborable init or
8470 -- an expression that is preelaborable.
8472 if Nkind
(N
) = N_Extension_Aggregate
then
8474 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
8477 if Is_Entity_Name
(Anc_Part
)
8478 and then Is_Type
(Entity
(Anc_Part
))
8480 if not Has_Preelaborable_Initialization
8486 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
8492 -- Check positional associations
8494 Exp
:= First
(Expressions
(N
));
8495 while Present
(Exp
) loop
8496 if not Is_Preelaborable_Expression
(Exp
) then
8503 -- Check named associations
8505 Assn
:= First
(Component_Associations
(N
));
8506 while Present
(Assn
) loop
8507 Choice
:= First
(Choices
(Assn
));
8508 while Present
(Choice
) loop
8509 if Is_Array_Aggr
then
8510 if Nkind
(Choice
) = N_Others_Choice
then
8513 elsif Nkind
(Choice
) = N_Range
then
8514 if not Is_OK_Static_Range
(Choice
) then
8518 elsif not Is_OK_Static_Expression
(Choice
) then
8523 Comp_Type
:= Etype
(Choice
);
8529 -- If the association has a <> at this point, then we have
8530 -- to check whether the component's type has preelaborable
8531 -- initialization. Note that this only occurs when the
8532 -- association's corresponding component does not have a
8533 -- default expression, the latter case having already been
8534 -- expanded as an expression for the association.
8536 if Box_Present
(Assn
) then
8537 if not Has_Preelaborable_Initialization
(Comp_Type
) then
8541 -- In the expression case we check whether the expression
8542 -- is preelaborable.
8545 not Is_Preelaborable_Expression
(Expression
(Assn
))
8553 -- If we get here then aggregate as a whole is preelaborable
8557 -- All other cases are not preelaborable
8562 end Is_Preelaborable_Expression
;
8564 -- Start of processing for Check_Components
8567 -- Loop through entities of record or protected type
8570 while Present
(Ent
) loop
8572 -- We are interested only in components and discriminants
8579 -- Get default expression if any. If there is no declaration
8580 -- node, it means we have an internal entity. The parent and
8581 -- tag fields are examples of such entities. For such cases,
8582 -- we just test the type of the entity.
8584 if Present
(Declaration_Node
(Ent
)) then
8585 Exp
:= Expression
(Declaration_Node
(Ent
));
8588 when E_Discriminant
=>
8590 -- Note: for a renamed discriminant, the Declaration_Node
8591 -- may point to the one from the ancestor, and have a
8592 -- different expression, so use the proper attribute to
8593 -- retrieve the expression from the derived constraint.
8595 Exp
:= Discriminant_Default_Value
(Ent
);
8598 goto Check_Next_Entity
;
8601 -- A component has PI if it has no default expression and the
8602 -- component type has PI.
8605 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
8610 -- Require the default expression to be preelaborable
8612 elsif not Is_Preelaborable_Expression
(Exp
) then
8617 <<Check_Next_Entity
>>
8620 end Check_Components
;
8622 -- Start of processing for Has_Preelaborable_Initialization
8625 -- Immediate return if already marked as known preelaborable init. This
8626 -- covers types for which this function has already been called once
8627 -- and returned True (in which case the result is cached), and also
8628 -- types to which a pragma Preelaborable_Initialization applies.
8630 if Known_To_Have_Preelab_Init
(E
) then
8634 -- If the type is a subtype representing a generic actual type, then
8635 -- test whether its base type has preelaborable initialization since
8636 -- the subtype representing the actual does not inherit this attribute
8637 -- from the actual or formal. (but maybe it should???)
8639 if Is_Generic_Actual_Type
(E
) then
8640 return Has_Preelaborable_Initialization
(Base_Type
(E
));
8643 -- All elementary types have preelaborable initialization
8645 if Is_Elementary_Type
(E
) then
8648 -- Array types have PI if the component type has PI
8650 elsif Is_Array_Type
(E
) then
8651 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
8653 -- A derived type has preelaborable initialization if its parent type
8654 -- has preelaborable initialization and (in the case of a derived record
8655 -- extension) if the non-inherited components all have preelaborable
8656 -- initialization. However, a user-defined controlled type with an
8657 -- overriding Initialize procedure does not have preelaborable
8660 elsif Is_Derived_Type
(E
) then
8662 -- If the derived type is a private extension then it doesn't have
8663 -- preelaborable initialization.
8665 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
8669 -- First check whether ancestor type has preelaborable initialization
8671 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
8673 -- If OK, check extension components (if any)
8675 if Has_PE
and then Is_Record_Type
(E
) then
8676 Check_Components
(First_Entity
(E
));
8679 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8680 -- with a user defined Initialize procedure does not have PI. If
8681 -- the type is untagged, the control primitives come from a component
8682 -- that has already been checked.
8685 and then Is_Controlled
(E
)
8686 and then Is_Tagged_Type
(E
)
8687 and then Has_Overriding_Initialize
(E
)
8692 -- Private types not derived from a type having preelaborable init and
8693 -- that are not marked with pragma Preelaborable_Initialization do not
8694 -- have preelaborable initialization.
8696 elsif Is_Private_Type
(E
) then
8699 -- Record type has PI if it is non private and all components have PI
8701 elsif Is_Record_Type
(E
) then
8703 Check_Components
(First_Entity
(E
));
8705 -- Protected types must not have entries, and components must meet
8706 -- same set of rules as for record components.
8708 elsif Is_Protected_Type
(E
) then
8709 if Has_Entries
(E
) then
8713 Check_Components
(First_Entity
(E
));
8714 Check_Components
(First_Private_Entity
(E
));
8717 -- Type System.Address always has preelaborable initialization
8719 elsif Is_RTE
(E
, RE_Address
) then
8722 -- In all other cases, type does not have preelaborable initialization
8728 -- If type has preelaborable initialization, cache result
8731 Set_Known_To_Have_Preelab_Init
(E
);
8735 end Has_Preelaborable_Initialization
;
8737 ---------------------------
8738 -- Has_Private_Component --
8739 ---------------------------
8741 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
8742 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
8743 Component
: Entity_Id
;
8746 if Error_Posted
(Type_Id
)
8747 or else Error_Posted
(Btype
)
8752 if Is_Class_Wide_Type
(Btype
) then
8753 Btype
:= Root_Type
(Btype
);
8756 if Is_Private_Type
(Btype
) then
8758 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
8761 if No
(Full_View
(Btype
)) then
8762 return not Is_Generic_Type
(Btype
)
8764 not Is_Generic_Type
(Root_Type
(Btype
));
8766 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
8769 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
8773 elsif Is_Array_Type
(Btype
) then
8774 return Has_Private_Component
(Component_Type
(Btype
));
8776 elsif Is_Record_Type
(Btype
) then
8777 Component
:= First_Component
(Btype
);
8778 while Present
(Component
) loop
8779 if Has_Private_Component
(Etype
(Component
)) then
8783 Next_Component
(Component
);
8788 elsif Is_Protected_Type
(Btype
)
8789 and then Present
(Corresponding_Record_Type
(Btype
))
8791 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
8796 end Has_Private_Component
;
8798 ----------------------
8799 -- Has_Signed_Zeros --
8800 ----------------------
8802 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
8804 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
8805 end Has_Signed_Zeros
;
8807 -----------------------------
8808 -- Has_Static_Array_Bounds --
8809 -----------------------------
8811 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
8812 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
8819 -- Unconstrained types do not have static bounds
8821 if not Is_Constrained
(Typ
) then
8825 -- First treat string literals specially, as the lower bound and length
8826 -- of string literals are not stored like those of arrays.
8828 -- A string literal always has static bounds
8830 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8834 -- Treat all dimensions in turn
8836 Index
:= First_Index
(Typ
);
8837 for Indx
in 1 .. Ndims
loop
8839 -- In case of an illegal index which is not a discrete type, return
8840 -- that the type is not static.
8842 if not Is_Discrete_Type
(Etype
(Index
))
8843 or else Etype
(Index
) = Any_Type
8848 Get_Index_Bounds
(Index
, Low
, High
);
8850 if Error_Posted
(Low
) or else Error_Posted
(High
) then
8854 if Is_OK_Static_Expression
(Low
)
8856 Is_OK_Static_Expression
(High
)
8866 -- If we fall through the loop, all indexes matched
8869 end Has_Static_Array_Bounds
;
8875 function Has_Stream
(T
: Entity_Id
) return Boolean is
8882 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
8885 elsif Is_Array_Type
(T
) then
8886 return Has_Stream
(Component_Type
(T
));
8888 elsif Is_Record_Type
(T
) then
8889 E
:= First_Component
(T
);
8890 while Present
(E
) loop
8891 if Has_Stream
(Etype
(E
)) then
8900 elsif Is_Private_Type
(T
) then
8901 return Has_Stream
(Underlying_Type
(T
));
8912 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
8914 Get_Name_String
(Chars
(E
));
8915 return Name_Buffer
(Name_Len
) = Suffix
;
8922 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8924 Get_Name_String
(Chars
(E
));
8925 Add_Char_To_Name_Buffer
(Suffix
);
8933 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8935 pragma Assert
(Has_Suffix
(E
, Suffix
));
8936 Get_Name_String
(Chars
(E
));
8937 Name_Len
:= Name_Len
- 1;
8941 --------------------------
8942 -- Has_Tagged_Component --
8943 --------------------------
8945 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
8949 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
8950 return Has_Tagged_Component
(Underlying_Type
(Typ
));
8952 elsif Is_Array_Type
(Typ
) then
8953 return Has_Tagged_Component
(Component_Type
(Typ
));
8955 elsif Is_Tagged_Type
(Typ
) then
8958 elsif Is_Record_Type
(Typ
) then
8959 Comp
:= First_Component
(Typ
);
8960 while Present
(Comp
) loop
8961 if Has_Tagged_Component
(Etype
(Comp
)) then
8965 Next_Component
(Comp
);
8973 end Has_Tagged_Component
;
8975 ----------------------------
8976 -- Has_Volatile_Component --
8977 ----------------------------
8979 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
8983 if Has_Volatile_Components
(Typ
) then
8986 elsif Is_Array_Type
(Typ
) then
8987 return Is_Volatile
(Component_Type
(Typ
));
8989 elsif Is_Record_Type
(Typ
) then
8990 Comp
:= First_Component
(Typ
);
8991 while Present
(Comp
) loop
8992 if Is_Volatile_Object
(Comp
) then
8996 Comp
:= Next_Component
(Comp
);
9001 end Has_Volatile_Component
;
9003 -------------------------
9004 -- Implementation_Kind --
9005 -------------------------
9007 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
9008 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
9011 pragma Assert
(Present
(Impl_Prag
));
9012 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
9013 return Chars
(Get_Pragma_Arg
(Arg
));
9014 end Implementation_Kind
;
9016 --------------------------
9017 -- Implements_Interface --
9018 --------------------------
9020 function Implements_Interface
9021 (Typ_Ent
: Entity_Id
;
9022 Iface_Ent
: Entity_Id
;
9023 Exclude_Parents
: Boolean := False) return Boolean
9025 Ifaces_List
: Elist_Id
;
9027 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
9028 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
9031 if Is_Class_Wide_Type
(Typ
) then
9032 Typ
:= Root_Type
(Typ
);
9035 if not Has_Interfaces
(Typ
) then
9039 if Is_Class_Wide_Type
(Iface
) then
9040 Iface
:= Root_Type
(Iface
);
9043 Collect_Interfaces
(Typ
, Ifaces_List
);
9045 Elmt
:= First_Elmt
(Ifaces_List
);
9046 while Present
(Elmt
) loop
9047 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
9048 and then Exclude_Parents
9052 elsif Node
(Elmt
) = Iface
then
9060 end Implements_Interface
;
9062 ------------------------------------
9063 -- In_Assertion_Expression_Pragma --
9064 ------------------------------------
9066 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
9068 Prag
: Node_Id
:= Empty
;
9071 -- Climb the parent chain looking for an enclosing pragma
9074 while Present
(Par
) loop
9075 if Nkind
(Par
) = N_Pragma
then
9079 -- Precondition-like pragmas are expanded into if statements, check
9080 -- the original node instead.
9082 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
9083 Prag
:= Original_Node
(Par
);
9086 -- The expansion of attribute 'Old generates a constant to capture
9087 -- the result of the prefix. If the parent traversal reaches
9088 -- one of these constants, then the node technically came from a
9089 -- postcondition-like pragma. Note that the Ekind is not tested here
9090 -- because N may be the expression of an object declaration which is
9091 -- currently being analyzed. Such objects carry Ekind of E_Void.
9093 elsif Nkind
(Par
) = N_Object_Declaration
9094 and then Constant_Present
(Par
)
9095 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
9099 -- Prevent the search from going too far
9101 elsif Is_Body_Or_Package_Declaration
(Par
) then
9105 Par
:= Parent
(Par
);
9110 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
9111 end In_Assertion_Expression_Pragma
;
9117 function In_Instance
return Boolean is
9118 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
9123 while Present
(S
) and then S
/= Standard_Standard
loop
9124 if Ekind_In
(S
, E_Function
, E_Package
, E_Procedure
)
9125 and then Is_Generic_Instance
(S
)
9127 -- A child instance is always compiled in the context of a parent
9128 -- instance. Nevertheless, the actuals are not analyzed in an
9129 -- instance context. We detect this case by examining the current
9130 -- compilation unit, which must be a child instance, and checking
9131 -- that it is not currently on the scope stack.
9133 if Is_Child_Unit
(Curr_Unit
)
9134 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
9135 N_Package_Instantiation
9136 and then not In_Open_Scopes
(Curr_Unit
)
9150 ----------------------
9151 -- In_Instance_Body --
9152 ----------------------
9154 function In_Instance_Body
return Boolean is
9159 while Present
(S
) and then S
/= Standard_Standard
loop
9160 if Ekind_In
(S
, E_Function
, E_Procedure
)
9161 and then Is_Generic_Instance
(S
)
9165 elsif Ekind
(S
) = E_Package
9166 and then In_Package_Body
(S
)
9167 and then Is_Generic_Instance
(S
)
9176 end In_Instance_Body
;
9178 -----------------------------
9179 -- In_Instance_Not_Visible --
9180 -----------------------------
9182 function In_Instance_Not_Visible
return Boolean is
9187 while Present
(S
) and then S
/= Standard_Standard
loop
9188 if Ekind_In
(S
, E_Function
, E_Procedure
)
9189 and then Is_Generic_Instance
(S
)
9193 elsif Ekind
(S
) = E_Package
9194 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
9195 and then Is_Generic_Instance
(S
)
9204 end In_Instance_Not_Visible
;
9206 ------------------------------
9207 -- In_Instance_Visible_Part --
9208 ------------------------------
9210 function In_Instance_Visible_Part
return Boolean is
9215 while Present
(S
) and then S
/= Standard_Standard
loop
9216 if Ekind
(S
) = E_Package
9217 and then Is_Generic_Instance
(S
)
9218 and then not In_Package_Body
(S
)
9219 and then not In_Private_Part
(S
)
9228 end In_Instance_Visible_Part
;
9230 ---------------------
9231 -- In_Package_Body --
9232 ---------------------
9234 function In_Package_Body
return Boolean is
9239 while Present
(S
) and then S
/= Standard_Standard
loop
9240 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
9248 end In_Package_Body
;
9250 --------------------------------
9251 -- In_Parameter_Specification --
9252 --------------------------------
9254 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
9259 while Present
(PN
) loop
9260 if Nkind
(PN
) = N_Parameter_Specification
then
9268 end In_Parameter_Specification
;
9270 --------------------------
9271 -- In_Pragma_Expression --
9272 --------------------------
9274 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
9281 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
9287 end In_Pragma_Expression
;
9289 -------------------------------------
9290 -- In_Reverse_Storage_Order_Object --
9291 -------------------------------------
9293 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
9295 Btyp
: Entity_Id
:= Empty
;
9298 -- Climb up indexed components
9302 case Nkind
(Pref
) is
9303 when N_Selected_Component
=>
9304 Pref
:= Prefix
(Pref
);
9307 when N_Indexed_Component
=>
9308 Pref
:= Prefix
(Pref
);
9316 if Present
(Pref
) then
9317 Btyp
:= Base_Type
(Etype
(Pref
));
9320 return Present
(Btyp
)
9321 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
9322 and then Reverse_Storage_Order
(Btyp
);
9323 end In_Reverse_Storage_Order_Object
;
9325 --------------------------------------
9326 -- In_Subprogram_Or_Concurrent_Unit --
9327 --------------------------------------
9329 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
9334 -- Use scope chain to check successively outer scopes
9340 if K
in Subprogram_Kind
9341 or else K
in Concurrent_Kind
9342 or else K
in Generic_Subprogram_Kind
9346 elsif E
= Standard_Standard
then
9352 end In_Subprogram_Or_Concurrent_Unit
;
9354 ---------------------
9355 -- In_Visible_Part --
9356 ---------------------
9358 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
9360 return Is_Package_Or_Generic_Package
(Scope_Id
)
9361 and then In_Open_Scopes
(Scope_Id
)
9362 and then not In_Package_Body
(Scope_Id
)
9363 and then not In_Private_Part
(Scope_Id
);
9364 end In_Visible_Part
;
9366 --------------------------------
9367 -- Incomplete_Or_Partial_View --
9368 --------------------------------
9370 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
9371 function Inspect_Decls
9373 Taft
: Boolean := False) return Entity_Id
;
9374 -- Check whether a declarative region contains the incomplete or partial
9381 function Inspect_Decls
9383 Taft
: Boolean := False) return Entity_Id
9389 Decl
:= First
(Decls
);
9390 while Present
(Decl
) loop
9394 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
9395 Match
:= Defining_Identifier
(Decl
);
9399 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
9400 N_Private_Type_Declaration
)
9402 Match
:= Defining_Identifier
(Decl
);
9407 and then Present
(Full_View
(Match
))
9408 and then Full_View
(Match
) = Id
9423 -- Start of processing for Incomplete_Or_Partial_View
9426 -- Deferred constant or incomplete type case
9428 Prev
:= Current_Entity_In_Scope
(Id
);
9431 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
9432 and then Present
(Full_View
(Prev
))
9433 and then Full_View
(Prev
) = Id
9438 -- Private or Taft amendment type case
9441 Pkg
: constant Entity_Id
:= Scope
(Id
);
9442 Pkg_Decl
: Node_Id
:= Pkg
;
9445 if Present
(Pkg
) and then Ekind
(Pkg
) = E_Package
then
9446 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
9447 Pkg_Decl
:= Parent
(Pkg_Decl
);
9450 -- It is knows that Typ has a private view, look for it in the
9451 -- visible declarations of the enclosing scope. A special case
9452 -- of this is when the two views have been exchanged - the full
9453 -- appears earlier than the private.
9455 if Has_Private_Declaration
(Id
) then
9456 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
9458 -- Exchanged view case, look in the private declarations
9461 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
9466 -- Otherwise if this is the package body, then Typ is a potential
9467 -- Taft amendment type. The incomplete view should be located in
9468 -- the private declarations of the enclosing scope.
9470 elsif In_Package_Body
(Pkg
) then
9471 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
9476 -- The type has no incomplete or private view
9479 end Incomplete_Or_Partial_View
;
9481 -----------------------------------------
9482 -- Inherit_Default_Init_Cond_Procedure --
9483 -----------------------------------------
9485 procedure Inherit_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
9486 Par_Typ
: constant Entity_Id
:= Etype
(Typ
);
9489 -- A derived type inherits the default initial condition procedure of
9492 if No
(Default_Init_Cond_Procedure
(Typ
)) then
9493 Set_Default_Init_Cond_Procedure
9494 (Typ
, Default_Init_Cond_Procedure
(Par_Typ
));
9496 end Inherit_Default_Init_Cond_Procedure
;
9498 ----------------------------
9499 -- Inherit_Rep_Item_Chain --
9500 ----------------------------
9502 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
9503 From_Item
: constant Node_Id
:= First_Rep_Item
(From_Typ
);
9504 Item
: Node_Id
:= Empty
;
9505 Last_Item
: Node_Id
:= Empty
;
9508 -- Reach the end of the destination type's chain (if any) and capture
9511 Item
:= First_Rep_Item
(Typ
);
9512 while Present
(Item
) loop
9514 -- Do not inherit a chain that has been inherited already
9516 if Item
= From_Item
then
9521 Item
:= Next_Rep_Item
(Item
);
9524 -- When the destination type has a rep item chain, the chain of the
9525 -- source type is appended to it.
9527 if Present
(Last_Item
) then
9528 Set_Next_Rep_Item
(Last_Item
, From_Item
);
9530 -- Otherwise the destination type directly inherits the rep item chain
9531 -- of the source type (if any).
9534 Set_First_Rep_Item
(Typ
, From_Item
);
9536 end Inherit_Rep_Item_Chain
;
9538 ---------------------------------
9539 -- Inherit_Subprogram_Contract --
9540 ---------------------------------
9542 procedure Inherit_Subprogram_Contract
9544 From_Subp
: Entity_Id
)
9546 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
);
9547 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
9550 --------------------
9551 -- Inherit_Pragma --
9552 --------------------
9554 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
) is
9555 Prag
: constant Node_Id
:= Get_Pragma
(From_Subp
, Prag_Id
);
9559 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
9560 -- chains, therefore the node must be replicated. The new pragma is
9561 -- flagged is inherited for distrinction purposes.
9563 if Present
(Prag
) then
9564 New_Prag
:= New_Copy_Tree
(Prag
);
9565 Set_Is_Inherited
(New_Prag
);
9567 Add_Contract_Item
(New_Prag
, Subp
);
9571 -- Start of processing for Inherit_Subprogram_Contract
9574 -- Inheritance is carried out only when both entities are subprograms
9577 if Is_Subprogram_Or_Generic_Subprogram
(Subp
)
9578 and then Is_Subprogram_Or_Generic_Subprogram
(From_Subp
)
9579 and then Present
(Contract
(Subp
))
9580 and then Present
(Contract
(From_Subp
))
9582 Inherit_Pragma
(Pragma_Extensions_Visible
);
9584 end Inherit_Subprogram_Contract
;
9586 ---------------------------------
9587 -- Insert_Explicit_Dereference --
9588 ---------------------------------
9590 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
9591 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
9592 Ent
: Entity_Id
:= Empty
;
9599 Save_Interps
(N
, New_Prefix
);
9602 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
9603 Prefix
=> New_Prefix
));
9605 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
9607 if Is_Overloaded
(New_Prefix
) then
9609 -- The dereference is also overloaded, and its interpretations are
9610 -- the designated types of the interpretations of the original node.
9612 Set_Etype
(N
, Any_Type
);
9614 Get_First_Interp
(New_Prefix
, I
, It
);
9615 while Present
(It
.Nam
) loop
9618 if Is_Access_Type
(T
) then
9619 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
9622 Get_Next_Interp
(I
, It
);
9628 -- Prefix is unambiguous: mark the original prefix (which might
9629 -- Come_From_Source) as a reference, since the new (relocated) one
9630 -- won't be taken into account.
9632 if Is_Entity_Name
(New_Prefix
) then
9633 Ent
:= Entity
(New_Prefix
);
9636 -- For a retrieval of a subcomponent of some composite object,
9637 -- retrieve the ultimate entity if there is one.
9639 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
9640 N_Indexed_Component
)
9642 Pref
:= Prefix
(New_Prefix
);
9643 while Present
(Pref
)
9644 and then Nkind_In
(Pref
, N_Selected_Component
,
9645 N_Indexed_Component
)
9647 Pref
:= Prefix
(Pref
);
9650 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
9651 Ent
:= Entity
(Pref
);
9655 -- Place the reference on the entity node
9657 if Present
(Ent
) then
9658 Generate_Reference
(Ent
, Pref
);
9661 end Insert_Explicit_Dereference
;
9663 ------------------------------------------
9664 -- Inspect_Deferred_Constant_Completion --
9665 ------------------------------------------
9667 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
9671 Decl
:= First
(Decls
);
9672 while Present
(Decl
) loop
9674 -- Deferred constant signature
9676 if Nkind
(Decl
) = N_Object_Declaration
9677 and then Constant_Present
(Decl
)
9678 and then No
(Expression
(Decl
))
9680 -- No need to check internally generated constants
9682 and then Comes_From_Source
(Decl
)
9684 -- The constant is not completed. A full object declaration or a
9685 -- pragma Import complete a deferred constant.
9687 and then not Has_Completion
(Defining_Identifier
(Decl
))
9690 ("constant declaration requires initialization expression",
9691 Defining_Identifier
(Decl
));
9694 Decl
:= Next
(Decl
);
9696 end Inspect_Deferred_Constant_Completion
;
9698 -----------------------------
9699 -- Is_Actual_Out_Parameter --
9700 -----------------------------
9702 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
9706 Find_Actual
(N
, Formal
, Call
);
9707 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
9708 end Is_Actual_Out_Parameter
;
9710 -------------------------
9711 -- Is_Actual_Parameter --
9712 -------------------------
9714 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
9715 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
9719 when N_Parameter_Association
=>
9720 return N
= Explicit_Actual_Parameter
(Parent
(N
));
9722 when N_Subprogram_Call
=>
9723 return Is_List_Member
(N
)
9725 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
9730 end Is_Actual_Parameter
;
9732 --------------------------------
9733 -- Is_Actual_Tagged_Parameter --
9734 --------------------------------
9736 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
9740 Find_Actual
(N
, Formal
, Call
);
9741 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
9742 end Is_Actual_Tagged_Parameter
;
9744 ---------------------
9745 -- Is_Aliased_View --
9746 ---------------------
9748 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
9752 if Is_Entity_Name
(Obj
) then
9759 or else (Present
(Renamed_Object
(E
))
9760 and then Is_Aliased_View
(Renamed_Object
(E
)))))
9762 or else ((Is_Formal
(E
)
9763 or else Ekind_In
(E
, E_Generic_In_Out_Parameter
,
9764 E_Generic_In_Parameter
))
9765 and then Is_Tagged_Type
(Etype
(E
)))
9767 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
9769 -- Current instance of type, either directly or as rewritten
9770 -- reference to the current object.
9772 or else (Is_Entity_Name
(Original_Node
(Obj
))
9773 and then Present
(Entity
(Original_Node
(Obj
)))
9774 and then Is_Type
(Entity
(Original_Node
(Obj
))))
9776 or else (Is_Type
(E
) and then E
= Current_Scope
)
9778 or else (Is_Incomplete_Or_Private_Type
(E
)
9779 and then Full_View
(E
) = Current_Scope
)
9781 -- Ada 2012 AI05-0053: the return object of an extended return
9782 -- statement is aliased if its type is immutably limited.
9784 or else (Is_Return_Object
(E
)
9785 and then Is_Limited_View
(Etype
(E
)));
9787 elsif Nkind
(Obj
) = N_Selected_Component
then
9788 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
9790 elsif Nkind
(Obj
) = N_Indexed_Component
then
9791 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
9793 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
9794 and then Has_Aliased_Components
9795 (Designated_Type
(Etype
(Prefix
(Obj
)))));
9797 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
9798 return Is_Tagged_Type
(Etype
(Obj
))
9799 and then Is_Aliased_View
(Expression
(Obj
));
9801 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
9802 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
9807 end Is_Aliased_View
;
9809 -------------------------
9810 -- Is_Ancestor_Package --
9811 -------------------------
9813 function Is_Ancestor_Package
9815 E2
: Entity_Id
) return Boolean
9821 while Present
(Par
) and then Par
/= Standard_Standard
loop
9830 end Is_Ancestor_Package
;
9832 ----------------------
9833 -- Is_Atomic_Object --
9834 ----------------------
9836 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
9838 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
9839 -- Determines if given object has atomic components
9841 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
9842 -- If prefix is an implicit dereference, examine designated type
9844 ----------------------
9845 -- Is_Atomic_Prefix --
9846 ----------------------
9848 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
9850 if Is_Access_Type
(Etype
(N
)) then
9852 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
9854 return Object_Has_Atomic_Components
(N
);
9856 end Is_Atomic_Prefix
;
9858 ----------------------------------
9859 -- Object_Has_Atomic_Components --
9860 ----------------------------------
9862 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
9864 if Has_Atomic_Components
(Etype
(N
))
9865 or else Is_Atomic
(Etype
(N
))
9869 elsif Is_Entity_Name
(N
)
9870 and then (Has_Atomic_Components
(Entity
(N
))
9871 or else Is_Atomic
(Entity
(N
)))
9875 elsif Nkind
(N
) = N_Selected_Component
9876 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9880 elsif Nkind
(N
) = N_Indexed_Component
9881 or else Nkind
(N
) = N_Selected_Component
9883 return Is_Atomic_Prefix
(Prefix
(N
));
9888 end Object_Has_Atomic_Components
;
9890 -- Start of processing for Is_Atomic_Object
9893 -- Predicate is not relevant to subprograms
9895 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
9898 elsif Is_Atomic
(Etype
(N
))
9899 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
9903 elsif Nkind
(N
) = N_Selected_Component
9904 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9908 elsif Nkind
(N
) = N_Indexed_Component
9909 or else Nkind
(N
) = N_Selected_Component
9911 return Is_Atomic_Prefix
(Prefix
(N
));
9916 end Is_Atomic_Object
;
9918 -------------------------
9919 -- Is_Attribute_Result --
9920 -------------------------
9922 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
9924 return Nkind
(N
) = N_Attribute_Reference
9925 and then Attribute_Name
(N
) = Name_Result
;
9926 end Is_Attribute_Result
;
9928 ------------------------------------
9929 -- Is_Body_Or_Package_Declaration --
9930 ------------------------------------
9932 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
9934 return Nkind_In
(N
, N_Entry_Body
,
9936 N_Package_Declaration
,
9940 end Is_Body_Or_Package_Declaration
;
9942 -----------------------
9943 -- Is_Bounded_String --
9944 -----------------------
9946 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
9947 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
9950 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9951 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9952 -- be True for all the Bounded_String types in instances of the
9953 -- Generic_Bounded_Length generics, and for types derived from those.
9955 return Present
(Under
)
9956 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
9957 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
9958 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
9959 end Is_Bounded_String
;
9961 -------------------------
9962 -- Is_Child_Or_Sibling --
9963 -------------------------
9965 function Is_Child_Or_Sibling
9966 (Pack_1
: Entity_Id
;
9967 Pack_2
: Entity_Id
) return Boolean
9969 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
9970 -- Given an arbitrary package, return the number of "climbs" necessary
9971 -- to reach scope Standard_Standard.
9973 procedure Equalize_Depths
9974 (Pack
: in out Entity_Id
;
9976 Depth_To_Reach
: Nat
);
9977 -- Given an arbitrary package, its depth and a target depth to reach,
9978 -- climb the scope chain until the said depth is reached. The pointer
9979 -- to the package and its depth a modified during the climb.
9981 ----------------------------
9982 -- Distance_From_Standard --
9983 ----------------------------
9985 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
9992 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
9994 Scop
:= Scope
(Scop
);
9998 end Distance_From_Standard
;
10000 ---------------------
10001 -- Equalize_Depths --
10002 ---------------------
10004 procedure Equalize_Depths
10005 (Pack
: in out Entity_Id
;
10006 Depth
: in out Nat
;
10007 Depth_To_Reach
: Nat
)
10010 -- The package must be at a greater or equal depth
10012 if Depth
< Depth_To_Reach
then
10013 raise Program_Error
;
10016 -- Climb the scope chain until the desired depth is reached
10018 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
10019 Pack
:= Scope
(Pack
);
10020 Depth
:= Depth
- 1;
10022 end Equalize_Depths
;
10026 P_1
: Entity_Id
:= Pack_1
;
10027 P_1_Child
: Boolean := False;
10028 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
10029 P_2
: Entity_Id
:= Pack_2
;
10030 P_2_Child
: Boolean := False;
10031 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
10033 -- Start of processing for Is_Child_Or_Sibling
10037 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
10039 -- Both packages denote the same entity, therefore they cannot be
10040 -- children or siblings.
10045 -- One of the packages is at a deeper level than the other. Note that
10046 -- both may still come from differen hierarchies.
10054 elsif P_1_Depth
> P_2_Depth
then
10057 Depth
=> P_1_Depth
,
10058 Depth_To_Reach
=> P_2_Depth
);
10067 elsif P_2_Depth
> P_1_Depth
then
10070 Depth
=> P_2_Depth
,
10071 Depth_To_Reach
=> P_1_Depth
);
10075 -- At this stage the package pointers have been elevated to the same
10076 -- depth. If the related entities are the same, then one package is a
10077 -- potential child of the other:
10081 -- X became P_1 P_2 or vica versa
10087 return Is_Child_Unit
(Pack_1
);
10089 else pragma Assert
(P_2_Child
);
10090 return Is_Child_Unit
(Pack_2
);
10093 -- The packages may come from the same package chain or from entirely
10094 -- different hierarcies. To determine this, climb the scope stack until
10095 -- a common root is found.
10097 -- (root) (root 1) (root 2)
10102 while Present
(P_1
) and then Present
(P_2
) loop
10104 -- The two packages may be siblings
10107 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
10110 P_1
:= Scope
(P_1
);
10111 P_2
:= Scope
(P_2
);
10116 end Is_Child_Or_Sibling
;
10118 -----------------------------
10119 -- Is_Concurrent_Interface --
10120 -----------------------------
10122 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
10124 return Is_Interface
(T
)
10126 (Is_Protected_Interface
(T
)
10127 or else Is_Synchronized_Interface
(T
)
10128 or else Is_Task_Interface
(T
));
10129 end Is_Concurrent_Interface
;
10131 ---------------------------
10132 -- Is_Container_Element --
10133 ---------------------------
10135 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
10136 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
10137 Pref
: constant Node_Id
:= Prefix
(Exp
);
10140 -- Call to an indexing aspect
10142 Cont_Typ
: Entity_Id
;
10143 -- The type of the container being accessed
10145 Elem_Typ
: Entity_Id
;
10146 -- Its element type
10148 Indexing
: Entity_Id
;
10149 Is_Const
: Boolean;
10150 -- Indicates that constant indexing is used, and the element is thus
10153 Ref_Typ
: Entity_Id
;
10154 -- The reference type returned by the indexing operation
10157 -- If C is a container, in a context that imposes the element type of
10158 -- that container, the indexing notation C (X) is rewritten as:
10160 -- Indexing (C, X).Discr.all
10162 -- where Indexing is one of the indexing aspects of the container.
10163 -- If the context does not require a reference, the construct can be
10168 -- First, verify that the construct has the proper form
10170 if not Expander_Active
then
10173 elsif Nkind
(Pref
) /= N_Selected_Component
then
10176 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
10180 Call
:= Prefix
(Pref
);
10181 Ref_Typ
:= Etype
(Call
);
10184 if not Has_Implicit_Dereference
(Ref_Typ
)
10185 or else No
(First
(Parameter_Associations
(Call
)))
10186 or else not Is_Entity_Name
(Name
(Call
))
10191 -- Retrieve type of container object, and its iterator aspects
10193 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
10194 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
10197 if No
(Indexing
) then
10199 -- Container should have at least one indexing operation
10203 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
10205 -- This may be a variable indexing operation
10207 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
10210 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
10219 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
10221 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
10225 -- Check that the expression is not the target of an assignment, in
10226 -- which case the rewriting is not possible.
10228 if not Is_Const
then
10234 while Present
(Par
)
10236 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
10237 and then Par
= Name
(Parent
(Par
))
10241 -- A renaming produces a reference, and the transformation
10244 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
10248 (Nkind
(Parent
(Par
)), N_Function_Call
,
10249 N_Procedure_Call_Statement
,
10250 N_Entry_Call_Statement
)
10252 -- Check that the element is not part of an actual for an
10253 -- in-out parameter.
10260 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
10261 A
:= First
(Parameter_Associations
(Parent
(Par
)));
10262 while Present
(F
) loop
10263 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
10272 -- E_In_Parameter in a call: element is not modified.
10277 Par
:= Parent
(Par
);
10282 -- The expression has the proper form and the context requires the
10283 -- element type. Retrieve the Element function of the container and
10284 -- rewrite the construct as a call to it.
10290 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
10291 while Present
(Op
) loop
10292 exit when Chars
(Node
(Op
)) = Name_Element
;
10301 Make_Function_Call
(Loc
,
10302 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
10303 Parameter_Associations
=> Parameter_Associations
(Call
)));
10304 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
10308 end Is_Container_Element
;
10310 -----------------------
10311 -- Is_Constant_Bound --
10312 -----------------------
10314 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
10316 if Compile_Time_Known_Value
(Exp
) then
10319 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
10320 return Is_Constant_Object
(Entity
(Exp
))
10321 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
10323 elsif Nkind
(Exp
) in N_Binary_Op
then
10324 return Is_Constant_Bound
(Left_Opnd
(Exp
))
10325 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
10326 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
10331 end Is_Constant_Bound
;
10333 --------------------------------------
10334 -- Is_Controlling_Limited_Procedure --
10335 --------------------------------------
10337 function Is_Controlling_Limited_Procedure
10338 (Proc_Nam
: Entity_Id
) return Boolean
10340 Param_Typ
: Entity_Id
:= Empty
;
10343 if Ekind
(Proc_Nam
) = E_Procedure
10344 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
10346 Param_Typ
:= Etype
(Parameter_Type
(First
(
10347 Parameter_Specifications
(Parent
(Proc_Nam
)))));
10349 -- In this case where an Itype was created, the procedure call has been
10352 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
10353 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
10355 Present
(Parameter_Associations
10356 (Associated_Node_For_Itype
(Proc_Nam
)))
10359 Etype
(First
(Parameter_Associations
10360 (Associated_Node_For_Itype
(Proc_Nam
))));
10363 if Present
(Param_Typ
) then
10365 Is_Interface
(Param_Typ
)
10366 and then Is_Limited_Record
(Param_Typ
);
10370 end Is_Controlling_Limited_Procedure
;
10372 -----------------------------
10373 -- Is_CPP_Constructor_Call --
10374 -----------------------------
10376 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
10378 return Nkind
(N
) = N_Function_Call
10379 and then Is_CPP_Class
(Etype
(Etype
(N
)))
10380 and then Is_Constructor
(Entity
(Name
(N
)))
10381 and then Is_Imported
(Entity
(Name
(N
)));
10382 end Is_CPP_Constructor_Call
;
10384 --------------------
10385 -- Is_Declaration --
10386 --------------------
10388 function Is_Declaration
(N
: Node_Id
) return Boolean is
10391 when N_Abstract_Subprogram_Declaration |
10392 N_Exception_Declaration |
10393 N_Exception_Renaming_Declaration |
10394 N_Full_Type_Declaration |
10395 N_Generic_Function_Renaming_Declaration |
10396 N_Generic_Package_Declaration |
10397 N_Generic_Package_Renaming_Declaration |
10398 N_Generic_Procedure_Renaming_Declaration |
10399 N_Generic_Subprogram_Declaration |
10400 N_Number_Declaration |
10401 N_Object_Declaration |
10402 N_Object_Renaming_Declaration |
10403 N_Package_Declaration |
10404 N_Package_Renaming_Declaration |
10405 N_Private_Extension_Declaration |
10406 N_Private_Type_Declaration |
10407 N_Subprogram_Declaration |
10408 N_Subprogram_Renaming_Declaration |
10409 N_Subtype_Declaration
=>
10415 end Is_Declaration
;
10421 function Is_Delegate
(T
: Entity_Id
) return Boolean is
10422 Desig_Type
: Entity_Id
;
10425 if VM_Target
/= CLI_Target
then
10429 -- Access-to-subprograms are delegates in CIL
10431 if Ekind
(T
) = E_Access_Subprogram_Type
then
10435 if not Is_Access_Type
(T
) then
10437 -- A delegate is a managed pointer. If no designated type is defined
10438 -- it means that it's not a delegate.
10443 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
10445 if not Is_Tagged_Type
(Desig_Type
) then
10449 -- Test if the type is inherited from [mscorlib]System.Delegate
10451 while Etype
(Desig_Type
) /= Desig_Type
loop
10452 if Chars
(Scope
(Desig_Type
)) /= No_Name
10453 and then Is_Imported
(Scope
(Desig_Type
))
10454 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
10459 Desig_Type
:= Etype
(Desig_Type
);
10465 ----------------------------------------------
10466 -- Is_Dependent_Component_Of_Mutable_Object --
10467 ----------------------------------------------
10469 function Is_Dependent_Component_Of_Mutable_Object
10470 (Object
: Node_Id
) return Boolean
10472 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
10473 -- Returns True if and only if Comp is declared within a variant part
10475 --------------------------------
10476 -- Is_Declared_Within_Variant --
10477 --------------------------------
10479 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
10480 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
10481 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
10483 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
10484 end Is_Declared_Within_Variant
;
10487 Prefix_Type
: Entity_Id
;
10488 P_Aliased
: Boolean := False;
10491 Deref
: Node_Id
:= Object
;
10492 -- Dereference node, in something like X.all.Y(2)
10494 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10497 -- Find the dereference node if any
10499 while Nkind_In
(Deref
, N_Indexed_Component
,
10500 N_Selected_Component
,
10503 Deref
:= Prefix
(Deref
);
10506 -- Ada 2005: If we have a component or slice of a dereference,
10507 -- something like X.all.Y (2), and the type of X is access-to-constant,
10508 -- Is_Variable will return False, because it is indeed a constant
10509 -- view. But it might be a view of a variable object, so we want the
10510 -- following condition to be True in that case.
10512 if Is_Variable
(Object
)
10513 or else (Ada_Version
>= Ada_2005
10514 and then Nkind
(Deref
) = N_Explicit_Dereference
)
10516 if Nkind
(Object
) = N_Selected_Component
then
10517 P
:= Prefix
(Object
);
10518 Prefix_Type
:= Etype
(P
);
10520 if Is_Entity_Name
(P
) then
10521 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
10522 Prefix_Type
:= Base_Type
(Prefix_Type
);
10525 if Is_Aliased
(Entity
(P
)) then
10529 -- A discriminant check on a selected component may be expanded
10530 -- into a dereference when removing side-effects. Recover the
10531 -- original node and its type, which may be unconstrained.
10533 elsif Nkind
(P
) = N_Explicit_Dereference
10534 and then not (Comes_From_Source
(P
))
10536 P
:= Original_Node
(P
);
10537 Prefix_Type
:= Etype
(P
);
10540 -- Check for prefix being an aliased component???
10546 -- A heap object is constrained by its initial value
10548 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10549 -- the dereferenced case, since the access value might denote an
10550 -- unconstrained aliased object, whereas in Ada 95 the designated
10551 -- object is guaranteed to be constrained. A worst-case assumption
10552 -- has to apply in Ada 2005 because we can't tell at compile
10553 -- time whether the object is "constrained by its initial value"
10554 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10555 -- rules (these rules are acknowledged to need fixing).
10557 if Ada_Version
< Ada_2005
then
10558 if Is_Access_Type
(Prefix_Type
)
10559 or else Nkind
(P
) = N_Explicit_Dereference
10564 else pragma Assert
(Ada_Version
>= Ada_2005
);
10565 if Is_Access_Type
(Prefix_Type
) then
10567 -- If the access type is pool-specific, and there is no
10568 -- constrained partial view of the designated type, then the
10569 -- designated object is known to be constrained.
10571 if Ekind
(Prefix_Type
) = E_Access_Type
10572 and then not Object_Type_Has_Constrained_Partial_View
10573 (Typ
=> Designated_Type
(Prefix_Type
),
10574 Scop
=> Current_Scope
)
10578 -- Otherwise (general access type, or there is a constrained
10579 -- partial view of the designated type), we need to check
10580 -- based on the designated type.
10583 Prefix_Type
:= Designated_Type
(Prefix_Type
);
10589 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
10591 -- As per AI-0017, the renaming is illegal in a generic body, even
10592 -- if the subtype is indefinite.
10594 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10596 if not Is_Constrained
(Prefix_Type
)
10597 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
10599 (Is_Generic_Type
(Prefix_Type
)
10600 and then Ekind
(Current_Scope
) = E_Generic_Package
10601 and then In_Package_Body
(Current_Scope
)))
10603 and then (Is_Declared_Within_Variant
(Comp
)
10604 or else Has_Discriminant_Dependent_Constraint
(Comp
))
10605 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
10609 -- If the prefix is of an access type at this point, then we want
10610 -- to return False, rather than calling this function recursively
10611 -- on the access object (which itself might be a discriminant-
10612 -- dependent component of some other object, but that isn't
10613 -- relevant to checking the object passed to us). This avoids
10614 -- issuing wrong errors when compiling with -gnatc, where there
10615 -- can be implicit dereferences that have not been expanded.
10617 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
10622 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10625 elsif Nkind
(Object
) = N_Indexed_Component
10626 or else Nkind
(Object
) = N_Slice
10628 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10630 -- A type conversion that Is_Variable is a view conversion:
10631 -- go back to the denoted object.
10633 elsif Nkind
(Object
) = N_Type_Conversion
then
10635 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
10640 end Is_Dependent_Component_Of_Mutable_Object
;
10642 ---------------------
10643 -- Is_Dereferenced --
10644 ---------------------
10646 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
10647 P
: constant Node_Id
:= Parent
(N
);
10649 return Nkind_In
(P
, N_Selected_Component
,
10650 N_Explicit_Dereference
,
10651 N_Indexed_Component
,
10653 and then Prefix
(P
) = N
;
10654 end Is_Dereferenced
;
10656 ----------------------
10657 -- Is_Descendent_Of --
10658 ----------------------
10660 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
10665 pragma Assert
(Nkind
(T1
) in N_Entity
);
10666 pragma Assert
(Nkind
(T2
) in N_Entity
);
10668 T
:= Base_Type
(T1
);
10670 -- Immediate return if the types match
10675 -- Comment needed here ???
10677 elsif Ekind
(T
) = E_Class_Wide_Type
then
10678 return Etype
(T
) = T2
;
10686 -- Done if we found the type we are looking for
10691 -- Done if no more derivations to check
10698 -- Following test catches error cases resulting from prev errors
10700 elsif No
(Etyp
) then
10703 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
10706 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
10710 T
:= Base_Type
(Etyp
);
10713 end Is_Descendent_Of
;
10715 -----------------------------
10716 -- Is_Effectively_Volatile --
10717 -----------------------------
10719 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
10721 if Is_Type
(Id
) then
10723 -- An arbitrary type is effectively volatile when it is subject to
10724 -- pragma Atomic or Volatile.
10726 if Is_Volatile
(Id
) then
10729 -- An array type is effectively volatile when it is subject to pragma
10730 -- Atomic_Components or Volatile_Components or its compolent type is
10731 -- effectively volatile.
10733 elsif Is_Array_Type
(Id
) then
10735 Has_Volatile_Components
(Id
)
10737 Is_Effectively_Volatile
(Component_Type
(Base_Type
(Id
)));
10743 -- Otherwise Id denotes an object
10748 or else Has_Volatile_Components
(Id
)
10749 or else Is_Effectively_Volatile
(Etype
(Id
));
10751 end Is_Effectively_Volatile
;
10753 ------------------------------------
10754 -- Is_Effectively_Volatile_Object --
10755 ------------------------------------
10757 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
10759 if Is_Entity_Name
(N
) then
10760 return Is_Effectively_Volatile
(Entity
(N
));
10762 elsif Nkind
(N
) = N_Expanded_Name
then
10763 return Is_Effectively_Volatile
(Entity
(N
));
10765 elsif Nkind
(N
) = N_Indexed_Component
then
10766 return Is_Effectively_Volatile_Object
(Prefix
(N
));
10768 elsif Nkind
(N
) = N_Selected_Component
then
10770 Is_Effectively_Volatile_Object
(Prefix
(N
))
10772 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
10777 end Is_Effectively_Volatile_Object
;
10779 ----------------------------
10780 -- Is_Expression_Function --
10781 ----------------------------
10783 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
10787 if Ekind
(Subp
) /= E_Function
then
10791 Decl
:= Unit_Declaration_Node
(Subp
);
10792 return Nkind
(Decl
) = N_Subprogram_Declaration
10794 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
10796 (Present
(Corresponding_Body
(Decl
))
10798 Nkind
(Original_Node
10799 (Unit_Declaration_Node
10800 (Corresponding_Body
(Decl
)))) =
10801 N_Expression_Function
));
10803 end Is_Expression_Function
;
10805 -----------------------
10806 -- Is_EVF_Expression --
10807 -----------------------
10809 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
10810 Orig_N
: constant Node_Id
:= Original_Node
(N
);
10816 -- Detect a reference to a formal parameter of a specific tagged type
10817 -- whose related subprogram is subject to pragma Expresions_Visible with
10820 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
10825 and then Is_Specific_Tagged_Type
(Etype
(Id
))
10826 and then Extensions_Visible_Status
(Id
) =
10827 Extensions_Visible_False
;
10829 -- A case expression is an EVF expression when it contains at least one
10830 -- EVF dependent_expression. Note that a case expression may have been
10831 -- expanded, hence the use of Original_Node.
10833 elsif Nkind
(Orig_N
) = N_Case_Expression
then
10834 Alt
:= First
(Alternatives
(Orig_N
));
10835 while Present
(Alt
) loop
10836 if Is_EVF_Expression
(Expression
(Alt
)) then
10843 -- An if expression is an EVF expression when it contains at least one
10844 -- EVF dependent_expression. Note that an if expression may have been
10845 -- expanded, hence the use of Original_Node.
10847 elsif Nkind
(Orig_N
) = N_If_Expression
then
10848 Expr
:= Next
(First
(Expressions
(Orig_N
)));
10849 while Present
(Expr
) loop
10850 if Is_EVF_Expression
(Expr
) then
10857 -- A qualified expression or a type conversion is an EVF expression when
10858 -- its operand is an EVF expression.
10860 elsif Nkind_In
(N
, N_Qualified_Expression
,
10861 N_Unchecked_Type_Conversion
,
10864 return Is_EVF_Expression
(Expression
(N
));
10866 -- Attributes 'Loop_Entry, 'Old and 'Update are an EVF expression when
10867 -- their prefix denotes an EVF expression.
10869 elsif Nkind
(N
) = N_Attribute_Reference
10870 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
10874 return Is_EVF_Expression
(Prefix
(N
));
10878 end Is_EVF_Expression
;
10884 function Is_False
(U
: Uint
) return Boolean is
10889 ---------------------------
10890 -- Is_Fixed_Model_Number --
10891 ---------------------------
10893 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
10894 S
: constant Ureal
:= Small_Value
(T
);
10895 M
: Urealp
.Save_Mark
;
10899 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
10900 Urealp
.Release
(M
);
10902 end Is_Fixed_Model_Number
;
10904 -------------------------------
10905 -- Is_Fully_Initialized_Type --
10906 -------------------------------
10908 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
10912 if Is_Scalar_Type
(Typ
) then
10914 -- A scalar type with an aspect Default_Value is fully initialized
10916 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
10917 -- of a scalar type, but we don't take that into account here, since
10918 -- we don't want these to affect warnings.
10920 return Has_Default_Aspect
(Typ
);
10922 elsif Is_Access_Type
(Typ
) then
10925 elsif Is_Array_Type
(Typ
) then
10926 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
10927 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
10932 -- An interesting case, if we have a constrained type one of whose
10933 -- bounds is known to be null, then there are no elements to be
10934 -- initialized, so all the elements are initialized.
10936 if Is_Constrained
(Typ
) then
10939 Indx_Typ
: Entity_Id
;
10940 Lbd
, Hbd
: Node_Id
;
10943 Indx
:= First_Index
(Typ
);
10944 while Present
(Indx
) loop
10945 if Etype
(Indx
) = Any_Type
then
10948 -- If index is a range, use directly
10950 elsif Nkind
(Indx
) = N_Range
then
10951 Lbd
:= Low_Bound
(Indx
);
10952 Hbd
:= High_Bound
(Indx
);
10955 Indx_Typ
:= Etype
(Indx
);
10957 if Is_Private_Type
(Indx_Typ
) then
10958 Indx_Typ
:= Full_View
(Indx_Typ
);
10961 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
10964 Lbd
:= Type_Low_Bound
(Indx_Typ
);
10965 Hbd
:= Type_High_Bound
(Indx_Typ
);
10969 if Compile_Time_Known_Value
(Lbd
)
10971 Compile_Time_Known_Value
(Hbd
)
10973 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
10983 -- If no null indexes, then type is not fully initialized
10989 elsif Is_Record_Type
(Typ
) then
10990 if Has_Discriminants
(Typ
)
10992 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
10993 and then Is_Fully_Initialized_Variant
(Typ
)
10998 -- We consider bounded string types to be fully initialized, because
10999 -- otherwise we get false alarms when the Data component is not
11000 -- default-initialized.
11002 if Is_Bounded_String
(Typ
) then
11006 -- Controlled records are considered to be fully initialized if
11007 -- there is a user defined Initialize routine. This may not be
11008 -- entirely correct, but as the spec notes, we are guessing here
11009 -- what is best from the point of view of issuing warnings.
11011 if Is_Controlled
(Typ
) then
11013 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
11016 if Present
(Utyp
) then
11018 Init
: constant Entity_Id
:=
11020 (Underlying_Type
(Typ
), Name_Initialize
));
11024 and then Comes_From_Source
(Init
)
11026 Is_Predefined_File_Name
11027 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
11031 elsif Has_Null_Extension
(Typ
)
11033 Is_Fully_Initialized_Type
11034 (Etype
(Base_Type
(Typ
)))
11043 -- Otherwise see if all record components are initialized
11049 Ent
:= First_Entity
(Typ
);
11050 while Present
(Ent
) loop
11051 if Ekind
(Ent
) = E_Component
11052 and then (No
(Parent
(Ent
))
11053 or else No
(Expression
(Parent
(Ent
))))
11054 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
11056 -- Special VM case for tag components, which need to be
11057 -- defined in this case, but are never initialized as VMs
11058 -- are using other dispatching mechanisms. Ignore this
11059 -- uninitialized case. Note that this applies both to the
11060 -- uTag entry and the main vtable pointer (CPP_Class case).
11062 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
11071 -- No uninitialized components, so type is fully initialized.
11072 -- Note that this catches the case of no components as well.
11076 elsif Is_Concurrent_Type
(Typ
) then
11079 elsif Is_Private_Type
(Typ
) then
11081 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11087 return Is_Fully_Initialized_Type
(U
);
11094 end Is_Fully_Initialized_Type
;
11096 ----------------------------------
11097 -- Is_Fully_Initialized_Variant --
11098 ----------------------------------
11100 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
11101 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
11102 Constraints
: constant List_Id
:= New_List
;
11103 Components
: constant Elist_Id
:= New_Elmt_List
;
11104 Comp_Elmt
: Elmt_Id
;
11106 Comp_List
: Node_Id
;
11108 Discr_Val
: Node_Id
;
11110 Report_Errors
: Boolean;
11111 pragma Warnings
(Off
, Report_Errors
);
11114 if Serious_Errors_Detected
> 0 then
11118 if Is_Record_Type
(Typ
)
11119 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
11120 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
11122 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
11124 Discr
:= First_Discriminant
(Typ
);
11125 while Present
(Discr
) loop
11126 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
11127 Discr_Val
:= Expression
(Parent
(Discr
));
11129 if Present
(Discr_Val
)
11130 and then Is_OK_Static_Expression
(Discr_Val
)
11132 Append_To
(Constraints
,
11133 Make_Component_Association
(Loc
,
11134 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
11135 Expression
=> New_Copy
(Discr_Val
)));
11143 Next_Discriminant
(Discr
);
11148 Comp_List
=> Comp_List
,
11149 Governed_By
=> Constraints
,
11150 Into
=> Components
,
11151 Report_Errors
=> Report_Errors
);
11153 -- Check that each component present is fully initialized
11155 Comp_Elmt
:= First_Elmt
(Components
);
11156 while Present
(Comp_Elmt
) loop
11157 Comp_Id
:= Node
(Comp_Elmt
);
11159 if Ekind
(Comp_Id
) = E_Component
11160 and then (No
(Parent
(Comp_Id
))
11161 or else No
(Expression
(Parent
(Comp_Id
))))
11162 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
11167 Next_Elmt
(Comp_Elmt
);
11172 elsif Is_Private_Type
(Typ
) then
11174 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11180 return Is_Fully_Initialized_Variant
(U
);
11187 end Is_Fully_Initialized_Variant
;
11189 ----------------------------
11190 -- Is_Inherited_Operation --
11191 ----------------------------
11193 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
11194 pragma Assert
(Is_Overloadable
(E
));
11195 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
11197 return Kind
= N_Full_Type_Declaration
11198 or else Kind
= N_Private_Extension_Declaration
11199 or else Kind
= N_Subtype_Declaration
11200 or else (Ekind
(E
) = E_Enumeration_Literal
11201 and then Is_Derived_Type
(Etype
(E
)));
11202 end Is_Inherited_Operation
;
11204 -------------------------------------
11205 -- Is_Inherited_Operation_For_Type --
11206 -------------------------------------
11208 function Is_Inherited_Operation_For_Type
11210 Typ
: Entity_Id
) return Boolean
11213 -- Check that the operation has been created by the type declaration
11215 return Is_Inherited_Operation
(E
)
11216 and then Defining_Identifier
(Parent
(E
)) = Typ
;
11217 end Is_Inherited_Operation_For_Type
;
11223 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
11224 Ifaces_List
: Elist_Id
;
11225 Iface_Elmt
: Elmt_Id
;
11229 if Is_Class_Wide_Type
(Typ
)
11230 and then Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
11231 Name_Reversible_Iterator
)
11233 Is_Predefined_File_Name
11234 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
11238 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
11241 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
11245 Collect_Interfaces
(Typ
, Ifaces_List
);
11247 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
11248 while Present
(Iface_Elmt
) loop
11249 Iface
:= Node
(Iface_Elmt
);
11250 if Chars
(Iface
) = Name_Forward_Iterator
11252 Is_Predefined_File_Name
11253 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
11258 Next_Elmt
(Iface_Elmt
);
11269 -- We seem to have a lot of overlapping functions that do similar things
11270 -- (testing for left hand sides or lvalues???).
11272 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
11273 P
: constant Node_Id
:= Parent
(N
);
11276 -- Return True if we are the left hand side of an assignment statement
11278 if Nkind
(P
) = N_Assignment_Statement
then
11279 if Name
(P
) = N
then
11285 -- Case of prefix of indexed or selected component or slice
11287 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
11288 and then N
= Prefix
(P
)
11290 -- Here we have the case where the parent P is N.Q or N(Q .. R).
11291 -- If P is an LHS, then N is also effectively an LHS, but there
11292 -- is an important exception. If N is of an access type, then
11293 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
11294 -- case this makes N.all a left hand side but not N itself.
11296 -- If we don't know the type yet, this is the case where we return
11297 -- Unknown, since the answer depends on the type which is unknown.
11299 if No
(Etype
(N
)) then
11302 -- We have an Etype set, so we can check it
11304 elsif Is_Access_Type
(Etype
(N
)) then
11307 -- OK, not access type case, so just test whole expression
11313 -- All other cases are not left hand sides
11320 -----------------------------
11321 -- Is_Library_Level_Entity --
11322 -----------------------------
11324 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
11326 -- The following is a small optimization, and it also properly handles
11327 -- discriminals, which in task bodies might appear in expressions before
11328 -- the corresponding procedure has been created, and which therefore do
11329 -- not have an assigned scope.
11331 if Is_Formal
(E
) then
11335 -- Normal test is simply that the enclosing dynamic scope is Standard
11337 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
11338 end Is_Library_Level_Entity
;
11340 --------------------------------
11341 -- Is_Limited_Class_Wide_Type --
11342 --------------------------------
11344 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
11347 Is_Class_Wide_Type
(Typ
)
11348 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
11349 end Is_Limited_Class_Wide_Type
;
11351 ---------------------------------
11352 -- Is_Local_Variable_Reference --
11353 ---------------------------------
11355 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
11357 if not Is_Entity_Name
(Expr
) then
11362 Ent
: constant Entity_Id
:= Entity
(Expr
);
11363 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
11365 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
11368 return Present
(Sub
) and then Sub
= Current_Subprogram
;
11372 end Is_Local_Variable_Reference
;
11374 -------------------------
11375 -- Is_Object_Reference --
11376 -------------------------
11378 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
11380 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
11381 -- Determine whether N is the name of an internally-generated renaming
11383 --------------------------------------
11384 -- Is_Internally_Generated_Renaming --
11385 --------------------------------------
11387 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
11392 while Present
(P
) loop
11393 if Nkind
(P
) = N_Object_Renaming_Declaration
then
11394 return not Comes_From_Source
(P
);
11395 elsif Is_List_Member
(P
) then
11403 end Is_Internally_Generated_Renaming
;
11405 -- Start of processing for Is_Object_Reference
11408 if Is_Entity_Name
(N
) then
11409 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
11413 when N_Indexed_Component | N_Slice
=>
11415 Is_Object_Reference
(Prefix
(N
))
11416 or else Is_Access_Type
(Etype
(Prefix
(N
)));
11418 -- In Ada 95, a function call is a constant object; a procedure
11421 when N_Function_Call
=>
11422 return Etype
(N
) /= Standard_Void_Type
;
11424 -- Attributes 'Input, 'Old and 'Result produce objects
11426 when N_Attribute_Reference
=>
11429 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
11431 when N_Selected_Component
=>
11433 Is_Object_Reference
(Selector_Name
(N
))
11435 (Is_Object_Reference
(Prefix
(N
))
11436 or else Is_Access_Type
(Etype
(Prefix
(N
))));
11438 when N_Explicit_Dereference
=>
11441 -- A view conversion of a tagged object is an object reference
11443 when N_Type_Conversion
=>
11444 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
11445 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
11446 and then Is_Object_Reference
(Expression
(N
));
11448 -- An unchecked type conversion is considered to be an object if
11449 -- the operand is an object (this construction arises only as a
11450 -- result of expansion activities).
11452 when N_Unchecked_Type_Conversion
=>
11455 -- Allow string literals to act as objects as long as they appear
11456 -- in internally-generated renamings. The expansion of iterators
11457 -- may generate such renamings when the range involves a string
11460 when N_String_Literal
=>
11461 return Is_Internally_Generated_Renaming
(Parent
(N
));
11463 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11464 -- This allows disambiguation of function calls and the use
11465 -- of aggregates in more contexts.
11467 when N_Qualified_Expression
=>
11468 if Ada_Version
< Ada_2012
then
11471 return Is_Object_Reference
(Expression
(N
))
11472 or else Nkind
(Expression
(N
)) = N_Aggregate
;
11479 end Is_Object_Reference
;
11481 -----------------------------------
11482 -- Is_OK_Variable_For_Out_Formal --
11483 -----------------------------------
11485 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
11487 Note_Possible_Modification
(AV
, Sure
=> True);
11489 -- We must reject parenthesized variable names. Comes_From_Source is
11490 -- checked because there are currently cases where the compiler violates
11491 -- this rule (e.g. passing a task object to its controlled Initialize
11492 -- routine). This should be properly documented in sinfo???
11494 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
11497 -- A variable is always allowed
11499 elsif Is_Variable
(AV
) then
11502 -- Generalized indexing operations are rewritten as explicit
11503 -- dereferences, and it is only during resolution that we can
11504 -- check whether the context requires an access_to_variable type.
11506 elsif Nkind
(AV
) = N_Explicit_Dereference
11507 and then Ada_Version
>= Ada_2012
11508 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
11509 and then Present
(Etype
(Original_Node
(AV
)))
11510 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
11512 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
11514 -- Unchecked conversions are allowed only if they come from the
11515 -- generated code, which sometimes uses unchecked conversions for out
11516 -- parameters in cases where code generation is unaffected. We tell
11517 -- source unchecked conversions by seeing if they are rewrites of
11518 -- an original Unchecked_Conversion function call, or of an explicit
11519 -- conversion of a function call or an aggregate (as may happen in the
11520 -- expansion of a packed array aggregate).
11522 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
11523 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
11526 elsif Comes_From_Source
(AV
)
11527 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
11531 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
11532 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
11538 -- Normal type conversions are allowed if argument is a variable
11540 elsif Nkind
(AV
) = N_Type_Conversion
then
11541 if Is_Variable
(Expression
(AV
))
11542 and then Paren_Count
(Expression
(AV
)) = 0
11544 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
11547 -- We also allow a non-parenthesized expression that raises
11548 -- constraint error if it rewrites what used to be a variable
11550 elsif Raises_Constraint_Error
(Expression
(AV
))
11551 and then Paren_Count
(Expression
(AV
)) = 0
11552 and then Is_Variable
(Original_Node
(Expression
(AV
)))
11556 -- Type conversion of something other than a variable
11562 -- If this node is rewritten, then test the original form, if that is
11563 -- OK, then we consider the rewritten node OK (for example, if the
11564 -- original node is a conversion, then Is_Variable will not be true
11565 -- but we still want to allow the conversion if it converts a variable).
11567 elsif Original_Node
(AV
) /= AV
then
11569 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11570 -- Reference function.
11572 if Ada_Version
>= Ada_2012
11573 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
11575 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
11580 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
11583 -- All other non-variables are rejected
11588 end Is_OK_Variable_For_Out_Formal
;
11590 -----------------------------------
11591 -- Is_Partially_Initialized_Type --
11592 -----------------------------------
11594 function Is_Partially_Initialized_Type
11596 Include_Implicit
: Boolean := True) return Boolean
11599 if Is_Scalar_Type
(Typ
) then
11602 elsif Is_Access_Type
(Typ
) then
11603 return Include_Implicit
;
11605 elsif Is_Array_Type
(Typ
) then
11607 -- If component type is partially initialized, so is array type
11609 if Is_Partially_Initialized_Type
11610 (Component_Type
(Typ
), Include_Implicit
)
11614 -- Otherwise we are only partially initialized if we are fully
11615 -- initialized (this is the empty array case, no point in us
11616 -- duplicating that code here).
11619 return Is_Fully_Initialized_Type
(Typ
);
11622 elsif Is_Record_Type
(Typ
) then
11624 -- A discriminated type is always partially initialized if in
11627 if Has_Discriminants
(Typ
) and then Include_Implicit
then
11630 -- A tagged type is always partially initialized
11632 elsif Is_Tagged_Type
(Typ
) then
11635 -- Case of non-discriminated record
11641 Component_Present
: Boolean := False;
11642 -- Set True if at least one component is present. If no
11643 -- components are present, then record type is fully
11644 -- initialized (another odd case, like the null array).
11647 -- Loop through components
11649 Ent
:= First_Entity
(Typ
);
11650 while Present
(Ent
) loop
11651 if Ekind
(Ent
) = E_Component
then
11652 Component_Present
:= True;
11654 -- If a component has an initialization expression then
11655 -- the enclosing record type is partially initialized
11657 if Present
(Parent
(Ent
))
11658 and then Present
(Expression
(Parent
(Ent
)))
11662 -- If a component is of a type which is itself partially
11663 -- initialized, then the enclosing record type is also.
11665 elsif Is_Partially_Initialized_Type
11666 (Etype
(Ent
), Include_Implicit
)
11675 -- No initialized components found. If we found any components
11676 -- they were all uninitialized so the result is false.
11678 if Component_Present
then
11681 -- But if we found no components, then all the components are
11682 -- initialized so we consider the type to be initialized.
11690 -- Concurrent types are always fully initialized
11692 elsif Is_Concurrent_Type
(Typ
) then
11695 -- For a private type, go to underlying type. If there is no underlying
11696 -- type then just assume this partially initialized. Not clear if this
11697 -- can happen in a non-error case, but no harm in testing for this.
11699 elsif Is_Private_Type
(Typ
) then
11701 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11706 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
11710 -- For any other type (are there any?) assume partially initialized
11715 end Is_Partially_Initialized_Type
;
11717 ------------------------------------
11718 -- Is_Potentially_Persistent_Type --
11719 ------------------------------------
11721 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
11726 -- For private type, test corresponding full type
11728 if Is_Private_Type
(T
) then
11729 return Is_Potentially_Persistent_Type
(Full_View
(T
));
11731 -- Scalar types are potentially persistent
11733 elsif Is_Scalar_Type
(T
) then
11736 -- Record type is potentially persistent if not tagged and the types of
11737 -- all it components are potentially persistent, and no component has
11738 -- an initialization expression.
11740 elsif Is_Record_Type
(T
)
11741 and then not Is_Tagged_Type
(T
)
11742 and then not Is_Partially_Initialized_Type
(T
)
11744 Comp
:= First_Component
(T
);
11745 while Present
(Comp
) loop
11746 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
11749 Next_Entity
(Comp
);
11755 -- Array type is potentially persistent if its component type is
11756 -- potentially persistent and if all its constraints are static.
11758 elsif Is_Array_Type
(T
) then
11759 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
11763 Indx
:= First_Index
(T
);
11764 while Present
(Indx
) loop
11765 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
11774 -- All other types are not potentially persistent
11779 end Is_Potentially_Persistent_Type
;
11781 --------------------------------
11782 -- Is_Potentially_Unevaluated --
11783 --------------------------------
11785 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
11793 -- A postcondition whose expression is a short-circuit is broken down
11794 -- into individual aspects for better exception reporting. The original
11795 -- short-circuit expression is rewritten as the second operand, and an
11796 -- occurrence of 'Old in that operand is potentially unevaluated.
11797 -- See Sem_ch13.adb for details of this transformation.
11799 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
11803 while not Nkind_In
(Par
, N_If_Expression
,
11811 Par
:= Parent
(Par
);
11813 -- If the context is not an expression, or if is the result of
11814 -- expansion of an enclosing construct (such as another attribute)
11815 -- the predicate does not apply.
11817 if Nkind
(Par
) not in N_Subexpr
11818 or else not Comes_From_Source
(Par
)
11824 if Nkind
(Par
) = N_If_Expression
then
11825 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
11827 elsif Nkind
(Par
) = N_Case_Expression
then
11828 return Expr
/= Expression
(Par
);
11830 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
11831 return Expr
= Right_Opnd
(Par
);
11833 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
11834 return Expr
/= Left_Opnd
(Par
);
11839 end Is_Potentially_Unevaluated
;
11841 ---------------------------------
11842 -- Is_Protected_Self_Reference --
11843 ---------------------------------
11845 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
11847 function In_Access_Definition
(N
: Node_Id
) return Boolean;
11848 -- Returns true if N belongs to an access definition
11850 --------------------------
11851 -- In_Access_Definition --
11852 --------------------------
11854 function In_Access_Definition
(N
: Node_Id
) return Boolean is
11859 while Present
(P
) loop
11860 if Nkind
(P
) = N_Access_Definition
then
11868 end In_Access_Definition
;
11870 -- Start of processing for Is_Protected_Self_Reference
11873 -- Verify that prefix is analyzed and has the proper form. Note that
11874 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11875 -- which also produce the address of an entity, do not analyze their
11876 -- prefix because they denote entities that are not necessarily visible.
11877 -- Neither of them can apply to a protected type.
11879 return Ada_Version
>= Ada_2005
11880 and then Is_Entity_Name
(N
)
11881 and then Present
(Entity
(N
))
11882 and then Is_Protected_Type
(Entity
(N
))
11883 and then In_Open_Scopes
(Entity
(N
))
11884 and then not In_Access_Definition
(N
);
11885 end Is_Protected_Self_Reference
;
11887 -----------------------------
11888 -- Is_RCI_Pkg_Spec_Or_Body --
11889 -----------------------------
11891 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
11893 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
11894 -- Return True if the unit of Cunit is an RCI package declaration
11896 ---------------------------
11897 -- Is_RCI_Pkg_Decl_Cunit --
11898 ---------------------------
11900 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
11901 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
11904 if Nkind
(The_Unit
) /= N_Package_Declaration
then
11908 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
11909 end Is_RCI_Pkg_Decl_Cunit
;
11911 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11914 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
11916 (Nkind
(Unit
(Cunit
)) = N_Package_Body
11917 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
11918 end Is_RCI_Pkg_Spec_Or_Body
;
11920 -----------------------------------------
11921 -- Is_Remote_Access_To_Class_Wide_Type --
11922 -----------------------------------------
11924 function Is_Remote_Access_To_Class_Wide_Type
11925 (E
: Entity_Id
) return Boolean
11928 -- A remote access to class-wide type is a general access to object type
11929 -- declared in the visible part of a Remote_Types or Remote_Call_
11932 return Ekind
(E
) = E_General_Access_Type
11933 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11934 end Is_Remote_Access_To_Class_Wide_Type
;
11936 -----------------------------------------
11937 -- Is_Remote_Access_To_Subprogram_Type --
11938 -----------------------------------------
11940 function Is_Remote_Access_To_Subprogram_Type
11941 (E
: Entity_Id
) return Boolean
11944 return (Ekind
(E
) = E_Access_Subprogram_Type
11945 or else (Ekind
(E
) = E_Record_Type
11946 and then Present
(Corresponding_Remote_Type
(E
))))
11947 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11948 end Is_Remote_Access_To_Subprogram_Type
;
11950 --------------------
11951 -- Is_Remote_Call --
11952 --------------------
11954 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
11956 if Nkind
(N
) not in N_Subprogram_Call
then
11958 -- An entry call cannot be remote
11962 elsif Nkind
(Name
(N
)) in N_Has_Entity
11963 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
11965 -- A subprogram declared in the spec of a RCI package is remote
11969 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
11970 and then Is_Remote_Access_To_Subprogram_Type
11971 (Etype
(Prefix
(Name
(N
))))
11973 -- The dereference of a RAS is a remote call
11977 elsif Present
(Controlling_Argument
(N
))
11978 and then Is_Remote_Access_To_Class_Wide_Type
11979 (Etype
(Controlling_Argument
(N
)))
11981 -- Any primitive operation call with a controlling argument of
11982 -- a RACW type is a remote call.
11987 -- All other calls are local calls
11990 end Is_Remote_Call
;
11992 ----------------------
11993 -- Is_Renamed_Entry --
11994 ----------------------
11996 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
11997 Orig_Node
: Node_Id
:= Empty
;
11998 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
12000 function Is_Entry
(Nam
: Node_Id
) return Boolean;
12001 -- Determine whether Nam is an entry. Traverse selectors if there are
12002 -- nested selected components.
12008 function Is_Entry
(Nam
: Node_Id
) return Boolean is
12010 if Nkind
(Nam
) = N_Selected_Component
then
12011 return Is_Entry
(Selector_Name
(Nam
));
12014 return Ekind
(Entity
(Nam
)) = E_Entry
;
12017 -- Start of processing for Is_Renamed_Entry
12020 if Present
(Alias
(Proc_Nam
)) then
12021 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
12024 -- Look for a rewritten subprogram renaming declaration
12026 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
12027 and then Present
(Original_Node
(Subp_Decl
))
12029 Orig_Node
:= Original_Node
(Subp_Decl
);
12032 -- The rewritten subprogram is actually an entry
12034 if Present
(Orig_Node
)
12035 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
12036 and then Is_Entry
(Name
(Orig_Node
))
12042 end Is_Renamed_Entry
;
12044 ----------------------------
12045 -- Is_Reversible_Iterator --
12046 ----------------------------
12048 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
12049 Ifaces_List
: Elist_Id
;
12050 Iface_Elmt
: Elmt_Id
;
12054 if Is_Class_Wide_Type
(Typ
)
12055 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
12056 and then Is_Predefined_File_Name
12057 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
12061 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
12065 Collect_Interfaces
(Typ
, Ifaces_List
);
12067 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
12068 while Present
(Iface_Elmt
) loop
12069 Iface
:= Node
(Iface_Elmt
);
12070 if Chars
(Iface
) = Name_Reversible_Iterator
12072 Is_Predefined_File_Name
12073 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
12078 Next_Elmt
(Iface_Elmt
);
12083 end Is_Reversible_Iterator
;
12085 ----------------------
12086 -- Is_Selector_Name --
12087 ----------------------
12089 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
12091 if not Is_List_Member
(N
) then
12093 P
: constant Node_Id
:= Parent
(N
);
12095 return Nkind_In
(P
, N_Expanded_Name
,
12096 N_Generic_Association
,
12097 N_Parameter_Association
,
12098 N_Selected_Component
)
12099 and then Selector_Name
(P
) = N
;
12104 L
: constant List_Id
:= List_Containing
(N
);
12105 P
: constant Node_Id
:= Parent
(L
);
12107 return (Nkind
(P
) = N_Discriminant_Association
12108 and then Selector_Names
(P
) = L
)
12110 (Nkind
(P
) = N_Component_Association
12111 and then Choices
(P
) = L
);
12114 end Is_Selector_Name
;
12116 -------------------------------------
12117 -- Is_SPARK_05_Initialization_Expr --
12118 -------------------------------------
12120 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
12123 Comp_Assn
: Node_Id
;
12124 Orig_N
: constant Node_Id
:= Original_Node
(N
);
12129 if not Comes_From_Source
(Orig_N
) then
12133 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
12135 case Nkind
(Orig_N
) is
12136 when N_Character_Literal |
12137 N_Integer_Literal |
12139 N_String_Literal
=>
12142 when N_Identifier |
12144 if Is_Entity_Name
(Orig_N
)
12145 and then Present
(Entity
(Orig_N
)) -- needed in some cases
12147 case Ekind
(Entity
(Orig_N
)) is
12149 E_Enumeration_Literal |
12154 if Is_Type
(Entity
(Orig_N
)) then
12162 when N_Qualified_Expression |
12163 N_Type_Conversion
=>
12164 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
12167 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12171 N_Membership_Test
=>
12172 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
12174 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12177 N_Extension_Aggregate
=>
12178 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
12180 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
12183 Expr
:= First
(Expressions
(Orig_N
));
12184 while Present
(Expr
) loop
12185 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
12193 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
12194 while Present
(Comp_Assn
) loop
12195 Expr
:= Expression
(Comp_Assn
);
12197 -- Note: test for Present here needed for box assocation
12200 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
12209 when N_Attribute_Reference
=>
12210 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
12211 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
12214 Expr
:= First
(Expressions
(Orig_N
));
12215 while Present
(Expr
) loop
12216 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
12224 -- Selected components might be expanded named not yet resolved, so
12225 -- default on the safe side. (Eg on sparklex.ads)
12227 when N_Selected_Component
=>
12236 end Is_SPARK_05_Initialization_Expr
;
12238 ----------------------------------
12239 -- Is_SPARK_05_Object_Reference --
12240 ----------------------------------
12242 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
12244 if Is_Entity_Name
(N
) then
12245 return Present
(Entity
(N
))
12247 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
12248 or else Ekind
(Entity
(N
)) in Formal_Kind
);
12252 when N_Selected_Component
=>
12253 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
12259 end Is_SPARK_05_Object_Reference
;
12261 -----------------------------
12262 -- Is_Specific_Tagged_Type --
12263 -----------------------------
12265 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
12266 Full_Typ
: Entity_Id
;
12269 -- Handle private types
12271 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
12272 Full_Typ
:= Full_View
(Typ
);
12277 -- A specific tagged type is a non-class-wide tagged type
12279 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
12280 end Is_Specific_Tagged_Type
;
12286 function Is_Statement
(N
: Node_Id
) return Boolean is
12289 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
12290 or else Nkind
(N
) = N_Procedure_Call_Statement
;
12293 --------------------------------------------------
12294 -- Is_Subprogram_Stub_Without_Prior_Declaration --
12295 --------------------------------------------------
12297 function Is_Subprogram_Stub_Without_Prior_Declaration
12298 (N
: Node_Id
) return Boolean
12301 -- A subprogram stub without prior declaration serves as declaration for
12302 -- the actual subprogram body. As such, it has an attached defining
12303 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
12305 return Nkind
(N
) = N_Subprogram_Body_Stub
12306 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
12307 end Is_Subprogram_Stub_Without_Prior_Declaration
;
12309 ---------------------------------
12310 -- Is_Synchronized_Tagged_Type --
12311 ---------------------------------
12313 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
12314 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
12317 -- A task or protected type derived from an interface is a tagged type.
12318 -- Such a tagged type is called a synchronized tagged type, as are
12319 -- synchronized interfaces and private extensions whose declaration
12320 -- includes the reserved word synchronized.
12322 return (Is_Tagged_Type
(E
)
12323 and then (Kind
= E_Task_Type
12325 Kind
= E_Protected_Type
))
12328 and then Is_Synchronized_Interface
(E
))
12330 (Ekind
(E
) = E_Record_Type_With_Private
12331 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
12332 and then (Synchronized_Present
(Parent
(E
))
12333 or else Is_Synchronized_Interface
(Etype
(E
))));
12334 end Is_Synchronized_Tagged_Type
;
12340 function Is_Transfer
(N
: Node_Id
) return Boolean is
12341 Kind
: constant Node_Kind
:= Nkind
(N
);
12344 if Kind
= N_Simple_Return_Statement
12346 Kind
= N_Extended_Return_Statement
12348 Kind
= N_Goto_Statement
12350 Kind
= N_Raise_Statement
12352 Kind
= N_Requeue_Statement
12356 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
12357 and then No
(Condition
(N
))
12361 elsif Kind
= N_Procedure_Call_Statement
12362 and then Is_Entity_Name
(Name
(N
))
12363 and then Present
(Entity
(Name
(N
)))
12364 and then No_Return
(Entity
(Name
(N
)))
12368 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
12380 function Is_True
(U
: Uint
) return Boolean is
12385 --------------------------------------
12386 -- Is_Unchecked_Conversion_Instance --
12387 --------------------------------------
12389 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
12390 Gen_Par
: Entity_Id
;
12393 -- Look for a function whose generic parent is the predefined intrinsic
12394 -- function Unchecked_Conversion.
12396 if Ekind
(Id
) = E_Function
then
12397 Gen_Par
:= Generic_Parent
(Parent
(Id
));
12401 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
12402 and then Is_Intrinsic_Subprogram
(Gen_Par
)
12403 and then Is_Predefined_File_Name
12404 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
12408 end Is_Unchecked_Conversion_Instance
;
12410 -------------------------------
12411 -- Is_Universal_Numeric_Type --
12412 -------------------------------
12414 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
12416 return T
= Universal_Integer
or else T
= Universal_Real
;
12417 end Is_Universal_Numeric_Type
;
12419 -------------------
12420 -- Is_Value_Type --
12421 -------------------
12423 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
12425 return VM_Target
= CLI_Target
12426 and then Nkind
(T
) in N_Has_Chars
12427 and then Chars
(T
) /= No_Name
12428 and then Get_Name_String
(Chars
(T
)) = "valuetype";
12431 ----------------------------
12432 -- Is_Variable_Size_Array --
12433 ----------------------------
12435 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
12439 pragma Assert
(Is_Array_Type
(E
));
12441 -- Check if some index is initialized with a non-constant value
12443 Idx
:= First_Index
(E
);
12444 while Present
(Idx
) loop
12445 if Nkind
(Idx
) = N_Range
then
12446 if not Is_Constant_Bound
(Low_Bound
(Idx
))
12447 or else not Is_Constant_Bound
(High_Bound
(Idx
))
12453 Idx
:= Next_Index
(Idx
);
12457 end Is_Variable_Size_Array
;
12459 -----------------------------
12460 -- Is_Variable_Size_Record --
12461 -----------------------------
12463 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
12465 Comp_Typ
: Entity_Id
;
12468 pragma Assert
(Is_Record_Type
(E
));
12470 Comp
:= First_Entity
(E
);
12471 while Present
(Comp
) loop
12472 Comp_Typ
:= Etype
(Comp
);
12474 -- Recursive call if the record type has discriminants
12476 if Is_Record_Type
(Comp_Typ
)
12477 and then Has_Discriminants
(Comp_Typ
)
12478 and then Is_Variable_Size_Record
(Comp_Typ
)
12482 elsif Is_Array_Type
(Comp_Typ
)
12483 and then Is_Variable_Size_Array
(Comp_Typ
)
12488 Next_Entity
(Comp
);
12492 end Is_Variable_Size_Record
;
12498 function Is_Variable
12500 Use_Original_Node
: Boolean := True) return Boolean
12502 Orig_Node
: Node_Id
;
12504 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
12505 -- Within a protected function, the private components of the enclosing
12506 -- protected type are constants. A function nested within a (protected)
12507 -- procedure is not itself protected. Within the body of a protected
12508 -- function the current instance of the protected type is a constant.
12510 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
12511 -- Prefixes can involve implicit dereferences, in which case we must
12512 -- test for the case of a reference of a constant access type, which can
12513 -- can never be a variable.
12515 ---------------------------
12516 -- In_Protected_Function --
12517 ---------------------------
12519 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
12524 -- E is the current instance of a type
12526 if Is_Type
(E
) then
12535 if not Is_Protected_Type
(Prot
) then
12539 S
:= Current_Scope
;
12540 while Present
(S
) and then S
/= Prot
loop
12541 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
12550 end In_Protected_Function
;
12552 ------------------------
12553 -- Is_Variable_Prefix --
12554 ------------------------
12556 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
12558 if Is_Access_Type
(Etype
(P
)) then
12559 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
12561 -- For the case of an indexed component whose prefix has a packed
12562 -- array type, the prefix has been rewritten into a type conversion.
12563 -- Determine variable-ness from the converted expression.
12565 elsif Nkind
(P
) = N_Type_Conversion
12566 and then not Comes_From_Source
(P
)
12567 and then Is_Array_Type
(Etype
(P
))
12568 and then Is_Packed
(Etype
(P
))
12570 return Is_Variable
(Expression
(P
));
12573 return Is_Variable
(P
);
12575 end Is_Variable_Prefix
;
12577 -- Start of processing for Is_Variable
12580 -- Check if we perform the test on the original node since this may be a
12581 -- test of syntactic categories which must not be disturbed by whatever
12582 -- rewriting might have occurred. For example, an aggregate, which is
12583 -- certainly NOT a variable, could be turned into a variable by
12586 if Use_Original_Node
then
12587 Orig_Node
:= Original_Node
(N
);
12592 -- Definitely OK if Assignment_OK is set. Since this is something that
12593 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12595 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
12598 -- Normally we go to the original node, but there is one exception where
12599 -- we use the rewritten node, namely when it is an explicit dereference.
12600 -- The generated code may rewrite a prefix which is an access type with
12601 -- an explicit dereference. The dereference is a variable, even though
12602 -- the original node may not be (since it could be a constant of the
12605 -- In Ada 2005 we have a further case to consider: the prefix may be a
12606 -- function call given in prefix notation. The original node appears to
12607 -- be a selected component, but we need to examine the call.
12609 elsif Nkind
(N
) = N_Explicit_Dereference
12610 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
12611 and then Present
(Etype
(Orig_Node
))
12612 and then Is_Access_Type
(Etype
(Orig_Node
))
12614 -- Note that if the prefix is an explicit dereference that does not
12615 -- come from source, we must check for a rewritten function call in
12616 -- prefixed notation before other forms of rewriting, to prevent a
12620 (Nkind
(Orig_Node
) = N_Function_Call
12621 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
12623 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
12625 -- in Ada 2012, the dereference may have been added for a type with
12626 -- a declared implicit dereference aspect. Check that it is not an
12627 -- access to constant.
12629 elsif Nkind
(N
) = N_Explicit_Dereference
12630 and then Present
(Etype
(Orig_Node
))
12631 and then Ada_Version
>= Ada_2012
12632 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
12634 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
12636 -- A function call is never a variable
12638 elsif Nkind
(N
) = N_Function_Call
then
12641 -- All remaining checks use the original node
12643 elsif Is_Entity_Name
(Orig_Node
)
12644 and then Present
(Entity
(Orig_Node
))
12647 E
: constant Entity_Id
:= Entity
(Orig_Node
);
12648 K
: constant Entity_Kind
:= Ekind
(E
);
12651 return (K
= E_Variable
12652 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
12653 or else (K
= E_Component
12654 and then not In_Protected_Function
(E
))
12655 or else K
= E_Out_Parameter
12656 or else K
= E_In_Out_Parameter
12657 or else K
= E_Generic_In_Out_Parameter
12659 -- Current instance of type. If this is a protected type, check
12660 -- we are not within the body of one of its protected functions.
12662 or else (Is_Type
(E
)
12663 and then In_Open_Scopes
(E
)
12664 and then not In_Protected_Function
(E
))
12666 or else (Is_Incomplete_Or_Private_Type
(E
)
12667 and then In_Open_Scopes
(Full_View
(E
)));
12671 case Nkind
(Orig_Node
) is
12672 when N_Indexed_Component | N_Slice
=>
12673 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
12675 when N_Selected_Component
=>
12676 return (Is_Variable
(Selector_Name
(Orig_Node
))
12677 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
12679 (Nkind
(N
) = N_Expanded_Name
12680 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
12682 -- For an explicit dereference, the type of the prefix cannot
12683 -- be an access to constant or an access to subprogram.
12685 when N_Explicit_Dereference
=>
12687 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
12689 return Is_Access_Type
(Typ
)
12690 and then not Is_Access_Constant
(Root_Type
(Typ
))
12691 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
12694 -- The type conversion is the case where we do not deal with the
12695 -- context dependent special case of an actual parameter. Thus
12696 -- the type conversion is only considered a variable for the
12697 -- purposes of this routine if the target type is tagged. However,
12698 -- a type conversion is considered to be a variable if it does not
12699 -- come from source (this deals for example with the conversions
12700 -- of expressions to their actual subtypes).
12702 when N_Type_Conversion
=>
12703 return Is_Variable
(Expression
(Orig_Node
))
12705 (not Comes_From_Source
(Orig_Node
)
12707 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
12709 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
12711 -- GNAT allows an unchecked type conversion as a variable. This
12712 -- only affects the generation of internal expanded code, since
12713 -- calls to instantiations of Unchecked_Conversion are never
12714 -- considered variables (since they are function calls).
12716 when N_Unchecked_Type_Conversion
=>
12717 return Is_Variable
(Expression
(Orig_Node
));
12725 ---------------------------
12726 -- Is_Visibly_Controlled --
12727 ---------------------------
12729 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
12730 Root
: constant Entity_Id
:= Root_Type
(T
);
12732 return Chars
(Scope
(Root
)) = Name_Finalization
12733 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
12734 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
12735 end Is_Visibly_Controlled
;
12737 ------------------------
12738 -- Is_Volatile_Object --
12739 ------------------------
12741 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
12743 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
12744 -- If prefix is an implicit dereference, examine designated type
12746 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
12747 -- Determines if given object has volatile components
12749 ------------------------
12750 -- Is_Volatile_Prefix --
12751 ------------------------
12753 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
12754 Typ
: constant Entity_Id
:= Etype
(N
);
12757 if Is_Access_Type
(Typ
) then
12759 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
12762 return Is_Volatile
(Dtyp
)
12763 or else Has_Volatile_Components
(Dtyp
);
12767 return Object_Has_Volatile_Components
(N
);
12769 end Is_Volatile_Prefix
;
12771 ------------------------------------
12772 -- Object_Has_Volatile_Components --
12773 ------------------------------------
12775 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
12776 Typ
: constant Entity_Id
:= Etype
(N
);
12779 if Is_Volatile
(Typ
)
12780 or else Has_Volatile_Components
(Typ
)
12784 elsif Is_Entity_Name
(N
)
12785 and then (Has_Volatile_Components
(Entity
(N
))
12786 or else Is_Volatile
(Entity
(N
)))
12790 elsif Nkind
(N
) = N_Indexed_Component
12791 or else Nkind
(N
) = N_Selected_Component
12793 return Is_Volatile_Prefix
(Prefix
(N
));
12798 end Object_Has_Volatile_Components
;
12800 -- Start of processing for Is_Volatile_Object
12803 if Nkind
(N
) = N_Defining_Identifier
then
12804 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
12806 elsif Nkind
(N
) = N_Expanded_Name
then
12807 return Is_Volatile_Object
(Entity
(N
));
12809 elsif Is_Volatile
(Etype
(N
))
12810 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
12814 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
12815 and then Is_Volatile_Prefix
(Prefix
(N
))
12819 elsif Nkind
(N
) = N_Selected_Component
12820 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
12827 end Is_Volatile_Object
;
12829 ---------------------------
12830 -- Itype_Has_Declaration --
12831 ---------------------------
12833 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
12835 pragma Assert
(Is_Itype
(Id
));
12836 return Present
(Parent
(Id
))
12837 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
12838 N_Subtype_Declaration
)
12839 and then Defining_Entity
(Parent
(Id
)) = Id
;
12840 end Itype_Has_Declaration
;
12842 -------------------------
12843 -- Kill_Current_Values --
12844 -------------------------
12846 procedure Kill_Current_Values
12848 Last_Assignment_Only
: Boolean := False)
12851 if Is_Assignable
(Ent
) then
12852 Set_Last_Assignment
(Ent
, Empty
);
12855 if Is_Object
(Ent
) then
12856 if not Last_Assignment_Only
then
12858 Set_Current_Value
(Ent
, Empty
);
12860 if not Can_Never_Be_Null
(Ent
) then
12861 Set_Is_Known_Non_Null
(Ent
, False);
12864 Set_Is_Known_Null
(Ent
, False);
12866 -- Reset Is_Known_Valid unless type is always valid, or if we have
12867 -- a loop parameter (loop parameters are always valid, since their
12868 -- bounds are defined by the bounds given in the loop header).
12870 if not Is_Known_Valid
(Etype
(Ent
))
12871 and then Ekind
(Ent
) /= E_Loop_Parameter
12873 Set_Is_Known_Valid
(Ent
, False);
12877 end Kill_Current_Values
;
12879 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
12882 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
12883 -- Clear current value for entity E and all entities chained to E
12885 ------------------------------------------
12886 -- Kill_Current_Values_For_Entity_Chain --
12887 ------------------------------------------
12889 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
12893 while Present
(Ent
) loop
12894 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
12897 end Kill_Current_Values_For_Entity_Chain
;
12899 -- Start of processing for Kill_Current_Values
12902 -- Kill all saved checks, a special case of killing saved values
12904 if not Last_Assignment_Only
then
12908 -- Loop through relevant scopes, which includes the current scope and
12909 -- any parent scopes if the current scope is a block or a package.
12911 S
:= Current_Scope
;
12914 -- Clear current values of all entities in current scope
12916 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
12918 -- If scope is a package, also clear current values of all private
12919 -- entities in the scope.
12921 if Is_Package_Or_Generic_Package
(S
)
12922 or else Is_Concurrent_Type
(S
)
12924 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
12927 -- If this is a not a subprogram, deal with parents
12929 if not Is_Subprogram
(S
) then
12931 exit Scope_Loop
when S
= Standard_Standard
;
12935 end loop Scope_Loop
;
12936 end Kill_Current_Values
;
12938 --------------------------
12939 -- Kill_Size_Check_Code --
12940 --------------------------
12942 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
12944 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
12945 and then Present
(Size_Check_Code
(E
))
12947 Remove
(Size_Check_Code
(E
));
12948 Set_Size_Check_Code
(E
, Empty
);
12950 end Kill_Size_Check_Code
;
12952 --------------------------
12953 -- Known_To_Be_Assigned --
12954 --------------------------
12956 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
12957 P
: constant Node_Id
:= Parent
(N
);
12962 -- Test left side of assignment
12964 when N_Assignment_Statement
=>
12965 return N
= Name
(P
);
12967 -- Function call arguments are never lvalues
12969 when N_Function_Call
=>
12972 -- Positional parameter for procedure or accept call
12974 when N_Procedure_Call_Statement |
12983 Proc
:= Get_Subprogram_Entity
(P
);
12989 -- If we are not a list member, something is strange, so
12990 -- be conservative and return False.
12992 if not Is_List_Member
(N
) then
12996 -- We are going to find the right formal by stepping forward
12997 -- through the formals, as we step backwards in the actuals.
12999 Form
:= First_Formal
(Proc
);
13002 -- If no formal, something is weird, so be conservative
13003 -- and return False.
13010 exit when No
(Act
);
13011 Next_Formal
(Form
);
13014 return Ekind
(Form
) /= E_In_Parameter
;
13017 -- Named parameter for procedure or accept call
13019 when N_Parameter_Association
=>
13025 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
13031 -- Loop through formals to find the one that matches
13033 Form
:= First_Formal
(Proc
);
13035 -- If no matching formal, that's peculiar, some kind of
13036 -- previous error, so return False to be conservative.
13037 -- Actually this also happens in legal code in the case
13038 -- where P is a parameter association for an Extra_Formal???
13044 -- Else test for match
13046 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
13047 return Ekind
(Form
) /= E_In_Parameter
;
13050 Next_Formal
(Form
);
13054 -- Test for appearing in a conversion that itself appears
13055 -- in an lvalue context, since this should be an lvalue.
13057 when N_Type_Conversion
=>
13058 return Known_To_Be_Assigned
(P
);
13060 -- All other references are definitely not known to be modifications
13066 end Known_To_Be_Assigned
;
13068 ---------------------------
13069 -- Last_Source_Statement --
13070 ---------------------------
13072 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
13076 N
:= Last
(Statements
(HSS
));
13077 while Present
(N
) loop
13078 exit when Comes_From_Source
(N
);
13083 end Last_Source_Statement
;
13085 ----------------------------------
13086 -- Matching_Static_Array_Bounds --
13087 ----------------------------------
13089 function Matching_Static_Array_Bounds
13091 R_Typ
: Node_Id
) return Boolean
13093 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
13094 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
13106 if L_Ndims
/= R_Ndims
then
13110 -- Unconstrained types do not have static bounds
13112 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
13116 -- First treat specially the first dimension, as the lower bound and
13117 -- length of string literals are not stored like those of arrays.
13119 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
13120 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
13121 L_Len
:= String_Literal_Length
(L_Typ
);
13123 L_Index
:= First_Index
(L_Typ
);
13124 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
13126 if Is_OK_Static_Expression
(L_Low
)
13128 Is_OK_Static_Expression
(L_High
)
13130 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
13133 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
13140 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
13141 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
13142 R_Len
:= String_Literal_Length
(R_Typ
);
13144 R_Index
:= First_Index
(R_Typ
);
13145 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
13147 if Is_OK_Static_Expression
(R_Low
)
13149 Is_OK_Static_Expression
(R_High
)
13151 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
13154 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
13161 if (Is_OK_Static_Expression
(L_Low
)
13163 Is_OK_Static_Expression
(R_Low
))
13164 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
13165 and then L_Len
= R_Len
13172 -- Then treat all other dimensions
13174 for Indx
in 2 .. L_Ndims
loop
13178 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
13179 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
13181 if (Is_OK_Static_Expression
(L_Low
) and then
13182 Is_OK_Static_Expression
(L_High
) and then
13183 Is_OK_Static_Expression
(R_Low
) and then
13184 Is_OK_Static_Expression
(R_High
))
13185 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
13187 Expr_Value
(L_High
) = Expr_Value
(R_High
))
13195 -- If we fall through the loop, all indexes matched
13198 end Matching_Static_Array_Bounds
;
13200 -------------------
13201 -- May_Be_Lvalue --
13202 -------------------
13204 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
13205 P
: constant Node_Id
:= Parent
(N
);
13210 -- Test left side of assignment
13212 when N_Assignment_Statement
=>
13213 return N
= Name
(P
);
13215 -- Test prefix of component or attribute. Note that the prefix of an
13216 -- explicit or implicit dereference cannot be an l-value.
13218 when N_Attribute_Reference
=>
13219 return N
= Prefix
(P
)
13220 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
13222 -- For an expanded name, the name is an lvalue if the expanded name
13223 -- is an lvalue, but the prefix is never an lvalue, since it is just
13224 -- the scope where the name is found.
13226 when N_Expanded_Name
=>
13227 if N
= Prefix
(P
) then
13228 return May_Be_Lvalue
(P
);
13233 -- For a selected component A.B, A is certainly an lvalue if A.B is.
13234 -- B is a little interesting, if we have A.B := 3, there is some
13235 -- discussion as to whether B is an lvalue or not, we choose to say
13236 -- it is. Note however that A is not an lvalue if it is of an access
13237 -- type since this is an implicit dereference.
13239 when N_Selected_Component
=>
13241 and then Present
(Etype
(N
))
13242 and then Is_Access_Type
(Etype
(N
))
13246 return May_Be_Lvalue
(P
);
13249 -- For an indexed component or slice, the index or slice bounds is
13250 -- never an lvalue. The prefix is an lvalue if the indexed component
13251 -- or slice is an lvalue, except if it is an access type, where we
13252 -- have an implicit dereference.
13254 when N_Indexed_Component | N_Slice
=>
13256 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
13260 return May_Be_Lvalue
(P
);
13263 -- Prefix of a reference is an lvalue if the reference is an lvalue
13265 when N_Reference
=>
13266 return May_Be_Lvalue
(P
);
13268 -- Prefix of explicit dereference is never an lvalue
13270 when N_Explicit_Dereference
=>
13273 -- Positional parameter for subprogram, entry, or accept call.
13274 -- In older versions of Ada function call arguments are never
13275 -- lvalues. In Ada 2012 functions can have in-out parameters.
13277 when N_Subprogram_Call |
13278 N_Entry_Call_Statement |
13281 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
13285 -- The following mechanism is clumsy and fragile. A single flag
13286 -- set in Resolve_Actuals would be preferable ???
13294 Proc
:= Get_Subprogram_Entity
(P
);
13300 -- If we are not a list member, something is strange, so be
13301 -- conservative and return True.
13303 if not Is_List_Member
(N
) then
13307 -- We are going to find the right formal by stepping forward
13308 -- through the formals, as we step backwards in the actuals.
13310 Form
:= First_Formal
(Proc
);
13313 -- If no formal, something is weird, so be conservative and
13321 exit when No
(Act
);
13322 Next_Formal
(Form
);
13325 return Ekind
(Form
) /= E_In_Parameter
;
13328 -- Named parameter for procedure or accept call
13330 when N_Parameter_Association
=>
13336 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
13342 -- Loop through formals to find the one that matches
13344 Form
:= First_Formal
(Proc
);
13346 -- If no matching formal, that's peculiar, some kind of
13347 -- previous error, so return True to be conservative.
13348 -- Actually happens with legal code for an unresolved call
13349 -- where we may get the wrong homonym???
13355 -- Else test for match
13357 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
13358 return Ekind
(Form
) /= E_In_Parameter
;
13361 Next_Formal
(Form
);
13365 -- Test for appearing in a conversion that itself appears in an
13366 -- lvalue context, since this should be an lvalue.
13368 when N_Type_Conversion
=>
13369 return May_Be_Lvalue
(P
);
13371 -- Test for appearance in object renaming declaration
13373 when N_Object_Renaming_Declaration
=>
13376 -- All other references are definitely not lvalues
13384 -----------------------
13385 -- Mark_Coextensions --
13386 -----------------------
13388 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
13389 Is_Dynamic
: Boolean;
13390 -- Indicates whether the context causes nested coextensions to be
13391 -- dynamic or static
13393 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
13394 -- Recognize an allocator node and label it as a dynamic coextension
13396 --------------------
13397 -- Mark_Allocator --
13398 --------------------
13400 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
13402 if Nkind
(N
) = N_Allocator
then
13404 Set_Is_Dynamic_Coextension
(N
);
13406 -- If the allocator expression is potentially dynamic, it may
13407 -- be expanded out of order and require dynamic allocation
13408 -- anyway, so we treat the coextension itself as dynamic.
13409 -- Potential optimization ???
13411 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
13412 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
13414 Set_Is_Dynamic_Coextension
(N
);
13416 Set_Is_Static_Coextension
(N
);
13421 end Mark_Allocator
;
13423 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
13425 -- Start of processing Mark_Coextensions
13428 case Nkind
(Context_Nod
) is
13430 -- Comment here ???
13432 when N_Assignment_Statement
=>
13433 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
13435 -- An allocator that is a component of a returned aggregate
13436 -- must be dynamic.
13438 when N_Simple_Return_Statement
=>
13440 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
13443 Nkind
(Expr
) = N_Allocator
13445 (Nkind
(Expr
) = N_Qualified_Expression
13446 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
13449 -- An alloctor within an object declaration in an extended return
13450 -- statement is of necessity dynamic.
13452 when N_Object_Declaration
=>
13453 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
13455 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
13457 -- This routine should not be called for constructs which may not
13458 -- contain coextensions.
13461 raise Program_Error
;
13464 Mark_Allocators
(Root_Nod
);
13465 end Mark_Coextensions
;
13467 ----------------------
13468 -- Needs_One_Actual --
13469 ----------------------
13471 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
13472 Formal
: Entity_Id
;
13475 -- Ada 2005 or later, and formals present
13477 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
13478 Formal
:= Next_Formal
(First_Formal
(E
));
13479 while Present
(Formal
) loop
13480 if No
(Default_Value
(Formal
)) then
13484 Next_Formal
(Formal
);
13489 -- Ada 83/95 or no formals
13494 end Needs_One_Actual
;
13496 ------------------------
13497 -- New_Copy_List_Tree --
13498 ------------------------
13500 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
13505 if List
= No_List
then
13512 while Present
(E
) loop
13513 Append
(New_Copy_Tree
(E
), NL
);
13519 end New_Copy_List_Tree
;
13521 --------------------------------------------------
13522 -- New_Copy_Tree Auxiliary Data and Subprograms --
13523 --------------------------------------------------
13525 use Atree
.Unchecked_Access
;
13526 use Atree_Private_Part
;
13528 -- Our approach here requires a two pass traversal of the tree. The
13529 -- first pass visits all nodes that eventually will be copied looking
13530 -- for defining Itypes. If any defining Itypes are found, then they are
13531 -- copied, and an entry is added to the replacement map. In the second
13532 -- phase, the tree is copied, using the replacement map to replace any
13533 -- Itype references within the copied tree.
13535 -- The following hash tables are used if the Map supplied has more
13536 -- than hash threshold entries to speed up access to the map. If
13537 -- there are fewer entries, then the map is searched sequentially
13538 -- (because setting up a hash table for only a few entries takes
13539 -- more time than it saves.
13541 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
13542 -- Hash function used for hash operations
13544 -------------------
13545 -- New_Copy_Hash --
13546 -------------------
13548 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
13550 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
13557 -- The hash table NCT_Assoc associates old entities in the table
13558 -- with their corresponding new entities (i.e. the pairs of entries
13559 -- presented in the original Map argument are Key-Element pairs).
13561 package NCT_Assoc
is new Simple_HTable
(
13562 Header_Num
=> NCT_Header_Num
,
13563 Element
=> Entity_Id
,
13564 No_Element
=> Empty
,
13566 Hash
=> New_Copy_Hash
,
13567 Equal
=> Types
."=");
13569 ---------------------
13570 -- NCT_Itype_Assoc --
13571 ---------------------
13573 -- The hash table NCT_Itype_Assoc contains entries only for those
13574 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13575 -- The key is the associated node, and the element is the new node
13576 -- itself (NOT the associated node for the new node).
13578 package NCT_Itype_Assoc
is new Simple_HTable
(
13579 Header_Num
=> NCT_Header_Num
,
13580 Element
=> Entity_Id
,
13581 No_Element
=> Empty
,
13583 Hash
=> New_Copy_Hash
,
13584 Equal
=> Types
."=");
13586 -------------------
13587 -- New_Copy_Tree --
13588 -------------------
13590 function New_Copy_Tree
13592 Map
: Elist_Id
:= No_Elist
;
13593 New_Sloc
: Source_Ptr
:= No_Location
;
13594 New_Scope
: Entity_Id
:= Empty
) return Node_Id
13596 Actual_Map
: Elist_Id
:= Map
;
13597 -- This is the actual map for the copy. It is initialized with the
13598 -- given elements, and then enlarged as required for Itypes that are
13599 -- copied during the first phase of the copy operation. The visit
13600 -- procedures add elements to this map as Itypes are encountered.
13601 -- The reason we cannot use Map directly, is that it may well be
13602 -- (and normally is) initialized to No_Elist, and if we have mapped
13603 -- entities, we have to reset it to point to a real Elist.
13605 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
13606 -- Called during second phase to map entities into their corresponding
13607 -- copies using Actual_Map. If the argument is not an entity, or is not
13608 -- in Actual_Map, then it is returned unchanged.
13610 procedure Build_NCT_Hash_Tables
;
13611 -- Builds hash tables (number of elements >= threshold value)
13613 function Copy_Elist_With_Replacement
13614 (Old_Elist
: Elist_Id
) return Elist_Id
;
13615 -- Called during second phase to copy element list doing replacements
13617 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
13618 -- Called during the second phase to process a copied Itype. The actual
13619 -- copy happened during the first phase (so that we could make the entry
13620 -- in the mapping), but we still have to deal with the descendents of
13621 -- the copied Itype and copy them where necessary.
13623 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
13624 -- Called during second phase to copy list doing replacements
13626 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
13627 -- Called during second phase to copy node doing replacements
13629 procedure Visit_Elist
(E
: Elist_Id
);
13630 -- Called during first phase to visit all elements of an Elist
13632 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
13633 -- Visit a single field, recursing to call Visit_Node or Visit_List
13634 -- if the field is a syntactic descendent of the current node (i.e.
13635 -- its parent is Node N).
13637 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
13638 -- Called during first phase to visit subsidiary fields of a defining
13639 -- Itype, and also create a copy and make an entry in the replacement
13640 -- map for the new copy.
13642 procedure Visit_List
(L
: List_Id
);
13643 -- Called during first phase to visit all elements of a List
13645 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
13646 -- Called during first phase to visit a node and all its subtrees
13652 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
13657 if not Has_Extension
(N
) or else No
(Actual_Map
) then
13660 elsif NCT_Hash_Tables_Used
then
13661 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
13663 if Present
(Ent
) then
13669 -- No hash table used, do serial search
13672 E
:= First_Elmt
(Actual_Map
);
13673 while Present
(E
) loop
13674 if Node
(E
) = N
then
13675 return Node
(Next_Elmt
(E
));
13677 E
:= Next_Elmt
(Next_Elmt
(E
));
13685 ---------------------------
13686 -- Build_NCT_Hash_Tables --
13687 ---------------------------
13689 procedure Build_NCT_Hash_Tables
is
13693 if NCT_Hash_Table_Setup
then
13695 NCT_Itype_Assoc
.Reset
;
13698 Elmt
:= First_Elmt
(Actual_Map
);
13699 while Present
(Elmt
) loop
13700 Ent
:= Node
(Elmt
);
13702 -- Get new entity, and associate old and new
13705 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
13707 if Is_Type
(Ent
) then
13709 Anode
: constant Entity_Id
:=
13710 Associated_Node_For_Itype
(Ent
);
13713 if Present
(Anode
) then
13715 -- Enter a link between the associated node of the
13716 -- old Itype and the new Itype, for updating later
13717 -- when node is copied.
13719 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
13727 NCT_Hash_Tables_Used
:= True;
13728 NCT_Hash_Table_Setup
:= True;
13729 end Build_NCT_Hash_Tables
;
13731 ---------------------------------
13732 -- Copy_Elist_With_Replacement --
13733 ---------------------------------
13735 function Copy_Elist_With_Replacement
13736 (Old_Elist
: Elist_Id
) return Elist_Id
13739 New_Elist
: Elist_Id
;
13742 if No
(Old_Elist
) then
13746 New_Elist
:= New_Elmt_List
;
13748 M
:= First_Elmt
(Old_Elist
);
13749 while Present
(M
) loop
13750 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
13756 end Copy_Elist_With_Replacement
;
13758 ---------------------------------
13759 -- Copy_Itype_With_Replacement --
13760 ---------------------------------
13762 -- This routine exactly parallels its phase one analog Visit_Itype,
13764 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
13766 -- Translate Next_Entity, Scope and Etype fields, in case they
13767 -- reference entities that have been mapped into copies.
13769 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
13770 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
13772 if Present
(New_Scope
) then
13773 Set_Scope
(New_Itype
, New_Scope
);
13775 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
13778 -- Copy referenced fields
13780 if Is_Discrete_Type
(New_Itype
) then
13781 Set_Scalar_Range
(New_Itype
,
13782 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
13784 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
13785 Set_Discriminant_Constraint
(New_Itype
,
13786 Copy_Elist_With_Replacement
13787 (Discriminant_Constraint
(New_Itype
)));
13789 elsif Is_Array_Type
(New_Itype
) then
13790 if Present
(First_Index
(New_Itype
)) then
13791 Set_First_Index
(New_Itype
,
13792 First
(Copy_List_With_Replacement
13793 (List_Containing
(First_Index
(New_Itype
)))));
13796 if Is_Packed
(New_Itype
) then
13797 Set_Packed_Array_Impl_Type
(New_Itype
,
13798 Copy_Node_With_Replacement
13799 (Packed_Array_Impl_Type
(New_Itype
)));
13802 end Copy_Itype_With_Replacement
;
13804 --------------------------------
13805 -- Copy_List_With_Replacement --
13806 --------------------------------
13808 function Copy_List_With_Replacement
13809 (Old_List
: List_Id
) return List_Id
13811 New_List
: List_Id
;
13815 if Old_List
= No_List
then
13819 New_List
:= Empty_List
;
13821 E
:= First
(Old_List
);
13822 while Present
(E
) loop
13823 Append
(Copy_Node_With_Replacement
(E
), New_List
);
13829 end Copy_List_With_Replacement
;
13831 --------------------------------
13832 -- Copy_Node_With_Replacement --
13833 --------------------------------
13835 function Copy_Node_With_Replacement
13836 (Old_Node
: Node_Id
) return Node_Id
13838 New_Node
: Node_Id
;
13840 procedure Adjust_Named_Associations
13841 (Old_Node
: Node_Id
;
13842 New_Node
: Node_Id
);
13843 -- If a call node has named associations, these are chained through
13844 -- the First_Named_Actual, Next_Named_Actual links. These must be
13845 -- propagated separately to the new parameter list, because these
13846 -- are not syntactic fields.
13848 function Copy_Field_With_Replacement
13849 (Field
: Union_Id
) return Union_Id
;
13850 -- Given Field, which is a field of Old_Node, return a copy of it
13851 -- if it is a syntactic field (i.e. its parent is Node), setting
13852 -- the parent of the copy to poit to New_Node. Otherwise returns
13853 -- the field (possibly mapped if it is an entity).
13855 -------------------------------
13856 -- Adjust_Named_Associations --
13857 -------------------------------
13859 procedure Adjust_Named_Associations
13860 (Old_Node
: Node_Id
;
13861 New_Node
: Node_Id
)
13866 Old_Next
: Node_Id
;
13867 New_Next
: Node_Id
;
13870 Old_E
:= First
(Parameter_Associations
(Old_Node
));
13871 New_E
:= First
(Parameter_Associations
(New_Node
));
13872 while Present
(Old_E
) loop
13873 if Nkind
(Old_E
) = N_Parameter_Association
13874 and then Present
(Next_Named_Actual
(Old_E
))
13876 if First_Named_Actual
(Old_Node
)
13877 = Explicit_Actual_Parameter
(Old_E
)
13879 Set_First_Named_Actual
13880 (New_Node
, Explicit_Actual_Parameter
(New_E
));
13883 -- Now scan parameter list from the beginning,to locate
13884 -- next named actual, which can be out of order.
13886 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
13887 New_Next
:= First
(Parameter_Associations
(New_Node
));
13889 while Nkind
(Old_Next
) /= N_Parameter_Association
13890 or else Explicit_Actual_Parameter
(Old_Next
)
13891 /= Next_Named_Actual
(Old_E
)
13897 Set_Next_Named_Actual
13898 (New_E
, Explicit_Actual_Parameter
(New_Next
));
13904 end Adjust_Named_Associations
;
13906 ---------------------------------
13907 -- Copy_Field_With_Replacement --
13908 ---------------------------------
13910 function Copy_Field_With_Replacement
13911 (Field
: Union_Id
) return Union_Id
13914 if Field
= Union_Id
(Empty
) then
13917 elsif Field
in Node_Range
then
13919 Old_N
: constant Node_Id
:= Node_Id
(Field
);
13923 -- If syntactic field, as indicated by the parent pointer
13924 -- being set, then copy the referenced node recursively.
13926 if Parent
(Old_N
) = Old_Node
then
13927 New_N
:= Copy_Node_With_Replacement
(Old_N
);
13929 if New_N
/= Old_N
then
13930 Set_Parent
(New_N
, New_Node
);
13933 -- For semantic fields, update possible entity reference
13934 -- from the replacement map.
13937 New_N
:= Assoc
(Old_N
);
13940 return Union_Id
(New_N
);
13943 elsif Field
in List_Range
then
13945 Old_L
: constant List_Id
:= List_Id
(Field
);
13949 -- If syntactic field, as indicated by the parent pointer,
13950 -- then recursively copy the entire referenced list.
13952 if Parent
(Old_L
) = Old_Node
then
13953 New_L
:= Copy_List_With_Replacement
(Old_L
);
13954 Set_Parent
(New_L
, New_Node
);
13956 -- For semantic list, just returned unchanged
13962 return Union_Id
(New_L
);
13965 -- Anything other than a list or a node is returned unchanged
13970 end Copy_Field_With_Replacement
;
13972 -- Start of processing for Copy_Node_With_Replacement
13975 if Old_Node
<= Empty_Or_Error
then
13978 elsif Has_Extension
(Old_Node
) then
13979 return Assoc
(Old_Node
);
13982 New_Node
:= New_Copy
(Old_Node
);
13984 -- If the node we are copying is the associated node of a
13985 -- previously copied Itype, then adjust the associated node
13986 -- of the copy of that Itype accordingly.
13988 if Present
(Actual_Map
) then
13994 -- Case of hash table used
13996 if NCT_Hash_Tables_Used
then
13997 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
13999 if Present
(Ent
) then
14000 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
14003 -- Case of no hash table used
14006 E
:= First_Elmt
(Actual_Map
);
14007 while Present
(E
) loop
14008 if Is_Itype
(Node
(E
))
14010 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
14012 Set_Associated_Node_For_Itype
14013 (Node
(Next_Elmt
(E
)), New_Node
);
14016 E
:= Next_Elmt
(Next_Elmt
(E
));
14022 -- Recursively copy descendents
14025 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
14027 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
14029 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
14031 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
14033 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
14035 -- Adjust Sloc of new node if necessary
14037 if New_Sloc
/= No_Location
then
14038 Set_Sloc
(New_Node
, New_Sloc
);
14040 -- If we adjust the Sloc, then we are essentially making
14041 -- a completely new node, so the Comes_From_Source flag
14042 -- should be reset to the proper default value.
14044 Nodes
.Table
(New_Node
).Comes_From_Source
:=
14045 Default_Node
.Comes_From_Source
;
14048 -- If the node is call and has named associations,
14049 -- set the corresponding links in the copy.
14051 if (Nkind
(Old_Node
) = N_Function_Call
14052 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
14054 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
14055 and then Present
(First_Named_Actual
(Old_Node
))
14057 Adjust_Named_Associations
(Old_Node
, New_Node
);
14060 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14061 -- The replacement mechanism applies to entities, and is not used
14062 -- here. Eventually we may need a more general graph-copying
14063 -- routine. For now, do a sequential search to find desired node.
14065 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
14066 and then Present
(First_Real_Statement
(Old_Node
))
14069 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
14073 N1
:= First
(Statements
(Old_Node
));
14074 N2
:= First
(Statements
(New_Node
));
14076 while N1
/= Old_F
loop
14081 Set_First_Real_Statement
(New_Node
, N2
);
14086 -- All done, return copied node
14089 end Copy_Node_With_Replacement
;
14095 procedure Visit_Elist
(E
: Elist_Id
) is
14098 if Present
(E
) then
14099 Elmt
:= First_Elmt
(E
);
14101 while Elmt
/= No_Elmt
loop
14102 Visit_Node
(Node
(Elmt
));
14112 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
14114 if F
= Union_Id
(Empty
) then
14117 elsif F
in Node_Range
then
14119 -- Copy node if it is syntactic, i.e. its parent pointer is
14120 -- set to point to the field that referenced it (certain
14121 -- Itypes will also meet this criterion, which is fine, since
14122 -- these are clearly Itypes that do need to be copied, since
14123 -- we are copying their parent.)
14125 if Parent
(Node_Id
(F
)) = N
then
14126 Visit_Node
(Node_Id
(F
));
14129 -- Another case, if we are pointing to an Itype, then we want
14130 -- to copy it if its associated node is somewhere in the tree
14133 -- Note: the exclusion of self-referential copies is just an
14134 -- optimization, since the search of the already copied list
14135 -- would catch it, but it is a common case (Etype pointing
14136 -- to itself for an Itype that is a base type).
14138 elsif Has_Extension
(Node_Id
(F
))
14139 and then Is_Itype
(Entity_Id
(F
))
14140 and then Node_Id
(F
) /= N
14146 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
14147 while Present
(P
) loop
14149 Visit_Node
(Node_Id
(F
));
14156 -- An Itype whose parent is not being copied definitely
14157 -- should NOT be copied, since it does not belong in any
14158 -- sense to the copied subtree.
14164 elsif F
in List_Range
and then Parent
(List_Id
(F
)) = N
then
14165 Visit_List
(List_Id
(F
));
14174 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
14175 New_Itype
: Entity_Id
;
14180 -- Itypes that describe the designated type of access to subprograms
14181 -- have the structure of subprogram declarations, with signatures,
14182 -- etc. Either we duplicate the signatures completely, or choose to
14183 -- share such itypes, which is fine because their elaboration will
14184 -- have no side effects.
14186 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
14190 New_Itype
:= New_Copy
(Old_Itype
);
14192 -- The new Itype has all the attributes of the old one, and
14193 -- we just copy the contents of the entity. However, the back-end
14194 -- needs different names for debugging purposes, so we create a
14195 -- new internal name for it in all cases.
14197 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
14199 -- If our associated node is an entity that has already been copied,
14200 -- then set the associated node of the copy to point to the right
14201 -- copy. If we have copied an Itype that is itself the associated
14202 -- node of some previously copied Itype, then we set the right
14203 -- pointer in the other direction.
14205 if Present
(Actual_Map
) then
14207 -- Case of hash tables used
14209 if NCT_Hash_Tables_Used
then
14211 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
14213 if Present
(Ent
) then
14214 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
14217 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
14218 if Present
(Ent
) then
14219 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
14221 -- If the hash table has no association for this Itype and
14222 -- its associated node, enter one now.
14225 NCT_Itype_Assoc
.Set
14226 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
14229 -- Case of hash tables not used
14232 E
:= First_Elmt
(Actual_Map
);
14233 while Present
(E
) loop
14234 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
14235 Set_Associated_Node_For_Itype
14236 (New_Itype
, Node
(Next_Elmt
(E
)));
14239 if Is_Type
(Node
(E
))
14240 and then Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
14242 Set_Associated_Node_For_Itype
14243 (Node
(Next_Elmt
(E
)), New_Itype
);
14246 E
:= Next_Elmt
(Next_Elmt
(E
));
14251 if Present
(Freeze_Node
(New_Itype
)) then
14252 Set_Is_Frozen
(New_Itype
, False);
14253 Set_Freeze_Node
(New_Itype
, Empty
);
14256 -- Add new association to map
14258 if No
(Actual_Map
) then
14259 Actual_Map
:= New_Elmt_List
;
14262 Append_Elmt
(Old_Itype
, Actual_Map
);
14263 Append_Elmt
(New_Itype
, Actual_Map
);
14265 if NCT_Hash_Tables_Used
then
14266 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
14269 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
14271 if NCT_Table_Entries
> NCT_Hash_Threshold
then
14272 Build_NCT_Hash_Tables
;
14276 -- If a record subtype is simply copied, the entity list will be
14277 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
14279 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
14280 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
14283 -- Visit descendents that eventually get copied
14285 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
14287 if Is_Discrete_Type
(Old_Itype
) then
14288 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
14290 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
14291 -- ??? This should involve call to Visit_Field
14292 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
14294 elsif Is_Array_Type
(Old_Itype
) then
14295 if Present
(First_Index
(Old_Itype
)) then
14296 Visit_Field
(Union_Id
(List_Containing
14297 (First_Index
(Old_Itype
))),
14301 if Is_Packed
(Old_Itype
) then
14302 Visit_Field
(Union_Id
(Packed_Array_Impl_Type
(Old_Itype
)),
14312 procedure Visit_List
(L
: List_Id
) is
14315 if L
/= No_List
then
14318 while Present
(N
) loop
14329 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
14331 -- Start of processing for Visit_Node
14334 -- Handle case of an Itype, which must be copied
14336 if Has_Extension
(N
) and then Is_Itype
(N
) then
14338 -- Nothing to do if already in the list. This can happen with an
14339 -- Itype entity that appears more than once in the tree.
14340 -- Note that we do not want to visit descendents in this case.
14342 -- Test for already in list when hash table is used
14344 if NCT_Hash_Tables_Used
then
14345 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
14349 -- Test for already in list when hash table not used
14355 if Present
(Actual_Map
) then
14356 E
:= First_Elmt
(Actual_Map
);
14357 while Present
(E
) loop
14358 if Node
(E
) = N
then
14361 E
:= Next_Elmt
(Next_Elmt
(E
));
14371 -- Visit descendents
14373 Visit_Field
(Field1
(N
), N
);
14374 Visit_Field
(Field2
(N
), N
);
14375 Visit_Field
(Field3
(N
), N
);
14376 Visit_Field
(Field4
(N
), N
);
14377 Visit_Field
(Field5
(N
), N
);
14380 -- Start of processing for New_Copy_Tree
14385 -- See if we should use hash table
14387 if No
(Actual_Map
) then
14388 NCT_Hash_Tables_Used
:= False;
14395 NCT_Table_Entries
:= 0;
14397 Elmt
:= First_Elmt
(Actual_Map
);
14398 while Present
(Elmt
) loop
14399 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
14404 if NCT_Table_Entries
> NCT_Hash_Threshold
then
14405 Build_NCT_Hash_Tables
;
14407 NCT_Hash_Tables_Used
:= False;
14412 -- Hash table set up if required, now start phase one by visiting
14413 -- top node (we will recursively visit the descendents).
14415 Visit_Node
(Source
);
14417 -- Now the second phase of the copy can start. First we process
14418 -- all the mapped entities, copying their descendents.
14420 if Present
(Actual_Map
) then
14423 New_Itype
: Entity_Id
;
14425 Elmt
:= First_Elmt
(Actual_Map
);
14426 while Present
(Elmt
) loop
14428 New_Itype
:= Node
(Elmt
);
14429 Copy_Itype_With_Replacement
(New_Itype
);
14435 -- Now we can copy the actual tree
14437 return Copy_Node_With_Replacement
(Source
);
14440 -------------------------
14441 -- New_External_Entity --
14442 -------------------------
14444 function New_External_Entity
14445 (Kind
: Entity_Kind
;
14446 Scope_Id
: Entity_Id
;
14447 Sloc_Value
: Source_Ptr
;
14448 Related_Id
: Entity_Id
;
14449 Suffix
: Character;
14450 Suffix_Index
: Nat
:= 0;
14451 Prefix
: Character := ' ') return Entity_Id
14453 N
: constant Entity_Id
:=
14454 Make_Defining_Identifier
(Sloc_Value
,
14456 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
14459 Set_Ekind
(N
, Kind
);
14460 Set_Is_Internal
(N
, True);
14461 Append_Entity
(N
, Scope_Id
);
14462 Set_Public_Status
(N
);
14464 if Kind
in Type_Kind
then
14465 Init_Size_Align
(N
);
14469 end New_External_Entity
;
14471 -------------------------
14472 -- New_Internal_Entity --
14473 -------------------------
14475 function New_Internal_Entity
14476 (Kind
: Entity_Kind
;
14477 Scope_Id
: Entity_Id
;
14478 Sloc_Value
: Source_Ptr
;
14479 Id_Char
: Character) return Entity_Id
14481 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
14484 Set_Ekind
(N
, Kind
);
14485 Set_Is_Internal
(N
, True);
14486 Append_Entity
(N
, Scope_Id
);
14488 if Kind
in Type_Kind
then
14489 Init_Size_Align
(N
);
14493 end New_Internal_Entity
;
14499 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
14503 -- If we are pointing at a positional parameter, it is a member of a
14504 -- node list (the list of parameters), and the next parameter is the
14505 -- next node on the list, unless we hit a parameter association, then
14506 -- we shift to using the chain whose head is the First_Named_Actual in
14507 -- the parent, and then is threaded using the Next_Named_Actual of the
14508 -- Parameter_Association. All this fiddling is because the original node
14509 -- list is in the textual call order, and what we need is the
14510 -- declaration order.
14512 if Is_List_Member
(Actual_Id
) then
14513 N
:= Next
(Actual_Id
);
14515 if Nkind
(N
) = N_Parameter_Association
then
14516 return First_Named_Actual
(Parent
(Actual_Id
));
14522 return Next_Named_Actual
(Parent
(Actual_Id
));
14526 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
14528 Actual_Id
:= Next_Actual
(Actual_Id
);
14531 -----------------------
14532 -- Normalize_Actuals --
14533 -----------------------
14535 -- Chain actuals according to formals of subprogram. If there are no named
14536 -- associations, the chain is simply the list of Parameter Associations,
14537 -- since the order is the same as the declaration order. If there are named
14538 -- associations, then the First_Named_Actual field in the N_Function_Call
14539 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14540 -- node for the parameter that comes first in declaration order. The
14541 -- remaining named parameters are then chained in declaration order using
14542 -- Next_Named_Actual.
14544 -- This routine also verifies that the number of actuals is compatible with
14545 -- the number and default values of formals, but performs no type checking
14546 -- (type checking is done by the caller).
14548 -- If the matching succeeds, Success is set to True and the caller proceeds
14549 -- with type-checking. If the match is unsuccessful, then Success is set to
14550 -- False, and the caller attempts a different interpretation, if there is
14553 -- If the flag Report is on, the call is not overloaded, and a failure to
14554 -- match can be reported here, rather than in the caller.
14556 procedure Normalize_Actuals
14560 Success
: out Boolean)
14562 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
14563 Actual
: Node_Id
:= Empty
;
14564 Formal
: Entity_Id
;
14565 Last
: Node_Id
:= Empty
;
14566 First_Named
: Node_Id
:= Empty
;
14569 Formals_To_Match
: Integer := 0;
14570 Actuals_To_Match
: Integer := 0;
14572 procedure Chain
(A
: Node_Id
);
14573 -- Add named actual at the proper place in the list, using the
14574 -- Next_Named_Actual link.
14576 function Reporting
return Boolean;
14577 -- Determines if an error is to be reported. To report an error, we
14578 -- need Report to be True, and also we do not report errors caused
14579 -- by calls to init procs that occur within other init procs. Such
14580 -- errors must always be cascaded errors, since if all the types are
14581 -- declared correctly, the compiler will certainly build decent calls.
14587 procedure Chain
(A
: Node_Id
) is
14591 -- Call node points to first actual in list
14593 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
14596 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
14600 Set_Next_Named_Actual
(Last
, Empty
);
14607 function Reporting
return Boolean is
14612 elsif not Within_Init_Proc
then
14615 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
14623 -- Start of processing for Normalize_Actuals
14626 if Is_Access_Type
(S
) then
14628 -- The name in the call is a function call that returns an access
14629 -- to subprogram. The designated type has the list of formals.
14631 Formal
:= First_Formal
(Designated_Type
(S
));
14633 Formal
:= First_Formal
(S
);
14636 while Present
(Formal
) loop
14637 Formals_To_Match
:= Formals_To_Match
+ 1;
14638 Next_Formal
(Formal
);
14641 -- Find if there is a named association, and verify that no positional
14642 -- associations appear after named ones.
14644 if Present
(Actuals
) then
14645 Actual
:= First
(Actuals
);
14648 while Present
(Actual
)
14649 and then Nkind
(Actual
) /= N_Parameter_Association
14651 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14655 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
14657 -- Most common case: positional notation, no defaults
14662 elsif Actuals_To_Match
> Formals_To_Match
then
14664 -- Too many actuals: will not work
14667 if Is_Entity_Name
(Name
(N
)) then
14668 Error_Msg_N
("too many arguments in call to&", Name
(N
));
14670 Error_Msg_N
("too many arguments in call", N
);
14678 First_Named
:= Actual
;
14680 while Present
(Actual
) loop
14681 if Nkind
(Actual
) /= N_Parameter_Association
then
14683 ("positional parameters not allowed after named ones", Actual
);
14688 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14694 if Present
(Actuals
) then
14695 Actual
:= First
(Actuals
);
14698 Formal
:= First_Formal
(S
);
14699 while Present
(Formal
) loop
14701 -- Match the formals in order. If the corresponding actual is
14702 -- positional, nothing to do. Else scan the list of named actuals
14703 -- to find the one with the right name.
14705 if Present
(Actual
)
14706 and then Nkind
(Actual
) /= N_Parameter_Association
14709 Actuals_To_Match
:= Actuals_To_Match
- 1;
14710 Formals_To_Match
:= Formals_To_Match
- 1;
14713 -- For named parameters, search the list of actuals to find
14714 -- one that matches the next formal name.
14716 Actual
:= First_Named
;
14718 while Present
(Actual
) loop
14719 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
14722 Actuals_To_Match
:= Actuals_To_Match
- 1;
14723 Formals_To_Match
:= Formals_To_Match
- 1;
14731 if Ekind
(Formal
) /= E_In_Parameter
14732 or else No
(Default_Value
(Formal
))
14735 if (Comes_From_Source
(S
)
14736 or else Sloc
(S
) = Standard_Location
)
14737 and then Is_Overloadable
(S
)
14741 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
14743 N_Parameter_Association
)
14744 and then Ekind
(S
) /= E_Function
14746 Set_Etype
(N
, Etype
(S
));
14749 Error_Msg_Name_1
:= Chars
(S
);
14750 Error_Msg_Sloc
:= Sloc
(S
);
14752 ("missing argument for parameter & "
14753 & "in call to % declared #", N
, Formal
);
14756 elsif Is_Overloadable
(S
) then
14757 Error_Msg_Name_1
:= Chars
(S
);
14759 -- Point to type derivation that generated the
14762 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
14765 ("missing argument for parameter & "
14766 & "in call to % (inherited) #", N
, Formal
);
14770 ("missing argument for parameter &", N
, Formal
);
14778 Formals_To_Match
:= Formals_To_Match
- 1;
14783 Next_Formal
(Formal
);
14786 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
14793 -- Find some superfluous named actual that did not get
14794 -- attached to the list of associations.
14796 Actual
:= First
(Actuals
);
14797 while Present
(Actual
) loop
14798 if Nkind
(Actual
) = N_Parameter_Association
14799 and then Actual
/= Last
14800 and then No
(Next_Named_Actual
(Actual
))
14802 Error_Msg_N
("unmatched actual & in call",
14803 Selector_Name
(Actual
));
14814 end Normalize_Actuals
;
14816 --------------------------------
14817 -- Note_Possible_Modification --
14818 --------------------------------
14820 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
14821 Modification_Comes_From_Source
: constant Boolean :=
14822 Comes_From_Source
(Parent
(N
));
14828 -- Loop to find referenced entity, if there is one
14834 if Is_Entity_Name
(Exp
) then
14835 Ent
:= Entity
(Exp
);
14837 -- If the entity is missing, it is an undeclared identifier,
14838 -- and there is nothing to annotate.
14844 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
14846 P
: constant Node_Id
:= Prefix
(Exp
);
14849 -- In formal verification mode, keep track of all reads and
14850 -- writes through explicit dereferences.
14852 if GNATprove_Mode
then
14853 SPARK_Specific
.Generate_Dereference
(N
, 'm');
14856 if Nkind
(P
) = N_Selected_Component
14857 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
14859 -- Case of a reference to an entry formal
14861 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
14863 elsif Nkind
(P
) = N_Identifier
14864 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
14865 and then Present
(Expression
(Parent
(Entity
(P
))))
14866 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
14869 -- Case of a reference to a value on which side effects have
14872 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
14880 elsif Nkind_In
(Exp
, N_Type_Conversion
,
14881 N_Unchecked_Type_Conversion
)
14883 Exp
:= Expression
(Exp
);
14886 elsif Nkind_In
(Exp
, N_Slice
,
14887 N_Indexed_Component
,
14888 N_Selected_Component
)
14890 -- Special check, if the prefix is an access type, then return
14891 -- since we are modifying the thing pointed to, not the prefix.
14892 -- When we are expanding, most usually the prefix is replaced
14893 -- by an explicit dereference, and this test is not needed, but
14894 -- in some cases (notably -gnatc mode and generics) when we do
14895 -- not do full expansion, we need this special test.
14897 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
14900 -- Otherwise go to prefix and keep going
14903 Exp
:= Prefix
(Exp
);
14907 -- All other cases, not a modification
14913 -- Now look for entity being referenced
14915 if Present
(Ent
) then
14916 if Is_Object
(Ent
) then
14917 if Comes_From_Source
(Exp
)
14918 or else Modification_Comes_From_Source
14920 -- Give warning if pragma unmodified given and we are
14921 -- sure this is a modification.
14923 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
14924 Error_Msg_NE
("??pragma Unmodified given for &!", N
, Ent
);
14927 Set_Never_Set_In_Source
(Ent
, False);
14930 Set_Is_True_Constant
(Ent
, False);
14931 Set_Current_Value
(Ent
, Empty
);
14932 Set_Is_Known_Null
(Ent
, False);
14934 if not Can_Never_Be_Null
(Ent
) then
14935 Set_Is_Known_Non_Null
(Ent
, False);
14938 -- Follow renaming chain
14940 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
14941 and then Present
(Renamed_Object
(Ent
))
14943 Exp
:= Renamed_Object
(Ent
);
14945 -- If the entity is the loop variable in an iteration over
14946 -- a container, retrieve container expression to indicate
14947 -- possible modificastion.
14949 if Present
(Related_Expression
(Ent
))
14950 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
14951 N_Iterator_Specification
14953 Exp
:= Original_Node
(Related_Expression
(Ent
));
14958 -- The expression may be the renaming of a subcomponent of an
14959 -- array or container. The assignment to the subcomponent is
14960 -- a modification of the container.
14962 elsif Comes_From_Source
(Original_Node
(Exp
))
14963 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
14964 N_Indexed_Component
)
14966 Exp
:= Prefix
(Original_Node
(Exp
));
14970 -- Generate a reference only if the assignment comes from
14971 -- source. This excludes, for example, calls to a dispatching
14972 -- assignment operation when the left-hand side is tagged. In
14973 -- GNATprove mode, we need those references also on generated
14974 -- code, as these are used to compute the local effects of
14977 if Modification_Comes_From_Source
or GNATprove_Mode
then
14978 Generate_Reference
(Ent
, Exp
, 'm');
14980 -- If the target of the assignment is the bound variable
14981 -- in an iterator, indicate that the corresponding array
14982 -- or container is also modified.
14984 if Ada_Version
>= Ada_2012
14985 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
14988 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
14991 -- TBD : in the full version of the construct, the
14992 -- domain of iteration can be given by an expression.
14994 if Is_Entity_Name
(Domain
) then
14995 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
14996 Set_Is_True_Constant
(Entity
(Domain
), False);
14997 Set_Never_Set_In_Source
(Entity
(Domain
), False);
15003 Check_Nested_Access
(Ent
);
15008 -- If we are sure this is a modification from source, and we know
15009 -- this modifies a constant, then give an appropriate warning.
15011 if Overlays_Constant
(Ent
)
15012 and then (Modification_Comes_From_Source
and Sure
)
15015 A
: constant Node_Id
:= Address_Clause
(Ent
);
15017 if Present
(A
) then
15019 Exp
: constant Node_Id
:= Expression
(A
);
15021 if Nkind
(Exp
) = N_Attribute_Reference
15022 and then Attribute_Name
(Exp
) = Name_Address
15023 and then Is_Entity_Name
(Prefix
(Exp
))
15025 Error_Msg_Sloc
:= Sloc
(A
);
15027 ("constant& may be modified via address "
15028 & "clause#??", N
, Entity
(Prefix
(Exp
)));
15041 end Note_Possible_Modification
;
15043 -------------------------
15044 -- Object_Access_Level --
15045 -------------------------
15047 -- Returns the static accessibility level of the view denoted by Obj. Note
15048 -- that the value returned is the result of a call to Scope_Depth. Only
15049 -- scope depths associated with dynamic scopes can actually be returned.
15050 -- Since only relative levels matter for accessibility checking, the fact
15051 -- that the distance between successive levels of accessibility is not
15052 -- always one is immaterial (invariant: if level(E2) is deeper than
15053 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15055 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
15056 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
15057 -- Determine whether N is a construct of the form
15058 -- Some_Type (Operand._tag'Address)
15059 -- This construct appears in the context of dispatching calls.
15061 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
15062 -- An explicit dereference is created when removing side-effects from
15063 -- expressions for constraint checking purposes. In this case a local
15064 -- access type is created for it. The correct access level is that of
15065 -- the original source node. We detect this case by noting that the
15066 -- prefix of the dereference is created by an object declaration whose
15067 -- initial expression is a reference.
15069 -----------------------------
15070 -- Is_Interface_Conversion --
15071 -----------------------------
15073 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
15075 return Nkind
(N
) = N_Unchecked_Type_Conversion
15076 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
15077 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
15078 end Is_Interface_Conversion
;
15084 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
15085 Pref
: constant Node_Id
:= Prefix
(Obj
);
15087 if Is_Entity_Name
(Pref
)
15088 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
15089 and then Present
(Expression
(Parent
(Entity
(Pref
))))
15090 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
15092 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
15102 -- Start of processing for Object_Access_Level
15105 if Nkind
(Obj
) = N_Defining_Identifier
15106 or else Is_Entity_Name
(Obj
)
15108 if Nkind
(Obj
) = N_Defining_Identifier
then
15114 if Is_Prival
(E
) then
15115 E
:= Prival_Link
(E
);
15118 -- If E is a type then it denotes a current instance. For this case
15119 -- we add one to the normal accessibility level of the type to ensure
15120 -- that current instances are treated as always being deeper than
15121 -- than the level of any visible named access type (see 3.10.2(21)).
15123 if Is_Type
(E
) then
15124 return Type_Access_Level
(E
) + 1;
15126 elsif Present
(Renamed_Object
(E
)) then
15127 return Object_Access_Level
(Renamed_Object
(E
));
15129 -- Similarly, if E is a component of the current instance of a
15130 -- protected type, any instance of it is assumed to be at a deeper
15131 -- level than the type. For a protected object (whose type is an
15132 -- anonymous protected type) its components are at the same level
15133 -- as the type itself.
15135 elsif not Is_Overloadable
(E
)
15136 and then Ekind
(Scope
(E
)) = E_Protected_Type
15137 and then Comes_From_Source
(Scope
(E
))
15139 return Type_Access_Level
(Scope
(E
)) + 1;
15142 -- Aliased formals take their access level from the point of call.
15143 -- This is smaller than the level of the subprogram itself.
15145 if Is_Formal
(E
) and then Is_Aliased
(E
) then
15146 return Type_Access_Level
(Etype
(E
));
15149 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
15153 elsif Nkind
(Obj
) = N_Selected_Component
then
15154 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
15155 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15157 return Object_Access_Level
(Prefix
(Obj
));
15160 elsif Nkind
(Obj
) = N_Indexed_Component
then
15161 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
15162 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15164 return Object_Access_Level
(Prefix
(Obj
));
15167 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
15169 -- If the prefix is a selected access discriminant then we make a
15170 -- recursive call on the prefix, which will in turn check the level
15171 -- of the prefix object of the selected discriminant.
15173 -- In Ada 2012, if the discriminant has implicit dereference and
15174 -- the context is a selected component, treat this as an object of
15175 -- unknown scope (see below). This is necessary in compile-only mode;
15176 -- otherwise expansion will already have transformed the prefix into
15179 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
15180 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
15182 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
15184 (not Has_Implicit_Dereference
15185 (Entity
(Selector_Name
(Prefix
(Obj
))))
15186 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
15188 return Object_Access_Level
(Prefix
(Obj
));
15190 -- Detect an interface conversion in the context of a dispatching
15191 -- call. Use the original form of the conversion to find the access
15192 -- level of the operand.
15194 elsif Is_Interface
(Etype
(Obj
))
15195 and then Is_Interface_Conversion
(Prefix
(Obj
))
15196 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
15198 return Object_Access_Level
(Original_Node
(Obj
));
15200 elsif not Comes_From_Source
(Obj
) then
15202 Ref
: constant Node_Id
:= Reference_To
(Obj
);
15204 if Present
(Ref
) then
15205 return Object_Access_Level
(Ref
);
15207 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15212 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15215 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
15216 return Object_Access_Level
(Expression
(Obj
));
15218 elsif Nkind
(Obj
) = N_Function_Call
then
15220 -- Function results are objects, so we get either the access level of
15221 -- the function or, in the case of an indirect call, the level of the
15222 -- access-to-subprogram type. (This code is used for Ada 95, but it
15223 -- looks wrong, because it seems that we should be checking the level
15224 -- of the call itself, even for Ada 95. However, using the Ada 2005
15225 -- version of the code causes regressions in several tests that are
15226 -- compiled with -gnat95. ???)
15228 if Ada_Version
< Ada_2005
then
15229 if Is_Entity_Name
(Name
(Obj
)) then
15230 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
15232 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
15235 -- For Ada 2005, the level of the result object of a function call is
15236 -- defined to be the level of the call's innermost enclosing master.
15237 -- We determine that by querying the depth of the innermost enclosing
15241 Return_Master_Scope_Depth_Of_Call
: declare
15243 function Innermost_Master_Scope_Depth
15244 (N
: Node_Id
) return Uint
;
15245 -- Returns the scope depth of the given node's innermost
15246 -- enclosing dynamic scope (effectively the accessibility
15247 -- level of the innermost enclosing master).
15249 ----------------------------------
15250 -- Innermost_Master_Scope_Depth --
15251 ----------------------------------
15253 function Innermost_Master_Scope_Depth
15254 (N
: Node_Id
) return Uint
15256 Node_Par
: Node_Id
:= Parent
(N
);
15259 -- Locate the nearest enclosing node (by traversing Parents)
15260 -- that Defining_Entity can be applied to, and return the
15261 -- depth of that entity's nearest enclosing dynamic scope.
15263 while Present
(Node_Par
) loop
15264 case Nkind
(Node_Par
) is
15265 when N_Component_Declaration |
15266 N_Entry_Declaration |
15267 N_Formal_Object_Declaration |
15268 N_Formal_Type_Declaration |
15269 N_Full_Type_Declaration |
15270 N_Incomplete_Type_Declaration |
15271 N_Loop_Parameter_Specification |
15272 N_Object_Declaration |
15273 N_Protected_Type_Declaration |
15274 N_Private_Extension_Declaration |
15275 N_Private_Type_Declaration |
15276 N_Subtype_Declaration |
15277 N_Function_Specification |
15278 N_Procedure_Specification |
15279 N_Task_Type_Declaration |
15281 N_Generic_Instantiation |
15283 N_Implicit_Label_Declaration |
15284 N_Package_Declaration |
15285 N_Single_Task_Declaration |
15286 N_Subprogram_Declaration |
15287 N_Generic_Declaration |
15288 N_Renaming_Declaration |
15289 N_Block_Statement |
15290 N_Formal_Subprogram_Declaration |
15291 N_Abstract_Subprogram_Declaration |
15293 N_Exception_Declaration |
15294 N_Formal_Package_Declaration |
15295 N_Number_Declaration |
15296 N_Package_Specification |
15297 N_Parameter_Specification |
15298 N_Single_Protected_Declaration |
15302 (Nearest_Dynamic_Scope
15303 (Defining_Entity
(Node_Par
)));
15309 Node_Par
:= Parent
(Node_Par
);
15312 pragma Assert
(False);
15314 -- Should never reach the following return
15316 return Scope_Depth
(Current_Scope
) + 1;
15317 end Innermost_Master_Scope_Depth
;
15319 -- Start of processing for Return_Master_Scope_Depth_Of_Call
15322 return Innermost_Master_Scope_Depth
(Obj
);
15323 end Return_Master_Scope_Depth_Of_Call
;
15326 -- For convenience we handle qualified expressions, even though they
15327 -- aren't technically object names.
15329 elsif Nkind
(Obj
) = N_Qualified_Expression
then
15330 return Object_Access_Level
(Expression
(Obj
));
15332 -- Ditto for aggregates. They have the level of the temporary that
15333 -- will hold their value.
15335 elsif Nkind
(Obj
) = N_Aggregate
then
15336 return Object_Access_Level
(Current_Scope
);
15338 -- Otherwise return the scope level of Standard. (If there are cases
15339 -- that fall through to this point they will be treated as having
15340 -- global accessibility for now. ???)
15343 return Scope_Depth
(Standard_Standard
);
15345 end Object_Access_Level
;
15347 --------------------------
15348 -- Original_Aspect_Name --
15349 --------------------------
15351 function Original_Aspect_Name
(N
: Node_Id
) return Name_Id
is
15356 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
15359 if Is_Rewrite_Substitution
(Pras
)
15360 and then Nkind
(Original_Node
(Pras
)) = N_Pragma
15362 Pras
:= Original_Node
(Pras
);
15365 -- Case where we came from aspect specication
15367 if Nkind
(Pras
) = N_Pragma
and then From_Aspect_Specification
(Pras
) then
15368 Pras
:= Corresponding_Aspect
(Pras
);
15371 -- Get name from aspect or pragma
15373 if Nkind
(Pras
) = N_Pragma
then
15374 Name
:= Pragma_Name
(Pras
);
15376 Name
:= Chars
(Identifier
(Pras
));
15379 -- Deal with 'Class
15381 if Class_Present
(Pras
) then
15384 -- Names that need converting to special _xxx form
15392 Name
:= Name_uPost
;
15394 when Name_Invariant
=>
15395 Name
:= Name_uInvariant
;
15397 when Name_Type_Invariant |
15398 Name_Type_Invariant_Class
=>
15399 Name
:= Name_uType_Invariant
;
15401 -- Nothing to do for other cases (e.g. a Check that derived
15402 -- from Pre_Class and has the flag set). Also we do nothing
15403 -- if the name is already in special _xxx form.
15411 end Original_Aspect_Name
;
15413 --------------------------------------
15414 -- Original_Corresponding_Operation --
15415 --------------------------------------
15417 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
15419 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
15422 -- If S is an inherited primitive S2 the original corresponding
15423 -- operation of S is the original corresponding operation of S2
15425 if Present
(Alias
(S
))
15426 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
15428 return Original_Corresponding_Operation
(Alias
(S
));
15430 -- If S overrides an inherited subprogram S2 the original corresponding
15431 -- operation of S is the original corresponding operation of S2
15433 elsif Present
(Overridden_Operation
(S
)) then
15434 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
15436 -- otherwise it is S itself
15441 end Original_Corresponding_Operation
;
15443 ----------------------
15444 -- Policy_In_Effect --
15445 ----------------------
15447 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
15448 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
15449 -- Determine the the mode of a policy in a N_Pragma list
15451 --------------------
15452 -- Policy_In_List --
15453 --------------------
15455 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
15462 while Present
(Prag
) loop
15463 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
15464 Expr
:= Get_Pragma_Arg
(Arg
);
15466 -- The current Check_Policy pragma matches the requested policy,
15467 -- return the second argument which denotes the policy identifier.
15469 if Chars
(Expr
) = Policy
then
15470 return Chars
(Get_Pragma_Arg
(Next
(Arg
)));
15473 Prag
:= Next_Pragma
(Prag
);
15477 end Policy_In_List
;
15483 -- Start of processing for Policy_In_Effect
15486 if not Is_Valid_Assertion_Kind
(Policy
) then
15487 raise Program_Error
;
15490 -- Inspect all policy pragmas that appear within scopes (if any)
15492 Kind
:= Policy_In_List
(Check_Policy_List
);
15494 -- Inspect all configuration policy pragmas (if any)
15496 if Kind
= No_Name
then
15497 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
15500 -- The context lacks policy pragmas, determine the mode based on whether
15501 -- assertions are enabled at the configuration level. This ensures that
15502 -- the policy is preserved when analyzing generics.
15504 if Kind
= No_Name
then
15505 if Assertions_Enabled_Config
then
15506 Kind
:= Name_Check
;
15508 Kind
:= Name_Ignore
;
15513 end Policy_In_Effect
;
15515 ----------------------------------
15516 -- Predicate_Tests_On_Arguments --
15517 ----------------------------------
15519 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
15521 -- Always test predicates on indirect call
15523 if Ekind
(Subp
) = E_Subprogram_Type
then
15526 -- Do not test predicates on call to generated default Finalize, since
15527 -- we are not interested in whether something we are finalizing (and
15528 -- typically destroying) satisfies its predicates.
15530 elsif Chars
(Subp
) = Name_Finalize
15531 and then not Comes_From_Source
(Subp
)
15535 -- Do not test predicates on any internally generated routines
15537 elsif Is_Internal_Name
(Chars
(Subp
)) then
15540 -- Do not test predicates on call to Init_Proc, since if needed the
15541 -- predicate test will occur at some other point.
15543 elsif Is_Init_Proc
(Subp
) then
15546 -- Do not test predicates on call to predicate function, since this
15547 -- would cause infinite recursion.
15549 elsif Ekind
(Subp
) = E_Function
15550 and then (Is_Predicate_Function
(Subp
)
15552 Is_Predicate_Function_M
(Subp
))
15556 -- For now, no other exceptions
15561 end Predicate_Tests_On_Arguments
;
15563 -----------------------
15564 -- Private_Component --
15565 -----------------------
15567 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
15568 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
15570 function Trace_Components
15572 Check
: Boolean) return Entity_Id
;
15573 -- Recursive function that does the work, and checks against circular
15574 -- definition for each subcomponent type.
15576 ----------------------
15577 -- Trace_Components --
15578 ----------------------
15580 function Trace_Components
15582 Check
: Boolean) return Entity_Id
15584 Btype
: constant Entity_Id
:= Base_Type
(T
);
15585 Component
: Entity_Id
;
15587 Candidate
: Entity_Id
:= Empty
;
15590 if Check
and then Btype
= Ancestor
then
15591 Error_Msg_N
("circular type definition", Type_Id
);
15595 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
15596 if Present
(Full_View
(Btype
))
15597 and then Is_Record_Type
(Full_View
(Btype
))
15598 and then not Is_Frozen
(Btype
)
15600 -- To indicate that the ancestor depends on a private type, the
15601 -- current Btype is sufficient. However, to check for circular
15602 -- definition we must recurse on the full view.
15604 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
15606 if Candidate
= Any_Type
then
15616 elsif Is_Array_Type
(Btype
) then
15617 return Trace_Components
(Component_Type
(Btype
), True);
15619 elsif Is_Record_Type
(Btype
) then
15620 Component
:= First_Entity
(Btype
);
15621 while Present
(Component
)
15622 and then Comes_From_Source
(Component
)
15624 -- Skip anonymous types generated by constrained components
15626 if not Is_Type
(Component
) then
15627 P
:= Trace_Components
(Etype
(Component
), True);
15629 if Present
(P
) then
15630 if P
= Any_Type
then
15638 Next_Entity
(Component
);
15646 end Trace_Components
;
15648 -- Start of processing for Private_Component
15651 return Trace_Components
(Type_Id
, False);
15652 end Private_Component
;
15654 ---------------------------
15655 -- Primitive_Names_Match --
15656 ---------------------------
15658 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
15660 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
15661 -- Given an internal name, returns the corresponding non-internal name
15663 ------------------------
15664 -- Non_Internal_Name --
15665 ------------------------
15667 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
15669 Get_Name_String
(Chars
(E
));
15670 Name_Len
:= Name_Len
- 1;
15672 end Non_Internal_Name
;
15674 -- Start of processing for Primitive_Names_Match
15677 pragma Assert
(Present
(E1
) and then Present
(E2
));
15679 return Chars
(E1
) = Chars
(E2
)
15681 (not Is_Internal_Name
(Chars
(E1
))
15682 and then Is_Internal_Name
(Chars
(E2
))
15683 and then Non_Internal_Name
(E2
) = Chars
(E1
))
15685 (not Is_Internal_Name
(Chars
(E2
))
15686 and then Is_Internal_Name
(Chars
(E1
))
15687 and then Non_Internal_Name
(E1
) = Chars
(E2
))
15689 (Is_Predefined_Dispatching_Operation
(E1
)
15690 and then Is_Predefined_Dispatching_Operation
(E2
)
15691 and then Same_TSS
(E1
, E2
))
15693 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
15694 end Primitive_Names_Match
;
15696 -----------------------
15697 -- Process_End_Label --
15698 -----------------------
15700 procedure Process_End_Label
15709 Label_Ref
: Boolean;
15710 -- Set True if reference to end label itself is required
15713 -- Gets set to the operator symbol or identifier that references the
15714 -- entity Ent. For the child unit case, this is the identifier from the
15715 -- designator. For other cases, this is simply Endl.
15717 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
15718 -- N is an identifier node that appears as a parent unit reference in
15719 -- the case where Ent is a child unit. This procedure generates an
15720 -- appropriate cross-reference entry. E is the corresponding entity.
15722 -------------------------
15723 -- Generate_Parent_Ref --
15724 -------------------------
15726 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
15728 -- If names do not match, something weird, skip reference
15730 if Chars
(E
) = Chars
(N
) then
15732 -- Generate the reference. We do NOT consider this as a reference
15733 -- for unreferenced symbol purposes.
15735 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
15737 if Style_Check
then
15738 Style
.Check_Identifier
(N
, E
);
15741 end Generate_Parent_Ref
;
15743 -- Start of processing for Process_End_Label
15746 -- If no node, ignore. This happens in some error situations, and
15747 -- also for some internally generated structures where no end label
15748 -- references are required in any case.
15754 -- Nothing to do if no End_Label, happens for internally generated
15755 -- constructs where we don't want an end label reference anyway. Also
15756 -- nothing to do if Endl is a string literal, which means there was
15757 -- some prior error (bad operator symbol)
15759 Endl
:= End_Label
(N
);
15761 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
15765 -- Reference node is not in extended main source unit
15767 if not In_Extended_Main_Source_Unit
(N
) then
15769 -- Generally we do not collect references except for the extended
15770 -- main source unit. The one exception is the 'e' entry for a
15771 -- package spec, where it is useful for a client to have the
15772 -- ending information to define scopes.
15778 Label_Ref
:= False;
15780 -- For this case, we can ignore any parent references, but we
15781 -- need the package name itself for the 'e' entry.
15783 if Nkind
(Endl
) = N_Designator
then
15784 Endl
:= Identifier
(Endl
);
15788 -- Reference is in extended main source unit
15793 -- For designator, generate references for the parent entries
15795 if Nkind
(Endl
) = N_Designator
then
15797 -- Generate references for the prefix if the END line comes from
15798 -- source (otherwise we do not need these references) We climb the
15799 -- scope stack to find the expected entities.
15801 if Comes_From_Source
(Endl
) then
15802 Nam
:= Name
(Endl
);
15803 Scop
:= Current_Scope
;
15804 while Nkind
(Nam
) = N_Selected_Component
loop
15805 Scop
:= Scope
(Scop
);
15806 exit when No
(Scop
);
15807 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
15808 Nam
:= Prefix
(Nam
);
15811 if Present
(Scop
) then
15812 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
15816 Endl
:= Identifier
(Endl
);
15820 -- If the end label is not for the given entity, then either we have
15821 -- some previous error, or this is a generic instantiation for which
15822 -- we do not need to make a cross-reference in this case anyway. In
15823 -- either case we simply ignore the call.
15825 if Chars
(Ent
) /= Chars
(Endl
) then
15829 -- If label was really there, then generate a normal reference and then
15830 -- adjust the location in the end label to point past the name (which
15831 -- should almost always be the semicolon).
15833 Loc
:= Sloc
(Endl
);
15835 if Comes_From_Source
(Endl
) then
15837 -- If a label reference is required, then do the style check and
15838 -- generate an l-type cross-reference entry for the label
15841 if Style_Check
then
15842 Style
.Check_Identifier
(Endl
, Ent
);
15845 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
15848 -- Set the location to point past the label (normally this will
15849 -- mean the semicolon immediately following the label). This is
15850 -- done for the sake of the 'e' or 't' entry generated below.
15852 Get_Decoded_Name_String
(Chars
(Endl
));
15853 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
15856 -- In SPARK mode, no missing label is allowed for packages and
15857 -- subprogram bodies. Detect those cases by testing whether
15858 -- Process_End_Label was called for a body (Typ = 't') or a package.
15860 if Restriction_Check_Required
(SPARK_05
)
15861 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
15863 Error_Msg_Node_1
:= Endl
;
15864 Check_SPARK_05_Restriction
15865 ("`END &` required", Endl
, Force
=> True);
15869 -- Now generate the e/t reference
15871 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
15873 -- Restore Sloc, in case modified above, since we have an identifier
15874 -- and the normal Sloc should be left set in the tree.
15876 Set_Sloc
(Endl
, Loc
);
15877 end Process_End_Label
;
15883 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
15884 Seen
: Boolean := False;
15886 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
15887 -- Determine whether node N denotes a reference to Id. If this is the
15888 -- case, set global flag Seen to True and stop the traversal.
15894 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
15896 if Is_Entity_Name
(N
)
15897 and then Present
(Entity
(N
))
15898 and then Entity
(N
) = Id
15907 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
15909 -- Start of processing for Referenced
15912 Inspect_Expression
(Expr
);
15916 ------------------------------------
15917 -- References_Generic_Formal_Type --
15918 ------------------------------------
15920 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
15922 function Process
(N
: Node_Id
) return Traverse_Result
;
15923 -- Process one node in search for generic formal type
15929 function Process
(N
: Node_Id
) return Traverse_Result
is
15931 if Nkind
(N
) in N_Has_Entity
then
15933 E
: constant Entity_Id
:= Entity
(N
);
15935 if Present
(E
) then
15936 if Is_Generic_Type
(E
) then
15938 elsif Present
(Etype
(E
))
15939 and then Is_Generic_Type
(Etype
(E
))
15950 function Traverse
is new Traverse_Func
(Process
);
15951 -- Traverse tree to look for generic type
15954 if Inside_A_Generic
then
15955 return Traverse
(N
) = Abandon
;
15959 end References_Generic_Formal_Type
;
15961 --------------------
15962 -- Remove_Homonym --
15963 --------------------
15965 procedure Remove_Homonym
(E
: Entity_Id
) is
15966 Prev
: Entity_Id
:= Empty
;
15970 if E
= Current_Entity
(E
) then
15971 if Present
(Homonym
(E
)) then
15972 Set_Current_Entity
(Homonym
(E
));
15974 Set_Name_Entity_Id
(Chars
(E
), Empty
);
15978 H
:= Current_Entity
(E
);
15979 while Present
(H
) and then H
/= E
loop
15984 -- If E is not on the homonym chain, nothing to do
15986 if Present
(H
) then
15987 Set_Homonym
(Prev
, Homonym
(E
));
15990 end Remove_Homonym
;
15992 ---------------------
15993 -- Rep_To_Pos_Flag --
15994 ---------------------
15996 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
15998 return New_Occurrence_Of
15999 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
16000 end Rep_To_Pos_Flag
;
16002 --------------------
16003 -- Require_Entity --
16004 --------------------
16006 procedure Require_Entity
(N
: Node_Id
) is
16008 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
16009 if Total_Errors_Detected
/= 0 then
16010 Set_Entity
(N
, Any_Id
);
16012 raise Program_Error
;
16015 end Require_Entity
;
16017 -------------------------------
16018 -- Requires_State_Refinement --
16019 -------------------------------
16021 function Requires_State_Refinement
16022 (Spec_Id
: Entity_Id
;
16023 Body_Id
: Entity_Id
) return Boolean
16025 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
16026 -- Given pragma SPARK_Mode, determine whether the mode is Off
16032 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
16036 -- The default SPARK mode is On
16042 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
16044 -- Then the pragma lacks an argument, the default mode is On
16049 return Chars
(Mode
) = Name_Off
;
16053 -- Start of processing for Requires_State_Refinement
16056 -- A package that does not define at least one abstract state cannot
16057 -- possibly require refinement.
16059 if No
(Abstract_States
(Spec_Id
)) then
16062 -- The package instroduces a single null state which does not merit
16065 elsif Has_Null_Abstract_State
(Spec_Id
) then
16068 -- Check whether the package body is subject to pragma SPARK_Mode. If
16069 -- it is and the mode is Off, the package body is considered to be in
16070 -- regular Ada and does not require refinement.
16072 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
16075 -- The body's SPARK_Mode may be inherited from a similar pragma that
16076 -- appears in the private declarations of the spec. The pragma we are
16077 -- interested appears as the second entry in SPARK_Pragma.
16079 elsif Present
(SPARK_Pragma
(Spec_Id
))
16080 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
16084 -- The spec defines at least one abstract state and the body has no way
16085 -- of circumventing the refinement.
16090 end Requires_State_Refinement
;
16092 ------------------------------
16093 -- Requires_Transient_Scope --
16094 ------------------------------
16096 -- A transient scope is required when variable-sized temporaries are
16097 -- allocated in the primary or secondary stack, or when finalization
16098 -- actions must be generated before the next instruction.
16100 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
16101 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
16103 -- Start of processing for Requires_Transient_Scope
16106 -- This is a private type which is not completed yet. This can only
16107 -- happen in a default expression (of a formal parameter or of a
16108 -- record component). Do not expand transient scope in this case
16113 -- Do not expand transient scope for non-existent procedure return
16115 elsif Typ
= Standard_Void_Type
then
16118 -- Elementary types do not require a transient scope
16120 elsif Is_Elementary_Type
(Typ
) then
16123 -- Generally, indefinite subtypes require a transient scope, since the
16124 -- back end cannot generate temporaries, since this is not a valid type
16125 -- for declaring an object. It might be possible to relax this in the
16126 -- future, e.g. by declaring the maximum possible space for the type.
16128 elsif Is_Indefinite_Subtype
(Typ
) then
16131 -- Functions returning tagged types may dispatch on result so their
16132 -- returned value is allocated on the secondary stack. Controlled
16133 -- type temporaries need finalization.
16135 elsif Is_Tagged_Type
(Typ
)
16136 or else Has_Controlled_Component
(Typ
)
16138 return not Is_Value_Type
(Typ
);
16142 elsif Is_Record_Type
(Typ
) then
16146 Comp
:= First_Entity
(Typ
);
16147 while Present
(Comp
) loop
16148 if Ekind
(Comp
) = E_Component
16149 and then Requires_Transient_Scope
(Etype
(Comp
))
16153 Next_Entity
(Comp
);
16160 -- String literal types never require transient scope
16162 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
16165 -- Array type. Note that we already know that this is a constrained
16166 -- array, since unconstrained arrays will fail the indefinite test.
16168 elsif Is_Array_Type
(Typ
) then
16170 -- If component type requires a transient scope, the array does too
16172 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
16175 -- Otherwise, we only need a transient scope if the size depends on
16176 -- the value of one or more discriminants.
16179 return Size_Depends_On_Discriminant
(Typ
);
16182 -- All other cases do not require a transient scope
16187 end Requires_Transient_Scope
;
16189 --------------------------
16190 -- Reset_Analyzed_Flags --
16191 --------------------------
16193 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
16195 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
16196 -- Function used to reset Analyzed flags in tree. Note that we do
16197 -- not reset Analyzed flags in entities, since there is no need to
16198 -- reanalyze entities, and indeed, it is wrong to do so, since it
16199 -- can result in generating auxiliary stuff more than once.
16201 --------------------
16202 -- Clear_Analyzed --
16203 --------------------
16205 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
16207 if not Has_Extension
(N
) then
16208 Set_Analyzed
(N
, False);
16212 end Clear_Analyzed
;
16214 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
16216 -- Start of processing for Reset_Analyzed_Flags
16219 Reset_Analyzed
(N
);
16220 end Reset_Analyzed_Flags
;
16222 ------------------------
16223 -- Restore_SPARK_Mode --
16224 ------------------------
16226 procedure Restore_SPARK_Mode
(Mode
: SPARK_Mode_Type
) is
16228 SPARK_Mode
:= Mode
;
16229 end Restore_SPARK_Mode
;
16231 --------------------------------
16232 -- Returns_Unconstrained_Type --
16233 --------------------------------
16235 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
16237 return Ekind
(Subp
) = E_Function
16238 and then not Is_Scalar_Type
(Etype
(Subp
))
16239 and then not Is_Access_Type
(Etype
(Subp
))
16240 and then not Is_Constrained
(Etype
(Subp
));
16241 end Returns_Unconstrained_Type
;
16243 ----------------------------
16244 -- Root_Type_Of_Full_View --
16245 ----------------------------
16247 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
16248 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
16251 -- The root type of the full view may itself be a private type. Keep
16252 -- looking for the ultimate derivation parent.
16254 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
16255 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
16259 end Root_Type_Of_Full_View
;
16261 ---------------------------
16262 -- Safe_To_Capture_Value --
16263 ---------------------------
16265 function Safe_To_Capture_Value
16268 Cond
: Boolean := False) return Boolean
16271 -- The only entities for which we track constant values are variables
16272 -- which are not renamings, constants, out parameters, and in out
16273 -- parameters, so check if we have this case.
16275 -- Note: it may seem odd to track constant values for constants, but in
16276 -- fact this routine is used for other purposes than simply capturing
16277 -- the value. In particular, the setting of Known[_Non]_Null.
16279 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
16281 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
16285 -- For conditionals, we also allow loop parameters and all formals,
16286 -- including in parameters.
16288 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
16291 -- For all other cases, not just unsafe, but impossible to capture
16292 -- Current_Value, since the above are the only entities which have
16293 -- Current_Value fields.
16299 -- Skip if volatile or aliased, since funny things might be going on in
16300 -- these cases which we cannot necessarily track. Also skip any variable
16301 -- for which an address clause is given, or whose address is taken. Also
16302 -- never capture value of library level variables (an attempt to do so
16303 -- can occur in the case of package elaboration code).
16305 if Treat_As_Volatile
(Ent
)
16306 or else Is_Aliased
(Ent
)
16307 or else Present
(Address_Clause
(Ent
))
16308 or else Address_Taken
(Ent
)
16309 or else (Is_Library_Level_Entity
(Ent
)
16310 and then Ekind
(Ent
) = E_Variable
)
16315 -- OK, all above conditions are met. We also require that the scope of
16316 -- the reference be the same as the scope of the entity, not counting
16317 -- packages and blocks and loops.
16320 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
16321 R_Scope
: Entity_Id
;
16324 R_Scope
:= Current_Scope
;
16325 while R_Scope
/= Standard_Standard
loop
16326 exit when R_Scope
= E_Scope
;
16328 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
16331 R_Scope
:= Scope
(R_Scope
);
16336 -- We also require that the reference does not appear in a context
16337 -- where it is not sure to be executed (i.e. a conditional context
16338 -- or an exception handler). We skip this if Cond is True, since the
16339 -- capturing of values from conditional tests handles this ok.
16352 -- Seems dubious that case expressions are not handled here ???
16355 while Present
(P
) loop
16356 if Nkind
(P
) = N_If_Statement
16357 or else Nkind
(P
) = N_Case_Statement
16358 or else (Nkind
(P
) in N_Short_Circuit
16359 and then Desc
= Right_Opnd
(P
))
16360 or else (Nkind
(P
) = N_If_Expression
16361 and then Desc
/= First
(Expressions
(P
)))
16362 or else Nkind
(P
) = N_Exception_Handler
16363 or else Nkind
(P
) = N_Selective_Accept
16364 or else Nkind
(P
) = N_Conditional_Entry_Call
16365 or else Nkind
(P
) = N_Timed_Entry_Call
16366 or else Nkind
(P
) = N_Asynchronous_Select
16374 -- A special Ada 2012 case: the original node may be part
16375 -- of the else_actions of a conditional expression, in which
16376 -- case it might not have been expanded yet, and appears in
16377 -- a non-syntactic list of actions. In that case it is clearly
16378 -- not safe to save a value.
16381 and then Is_List_Member
(Desc
)
16382 and then No
(Parent
(List_Containing
(Desc
)))
16390 -- OK, looks safe to set value
16393 end Safe_To_Capture_Value
;
16399 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
16400 K1
: constant Node_Kind
:= Nkind
(N1
);
16401 K2
: constant Node_Kind
:= Nkind
(N2
);
16404 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
16405 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
16407 return Chars
(N1
) = Chars
(N2
);
16409 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
16410 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
16412 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
16413 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
16424 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
16425 N1
: constant Node_Id
:= Original_Node
(Node1
);
16426 N2
: constant Node_Id
:= Original_Node
(Node2
);
16427 -- We do the tests on original nodes, since we are most interested
16428 -- in the original source, not any expansion that got in the way.
16430 K1
: constant Node_Kind
:= Nkind
(N1
);
16431 K2
: constant Node_Kind
:= Nkind
(N2
);
16434 -- First case, both are entities with same entity
16436 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
16438 EN1
: constant Entity_Id
:= Entity
(N1
);
16439 EN2
: constant Entity_Id
:= Entity
(N2
);
16441 if Present
(EN1
) and then Present
(EN2
)
16442 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
16443 or else Is_Formal
(EN1
))
16451 -- Second case, selected component with same selector, same record
16453 if K1
= N_Selected_Component
16454 and then K2
= N_Selected_Component
16455 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
16457 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
16459 -- Third case, indexed component with same subscripts, same array
16461 elsif K1
= N_Indexed_Component
16462 and then K2
= N_Indexed_Component
16463 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
16468 E1
:= First
(Expressions
(N1
));
16469 E2
:= First
(Expressions
(N2
));
16470 while Present
(E1
) loop
16471 if not Same_Value
(E1
, E2
) then
16482 -- Fourth case, slice of same array with same bounds
16485 and then K2
= N_Slice
16486 and then Nkind
(Discrete_Range
(N1
)) = N_Range
16487 and then Nkind
(Discrete_Range
(N2
)) = N_Range
16488 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
16489 Low_Bound
(Discrete_Range
(N2
)))
16490 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
16491 High_Bound
(Discrete_Range
(N2
)))
16493 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
16495 -- All other cases, not clearly the same object
16506 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
16511 elsif not Is_Constrained
(T1
)
16512 and then not Is_Constrained
(T2
)
16513 and then Base_Type
(T1
) = Base_Type
(T2
)
16517 -- For now don't bother with case of identical constraints, to be
16518 -- fiddled with later on perhaps (this is only used for optimization
16519 -- purposes, so it is not critical to do a best possible job)
16530 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
16532 if Compile_Time_Known_Value
(Node1
)
16533 and then Compile_Time_Known_Value
(Node2
)
16534 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
16537 elsif Same_Object
(Node1
, Node2
) then
16544 -----------------------------
16545 -- Save_SPARK_Mode_And_Set --
16546 -----------------------------
16548 procedure Save_SPARK_Mode_And_Set
16549 (Context
: Entity_Id
;
16550 Mode
: out SPARK_Mode_Type
)
16553 -- Save the current mode in effect
16555 Mode
:= SPARK_Mode
;
16557 -- Do not consider illegal or partially decorated constructs
16559 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
16562 elsif Present
(SPARK_Pragma
(Context
)) then
16563 SPARK_Mode
:= Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Context
));
16565 end Save_SPARK_Mode_And_Set
;
16567 -------------------------
16568 -- Scalar_Part_Present --
16569 -------------------------
16571 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
16575 if Is_Scalar_Type
(T
) then
16578 elsif Is_Array_Type
(T
) then
16579 return Scalar_Part_Present
(Component_Type
(T
));
16581 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
16582 C
:= First_Component_Or_Discriminant
(T
);
16583 while Present
(C
) loop
16584 if Scalar_Part_Present
(Etype
(C
)) then
16587 Next_Component_Or_Discriminant
(C
);
16593 end Scalar_Part_Present
;
16595 ------------------------
16596 -- Scope_Is_Transient --
16597 ------------------------
16599 function Scope_Is_Transient
return Boolean is
16601 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
16602 end Scope_Is_Transient
;
16608 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16613 while Scop
/= Standard_Standard
loop
16614 Scop
:= Scope
(Scop
);
16616 if Scop
= Scope2
then
16624 --------------------------
16625 -- Scope_Within_Or_Same --
16626 --------------------------
16628 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16633 while Scop
/= Standard_Standard
loop
16634 if Scop
= Scope2
then
16637 Scop
:= Scope
(Scop
);
16642 end Scope_Within_Or_Same
;
16644 --------------------
16645 -- Set_Convention --
16646 --------------------
16648 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
16650 Basic_Set_Convention
(E
, Val
);
16653 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
16654 and then Has_Foreign_Convention
(E
)
16656 Set_Can_Use_Internal_Rep
(E
, False);
16659 -- If E is an object or component, and the type of E is an anonymous
16660 -- access type with no convention set, then also set the convention of
16661 -- the anonymous access type. We do not do this for anonymous protected
16662 -- types, since protected types always have the default convention.
16664 if Present
(Etype
(E
))
16665 and then (Is_Object
(E
)
16666 or else Ekind
(E
) = E_Component
16668 -- Allow E_Void (happens for pragma Convention appearing
16669 -- in the middle of a record applying to a component)
16671 or else Ekind
(E
) = E_Void
)
16674 Typ
: constant Entity_Id
:= Etype
(E
);
16677 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
16678 E_Anonymous_Access_Subprogram_Type
)
16679 and then not Has_Convention_Pragma
(Typ
)
16681 Basic_Set_Convention
(Typ
, Val
);
16682 Set_Has_Convention_Pragma
(Typ
);
16684 -- And for the access subprogram type, deal similarly with the
16685 -- designated E_Subprogram_Type if it is also internal (which
16688 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
16690 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
16692 if Ekind
(Dtype
) = E_Subprogram_Type
16693 and then Is_Itype
(Dtype
)
16694 and then not Has_Convention_Pragma
(Dtype
)
16696 Basic_Set_Convention
(Dtype
, Val
);
16697 Set_Has_Convention_Pragma
(Dtype
);
16704 end Set_Convention
;
16706 ------------------------
16707 -- Set_Current_Entity --
16708 ------------------------
16710 -- The given entity is to be set as the currently visible definition of its
16711 -- associated name (i.e. the Node_Id associated with its name). All we have
16712 -- to do is to get the name from the identifier, and then set the
16713 -- associated Node_Id to point to the given entity.
16715 procedure Set_Current_Entity
(E
: Entity_Id
) is
16717 Set_Name_Entity_Id
(Chars
(E
), E
);
16718 end Set_Current_Entity
;
16720 ---------------------------
16721 -- Set_Debug_Info_Needed --
16722 ---------------------------
16724 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
16726 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
16727 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
16728 -- Used to set debug info in a related node if not set already
16730 --------------------------------------
16731 -- Set_Debug_Info_Needed_If_Not_Set --
16732 --------------------------------------
16734 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
16736 if Present
(E
) and then not Needs_Debug_Info
(E
) then
16737 Set_Debug_Info_Needed
(E
);
16739 -- For a private type, indicate that the full view also needs
16740 -- debug information.
16743 and then Is_Private_Type
(E
)
16744 and then Present
(Full_View
(E
))
16746 Set_Debug_Info_Needed
(Full_View
(E
));
16749 end Set_Debug_Info_Needed_If_Not_Set
;
16751 -- Start of processing for Set_Debug_Info_Needed
16754 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16755 -- indicates that Debug_Info_Needed is never required for the entity.
16756 -- Nothing to do if entity comes from a predefined file. Library files
16757 -- are compiled without debug information, but inlined bodies of these
16758 -- routines may appear in user code, and debug information on them ends
16759 -- up complicating debugging the user code.
16762 or else Debug_Info_Off
(T
)
16766 elsif In_Inlined_Body
16767 and then Is_Predefined_File_Name
16768 (Unit_File_Name
(Get_Source_Unit
(Sloc
(T
))))
16770 Set_Needs_Debug_Info
(T
, False);
16773 -- Set flag in entity itself. Note that we will go through the following
16774 -- circuitry even if the flag is already set on T. That's intentional,
16775 -- it makes sure that the flag will be set in subsidiary entities.
16777 Set_Needs_Debug_Info
(T
);
16779 -- Set flag on subsidiary entities if not set already
16781 if Is_Object
(T
) then
16782 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16784 elsif Is_Type
(T
) then
16785 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16787 if Is_Record_Type
(T
) then
16789 Ent
: Entity_Id
:= First_Entity
(T
);
16791 while Present
(Ent
) loop
16792 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
16797 -- For a class wide subtype, we also need debug information
16798 -- for the equivalent type.
16800 if Ekind
(T
) = E_Class_Wide_Subtype
then
16801 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
16804 elsif Is_Array_Type
(T
) then
16805 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
16808 Indx
: Node_Id
:= First_Index
(T
);
16810 while Present
(Indx
) loop
16811 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
16812 Indx
:= Next_Index
(Indx
);
16816 -- For a packed array type, we also need debug information for
16817 -- the type used to represent the packed array. Conversely, we
16818 -- also need it for the former if we need it for the latter.
16820 if Is_Packed
(T
) then
16821 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
16824 if Is_Packed_Array_Impl_Type
(T
) then
16825 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
16828 elsif Is_Access_Type
(T
) then
16829 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
16831 elsif Is_Private_Type
(T
) then
16832 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
16834 elsif Is_Protected_Type
(T
) then
16835 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
16837 elsif Is_Scalar_Type
(T
) then
16839 -- If the subrange bounds are materialized by dedicated constant
16840 -- objects, also include them in the debug info to make sure the
16841 -- debugger can properly use them.
16843 if Present
(Scalar_Range
(T
))
16844 and then Nkind
(Scalar_Range
(T
)) = N_Range
16847 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
16848 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
16851 if Is_Entity_Name
(Low_Bnd
) then
16852 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
16855 if Is_Entity_Name
(High_Bnd
) then
16856 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
16862 end Set_Debug_Info_Needed
;
16864 ----------------------------
16865 -- Set_Entity_With_Checks --
16866 ----------------------------
16868 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
16869 Val_Actual
: Entity_Id
;
16871 Post_Node
: Node_Id
;
16874 -- Unconditionally set the entity
16876 Set_Entity
(N
, Val
);
16878 -- The node to post on is the selector in the case of an expanded name,
16879 -- and otherwise the node itself.
16881 if Nkind
(N
) = N_Expanded_Name
then
16882 Post_Node
:= Selector_Name
(N
);
16887 -- Check for violation of No_Fixed_IO
16889 if Restriction_Check_Required
(No_Fixed_IO
)
16891 ((RTU_Loaded
(Ada_Text_IO
)
16892 and then (Is_RTE
(Val
, RE_Decimal_IO
)
16894 Is_RTE
(Val
, RE_Fixed_IO
)))
16897 (RTU_Loaded
(Ada_Wide_Text_IO
)
16898 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
16900 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
16903 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
16904 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
16906 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
16908 -- A special extra check, don't complain about a reference from within
16909 -- the Ada.Interrupts package itself!
16911 and then not In_Same_Extended_Unit
(N
, Val
)
16913 Check_Restriction
(No_Fixed_IO
, Post_Node
);
16916 -- Remaining checks are only done on source nodes. Note that we test
16917 -- for violation of No_Fixed_IO even on non-source nodes, because the
16918 -- cases for checking violations of this restriction are instantiations
16919 -- where the reference in the instance has Comes_From_Source False.
16921 if not Comes_From_Source
(N
) then
16925 -- Check for violation of No_Abort_Statements, which is triggered by
16926 -- call to Ada.Task_Identification.Abort_Task.
16928 if Restriction_Check_Required
(No_Abort_Statements
)
16929 and then (Is_RTE
(Val
, RE_Abort_Task
))
16931 -- A special extra check, don't complain about a reference from within
16932 -- the Ada.Task_Identification package itself!
16934 and then not In_Same_Extended_Unit
(N
, Val
)
16936 Check_Restriction
(No_Abort_Statements
, Post_Node
);
16939 if Val
= Standard_Long_Long_Integer
then
16940 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
16943 -- Check for violation of No_Dynamic_Attachment
16945 if Restriction_Check_Required
(No_Dynamic_Attachment
)
16946 and then RTU_Loaded
(Ada_Interrupts
)
16947 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
16948 Is_RTE
(Val
, RE_Is_Attached
) or else
16949 Is_RTE
(Val
, RE_Current_Handler
) or else
16950 Is_RTE
(Val
, RE_Attach_Handler
) or else
16951 Is_RTE
(Val
, RE_Exchange_Handler
) or else
16952 Is_RTE
(Val
, RE_Detach_Handler
) or else
16953 Is_RTE
(Val
, RE_Reference
))
16955 -- A special extra check, don't complain about a reference from within
16956 -- the Ada.Interrupts package itself!
16958 and then not In_Same_Extended_Unit
(N
, Val
)
16960 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
16963 -- Check for No_Implementation_Identifiers
16965 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
16967 -- We have an implementation defined entity if it is marked as
16968 -- implementation defined, or is defined in a package marked as
16969 -- implementation defined. However, library packages themselves
16970 -- are excluded (we don't want to flag Interfaces itself, just
16971 -- the entities within it).
16973 if (Is_Implementation_Defined
(Val
)
16975 (Present
(Scope
(Val
))
16976 and then Is_Implementation_Defined
(Scope
(Val
))))
16977 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
16978 and then Is_Library_Level_Entity
(Val
))
16980 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
16984 -- Do the style check
16987 and then not Suppress_Style_Checks
(Val
)
16988 and then not In_Instance
16990 if Nkind
(N
) = N_Identifier
then
16992 elsif Nkind
(N
) = N_Expanded_Name
then
16993 Nod
:= Selector_Name
(N
);
16998 -- A special situation arises for derived operations, where we want
16999 -- to do the check against the parent (since the Sloc of the derived
17000 -- operation points to the derived type declaration itself).
17003 while not Comes_From_Source
(Val_Actual
)
17004 and then Nkind
(Val_Actual
) in N_Entity
17005 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
17006 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
17007 and then Present
(Alias
(Val_Actual
))
17009 Val_Actual
:= Alias
(Val_Actual
);
17012 -- Renaming declarations for generic actuals do not come from source,
17013 -- and have a different name from that of the entity they rename, so
17014 -- there is no style check to perform here.
17016 if Chars
(Nod
) = Chars
(Val_Actual
) then
17017 Style
.Check_Identifier
(Nod
, Val_Actual
);
17021 Set_Entity
(N
, Val
);
17022 end Set_Entity_With_Checks
;
17024 ------------------------
17025 -- Set_Name_Entity_Id --
17026 ------------------------
17028 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
17030 Set_Name_Table_Int
(Id
, Int
(Val
));
17031 end Set_Name_Entity_Id
;
17033 ---------------------
17034 -- Set_Next_Actual --
17035 ---------------------
17037 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
17039 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
17040 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
17042 end Set_Next_Actual
;
17044 ----------------------------------
17045 -- Set_Optimize_Alignment_Flags --
17046 ----------------------------------
17048 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
17050 if Optimize_Alignment
= 'S' then
17051 Set_Optimize_Alignment_Space
(E
);
17052 elsif Optimize_Alignment
= 'T' then
17053 Set_Optimize_Alignment_Time
(E
);
17055 end Set_Optimize_Alignment_Flags
;
17057 -----------------------
17058 -- Set_Public_Status --
17059 -----------------------
17061 procedure Set_Public_Status
(Id
: Entity_Id
) is
17062 S
: constant Entity_Id
:= Current_Scope
;
17064 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
17065 -- Determines if E is defined within handled statement sequence or
17066 -- an if statement, returns True if so, False otherwise.
17068 ----------------------
17069 -- Within_HSS_Or_If --
17070 ----------------------
17072 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
17075 N
:= Declaration_Node
(E
);
17082 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
17088 end Within_HSS_Or_If
;
17090 -- Start of processing for Set_Public_Status
17093 -- Everything in the scope of Standard is public
17095 if S
= Standard_Standard
then
17096 Set_Is_Public
(Id
);
17098 -- Entity is definitely not public if enclosing scope is not public
17100 elsif not Is_Public
(S
) then
17103 -- An object or function declaration that occurs in a handled sequence
17104 -- of statements or within an if statement is the declaration for a
17105 -- temporary object or local subprogram generated by the expander. It
17106 -- never needs to be made public and furthermore, making it public can
17107 -- cause back end problems.
17109 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
17110 N_Function_Specification
)
17111 and then Within_HSS_Or_If
(Id
)
17115 -- Entities in public packages or records are public
17117 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
17118 Set_Is_Public
(Id
);
17120 -- The bounds of an entry family declaration can generate object
17121 -- declarations that are visible to the back-end, e.g. in the
17122 -- the declaration of a composite type that contains tasks.
17124 elsif Is_Concurrent_Type
(S
)
17125 and then not Has_Completion
(S
)
17126 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
17128 Set_Is_Public
(Id
);
17130 end Set_Public_Status
;
17132 -----------------------------
17133 -- Set_Referenced_Modified --
17134 -----------------------------
17136 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
17140 -- Deal with indexed or selected component where prefix is modified
17142 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
17143 Pref
:= Prefix
(N
);
17145 -- If prefix is access type, then it is the designated object that is
17146 -- being modified, which means we have no entity to set the flag on.
17148 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
17151 -- Otherwise chase the prefix
17154 Set_Referenced_Modified
(Pref
, Out_Param
);
17157 -- Otherwise see if we have an entity name (only other case to process)
17159 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
17160 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
17161 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
17163 end Set_Referenced_Modified
;
17165 ----------------------------
17166 -- Set_Scope_Is_Transient --
17167 ----------------------------
17169 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
17171 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
17172 end Set_Scope_Is_Transient
;
17174 -------------------
17175 -- Set_Size_Info --
17176 -------------------
17178 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
17180 -- We copy Esize, but not RM_Size, since in general RM_Size is
17181 -- subtype specific and does not get inherited by all subtypes.
17183 Set_Esize
(T1
, Esize
(T2
));
17184 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
17186 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
17188 Is_Discrete_Or_Fixed_Point_Type
(T2
)
17190 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
17193 Set_Alignment
(T1
, Alignment
(T2
));
17196 --------------------
17197 -- Static_Boolean --
17198 --------------------
17200 function Static_Boolean
(N
: Node_Id
) return Uint
is
17202 Analyze_And_Resolve
(N
, Standard_Boolean
);
17205 or else Error_Posted
(N
)
17206 or else Etype
(N
) = Any_Type
17211 if Is_OK_Static_Expression
(N
) then
17212 if not Raises_Constraint_Error
(N
) then
17213 return Expr_Value
(N
);
17218 elsif Etype
(N
) = Any_Type
then
17222 Flag_Non_Static_Expr
17223 ("static boolean expression required here", N
);
17226 end Static_Boolean
;
17228 --------------------
17229 -- Static_Integer --
17230 --------------------
17232 function Static_Integer
(N
: Node_Id
) return Uint
is
17234 Analyze_And_Resolve
(N
, Any_Integer
);
17237 or else Error_Posted
(N
)
17238 or else Etype
(N
) = Any_Type
17243 if Is_OK_Static_Expression
(N
) then
17244 if not Raises_Constraint_Error
(N
) then
17245 return Expr_Value
(N
);
17250 elsif Etype
(N
) = Any_Type
then
17254 Flag_Non_Static_Expr
17255 ("static integer expression required here", N
);
17258 end Static_Integer
;
17260 --------------------------
17261 -- Statically_Different --
17262 --------------------------
17264 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
17265 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
17266 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
17268 return Is_Entity_Name
(R1
)
17269 and then Is_Entity_Name
(R2
)
17270 and then Entity
(R1
) /= Entity
(R2
)
17271 and then not Is_Formal
(Entity
(R1
))
17272 and then not Is_Formal
(Entity
(R2
));
17273 end Statically_Different
;
17275 --------------------------------------
17276 -- Subject_To_Loop_Entry_Attributes --
17277 --------------------------------------
17279 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
17285 -- The expansion mechanism transform a loop subject to at least one
17286 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
17287 -- the conditional part.
17289 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
17290 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
17292 Stmt
:= Original_Node
(N
);
17296 Nkind
(Stmt
) = N_Loop_Statement
17297 and then Present
(Identifier
(Stmt
))
17298 and then Present
(Entity
(Identifier
(Stmt
)))
17299 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
17300 end Subject_To_Loop_Entry_Attributes
;
17302 -----------------------------
17303 -- Subprogram_Access_Level --
17304 -----------------------------
17306 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
17308 if Present
(Alias
(Subp
)) then
17309 return Subprogram_Access_Level
(Alias
(Subp
));
17311 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
17313 end Subprogram_Access_Level
;
17315 -------------------------------
17316 -- Support_Atomic_Primitives --
17317 -------------------------------
17319 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
17323 -- Verify the alignment of Typ is known
17325 if not Known_Alignment
(Typ
) then
17329 if Known_Static_Esize
(Typ
) then
17330 Size
:= UI_To_Int
(Esize
(Typ
));
17332 -- If the Esize (Object_Size) is unknown at compile time, look at the
17333 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
17335 elsif Known_Static_RM_Size
(Typ
) then
17336 Size
:= UI_To_Int
(RM_Size
(Typ
));
17338 -- Otherwise, the size is considered to be unknown.
17344 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
17345 -- Typ is properly aligned.
17348 when 8 |
16 |
32 |
64 =>
17349 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
17353 end Support_Atomic_Primitives
;
17359 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
17361 if Debug_Flag_W
then
17362 for J
in 0 .. Scope_Stack
.Last
loop
17367 Write_Name
(Chars
(E
));
17368 Write_Str
(" from ");
17369 Write_Location
(Sloc
(N
));
17374 -----------------------
17375 -- Transfer_Entities --
17376 -----------------------
17378 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
17379 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
17380 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
17381 -- Set_Public_Status. If successfull and Id denotes a record type, set
17382 -- the Is_Public attribute of its fields.
17384 --------------------------
17385 -- Set_Public_Status_Of --
17386 --------------------------
17388 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
17392 if not Is_Public
(Id
) then
17393 Set_Public_Status
(Id
);
17395 -- When the input entity is a public record type, ensure that all
17396 -- its internal fields are also exposed to the linker. The fields
17397 -- of a class-wide type are never made public.
17400 and then Is_Record_Type
(Id
)
17401 and then not Is_Class_Wide_Type
(Id
)
17403 Field
:= First_Entity
(Id
);
17404 while Present
(Field
) loop
17405 Set_Is_Public
(Field
);
17406 Next_Entity
(Field
);
17410 end Set_Public_Status_Of
;
17414 Full_Id
: Entity_Id
;
17417 -- Start of processing for Transfer_Entities
17420 Id
:= First_Entity
(From
);
17422 if Present
(Id
) then
17424 -- Merge the entity chain of the source scope with that of the
17425 -- destination scope.
17427 if Present
(Last_Entity
(To
)) then
17428 Set_Next_Entity
(Last_Entity
(To
), Id
);
17430 Set_First_Entity
(To
, Id
);
17433 Set_Last_Entity
(To
, Last_Entity
(From
));
17435 -- Inspect the entities of the source scope and update their Scope
17438 while Present
(Id
) loop
17439 Set_Scope
(Id
, To
);
17440 Set_Public_Status_Of
(Id
);
17442 -- Handle an internally generated full view for a private type
17444 if Is_Private_Type
(Id
)
17445 and then Present
(Full_View
(Id
))
17446 and then Is_Itype
(Full_View
(Id
))
17448 Full_Id
:= Full_View
(Id
);
17450 Set_Scope
(Full_Id
, To
);
17451 Set_Public_Status_Of
(Full_Id
);
17457 Set_First_Entity
(From
, Empty
);
17458 Set_Last_Entity
(From
, Empty
);
17460 end Transfer_Entities
;
17462 -----------------------
17463 -- Type_Access_Level --
17464 -----------------------
17466 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
17470 Btyp
:= Base_Type
(Typ
);
17472 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
17473 -- simply use the level where the type is declared. This is true for
17474 -- stand-alone object declarations, and for anonymous access types
17475 -- associated with components the level is the same as that of the
17476 -- enclosing composite type. However, special treatment is needed for
17477 -- the cases of access parameters, return objects of an anonymous access
17478 -- type, and, in Ada 95, access discriminants of limited types.
17480 if Is_Access_Type
(Btyp
) then
17481 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
17483 -- If the type is a nonlocal anonymous access type (such as for
17484 -- an access parameter) we treat it as being declared at the
17485 -- library level to ensure that names such as X.all'access don't
17486 -- fail static accessibility checks.
17488 if not Is_Local_Anonymous_Access
(Typ
) then
17489 return Scope_Depth
(Standard_Standard
);
17491 -- If this is a return object, the accessibility level is that of
17492 -- the result subtype of the enclosing function. The test here is
17493 -- little complicated, because we have to account for extended
17494 -- return statements that have been rewritten as blocks, in which
17495 -- case we have to find and the Is_Return_Object attribute of the
17496 -- itype's associated object. It would be nice to find a way to
17497 -- simplify this test, but it doesn't seem worthwhile to add a new
17498 -- flag just for purposes of this test. ???
17500 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
17503 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
17504 N_Object_Declaration
17505 and then Is_Return_Object
17506 (Defining_Identifier
17507 (Associated_Node_For_Itype
(Btyp
))))
17513 Scop
:= Scope
(Scope
(Btyp
));
17514 while Present
(Scop
) loop
17515 exit when Ekind
(Scop
) = E_Function
;
17516 Scop
:= Scope
(Scop
);
17519 -- Treat the return object's type as having the level of the
17520 -- function's result subtype (as per RM05-6.5(5.3/2)).
17522 return Type_Access_Level
(Etype
(Scop
));
17527 Btyp
:= Root_Type
(Btyp
);
17529 -- The accessibility level of anonymous access types associated with
17530 -- discriminants is that of the current instance of the type, and
17531 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
17533 -- AI-402: access discriminants have accessibility based on the
17534 -- object rather than the type in Ada 2005, so the above paragraph
17537 -- ??? Needs completion with rules from AI-416
17539 if Ada_Version
<= Ada_95
17540 and then Ekind
(Typ
) = E_Anonymous_Access_Type
17541 and then Present
(Associated_Node_For_Itype
(Typ
))
17542 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
17543 N_Discriminant_Specification
17545 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
17549 -- Return library level for a generic formal type. This is done because
17550 -- RM(10.3.2) says that "The statically deeper relationship does not
17551 -- apply to ... a descendant of a generic formal type". Rather than
17552 -- checking at each point where a static accessibility check is
17553 -- performed to see if we are dealing with a formal type, this rule is
17554 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17555 -- return extreme values for a formal type; Deepest_Type_Access_Level
17556 -- returns Int'Last. By calling the appropriate function from among the
17557 -- two, we ensure that the static accessibility check will pass if we
17558 -- happen to run into a formal type. More specifically, we should call
17559 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17560 -- call occurs as part of a static accessibility check and the error
17561 -- case is the case where the type's level is too shallow (as opposed
17564 if Is_Generic_Type
(Root_Type
(Btyp
)) then
17565 return Scope_Depth
(Standard_Standard
);
17568 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
17569 end Type_Access_Level
;
17571 ------------------------------------
17572 -- Type_Without_Stream_Operation --
17573 ------------------------------------
17575 function Type_Without_Stream_Operation
17577 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
17579 BT
: constant Entity_Id
:= Base_Type
(T
);
17580 Op_Missing
: Boolean;
17583 if not Restriction_Active
(No_Default_Stream_Attributes
) then
17587 if Is_Elementary_Type
(T
) then
17588 if Op
= TSS_Null
then
17590 No
(TSS
(BT
, TSS_Stream_Read
))
17591 or else No
(TSS
(BT
, TSS_Stream_Write
));
17594 Op_Missing
:= No
(TSS
(BT
, Op
));
17603 elsif Is_Array_Type
(T
) then
17604 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
17606 elsif Is_Record_Type
(T
) then
17612 Comp
:= First_Component
(T
);
17613 while Present
(Comp
) loop
17614 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
17616 if Present
(C_Typ
) then
17620 Next_Component
(Comp
);
17626 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
17627 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
17631 end Type_Without_Stream_Operation
;
17633 ----------------------------
17634 -- Unique_Defining_Entity --
17635 ----------------------------
17637 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
17639 return Unique_Entity
(Defining_Entity
(N
));
17640 end Unique_Defining_Entity
;
17642 -------------------
17643 -- Unique_Entity --
17644 -------------------
17646 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
17647 U
: Entity_Id
:= E
;
17653 if Present
(Full_View
(E
)) then
17654 U
:= Full_View
(E
);
17658 if Present
(Full_View
(E
)) then
17659 U
:= Full_View
(E
);
17662 when E_Package_Body
=>
17665 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17669 U
:= Corresponding_Spec
(P
);
17671 when E_Subprogram_Body
=>
17674 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17680 if Nkind
(P
) = N_Subprogram_Body_Stub
then
17681 if Present
(Library_Unit
(P
)) then
17683 -- Get to the function or procedure (generic) entity through
17684 -- the body entity.
17687 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
17690 U
:= Corresponding_Spec
(P
);
17693 when Formal_Kind
=>
17694 if Present
(Spec_Entity
(E
)) then
17695 U
:= Spec_Entity
(E
);
17709 function Unique_Name
(E
: Entity_Id
) return String is
17711 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17712 -- reliable, as they may not include the overloading suffix. Instead,
17713 -- when looking for the name of E or one of its enclosing scope, we get
17714 -- the name of the corresponding Unique_Entity.
17716 function Get_Scoped_Name
(E
: Entity_Id
) return String;
17717 -- Return the name of E prefixed by all the names of the scopes to which
17718 -- E belongs, except for Standard.
17720 ---------------------
17721 -- Get_Scoped_Name --
17722 ---------------------
17724 function Get_Scoped_Name
(E
: Entity_Id
) return String is
17725 Name
: constant String := Get_Name_String
(Chars
(E
));
17727 if Has_Fully_Qualified_Name
(E
)
17728 or else Scope
(E
) = Standard_Standard
17732 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
17734 end Get_Scoped_Name
;
17736 -- Start of processing for Unique_Name
17739 if E
= Standard_Standard
then
17740 return Get_Name_String
(Name_Standard
);
17742 elsif Scope
(E
) = Standard_Standard
17743 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
17745 return Get_Name_String
(Name_Standard
) & "__" &
17746 Get_Name_String
(Chars
(E
));
17748 elsif Ekind
(E
) = E_Enumeration_Literal
then
17749 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
17752 return Get_Scoped_Name
(Unique_Entity
(E
));
17756 ---------------------
17757 -- Unit_Is_Visible --
17758 ---------------------
17760 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
17761 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
17762 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
17764 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
17765 -- For a child unit, check whether unit appears in a with_clause
17768 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
17769 -- Scan the context clause of one compilation unit looking for a
17770 -- with_clause for the unit in question.
17772 ----------------------------
17773 -- Unit_In_Parent_Context --
17774 ----------------------------
17776 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
17778 if Unit_In_Context
(Par_Unit
) then
17781 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
17782 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
17787 end Unit_In_Parent_Context
;
17789 ---------------------
17790 -- Unit_In_Context --
17791 ---------------------
17793 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
17797 Clause
:= First
(Context_Items
(Comp_Unit
));
17798 while Present
(Clause
) loop
17799 if Nkind
(Clause
) = N_With_Clause
then
17800 if Library_Unit
(Clause
) = U
then
17803 -- The with_clause may denote a renaming of the unit we are
17804 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17807 Renamed_Entity
(Entity
(Name
(Clause
))) =
17808 Defining_Entity
(Unit
(U
))
17818 end Unit_In_Context
;
17820 -- Start of processing for Unit_Is_Visible
17823 -- The currrent unit is directly visible
17828 elsif Unit_In_Context
(Curr
) then
17831 -- If the current unit is a body, check the context of the spec
17833 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
17835 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
17836 and then not Acts_As_Spec
(Unit
(Curr
)))
17838 if Unit_In_Context
(Library_Unit
(Curr
)) then
17843 -- If the spec is a child unit, examine the parents
17845 if Is_Child_Unit
(Curr_Entity
) then
17846 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
17848 Unit_In_Parent_Context
17849 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
17851 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
17857 end Unit_Is_Visible
;
17859 ------------------------------
17860 -- Universal_Interpretation --
17861 ------------------------------
17863 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
17864 Index
: Interp_Index
;
17868 -- The argument may be a formal parameter of an operator or subprogram
17869 -- with multiple interpretations, or else an expression for an actual.
17871 if Nkind
(Opnd
) = N_Defining_Identifier
17872 or else not Is_Overloaded
(Opnd
)
17874 if Etype
(Opnd
) = Universal_Integer
17875 or else Etype
(Opnd
) = Universal_Real
17877 return Etype
(Opnd
);
17883 Get_First_Interp
(Opnd
, Index
, It
);
17884 while Present
(It
.Typ
) loop
17885 if It
.Typ
= Universal_Integer
17886 or else It
.Typ
= Universal_Real
17891 Get_Next_Interp
(Index
, It
);
17896 end Universal_Interpretation
;
17902 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
17904 -- Recurse to handle unlikely case of multiple levels of qualification
17906 if Nkind
(Expr
) = N_Qualified_Expression
then
17907 return Unqualify
(Expression
(Expr
));
17909 -- Normal case, not a qualified expression
17916 -----------------------
17917 -- Visible_Ancestors --
17918 -----------------------
17920 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
17926 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
17928 -- Collect all the parents and progenitors of Typ. If the full-view of
17929 -- private parents and progenitors is available then it is used to
17930 -- generate the list of visible ancestors; otherwise their partial
17931 -- view is added to the resulting list.
17936 Use_Full_View
=> True);
17940 Ifaces_List
=> List_2
,
17941 Exclude_Parents
=> True,
17942 Use_Full_View
=> True);
17944 -- Join the two lists. Avoid duplications because an interface may
17945 -- simultaneously be parent and progenitor of a type.
17947 Elmt
:= First_Elmt
(List_2
);
17948 while Present
(Elmt
) loop
17949 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
17954 end Visible_Ancestors
;
17956 ----------------------
17957 -- Within_Init_Proc --
17958 ----------------------
17960 function Within_Init_Proc
return Boolean is
17964 S
:= Current_Scope
;
17965 while not Is_Overloadable
(S
) loop
17966 if S
= Standard_Standard
then
17973 return Is_Init_Proc
(S
);
17974 end Within_Init_Proc
;
17980 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
17987 elsif SE
= Standard_Standard
then
17999 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
18000 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
18001 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
18003 Matching_Field
: Entity_Id
;
18004 -- Entity to give a more precise suggestion on how to write a one-
18005 -- element positional aggregate.
18007 function Has_One_Matching_Field
return Boolean;
18008 -- Determines if Expec_Type is a record type with a single component or
18009 -- discriminant whose type matches the found type or is one dimensional
18010 -- array whose component type matches the found type. In the case of
18011 -- one discriminant, we ignore the variant parts. That's not accurate,
18012 -- but good enough for the warning.
18014 ----------------------------
18015 -- Has_One_Matching_Field --
18016 ----------------------------
18018 function Has_One_Matching_Field
return Boolean is
18022 Matching_Field
:= Empty
;
18024 if Is_Array_Type
(Expec_Type
)
18025 and then Number_Dimensions
(Expec_Type
) = 1
18026 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
18028 -- Use type name if available. This excludes multidimensional
18029 -- arrays and anonymous arrays.
18031 if Comes_From_Source
(Expec_Type
) then
18032 Matching_Field
:= Expec_Type
;
18034 -- For an assignment, use name of target
18036 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
18037 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
18039 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
18044 elsif not Is_Record_Type
(Expec_Type
) then
18048 E
:= First_Entity
(Expec_Type
);
18053 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
18054 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
18063 if not Covers
(Etype
(E
), Found_Type
) then
18066 elsif Present
(Next_Entity
(E
))
18067 and then (Ekind
(E
) = E_Component
18068 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
18073 Matching_Field
:= E
;
18077 end Has_One_Matching_Field
;
18079 -- Start of processing for Wrong_Type
18082 -- Don't output message if either type is Any_Type, or if a message
18083 -- has already been posted for this node. We need to do the latter
18084 -- check explicitly (it is ordinarily done in Errout), because we
18085 -- are using ! to force the output of the error messages.
18087 if Expec_Type
= Any_Type
18088 or else Found_Type
= Any_Type
18089 or else Error_Posted
(Expr
)
18093 -- If one of the types is a Taft-Amendment type and the other it its
18094 -- completion, it must be an illegal use of a TAT in the spec, for
18095 -- which an error was already emitted. Avoid cascaded errors.
18097 elsif Is_Incomplete_Type
(Expec_Type
)
18098 and then Has_Completion_In_Body
(Expec_Type
)
18099 and then Full_View
(Expec_Type
) = Etype
(Expr
)
18103 elsif Is_Incomplete_Type
(Etype
(Expr
))
18104 and then Has_Completion_In_Body
(Etype
(Expr
))
18105 and then Full_View
(Etype
(Expr
)) = Expec_Type
18109 -- In an instance, there is an ongoing problem with completion of
18110 -- type derived from private types. Their structure is what Gigi
18111 -- expects, but the Etype is the parent type rather than the
18112 -- derived private type itself. Do not flag error in this case. The
18113 -- private completion is an entity without a parent, like an Itype.
18114 -- Similarly, full and partial views may be incorrect in the instance.
18115 -- There is no simple way to insure that it is consistent ???
18117 -- A similar view discrepancy can happen in an inlined body, for the
18118 -- same reason: inserted body may be outside of the original package
18119 -- and only partial views are visible at the point of insertion.
18121 elsif In_Instance
or else In_Inlined_Body
then
18122 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
18124 (Has_Private_Declaration
(Expected_Type
)
18125 or else Has_Private_Declaration
(Etype
(Expr
)))
18126 and then No
(Parent
(Expected_Type
))
18130 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
18131 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
18135 elsif Is_Private_Type
(Expected_Type
)
18136 and then Present
(Full_View
(Expected_Type
))
18137 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
18143 -- An interesting special check. If the expression is parenthesized
18144 -- and its type corresponds to the type of the sole component of the
18145 -- expected record type, or to the component type of the expected one
18146 -- dimensional array type, then assume we have a bad aggregate attempt.
18148 if Nkind
(Expr
) in N_Subexpr
18149 and then Paren_Count
(Expr
) /= 0
18150 and then Has_One_Matching_Field
18152 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
18153 if Present
(Matching_Field
) then
18154 if Is_Array_Type
(Expec_Type
) then
18156 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
18160 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
18164 -- Another special check, if we are looking for a pool-specific access
18165 -- type and we found an E_Access_Attribute_Type, then we have the case
18166 -- of an Access attribute being used in a context which needs a pool-
18167 -- specific type, which is never allowed. The one extra check we make
18168 -- is that the expected designated type covers the Found_Type.
18170 elsif Is_Access_Type
(Expec_Type
)
18171 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
18172 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
18173 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
18175 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
18177 Error_Msg_N
-- CODEFIX
18178 ("result must be general access type!", Expr
);
18179 Error_Msg_NE
-- CODEFIX
18180 ("add ALL to }!", Expr
, Expec_Type
);
18182 -- Another special check, if the expected type is an integer type,
18183 -- but the expression is of type System.Address, and the parent is
18184 -- an addition or subtraction operation whose left operand is the
18185 -- expression in question and whose right operand is of an integral
18186 -- type, then this is an attempt at address arithmetic, so give
18187 -- appropriate message.
18189 elsif Is_Integer_Type
(Expec_Type
)
18190 and then Is_RTE
(Found_Type
, RE_Address
)
18191 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
18192 and then Expr
= Left_Opnd
(Parent
(Expr
))
18193 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
18196 ("address arithmetic not predefined in package System",
18199 ("\possible missing with/use of System.Storage_Elements",
18203 -- If the expected type is an anonymous access type, as for access
18204 -- parameters and discriminants, the error is on the designated types.
18206 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
18207 if Comes_From_Source
(Expec_Type
) then
18208 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
18211 ("expected an access type with designated}",
18212 Expr
, Designated_Type
(Expec_Type
));
18215 if Is_Access_Type
(Found_Type
)
18216 and then not Comes_From_Source
(Found_Type
)
18219 ("\\found an access type with designated}!",
18220 Expr
, Designated_Type
(Found_Type
));
18222 if From_Limited_With
(Found_Type
) then
18223 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
18224 Error_Msg_Qual_Level
:= 99;
18225 Error_Msg_NE
-- CODEFIX
18226 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
18227 Error_Msg_Qual_Level
:= 0;
18229 Error_Msg_NE
("found}!", Expr
, Found_Type
);
18233 -- Normal case of one type found, some other type expected
18236 -- If the names of the two types are the same, see if some number
18237 -- of levels of qualification will help. Don't try more than three
18238 -- levels, and if we get to standard, it's no use (and probably
18239 -- represents an error in the compiler) Also do not bother with
18240 -- internal scope names.
18243 Expec_Scope
: Entity_Id
;
18244 Found_Scope
: Entity_Id
;
18247 Expec_Scope
:= Expec_Type
;
18248 Found_Scope
:= Found_Type
;
18250 for Levels
in Int
range 0 .. 3 loop
18251 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
18252 Error_Msg_Qual_Level
:= Levels
;
18256 Expec_Scope
:= Scope
(Expec_Scope
);
18257 Found_Scope
:= Scope
(Found_Scope
);
18259 exit when Expec_Scope
= Standard_Standard
18260 or else Found_Scope
= Standard_Standard
18261 or else not Comes_From_Source
(Expec_Scope
)
18262 or else not Comes_From_Source
(Found_Scope
);
18266 if Is_Record_Type
(Expec_Type
)
18267 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
18269 Error_Msg_NE
("expected}!", Expr
,
18270 Corresponding_Remote_Type
(Expec_Type
));
18272 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
18275 if Is_Entity_Name
(Expr
)
18276 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
18278 Error_Msg_N
("\\found package name!", Expr
);
18280 elsif Is_Entity_Name
(Expr
)
18281 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
18283 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
18285 ("found procedure name, possibly missing Access attribute!",
18289 ("\\found procedure name instead of function!", Expr
);
18292 elsif Nkind
(Expr
) = N_Function_Call
18293 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
18294 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
18295 and then No
(Parameter_Associations
(Expr
))
18298 ("found function name, possibly missing Access attribute!",
18301 -- Catch common error: a prefix or infix operator which is not
18302 -- directly visible because the type isn't.
18304 elsif Nkind
(Expr
) in N_Op
18305 and then Is_Overloaded
(Expr
)
18306 and then not Is_Immediately_Visible
(Expec_Type
)
18307 and then not Is_Potentially_Use_Visible
(Expec_Type
)
18308 and then not In_Use
(Expec_Type
)
18309 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
18312 ("operator of the type is not directly visible!", Expr
);
18314 elsif Ekind
(Found_Type
) = E_Void
18315 and then Present
(Parent
(Found_Type
))
18316 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
18318 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
18321 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
18324 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
18325 -- of the same modular type, and (M1 and M2) = 0 was intended.
18327 if Expec_Type
= Standard_Boolean
18328 and then Is_Modular_Integer_Type
(Found_Type
)
18329 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
18330 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
18333 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
18334 L
: constant Node_Id
:= Left_Opnd
(Op
);
18335 R
: constant Node_Id
:= Right_Opnd
(Op
);
18338 -- The case for the message is when the left operand of the
18339 -- comparison is the same modular type, or when it is an
18340 -- integer literal (or other universal integer expression),
18341 -- which would have been typed as the modular type if the
18342 -- parens had been there.
18344 if (Etype
(L
) = Found_Type
18346 Etype
(L
) = Universal_Integer
)
18347 and then Is_Integer_Type
(Etype
(R
))
18350 ("\\possible missing parens for modular operation", Expr
);
18355 -- Reset error message qualification indication
18357 Error_Msg_Qual_Level
:= 0;