1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2014, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Util
; use Exp_Util
;
36 with Fname
; use Fname
;
37 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
.Sp
; use Namet
.Sp
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
43 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Attr
; use Sem_Attr
;
50 with Sem_Ch8
; use Sem_Ch8
;
51 with Sem_Ch13
; use Sem_Ch13
;
52 with Sem_Disp
; use Sem_Disp
;
53 with Sem_Eval
; use Sem_Eval
;
54 with Sem_Prag
; use Sem_Prag
;
55 with Sem_Res
; use Sem_Res
;
56 with Sem_Warn
; use Sem_Warn
;
57 with Sem_Type
; use Sem_Type
;
58 with Sinfo
; use Sinfo
;
59 with Sinput
; use Sinput
;
60 with Stand
; use Stand
;
62 with Stringt
; use Stringt
;
63 with Targparm
; use Targparm
;
64 with Tbuild
; use Tbuild
;
65 with Ttypes
; use Ttypes
;
66 with Uname
; use Uname
;
68 with GNAT
.HTable
; use GNAT
.HTable
;
70 package body Sem_Util
is
72 ----------------------------------------
73 -- Global_Variables for New_Copy_Tree --
74 ----------------------------------------
76 -- These global variables are used by New_Copy_Tree. See description of the
77 -- body of this subprogram for details. Global variables can be safely used
78 -- by New_Copy_Tree, since there is no case of a recursive call from the
79 -- processing inside New_Copy_Tree.
81 NCT_Hash_Threshold
: constant := 20;
82 -- If there are more than this number of pairs of entries in the map, then
83 -- Hash_Tables_Used will be set, and the hash tables will be initialized
84 -- and used for the searches.
86 NCT_Hash_Tables_Used
: Boolean := False;
87 -- Set to True if hash tables are in use
89 NCT_Table_Entries
: Nat
:= 0;
90 -- Count entries in table to see if threshold is reached
92 NCT_Hash_Table_Setup
: Boolean := False;
93 -- Set to True if hash table contains data. We set this True if we setup
94 -- the hash table with data, and leave it set permanently from then on,
95 -- this is a signal that second and subsequent users of the hash table
96 -- must clear the old entries before reuse.
98 subtype NCT_Header_Num
is Int
range 0 .. 511;
99 -- Defines range of headers in hash tables (512 headers)
101 -----------------------
102 -- Local Subprograms --
103 -----------------------
105 function Build_Component_Subtype
108 T
: Entity_Id
) return Node_Id
;
109 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
110 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
111 -- Loc is the source location, T is the original subtype.
113 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
114 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
115 -- with discriminants whose default values are static, examine only the
116 -- components in the selected variant to determine whether all of them
119 function Has_Enabled_Property
120 (Item_Id
: Entity_Id
;
121 Property
: Name_Id
) return Boolean;
122 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
123 -- Determine whether an abstract state or a variable denoted by entity
124 -- Item_Id has enabled property Property.
126 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
127 -- T is a derived tagged type. Check whether the type extension is null.
128 -- If the parent type is fully initialized, T can be treated as such.
130 ------------------------------
131 -- Abstract_Interface_List --
132 ------------------------------
134 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
138 if Is_Concurrent_Type
(Typ
) then
140 -- If we are dealing with a synchronized subtype, go to the base
141 -- type, whose declaration has the interface list.
143 -- Shouldn't this be Declaration_Node???
145 Nod
:= Parent
(Base_Type
(Typ
));
147 if Nkind
(Nod
) = N_Full_Type_Declaration
then
151 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
152 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
153 Nod
:= Type_Definition
(Parent
(Typ
));
155 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
156 if Present
(Full_View
(Typ
))
158 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
160 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
162 -- If the full-view is not available we cannot do anything else
163 -- here (the source has errors).
169 -- Support for generic formals with interfaces is still missing ???
171 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
176 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
180 elsif Ekind
(Typ
) = E_Record_Subtype
then
181 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
183 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
185 -- Recurse, because parent may still be a private extension. Also
186 -- note that the full view of the subtype or the full view of its
187 -- base type may (both) be unavailable.
189 return Abstract_Interface_List
(Etype
(Typ
));
191 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
192 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
193 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
195 Nod
:= Type_Definition
(Parent
(Typ
));
199 return Interface_List
(Nod
);
200 end Abstract_Interface_List
;
202 --------------------------------
203 -- Add_Access_Type_To_Process --
204 --------------------------------
206 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
210 Ensure_Freeze_Node
(E
);
211 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
215 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
219 end Add_Access_Type_To_Process
;
221 --------------------------
222 -- Add_Block_Identifier --
223 --------------------------
225 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
226 Loc
: constant Source_Ptr
:= Sloc
(N
);
229 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
231 -- The block already has a label, return its entity
233 if Present
(Identifier
(N
)) then
234 Id
:= Entity
(Identifier
(N
));
236 -- Create a new block label and set its attributes
239 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
240 Set_Etype
(Id
, Standard_Void_Type
);
243 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
244 Set_Block_Node
(Id
, Identifier
(N
));
246 end Add_Block_Identifier
;
248 -----------------------
249 -- Add_Contract_Item --
250 -----------------------
252 procedure Add_Contract_Item
(Prag
: Node_Id
; Id
: Entity_Id
) is
253 Items
: constant Node_Id
:= Contract
(Id
);
258 -- The related context must have a contract and the item to be added
261 pragma Assert
(Present
(Items
));
262 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
264 Nam
:= Original_Aspect_Name
(Prag
);
266 -- Contract items related to [generic] packages or instantiations. The
267 -- applicable pragmas are:
271 -- Part_Of (instantiation only)
273 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
274 if Nam_In
(Nam
, Name_Abstract_State
,
275 Name_Initial_Condition
,
278 Set_Next_Pragma
(Prag
, Classifications
(Items
));
279 Set_Classifications
(Items
, Prag
);
281 -- Indicator Part_Of must be associated with a package instantiation
283 elsif Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) then
284 Set_Next_Pragma
(Prag
, Classifications
(Items
));
285 Set_Classifications
(Items
, Prag
);
287 -- The pragma is not a proper contract item
293 -- Contract items related to package bodies. The applicable pragmas are:
296 elsif Ekind
(Id
) = E_Package_Body
then
297 if Nam
= Name_Refined_State
then
298 Set_Next_Pragma
(Prag
, Classifications
(Items
));
299 Set_Classifications
(Items
, Prag
);
301 -- The pragma is not a proper contract item
307 -- Contract items related to subprogram or entry declarations. The
308 -- applicable pragmas are:
318 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
319 or else Is_Generic_Subprogram
(Id
)
320 or else Is_Subprogram
(Id
)
322 if Nam_In
(Nam
, Name_Precondition
,
329 -- Before we add a precondition or postcondition to the list,
330 -- make sure we do not have a disallowed duplicate, which can
331 -- happen if we use a pragma for Pre[_Class] or Post[_Class]
332 -- instead of the corresponding aspect.
334 if not From_Aspect_Specification
(Prag
)
335 and then Nam_In
(Nam
, Name_Pre_Class
,
342 N
:= Pre_Post_Conditions
(Items
);
343 while Present
(N
) loop
345 and then Original_Aspect_Name
(N
) = Nam
347 Error_Msg_Sloc
:= Sloc
(N
);
349 ("duplication of aspect for & given#", Prag
, Id
);
352 N
:= Next_Pragma
(N
);
357 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
358 Set_Pre_Post_Conditions
(Items
, Prag
);
360 elsif Nam_In
(Nam
, Name_Contract_Cases
, Name_Test_Case
) then
361 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
362 Set_Contract_Test_Cases
(Items
, Prag
);
364 elsif Nam_In
(Nam
, Name_Depends
, Name_Global
) then
365 Set_Next_Pragma
(Prag
, Classifications
(Items
));
366 Set_Classifications
(Items
, Prag
);
368 -- The pragma is not a proper contract item
374 -- Contract items related to subprogram bodies. The applicable pragmas
380 elsif Ekind
(Id
) = E_Subprogram_Body
then
381 if Nam
= Name_Refined_Post
then
382 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
383 Set_Pre_Post_Conditions
(Items
, Prag
);
385 elsif Nam_In
(Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
386 Set_Next_Pragma
(Prag
, Classifications
(Items
));
387 Set_Classifications
(Items
, Prag
);
389 -- The pragma is not a proper contract item
395 -- Contract items related to variables. The applicable pragmas are:
402 elsif Ekind
(Id
) = E_Variable
then
403 if Nam_In
(Nam
, Name_Async_Readers
,
405 Name_Effective_Reads
,
406 Name_Effective_Writes
,
409 Set_Next_Pragma
(Prag
, Classifications
(Items
));
410 Set_Classifications
(Items
, Prag
);
412 -- The pragma is not a proper contract item
418 end Add_Contract_Item
;
420 ----------------------------
421 -- Add_Global_Declaration --
422 ----------------------------
424 procedure Add_Global_Declaration
(N
: Node_Id
) is
425 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
428 if No
(Declarations
(Aux_Node
)) then
429 Set_Declarations
(Aux_Node
, New_List
);
432 Append_To
(Declarations
(Aux_Node
), N
);
434 end Add_Global_Declaration
;
436 --------------------------------
437 -- Address_Integer_Convert_OK --
438 --------------------------------
440 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
442 if Allow_Integer_Address
443 and then ((Is_Descendent_Of_Address
(T1
)
444 and then Is_Private_Type
(T1
)
445 and then Is_Integer_Type
(T2
))
447 (Is_Descendent_Of_Address
(T2
)
448 and then Is_Private_Type
(T2
)
449 and then Is_Integer_Type
(T1
)))
455 end Address_Integer_Convert_OK
;
461 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
463 function Addressable
(V
: Uint
) return Boolean is
465 return V
= Uint_8
or else
471 function Addressable
(V
: Int
) return Boolean is
479 ---------------------------------
480 -- Aggregate_Constraint_Checks --
481 ---------------------------------
483 procedure Aggregate_Constraint_Checks
485 Check_Typ
: Entity_Id
)
487 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
490 if Raises_Constraint_Error
(Exp
) then
494 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
495 -- component's type to force the appropriate accessibility checks.
497 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
498 -- type to force the corresponding run-time check
500 if Is_Access_Type
(Check_Typ
)
501 and then ((Is_Local_Anonymous_Access
(Check_Typ
))
502 or else (Can_Never_Be_Null
(Check_Typ
)
503 and then not Can_Never_Be_Null
(Exp_Typ
)))
505 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
506 Analyze_And_Resolve
(Exp
, Check_Typ
);
507 Check_Unset_Reference
(Exp
);
510 -- This is really expansion activity, so make sure that expansion is
511 -- on and is allowed. In GNATprove mode, we also want check flags to
512 -- be added in the tree, so that the formal verification can rely on
513 -- those to be present. In GNATprove mode for formal verification, some
514 -- treatment typically only done during expansion needs to be performed
515 -- on the tree, but it should not be applied inside generics. Otherwise,
516 -- this breaks the name resolution mechanism for generic instances.
518 if not Expander_Active
519 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
524 -- First check if we have to insert discriminant checks
526 if Has_Discriminants
(Exp_Typ
) then
527 Apply_Discriminant_Check
(Exp
, Check_Typ
);
529 -- Next emit length checks for array aggregates
531 elsif Is_Array_Type
(Exp_Typ
) then
532 Apply_Length_Check
(Exp
, Check_Typ
);
534 -- Finally emit scalar and string checks. If we are dealing with a
535 -- scalar literal we need to check by hand because the Etype of
536 -- literals is not necessarily correct.
538 elsif Is_Scalar_Type
(Exp_Typ
)
539 and then Compile_Time_Known_Value
(Exp
)
541 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
542 Apply_Compile_Time_Constraint_Error
543 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
544 Ent
=> Base_Type
(Check_Typ
),
545 Typ
=> Base_Type
(Check_Typ
));
547 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
548 Apply_Compile_Time_Constraint_Error
549 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
553 elsif not Range_Checks_Suppressed
(Check_Typ
) then
554 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
557 -- Verify that target type is also scalar, to prevent view anomalies
558 -- in instantiations.
560 elsif (Is_Scalar_Type
(Exp_Typ
)
561 or else Nkind
(Exp
) = N_String_Literal
)
562 and then Is_Scalar_Type
(Check_Typ
)
563 and then Exp_Typ
/= Check_Typ
565 if Is_Entity_Name
(Exp
)
566 and then Ekind
(Entity
(Exp
)) = E_Constant
568 -- If expression is a constant, it is worthwhile checking whether
569 -- it is a bound of the type.
571 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
572 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
574 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
575 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
580 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
581 Analyze_And_Resolve
(Exp
, Check_Typ
);
582 Check_Unset_Reference
(Exp
);
585 -- Could use a comment on this case ???
588 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
589 Analyze_And_Resolve
(Exp
, Check_Typ
);
590 Check_Unset_Reference
(Exp
);
594 end Aggregate_Constraint_Checks
;
596 -----------------------
597 -- Alignment_In_Bits --
598 -----------------------
600 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
602 return Alignment
(E
) * System_Storage_Unit
;
603 end Alignment_In_Bits
;
605 ---------------------------------
606 -- Append_Inherited_Subprogram --
607 ---------------------------------
609 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
610 Par
: constant Entity_Id
:= Alias
(S
);
611 -- The parent subprogram
613 Scop
: constant Entity_Id
:= Scope
(Par
);
614 -- The scope of definition of the parent subprogram
616 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
617 -- The derived type of which S is a primitive operation
623 if Ekind
(Current_Scope
) = E_Package
624 and then In_Private_Part
(Current_Scope
)
625 and then Has_Private_Declaration
(Typ
)
626 and then Is_Tagged_Type
(Typ
)
627 and then Scop
= Current_Scope
629 -- The inherited operation is available at the earliest place after
630 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
631 -- relevant for type extensions. If the parent operation appears
632 -- after the type extension, the operation is not visible.
635 (Visible_Declarations
636 (Package_Specification
(Current_Scope
)));
637 while Present
(Decl
) loop
638 if Nkind
(Decl
) = N_Private_Extension_Declaration
639 and then Defining_Entity
(Decl
) = Typ
641 if Sloc
(Decl
) > Sloc
(Par
) then
642 Next_E
:= Next_Entity
(Par
);
643 Set_Next_Entity
(Par
, S
);
644 Set_Next_Entity
(S
, Next_E
);
656 -- If partial view is not a type extension, or it appears before the
657 -- subprogram declaration, insert normally at end of entity list.
659 Append_Entity
(S
, Current_Scope
);
660 end Append_Inherited_Subprogram
;
662 -----------------------------------------
663 -- Apply_Compile_Time_Constraint_Error --
664 -----------------------------------------
666 procedure Apply_Compile_Time_Constraint_Error
669 Reason
: RT_Exception_Code
;
670 Ent
: Entity_Id
:= Empty
;
671 Typ
: Entity_Id
:= Empty
;
672 Loc
: Source_Ptr
:= No_Location
;
673 Rep
: Boolean := True;
674 Warn
: Boolean := False)
676 Stat
: constant Boolean := Is_Static_Expression
(N
);
677 R_Stat
: constant Node_Id
:=
678 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
689 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
695 -- Now we replace the node by an N_Raise_Constraint_Error node
696 -- This does not need reanalyzing, so set it as analyzed now.
699 Set_Analyzed
(N
, True);
702 Set_Raises_Constraint_Error
(N
);
704 -- Now deal with possible local raise handling
706 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
708 -- If the original expression was marked as static, the result is
709 -- still marked as static, but the Raises_Constraint_Error flag is
710 -- always set so that further static evaluation is not attempted.
713 Set_Is_Static_Expression
(N
);
715 end Apply_Compile_Time_Constraint_Error
;
717 ---------------------------
718 -- Async_Readers_Enabled --
719 ---------------------------
721 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
723 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
724 end Async_Readers_Enabled
;
726 ---------------------------
727 -- Async_Writers_Enabled --
728 ---------------------------
730 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
732 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
733 end Async_Writers_Enabled
;
735 --------------------------------------
736 -- Available_Full_View_Of_Component --
737 --------------------------------------
739 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
740 ST
: constant Entity_Id
:= Scope
(T
);
741 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
743 return In_Open_Scopes
(ST
)
744 and then In_Open_Scopes
(SCT
)
745 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
746 end Available_Full_View_Of_Component
;
752 procedure Bad_Attribute
755 Warn
: Boolean := False)
758 Error_Msg_Warn
:= Warn
;
759 Error_Msg_N
("unrecognized attribute&<<", N
);
761 -- Check for possible misspelling
763 Error_Msg_Name_1
:= First_Attribute_Name
;
764 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
765 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
766 Error_Msg_N
-- CODEFIX
767 ("\possible misspelling of %<<", N
);
771 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
775 --------------------------------
776 -- Bad_Predicated_Subtype_Use --
777 --------------------------------
779 procedure Bad_Predicated_Subtype_Use
783 Suggest_Static
: Boolean := False)
788 -- Avoid cascaded errors
790 if Error_Posted
(N
) then
794 if Inside_A_Generic
then
795 Gen
:= Current_Scope
;
796 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
804 if Is_Generic_Formal
(Typ
)
805 and then Is_Discrete_Type
(Typ
)
807 Set_No_Predicate_On_Actual
(Typ
);
810 elsif Has_Predicates
(Typ
) then
811 if Is_Generic_Actual_Type
(Typ
) then
813 -- The restriction on loop parameters is only that the type
814 -- should have no dynamic predicates.
816 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
817 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
818 and then Is_OK_Static_Subtype
(Typ
)
823 Gen
:= Current_Scope
;
824 while not Is_Generic_Instance
(Gen
) loop
828 pragma Assert
(Present
(Gen
));
830 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
831 Error_Msg_Warn
:= SPARK_Mode
/= On
;
832 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
833 Error_Msg_F
("\Program_Error [<<", N
);
836 Make_Raise_Program_Error
(Sloc
(N
),
837 Reason
=> PE_Bad_Predicated_Generic_Type
));
840 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
844 Error_Msg_FE
(Msg
, N
, Typ
);
847 -- Emit an optional suggestion on how to remedy the error if the
848 -- context warrants it.
850 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
851 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
854 end Bad_Predicated_Subtype_Use
;
856 -----------------------------------------
857 -- Bad_Unordered_Enumeration_Reference --
858 -----------------------------------------
860 function Bad_Unordered_Enumeration_Reference
862 T
: Entity_Id
) return Boolean
865 return Is_Enumeration_Type
(T
)
866 and then Comes_From_Source
(N
)
867 and then Warn_On_Unordered_Enumeration_Type
868 and then not Has_Pragma_Ordered
(T
)
869 and then not In_Same_Extended_Unit
(N
, T
);
870 end Bad_Unordered_Enumeration_Reference
;
872 --------------------------
873 -- Build_Actual_Subtype --
874 --------------------------
876 function Build_Actual_Subtype
878 N
: Node_Or_Entity_Id
) return Node_Id
881 -- Normally Sloc (N), but may point to corresponding body in some cases
883 Constraints
: List_Id
;
889 Disc_Type
: Entity_Id
;
895 if Nkind
(N
) = N_Defining_Identifier
then
896 Obj
:= New_Occurrence_Of
(N
, Loc
);
898 -- If this is a formal parameter of a subprogram declaration, and
899 -- we are compiling the body, we want the declaration for the
900 -- actual subtype to carry the source position of the body, to
901 -- prevent anomalies in gdb when stepping through the code.
903 if Is_Formal
(N
) then
905 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
907 if Nkind
(Decl
) = N_Subprogram_Declaration
908 and then Present
(Corresponding_Body
(Decl
))
910 Loc
:= Sloc
(Corresponding_Body
(Decl
));
919 if Is_Array_Type
(T
) then
920 Constraints
:= New_List
;
921 for J
in 1 .. Number_Dimensions
(T
) loop
923 -- Build an array subtype declaration with the nominal subtype and
924 -- the bounds of the actual. Add the declaration in front of the
925 -- local declarations for the subprogram, for analysis before any
926 -- reference to the formal in the body.
929 Make_Attribute_Reference
(Loc
,
931 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
932 Attribute_Name
=> Name_First
,
933 Expressions
=> New_List
(
934 Make_Integer_Literal
(Loc
, J
)));
937 Make_Attribute_Reference
(Loc
,
939 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
940 Attribute_Name
=> Name_Last
,
941 Expressions
=> New_List
(
942 Make_Integer_Literal
(Loc
, J
)));
944 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
947 -- If the type has unknown discriminants there is no constrained
948 -- subtype to build. This is never called for a formal or for a
949 -- lhs, so returning the type is ok ???
951 elsif Has_Unknown_Discriminants
(T
) then
955 Constraints
:= New_List
;
957 -- Type T is a generic derived type, inherit the discriminants from
960 if Is_Private_Type
(T
)
961 and then No
(Full_View
(T
))
963 -- T was flagged as an error if it was declared as a formal
964 -- derived type with known discriminants. In this case there
965 -- is no need to look at the parent type since T already carries
966 -- its own discriminants.
968 and then not Error_Posted
(T
)
970 Disc_Type
:= Etype
(Base_Type
(T
));
975 Discr
:= First_Discriminant
(Disc_Type
);
976 while Present
(Discr
) loop
977 Append_To
(Constraints
,
978 Make_Selected_Component
(Loc
,
980 Duplicate_Subexpr_No_Checks
(Obj
),
981 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
982 Next_Discriminant
(Discr
);
986 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
987 Set_Is_Internal
(Subt
);
990 Make_Subtype_Declaration
(Loc
,
991 Defining_Identifier
=> Subt
,
992 Subtype_Indication
=>
993 Make_Subtype_Indication
(Loc
,
994 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
996 Make_Index_Or_Discriminant_Constraint
(Loc
,
997 Constraints
=> Constraints
)));
999 Mark_Rewrite_Insertion
(Decl
);
1001 end Build_Actual_Subtype
;
1003 ---------------------------------------
1004 -- Build_Actual_Subtype_Of_Component --
1005 ---------------------------------------
1007 function Build_Actual_Subtype_Of_Component
1009 N
: Node_Id
) return Node_Id
1011 Loc
: constant Source_Ptr
:= Sloc
(N
);
1012 P
: constant Node_Id
:= Prefix
(N
);
1015 Index_Typ
: Entity_Id
;
1017 Desig_Typ
: Entity_Id
;
1018 -- This is either a copy of T, or if T is an access type, then it is
1019 -- the directly designated type of this access type.
1021 function Build_Actual_Array_Constraint
return List_Id
;
1022 -- If one or more of the bounds of the component depends on
1023 -- discriminants, build actual constraint using the discriminants
1026 function Build_Actual_Record_Constraint
return List_Id
;
1027 -- Similar to previous one, for discriminated components constrained
1028 -- by the discriminant of the enclosing object.
1030 -----------------------------------
1031 -- Build_Actual_Array_Constraint --
1032 -----------------------------------
1034 function Build_Actual_Array_Constraint
return List_Id
is
1035 Constraints
: constant List_Id
:= New_List
;
1043 Indx
:= First_Index
(Desig_Typ
);
1044 while Present
(Indx
) loop
1045 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1046 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1048 if Denotes_Discriminant
(Old_Lo
) then
1050 Make_Selected_Component
(Loc
,
1051 Prefix
=> New_Copy_Tree
(P
),
1052 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1055 Lo
:= New_Copy_Tree
(Old_Lo
);
1057 -- The new bound will be reanalyzed in the enclosing
1058 -- declaration. For literal bounds that come from a type
1059 -- declaration, the type of the context must be imposed, so
1060 -- insure that analysis will take place. For non-universal
1061 -- types this is not strictly necessary.
1063 Set_Analyzed
(Lo
, False);
1066 if Denotes_Discriminant
(Old_Hi
) then
1068 Make_Selected_Component
(Loc
,
1069 Prefix
=> New_Copy_Tree
(P
),
1070 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1073 Hi
:= New_Copy_Tree
(Old_Hi
);
1074 Set_Analyzed
(Hi
, False);
1077 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1082 end Build_Actual_Array_Constraint
;
1084 ------------------------------------
1085 -- Build_Actual_Record_Constraint --
1086 ------------------------------------
1088 function Build_Actual_Record_Constraint
return List_Id
is
1089 Constraints
: constant List_Id
:= New_List
;
1094 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1095 while Present
(D
) loop
1096 if Denotes_Discriminant
(Node
(D
)) then
1097 D_Val
:= Make_Selected_Component
(Loc
,
1098 Prefix
=> New_Copy_Tree
(P
),
1099 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1102 D_Val
:= New_Copy_Tree
(Node
(D
));
1105 Append
(D_Val
, Constraints
);
1110 end Build_Actual_Record_Constraint
;
1112 -- Start of processing for Build_Actual_Subtype_Of_Component
1115 -- Why the test for Spec_Expression mode here???
1117 if In_Spec_Expression
then
1120 -- More comments for the rest of this body would be good ???
1122 elsif Nkind
(N
) = N_Explicit_Dereference
then
1123 if Is_Composite_Type
(T
)
1124 and then not Is_Constrained
(T
)
1125 and then not (Is_Class_Wide_Type
(T
)
1126 and then Is_Constrained
(Root_Type
(T
)))
1127 and then not Has_Unknown_Discriminants
(T
)
1129 -- If the type of the dereference is already constrained, it is an
1132 if Is_Array_Type
(Etype
(N
))
1133 and then Is_Constrained
(Etype
(N
))
1137 Remove_Side_Effects
(P
);
1138 return Build_Actual_Subtype
(T
, N
);
1145 if Ekind
(T
) = E_Access_Subtype
then
1146 Desig_Typ
:= Designated_Type
(T
);
1151 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1152 Id
:= First_Index
(Desig_Typ
);
1153 while Present
(Id
) loop
1154 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1156 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1158 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1160 Remove_Side_Effects
(P
);
1162 Build_Component_Subtype
1163 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1169 elsif Is_Composite_Type
(Desig_Typ
)
1170 and then Has_Discriminants
(Desig_Typ
)
1171 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1173 if Is_Private_Type
(Desig_Typ
)
1174 and then No
(Discriminant_Constraint
(Desig_Typ
))
1176 Desig_Typ
:= Full_View
(Desig_Typ
);
1179 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1180 while Present
(D
) loop
1181 if Denotes_Discriminant
(Node
(D
)) then
1182 Remove_Side_Effects
(P
);
1184 Build_Component_Subtype
(
1185 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1192 -- If none of the above, the actual and nominal subtypes are the same
1195 end Build_Actual_Subtype_Of_Component
;
1197 -----------------------------
1198 -- Build_Component_Subtype --
1199 -----------------------------
1201 function Build_Component_Subtype
1204 T
: Entity_Id
) return Node_Id
1210 -- Unchecked_Union components do not require component subtypes
1212 if Is_Unchecked_Union
(T
) then
1216 Subt
:= Make_Temporary
(Loc
, 'S');
1217 Set_Is_Internal
(Subt
);
1220 Make_Subtype_Declaration
(Loc
,
1221 Defining_Identifier
=> Subt
,
1222 Subtype_Indication
=>
1223 Make_Subtype_Indication
(Loc
,
1224 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1226 Make_Index_Or_Discriminant_Constraint
(Loc
,
1227 Constraints
=> C
)));
1229 Mark_Rewrite_Insertion
(Decl
);
1231 end Build_Component_Subtype
;
1233 ----------------------------------
1234 -- Build_Default_Init_Cond_Call --
1235 ----------------------------------
1237 function Build_Default_Init_Cond_Call
1240 Typ
: Entity_Id
) return Node_Id
1242 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1243 Formal_Typ
: constant Entity_Id
:= Etype
(First_Formal
(Proc_Id
));
1247 Make_Procedure_Call_Statement
(Loc
,
1248 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
1249 Parameter_Associations
=> New_List
(
1250 Make_Type_Conversion
(Loc
,
1251 Subtype_Mark
=> New_Occurrence_Of
(Formal_Typ
, Loc
),
1252 Expression
=> New_Occurrence_Of
(Obj_Id
, Loc
))));
1253 end Build_Default_Init_Cond_Call
;
1255 --------------------------------------------
1256 -- Build_Default_Init_Cond_Procedure_Body --
1257 --------------------------------------------
1259 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
) is
1260 Param_Id
: Entity_Id
;
1261 -- The entity of the formal parameter of the default initial condition
1264 procedure Replace_Type_Reference
(N
: Node_Id
);
1265 -- Replace a single reference to type Typ with a reference to Param_Id
1267 ----------------------------
1268 -- Replace_Type_Reference --
1269 ----------------------------
1271 procedure Replace_Type_Reference
(N
: Node_Id
) is
1273 Rewrite
(N
, New_Occurrence_Of
(Param_Id
, Sloc
(N
)));
1274 end Replace_Type_Reference
;
1276 procedure Replace_Type_References
is
1277 new Replace_Type_References_Generic
(Replace_Type_Reference
);
1281 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1282 Prag
: constant Node_Id
:=
1283 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1284 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1285 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Proc_Id
);
1286 Body_Decl
: Node_Id
;
1290 -- Start of processing for Build_Default_Init_Cond_Procedure
1293 -- The procedure should be generated only for types subject to pragma
1294 -- Default_Initial_Condition. Types that inherit the pragma do not get
1295 -- this specialized procedure.
1297 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1298 pragma Assert
(Present
(Prag
));
1299 pragma Assert
(Present
(Proc_Id
));
1301 -- Nothing to do if the body was already built
1303 if Present
(Corresponding_Body
(Spec_Decl
)) then
1307 Param_Id
:= First_Formal
(Proc_Id
);
1309 -- The pragma has an argument. Note that the argument is analyzed after
1310 -- all references to the current instance of the type are replaced.
1312 if Present
(Pragma_Argument_Associations
(Prag
)) then
1313 Expr
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
1315 if Nkind
(Expr
) = N_Null
then
1316 Stmt
:= Make_Null_Statement
(Loc
);
1318 -- Preserve the original argument of the pragma by replicating it.
1319 -- Replace all references to the current instance of the type with
1320 -- references to the formal parameter.
1323 Expr
:= New_Copy_Tree
(Expr
);
1324 Replace_Type_References
(Expr
, Typ
);
1327 -- pragma Check (Default_Initial_Condition, <Expr>);
1331 Pragma_Identifier
=>
1332 Make_Identifier
(Loc
, Name_Check
),
1334 Pragma_Argument_Associations
=> New_List
(
1335 Make_Pragma_Argument_Association
(Loc
,
1337 Make_Identifier
(Loc
, Name_Default_Initial_Condition
)),
1338 Make_Pragma_Argument_Association
(Loc
,
1339 Expression
=> Expr
)));
1342 -- Otherwise the pragma appears without an argument
1345 Stmt
:= Make_Null_Statement
(Loc
);
1349 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1352 -- end <Typ>Default_Init_Cond;
1355 Make_Subprogram_Body
(Loc
,
1357 Copy_Separate_Tree
(Specification
(Spec_Decl
)),
1358 Declarations
=> Empty_List
,
1359 Handled_Statement_Sequence
=>
1360 Make_Handled_Sequence_Of_Statements
(Loc
,
1361 Statements
=> New_List
(Stmt
)));
1363 -- Link the spec and body of the default initial condition procedure
1364 -- to prevent the generation of a duplicate body in case there is an
1365 -- attempt to freeze the related type again.
1367 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
1368 Set_Corresponding_Spec
(Body_Decl
, Proc_Id
);
1370 Append_Freeze_Action
(Typ
, Body_Decl
);
1371 end Build_Default_Init_Cond_Procedure_Body
;
1373 ---------------------------------------------------
1374 -- Build_Default_Init_Cond_Procedure_Declaration --
1375 ---------------------------------------------------
1377 procedure Build_Default_Init_Cond_Procedure_Declaration
(Typ
: Entity_Id
) is
1378 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1379 Prag
: constant Node_Id
:=
1380 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1381 Proc_Id
: Entity_Id
;
1384 -- The procedure should be generated only for types subject to pragma
1385 -- Default_Initial_Condition. Types that inherit the pragma do not get
1386 -- this specialized procedure.
1388 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1389 pragma Assert
(Present
(Prag
));
1392 Make_Defining_Identifier
(Loc
,
1393 Chars
=> New_External_Name
(Chars
(Typ
), "Default_Init_Cond"));
1395 -- Associate default initial condition procedure with the private type
1397 Set_Ekind
(Proc_Id
, E_Procedure
);
1398 Set_Is_Default_Init_Cond_Procedure
(Proc_Id
);
1399 Set_Default_Init_Cond_Procedure
(Typ
, Proc_Id
);
1402 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1404 Insert_After_And_Analyze
(Prag
,
1405 Make_Subprogram_Declaration
(Loc
,
1407 Make_Procedure_Specification
(Loc
,
1408 Defining_Unit_Name
=> Proc_Id
,
1409 Parameter_Specifications
=> New_List
(
1410 Make_Parameter_Specification
(Loc
,
1411 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
1412 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))))));
1413 end Build_Default_Init_Cond_Procedure_Declaration
;
1415 ---------------------------
1416 -- Build_Default_Subtype --
1417 ---------------------------
1419 function Build_Default_Subtype
1421 N
: Node_Id
) return Entity_Id
1423 Loc
: constant Source_Ptr
:= Sloc
(N
);
1427 -- The base type that is to be constrained by the defaults
1430 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1434 Bas
:= Base_Type
(T
);
1436 -- If T is non-private but its base type is private, this is the
1437 -- completion of a subtype declaration whose parent type is private
1438 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1439 -- are to be found in the full view of the base. Check that the private
1440 -- status of T and its base differ.
1442 if Is_Private_Type
(Bas
)
1443 and then not Is_Private_Type
(T
)
1444 and then Present
(Full_View
(Bas
))
1446 Bas
:= Full_View
(Bas
);
1449 Disc
:= First_Discriminant
(T
);
1451 if No
(Discriminant_Default_Value
(Disc
)) then
1456 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1457 Constraints
: constant List_Id
:= New_List
;
1461 while Present
(Disc
) loop
1462 Append_To
(Constraints
,
1463 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1464 Next_Discriminant
(Disc
);
1468 Make_Subtype_Declaration
(Loc
,
1469 Defining_Identifier
=> Act
,
1470 Subtype_Indication
=>
1471 Make_Subtype_Indication
(Loc
,
1472 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1474 Make_Index_Or_Discriminant_Constraint
(Loc
,
1475 Constraints
=> Constraints
)));
1477 Insert_Action
(N
, Decl
);
1481 end Build_Default_Subtype
;
1483 --------------------------------------------
1484 -- Build_Discriminal_Subtype_Of_Component --
1485 --------------------------------------------
1487 function Build_Discriminal_Subtype_Of_Component
1488 (T
: Entity_Id
) return Node_Id
1490 Loc
: constant Source_Ptr
:= Sloc
(T
);
1494 function Build_Discriminal_Array_Constraint
return List_Id
;
1495 -- If one or more of the bounds of the component depends on
1496 -- discriminants, build actual constraint using the discriminants
1499 function Build_Discriminal_Record_Constraint
return List_Id
;
1500 -- Similar to previous one, for discriminated components constrained by
1501 -- the discriminant of the enclosing object.
1503 ----------------------------------------
1504 -- Build_Discriminal_Array_Constraint --
1505 ----------------------------------------
1507 function Build_Discriminal_Array_Constraint
return List_Id
is
1508 Constraints
: constant List_Id
:= New_List
;
1516 Indx
:= First_Index
(T
);
1517 while Present
(Indx
) loop
1518 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1519 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1521 if Denotes_Discriminant
(Old_Lo
) then
1522 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1525 Lo
:= New_Copy_Tree
(Old_Lo
);
1528 if Denotes_Discriminant
(Old_Hi
) then
1529 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1532 Hi
:= New_Copy_Tree
(Old_Hi
);
1535 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1540 end Build_Discriminal_Array_Constraint
;
1542 -----------------------------------------
1543 -- Build_Discriminal_Record_Constraint --
1544 -----------------------------------------
1546 function Build_Discriminal_Record_Constraint
return List_Id
is
1547 Constraints
: constant List_Id
:= New_List
;
1552 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1553 while Present
(D
) loop
1554 if Denotes_Discriminant
(Node
(D
)) then
1556 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1558 D_Val
:= New_Copy_Tree
(Node
(D
));
1561 Append
(D_Val
, Constraints
);
1566 end Build_Discriminal_Record_Constraint
;
1568 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1571 if Ekind
(T
) = E_Array_Subtype
then
1572 Id
:= First_Index
(T
);
1573 while Present
(Id
) loop
1574 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1576 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1578 return Build_Component_Subtype
1579 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1585 elsif Ekind
(T
) = E_Record_Subtype
1586 and then Has_Discriminants
(T
)
1587 and then not Has_Unknown_Discriminants
(T
)
1589 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1590 while Present
(D
) loop
1591 if Denotes_Discriminant
(Node
(D
)) then
1592 return Build_Component_Subtype
1593 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1600 -- If none of the above, the actual and nominal subtypes are the same
1603 end Build_Discriminal_Subtype_Of_Component
;
1605 ------------------------------
1606 -- Build_Elaboration_Entity --
1607 ------------------------------
1609 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1610 Loc
: constant Source_Ptr
:= Sloc
(N
);
1612 Elab_Ent
: Entity_Id
;
1614 procedure Set_Package_Name
(Ent
: Entity_Id
);
1615 -- Given an entity, sets the fully qualified name of the entity in
1616 -- Name_Buffer, with components separated by double underscores. This
1617 -- is a recursive routine that climbs the scope chain to Standard.
1619 ----------------------
1620 -- Set_Package_Name --
1621 ----------------------
1623 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1625 if Scope
(Ent
) /= Standard_Standard
then
1626 Set_Package_Name
(Scope
(Ent
));
1629 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1631 Name_Buffer
(Name_Len
+ 1) := '_';
1632 Name_Buffer
(Name_Len
+ 2) := '_';
1633 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1634 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1638 Get_Name_String
(Chars
(Ent
));
1640 end Set_Package_Name
;
1642 -- Start of processing for Build_Elaboration_Entity
1645 -- Ignore call if already constructed
1647 if Present
(Elaboration_Entity
(Spec_Id
)) then
1650 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1651 -- no role in analysis.
1653 elsif ASIS_Mode
then
1656 -- See if we need elaboration entity. We always need it for the dynamic
1657 -- elaboration model, since it is needed to properly generate the PE
1658 -- exception for access before elaboration.
1660 elsif Dynamic_Elaboration_Checks
then
1663 -- For the static model, we don't need the elaboration counter if this
1664 -- unit is sure to have no elaboration code, since that means there
1665 -- is no elaboration unit to be called. Note that we can't just decide
1666 -- after the fact by looking to see whether there was elaboration code,
1667 -- because that's too late to make this decision.
1669 elsif Restriction_Active
(No_Elaboration_Code
) then
1672 -- Similarly, for the static model, we can skip the elaboration counter
1673 -- if we have the No_Multiple_Elaboration restriction, since for the
1674 -- static model, that's the only purpose of the counter (to avoid
1675 -- multiple elaboration).
1677 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1681 -- Here we need the elaboration entity
1683 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1684 -- name with dots replaced by double underscore. We have to manually
1685 -- construct this name, since it will be elaborated in the outer scope,
1686 -- and thus will not have the unit name automatically prepended.
1688 Set_Package_Name
(Spec_Id
);
1689 Add_Str_To_Name_Buffer
("_E");
1691 -- Create elaboration counter
1693 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1694 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1697 Make_Object_Declaration
(Loc
,
1698 Defining_Identifier
=> Elab_Ent
,
1699 Object_Definition
=>
1700 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1701 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1703 Push_Scope
(Standard_Standard
);
1704 Add_Global_Declaration
(Decl
);
1707 -- Reset True_Constant indication, since we will indeed assign a value
1708 -- to the variable in the binder main. We also kill the Current_Value
1709 -- and Last_Assignment fields for the same reason.
1711 Set_Is_True_Constant
(Elab_Ent
, False);
1712 Set_Current_Value
(Elab_Ent
, Empty
);
1713 Set_Last_Assignment
(Elab_Ent
, Empty
);
1715 -- We do not want any further qualification of the name (if we did not
1716 -- do this, we would pick up the name of the generic package in the case
1717 -- of a library level generic instantiation).
1719 Set_Has_Qualified_Name
(Elab_Ent
);
1720 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1721 end Build_Elaboration_Entity
;
1723 --------------------------------
1724 -- Build_Explicit_Dereference --
1725 --------------------------------
1727 procedure Build_Explicit_Dereference
1731 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1734 -- An entity of a type with a reference aspect is overloaded with
1735 -- both interpretations: with and without the dereference. Now that
1736 -- the dereference is made explicit, set the type of the node properly,
1737 -- to prevent anomalies in the backend. Same if the expression is an
1738 -- overloaded function call whose return type has a reference aspect.
1740 if Is_Entity_Name
(Expr
) then
1741 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1743 elsif Nkind
(Expr
) = N_Function_Call
then
1744 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1747 Set_Is_Overloaded
(Expr
, False);
1749 -- The expression will often be a generalized indexing that yields a
1750 -- container element that is then dereferenced, in which case the
1751 -- generalized indexing call is also non-overloaded.
1753 if Nkind
(Expr
) = N_Indexed_Component
1754 and then Present
(Generalized_Indexing
(Expr
))
1756 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1760 Make_Explicit_Dereference
(Loc
,
1762 Make_Selected_Component
(Loc
,
1763 Prefix
=> Relocate_Node
(Expr
),
1764 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1765 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1766 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1767 end Build_Explicit_Dereference
;
1769 -----------------------------------
1770 -- Cannot_Raise_Constraint_Error --
1771 -----------------------------------
1773 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1775 if Compile_Time_Known_Value
(Expr
) then
1778 elsif Do_Range_Check
(Expr
) then
1781 elsif Raises_Constraint_Error
(Expr
) then
1785 case Nkind
(Expr
) is
1786 when N_Identifier
=>
1789 when N_Expanded_Name
=>
1792 when N_Selected_Component
=>
1793 return not Do_Discriminant_Check
(Expr
);
1795 when N_Attribute_Reference
=>
1796 if Do_Overflow_Check
(Expr
) then
1799 elsif No
(Expressions
(Expr
)) then
1807 N
:= First
(Expressions
(Expr
));
1808 while Present
(N
) loop
1809 if Cannot_Raise_Constraint_Error
(N
) then
1820 when N_Type_Conversion
=>
1821 if Do_Overflow_Check
(Expr
)
1822 or else Do_Length_Check
(Expr
)
1823 or else Do_Tag_Check
(Expr
)
1827 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1830 when N_Unchecked_Type_Conversion
=>
1831 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1834 if Do_Overflow_Check
(Expr
) then
1837 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1844 if Do_Division_Check
(Expr
)
1846 Do_Overflow_Check
(Expr
)
1851 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1853 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1872 N_Op_Shift_Right_Arithmetic |
1876 if Do_Overflow_Check
(Expr
) then
1880 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1882 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1889 end Cannot_Raise_Constraint_Error
;
1891 -----------------------------------------
1892 -- Check_Dynamically_Tagged_Expression --
1893 -----------------------------------------
1895 procedure Check_Dynamically_Tagged_Expression
1898 Related_Nod
: Node_Id
)
1901 pragma Assert
(Is_Tagged_Type
(Typ
));
1903 -- In order to avoid spurious errors when analyzing the expanded code,
1904 -- this check is done only for nodes that come from source and for
1905 -- actuals of generic instantiations.
1907 if (Comes_From_Source
(Related_Nod
)
1908 or else In_Generic_Actual
(Expr
))
1909 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1910 or else Is_Dynamically_Tagged
(Expr
))
1911 and then Is_Tagged_Type
(Typ
)
1912 and then not Is_Class_Wide_Type
(Typ
)
1914 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1916 end Check_Dynamically_Tagged_Expression
;
1918 --------------------------
1919 -- Check_Fully_Declared --
1920 --------------------------
1922 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1924 if Ekind
(T
) = E_Incomplete_Type
then
1926 -- Ada 2005 (AI-50217): If the type is available through a limited
1927 -- with_clause, verify that its full view has been analyzed.
1929 if From_Limited_With
(T
)
1930 and then Present
(Non_Limited_View
(T
))
1931 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
1933 -- The non-limited view is fully declared
1938 ("premature usage of incomplete}", N
, First_Subtype
(T
));
1941 -- Need comments for these tests ???
1943 elsif Has_Private_Component
(T
)
1944 and then not Is_Generic_Type
(Root_Type
(T
))
1945 and then not In_Spec_Expression
1947 -- Special case: if T is the anonymous type created for a single
1948 -- task or protected object, use the name of the source object.
1950 if Is_Concurrent_Type
(T
)
1951 and then not Comes_From_Source
(T
)
1952 and then Nkind
(N
) = N_Object_Declaration
1955 ("type of& has incomplete component",
1956 N
, Defining_Identifier
(N
));
1959 ("premature usage of incomplete}",
1960 N
, First_Subtype
(T
));
1963 end Check_Fully_Declared
;
1965 -------------------------------------
1966 -- Check_Function_Writable_Actuals --
1967 -------------------------------------
1969 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
1970 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
1971 Identifiers_List
: Elist_Id
:= No_Elist
;
1972 Error_Node
: Node_Id
:= Empty
;
1974 procedure Collect_Identifiers
(N
: Node_Id
);
1975 -- In a single traversal of subtree N collect in Writable_Actuals_List
1976 -- all the actuals of functions with writable actuals, and in the list
1977 -- Identifiers_List collect all the identifiers that are not actuals of
1978 -- functions with writable actuals. If a writable actual is referenced
1979 -- twice as writable actual then Error_Node is set to reference its
1980 -- second occurrence, the error is reported, and the tree traversal
1983 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
1984 -- Return the entity associated with the function call
1986 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
1987 -- Preanalyze N without reporting errors. Very dubious, you can't just
1988 -- go analyzing things more than once???
1990 -------------------------
1991 -- Collect_Identifiers --
1992 -------------------------
1994 procedure Collect_Identifiers
(N
: Node_Id
) is
1996 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
1997 -- Process a single node during the tree traversal to collect the
1998 -- writable actuals of functions and all the identifiers which are
1999 -- not writable actuals of functions.
2001 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2002 -- Returns True if List has a node whose Entity is Entity (N)
2004 -------------------------
2005 -- Check_Function_Call --
2006 -------------------------
2008 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2009 Is_Writable_Actual
: Boolean := False;
2013 if Nkind
(N
) = N_Identifier
then
2015 -- No analysis possible if the entity is not decorated
2017 if No
(Entity
(N
)) then
2020 -- Don't collect identifiers of packages, called functions, etc
2022 elsif Ekind_In
(Entity
(N
), E_Package
,
2029 -- Analyze if N is a writable actual of a function
2031 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2033 Call
: constant Node_Id
:= Parent
(N
);
2038 Id
:= Get_Function_Id
(Call
);
2040 Formal
:= First_Formal
(Id
);
2041 Actual
:= First_Actual
(Call
);
2042 while Present
(Actual
) and then Present
(Formal
) loop
2044 if Ekind_In
(Formal
, E_Out_Parameter
,
2047 Is_Writable_Actual
:= True;
2053 Next_Formal
(Formal
);
2054 Next_Actual
(Actual
);
2059 if Is_Writable_Actual
then
2060 if Contains
(Writable_Actuals_List
, N
) then
2062 ("value may be affected by call to& "
2063 & "because order of evaluation is arbitrary", N
, Id
);
2068 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2071 if Identifiers_List
= No_Elist
then
2072 Identifiers_List
:= New_Elmt_List
;
2075 Append_Unique_Elmt
(N
, Identifiers_List
);
2088 N
: Node_Id
) return Boolean
2090 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2095 if List
= No_Elist
then
2099 Elmt
:= First_Elmt
(List
);
2100 while Present
(Elmt
) loop
2101 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2115 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2116 -- The traversal procedure
2118 -- Start of processing for Collect_Identifiers
2121 if Present
(Error_Node
) then
2125 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2130 end Collect_Identifiers
;
2132 ---------------------
2133 -- Get_Function_Id --
2134 ---------------------
2136 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
2137 Nam
: constant Node_Id
:= Name
(Call
);
2141 if Nkind
(Nam
) = N_Explicit_Dereference
then
2143 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
2145 elsif Nkind
(Nam
) = N_Selected_Component
then
2146 Id
:= Entity
(Selector_Name
(Nam
));
2148 elsif Nkind
(Nam
) = N_Indexed_Component
then
2149 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
2156 end Get_Function_Id
;
2158 ---------------------------
2159 -- Preanalyze_Expression --
2160 ---------------------------
2162 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2163 Status
: constant Boolean := Get_Ignore_Errors
;
2165 Set_Ignore_Errors
(True);
2167 Set_Ignore_Errors
(Status
);
2168 end Preanalyze_Without_Errors
;
2170 -- Start of processing for Check_Function_Writable_Actuals
2173 -- The check only applies to Ada 2012 code, and only to constructs that
2174 -- have multiple constituents whose order of evaluation is not specified
2177 if Ada_Version
< Ada_2012
2178 or else (not (Nkind
(N
) in N_Op
)
2179 and then not (Nkind
(N
) in N_Membership_Test
)
2180 and then not Nkind_In
(N
, N_Range
,
2182 N_Extension_Aggregate
,
2183 N_Full_Type_Declaration
,
2185 N_Procedure_Call_Statement
,
2186 N_Entry_Call_Statement
))
2187 or else (Nkind
(N
) = N_Full_Type_Declaration
2188 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2190 -- In addition, this check only applies to source code, not to code
2191 -- generated by constraint checks.
2193 or else not Comes_From_Source
(N
)
2198 -- If a construct C has two or more direct constituents that are names
2199 -- or expressions whose evaluation may occur in an arbitrary order, at
2200 -- least one of which contains a function call with an in out or out
2201 -- parameter, then the construct is legal only if: for each name N that
2202 -- is passed as a parameter of mode in out or out to some inner function
2203 -- call C2 (not including the construct C itself), there is no other
2204 -- name anywhere within a direct constituent of the construct C other
2205 -- than the one containing C2, that is known to refer to the same
2206 -- object (RM 6.4.1(6.17/3)).
2210 Collect_Identifiers
(Low_Bound
(N
));
2211 Collect_Identifiers
(High_Bound
(N
));
2213 when N_Op | N_Membership_Test
=>
2218 Collect_Identifiers
(Left_Opnd
(N
));
2220 if Present
(Right_Opnd
(N
)) then
2221 Collect_Identifiers
(Right_Opnd
(N
));
2224 if Nkind_In
(N
, N_In
, N_Not_In
)
2225 and then Present
(Alternatives
(N
))
2227 Expr
:= First
(Alternatives
(N
));
2228 while Present
(Expr
) loop
2229 Collect_Identifiers
(Expr
);
2236 when N_Full_Type_Declaration
=>
2238 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2239 -- Return the record part of this record type definition
2241 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2242 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2244 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2245 return Record_Extension_Part
(Type_Def
);
2249 end Get_Record_Part
;
2252 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2253 Rec
: Node_Id
:= Get_Record_Part
(N
);
2256 -- No need to perform any analysis if the record has no
2259 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2263 -- Collect the identifiers starting from the deepest
2264 -- derivation. Done to report the error in the deepest
2268 if Present
(Component_List
(Rec
)) then
2269 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2270 while Present
(Comp
) loop
2271 if Nkind
(Comp
) = N_Component_Declaration
2272 and then Present
(Expression
(Comp
))
2274 Collect_Identifiers
(Expression
(Comp
));
2281 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2282 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2285 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2286 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2290 when N_Subprogram_Call |
2291 N_Entry_Call_Statement
=>
2293 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
2298 Formal
:= First_Formal
(Id
);
2299 Actual
:= First_Actual
(N
);
2300 while Present
(Actual
) and then Present
(Formal
) loop
2301 if Ekind_In
(Formal
, E_Out_Parameter
,
2304 Collect_Identifiers
(Actual
);
2307 Next_Formal
(Formal
);
2308 Next_Actual
(Actual
);
2313 N_Extension_Aggregate
=>
2317 Comp_Expr
: Node_Id
;
2320 -- Handle the N_Others_Choice of array aggregates with static
2321 -- bounds. There is no need to perform this analysis in
2322 -- aggregates without static bounds since we cannot evaluate
2323 -- if the N_Others_Choice covers several elements. There is
2324 -- no need to handle the N_Others choice of record aggregates
2325 -- since at this stage it has been already expanded by
2326 -- Resolve_Record_Aggregate.
2328 if Is_Array_Type
(Etype
(N
))
2329 and then Nkind
(N
) = N_Aggregate
2330 and then Present
(Aggregate_Bounds
(N
))
2331 and then Compile_Time_Known_Bounds
(Etype
(N
))
2332 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2334 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2337 Count_Components
: Uint
:= Uint_0
;
2338 Num_Components
: Uint
;
2339 Others_Assoc
: Node_Id
;
2340 Others_Choice
: Node_Id
:= Empty
;
2341 Others_Box_Present
: Boolean := False;
2344 -- Count positional associations
2346 if Present
(Expressions
(N
)) then
2347 Comp_Expr
:= First
(Expressions
(N
));
2348 while Present
(Comp_Expr
) loop
2349 Count_Components
:= Count_Components
+ 1;
2354 -- Count the rest of elements and locate the N_Others
2357 Assoc
:= First
(Component_Associations
(N
));
2358 while Present
(Assoc
) loop
2359 Choice
:= First
(Choices
(Assoc
));
2360 while Present
(Choice
) loop
2361 if Nkind
(Choice
) = N_Others_Choice
then
2362 Others_Assoc
:= Assoc
;
2363 Others_Choice
:= Choice
;
2364 Others_Box_Present
:= Box_Present
(Assoc
);
2366 -- Count several components
2368 elsif Nkind_In
(Choice
, N_Range
,
2369 N_Subtype_Indication
)
2370 or else (Is_Entity_Name
(Choice
)
2371 and then Is_Type
(Entity
(Choice
)))
2376 Get_Index_Bounds
(Choice
, L
, H
);
2378 (Compile_Time_Known_Value
(L
)
2379 and then Compile_Time_Known_Value
(H
));
2382 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2385 -- Count single component. No other case available
2386 -- since we are handling an aggregate with static
2390 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2391 or else Nkind
(Choice
) = N_Identifier
2392 or else Nkind
(Choice
) = N_Integer_Literal
);
2394 Count_Components
:= Count_Components
+ 1;
2404 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2405 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2407 pragma Assert
(Count_Components
<= Num_Components
);
2409 -- Handle the N_Others choice if it covers several
2412 if Present
(Others_Choice
)
2413 and then (Num_Components
- Count_Components
) > 1
2415 if not Others_Box_Present
then
2417 -- At this stage, if expansion is active, the
2418 -- expression of the others choice has not been
2419 -- analyzed. Hence we generate a duplicate and
2420 -- we analyze it silently to have available the
2421 -- minimum decoration required to collect the
2424 if not Expander_Active
then
2425 Comp_Expr
:= Expression
(Others_Assoc
);
2428 New_Copy_Tree
(Expression
(Others_Assoc
));
2429 Preanalyze_Without_Errors
(Comp_Expr
);
2432 Collect_Identifiers
(Comp_Expr
);
2434 if Writable_Actuals_List
/= No_Elist
then
2436 -- As suggested by Robert, at current stage we
2437 -- report occurrences of this case as warnings.
2440 ("writable function parameter may affect "
2441 & "value in other component because order "
2442 & "of evaluation is unspecified??",
2443 Node
(First_Elmt
(Writable_Actuals_List
)));
2450 -- Handle ancestor part of extension aggregates
2452 if Nkind
(N
) = N_Extension_Aggregate
then
2453 Collect_Identifiers
(Ancestor_Part
(N
));
2456 -- Handle positional associations
2458 if Present
(Expressions
(N
)) then
2459 Comp_Expr
:= First
(Expressions
(N
));
2460 while Present
(Comp_Expr
) loop
2461 if not Is_OK_Static_Expression
(Comp_Expr
) then
2462 Collect_Identifiers
(Comp_Expr
);
2469 -- Handle discrete associations
2471 if Present
(Component_Associations
(N
)) then
2472 Assoc
:= First
(Component_Associations
(N
));
2473 while Present
(Assoc
) loop
2475 if not Box_Present
(Assoc
) then
2476 Choice
:= First
(Choices
(Assoc
));
2477 while Present
(Choice
) loop
2479 -- For now we skip discriminants since it requires
2480 -- performing the analysis in two phases: first one
2481 -- analyzing discriminants and second one analyzing
2482 -- the rest of components since discriminants are
2483 -- evaluated prior to components: too much extra
2484 -- work to detect a corner case???
2486 if Nkind
(Choice
) in N_Has_Entity
2487 and then Present
(Entity
(Choice
))
2488 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2492 elsif Box_Present
(Assoc
) then
2496 if not Analyzed
(Expression
(Assoc
)) then
2498 New_Copy_Tree
(Expression
(Assoc
));
2499 Set_Parent
(Comp_Expr
, Parent
(N
));
2500 Preanalyze_Without_Errors
(Comp_Expr
);
2502 Comp_Expr
:= Expression
(Assoc
);
2505 Collect_Identifiers
(Comp_Expr
);
2521 -- No further action needed if we already reported an error
2523 if Present
(Error_Node
) then
2527 -- Check if some writable argument of a function is referenced
2529 if Writable_Actuals_List
/= No_Elist
2530 and then Identifiers_List
/= No_Elist
2537 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2538 while Present
(Elmt_1
) loop
2539 Elmt_2
:= First_Elmt
(Identifiers_List
);
2540 while Present
(Elmt_2
) loop
2541 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2542 case Nkind
(Parent
(Node
(Elmt_2
))) is
2544 N_Component_Association |
2545 N_Component_Declaration
=>
2547 ("value may be affected by call in other "
2548 & "component because they are evaluated "
2549 & "in unspecified order",
2552 when N_In | N_Not_In
=>
2554 ("value may be affected by call in other "
2555 & "alternative because they are evaluated "
2556 & "in unspecified order",
2561 ("value of actual may be affected by call in "
2562 & "other actual because they are evaluated "
2563 & "in unspecified order",
2575 end Check_Function_Writable_Actuals
;
2577 --------------------------------
2578 -- Check_Implicit_Dereference --
2579 --------------------------------
2581 procedure Check_Implicit_Dereference
(Nam
: Node_Id
; Typ
: Entity_Id
) is
2586 if Ada_Version
< Ada_2012
2587 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2591 elsif not Comes_From_Source
(Nam
) then
2594 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2598 Disc
:= First_Discriminant
(Typ
);
2599 while Present
(Disc
) loop
2600 if Has_Implicit_Dereference
(Disc
) then
2601 Desig
:= Designated_Type
(Etype
(Disc
));
2602 Add_One_Interp
(Nam
, Disc
, Desig
);
2606 Next_Discriminant
(Disc
);
2609 end Check_Implicit_Dereference
;
2611 ----------------------------------
2612 -- Check_Internal_Protected_Use --
2613 ----------------------------------
2615 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2621 while Present
(S
) loop
2622 if S
= Standard_Standard
then
2625 elsif Ekind
(S
) = E_Function
2626 and then Ekind
(Scope
(S
)) = E_Protected_Type
2635 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2637 -- An indirect function call (e.g. a callback within a protected
2638 -- function body) is not statically illegal. If the access type is
2639 -- anonymous and is the type of an access parameter, the scope of Nam
2640 -- will be the protected type, but it is not a protected operation.
2642 if Ekind
(Nam
) = E_Subprogram_Type
2644 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2648 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2650 ("within protected function cannot use protected "
2651 & "procedure in renaming or as generic actual", N
);
2653 elsif Nkind
(N
) = N_Attribute_Reference
then
2655 ("within protected function cannot take access of "
2656 & " protected procedure", N
);
2660 ("within protected function, protected object is constant", N
);
2662 ("\cannot call operation that may modify it", N
);
2665 end Check_Internal_Protected_Use
;
2667 ---------------------------------------
2668 -- Check_Later_Vs_Basic_Declarations --
2669 ---------------------------------------
2671 procedure Check_Later_Vs_Basic_Declarations
2673 During_Parsing
: Boolean)
2675 Body_Sloc
: Source_Ptr
;
2678 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2679 -- Return whether Decl is considered as a declarative item.
2680 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2681 -- When During_Parsing is False, the semantics of SPARK is followed.
2683 -------------------------------
2684 -- Is_Later_Declarative_Item --
2685 -------------------------------
2687 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2689 if Nkind
(Decl
) in N_Later_Decl_Item
then
2692 elsif Nkind
(Decl
) = N_Pragma
then
2695 elsif During_Parsing
then
2698 -- In SPARK, a package declaration is not considered as a later
2699 -- declarative item.
2701 elsif Nkind
(Decl
) = N_Package_Declaration
then
2704 -- In SPARK, a renaming is considered as a later declarative item
2706 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2712 end Is_Later_Declarative_Item
;
2714 -- Start of Check_Later_Vs_Basic_Declarations
2717 Decl
:= First
(Decls
);
2719 -- Loop through sequence of basic declarative items
2721 Outer
: while Present
(Decl
) loop
2722 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2723 and then Nkind
(Decl
) not in N_Body_Stub
2727 -- Once a body is encountered, we only allow later declarative
2728 -- items. The inner loop checks the rest of the list.
2731 Body_Sloc
:= Sloc
(Decl
);
2733 Inner
: while Present
(Decl
) loop
2734 if not Is_Later_Declarative_Item
(Decl
) then
2735 if During_Parsing
then
2736 if Ada_Version
= Ada_83
then
2737 Error_Msg_Sloc
:= Body_Sloc
;
2739 ("(Ada 83) decl cannot appear after body#", Decl
);
2742 Error_Msg_Sloc
:= Body_Sloc
;
2743 Check_SPARK_05_Restriction
2744 ("decl cannot appear after body#", Decl
);
2752 end Check_Later_Vs_Basic_Declarations
;
2754 -------------------------
2755 -- Check_Nested_Access --
2756 -------------------------
2758 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2759 Scop
: constant Entity_Id
:= Current_Scope
;
2760 Current_Subp
: Entity_Id
;
2761 Enclosing
: Entity_Id
;
2764 -- Currently only enabled for VM back-ends for efficiency, should we
2765 -- enable it more systematically ???
2767 -- Check for Is_Imported needs commenting below ???
2769 if VM_Target
/= No_VM
2770 and then Ekind_In
(Ent
, E_Variable
, E_Constant
, E_Loop_Parameter
)
2771 and then Scope
(Ent
) /= Empty
2772 and then not Is_Library_Level_Entity
(Ent
)
2773 and then not Is_Imported
(Ent
)
2775 if Is_Subprogram
(Scop
)
2776 or else Is_Generic_Subprogram
(Scop
)
2777 or else Is_Entry
(Scop
)
2779 Current_Subp
:= Scop
;
2781 Current_Subp
:= Current_Subprogram
;
2784 Enclosing
:= Enclosing_Subprogram
(Ent
);
2786 if Enclosing
/= Empty
and then Enclosing
/= Current_Subp
then
2787 Set_Has_Up_Level_Access
(Ent
, True);
2790 end Check_Nested_Access
;
2792 ---------------------------
2793 -- Check_No_Hidden_State --
2794 ---------------------------
2796 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2797 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2798 -- Determine whether the entity of a package denoted by Pkg has a null
2801 -----------------------------
2802 -- Has_Null_Abstract_State --
2803 -----------------------------
2805 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2806 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2809 -- Check first available state of related package. A null abstract
2810 -- state always appears as the sole element of the state list.
2814 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2815 end Has_Null_Abstract_State
;
2819 Context
: Entity_Id
:= Empty
;
2820 Not_Visible
: Boolean := False;
2823 -- Start of processing for Check_No_Hidden_State
2826 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2828 -- Find the proper context where the object or state appears
2831 while Present
(Scop
) loop
2834 -- Keep track of the context's visibility
2836 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2838 -- Prevent the search from going too far
2840 if Context
= Standard_Standard
then
2843 -- Objects and states that appear immediately within a subprogram or
2844 -- inside a construct nested within a subprogram do not introduce a
2845 -- hidden state. They behave as local variable declarations.
2847 elsif Is_Subprogram
(Context
) then
2850 -- When examining a package body, use the entity of the spec as it
2851 -- carries the abstract state declarations.
2853 elsif Ekind
(Context
) = E_Package_Body
then
2854 Context
:= Spec_Entity
(Context
);
2857 -- Stop the traversal when a package subject to a null abstract state
2860 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2861 and then Has_Null_Abstract_State
(Context
)
2866 Scop
:= Scope
(Scop
);
2869 -- At this point we know that there is at least one package with a null
2870 -- abstract state in visibility. Emit an error message unconditionally
2871 -- if the entity being processed is a state because the placement of the
2872 -- related package is irrelevant. This is not the case for objects as
2873 -- the intermediate context matters.
2875 if Present
(Context
)
2876 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
2878 Error_Msg_N
("cannot introduce hidden state &", Id
);
2879 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
2881 end Check_No_Hidden_State
;
2883 ------------------------------------------
2884 -- Check_Potentially_Blocking_Operation --
2885 ------------------------------------------
2887 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2891 -- N is one of the potentially blocking operations listed in 9.5.1(8).
2892 -- When pragma Detect_Blocking is active, the run time will raise
2893 -- Program_Error. Here we only issue a warning, since we generally
2894 -- support the use of potentially blocking operations in the absence
2897 -- Indirect blocking through a subprogram call cannot be diagnosed
2898 -- statically without interprocedural analysis, so we do not attempt
2901 S
:= Scope
(Current_Scope
);
2902 while Present
(S
) and then S
/= Standard_Standard
loop
2903 if Is_Protected_Type
(S
) then
2905 ("potentially blocking operation in protected operation??", N
);
2911 end Check_Potentially_Blocking_Operation
;
2913 ---------------------------------
2914 -- Check_Result_And_Post_State --
2915 ---------------------------------
2917 procedure Check_Result_And_Post_State
2919 Result_Seen
: in out Boolean)
2921 procedure Check_Expression
(Expr
: Node_Id
);
2922 -- Perform the 'Result and post-state checks on a given expression
2924 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
2925 -- Attempt to find attribute 'Result in a subtree denoted by N
2927 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
2928 -- Determine whether source node N denotes "True" or "False"
2930 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
2931 -- Determine whether a subtree denoted by N mentions any construct that
2932 -- denotes a post-state.
2934 procedure Check_Function_Result
is
2935 new Traverse_Proc
(Is_Function_Result
);
2937 ----------------------
2938 -- Check_Expression --
2939 ----------------------
2941 procedure Check_Expression
(Expr
: Node_Id
) is
2943 if not Is_Trivial_Boolean
(Expr
) then
2944 Check_Function_Result
(Expr
);
2946 if not Mentions_Post_State
(Expr
) then
2947 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
2949 ("contract case refers only to pre-state?T?", Expr
);
2951 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
2953 ("refined postcondition refers only to pre-state?T?",
2958 ("postcondition refers only to pre-state?T?", Prag
);
2962 end Check_Expression
;
2964 ------------------------
2965 -- Is_Function_Result --
2966 ------------------------
2968 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
2970 if Is_Attribute_Result
(N
) then
2971 Result_Seen
:= True;
2974 -- Continue the traversal
2979 end Is_Function_Result
;
2981 ------------------------
2982 -- Is_Trivial_Boolean --
2983 ------------------------
2985 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
2988 Comes_From_Source
(N
)
2989 and then Is_Entity_Name
(N
)
2990 and then (Entity
(N
) = Standard_True
2991 or else Entity
(N
) = Standard_False
);
2992 end Is_Trivial_Boolean
;
2994 -------------------------
2995 -- Mentions_Post_State --
2996 -------------------------
2998 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
2999 Post_State_Seen
: Boolean := False;
3001 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3002 -- Attempt to find a construct that denotes a post-state. If this is
3003 -- the case, set flag Post_State_Seen.
3009 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3013 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3014 Post_State_Seen
:= True;
3017 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3020 -- The entity may be modifiable through an implicit dereference
3023 or else Ekind
(Ent
) in Assignable_Kind
3024 or else (Is_Access_Type
(Etype
(Ent
))
3025 and then Nkind
(Parent
(N
)) = N_Selected_Component
)
3027 Post_State_Seen
:= True;
3031 elsif Nkind
(N
) = N_Attribute_Reference
then
3032 if Attribute_Name
(N
) = Name_Old
then
3035 elsif Attribute_Name
(N
) = Name_Result
then
3036 Post_State_Seen
:= True;
3044 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3046 -- Start of processing for Mentions_Post_State
3049 Find_Post_State
(N
);
3051 return Post_State_Seen
;
3052 end Mentions_Post_State
;
3056 Expr
: constant Node_Id
:=
3057 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
3058 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3061 -- Start of processing for Check_Result_And_Post_State
3064 -- Examine all consequences
3066 if Nam
= Name_Contract_Cases
then
3067 CCase
:= First
(Component_Associations
(Expr
));
3068 while Present
(CCase
) loop
3069 Check_Expression
(Expression
(CCase
));
3074 -- Examine the expression of a postcondition
3076 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
, Name_Refined_Post
));
3077 Check_Expression
(Expr
);
3079 end Check_Result_And_Post_State
;
3081 ---------------------------------
3082 -- Check_SPARK_Mode_In_Generic --
3083 ---------------------------------
3085 procedure Check_SPARK_Mode_In_Generic
(N
: Node_Id
) is
3089 -- Try to find aspect SPARK_Mode and flag it as illegal
3091 if Has_Aspects
(N
) then
3092 Aspect
:= First
(Aspect_Specifications
(N
));
3093 while Present
(Aspect
) loop
3094 if Get_Aspect_Id
(Aspect
) = Aspect_SPARK_Mode
then
3095 Error_Msg_Name_1
:= Name_SPARK_Mode
;
3097 ("incorrect placement of aspect % on a generic", Aspect
);
3104 end Check_SPARK_Mode_In_Generic
;
3106 ------------------------------
3107 -- Check_Unprotected_Access --
3108 ------------------------------
3110 procedure Check_Unprotected_Access
3114 Cont_Encl_Typ
: Entity_Id
;
3115 Pref_Encl_Typ
: Entity_Id
;
3117 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
3118 -- Check whether Obj is a private component of a protected object.
3119 -- Return the protected type where the component resides, Empty
3122 function Is_Public_Operation
return Boolean;
3123 -- Verify that the enclosing operation is callable from outside the
3124 -- protected object, to minimize false positives.
3126 ------------------------------
3127 -- Enclosing_Protected_Type --
3128 ------------------------------
3130 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
3132 if Is_Entity_Name
(Obj
) then
3134 Ent
: Entity_Id
:= Entity
(Obj
);
3137 -- The object can be a renaming of a private component, use
3138 -- the original record component.
3140 if Is_Prival
(Ent
) then
3141 Ent
:= Prival_Link
(Ent
);
3144 if Is_Protected_Type
(Scope
(Ent
)) then
3150 -- For indexed and selected components, recursively check the prefix
3152 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
3153 return Enclosing_Protected_Type
(Prefix
(Obj
));
3155 -- The object does not denote a protected component
3160 end Enclosing_Protected_Type
;
3162 -------------------------
3163 -- Is_Public_Operation --
3164 -------------------------
3166 function Is_Public_Operation
return Boolean is
3172 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
3173 if Scope
(S
) = Pref_Encl_Typ
then
3174 E
:= First_Entity
(Pref_Encl_Typ
);
3176 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
3190 end Is_Public_Operation
;
3192 -- Start of processing for Check_Unprotected_Access
3195 if Nkind
(Expr
) = N_Attribute_Reference
3196 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
3198 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
3199 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
3201 -- Check whether we are trying to export a protected component to a
3202 -- context with an equal or lower access level.
3204 if Present
(Pref_Encl_Typ
)
3205 and then No
(Cont_Encl_Typ
)
3206 and then Is_Public_Operation
3207 and then Scope_Depth
(Pref_Encl_Typ
) >=
3208 Object_Access_Level
(Context
)
3211 ("??possible unprotected access to protected data", Expr
);
3214 end Check_Unprotected_Access
;
3216 ------------------------
3217 -- Collect_Interfaces --
3218 ------------------------
3220 procedure Collect_Interfaces
3222 Ifaces_List
: out Elist_Id
;
3223 Exclude_Parents
: Boolean := False;
3224 Use_Full_View
: Boolean := True)
3226 procedure Collect
(Typ
: Entity_Id
);
3227 -- Subsidiary subprogram used to traverse the whole list
3228 -- of directly and indirectly implemented interfaces
3234 procedure Collect
(Typ
: Entity_Id
) is
3235 Ancestor
: Entity_Id
;
3243 -- Handle private types
3246 and then Is_Private_Type
(Typ
)
3247 and then Present
(Full_View
(Typ
))
3249 Full_T
:= Full_View
(Typ
);
3252 -- Include the ancestor if we are generating the whole list of
3253 -- abstract interfaces.
3255 if Etype
(Full_T
) /= Typ
3257 -- Protect the frontend against wrong sources. For example:
3260 -- type A is tagged null record;
3261 -- type B is new A with private;
3262 -- type C is new A with private;
3264 -- type B is new C with null record;
3265 -- type C is new B with null record;
3268 and then Etype
(Full_T
) /= T
3270 Ancestor
:= Etype
(Full_T
);
3273 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
3274 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
3278 -- Traverse the graph of ancestor interfaces
3280 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
3281 Id
:= First
(Abstract_Interface_List
(Full_T
));
3282 while Present
(Id
) loop
3283 Iface
:= Etype
(Id
);
3285 -- Protect against wrong uses. For example:
3286 -- type I is interface;
3287 -- type O is tagged null record;
3288 -- type Wrong is new I and O with null record; -- ERROR
3290 if Is_Interface
(Iface
) then
3292 and then Etype
(T
) /= T
3293 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
3298 Append_Unique_Elmt
(Iface
, Ifaces_List
);
3307 -- Start of processing for Collect_Interfaces
3310 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
3311 Ifaces_List
:= New_Elmt_List
;
3313 end Collect_Interfaces
;
3315 ----------------------------------
3316 -- Collect_Interface_Components --
3317 ----------------------------------
3319 procedure Collect_Interface_Components
3320 (Tagged_Type
: Entity_Id
;
3321 Components_List
: out Elist_Id
)
3323 procedure Collect
(Typ
: Entity_Id
);
3324 -- Subsidiary subprogram used to climb to the parents
3330 procedure Collect
(Typ
: Entity_Id
) is
3331 Tag_Comp
: Entity_Id
;
3332 Parent_Typ
: Entity_Id
;
3335 -- Handle private types
3337 if Present
(Full_View
(Etype
(Typ
))) then
3338 Parent_Typ
:= Full_View
(Etype
(Typ
));
3340 Parent_Typ
:= Etype
(Typ
);
3343 if Parent_Typ
/= Typ
3345 -- Protect the frontend against wrong sources. For example:
3348 -- type A is tagged null record;
3349 -- type B is new A with private;
3350 -- type C is new A with private;
3352 -- type B is new C with null record;
3353 -- type C is new B with null record;
3356 and then Parent_Typ
/= Tagged_Type
3358 Collect
(Parent_Typ
);
3361 -- Collect the components containing tags of secondary dispatch
3364 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
3365 while Present
(Tag_Comp
) loop
3366 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
3367 Append_Elmt
(Tag_Comp
, Components_List
);
3369 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
3373 -- Start of processing for Collect_Interface_Components
3376 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
3377 and then Is_Tagged_Type
(Tagged_Type
));
3379 Components_List
:= New_Elmt_List
;
3380 Collect
(Tagged_Type
);
3381 end Collect_Interface_Components
;
3383 -----------------------------
3384 -- Collect_Interfaces_Info --
3385 -----------------------------
3387 procedure Collect_Interfaces_Info
3389 Ifaces_List
: out Elist_Id
;
3390 Components_List
: out Elist_Id
;
3391 Tags_List
: out Elist_Id
)
3393 Comps_List
: Elist_Id
;
3394 Comp_Elmt
: Elmt_Id
;
3395 Comp_Iface
: Entity_Id
;
3396 Iface_Elmt
: Elmt_Id
;
3399 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3400 -- Search for the secondary tag associated with the interface type
3401 -- Iface that is implemented by T.
3407 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3410 if not Is_CPP_Class
(T
) then
3411 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3413 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3417 and then Is_Tag
(Node
(ADT
))
3418 and then Related_Type
(Node
(ADT
)) /= Iface
3420 -- Skip secondary dispatch table referencing thunks to user
3421 -- defined primitives covered by this interface.
3423 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3426 -- Skip secondary dispatch tables of Ada types
3428 if not Is_CPP_Class
(T
) then
3430 -- Skip secondary dispatch table referencing thunks to
3431 -- predefined primitives.
3433 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3436 -- Skip secondary dispatch table referencing user-defined
3437 -- primitives covered by this interface.
3439 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3442 -- Skip secondary dispatch table referencing predefined
3445 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3450 pragma Assert
(Is_Tag
(Node
(ADT
)));
3454 -- Start of processing for Collect_Interfaces_Info
3457 Collect_Interfaces
(T
, Ifaces_List
);
3458 Collect_Interface_Components
(T
, Comps_List
);
3460 -- Search for the record component and tag associated with each
3461 -- interface type of T.
3463 Components_List
:= New_Elmt_List
;
3464 Tags_List
:= New_Elmt_List
;
3466 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3467 while Present
(Iface_Elmt
) loop
3468 Iface
:= Node
(Iface_Elmt
);
3470 -- Associate the primary tag component and the primary dispatch table
3471 -- with all the interfaces that are parents of T
3473 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3474 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3475 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3477 -- Otherwise search for the tag component and secondary dispatch
3481 Comp_Elmt
:= First_Elmt
(Comps_List
);
3482 while Present
(Comp_Elmt
) loop
3483 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3485 if Comp_Iface
= Iface
3486 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3488 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3489 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3493 Next_Elmt
(Comp_Elmt
);
3495 pragma Assert
(Present
(Comp_Elmt
));
3498 Next_Elmt
(Iface_Elmt
);
3500 end Collect_Interfaces_Info
;
3502 ---------------------
3503 -- Collect_Parents --
3504 ---------------------
3506 procedure Collect_Parents
3508 List
: out Elist_Id
;
3509 Use_Full_View
: Boolean := True)
3511 Current_Typ
: Entity_Id
:= T
;
3512 Parent_Typ
: Entity_Id
;
3515 List
:= New_Elmt_List
;
3517 -- No action if the if the type has no parents
3519 if T
= Etype
(T
) then
3524 Parent_Typ
:= Etype
(Current_Typ
);
3526 if Is_Private_Type
(Parent_Typ
)
3527 and then Present
(Full_View
(Parent_Typ
))
3528 and then Use_Full_View
3530 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3533 Append_Elmt
(Parent_Typ
, List
);
3535 exit when Parent_Typ
= Current_Typ
;
3536 Current_Typ
:= Parent_Typ
;
3538 end Collect_Parents
;
3540 ----------------------------------
3541 -- Collect_Primitive_Operations --
3542 ----------------------------------
3544 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3545 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3546 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3547 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3551 Is_Type_In_Pkg
: Boolean;
3552 Formal_Derived
: Boolean := False;
3555 function Match
(E
: Entity_Id
) return Boolean;
3556 -- True if E's base type is B_Type, or E is of an anonymous access type
3557 -- and the base type of its designated type is B_Type.
3563 function Match
(E
: Entity_Id
) return Boolean is
3564 Etyp
: Entity_Id
:= Etype
(E
);
3567 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
3568 Etyp
:= Designated_Type
(Etyp
);
3571 -- In Ada 2012 a primitive operation may have a formal of an
3572 -- incomplete view of the parent type.
3574 return Base_Type
(Etyp
) = B_Type
3576 (Ada_Version
>= Ada_2012
3577 and then Ekind
(Etyp
) = E_Incomplete_Type
3578 and then Full_View
(Etyp
) = B_Type
);
3581 -- Start of processing for Collect_Primitive_Operations
3584 -- For tagged types, the primitive operations are collected as they
3585 -- are declared, and held in an explicit list which is simply returned.
3587 if Is_Tagged_Type
(B_Type
) then
3588 return Primitive_Operations
(B_Type
);
3590 -- An untagged generic type that is a derived type inherits the
3591 -- primitive operations of its parent type. Other formal types only
3592 -- have predefined operators, which are not explicitly represented.
3594 elsif Is_Generic_Type
(B_Type
) then
3595 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
3596 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
3597 N_Formal_Derived_Type_Definition
3599 Formal_Derived
:= True;
3601 return New_Elmt_List
;
3605 Op_List
:= New_Elmt_List
;
3607 if B_Scope
= Standard_Standard
then
3608 if B_Type
= Standard_String
then
3609 Append_Elmt
(Standard_Op_Concat
, Op_List
);
3611 elsif B_Type
= Standard_Wide_String
then
3612 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
3618 -- Locate the primitive subprograms of the type
3621 -- The primitive operations appear after the base type, except
3622 -- if the derivation happens within the private part of B_Scope
3623 -- and the type is a private type, in which case both the type
3624 -- and some primitive operations may appear before the base
3625 -- type, and the list of candidates starts after the type.
3627 if In_Open_Scopes
(B_Scope
)
3628 and then Scope
(T
) = B_Scope
3629 and then In_Private_Part
(B_Scope
)
3631 Id
:= Next_Entity
(T
);
3633 -- In Ada 2012, If the type has an incomplete partial view, there
3634 -- may be primitive operations declared before the full view, so
3635 -- we need to start scanning from the incomplete view, which is
3636 -- earlier on the entity chain.
3638 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
3639 and then Present
(Incomplete_View
(Parent
(B_Type
)))
3641 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
3644 Id
:= Next_Entity
(B_Type
);
3647 -- Set flag if this is a type in a package spec
3650 Is_Package_Or_Generic_Package
(B_Scope
)
3652 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
3655 while Present
(Id
) loop
3657 -- Test whether the result type or any of the parameter types of
3658 -- each subprogram following the type match that type when the
3659 -- type is declared in a package spec, is a derived type, or the
3660 -- subprogram is marked as primitive. (The Is_Primitive test is
3661 -- needed to find primitives of nonderived types in declarative
3662 -- parts that happen to override the predefined "=" operator.)
3664 -- Note that generic formal subprograms are not considered to be
3665 -- primitive operations and thus are never inherited.
3667 if Is_Overloadable
(Id
)
3668 and then (Is_Type_In_Pkg
3669 or else Is_Derived_Type
(B_Type
)
3670 or else Is_Primitive
(Id
))
3671 and then Nkind
(Parent
(Parent
(Id
)))
3672 not in N_Formal_Subprogram_Declaration
3680 Formal
:= First_Formal
(Id
);
3681 while Present
(Formal
) loop
3682 if Match
(Formal
) then
3687 Next_Formal
(Formal
);
3691 -- For a formal derived type, the only primitives are the ones
3692 -- inherited from the parent type. Operations appearing in the
3693 -- package declaration are not primitive for it.
3696 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
3698 -- In the special case of an equality operator aliased to
3699 -- an overriding dispatching equality belonging to the same
3700 -- type, we don't include it in the list of primitives.
3701 -- This avoids inheriting multiple equality operators when
3702 -- deriving from untagged private types whose full type is
3703 -- tagged, which can otherwise cause ambiguities. Note that
3704 -- this should only happen for this kind of untagged parent
3705 -- type, since normally dispatching operations are inherited
3706 -- using the type's Primitive_Operations list.
3708 if Chars
(Id
) = Name_Op_Eq
3709 and then Is_Dispatching_Operation
(Id
)
3710 and then Present
(Alias
(Id
))
3711 and then Present
(Overridden_Operation
(Alias
(Id
)))
3712 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3713 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3717 -- Include the subprogram in the list of primitives
3720 Append_Elmt
(Id
, Op_List
);
3727 -- For a type declared in System, some of its operations may
3728 -- appear in the target-specific extension to System.
3731 and then B_Scope
= RTU_Entity
(System
)
3732 and then Present_System_Aux
3734 B_Scope
:= System_Aux_Id
;
3735 Id
:= First_Entity
(System_Aux_Id
);
3741 end Collect_Primitive_Operations
;
3743 -----------------------------------
3744 -- Compile_Time_Constraint_Error --
3745 -----------------------------------
3747 function Compile_Time_Constraint_Error
3750 Ent
: Entity_Id
:= Empty
;
3751 Loc
: Source_Ptr
:= No_Location
;
3752 Warn
: Boolean := False) return Node_Id
3754 Msgc
: String (1 .. Msg
'Length + 3);
3755 -- Copy of message, with room for possible ?? or << and ! at end
3761 -- Start of processing for Compile_Time_Constraint_Error
3764 -- If this is a warning, convert it into an error if we are in code
3765 -- subject to SPARK_Mode being set ON.
3767 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3769 -- A static constraint error in an instance body is not a fatal error.
3770 -- we choose to inhibit the message altogether, because there is no
3771 -- obvious node (for now) on which to post it. On the other hand the
3772 -- offending node must be replaced with a constraint_error in any case.
3774 -- No messages are generated if we already posted an error on this node
3776 if not Error_Posted
(N
) then
3777 if Loc
/= No_Location
then
3783 -- Copy message to Msgc, converting any ? in the message into
3784 -- < instead, so that we have an error in GNATprove mode.
3788 for J
in 1 .. Msgl
loop
3789 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
3792 Msgc
(J
) := Msg
(J
);
3796 -- Message is a warning, even in Ada 95 case
3798 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
3801 -- In Ada 83, all messages are warnings. In the private part and
3802 -- the body of an instance, constraint_checks are only warnings.
3803 -- We also make this a warning if the Warn parameter is set.
3806 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
3814 elsif In_Instance_Not_Visible
then
3821 -- Otherwise we have a real error message (Ada 95 static case)
3822 -- and we make this an unconditional message. Note that in the
3823 -- warning case we do not make the message unconditional, it seems
3824 -- quite reasonable to delete messages like this (about exceptions
3825 -- that will be raised) in dead code.
3833 -- One more test, skip the warning if the related expression is
3834 -- statically unevaluated, since we don't want to warn about what
3835 -- will happen when something is evaluated if it never will be
3838 if not Is_Statically_Unevaluated
(N
) then
3839 Error_Msg_Warn
:= SPARK_Mode
/= On
;
3841 if Present
(Ent
) then
3842 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
3844 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
3849 -- Check whether the context is an Init_Proc
3851 if Inside_Init_Proc
then
3853 Conc_Typ
: constant Entity_Id
:=
3854 Corresponding_Concurrent_Type
3855 (Entity
(Parameter_Type
(First
3856 (Parameter_Specifications
3857 (Parent
(Current_Scope
))))));
3860 -- Don't complain if the corresponding concurrent type
3861 -- doesn't come from source (i.e. a single task/protected
3864 if Present
(Conc_Typ
)
3865 and then not Comes_From_Source
(Conc_Typ
)
3868 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3871 if GNATprove_Mode
then
3873 ("\& would have been raised for objects of this "
3874 & "type", N
, Standard_Constraint_Error
, Eloc
);
3877 ("\& will be raised for objects of this type??",
3878 N
, Standard_Constraint_Error
, Eloc
);
3884 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
3888 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
3889 Set_Error_Posted
(N
);
3895 end Compile_Time_Constraint_Error
;
3897 -----------------------
3898 -- Conditional_Delay --
3899 -----------------------
3901 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
3903 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
3904 Set_Has_Delayed_Freeze
(New_Ent
);
3906 end Conditional_Delay
;
3908 ----------------------------
3909 -- Contains_Refined_State --
3910 ----------------------------
3912 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
3913 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
3914 -- Determine whether a dependency list mentions a state with a visible
3917 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
3918 -- Determine whether a global list mentions a state with a visible
3921 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
3922 -- Determine whether Item is a reference to an abstract state with a
3923 -- visible refinement.
3925 -----------------------------
3926 -- Has_State_In_Dependency --
3927 -----------------------------
3929 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
3934 -- A null dependency list does not mention any states
3936 if Nkind
(List
) = N_Null
then
3939 -- Dependency clauses appear as component associations of an
3942 elsif Nkind
(List
) = N_Aggregate
3943 and then Present
(Component_Associations
(List
))
3945 Clause
:= First
(Component_Associations
(List
));
3946 while Present
(Clause
) loop
3948 -- Inspect the outputs of a dependency clause
3950 Output
:= First
(Choices
(Clause
));
3951 while Present
(Output
) loop
3952 if Is_Refined_State
(Output
) then
3959 -- Inspect the outputs of a dependency clause
3961 if Is_Refined_State
(Expression
(Clause
)) then
3968 -- If we get here, then none of the dependency clauses mention a
3969 -- state with visible refinement.
3973 -- An illegal pragma managed to sneak in
3976 raise Program_Error
;
3978 end Has_State_In_Dependency
;
3980 -------------------------
3981 -- Has_State_In_Global --
3982 -------------------------
3984 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
3988 -- A null global list does not mention any states
3990 if Nkind
(List
) = N_Null
then
3993 -- Simple global list or moded global list declaration
3995 elsif Nkind
(List
) = N_Aggregate
then
3997 -- The declaration of a simple global list appear as a collection
4000 if Present
(Expressions
(List
)) then
4001 Item
:= First
(Expressions
(List
));
4002 while Present
(Item
) loop
4003 if Is_Refined_State
(Item
) then
4010 -- The declaration of a moded global list appears as a collection
4011 -- of component associations where individual choices denote
4015 Item
:= First
(Component_Associations
(List
));
4016 while Present
(Item
) loop
4017 if Has_State_In_Global
(Expression
(Item
)) then
4025 -- If we get here, then the simple/moded global list did not
4026 -- mention any states with a visible refinement.
4030 -- Single global item declaration
4032 elsif Is_Entity_Name
(List
) then
4033 return Is_Refined_State
(List
);
4035 -- An illegal pragma managed to sneak in
4038 raise Program_Error
;
4040 end Has_State_In_Global
;
4042 ----------------------
4043 -- Is_Refined_State --
4044 ----------------------
4046 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
4048 Item_Id
: Entity_Id
;
4051 if Nkind
(Item
) = N_Null
then
4054 -- States cannot be subject to attribute 'Result. This case arises
4055 -- in dependency relations.
4057 elsif Nkind
(Item
) = N_Attribute_Reference
4058 and then Attribute_Name
(Item
) = Name_Result
4062 -- Multiple items appear as an aggregate. This case arises in
4063 -- dependency relations.
4065 elsif Nkind
(Item
) = N_Aggregate
4066 and then Present
(Expressions
(Item
))
4068 Elmt
:= First
(Expressions
(Item
));
4069 while Present
(Elmt
) loop
4070 if Is_Refined_State
(Elmt
) then
4077 -- If we get here, then none of the inputs or outputs reference a
4078 -- state with visible refinement.
4085 Item_Id
:= Entity_Of
(Item
);
4089 and then Ekind
(Item_Id
) = E_Abstract_State
4090 and then Has_Visible_Refinement
(Item_Id
);
4092 end Is_Refined_State
;
4096 Arg
: constant Node_Id
:=
4097 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
4098 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4100 -- Start of processing for Contains_Refined_State
4103 if Nam
= Name_Depends
then
4104 return Has_State_In_Dependency
(Arg
);
4106 else pragma Assert
(Nam
= Name_Global
);
4107 return Has_State_In_Global
(Arg
);
4109 end Contains_Refined_State
;
4111 -------------------------
4112 -- Copy_Component_List --
4113 -------------------------
4115 function Copy_Component_List
4117 Loc
: Source_Ptr
) return List_Id
4120 Comps
: constant List_Id
:= New_List
;
4123 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
4124 while Present
(Comp
) loop
4125 if Comes_From_Source
(Comp
) then
4127 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
4130 Make_Component_Declaration
(Loc
,
4131 Defining_Identifier
=>
4132 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
4133 Component_Definition
=>
4135 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
4139 Next_Component
(Comp
);
4143 end Copy_Component_List
;
4145 -------------------------
4146 -- Copy_Parameter_List --
4147 -------------------------
4149 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
4150 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
4155 if No
(First_Formal
(Subp_Id
)) then
4159 Formal
:= First_Formal
(Subp_Id
);
4160 while Present
(Formal
) loop
4162 (Make_Parameter_Specification
(Loc
,
4163 Defining_Identifier
=>
4164 Make_Defining_Identifier
(Sloc
(Formal
),
4165 Chars
=> Chars
(Formal
)),
4166 In_Present
=> In_Present
(Parent
(Formal
)),
4167 Out_Present
=> Out_Present
(Parent
(Formal
)),
4169 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4171 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
4174 Next_Formal
(Formal
);
4179 end Copy_Parameter_List
;
4181 --------------------------------
4182 -- Corresponding_Generic_Type --
4183 --------------------------------
4185 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
4191 if not Is_Generic_Actual_Type
(T
) then
4194 -- If the actual is the actual of an enclosing instance, resolution
4195 -- was correct in the generic.
4197 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
4198 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
4200 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
4207 if Is_Wrapper_Package
(Inst
) then
4208 Inst
:= Related_Instance
(Inst
);
4213 (Specification
(Unit_Declaration_Node
(Inst
)));
4215 -- Generic actual has the same name as the corresponding formal
4217 Typ
:= First_Entity
(Gen
);
4218 while Present
(Typ
) loop
4219 if Chars
(Typ
) = Chars
(T
) then
4228 end Corresponding_Generic_Type
;
4230 --------------------
4231 -- Current_Entity --
4232 --------------------
4234 -- The currently visible definition for a given identifier is the
4235 -- one most chained at the start of the visibility chain, i.e. the
4236 -- one that is referenced by the Node_Id value of the name of the
4237 -- given identifier.
4239 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
4241 return Get_Name_Entity_Id
(Chars
(N
));
4244 -----------------------------
4245 -- Current_Entity_In_Scope --
4246 -----------------------------
4248 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
4250 CS
: constant Entity_Id
:= Current_Scope
;
4252 Transient_Case
: constant Boolean := Scope_Is_Transient
;
4255 E
:= Get_Name_Entity_Id
(Chars
(N
));
4257 and then Scope
(E
) /= CS
4258 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
4264 end Current_Entity_In_Scope
;
4270 function Current_Scope
return Entity_Id
is
4272 if Scope_Stack
.Last
= -1 then
4273 return Standard_Standard
;
4276 C
: constant Entity_Id
:=
4277 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
4282 return Standard_Standard
;
4288 ------------------------
4289 -- Current_Subprogram --
4290 ------------------------
4292 function Current_Subprogram
return Entity_Id
is
4293 Scop
: constant Entity_Id
:= Current_Scope
;
4295 if Is_Subprogram
(Scop
) or else Is_Generic_Subprogram
(Scop
) then
4298 return Enclosing_Subprogram
(Scop
);
4300 end Current_Subprogram
;
4302 ----------------------------------
4303 -- Deepest_Type_Access_Level --
4304 ----------------------------------
4306 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
4308 if Ekind
(Typ
) = E_Anonymous_Access_Type
4309 and then not Is_Local_Anonymous_Access
(Typ
)
4310 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
4312 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4316 Scope_Depth
(Enclosing_Dynamic_Scope
4317 (Defining_Identifier
4318 (Associated_Node_For_Itype
(Typ
))));
4320 -- For generic formal type, return Int'Last (infinite).
4321 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4323 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
4324 return UI_From_Int
(Int
'Last);
4327 return Type_Access_Level
(Typ
);
4329 end Deepest_Type_Access_Level
;
4331 ---------------------
4332 -- Defining_Entity --
4333 ---------------------
4335 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4336 K
: constant Node_Kind
:= Nkind
(N
);
4337 Err
: Entity_Id
:= Empty
;
4342 N_Subprogram_Declaration |
4343 N_Abstract_Subprogram_Declaration |
4345 N_Package_Declaration |
4346 N_Subprogram_Renaming_Declaration |
4347 N_Subprogram_Body_Stub |
4348 N_Generic_Subprogram_Declaration |
4349 N_Generic_Package_Declaration |
4350 N_Formal_Subprogram_Declaration |
4351 N_Expression_Function
4353 return Defining_Entity
(Specification
(N
));
4356 N_Component_Declaration |
4357 N_Defining_Program_Unit_Name |
4358 N_Discriminant_Specification |
4360 N_Entry_Declaration |
4361 N_Entry_Index_Specification |
4362 N_Exception_Declaration |
4363 N_Exception_Renaming_Declaration |
4364 N_Formal_Object_Declaration |
4365 N_Formal_Package_Declaration |
4366 N_Formal_Type_Declaration |
4367 N_Full_Type_Declaration |
4368 N_Implicit_Label_Declaration |
4369 N_Incomplete_Type_Declaration |
4370 N_Loop_Parameter_Specification |
4371 N_Number_Declaration |
4372 N_Object_Declaration |
4373 N_Object_Renaming_Declaration |
4374 N_Package_Body_Stub |
4375 N_Parameter_Specification |
4376 N_Private_Extension_Declaration |
4377 N_Private_Type_Declaration |
4379 N_Protected_Body_Stub |
4380 N_Protected_Type_Declaration |
4381 N_Single_Protected_Declaration |
4382 N_Single_Task_Declaration |
4383 N_Subtype_Declaration |
4386 N_Task_Type_Declaration
4388 return Defining_Identifier
(N
);
4391 return Defining_Entity
(Proper_Body
(N
));
4394 N_Function_Instantiation |
4395 N_Function_Specification |
4396 N_Generic_Function_Renaming_Declaration |
4397 N_Generic_Package_Renaming_Declaration |
4398 N_Generic_Procedure_Renaming_Declaration |
4400 N_Package_Instantiation |
4401 N_Package_Renaming_Declaration |
4402 N_Package_Specification |
4403 N_Procedure_Instantiation |
4404 N_Procedure_Specification
4407 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
4410 if Nkind
(Nam
) in N_Entity
then
4413 -- For Error, make up a name and attach to declaration
4414 -- so we can continue semantic analysis
4416 elsif Nam
= Error
then
4417 Err
:= Make_Temporary
(Sloc
(N
), 'T');
4418 Set_Defining_Unit_Name
(N
, Err
);
4422 -- If not an entity, get defining identifier
4425 return Defining_Identifier
(Nam
);
4433 return Entity
(Identifier
(N
));
4436 raise Program_Error
;
4439 end Defining_Entity
;
4441 --------------------------
4442 -- Denotes_Discriminant --
4443 --------------------------
4445 function Denotes_Discriminant
4447 Check_Concurrent
: Boolean := False) return Boolean
4452 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
4458 -- If we are checking for a protected type, the discriminant may have
4459 -- been rewritten as the corresponding discriminal of the original type
4460 -- or of the corresponding concurrent record, depending on whether we
4461 -- are in the spec or body of the protected type.
4463 return Ekind
(E
) = E_Discriminant
4466 and then Ekind
(E
) = E_In_Parameter
4467 and then Present
(Discriminal_Link
(E
))
4469 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
4471 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
4473 end Denotes_Discriminant
;
4475 -------------------------
4476 -- Denotes_Same_Object --
4477 -------------------------
4479 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
4480 Obj1
: Node_Id
:= A1
;
4481 Obj2
: Node_Id
:= A2
;
4483 function Has_Prefix
(N
: Node_Id
) return Boolean;
4484 -- Return True if N has attribute Prefix
4486 function Is_Renaming
(N
: Node_Id
) return Boolean;
4487 -- Return true if N names a renaming entity
4489 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
4490 -- For renamings, return False if the prefix of any dereference within
4491 -- the renamed object_name is a variable, or any expression within the
4492 -- renamed object_name contains references to variables or calls on
4493 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4499 function Has_Prefix
(N
: Node_Id
) return Boolean is
4503 N_Attribute_Reference
,
4505 N_Explicit_Dereference
,
4506 N_Indexed_Component
,
4508 N_Selected_Component
,
4516 function Is_Renaming
(N
: Node_Id
) return Boolean is
4518 return Is_Entity_Name
(N
)
4519 and then Present
(Renamed_Entity
(Entity
(N
)));
4522 -----------------------
4523 -- Is_Valid_Renaming --
4524 -----------------------
4526 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
4528 function Check_Renaming
(N
: Node_Id
) return Boolean;
4529 -- Recursive function used to traverse all the prefixes of N
4531 function Check_Renaming
(N
: Node_Id
) return Boolean is
4534 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
4539 if Nkind
(N
) = N_Indexed_Component
then
4544 Indx
:= First
(Expressions
(N
));
4545 while Present
(Indx
) loop
4546 if not Is_OK_Static_Expression
(Indx
) then
4555 if Has_Prefix
(N
) then
4557 P
: constant Node_Id
:= Prefix
(N
);
4560 if Nkind
(N
) = N_Explicit_Dereference
4561 and then Is_Variable
(P
)
4565 elsif Is_Entity_Name
(P
)
4566 and then Ekind
(Entity
(P
)) = E_Function
4570 elsif Nkind
(P
) = N_Function_Call
then
4574 -- Recursion to continue traversing the prefix of the
4575 -- renaming expression
4577 return Check_Renaming
(P
);
4584 -- Start of processing for Is_Valid_Renaming
4587 return Check_Renaming
(N
);
4588 end Is_Valid_Renaming
;
4590 -- Start of processing for Denotes_Same_Object
4593 -- Both names statically denote the same stand-alone object or parameter
4594 -- (RM 6.4.1(6.5/3))
4596 if Is_Entity_Name
(Obj1
)
4597 and then Is_Entity_Name
(Obj2
)
4598 and then Entity
(Obj1
) = Entity
(Obj2
)
4603 -- For renamings, the prefix of any dereference within the renamed
4604 -- object_name is not a variable, and any expression within the
4605 -- renamed object_name contains no references to variables nor
4606 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4608 if Is_Renaming
(Obj1
) then
4609 if Is_Valid_Renaming
(Obj1
) then
4610 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
4616 if Is_Renaming
(Obj2
) then
4617 if Is_Valid_Renaming
(Obj2
) then
4618 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
4624 -- No match if not same node kind (such cases are handled by
4625 -- Denotes_Same_Prefix)
4627 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
4630 -- After handling valid renamings, one of the two names statically
4631 -- denoted a renaming declaration whose renamed object_name is known
4632 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4634 elsif Is_Entity_Name
(Obj1
) then
4635 if Is_Entity_Name
(Obj2
) then
4636 return Entity
(Obj1
) = Entity
(Obj2
);
4641 -- Both names are selected_components, their prefixes are known to
4642 -- denote the same object, and their selector_names denote the same
4643 -- component (RM 6.4.1(6.6/3)
4645 elsif Nkind
(Obj1
) = N_Selected_Component
then
4646 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4648 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
4650 -- Both names are dereferences and the dereferenced names are known to
4651 -- denote the same object (RM 6.4.1(6.7/3))
4653 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
4654 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
4656 -- Both names are indexed_components, their prefixes are known to denote
4657 -- the same object, and each of the pairs of corresponding index values
4658 -- are either both static expressions with the same static value or both
4659 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4661 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4662 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4670 Indx1
:= First
(Expressions
(Obj1
));
4671 Indx2
:= First
(Expressions
(Obj2
));
4672 while Present
(Indx1
) loop
4674 -- Indexes must denote the same static value or same object
4676 if Is_OK_Static_Expression
(Indx1
) then
4677 if not Is_OK_Static_Expression
(Indx2
) then
4680 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4684 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4696 -- Both names are slices, their prefixes are known to denote the same
4697 -- object, and the two slices have statically matching index constraints
4698 -- (RM 6.4.1(6.9/3))
4700 elsif Nkind
(Obj1
) = N_Slice
4701 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4704 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4707 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4708 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4710 -- Check whether bounds are statically identical. There is no
4711 -- attempt to detect partial overlap of slices.
4713 return Denotes_Same_Object
(Lo1
, Lo2
)
4714 and then Denotes_Same_Object
(Hi1
, Hi2
);
4717 -- In the recursion, literals appear as indexes
4719 elsif Nkind
(Obj1
) = N_Integer_Literal
4721 Nkind
(Obj2
) = N_Integer_Literal
4723 return Intval
(Obj1
) = Intval
(Obj2
);
4728 end Denotes_Same_Object
;
4730 -------------------------
4731 -- Denotes_Same_Prefix --
4732 -------------------------
4734 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
4737 if Is_Entity_Name
(A1
) then
4738 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
4739 and then not Is_Access_Type
(Etype
(A1
))
4741 return Denotes_Same_Object
(A1
, Prefix
(A2
))
4742 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
4747 elsif Is_Entity_Name
(A2
) then
4748 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
4750 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4752 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
4755 Root1
, Root2
: Node_Id
;
4756 Depth1
, Depth2
: Int
:= 0;
4759 Root1
:= Prefix
(A1
);
4760 while not Is_Entity_Name
(Root1
) loop
4762 (Root1
, N_Selected_Component
, N_Indexed_Component
)
4766 Root1
:= Prefix
(Root1
);
4769 Depth1
:= Depth1
+ 1;
4772 Root2
:= Prefix
(A2
);
4773 while not Is_Entity_Name
(Root2
) loop
4775 (Root2
, N_Selected_Component
, N_Indexed_Component
)
4779 Root2
:= Prefix
(Root2
);
4782 Depth2
:= Depth2
+ 1;
4785 -- If both have the same depth and they do not denote the same
4786 -- object, they are disjoint and no warning is needed.
4788 if Depth1
= Depth2
then
4791 elsif Depth1
> Depth2
then
4792 Root1
:= Prefix
(A1
);
4793 for I
in 1 .. Depth1
- Depth2
- 1 loop
4794 Root1
:= Prefix
(Root1
);
4797 return Denotes_Same_Object
(Root1
, A2
);
4800 Root2
:= Prefix
(A2
);
4801 for I
in 1 .. Depth2
- Depth1
- 1 loop
4802 Root2
:= Prefix
(Root2
);
4805 return Denotes_Same_Object
(A1
, Root2
);
4812 end Denotes_Same_Prefix
;
4814 ----------------------
4815 -- Denotes_Variable --
4816 ----------------------
4818 function Denotes_Variable
(N
: Node_Id
) return Boolean is
4820 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
4821 end Denotes_Variable
;
4823 -----------------------------
4824 -- Depends_On_Discriminant --
4825 -----------------------------
4827 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
4832 Get_Index_Bounds
(N
, L
, H
);
4833 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
4834 end Depends_On_Discriminant
;
4836 -------------------------
4837 -- Designate_Same_Unit --
4838 -------------------------
4840 function Designate_Same_Unit
4842 Name2
: Node_Id
) return Boolean
4844 K1
: constant Node_Kind
:= Nkind
(Name1
);
4845 K2
: constant Node_Kind
:= Nkind
(Name2
);
4847 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
4848 -- Returns the parent unit name node of a defining program unit name
4849 -- or the prefix if N is a selected component or an expanded name.
4851 function Select_Node
(N
: Node_Id
) return Node_Id
;
4852 -- Returns the defining identifier node of a defining program unit
4853 -- name or the selector node if N is a selected component or an
4860 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
4862 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4874 function Select_Node
(N
: Node_Id
) return Node_Id
is
4876 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
4877 return Defining_Identifier
(N
);
4880 return Selector_Name
(N
);
4884 -- Start of processing for Designate_Next_Unit
4887 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
4889 (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
4891 return Chars
(Name1
) = Chars
(Name2
);
4894 (K1
= N_Expanded_Name
or else
4895 K1
= N_Selected_Component
or else
4896 K1
= N_Defining_Program_Unit_Name
)
4898 (K2
= N_Expanded_Name
or else
4899 K2
= N_Selected_Component
or else
4900 K2
= N_Defining_Program_Unit_Name
)
4903 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
4905 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
4910 end Designate_Same_Unit
;
4912 ------------------------------------------
4913 -- function Dynamic_Accessibility_Level --
4914 ------------------------------------------
4916 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
4918 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
4920 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
4921 -- Construct an integer literal representing an accessibility level
4922 -- with its type set to Natural.
4924 ------------------------
4925 -- Make_Level_Literal --
4926 ------------------------
4928 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
4929 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
4931 Set_Etype
(Result
, Standard_Natural
);
4933 end Make_Level_Literal
;
4935 -- Start of processing for Dynamic_Accessibility_Level
4938 if Is_Entity_Name
(Expr
) then
4941 if Present
(Renamed_Object
(E
)) then
4942 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
4945 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
4946 if Present
(Extra_Accessibility
(E
)) then
4947 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
4952 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
4954 case Nkind
(Expr
) is
4956 -- For access discriminant, the level of the enclosing object
4958 when N_Selected_Component
=>
4959 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
4960 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
4961 E_Anonymous_Access_Type
4963 return Make_Level_Literal
(Object_Access_Level
(Expr
));
4966 when N_Attribute_Reference
=>
4967 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
4969 -- For X'Access, the level of the prefix X
4971 when Attribute_Access
=>
4972 return Make_Level_Literal
4973 (Object_Access_Level
(Prefix
(Expr
)));
4975 -- Treat the unchecked attributes as library-level
4977 when Attribute_Unchecked_Access |
4978 Attribute_Unrestricted_Access
=>
4979 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
4981 -- No other access-valued attributes
4984 raise Program_Error
;
4989 -- Unimplemented: depends on context. As an actual parameter where
4990 -- formal type is anonymous, use
4991 -- Scope_Depth (Current_Scope) + 1.
4992 -- For other cases, see 3.10.2(14/3) and following. ???
4996 when N_Type_Conversion
=>
4997 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
4999 -- Handle type conversions introduced for a rename of an
5000 -- Ada 2012 stand-alone object of an anonymous access type.
5002 return Dynamic_Accessibility_Level
(Expression
(Expr
));
5009 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
5010 end Dynamic_Accessibility_Level
;
5012 -----------------------------------
5013 -- Effective_Extra_Accessibility --
5014 -----------------------------------
5016 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
5018 if Present
(Renamed_Object
(Id
))
5019 and then Is_Entity_Name
(Renamed_Object
(Id
))
5021 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
5023 return Extra_Accessibility
(Id
);
5025 end Effective_Extra_Accessibility
;
5027 -----------------------------
5028 -- Effective_Reads_Enabled --
5029 -----------------------------
5031 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
5033 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
5034 end Effective_Reads_Enabled
;
5036 ------------------------------
5037 -- Effective_Writes_Enabled --
5038 ------------------------------
5040 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
5042 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
5043 end Effective_Writes_Enabled
;
5045 ------------------------------
5046 -- Enclosing_Comp_Unit_Node --
5047 ------------------------------
5049 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
5050 Current_Node
: Node_Id
;
5054 while Present
(Current_Node
)
5055 and then Nkind
(Current_Node
) /= N_Compilation_Unit
5057 Current_Node
:= Parent
(Current_Node
);
5060 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
5063 return Current_Node
;
5065 end Enclosing_Comp_Unit_Node
;
5067 --------------------------
5068 -- Enclosing_CPP_Parent --
5069 --------------------------
5071 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
5072 Parent_Typ
: Entity_Id
:= Typ
;
5075 while not Is_CPP_Class
(Parent_Typ
)
5076 and then Etype
(Parent_Typ
) /= Parent_Typ
5078 Parent_Typ
:= Etype
(Parent_Typ
);
5080 if Is_Private_Type
(Parent_Typ
) then
5081 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5085 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
5087 end Enclosing_CPP_Parent
;
5089 ----------------------------
5090 -- Enclosing_Generic_Body --
5091 ----------------------------
5093 function Enclosing_Generic_Body
5094 (N
: Node_Id
) return Node_Id
5102 while Present
(P
) loop
5103 if Nkind
(P
) = N_Package_Body
5104 or else Nkind
(P
) = N_Subprogram_Body
5106 Spec
:= Corresponding_Spec
(P
);
5108 if Present
(Spec
) then
5109 Decl
:= Unit_Declaration_Node
(Spec
);
5111 if Nkind
(Decl
) = N_Generic_Package_Declaration
5112 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5123 end Enclosing_Generic_Body
;
5125 ----------------------------
5126 -- Enclosing_Generic_Unit --
5127 ----------------------------
5129 function Enclosing_Generic_Unit
5130 (N
: Node_Id
) return Node_Id
5138 while Present
(P
) loop
5139 if Nkind
(P
) = N_Generic_Package_Declaration
5140 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
5144 elsif Nkind
(P
) = N_Package_Body
5145 or else Nkind
(P
) = N_Subprogram_Body
5147 Spec
:= Corresponding_Spec
(P
);
5149 if Present
(Spec
) then
5150 Decl
:= Unit_Declaration_Node
(Spec
);
5152 if Nkind
(Decl
) = N_Generic_Package_Declaration
5153 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5164 end Enclosing_Generic_Unit
;
5166 -------------------------------
5167 -- Enclosing_Lib_Unit_Entity --
5168 -------------------------------
5170 function Enclosing_Lib_Unit_Entity
5171 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
5173 Unit_Entity
: Entity_Id
;
5176 -- Look for enclosing library unit entity by following scope links.
5177 -- Equivalent to, but faster than indexing through the scope stack.
5180 while (Present
(Scope
(Unit_Entity
))
5181 and then Scope
(Unit_Entity
) /= Standard_Standard
)
5182 and not Is_Child_Unit
(Unit_Entity
)
5184 Unit_Entity
:= Scope
(Unit_Entity
);
5188 end Enclosing_Lib_Unit_Entity
;
5190 -----------------------
5191 -- Enclosing_Package --
5192 -----------------------
5194 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
5195 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5198 if Dynamic_Scope
= Standard_Standard
then
5199 return Standard_Standard
;
5201 elsif Dynamic_Scope
= Empty
then
5204 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
5207 return Dynamic_Scope
;
5210 return Enclosing_Package
(Dynamic_Scope
);
5212 end Enclosing_Package
;
5214 --------------------------
5215 -- Enclosing_Subprogram --
5216 --------------------------
5218 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5219 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5222 if Dynamic_Scope
= Standard_Standard
then
5225 elsif Dynamic_Scope
= Empty
then
5228 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
5229 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
5231 elsif Ekind
(Dynamic_Scope
) = E_Block
5232 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
5234 return Enclosing_Subprogram
(Dynamic_Scope
);
5236 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
5237 return Get_Task_Body_Procedure
(Dynamic_Scope
);
5239 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
5240 and then Present
(Full_View
(Dynamic_Scope
))
5241 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
5243 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
5245 -- No body is generated if the protected operation is eliminated
5247 elsif Convention
(Dynamic_Scope
) = Convention_Protected
5248 and then not Is_Eliminated
(Dynamic_Scope
)
5249 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
5251 return Protected_Body_Subprogram
(Dynamic_Scope
);
5254 return Dynamic_Scope
;
5256 end Enclosing_Subprogram
;
5258 ------------------------
5259 -- Ensure_Freeze_Node --
5260 ------------------------
5262 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
5265 if No
(Freeze_Node
(E
)) then
5266 FN
:= Make_Freeze_Entity
(Sloc
(E
));
5267 Set_Has_Delayed_Freeze
(E
);
5268 Set_Freeze_Node
(E
, FN
);
5269 Set_Access_Types_To_Process
(FN
, No_Elist
);
5270 Set_TSS_Elist
(FN
, No_Elist
);
5273 end Ensure_Freeze_Node
;
5279 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5280 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5281 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5282 S
: constant Entity_Id
:= Current_Scope
;
5285 Generate_Definition
(Def_Id
);
5287 -- Add new name to current scope declarations. Check for duplicate
5288 -- declaration, which may or may not be a genuine error.
5292 -- Case of previous entity entered because of a missing declaration
5293 -- or else a bad subtype indication. Best is to use the new entity,
5294 -- and make the previous one invisible.
5296 if Etype
(E
) = Any_Type
then
5297 Set_Is_Immediately_Visible
(E
, False);
5299 -- Case of renaming declaration constructed for package instances.
5300 -- if there is an explicit declaration with the same identifier,
5301 -- the renaming is not immediately visible any longer, but remains
5302 -- visible through selected component notation.
5304 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
5305 and then not Comes_From_Source
(E
)
5307 Set_Is_Immediately_Visible
(E
, False);
5309 -- The new entity may be the package renaming, which has the same
5310 -- same name as a generic formal which has been seen already.
5312 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
5313 and then not Comes_From_Source
(Def_Id
)
5315 Set_Is_Immediately_Visible
(E
, False);
5317 -- For a fat pointer corresponding to a remote access to subprogram,
5318 -- we use the same identifier as the RAS type, so that the proper
5319 -- name appears in the stub. This type is only retrieved through
5320 -- the RAS type and never by visibility, and is not added to the
5321 -- visibility list (see below).
5323 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
5324 and then Ekind
(Def_Id
) = E_Record_Type
5325 and then Present
(Corresponding_Remote_Type
(Def_Id
))
5329 -- Case of an implicit operation or derived literal. The new entity
5330 -- hides the implicit one, which is removed from all visibility,
5331 -- i.e. the entity list of its scope, and homonym chain of its name.
5333 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
5334 or else Is_Internal
(E
)
5338 Prev_Vis
: Entity_Id
;
5339 Decl
: constant Node_Id
:= Parent
(E
);
5342 -- If E is an implicit declaration, it cannot be the first
5343 -- entity in the scope.
5345 Prev
:= First_Entity
(Current_Scope
);
5346 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
5352 -- If E is not on the entity chain of the current scope,
5353 -- it is an implicit declaration in the generic formal
5354 -- part of a generic subprogram. When analyzing the body,
5355 -- the generic formals are visible but not on the entity
5356 -- chain of the subprogram. The new entity will become
5357 -- the visible one in the body.
5360 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
5364 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5366 if No
(Next_Entity
(Prev
)) then
5367 Set_Last_Entity
(Current_Scope
, Prev
);
5370 if E
= Current_Entity
(E
) then
5374 Prev_Vis
:= Current_Entity
(E
);
5375 while Homonym
(Prev_Vis
) /= E
loop
5376 Prev_Vis
:= Homonym
(Prev_Vis
);
5380 if Present
(Prev_Vis
) then
5382 -- Skip E in the visibility chain
5384 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5387 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5392 -- This section of code could use a comment ???
5394 elsif Present
(Etype
(E
))
5395 and then Is_Concurrent_Type
(Etype
(E
))
5400 -- If the homograph is a protected component renaming, it should not
5401 -- be hiding the current entity. Such renamings are treated as weak
5404 elsif Is_Prival
(E
) then
5405 Set_Is_Immediately_Visible
(E
, False);
5407 -- In this case the current entity is a protected component renaming.
5408 -- Perform minimal decoration by setting the scope and return since
5409 -- the prival should not be hiding other visible entities.
5411 elsif Is_Prival
(Def_Id
) then
5412 Set_Scope
(Def_Id
, Current_Scope
);
5415 -- Analogous to privals, the discriminal generated for an entry index
5416 -- parameter acts as a weak declaration. Perform minimal decoration
5417 -- to avoid bogus errors.
5419 elsif Is_Discriminal
(Def_Id
)
5420 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
5422 Set_Scope
(Def_Id
, Current_Scope
);
5425 -- In the body or private part of an instance, a type extension may
5426 -- introduce a component with the same name as that of an actual. The
5427 -- legality rule is not enforced, but the semantics of the full type
5428 -- with two components of same name are not clear at this point???
5430 elsif In_Instance_Not_Visible
then
5433 -- When compiling a package body, some child units may have become
5434 -- visible. They cannot conflict with local entities that hide them.
5436 elsif Is_Child_Unit
(E
)
5437 and then In_Open_Scopes
(Scope
(E
))
5438 and then not Is_Immediately_Visible
(E
)
5442 -- Conversely, with front-end inlining we may compile the parent body
5443 -- first, and a child unit subsequently. The context is now the
5444 -- parent spec, and body entities are not visible.
5446 elsif Is_Child_Unit
(Def_Id
)
5447 and then Is_Package_Body_Entity
(E
)
5448 and then not In_Package_Body
(Current_Scope
)
5452 -- Case of genuine duplicate declaration
5455 Error_Msg_Sloc
:= Sloc
(E
);
5457 -- If the previous declaration is an incomplete type declaration
5458 -- this may be an attempt to complete it with a private type. The
5459 -- following avoids confusing cascaded errors.
5461 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
5462 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
5465 ("incomplete type cannot be completed with a private " &
5466 "declaration", Parent
(Def_Id
));
5467 Set_Is_Immediately_Visible
(E
, False);
5468 Set_Full_View
(E
, Def_Id
);
5470 -- An inherited component of a record conflicts with a new
5471 -- discriminant. The discriminant is inserted first in the scope,
5472 -- but the error should be posted on it, not on the component.
5474 elsif Ekind
(E
) = E_Discriminant
5475 and then Present
(Scope
(Def_Id
))
5476 and then Scope
(Def_Id
) /= Current_Scope
5478 Error_Msg_Sloc
:= Sloc
(Def_Id
);
5479 Error_Msg_N
("& conflicts with declaration#", E
);
5482 -- If the name of the unit appears in its own context clause, a
5483 -- dummy package with the name has already been created, and the
5484 -- error emitted. Try to continue quietly.
5486 elsif Error_Posted
(E
)
5487 and then Sloc
(E
) = No_Location
5488 and then Nkind
(Parent
(E
)) = N_Package_Specification
5489 and then Current_Scope
= Standard_Standard
5491 Set_Scope
(Def_Id
, Current_Scope
);
5495 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
5497 -- Avoid cascaded messages with duplicate components in
5500 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
5505 if Nkind
(Parent
(Parent
(Def_Id
))) =
5506 N_Generic_Subprogram_Declaration
5508 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
5510 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
5513 -- If entity is in standard, then we are in trouble, because it
5514 -- means that we have a library package with a duplicated name.
5515 -- That's hard to recover from, so abort.
5517 if S
= Standard_Standard
then
5518 raise Unrecoverable_Error
;
5520 -- Otherwise we continue with the declaration. Having two
5521 -- identical declarations should not cause us too much trouble.
5529 -- If we fall through, declaration is OK, at least OK enough to continue
5531 -- If Def_Id is a discriminant or a record component we are in the midst
5532 -- of inheriting components in a derived record definition. Preserve
5533 -- their Ekind and Etype.
5535 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
5538 -- If a type is already set, leave it alone (happens when a type
5539 -- declaration is reanalyzed following a call to the optimizer).
5541 elsif Present
(Etype
(Def_Id
)) then
5544 -- Otherwise, the kind E_Void insures that premature uses of the entity
5545 -- will be detected. Any_Type insures that no cascaded errors will occur
5548 Set_Ekind
(Def_Id
, E_Void
);
5549 Set_Etype
(Def_Id
, Any_Type
);
5552 -- Inherited discriminants and components in derived record types are
5553 -- immediately visible. Itypes are not.
5555 -- Unless the Itype is for a record type with a corresponding remote
5556 -- type (what is that about, it was not commented ???)
5558 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
5560 ((not Is_Record_Type
(Def_Id
)
5561 or else No
(Corresponding_Remote_Type
(Def_Id
)))
5562 and then not Is_Itype
(Def_Id
))
5564 Set_Is_Immediately_Visible
(Def_Id
);
5565 Set_Current_Entity
(Def_Id
);
5568 Set_Homonym
(Def_Id
, C
);
5569 Append_Entity
(Def_Id
, S
);
5570 Set_Public_Status
(Def_Id
);
5572 -- Declaring a homonym is not allowed in SPARK ...
5574 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
5576 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
5577 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
5578 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
5581 -- ... unless the new declaration is in a subprogram, and the
5582 -- visible declaration is a variable declaration or a parameter
5583 -- specification outside that subprogram.
5585 if Present
(Enclosing_Subp
)
5586 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
5587 N_Parameter_Specification
)
5588 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
5592 -- ... or the new declaration is in a package, and the visible
5593 -- declaration occurs outside that package.
5595 elsif Present
(Enclosing_Pack
)
5596 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
5600 -- ... or the new declaration is a component declaration in a
5601 -- record type definition.
5603 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
5606 -- Don't issue error for non-source entities
5608 elsif Comes_From_Source
(Def_Id
)
5609 and then Comes_From_Source
(C
)
5611 Error_Msg_Sloc
:= Sloc
(C
);
5612 Check_SPARK_05_Restriction
5613 ("redeclaration of identifier &#", Def_Id
);
5618 -- Warn if new entity hides an old one
5620 if Warn_On_Hiding
and then Present
(C
)
5622 -- Don't warn for record components since they always have a well
5623 -- defined scope which does not confuse other uses. Note that in
5624 -- some cases, Ekind has not been set yet.
5626 and then Ekind
(C
) /= E_Component
5627 and then Ekind
(C
) /= E_Discriminant
5628 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
5629 and then Ekind
(Def_Id
) /= E_Component
5630 and then Ekind
(Def_Id
) /= E_Discriminant
5631 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
5633 -- Don't warn for one character variables. It is too common to use
5634 -- such variables as locals and will just cause too many false hits.
5636 and then Length_Of_Name
(Chars
(C
)) /= 1
5638 -- Don't warn for non-source entities
5640 and then Comes_From_Source
(C
)
5641 and then Comes_From_Source
(Def_Id
)
5643 -- Don't warn unless entity in question is in extended main source
5645 and then In_Extended_Main_Source_Unit
(Def_Id
)
5647 -- Finally, the hidden entity must be either immediately visible or
5648 -- use visible (i.e. from a used package).
5651 (Is_Immediately_Visible
(C
)
5653 Is_Potentially_Use_Visible
(C
))
5655 Error_Msg_Sloc
:= Sloc
(C
);
5656 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
5664 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
5670 if Is_Entity_Name
(N
) then
5673 -- Follow a possible chain of renamings to reach the root renamed
5676 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5677 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5678 Id
:= Entity
(Renamed_Object
(Id
));
5689 --------------------------
5690 -- Explain_Limited_Type --
5691 --------------------------
5693 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5697 -- For array, component type must be limited
5699 if Is_Array_Type
(T
) then
5700 Error_Msg_Node_2
:= T
;
5702 ("\component type& of type& is limited", N
, Component_Type
(T
));
5703 Explain_Limited_Type
(Component_Type
(T
), N
);
5705 elsif Is_Record_Type
(T
) then
5707 -- No need for extra messages if explicit limited record
5709 if Is_Limited_Record
(Base_Type
(T
)) then
5713 -- Otherwise find a limited component. Check only components that
5714 -- come from source, or inherited components that appear in the
5715 -- source of the ancestor.
5717 C
:= First_Component
(T
);
5718 while Present
(C
) loop
5719 if Is_Limited_Type
(Etype
(C
))
5721 (Comes_From_Source
(C
)
5723 (Present
(Original_Record_Component
(C
))
5725 Comes_From_Source
(Original_Record_Component
(C
))))
5727 Error_Msg_Node_2
:= T
;
5728 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
5729 Explain_Limited_Type
(Etype
(C
), N
);
5736 -- The type may be declared explicitly limited, even if no component
5737 -- of it is limited, in which case we fall out of the loop.
5740 end Explain_Limited_Type
;
5746 procedure Find_Actual
5748 Formal
: out Entity_Id
;
5751 Parnt
: constant Node_Id
:= Parent
(N
);
5755 if Nkind_In
(Parnt
, N_Indexed_Component
, N_Selected_Component
)
5756 and then N
= Prefix
(Parnt
)
5758 Find_Actual
(Parnt
, Formal
, Call
);
5761 elsif Nkind
(Parnt
) = N_Parameter_Association
5762 and then N
= Explicit_Actual_Parameter
(Parnt
)
5764 Call
:= Parent
(Parnt
);
5766 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
5775 -- If we have a call to a subprogram look for the parameter. Note that
5776 -- we exclude overloaded calls, since we don't know enough to be sure
5777 -- of giving the right answer in this case.
5779 if Nkind_In
(Call
, N_Function_Call
, N_Procedure_Call_Statement
)
5780 and then Is_Entity_Name
(Name
(Call
))
5781 and then Present
(Entity
(Name
(Call
)))
5782 and then Is_Overloadable
(Entity
(Name
(Call
)))
5783 and then not Is_Overloaded
(Name
(Call
))
5785 -- Fall here if we are definitely a parameter
5787 Actual
:= First_Actual
(Call
);
5788 Formal
:= First_Formal
(Entity
(Name
(Call
)));
5789 while Present
(Formal
) and then Present
(Actual
) loop
5793 -- An actual that is the prefix in a prefixed call may have
5794 -- been rewritten in the call, after the deferred reference
5795 -- was collected. Check if sloc and kinds and names match.
5797 elsif Sloc
(Actual
) = Sloc
(N
)
5798 and then Nkind
(Actual
) = N_Identifier
5799 and then Nkind
(Actual
) = Nkind
(N
)
5800 and then Chars
(Actual
) = Chars
(N
)
5805 Actual
:= Next_Actual
(Actual
);
5806 Formal
:= Next_Formal
(Formal
);
5811 -- Fall through here if we did not find matching actual
5817 ---------------------------
5818 -- Find_Body_Discriminal --
5819 ---------------------------
5821 function Find_Body_Discriminal
5822 (Spec_Discriminant
: Entity_Id
) return Entity_Id
5828 -- If expansion is suppressed, then the scope can be the concurrent type
5829 -- itself rather than a corresponding concurrent record type.
5831 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
5832 Tsk
:= Scope
(Spec_Discriminant
);
5835 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
5837 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
5840 -- Find discriminant of original concurrent type, and use its current
5841 -- discriminal, which is the renaming within the task/protected body.
5843 Disc
:= First_Discriminant
(Tsk
);
5844 while Present
(Disc
) loop
5845 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
5846 return Discriminal
(Disc
);
5849 Next_Discriminant
(Disc
);
5852 -- That loop should always succeed in finding a matching entry and
5853 -- returning. Fatal error if not.
5855 raise Program_Error
;
5856 end Find_Body_Discriminal
;
5858 -------------------------------------
5859 -- Find_Corresponding_Discriminant --
5860 -------------------------------------
5862 function Find_Corresponding_Discriminant
5864 Typ
: Entity_Id
) return Entity_Id
5866 Par_Disc
: Entity_Id
;
5867 Old_Disc
: Entity_Id
;
5868 New_Disc
: Entity_Id
;
5871 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
5873 -- The original type may currently be private, and the discriminant
5874 -- only appear on its full view.
5876 if Is_Private_Type
(Scope
(Par_Disc
))
5877 and then not Has_Discriminants
(Scope
(Par_Disc
))
5878 and then Present
(Full_View
(Scope
(Par_Disc
)))
5880 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
5882 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
5885 if Is_Class_Wide_Type
(Typ
) then
5886 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
5888 New_Disc
:= First_Discriminant
(Typ
);
5891 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
5892 if Old_Disc
= Par_Disc
then
5896 Next_Discriminant
(Old_Disc
);
5897 Next_Discriminant
(New_Disc
);
5900 -- Should always find it
5902 raise Program_Error
;
5903 end Find_Corresponding_Discriminant
;
5905 ----------------------------------
5906 -- Find_Enclosing_Iterator_Loop --
5907 ----------------------------------
5909 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
5914 -- Traverse the scope chain looking for an iterator loop. Such loops are
5915 -- usually transformed into blocks, hence the use of Original_Node.
5918 while Present
(S
) and then S
/= Standard_Standard
loop
5919 if Ekind
(S
) = E_Loop
5920 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
5922 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
5924 if Nkind
(Constr
) = N_Loop_Statement
5925 and then Present
(Iteration_Scheme
(Constr
))
5926 and then Nkind
(Iterator_Specification
5927 (Iteration_Scheme
(Constr
))) =
5928 N_Iterator_Specification
5938 end Find_Enclosing_Iterator_Loop
;
5940 ------------------------------------
5941 -- Find_Loop_In_Conditional_Block --
5942 ------------------------------------
5944 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
5950 if Nkind
(Stmt
) = N_If_Statement
then
5951 Stmt
:= First
(Then_Statements
(Stmt
));
5954 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
5956 -- Inspect the statements of the conditional block. In general the loop
5957 -- should be the first statement in the statement sequence of the block,
5958 -- but the finalization machinery may have introduced extra object
5961 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
5962 while Present
(Stmt
) loop
5963 if Nkind
(Stmt
) = N_Loop_Statement
then
5970 -- The expansion of attribute 'Loop_Entry produced a malformed block
5972 raise Program_Error
;
5973 end Find_Loop_In_Conditional_Block
;
5975 --------------------------
5976 -- Find_Overlaid_Entity --
5977 --------------------------
5979 procedure Find_Overlaid_Entity
5981 Ent
: out Entity_Id
;
5987 -- We are looking for one of the two following forms:
5989 -- for X'Address use Y'Address
5993 -- Const : constant Address := expr;
5995 -- for X'Address use Const;
5997 -- In the second case, the expr is either Y'Address, or recursively a
5998 -- constant that eventually references Y'Address.
6003 if Nkind
(N
) = N_Attribute_Definition_Clause
6004 and then Chars
(N
) = Name_Address
6006 Expr
:= Expression
(N
);
6008 -- This loop checks the form of the expression for Y'Address,
6009 -- using recursion to deal with intermediate constants.
6012 -- Check for Y'Address
6014 if Nkind
(Expr
) = N_Attribute_Reference
6015 and then Attribute_Name
(Expr
) = Name_Address
6017 Expr
:= Prefix
(Expr
);
6020 -- Check for Const where Const is a constant entity
6022 elsif Is_Entity_Name
(Expr
)
6023 and then Ekind
(Entity
(Expr
)) = E_Constant
6025 Expr
:= Constant_Value
(Entity
(Expr
));
6027 -- Anything else does not need checking
6034 -- This loop checks the form of the prefix for an entity, using
6035 -- recursion to deal with intermediate components.
6038 -- Check for Y where Y is an entity
6040 if Is_Entity_Name
(Expr
) then
6041 Ent
:= Entity
(Expr
);
6044 -- Check for components
6047 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
6049 Expr
:= Prefix
(Expr
);
6052 -- Anything else does not need checking
6059 end Find_Overlaid_Entity
;
6061 -------------------------
6062 -- Find_Parameter_Type --
6063 -------------------------
6065 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
6067 if Nkind
(Param
) /= N_Parameter_Specification
then
6070 -- For an access parameter, obtain the type from the formal entity
6071 -- itself, because access to subprogram nodes do not carry a type.
6072 -- Shouldn't we always use the formal entity ???
6074 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
6075 return Etype
(Defining_Identifier
(Param
));
6078 return Etype
(Parameter_Type
(Param
));
6080 end Find_Parameter_Type
;
6082 -----------------------------------
6083 -- Find_Placement_In_State_Space --
6084 -----------------------------------
6086 procedure Find_Placement_In_State_Space
6087 (Item_Id
: Entity_Id
;
6088 Placement
: out State_Space_Kind
;
6089 Pack_Id
: out Entity_Id
)
6091 Context
: Entity_Id
;
6094 -- Assume that the item does not appear in the state space of a package
6096 Placement
:= Not_In_Package
;
6099 -- Climb the scope stack and examine the enclosing context
6101 Context
:= Scope
(Item_Id
);
6102 while Present
(Context
) and then Context
/= Standard_Standard
loop
6103 if Ekind
(Context
) = E_Package
then
6106 -- A package body is a cut off point for the traversal as the item
6107 -- cannot be visible to the outside from this point on. Note that
6108 -- this test must be done first as a body is also classified as a
6111 if In_Package_Body
(Context
) then
6112 Placement
:= Body_State_Space
;
6115 -- The private part of a package is a cut off point for the
6116 -- traversal as the item cannot be visible to the outside from
6119 elsif In_Private_Part
(Context
) then
6120 Placement
:= Private_State_Space
;
6123 -- When the item appears in the visible state space of a package,
6124 -- continue to climb the scope stack as this may not be the final
6128 Placement
:= Visible_State_Space
;
6130 -- The visible state space of a child unit acts as the proper
6131 -- placement of an item.
6133 if Is_Child_Unit
(Context
) then
6138 -- The item or its enclosing package appear in a construct that has
6142 Placement
:= Not_In_Package
;
6146 Context
:= Scope
(Context
);
6148 end Find_Placement_In_State_Space
;
6150 ------------------------
6151 -- Find_Specific_Type --
6152 ------------------------
6154 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
6155 Typ
: Entity_Id
:= Root_Type
(CW
);
6158 if Ekind
(Typ
) = E_Incomplete_Type
then
6159 if From_Limited_With
(Typ
) then
6160 Typ
:= Non_Limited_View
(Typ
);
6162 Typ
:= Full_View
(Typ
);
6166 if Is_Private_Type
(Typ
)
6167 and then not Is_Tagged_Type
(Typ
)
6168 and then Present
(Full_View
(Typ
))
6170 return Full_View
(Typ
);
6174 end Find_Specific_Type
;
6176 -----------------------------
6177 -- Find_Static_Alternative --
6178 -----------------------------
6180 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
6181 Expr
: constant Node_Id
:= Expression
(N
);
6182 Val
: constant Uint
:= Expr_Value
(Expr
);
6187 Alt
:= First
(Alternatives
(N
));
6190 if Nkind
(Alt
) /= N_Pragma
then
6191 Choice
:= First
(Discrete_Choices
(Alt
));
6192 while Present
(Choice
) loop
6194 -- Others choice, always matches
6196 if Nkind
(Choice
) = N_Others_Choice
then
6199 -- Range, check if value is in the range
6201 elsif Nkind
(Choice
) = N_Range
then
6203 Val
>= Expr_Value
(Low_Bound
(Choice
))
6205 Val
<= Expr_Value
(High_Bound
(Choice
));
6207 -- Choice is a subtype name. Note that we know it must
6208 -- be a static subtype, since otherwise it would have
6209 -- been diagnosed as illegal.
6211 elsif Is_Entity_Name
(Choice
) and then Is_Type
(Entity
(Choice
))
6213 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
6214 Assume_Valid
=> False);
6216 -- Choice is a subtype indication
6218 elsif Nkind
(Choice
) = N_Subtype_Indication
then
6220 C
: constant Node_Id
:= Constraint
(Choice
);
6221 R
: constant Node_Id
:= Range_Expression
(C
);
6225 Val
>= Expr_Value
(Low_Bound
(R
))
6227 Val
<= Expr_Value
(High_Bound
(R
));
6230 -- Choice is a simple expression
6233 exit Search
when Val
= Expr_Value
(Choice
);
6241 pragma Assert
(Present
(Alt
));
6244 -- The above loop *must* terminate by finding a match, since
6245 -- we know the case statement is valid, and the value of the
6246 -- expression is known at compile time. When we fall out of
6247 -- the loop, Alt points to the alternative that we know will
6248 -- be selected at run time.
6251 end Find_Static_Alternative
;
6257 function First_Actual
(Node
: Node_Id
) return Node_Id
is
6261 if No
(Parameter_Associations
(Node
)) then
6265 N
:= First
(Parameter_Associations
(Node
));
6267 if Nkind
(N
) = N_Parameter_Association
then
6268 return First_Named_Actual
(Node
);
6274 -----------------------
6275 -- Gather_Components --
6276 -----------------------
6278 procedure Gather_Components
6280 Comp_List
: Node_Id
;
6281 Governed_By
: List_Id
;
6283 Report_Errors
: out Boolean)
6287 Discrete_Choice
: Node_Id
;
6288 Comp_Item
: Node_Id
;
6290 Discrim
: Entity_Id
;
6291 Discrim_Name
: Node_Id
;
6292 Discrim_Value
: Node_Id
;
6295 Report_Errors
:= False;
6297 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
6300 elsif Present
(Component_Items
(Comp_List
)) then
6301 Comp_Item
:= First
(Component_Items
(Comp_List
));
6307 while Present
(Comp_Item
) loop
6309 -- Skip the tag of a tagged record, the interface tags, as well
6310 -- as all items that are not user components (anonymous types,
6311 -- rep clauses, Parent field, controller field).
6313 if Nkind
(Comp_Item
) = N_Component_Declaration
then
6315 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
6317 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
6318 Append_Elmt
(Comp
, Into
);
6326 if No
(Variant_Part
(Comp_List
)) then
6329 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
6330 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
6333 -- Look for the discriminant that governs this variant part.
6334 -- The discriminant *must* be in the Governed_By List
6336 Assoc
:= First
(Governed_By
);
6337 Find_Constraint
: loop
6338 Discrim
:= First
(Choices
(Assoc
));
6339 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
6340 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
6342 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
6343 Chars
(Discrim_Name
))
6344 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
6345 = Chars
(Discrim_Name
);
6347 if No
(Next
(Assoc
)) then
6348 if not Is_Constrained
(Typ
)
6349 and then Is_Derived_Type
(Typ
)
6350 and then Present
(Stored_Constraint
(Typ
))
6352 -- If the type is a tagged type with inherited discriminants,
6353 -- use the stored constraint on the parent in order to find
6354 -- the values of discriminants that are otherwise hidden by an
6355 -- explicit constraint. Renamed discriminants are handled in
6358 -- If several parent discriminants are renamed by a single
6359 -- discriminant of the derived type, the call to obtain the
6360 -- Corresponding_Discriminant field only retrieves the last
6361 -- of them. We recover the constraint on the others from the
6362 -- Stored_Constraint as well.
6369 D
:= First_Discriminant
(Etype
(Typ
));
6370 C
:= First_Elmt
(Stored_Constraint
(Typ
));
6371 while Present
(D
) and then Present
(C
) loop
6372 if Chars
(Discrim_Name
) = Chars
(D
) then
6373 if Is_Entity_Name
(Node
(C
))
6374 and then Entity
(Node
(C
)) = Entity
(Discrim
)
6376 -- D is renamed by Discrim, whose value is given in
6383 Make_Component_Association
(Sloc
(Typ
),
6385 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
6386 Duplicate_Subexpr_No_Checks
(Node
(C
)));
6388 exit Find_Constraint
;
6391 Next_Discriminant
(D
);
6398 if No
(Next
(Assoc
)) then
6399 Error_Msg_NE
(" missing value for discriminant&",
6400 First
(Governed_By
), Discrim_Name
);
6401 Report_Errors
:= True;
6406 end loop Find_Constraint
;
6408 Discrim_Value
:= Expression
(Assoc
);
6410 if not Is_OK_Static_Expression
(Discrim_Value
) then
6412 ("value for discriminant & must be static!",
6413 Discrim_Value
, Discrim
);
6414 Why_Not_Static
(Discrim_Value
);
6415 Report_Errors
:= True;
6419 Search_For_Discriminant_Value
: declare
6425 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
6428 Find_Discrete_Value
: while Present
(Variant
) loop
6429 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
6430 while Present
(Discrete_Choice
) loop
6431 exit Find_Discrete_Value
when
6432 Nkind
(Discrete_Choice
) = N_Others_Choice
;
6434 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
6436 UI_Low
:= Expr_Value
(Low
);
6437 UI_High
:= Expr_Value
(High
);
6439 exit Find_Discrete_Value
when
6440 UI_Low
<= UI_Discrim_Value
6442 UI_High
>= UI_Discrim_Value
;
6444 Next
(Discrete_Choice
);
6447 Next_Non_Pragma
(Variant
);
6448 end loop Find_Discrete_Value
;
6449 end Search_For_Discriminant_Value
;
6451 if No
(Variant
) then
6453 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
6454 Report_Errors
:= True;
6458 -- If we have found the corresponding choice, recursively add its
6459 -- components to the Into list.
6462 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
6463 end Gather_Components
;
6465 ------------------------
6466 -- Get_Actual_Subtype --
6467 ------------------------
6469 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
6470 Typ
: constant Entity_Id
:= Etype
(N
);
6471 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
6480 -- If what we have is an identifier that references a subprogram
6481 -- formal, or a variable or constant object, then we get the actual
6482 -- subtype from the referenced entity if one has been built.
6484 if Nkind
(N
) = N_Identifier
6486 (Is_Formal
(Entity
(N
))
6487 or else Ekind
(Entity
(N
)) = E_Constant
6488 or else Ekind
(Entity
(N
)) = E_Variable
)
6489 and then Present
(Actual_Subtype
(Entity
(N
)))
6491 return Actual_Subtype
(Entity
(N
));
6493 -- Actual subtype of unchecked union is always itself. We never need
6494 -- the "real" actual subtype. If we did, we couldn't get it anyway
6495 -- because the discriminant is not available. The restrictions on
6496 -- Unchecked_Union are designed to make sure that this is OK.
6498 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
6501 -- Here for the unconstrained case, we must find actual subtype
6502 -- No actual subtype is available, so we must build it on the fly.
6504 -- Checking the type, not the underlying type, for constrainedness
6505 -- seems to be necessary. Maybe all the tests should be on the type???
6507 elsif (not Is_Constrained
(Typ
))
6508 and then (Is_Array_Type
(Utyp
)
6509 or else (Is_Record_Type
(Utyp
)
6510 and then Has_Discriminants
(Utyp
)))
6511 and then not Has_Unknown_Discriminants
(Utyp
)
6512 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
6514 -- Nothing to do if in spec expression (why not???)
6516 if In_Spec_Expression
then
6519 elsif Is_Private_Type
(Typ
)
6520 and then not Has_Discriminants
(Typ
)
6522 -- If the type has no discriminants, there is no subtype to
6523 -- build, even if the underlying type is discriminated.
6527 -- Else build the actual subtype
6530 Decl
:= Build_Actual_Subtype
(Typ
, N
);
6531 Atyp
:= Defining_Identifier
(Decl
);
6533 -- If Build_Actual_Subtype generated a new declaration then use it
6537 -- The actual subtype is an Itype, so analyze the declaration,
6538 -- but do not attach it to the tree, to get the type defined.
6540 Set_Parent
(Decl
, N
);
6541 Set_Is_Itype
(Atyp
);
6542 Analyze
(Decl
, Suppress
=> All_Checks
);
6543 Set_Associated_Node_For_Itype
(Atyp
, N
);
6544 Set_Has_Delayed_Freeze
(Atyp
, False);
6546 -- We need to freeze the actual subtype immediately. This is
6547 -- needed, because otherwise this Itype will not get frozen
6548 -- at all, and it is always safe to freeze on creation because
6549 -- any associated types must be frozen at this point.
6551 Freeze_Itype
(Atyp
, N
);
6554 -- Otherwise we did not build a declaration, so return original
6561 -- For all remaining cases, the actual subtype is the same as
6562 -- the nominal type.
6567 end Get_Actual_Subtype
;
6569 -------------------------------------
6570 -- Get_Actual_Subtype_If_Available --
6571 -------------------------------------
6573 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
6574 Typ
: constant Entity_Id
:= Etype
(N
);
6577 -- If what we have is an identifier that references a subprogram
6578 -- formal, or a variable or constant object, then we get the actual
6579 -- subtype from the referenced entity if one has been built.
6581 if Nkind
(N
) = N_Identifier
6583 (Is_Formal
(Entity
(N
))
6584 or else Ekind
(Entity
(N
)) = E_Constant
6585 or else Ekind
(Entity
(N
)) = E_Variable
)
6586 and then Present
(Actual_Subtype
(Entity
(N
)))
6588 return Actual_Subtype
(Entity
(N
));
6590 -- Otherwise the Etype of N is returned unchanged
6595 end Get_Actual_Subtype_If_Available
;
6597 ------------------------
6598 -- Get_Body_From_Stub --
6599 ------------------------
6601 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
6603 return Proper_Body
(Unit
(Library_Unit
(N
)));
6604 end Get_Body_From_Stub
;
6606 ---------------------
6607 -- Get_Cursor_Type --
6608 ---------------------
6610 function Get_Cursor_Type
6612 Typ
: Entity_Id
) return Entity_Id
6616 First_Op
: Entity_Id
;
6620 -- If error already detected, return
6622 if Error_Posted
(Aspect
) then
6626 -- The cursor type for an Iterable aspect is the return type of a
6627 -- non-overloaded First primitive operation. Locate association for
6630 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
6632 while Present
(Assoc
) loop
6633 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
6634 First_Op
:= Expression
(Assoc
);
6641 if First_Op
= Any_Id
then
6642 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
6648 -- Locate function with desired name and profile in scope of type
6650 Func
:= First_Entity
(Scope
(Typ
));
6651 while Present
(Func
) loop
6652 if Chars
(Func
) = Chars
(First_Op
)
6653 and then Ekind
(Func
) = E_Function
6654 and then Present
(First_Formal
(Func
))
6655 and then Etype
(First_Formal
(Func
)) = Typ
6656 and then No
(Next_Formal
(First_Formal
(Func
)))
6658 if Cursor
/= Any_Type
then
6660 ("Operation First for iterable type must be unique", Aspect
);
6663 Cursor
:= Etype
(Func
);
6670 -- If not found, no way to resolve remaining primitives.
6672 if Cursor
= Any_Type
then
6674 ("No legal primitive operation First for Iterable type", Aspect
);
6678 end Get_Cursor_Type
;
6680 -------------------------------
6681 -- Get_Default_External_Name --
6682 -------------------------------
6684 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
6686 Get_Decoded_Name_String
(Chars
(E
));
6688 if Opt
.External_Name_Imp_Casing
= Uppercase
then
6689 Set_Casing
(All_Upper_Case
);
6691 Set_Casing
(All_Lower_Case
);
6695 Make_String_Literal
(Sloc
(E
),
6696 Strval
=> String_From_Name_Buffer
);
6697 end Get_Default_External_Name
;
6699 --------------------------
6700 -- Get_Enclosing_Object --
6701 --------------------------
6703 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
6705 if Is_Entity_Name
(N
) then
6709 when N_Indexed_Component |
6711 N_Selected_Component
=>
6713 -- If not generating code, a dereference may be left implicit.
6714 -- In thoses cases, return Empty.
6716 if Is_Access_Type
(Etype
(Prefix
(N
))) then
6719 return Get_Enclosing_Object
(Prefix
(N
));
6722 when N_Type_Conversion
=>
6723 return Get_Enclosing_Object
(Expression
(N
));
6729 end Get_Enclosing_Object
;
6731 ---------------------------
6732 -- Get_Enum_Lit_From_Pos --
6733 ---------------------------
6735 function Get_Enum_Lit_From_Pos
6738 Loc
: Source_Ptr
) return Node_Id
6740 Btyp
: Entity_Id
:= Base_Type
(T
);
6744 -- In the case where the literal is of type Character, Wide_Character
6745 -- or Wide_Wide_Character or of a type derived from them, there needs
6746 -- to be some special handling since there is no explicit chain of
6747 -- literals to search. Instead, an N_Character_Literal node is created
6748 -- with the appropriate Char_Code and Chars fields.
6750 if Is_Standard_Character_Type
(T
) then
6751 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
6753 Make_Character_Literal
(Loc
,
6755 Char_Literal_Value
=> Pos
);
6757 -- For all other cases, we have a complete table of literals, and
6758 -- we simply iterate through the chain of literal until the one
6759 -- with the desired position value is found.
6763 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
6764 Btyp
:= Full_View
(Btyp
);
6767 Lit
:= First_Literal
(Btyp
);
6768 for J
in 1 .. UI_To_Int
(Pos
) loop
6772 return New_Occurrence_Of
(Lit
, Loc
);
6774 end Get_Enum_Lit_From_Pos
;
6776 ---------------------------------
6777 -- Get_Ensures_From_CTC_Pragma --
6778 ---------------------------------
6780 function Get_Ensures_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
6781 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
6785 if List_Length
(Args
) = 4 then
6786 Res
:= Pick
(Args
, 4);
6788 elsif List_Length
(Args
) = 3 then
6789 Res
:= Pick
(Args
, 3);
6791 if Chars
(Res
) /= Name_Ensures
then
6800 end Get_Ensures_From_CTC_Pragma
;
6802 ------------------------
6803 -- Get_Generic_Entity --
6804 ------------------------
6806 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
6807 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
6809 if Present
(Renamed_Object
(Ent
)) then
6810 return Renamed_Object
(Ent
);
6814 end Get_Generic_Entity
;
6816 -------------------------------------
6817 -- Get_Incomplete_View_Of_Ancestor --
6818 -------------------------------------
6820 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
6821 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
6822 Par_Scope
: Entity_Id
;
6823 Par_Type
: Entity_Id
;
6826 -- The incomplete view of an ancestor is only relevant for private
6827 -- derived types in child units.
6829 if not Is_Derived_Type
(E
)
6830 or else not Is_Child_Unit
(Cur_Unit
)
6835 Par_Scope
:= Scope
(Cur_Unit
);
6836 if No
(Par_Scope
) then
6840 Par_Type
:= Etype
(Base_Type
(E
));
6842 -- Traverse list of ancestor types until we find one declared in
6843 -- a parent or grandparent unit (two levels seem sufficient).
6845 while Present
(Par_Type
) loop
6846 if Scope
(Par_Type
) = Par_Scope
6847 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
6851 elsif not Is_Derived_Type
(Par_Type
) then
6855 Par_Type
:= Etype
(Base_Type
(Par_Type
));
6859 -- If none found, there is no relevant ancestor type.
6863 end Get_Incomplete_View_Of_Ancestor
;
6865 ----------------------
6866 -- Get_Index_Bounds --
6867 ----------------------
6869 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
6870 Kind
: constant Node_Kind
:= Nkind
(N
);
6874 if Kind
= N_Range
then
6876 H
:= High_Bound
(N
);
6878 elsif Kind
= N_Subtype_Indication
then
6879 R
:= Range_Expression
(Constraint
(N
));
6887 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
6888 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
6891 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
6892 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
6896 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
6897 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
6900 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
6901 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
6905 -- N is an expression, indicating a range with one value
6910 end Get_Index_Bounds
;
6912 ---------------------------------
6913 -- Get_Iterable_Type_Primitive --
6914 ---------------------------------
6916 function Get_Iterable_Type_Primitive
6918 Nam
: Name_Id
) return Entity_Id
6920 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
6928 Assoc
:= First
(Component_Associations
(Funcs
));
6929 while Present
(Assoc
) loop
6930 if Chars
(First
(Choices
(Assoc
))) = Nam
then
6931 return Entity
(Expression
(Assoc
));
6934 Assoc
:= Next
(Assoc
);
6939 end Get_Iterable_Type_Primitive
;
6941 ----------------------------------
6942 -- Get_Library_Unit_Name_string --
6943 ----------------------------------
6945 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
6946 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
6949 Get_Unit_Name_String
(Unit_Name_Id
);
6951 -- Remove seven last character (" (spec)" or " (body)")
6953 Name_Len
:= Name_Len
- 7;
6954 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
6955 end Get_Library_Unit_Name_String
;
6957 ------------------------
6958 -- Get_Name_Entity_Id --
6959 ------------------------
6961 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
6963 return Entity_Id
(Get_Name_Table_Info
(Id
));
6964 end Get_Name_Entity_Id
;
6966 ------------------------------
6967 -- Get_Name_From_CTC_Pragma --
6968 ------------------------------
6970 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
6971 Arg
: constant Node_Id
:=
6972 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
6974 return Strval
(Expr_Value_S
(Arg
));
6975 end Get_Name_From_CTC_Pragma
;
6977 -----------------------
6978 -- Get_Parent_Entity --
6979 -----------------------
6981 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
6983 if Nkind
(Unit
) = N_Package_Body
6984 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
6986 return Defining_Entity
6987 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
6988 elsif Nkind
(Unit
) = N_Package_Instantiation
then
6989 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
6991 return Defining_Entity
(Unit
);
6993 end Get_Parent_Entity
;
6998 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
7000 return Get_Pragma_Id
(Pragma_Name
(N
));
7003 -----------------------
7004 -- Get_Reason_String --
7005 -----------------------
7007 procedure Get_Reason_String
(N
: Node_Id
) is
7009 if Nkind
(N
) = N_String_Literal
then
7010 Store_String_Chars
(Strval
(N
));
7012 elsif Nkind
(N
) = N_Op_Concat
then
7013 Get_Reason_String
(Left_Opnd
(N
));
7014 Get_Reason_String
(Right_Opnd
(N
));
7016 -- If not of required form, error
7020 ("Reason for pragma Warnings has wrong form", N
);
7022 ("\must be string literal or concatenation of string literals", N
);
7025 end Get_Reason_String
;
7027 ---------------------------
7028 -- Get_Referenced_Object --
7029 ---------------------------
7031 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
7036 while Is_Entity_Name
(R
)
7037 and then Present
(Renamed_Object
(Entity
(R
)))
7039 R
:= Renamed_Object
(Entity
(R
));
7043 end Get_Referenced_Object
;
7045 ------------------------
7046 -- Get_Renamed_Entity --
7047 ------------------------
7049 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
7054 while Present
(Renamed_Entity
(R
)) loop
7055 R
:= Renamed_Entity
(R
);
7059 end Get_Renamed_Entity
;
7061 ----------------------------------
7062 -- Get_Requires_From_CTC_Pragma --
7063 ----------------------------------
7065 function Get_Requires_From_CTC_Pragma
(N
: Node_Id
) return Node_Id
is
7066 Args
: constant List_Id
:= Pragma_Argument_Associations
(N
);
7070 if List_Length
(Args
) >= 3 then
7071 Res
:= Pick
(Args
, 3);
7073 if Chars
(Res
) /= Name_Requires
then
7082 end Get_Requires_From_CTC_Pragma
;
7084 -------------------------
7085 -- Get_Subprogram_Body --
7086 -------------------------
7088 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
7092 Decl
:= Unit_Declaration_Node
(E
);
7094 if Nkind
(Decl
) = N_Subprogram_Body
then
7097 -- The below comment is bad, because it is possible for
7098 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7100 else -- Nkind (Decl) = N_Subprogram_Declaration
7102 if Present
(Corresponding_Body
(Decl
)) then
7103 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
7105 -- Imported subprogram case
7111 end Get_Subprogram_Body
;
7113 ---------------------------
7114 -- Get_Subprogram_Entity --
7115 ---------------------------
7117 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
7119 Subp_Id
: Entity_Id
;
7122 if Nkind
(Nod
) = N_Accept_Statement
then
7123 Subp
:= Entry_Direct_Name
(Nod
);
7125 elsif Nkind
(Nod
) = N_Slice
then
7126 Subp
:= Prefix
(Nod
);
7132 -- Strip the subprogram call
7135 if Nkind_In
(Subp
, N_Explicit_Dereference
,
7136 N_Indexed_Component
,
7137 N_Selected_Component
)
7139 Subp
:= Prefix
(Subp
);
7141 elsif Nkind_In
(Subp
, N_Type_Conversion
,
7142 N_Unchecked_Type_Conversion
)
7144 Subp
:= Expression
(Subp
);
7151 -- Extract the entity of the subprogram call
7153 if Is_Entity_Name
(Subp
) then
7154 Subp_Id
:= Entity
(Subp
);
7156 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
7157 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
7160 if Is_Subprogram
(Subp_Id
) then
7166 -- The search did not find a construct that denotes a subprogram
7171 end Get_Subprogram_Entity
;
7173 -----------------------------
7174 -- Get_Task_Body_Procedure --
7175 -----------------------------
7177 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
7179 -- Note: A task type may be the completion of a private type with
7180 -- discriminants. When performing elaboration checks on a task
7181 -- declaration, the current view of the type may be the private one,
7182 -- and the procedure that holds the body of the task is held in its
7185 -- This is an odd function, why not have Task_Body_Procedure do
7186 -- the following digging???
7188 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
7189 end Get_Task_Body_Procedure
;
7191 -----------------------
7192 -- Has_Access_Values --
7193 -----------------------
7195 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
7196 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
7199 -- Case of a private type which is not completed yet. This can only
7200 -- happen in the case of a generic format type appearing directly, or
7201 -- as a component of the type to which this function is being applied
7202 -- at the top level. Return False in this case, since we certainly do
7203 -- not know that the type contains access types.
7208 elsif Is_Access_Type
(Typ
) then
7211 elsif Is_Array_Type
(Typ
) then
7212 return Has_Access_Values
(Component_Type
(Typ
));
7214 elsif Is_Record_Type
(Typ
) then
7219 -- Loop to Check components
7221 Comp
:= First_Component_Or_Discriminant
(Typ
);
7222 while Present
(Comp
) loop
7224 -- Check for access component, tag field does not count, even
7225 -- though it is implemented internally using an access type.
7227 if Has_Access_Values
(Etype
(Comp
))
7228 and then Chars
(Comp
) /= Name_uTag
7233 Next_Component_Or_Discriminant
(Comp
);
7242 end Has_Access_Values
;
7244 ------------------------------
7245 -- Has_Compatible_Alignment --
7246 ------------------------------
7248 function Has_Compatible_Alignment
7250 Expr
: Node_Id
) return Alignment_Result
7252 function Has_Compatible_Alignment_Internal
7255 Default
: Alignment_Result
) return Alignment_Result
;
7256 -- This is the internal recursive function that actually does the work.
7257 -- There is one additional parameter, which says what the result should
7258 -- be if no alignment information is found, and there is no definite
7259 -- indication of compatible alignments. At the outer level, this is set
7260 -- to Unknown, but for internal recursive calls in the case where types
7261 -- are known to be correct, it is set to Known_Compatible.
7263 ---------------------------------------
7264 -- Has_Compatible_Alignment_Internal --
7265 ---------------------------------------
7267 function Has_Compatible_Alignment_Internal
7270 Default
: Alignment_Result
) return Alignment_Result
7272 Result
: Alignment_Result
:= Known_Compatible
;
7273 -- Holds the current status of the result. Note that once a value of
7274 -- Known_Incompatible is set, it is sticky and does not get changed
7275 -- to Unknown (the value in Result only gets worse as we go along,
7278 Offs
: Uint
:= No_Uint
;
7279 -- Set to a factor of the offset from the base object when Expr is a
7280 -- selected or indexed component, based on Component_Bit_Offset and
7281 -- Component_Size respectively. A negative value is used to represent
7282 -- a value which is not known at compile time.
7284 procedure Check_Prefix
;
7285 -- Checks the prefix recursively in the case where the expression
7286 -- is an indexed or selected component.
7288 procedure Set_Result
(R
: Alignment_Result
);
7289 -- If R represents a worse outcome (unknown instead of known
7290 -- compatible, or known incompatible), then set Result to R.
7296 procedure Check_Prefix
is
7298 -- The subtlety here is that in doing a recursive call to check
7299 -- the prefix, we have to decide what to do in the case where we
7300 -- don't find any specific indication of an alignment problem.
7302 -- At the outer level, we normally set Unknown as the result in
7303 -- this case, since we can only set Known_Compatible if we really
7304 -- know that the alignment value is OK, but for the recursive
7305 -- call, in the case where the types match, and we have not
7306 -- specified a peculiar alignment for the object, we are only
7307 -- concerned about suspicious rep clauses, the default case does
7308 -- not affect us, since the compiler will, in the absence of such
7309 -- rep clauses, ensure that the alignment is correct.
7311 if Default
= Known_Compatible
7313 (Etype
(Obj
) = Etype
(Expr
)
7314 and then (Unknown_Alignment
(Obj
)
7316 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
7319 (Has_Compatible_Alignment_Internal
7320 (Obj
, Prefix
(Expr
), Known_Compatible
));
7322 -- In all other cases, we need a full check on the prefix
7326 (Has_Compatible_Alignment_Internal
7327 (Obj
, Prefix
(Expr
), Unknown
));
7335 procedure Set_Result
(R
: Alignment_Result
) is
7342 -- Start of processing for Has_Compatible_Alignment_Internal
7345 -- If Expr is a selected component, we must make sure there is no
7346 -- potentially troublesome component clause, and that the record is
7349 if Nkind
(Expr
) = N_Selected_Component
then
7351 -- Packed record always generate unknown alignment
7353 if Is_Packed
(Etype
(Prefix
(Expr
))) then
7354 Set_Result
(Unknown
);
7357 -- Check prefix and component offset
7360 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
7362 -- If Expr is an indexed component, we must make sure there is no
7363 -- potentially troublesome Component_Size clause and that the array
7364 -- is not bit-packed.
7366 elsif Nkind
(Expr
) = N_Indexed_Component
then
7368 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
7369 Ind
: constant Node_Id
:= First_Index
(Typ
);
7372 -- Bit packed array always generates unknown alignment
7374 if Is_Bit_Packed_Array
(Typ
) then
7375 Set_Result
(Unknown
);
7378 -- Check prefix and component offset
7381 Offs
:= Component_Size
(Typ
);
7383 -- Small optimization: compute the full offset when possible
7386 and then Offs
> Uint_0
7387 and then Present
(Ind
)
7388 and then Nkind
(Ind
) = N_Range
7389 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
7390 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
7392 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
7393 - Expr_Value
(Low_Bound
((Ind
))));
7398 -- If we have a null offset, the result is entirely determined by
7399 -- the base object and has already been computed recursively.
7401 if Offs
= Uint_0
then
7404 -- Case where we know the alignment of the object
7406 elsif Known_Alignment
(Obj
) then
7408 ObjA
: constant Uint
:= Alignment
(Obj
);
7409 ExpA
: Uint
:= No_Uint
;
7410 SizA
: Uint
:= No_Uint
;
7413 -- If alignment of Obj is 1, then we are always OK
7416 Set_Result
(Known_Compatible
);
7418 -- Alignment of Obj is greater than 1, so we need to check
7421 -- If we have an offset, see if it is compatible
7423 if Offs
/= No_Uint
and Offs
> Uint_0
then
7424 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
7425 Set_Result
(Known_Incompatible
);
7428 -- See if Expr is an object with known alignment
7430 elsif Is_Entity_Name
(Expr
)
7431 and then Known_Alignment
(Entity
(Expr
))
7433 ExpA
:= Alignment
(Entity
(Expr
));
7435 -- Otherwise, we can use the alignment of the type of
7436 -- Expr given that we already checked for
7437 -- discombobulating rep clauses for the cases of indexed
7438 -- and selected components above.
7440 elsif Known_Alignment
(Etype
(Expr
)) then
7441 ExpA
:= Alignment
(Etype
(Expr
));
7443 -- Otherwise the alignment is unknown
7446 Set_Result
(Default
);
7449 -- If we got an alignment, see if it is acceptable
7451 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
7452 Set_Result
(Known_Incompatible
);
7455 -- If Expr is not a piece of a larger object, see if size
7456 -- is given. If so, check that it is not too small for the
7457 -- required alignment.
7459 if Offs
/= No_Uint
then
7462 -- See if Expr is an object with known size
7464 elsif Is_Entity_Name
(Expr
)
7465 and then Known_Static_Esize
(Entity
(Expr
))
7467 SizA
:= Esize
(Entity
(Expr
));
7469 -- Otherwise, we check the object size of the Expr type
7471 elsif Known_Static_Esize
(Etype
(Expr
)) then
7472 SizA
:= Esize
(Etype
(Expr
));
7475 -- If we got a size, see if it is a multiple of the Obj
7476 -- alignment, if not, then the alignment cannot be
7477 -- acceptable, since the size is always a multiple of the
7480 if SizA
/= No_Uint
then
7481 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
7482 Set_Result
(Known_Incompatible
);
7488 -- If we do not know required alignment, any non-zero offset is a
7489 -- potential problem (but certainly may be OK, so result is unknown).
7491 elsif Offs
/= No_Uint
then
7492 Set_Result
(Unknown
);
7494 -- If we can't find the result by direct comparison of alignment
7495 -- values, then there is still one case that we can determine known
7496 -- result, and that is when we can determine that the types are the
7497 -- same, and no alignments are specified. Then we known that the
7498 -- alignments are compatible, even if we don't know the alignment
7499 -- value in the front end.
7501 elsif Etype
(Obj
) = Etype
(Expr
) then
7503 -- Types are the same, but we have to check for possible size
7504 -- and alignments on the Expr object that may make the alignment
7505 -- different, even though the types are the same.
7507 if Is_Entity_Name
(Expr
) then
7509 -- First check alignment of the Expr object. Any alignment less
7510 -- than Maximum_Alignment is worrisome since this is the case
7511 -- where we do not know the alignment of Obj.
7513 if Known_Alignment
(Entity
(Expr
))
7514 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
7515 Ttypes
.Maximum_Alignment
7517 Set_Result
(Unknown
);
7519 -- Now check size of Expr object. Any size that is not an
7520 -- even multiple of Maximum_Alignment is also worrisome
7521 -- since it may cause the alignment of the object to be less
7522 -- than the alignment of the type.
7524 elsif Known_Static_Esize
(Entity
(Expr
))
7526 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
7527 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
7530 Set_Result
(Unknown
);
7532 -- Otherwise same type is decisive
7535 Set_Result
(Known_Compatible
);
7539 -- Another case to deal with is when there is an explicit size or
7540 -- alignment clause when the types are not the same. If so, then the
7541 -- result is Unknown. We don't need to do this test if the Default is
7542 -- Unknown, since that result will be set in any case.
7544 elsif Default
/= Unknown
7545 and then (Has_Size_Clause
(Etype
(Expr
))
7547 Has_Alignment_Clause
(Etype
(Expr
)))
7549 Set_Result
(Unknown
);
7551 -- If no indication found, set default
7554 Set_Result
(Default
);
7557 -- Return worst result found
7560 end Has_Compatible_Alignment_Internal
;
7562 -- Start of processing for Has_Compatible_Alignment
7565 -- If Obj has no specified alignment, then set alignment from the type
7566 -- alignment. Perhaps we should always do this, but for sure we should
7567 -- do it when there is an address clause since we can do more if the
7568 -- alignment is known.
7570 if Unknown_Alignment
(Obj
) then
7571 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
7574 -- Now do the internal call that does all the work
7576 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
7577 end Has_Compatible_Alignment
;
7579 ----------------------
7580 -- Has_Declarations --
7581 ----------------------
7583 function Has_Declarations
(N
: Node_Id
) return Boolean is
7585 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
7587 N_Compilation_Unit_Aux
,
7593 N_Package_Specification
);
7594 end Has_Declarations
;
7596 ---------------------------------
7597 -- Has_Defaulted_Discriminants --
7598 ---------------------------------
7600 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
7602 return Has_Discriminants
(Typ
)
7603 and then Present
(First_Discriminant
(Typ
))
7604 and then Present
(Discriminant_Default_Value
7605 (First_Discriminant
(Typ
)));
7606 end Has_Defaulted_Discriminants
;
7612 function Has_Denormals
(E
: Entity_Id
) return Boolean is
7614 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
7617 -------------------------------------------
7618 -- Has_Discriminant_Dependent_Constraint --
7619 -------------------------------------------
7621 function Has_Discriminant_Dependent_Constraint
7622 (Comp
: Entity_Id
) return Boolean
7624 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7625 Subt_Indic
: Node_Id
;
7630 -- Discriminants can't depend on discriminants
7632 if Ekind
(Comp
) = E_Discriminant
then
7636 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
7638 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
7639 Constr
:= Constraint
(Subt_Indic
);
7641 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
7642 Assn
:= First
(Constraints
(Constr
));
7643 while Present
(Assn
) loop
7644 case Nkind
(Assn
) is
7645 when N_Subtype_Indication |
7649 if Depends_On_Discriminant
(Assn
) then
7653 when N_Discriminant_Association
=>
7654 if Depends_On_Discriminant
(Expression
(Assn
)) then
7669 end Has_Discriminant_Dependent_Constraint
;
7671 --------------------------
7672 -- Has_Enabled_Property --
7673 --------------------------
7675 function Has_Enabled_Property
7676 (Item_Id
: Entity_Id
;
7677 Property
: Name_Id
) return Boolean
7679 function State_Has_Enabled_Property
return Boolean;
7680 -- Determine whether a state denoted by Item_Id has the property enabled
7682 function Variable_Has_Enabled_Property
return Boolean;
7683 -- Determine whether a variable denoted by Item_Id has the property
7686 --------------------------------
7687 -- State_Has_Enabled_Property --
7688 --------------------------------
7690 function State_Has_Enabled_Property
return Boolean is
7691 Decl
: constant Node_Id
:= Parent
(Item_Id
);
7699 -- The declaration of an external abstract state appears as an
7700 -- extension aggregate. If this is not the case, properties can never
7703 if Nkind
(Decl
) /= N_Extension_Aggregate
then
7707 -- When External appears as a simple option, it automatically enables
7710 Opt
:= First
(Expressions
(Decl
));
7711 while Present
(Opt
) loop
7712 if Nkind
(Opt
) = N_Identifier
7713 and then Chars
(Opt
) = Name_External
7721 -- When External specifies particular properties, inspect those and
7722 -- find the desired one (if any).
7724 Opt
:= First
(Component_Associations
(Decl
));
7725 while Present
(Opt
) loop
7726 Opt_Nam
:= First
(Choices
(Opt
));
7728 if Nkind
(Opt_Nam
) = N_Identifier
7729 and then Chars
(Opt_Nam
) = Name_External
7731 Props
:= Expression
(Opt
);
7733 -- Multiple properties appear as an aggregate
7735 if Nkind
(Props
) = N_Aggregate
then
7737 -- Simple property form
7739 Prop
:= First
(Expressions
(Props
));
7740 while Present
(Prop
) loop
7741 if Chars
(Prop
) = Property
then
7748 -- Property with expression form
7750 Prop
:= First
(Component_Associations
(Props
));
7751 while Present
(Prop
) loop
7752 Prop_Nam
:= First
(Choices
(Prop
));
7754 -- The property can be represented in two ways:
7755 -- others => <value>
7756 -- <property> => <value>
7758 if Nkind
(Prop_Nam
) = N_Others_Choice
7759 or else (Nkind
(Prop_Nam
) = N_Identifier
7760 and then Chars
(Prop_Nam
) = Property
)
7762 return Is_True
(Expr_Value
(Expression
(Prop
)));
7771 return Chars
(Props
) = Property
;
7779 end State_Has_Enabled_Property
;
7781 -----------------------------------
7782 -- Variable_Has_Enabled_Property --
7783 -----------------------------------
7785 function Variable_Has_Enabled_Property
return Boolean is
7786 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
7787 -- Determine whether property pragma Prag (if present) denotes an
7788 -- enabled property.
7794 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
7798 if Present
(Prag
) then
7799 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
7801 -- The pragma has an optional Boolean expression, the related
7802 -- property is enabled only when the expression evaluates to
7805 if Present
(Arg2
) then
7806 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg2
)));
7808 -- Otherwise the lack of expression enables the property by
7815 -- The property was never set in the first place
7824 AR
: constant Node_Id
:=
7825 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
7826 AW
: constant Node_Id
:=
7827 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
7828 ER
: constant Node_Id
:=
7829 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
7830 EW
: constant Node_Id
:=
7831 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
7833 -- Start of processing for Variable_Has_Enabled_Property
7836 -- A non-effectively volatile object can never possess external
7839 if not Is_Effectively_Volatile
(Item_Id
) then
7842 -- External properties related to variables come in two flavors -
7843 -- explicit and implicit. The explicit case is characterized by the
7844 -- presence of a property pragma with an optional Boolean flag. The
7845 -- property is enabled when the flag evaluates to True or the flag is
7846 -- missing altogether.
7848 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
7851 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
7854 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
7857 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
7860 -- The implicit case lacks all property pragmas
7862 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
7868 end Variable_Has_Enabled_Property
;
7870 -- Start of processing for Has_Enabled_Property
7873 -- Abstract states and variables have a flexible scheme of specifying
7874 -- external properties.
7876 if Ekind
(Item_Id
) = E_Abstract_State
then
7877 return State_Has_Enabled_Property
;
7879 elsif Ekind
(Item_Id
) = E_Variable
then
7880 return Variable_Has_Enabled_Property
;
7882 -- Otherwise a property is enabled when the related item is effectively
7886 return Is_Effectively_Volatile
(Item_Id
);
7888 end Has_Enabled_Property
;
7890 --------------------
7891 -- Has_Infinities --
7892 --------------------
7894 function Has_Infinities
(E
: Entity_Id
) return Boolean is
7897 Is_Floating_Point_Type
(E
)
7898 and then Nkind
(Scalar_Range
(E
)) = N_Range
7899 and then Includes_Infinities
(Scalar_Range
(E
));
7902 --------------------
7903 -- Has_Interfaces --
7904 --------------------
7906 function Has_Interfaces
7908 Use_Full_View
: Boolean := True) return Boolean
7910 Typ
: Entity_Id
:= Base_Type
(T
);
7913 -- Handle concurrent types
7915 if Is_Concurrent_Type
(Typ
) then
7916 Typ
:= Corresponding_Record_Type
(Typ
);
7919 if not Present
(Typ
)
7920 or else not Is_Record_Type
(Typ
)
7921 or else not Is_Tagged_Type
(Typ
)
7926 -- Handle private types
7928 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
7929 Typ
:= Full_View
(Typ
);
7932 -- Handle concurrent record types
7934 if Is_Concurrent_Record_Type
(Typ
)
7935 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
7941 if Is_Interface
(Typ
)
7943 (Is_Record_Type
(Typ
)
7944 and then Present
(Interfaces
(Typ
))
7945 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
7950 exit when Etype
(Typ
) = Typ
7952 -- Handle private types
7954 or else (Present
(Full_View
(Etype
(Typ
)))
7955 and then Full_View
(Etype
(Typ
)) = Typ
)
7957 -- Protect frontend against wrong sources with cyclic derivations
7959 or else Etype
(Typ
) = T
;
7961 -- Climb to the ancestor type handling private types
7963 if Present
(Full_View
(Etype
(Typ
))) then
7964 Typ
:= Full_View
(Etype
(Typ
));
7973 ---------------------------------
7974 -- Has_No_Obvious_Side_Effects --
7975 ---------------------------------
7977 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
7979 -- For now, just handle literals, constants, and non-volatile
7980 -- variables and expressions combining these with operators or
7981 -- short circuit forms.
7983 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
7986 elsif Nkind
(N
) = N_Character_Literal
then
7989 elsif Nkind
(N
) in N_Unary_Op
then
7990 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
7992 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
7993 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
7995 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
7997 elsif Nkind
(N
) = N_Expression_With_Actions
7998 and then Is_Empty_List
(Actions
(N
))
8000 return Has_No_Obvious_Side_Effects
(Expression
(N
));
8002 elsif Nkind
(N
) in N_Has_Entity
then
8003 return Present
(Entity
(N
))
8004 and then Ekind_In
(Entity
(N
), E_Variable
,
8006 E_Enumeration_Literal
,
8010 and then not Is_Volatile
(Entity
(N
));
8015 end Has_No_Obvious_Side_Effects
;
8017 ------------------------
8018 -- Has_Null_Exclusion --
8019 ------------------------
8021 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
8024 when N_Access_Definition |
8025 N_Access_Function_Definition |
8026 N_Access_Procedure_Definition |
8027 N_Access_To_Object_Definition |
8029 N_Derived_Type_Definition |
8030 N_Function_Specification |
8031 N_Subtype_Declaration
=>
8032 return Null_Exclusion_Present
(N
);
8034 when N_Component_Definition |
8035 N_Formal_Object_Declaration |
8036 N_Object_Renaming_Declaration
=>
8037 if Present
(Subtype_Mark
(N
)) then
8038 return Null_Exclusion_Present
(N
);
8039 else pragma Assert
(Present
(Access_Definition
(N
)));
8040 return Null_Exclusion_Present
(Access_Definition
(N
));
8043 when N_Discriminant_Specification
=>
8044 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
8045 return Null_Exclusion_Present
(Discriminant_Type
(N
));
8047 return Null_Exclusion_Present
(N
);
8050 when N_Object_Declaration
=>
8051 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
8052 return Null_Exclusion_Present
(Object_Definition
(N
));
8054 return Null_Exclusion_Present
(N
);
8057 when N_Parameter_Specification
=>
8058 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
8059 return Null_Exclusion_Present
(Parameter_Type
(N
));
8061 return Null_Exclusion_Present
(N
);
8068 end Has_Null_Exclusion
;
8070 ------------------------
8071 -- Has_Null_Extension --
8072 ------------------------
8074 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
8075 B
: constant Entity_Id
:= Base_Type
(T
);
8080 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
8081 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
8083 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
8085 if Present
(Ext
) then
8086 if Null_Present
(Ext
) then
8089 Comps
:= Component_List
(Ext
);
8091 -- The null component list is rewritten during analysis to
8092 -- include the parent component. Any other component indicates
8093 -- that the extension was not originally null.
8095 return Null_Present
(Comps
)
8096 or else No
(Next
(First
(Component_Items
(Comps
))));
8105 end Has_Null_Extension
;
8107 -------------------------------
8108 -- Has_Overriding_Initialize --
8109 -------------------------------
8111 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
8112 BT
: constant Entity_Id
:= Base_Type
(T
);
8116 if Is_Controlled
(BT
) then
8117 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
8120 elsif Present
(Primitive_Operations
(BT
)) then
8121 P
:= First_Elmt
(Primitive_Operations
(BT
));
8122 while Present
(P
) loop
8124 Init
: constant Entity_Id
:= Node
(P
);
8125 Formal
: constant Entity_Id
:= First_Formal
(Init
);
8127 if Ekind
(Init
) = E_Procedure
8128 and then Chars
(Init
) = Name_Initialize
8129 and then Comes_From_Source
(Init
)
8130 and then Present
(Formal
)
8131 and then Etype
(Formal
) = BT
8132 and then No
(Next_Formal
(Formal
))
8133 and then (Ada_Version
< Ada_2012
8134 or else not Null_Present
(Parent
(Init
)))
8144 -- Here if type itself does not have a non-null Initialize operation:
8145 -- check immediate ancestor.
8147 if Is_Derived_Type
(BT
)
8148 and then Has_Overriding_Initialize
(Etype
(BT
))
8155 end Has_Overriding_Initialize
;
8157 --------------------------------------
8158 -- Has_Preelaborable_Initialization --
8159 --------------------------------------
8161 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
8164 procedure Check_Components
(E
: Entity_Id
);
8165 -- Check component/discriminant chain, sets Has_PE False if a component
8166 -- or discriminant does not meet the preelaborable initialization rules.
8168 ----------------------
8169 -- Check_Components --
8170 ----------------------
8172 procedure Check_Components
(E
: Entity_Id
) is
8176 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
8177 -- Returns True if and only if the expression denoted by N does not
8178 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8180 ---------------------------------
8181 -- Is_Preelaborable_Expression --
8182 ---------------------------------
8184 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
8188 Comp_Type
: Entity_Id
;
8189 Is_Array_Aggr
: Boolean;
8192 if Is_OK_Static_Expression
(N
) then
8195 elsif Nkind
(N
) = N_Null
then
8198 -- Attributes are allowed in general, even if their prefix is a
8199 -- formal type. (It seems that certain attributes known not to be
8200 -- static might not be allowed, but there are no rules to prevent
8203 elsif Nkind
(N
) = N_Attribute_Reference
then
8206 -- The name of a discriminant evaluated within its parent type is
8207 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8208 -- names that denote discriminals as well as discriminants to
8209 -- catch references occurring within init procs.
8211 elsif Is_Entity_Name
(N
)
8213 (Ekind
(Entity
(N
)) = E_Discriminant
8215 ((Ekind
(Entity
(N
)) = E_Constant
8216 or else Ekind
(Entity
(N
)) = E_In_Parameter
)
8217 and then Present
(Discriminal_Link
(Entity
(N
)))))
8221 elsif Nkind
(N
) = N_Qualified_Expression
then
8222 return Is_Preelaborable_Expression
(Expression
(N
));
8224 -- For aggregates we have to check that each of the associations
8225 -- is preelaborable.
8227 elsif Nkind
(N
) = N_Aggregate
8228 or else Nkind
(N
) = N_Extension_Aggregate
8230 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
8232 if Is_Array_Aggr
then
8233 Comp_Type
:= Component_Type
(Etype
(N
));
8236 -- Check the ancestor part of extension aggregates, which must
8237 -- be either the name of a type that has preelaborable init or
8238 -- an expression that is preelaborable.
8240 if Nkind
(N
) = N_Extension_Aggregate
then
8242 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
8245 if Is_Entity_Name
(Anc_Part
)
8246 and then Is_Type
(Entity
(Anc_Part
))
8248 if not Has_Preelaborable_Initialization
8254 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
8260 -- Check positional associations
8262 Exp
:= First
(Expressions
(N
));
8263 while Present
(Exp
) loop
8264 if not Is_Preelaborable_Expression
(Exp
) then
8271 -- Check named associations
8273 Assn
:= First
(Component_Associations
(N
));
8274 while Present
(Assn
) loop
8275 Choice
:= First
(Choices
(Assn
));
8276 while Present
(Choice
) loop
8277 if Is_Array_Aggr
then
8278 if Nkind
(Choice
) = N_Others_Choice
then
8281 elsif Nkind
(Choice
) = N_Range
then
8282 if not Is_OK_Static_Range
(Choice
) then
8286 elsif not Is_OK_Static_Expression
(Choice
) then
8291 Comp_Type
:= Etype
(Choice
);
8297 -- If the association has a <> at this point, then we have
8298 -- to check whether the component's type has preelaborable
8299 -- initialization. Note that this only occurs when the
8300 -- association's corresponding component does not have a
8301 -- default expression, the latter case having already been
8302 -- expanded as an expression for the association.
8304 if Box_Present
(Assn
) then
8305 if not Has_Preelaborable_Initialization
(Comp_Type
) then
8309 -- In the expression case we check whether the expression
8310 -- is preelaborable.
8313 not Is_Preelaborable_Expression
(Expression
(Assn
))
8321 -- If we get here then aggregate as a whole is preelaborable
8325 -- All other cases are not preelaborable
8330 end Is_Preelaborable_Expression
;
8332 -- Start of processing for Check_Components
8335 -- Loop through entities of record or protected type
8338 while Present
(Ent
) loop
8340 -- We are interested only in components and discriminants
8347 -- Get default expression if any. If there is no declaration
8348 -- node, it means we have an internal entity. The parent and
8349 -- tag fields are examples of such entities. For such cases,
8350 -- we just test the type of the entity.
8352 if Present
(Declaration_Node
(Ent
)) then
8353 Exp
:= Expression
(Declaration_Node
(Ent
));
8356 when E_Discriminant
=>
8358 -- Note: for a renamed discriminant, the Declaration_Node
8359 -- may point to the one from the ancestor, and have a
8360 -- different expression, so use the proper attribute to
8361 -- retrieve the expression from the derived constraint.
8363 Exp
:= Discriminant_Default_Value
(Ent
);
8366 goto Check_Next_Entity
;
8369 -- A component has PI if it has no default expression and the
8370 -- component type has PI.
8373 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
8378 -- Require the default expression to be preelaborable
8380 elsif not Is_Preelaborable_Expression
(Exp
) then
8385 <<Check_Next_Entity
>>
8388 end Check_Components
;
8390 -- Start of processing for Has_Preelaborable_Initialization
8393 -- Immediate return if already marked as known preelaborable init. This
8394 -- covers types for which this function has already been called once
8395 -- and returned True (in which case the result is cached), and also
8396 -- types to which a pragma Preelaborable_Initialization applies.
8398 if Known_To_Have_Preelab_Init
(E
) then
8402 -- If the type is a subtype representing a generic actual type, then
8403 -- test whether its base type has preelaborable initialization since
8404 -- the subtype representing the actual does not inherit this attribute
8405 -- from the actual or formal. (but maybe it should???)
8407 if Is_Generic_Actual_Type
(E
) then
8408 return Has_Preelaborable_Initialization
(Base_Type
(E
));
8411 -- All elementary types have preelaborable initialization
8413 if Is_Elementary_Type
(E
) then
8416 -- Array types have PI if the component type has PI
8418 elsif Is_Array_Type
(E
) then
8419 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
8421 -- A derived type has preelaborable initialization if its parent type
8422 -- has preelaborable initialization and (in the case of a derived record
8423 -- extension) if the non-inherited components all have preelaborable
8424 -- initialization. However, a user-defined controlled type with an
8425 -- overriding Initialize procedure does not have preelaborable
8428 elsif Is_Derived_Type
(E
) then
8430 -- If the derived type is a private extension then it doesn't have
8431 -- preelaborable initialization.
8433 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
8437 -- First check whether ancestor type has preelaborable initialization
8439 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
8441 -- If OK, check extension components (if any)
8443 if Has_PE
and then Is_Record_Type
(E
) then
8444 Check_Components
(First_Entity
(E
));
8447 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8448 -- with a user defined Initialize procedure does not have PI. If
8449 -- the type is untagged, the control primitives come from a component
8450 -- that has already been checked.
8453 and then Is_Controlled
(E
)
8454 and then Is_Tagged_Type
(E
)
8455 and then Has_Overriding_Initialize
(E
)
8460 -- Private types not derived from a type having preelaborable init and
8461 -- that are not marked with pragma Preelaborable_Initialization do not
8462 -- have preelaborable initialization.
8464 elsif Is_Private_Type
(E
) then
8467 -- Record type has PI if it is non private and all components have PI
8469 elsif Is_Record_Type
(E
) then
8471 Check_Components
(First_Entity
(E
));
8473 -- Protected types must not have entries, and components must meet
8474 -- same set of rules as for record components.
8476 elsif Is_Protected_Type
(E
) then
8477 if Has_Entries
(E
) then
8481 Check_Components
(First_Entity
(E
));
8482 Check_Components
(First_Private_Entity
(E
));
8485 -- Type System.Address always has preelaborable initialization
8487 elsif Is_RTE
(E
, RE_Address
) then
8490 -- In all other cases, type does not have preelaborable initialization
8496 -- If type has preelaborable initialization, cache result
8499 Set_Known_To_Have_Preelab_Init
(E
);
8503 end Has_Preelaborable_Initialization
;
8505 ---------------------------
8506 -- Has_Private_Component --
8507 ---------------------------
8509 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
8510 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
8511 Component
: Entity_Id
;
8514 if Error_Posted
(Type_Id
)
8515 or else Error_Posted
(Btype
)
8520 if Is_Class_Wide_Type
(Btype
) then
8521 Btype
:= Root_Type
(Btype
);
8524 if Is_Private_Type
(Btype
) then
8526 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
8529 if No
(Full_View
(Btype
)) then
8530 return not Is_Generic_Type
(Btype
)
8531 and then not Is_Generic_Type
(Root_Type
(Btype
));
8533 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
8536 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
8540 elsif Is_Array_Type
(Btype
) then
8541 return Has_Private_Component
(Component_Type
(Btype
));
8543 elsif Is_Record_Type
(Btype
) then
8544 Component
:= First_Component
(Btype
);
8545 while Present
(Component
) loop
8546 if Has_Private_Component
(Etype
(Component
)) then
8550 Next_Component
(Component
);
8555 elsif Is_Protected_Type
(Btype
)
8556 and then Present
(Corresponding_Record_Type
(Btype
))
8558 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
8563 end Has_Private_Component
;
8565 ----------------------
8566 -- Has_Signed_Zeros --
8567 ----------------------
8569 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
8571 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
8572 end Has_Signed_Zeros
;
8574 -----------------------------
8575 -- Has_Static_Array_Bounds --
8576 -----------------------------
8578 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
8579 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
8586 -- Unconstrained types do not have static bounds
8588 if not Is_Constrained
(Typ
) then
8592 -- First treat string literals specially, as the lower bound and length
8593 -- of string literals are not stored like those of arrays.
8595 -- A string literal always has static bounds
8597 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8601 -- Treat all dimensions in turn
8603 Index
:= First_Index
(Typ
);
8604 for Indx
in 1 .. Ndims
loop
8606 -- In case of an illegal index which is not a discrete type, return
8607 -- that the type is not static.
8609 if not Is_Discrete_Type
(Etype
(Index
))
8610 or else Etype
(Index
) = Any_Type
8615 Get_Index_Bounds
(Index
, Low
, High
);
8617 if Error_Posted
(Low
) or else Error_Posted
(High
) then
8621 if Is_OK_Static_Expression
(Low
)
8623 Is_OK_Static_Expression
(High
)
8633 -- If we fall through the loop, all indexes matched
8636 end Has_Static_Array_Bounds
;
8642 function Has_Stream
(T
: Entity_Id
) return Boolean is
8649 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
8652 elsif Is_Array_Type
(T
) then
8653 return Has_Stream
(Component_Type
(T
));
8655 elsif Is_Record_Type
(T
) then
8656 E
:= First_Component
(T
);
8657 while Present
(E
) loop
8658 if Has_Stream
(Etype
(E
)) then
8667 elsif Is_Private_Type
(T
) then
8668 return Has_Stream
(Underlying_Type
(T
));
8679 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
8681 Get_Name_String
(Chars
(E
));
8682 return Name_Buffer
(Name_Len
) = Suffix
;
8689 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8691 Get_Name_String
(Chars
(E
));
8692 Add_Char_To_Name_Buffer
(Suffix
);
8700 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
8702 pragma Assert
(Has_Suffix
(E
, Suffix
));
8703 Get_Name_String
(Chars
(E
));
8704 Name_Len
:= Name_Len
- 1;
8708 --------------------------
8709 -- Has_Tagged_Component --
8710 --------------------------
8712 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
8716 if Is_Private_Type
(Typ
)
8717 and then Present
(Underlying_Type
(Typ
))
8719 return Has_Tagged_Component
(Underlying_Type
(Typ
));
8721 elsif Is_Array_Type
(Typ
) then
8722 return Has_Tagged_Component
(Component_Type
(Typ
));
8724 elsif Is_Tagged_Type
(Typ
) then
8727 elsif Is_Record_Type
(Typ
) then
8728 Comp
:= First_Component
(Typ
);
8729 while Present
(Comp
) loop
8730 if Has_Tagged_Component
(Etype
(Comp
)) then
8734 Next_Component
(Comp
);
8742 end Has_Tagged_Component
;
8744 ----------------------------
8745 -- Has_Volatile_Component --
8746 ----------------------------
8748 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
8752 if Has_Volatile_Components
(Typ
) then
8755 elsif Is_Array_Type
(Typ
) then
8756 return Is_Volatile
(Component_Type
(Typ
));
8758 elsif Is_Record_Type
(Typ
) then
8759 Comp
:= First_Component
(Typ
);
8760 while Present
(Comp
) loop
8761 if Is_Volatile_Object
(Comp
) then
8765 Comp
:= Next_Component
(Comp
);
8770 end Has_Volatile_Component
;
8772 -------------------------
8773 -- Implementation_Kind --
8774 -------------------------
8776 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
8777 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
8780 pragma Assert
(Present
(Impl_Prag
));
8781 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
8782 return Chars
(Get_Pragma_Arg
(Arg
));
8783 end Implementation_Kind
;
8785 --------------------------
8786 -- Implements_Interface --
8787 --------------------------
8789 function Implements_Interface
8790 (Typ_Ent
: Entity_Id
;
8791 Iface_Ent
: Entity_Id
;
8792 Exclude_Parents
: Boolean := False) return Boolean
8794 Ifaces_List
: Elist_Id
;
8796 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
8797 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
8800 if Is_Class_Wide_Type
(Typ
) then
8801 Typ
:= Root_Type
(Typ
);
8804 if not Has_Interfaces
(Typ
) then
8808 if Is_Class_Wide_Type
(Iface
) then
8809 Iface
:= Root_Type
(Iface
);
8812 Collect_Interfaces
(Typ
, Ifaces_List
);
8814 Elmt
:= First_Elmt
(Ifaces_List
);
8815 while Present
(Elmt
) loop
8816 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
8817 and then Exclude_Parents
8821 elsif Node
(Elmt
) = Iface
then
8829 end Implements_Interface
;
8831 ------------------------------------
8832 -- In_Assertion_Expression_Pragma --
8833 ------------------------------------
8835 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
8837 Prag
: Node_Id
:= Empty
;
8840 -- Climb the parent chain looking for an enclosing pragma
8843 while Present
(Par
) loop
8844 if Nkind
(Par
) = N_Pragma
then
8848 -- Precondition-like pragmas are expanded into if statements, check
8849 -- the original node instead.
8851 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
8852 Prag
:= Original_Node
(Par
);
8855 -- The expansion of attribute 'Old generates a constant to capture
8856 -- the result of the prefix. If the parent traversal reaches
8857 -- one of these constants, then the node technically came from a
8858 -- postcondition-like pragma. Note that the Ekind is not tested here
8859 -- because N may be the expression of an object declaration which is
8860 -- currently being analyzed. Such objects carry Ekind of E_Void.
8862 elsif Nkind
(Par
) = N_Object_Declaration
8863 and then Constant_Present
(Par
)
8864 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
8868 -- Prevent the search from going too far
8870 elsif Is_Body_Or_Package_Declaration
(Par
) then
8874 Par
:= Parent
(Par
);
8879 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
8880 end In_Assertion_Expression_Pragma
;
8886 function In_Instance
return Boolean is
8887 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
8892 while Present
(S
) and then S
/= Standard_Standard
loop
8893 if (Ekind
(S
) = E_Function
8894 or else Ekind
(S
) = E_Package
8895 or else Ekind
(S
) = E_Procedure
)
8896 and then Is_Generic_Instance
(S
)
8898 -- A child instance is always compiled in the context of a parent
8899 -- instance. Nevertheless, the actuals are not analyzed in an
8900 -- instance context. We detect this case by examining the current
8901 -- compilation unit, which must be a child instance, and checking
8902 -- that it is not currently on the scope stack.
8904 if Is_Child_Unit
(Curr_Unit
)
8905 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
8906 N_Package_Instantiation
8907 and then not In_Open_Scopes
(Curr_Unit
)
8921 ----------------------
8922 -- In_Instance_Body --
8923 ----------------------
8925 function In_Instance_Body
return Boolean is
8930 while Present
(S
) and then S
/= Standard_Standard
loop
8931 if Ekind_In
(S
, E_Function
, E_Procedure
)
8932 and then Is_Generic_Instance
(S
)
8936 elsif Ekind
(S
) = E_Package
8937 and then In_Package_Body
(S
)
8938 and then Is_Generic_Instance
(S
)
8947 end In_Instance_Body
;
8949 -----------------------------
8950 -- In_Instance_Not_Visible --
8951 -----------------------------
8953 function In_Instance_Not_Visible
return Boolean is
8958 while Present
(S
) and then S
/= Standard_Standard
loop
8959 if Ekind_In
(S
, E_Function
, E_Procedure
)
8960 and then Is_Generic_Instance
(S
)
8964 elsif Ekind
(S
) = E_Package
8965 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
8966 and then Is_Generic_Instance
(S
)
8975 end In_Instance_Not_Visible
;
8977 ------------------------------
8978 -- In_Instance_Visible_Part --
8979 ------------------------------
8981 function In_Instance_Visible_Part
return Boolean is
8986 while Present
(S
) and then S
/= Standard_Standard
loop
8987 if Ekind
(S
) = E_Package
8988 and then Is_Generic_Instance
(S
)
8989 and then not In_Package_Body
(S
)
8990 and then not In_Private_Part
(S
)
8999 end In_Instance_Visible_Part
;
9001 ---------------------
9002 -- In_Package_Body --
9003 ---------------------
9005 function In_Package_Body
return Boolean is
9010 while Present
(S
) and then S
/= Standard_Standard
loop
9011 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
9019 end In_Package_Body
;
9021 --------------------------------
9022 -- In_Parameter_Specification --
9023 --------------------------------
9025 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
9030 while Present
(PN
) loop
9031 if Nkind
(PN
) = N_Parameter_Specification
then
9039 end In_Parameter_Specification
;
9041 --------------------------
9042 -- In_Pragma_Expression --
9043 --------------------------
9045 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
9052 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
9058 end In_Pragma_Expression
;
9060 -------------------------------------
9061 -- In_Reverse_Storage_Order_Object --
9062 -------------------------------------
9064 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
9066 Btyp
: Entity_Id
:= Empty
;
9069 -- Climb up indexed components
9073 case Nkind
(Pref
) is
9074 when N_Selected_Component
=>
9075 Pref
:= Prefix
(Pref
);
9078 when N_Indexed_Component
=>
9079 Pref
:= Prefix
(Pref
);
9087 if Present
(Pref
) then
9088 Btyp
:= Base_Type
(Etype
(Pref
));
9091 return Present
(Btyp
)
9092 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
9093 and then Reverse_Storage_Order
(Btyp
);
9094 end In_Reverse_Storage_Order_Object
;
9096 --------------------------------------
9097 -- In_Subprogram_Or_Concurrent_Unit --
9098 --------------------------------------
9100 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
9105 -- Use scope chain to check successively outer scopes
9111 if K
in Subprogram_Kind
9112 or else K
in Concurrent_Kind
9113 or else K
in Generic_Subprogram_Kind
9117 elsif E
= Standard_Standard
then
9123 end In_Subprogram_Or_Concurrent_Unit
;
9125 ---------------------
9126 -- In_Visible_Part --
9127 ---------------------
9129 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
9131 return Is_Package_Or_Generic_Package
(Scope_Id
)
9132 and then In_Open_Scopes
(Scope_Id
)
9133 and then not In_Package_Body
(Scope_Id
)
9134 and then not In_Private_Part
(Scope_Id
);
9135 end In_Visible_Part
;
9137 --------------------------------
9138 -- Incomplete_Or_Private_View --
9139 --------------------------------
9141 function Incomplete_Or_Private_View
(Typ
: Entity_Id
) return Entity_Id
is
9142 function Inspect_Decls
9144 Taft
: Boolean := False) return Entity_Id
;
9145 -- Check whether a declarative region contains the incomplete or private
9152 function Inspect_Decls
9154 Taft
: Boolean := False) return Entity_Id
9160 Decl
:= First
(Decls
);
9161 while Present
(Decl
) loop
9165 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
9166 Match
:= Defining_Identifier
(Decl
);
9170 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
9171 N_Private_Type_Declaration
)
9173 Match
:= Defining_Identifier
(Decl
);
9178 and then Present
(Full_View
(Match
))
9179 and then Full_View
(Match
) = Typ
9194 -- Start of processing for Incomplete_Or_Partial_View
9197 -- Incomplete type case
9199 Prev
:= Current_Entity_In_Scope
(Typ
);
9202 and then Is_Incomplete_Type
(Prev
)
9203 and then Present
(Full_View
(Prev
))
9204 and then Full_View
(Prev
) = Typ
9209 -- Private or Taft amendment type case
9212 Pkg
: constant Entity_Id
:= Scope
(Typ
);
9213 Pkg_Decl
: Node_Id
:= Pkg
;
9216 if Ekind
(Pkg
) = E_Package
then
9217 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
9218 Pkg_Decl
:= Parent
(Pkg_Decl
);
9221 -- It is knows that Typ has a private view, look for it in the
9222 -- visible declarations of the enclosing scope. A special case
9223 -- of this is when the two views have been exchanged - the full
9224 -- appears earlier than the private.
9226 if Has_Private_Declaration
(Typ
) then
9227 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
9229 -- Exchanged view case, look in the private declarations
9232 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
9237 -- Otherwise if this is the package body, then Typ is a potential
9238 -- Taft amendment type. The incomplete view should be located in
9239 -- the private declarations of the enclosing scope.
9241 elsif In_Package_Body
(Pkg
) then
9242 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
9247 -- The type has no incomplete or private view
9250 end Incomplete_Or_Private_View
;
9252 -----------------------------------------
9253 -- Inherit_Default_Init_Cond_Procedure --
9254 -----------------------------------------
9256 procedure Inherit_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
9257 Par_Typ
: constant Entity_Id
:= Etype
(Typ
);
9260 -- A derived type inherits the default initial condition procedure of
9263 if No
(Default_Init_Cond_Procedure
(Typ
)) then
9264 Set_Default_Init_Cond_Procedure
9265 (Typ
, Default_Init_Cond_Procedure
(Par_Typ
));
9267 end Inherit_Default_Init_Cond_Procedure
;
9269 ---------------------------------
9270 -- Insert_Explicit_Dereference --
9271 ---------------------------------
9273 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
9274 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
9275 Ent
: Entity_Id
:= Empty
;
9282 Save_Interps
(N
, New_Prefix
);
9285 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
9286 Prefix
=> New_Prefix
));
9288 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
9290 if Is_Overloaded
(New_Prefix
) then
9292 -- The dereference is also overloaded, and its interpretations are
9293 -- the designated types of the interpretations of the original node.
9295 Set_Etype
(N
, Any_Type
);
9297 Get_First_Interp
(New_Prefix
, I
, It
);
9298 while Present
(It
.Nam
) loop
9301 if Is_Access_Type
(T
) then
9302 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
9305 Get_Next_Interp
(I
, It
);
9311 -- Prefix is unambiguous: mark the original prefix (which might
9312 -- Come_From_Source) as a reference, since the new (relocated) one
9313 -- won't be taken into account.
9315 if Is_Entity_Name
(New_Prefix
) then
9316 Ent
:= Entity
(New_Prefix
);
9319 -- For a retrieval of a subcomponent of some composite object,
9320 -- retrieve the ultimate entity if there is one.
9322 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
9323 N_Indexed_Component
)
9325 Pref
:= Prefix
(New_Prefix
);
9326 while Present
(Pref
)
9327 and then Nkind_In
(Pref
, N_Selected_Component
,
9328 N_Indexed_Component
)
9330 Pref
:= Prefix
(Pref
);
9333 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
9334 Ent
:= Entity
(Pref
);
9338 -- Place the reference on the entity node
9340 if Present
(Ent
) then
9341 Generate_Reference
(Ent
, Pref
);
9344 end Insert_Explicit_Dereference
;
9346 ------------------------------------------
9347 -- Inspect_Deferred_Constant_Completion --
9348 ------------------------------------------
9350 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
9354 Decl
:= First
(Decls
);
9355 while Present
(Decl
) loop
9357 -- Deferred constant signature
9359 if Nkind
(Decl
) = N_Object_Declaration
9360 and then Constant_Present
(Decl
)
9361 and then No
(Expression
(Decl
))
9363 -- No need to check internally generated constants
9365 and then Comes_From_Source
(Decl
)
9367 -- The constant is not completed. A full object declaration or a
9368 -- pragma Import complete a deferred constant.
9370 and then not Has_Completion
(Defining_Identifier
(Decl
))
9373 ("constant declaration requires initialization expression",
9374 Defining_Identifier
(Decl
));
9377 Decl
:= Next
(Decl
);
9379 end Inspect_Deferred_Constant_Completion
;
9381 -----------------------------
9382 -- Is_Actual_Out_Parameter --
9383 -----------------------------
9385 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
9389 Find_Actual
(N
, Formal
, Call
);
9390 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
9391 end Is_Actual_Out_Parameter
;
9393 -------------------------
9394 -- Is_Actual_Parameter --
9395 -------------------------
9397 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
9398 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
9402 when N_Parameter_Association
=>
9403 return N
= Explicit_Actual_Parameter
(Parent
(N
));
9405 when N_Subprogram_Call
=>
9406 return Is_List_Member
(N
)
9408 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
9413 end Is_Actual_Parameter
;
9415 --------------------------------
9416 -- Is_Actual_Tagged_Parameter --
9417 --------------------------------
9419 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
9423 Find_Actual
(N
, Formal
, Call
);
9424 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
9425 end Is_Actual_Tagged_Parameter
;
9427 ---------------------
9428 -- Is_Aliased_View --
9429 ---------------------
9431 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
9435 if Is_Entity_Name
(Obj
) then
9442 or else (Present
(Renamed_Object
(E
))
9443 and then Is_Aliased_View
(Renamed_Object
(E
)))))
9445 or else ((Is_Formal
(E
)
9446 or else Ekind
(E
) = E_Generic_In_Out_Parameter
9447 or else Ekind
(E
) = E_Generic_In_Parameter
)
9448 and then Is_Tagged_Type
(Etype
(E
)))
9450 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
9452 -- Current instance of type, either directly or as rewritten
9453 -- reference to the current object.
9455 or else (Is_Entity_Name
(Original_Node
(Obj
))
9456 and then Present
(Entity
(Original_Node
(Obj
)))
9457 and then Is_Type
(Entity
(Original_Node
(Obj
))))
9459 or else (Is_Type
(E
) and then E
= Current_Scope
)
9461 or else (Is_Incomplete_Or_Private_Type
(E
)
9462 and then Full_View
(E
) = Current_Scope
)
9464 -- Ada 2012 AI05-0053: the return object of an extended return
9465 -- statement is aliased if its type is immutably limited.
9467 or else (Is_Return_Object
(E
)
9468 and then Is_Limited_View
(Etype
(E
)));
9470 elsif Nkind
(Obj
) = N_Selected_Component
then
9471 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
9473 elsif Nkind
(Obj
) = N_Indexed_Component
then
9474 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
9476 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
9477 and then Has_Aliased_Components
9478 (Designated_Type
(Etype
(Prefix
(Obj
)))));
9480 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
9481 return Is_Tagged_Type
(Etype
(Obj
))
9482 and then Is_Aliased_View
(Expression
(Obj
));
9484 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
9485 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
9490 end Is_Aliased_View
;
9492 -------------------------
9493 -- Is_Ancestor_Package --
9494 -------------------------
9496 function Is_Ancestor_Package
9498 E2
: Entity_Id
) return Boolean
9504 while Present
(Par
) and then Par
/= Standard_Standard
loop
9513 end Is_Ancestor_Package
;
9515 ----------------------
9516 -- Is_Atomic_Object --
9517 ----------------------
9519 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
9521 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
9522 -- Determines if given object has atomic components
9524 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
9525 -- If prefix is an implicit dereference, examine designated type
9527 ----------------------
9528 -- Is_Atomic_Prefix --
9529 ----------------------
9531 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
9533 if Is_Access_Type
(Etype
(N
)) then
9535 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
9537 return Object_Has_Atomic_Components
(N
);
9539 end Is_Atomic_Prefix
;
9541 ----------------------------------
9542 -- Object_Has_Atomic_Components --
9543 ----------------------------------
9545 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
9547 if Has_Atomic_Components
(Etype
(N
))
9548 or else Is_Atomic
(Etype
(N
))
9552 elsif Is_Entity_Name
(N
)
9553 and then (Has_Atomic_Components
(Entity
(N
))
9554 or else Is_Atomic
(Entity
(N
)))
9558 elsif Nkind
(N
) = N_Selected_Component
9559 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9563 elsif Nkind
(N
) = N_Indexed_Component
9564 or else Nkind
(N
) = N_Selected_Component
9566 return Is_Atomic_Prefix
(Prefix
(N
));
9571 end Object_Has_Atomic_Components
;
9573 -- Start of processing for Is_Atomic_Object
9576 -- Predicate is not relevant to subprograms
9578 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
9581 elsif Is_Atomic
(Etype
(N
))
9582 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
9586 elsif Nkind
(N
) = N_Selected_Component
9587 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
9591 elsif Nkind
(N
) = N_Indexed_Component
9592 or else Nkind
(N
) = N_Selected_Component
9594 return Is_Atomic_Prefix
(Prefix
(N
));
9599 end Is_Atomic_Object
;
9601 -------------------------
9602 -- Is_Attribute_Result --
9603 -------------------------
9605 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
9607 return Nkind
(N
) = N_Attribute_Reference
9608 and then Attribute_Name
(N
) = Name_Result
;
9609 end Is_Attribute_Result
;
9611 ------------------------------------
9612 -- Is_Body_Or_Package_Declaration --
9613 ------------------------------------
9615 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
9617 return Nkind_In
(N
, N_Entry_Body
,
9619 N_Package_Declaration
,
9623 end Is_Body_Or_Package_Declaration
;
9625 -----------------------
9626 -- Is_Bounded_String --
9627 -----------------------
9629 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
9630 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
9633 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
9634 -- Super_String, or one of the [Wide_]Wide_ versions. This will
9635 -- be True for all the Bounded_String types in instances of the
9636 -- Generic_Bounded_Length generics, and for types derived from those.
9638 return Present
(Under
)
9639 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
9640 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
9641 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
9642 end Is_Bounded_String
;
9644 -------------------------
9645 -- Is_Child_Or_Sibling --
9646 -------------------------
9648 function Is_Child_Or_Sibling
9649 (Pack_1
: Entity_Id
;
9650 Pack_2
: Entity_Id
) return Boolean
9652 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
9653 -- Given an arbitrary package, return the number of "climbs" necessary
9654 -- to reach scope Standard_Standard.
9656 procedure Equalize_Depths
9657 (Pack
: in out Entity_Id
;
9659 Depth_To_Reach
: Nat
);
9660 -- Given an arbitrary package, its depth and a target depth to reach,
9661 -- climb the scope chain until the said depth is reached. The pointer
9662 -- to the package and its depth a modified during the climb.
9664 ----------------------------
9665 -- Distance_From_Standard --
9666 ----------------------------
9668 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
9675 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
9677 Scop
:= Scope
(Scop
);
9681 end Distance_From_Standard
;
9683 ---------------------
9684 -- Equalize_Depths --
9685 ---------------------
9687 procedure Equalize_Depths
9688 (Pack
: in out Entity_Id
;
9690 Depth_To_Reach
: Nat
)
9693 -- The package must be at a greater or equal depth
9695 if Depth
< Depth_To_Reach
then
9696 raise Program_Error
;
9699 -- Climb the scope chain until the desired depth is reached
9701 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
9702 Pack
:= Scope
(Pack
);
9705 end Equalize_Depths
;
9709 P_1
: Entity_Id
:= Pack_1
;
9710 P_1_Child
: Boolean := False;
9711 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
9712 P_2
: Entity_Id
:= Pack_2
;
9713 P_2_Child
: Boolean := False;
9714 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
9716 -- Start of processing for Is_Child_Or_Sibling
9720 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
9722 -- Both packages denote the same entity, therefore they cannot be
9723 -- children or siblings.
9728 -- One of the packages is at a deeper level than the other. Note that
9729 -- both may still come from differen hierarchies.
9737 elsif P_1_Depth
> P_2_Depth
then
9741 Depth_To_Reach
=> P_2_Depth
);
9750 elsif P_2_Depth
> P_1_Depth
then
9754 Depth_To_Reach
=> P_1_Depth
);
9758 -- At this stage the package pointers have been elevated to the same
9759 -- depth. If the related entities are the same, then one package is a
9760 -- potential child of the other:
9764 -- X became P_1 P_2 or vica versa
9770 return Is_Child_Unit
(Pack_1
);
9772 else pragma Assert
(P_2_Child
);
9773 return Is_Child_Unit
(Pack_2
);
9776 -- The packages may come from the same package chain or from entirely
9777 -- different hierarcies. To determine this, climb the scope stack until
9778 -- a common root is found.
9780 -- (root) (root 1) (root 2)
9785 while Present
(P_1
) and then Present
(P_2
) loop
9787 -- The two packages may be siblings
9790 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
9799 end Is_Child_Or_Sibling
;
9801 -----------------------------
9802 -- Is_Concurrent_Interface --
9803 -----------------------------
9805 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
9807 return Is_Interface
(T
)
9809 (Is_Protected_Interface
(T
)
9810 or else Is_Synchronized_Interface
(T
)
9811 or else Is_Task_Interface
(T
));
9812 end Is_Concurrent_Interface
;
9814 ---------------------------
9815 -- Is_Container_Element --
9816 ---------------------------
9818 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
9819 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
9820 Pref
: constant Node_Id
:= Prefix
(Exp
);
9823 -- Call to an indexing aspect
9825 Cont_Typ
: Entity_Id
;
9826 -- The type of the container being accessed
9828 Elem_Typ
: Entity_Id
;
9831 Indexing
: Entity_Id
;
9833 -- Indicates that constant indexing is used, and the element is thus
9836 Ref_Typ
: Entity_Id
;
9837 -- The reference type returned by the indexing operation
9840 -- If C is a container, in a context that imposes the element type of
9841 -- that container, the indexing notation C (X) is rewritten as:
9843 -- Indexing (C, X).Discr.all
9845 -- where Indexing is one of the indexing aspects of the container.
9846 -- If the context does not require a reference, the construct can be
9851 -- First, verify that the construct has the proper form
9853 if not Expander_Active
then
9856 elsif Nkind
(Pref
) /= N_Selected_Component
then
9859 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
9863 Call
:= Prefix
(Pref
);
9864 Ref_Typ
:= Etype
(Call
);
9867 if not Has_Implicit_Dereference
(Ref_Typ
)
9868 or else No
(First
(Parameter_Associations
(Call
)))
9869 or else not Is_Entity_Name
(Name
(Call
))
9874 -- Retrieve type of container object, and its iterator aspects
9876 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
9877 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
9880 if No
(Indexing
) then
9882 -- Container should have at least one indexing operation
9886 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
9888 -- This may be a variable indexing operation
9890 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
9893 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
9902 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
9904 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
9908 -- Check that the expression is not the target of an assignment, in
9909 -- which case the rewriting is not possible.
9911 if not Is_Const
then
9919 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
9920 and then Par
= Name
(Parent
(Par
))
9924 -- A renaming produces a reference, and the transformation
9927 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
9931 (Nkind
(Parent
(Par
)), N_Function_Call
,
9932 N_Procedure_Call_Statement
,
9933 N_Entry_Call_Statement
)
9935 -- Check that the element is not part of an actual for an
9936 -- in-out parameter.
9943 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
9944 A
:= First
(Parameter_Associations
(Parent
(Par
)));
9945 while Present
(F
) loop
9946 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
9955 -- E_In_Parameter in a call: element is not modified.
9960 Par
:= Parent
(Par
);
9965 -- The expression has the proper form and the context requires the
9966 -- element type. Retrieve the Element function of the container and
9967 -- rewrite the construct as a call to it.
9973 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
9974 while Present
(Op
) loop
9975 exit when Chars
(Node
(Op
)) = Name_Element
;
9984 Make_Function_Call
(Loc
,
9985 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
9986 Parameter_Associations
=> Parameter_Associations
(Call
)));
9987 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
9991 end Is_Container_Element
;
9993 -----------------------
9994 -- Is_Constant_Bound --
9995 -----------------------
9997 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
9999 if Compile_Time_Known_Value
(Exp
) then
10002 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
10003 return Is_Constant_Object
(Entity
(Exp
))
10004 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
10006 elsif Nkind
(Exp
) in N_Binary_Op
then
10007 return Is_Constant_Bound
(Left_Opnd
(Exp
))
10008 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
10009 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
10014 end Is_Constant_Bound
;
10016 --------------------------------------
10017 -- Is_Controlling_Limited_Procedure --
10018 --------------------------------------
10020 function Is_Controlling_Limited_Procedure
10021 (Proc_Nam
: Entity_Id
) return Boolean
10023 Param_Typ
: Entity_Id
:= Empty
;
10026 if Ekind
(Proc_Nam
) = E_Procedure
10027 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
10029 Param_Typ
:= Etype
(Parameter_Type
(First
(
10030 Parameter_Specifications
(Parent
(Proc_Nam
)))));
10032 -- In this case where an Itype was created, the procedure call has been
10035 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
10036 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
10038 Present
(Parameter_Associations
10039 (Associated_Node_For_Itype
(Proc_Nam
)))
10042 Etype
(First
(Parameter_Associations
10043 (Associated_Node_For_Itype
(Proc_Nam
))));
10046 if Present
(Param_Typ
) then
10048 Is_Interface
(Param_Typ
)
10049 and then Is_Limited_Record
(Param_Typ
);
10053 end Is_Controlling_Limited_Procedure
;
10055 -----------------------------
10056 -- Is_CPP_Constructor_Call --
10057 -----------------------------
10059 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
10061 return Nkind
(N
) = N_Function_Call
10062 and then Is_CPP_Class
(Etype
(Etype
(N
)))
10063 and then Is_Constructor
(Entity
(Name
(N
)))
10064 and then Is_Imported
(Entity
(Name
(N
)));
10065 end Is_CPP_Constructor_Call
;
10071 function Is_Delegate
(T
: Entity_Id
) return Boolean is
10072 Desig_Type
: Entity_Id
;
10075 if VM_Target
/= CLI_Target
then
10079 -- Access-to-subprograms are delegates in CIL
10081 if Ekind
(T
) = E_Access_Subprogram_Type
then
10085 if not Is_Access_Type
(T
) then
10087 -- A delegate is a managed pointer. If no designated type is defined
10088 -- it means that it's not a delegate.
10093 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
10095 if not Is_Tagged_Type
(Desig_Type
) then
10099 -- Test if the type is inherited from [mscorlib]System.Delegate
10101 while Etype
(Desig_Type
) /= Desig_Type
loop
10102 if Chars
(Scope
(Desig_Type
)) /= No_Name
10103 and then Is_Imported
(Scope
(Desig_Type
))
10104 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
10109 Desig_Type
:= Etype
(Desig_Type
);
10115 ----------------------------------------------
10116 -- Is_Dependent_Component_Of_Mutable_Object --
10117 ----------------------------------------------
10119 function Is_Dependent_Component_Of_Mutable_Object
10120 (Object
: Node_Id
) return Boolean
10122 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
10123 -- Returns True if and only if Comp is declared within a variant part
10125 --------------------------------
10126 -- Is_Declared_Within_Variant --
10127 --------------------------------
10129 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
10130 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
10131 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
10133 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
10134 end Is_Declared_Within_Variant
;
10137 Prefix_Type
: Entity_Id
;
10138 P_Aliased
: Boolean := False;
10141 Deref
: Node_Id
:= Object
;
10142 -- Dereference node, in something like X.all.Y(2)
10144 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10147 -- Find the dereference node if any
10149 while Nkind_In
(Deref
, N_Indexed_Component
,
10150 N_Selected_Component
,
10153 Deref
:= Prefix
(Deref
);
10156 -- Ada 2005: If we have a component or slice of a dereference,
10157 -- something like X.all.Y (2), and the type of X is access-to-constant,
10158 -- Is_Variable will return False, because it is indeed a constant
10159 -- view. But it might be a view of a variable object, so we want the
10160 -- following condition to be True in that case.
10162 if Is_Variable
(Object
)
10163 or else (Ada_Version
>= Ada_2005
10164 and then Nkind
(Deref
) = N_Explicit_Dereference
)
10166 if Nkind
(Object
) = N_Selected_Component
then
10167 P
:= Prefix
(Object
);
10168 Prefix_Type
:= Etype
(P
);
10170 if Is_Entity_Name
(P
) then
10171 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
10172 Prefix_Type
:= Base_Type
(Prefix_Type
);
10175 if Is_Aliased
(Entity
(P
)) then
10179 -- A discriminant check on a selected component may be expanded
10180 -- into a dereference when removing side-effects. Recover the
10181 -- original node and its type, which may be unconstrained.
10183 elsif Nkind
(P
) = N_Explicit_Dereference
10184 and then not (Comes_From_Source
(P
))
10186 P
:= Original_Node
(P
);
10187 Prefix_Type
:= Etype
(P
);
10190 -- Check for prefix being an aliased component???
10196 -- A heap object is constrained by its initial value
10198 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10199 -- the dereferenced case, since the access value might denote an
10200 -- unconstrained aliased object, whereas in Ada 95 the designated
10201 -- object is guaranteed to be constrained. A worst-case assumption
10202 -- has to apply in Ada 2005 because we can't tell at compile
10203 -- time whether the object is "constrained by its initial value"
10204 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10205 -- rules (these rules are acknowledged to need fixing).
10207 if Ada_Version
< Ada_2005
then
10208 if Is_Access_Type
(Prefix_Type
)
10209 or else Nkind
(P
) = N_Explicit_Dereference
10214 else pragma Assert
(Ada_Version
>= Ada_2005
);
10215 if Is_Access_Type
(Prefix_Type
) then
10217 -- If the access type is pool-specific, and there is no
10218 -- constrained partial view of the designated type, then the
10219 -- designated object is known to be constrained.
10221 if Ekind
(Prefix_Type
) = E_Access_Type
10222 and then not Object_Type_Has_Constrained_Partial_View
10223 (Typ
=> Designated_Type
(Prefix_Type
),
10224 Scop
=> Current_Scope
)
10228 -- Otherwise (general access type, or there is a constrained
10229 -- partial view of the designated type), we need to check
10230 -- based on the designated type.
10233 Prefix_Type
:= Designated_Type
(Prefix_Type
);
10239 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
10241 -- As per AI-0017, the renaming is illegal in a generic body, even
10242 -- if the subtype is indefinite.
10244 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10246 if not Is_Constrained
(Prefix_Type
)
10247 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
10249 (Is_Generic_Type
(Prefix_Type
)
10250 and then Ekind
(Current_Scope
) = E_Generic_Package
10251 and then In_Package_Body
(Current_Scope
)))
10253 and then (Is_Declared_Within_Variant
(Comp
)
10254 or else Has_Discriminant_Dependent_Constraint
(Comp
))
10255 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
10259 -- If the prefix is of an access type at this point, then we want
10260 -- to return False, rather than calling this function recursively
10261 -- on the access object (which itself might be a discriminant-
10262 -- dependent component of some other object, but that isn't
10263 -- relevant to checking the object passed to us). This avoids
10264 -- issuing wrong errors when compiling with -gnatc, where there
10265 -- can be implicit dereferences that have not been expanded.
10267 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
10272 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10275 elsif Nkind
(Object
) = N_Indexed_Component
10276 or else Nkind
(Object
) = N_Slice
10278 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10280 -- A type conversion that Is_Variable is a view conversion:
10281 -- go back to the denoted object.
10283 elsif Nkind
(Object
) = N_Type_Conversion
then
10285 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
10290 end Is_Dependent_Component_Of_Mutable_Object
;
10292 ---------------------
10293 -- Is_Dereferenced --
10294 ---------------------
10296 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
10297 P
: constant Node_Id
:= Parent
(N
);
10299 return Nkind_In
(P
, N_Selected_Component
,
10300 N_Explicit_Dereference
,
10301 N_Indexed_Component
,
10303 and then Prefix
(P
) = N
;
10304 end Is_Dereferenced
;
10306 ----------------------
10307 -- Is_Descendent_Of --
10308 ----------------------
10310 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
10315 pragma Assert
(Nkind
(T1
) in N_Entity
);
10316 pragma Assert
(Nkind
(T2
) in N_Entity
);
10318 T
:= Base_Type
(T1
);
10320 -- Immediate return if the types match
10325 -- Comment needed here ???
10327 elsif Ekind
(T
) = E_Class_Wide_Type
then
10328 return Etype
(T
) = T2
;
10336 -- Done if we found the type we are looking for
10341 -- Done if no more derivations to check
10348 -- Following test catches error cases resulting from prev errors
10350 elsif No
(Etyp
) then
10353 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
10356 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
10360 T
:= Base_Type
(Etyp
);
10363 end Is_Descendent_Of
;
10365 -----------------------------
10366 -- Is_Effectively_Volatile --
10367 -----------------------------
10369 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
10371 if Is_Type
(Id
) then
10373 -- An arbitrary type is effectively volatile when it is subject to
10374 -- pragma Atomic or Volatile.
10376 if Is_Volatile
(Id
) then
10379 -- An array type is effectively volatile when it is subject to pragma
10380 -- Atomic_Components or Volatile_Components or its compolent type is
10381 -- effectively volatile.
10383 elsif Is_Array_Type
(Id
) then
10385 Has_Volatile_Components
(Id
)
10387 Is_Effectively_Volatile
(Component_Type
(Base_Type
(Id
)));
10393 -- Otherwise Id denotes an object
10398 or else Has_Volatile_Components
(Id
)
10399 or else Is_Effectively_Volatile
(Etype
(Id
));
10401 end Is_Effectively_Volatile
;
10403 ------------------------------------
10404 -- Is_Effectively_Volatile_Object --
10405 ------------------------------------
10407 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
10409 if Is_Entity_Name
(N
) then
10410 return Is_Effectively_Volatile
(Entity
(N
));
10412 elsif Nkind
(N
) = N_Expanded_Name
then
10413 return Is_Effectively_Volatile
(Entity
(N
));
10415 elsif Nkind
(N
) = N_Indexed_Component
then
10416 return Is_Effectively_Volatile_Object
(Prefix
(N
));
10418 elsif Nkind
(N
) = N_Selected_Component
then
10420 Is_Effectively_Volatile_Object
(Prefix
(N
))
10422 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
10427 end Is_Effectively_Volatile_Object
;
10429 ----------------------------
10430 -- Is_Expression_Function --
10431 ----------------------------
10433 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
10437 if Ekind
(Subp
) /= E_Function
then
10441 Decl
:= Unit_Declaration_Node
(Subp
);
10442 return Nkind
(Decl
) = N_Subprogram_Declaration
10444 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
10446 (Present
(Corresponding_Body
(Decl
))
10448 Nkind
(Original_Node
10449 (Unit_Declaration_Node
10450 (Corresponding_Body
(Decl
)))) =
10451 N_Expression_Function
));
10453 end Is_Expression_Function
;
10459 function Is_False
(U
: Uint
) return Boolean is
10464 ---------------------------
10465 -- Is_Fixed_Model_Number --
10466 ---------------------------
10468 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
10469 S
: constant Ureal
:= Small_Value
(T
);
10470 M
: Urealp
.Save_Mark
;
10474 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
10475 Urealp
.Release
(M
);
10477 end Is_Fixed_Model_Number
;
10479 -------------------------------
10480 -- Is_Fully_Initialized_Type --
10481 -------------------------------
10483 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
10485 -- In Ada2012, a scalar type with an aspect Default_Value
10486 -- is fully initialized.
10488 if Is_Scalar_Type
(Typ
) then
10489 return Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
);
10491 elsif Is_Access_Type
(Typ
) then
10494 elsif Is_Array_Type
(Typ
) then
10495 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
10496 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
10501 -- An interesting case, if we have a constrained type one of whose
10502 -- bounds is known to be null, then there are no elements to be
10503 -- initialized, so all the elements are initialized.
10505 if Is_Constrained
(Typ
) then
10508 Indx_Typ
: Entity_Id
;
10509 Lbd
, Hbd
: Node_Id
;
10512 Indx
:= First_Index
(Typ
);
10513 while Present
(Indx
) loop
10514 if Etype
(Indx
) = Any_Type
then
10517 -- If index is a range, use directly
10519 elsif Nkind
(Indx
) = N_Range
then
10520 Lbd
:= Low_Bound
(Indx
);
10521 Hbd
:= High_Bound
(Indx
);
10524 Indx_Typ
:= Etype
(Indx
);
10526 if Is_Private_Type
(Indx_Typ
) then
10527 Indx_Typ
:= Full_View
(Indx_Typ
);
10530 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
10533 Lbd
:= Type_Low_Bound
(Indx_Typ
);
10534 Hbd
:= Type_High_Bound
(Indx_Typ
);
10538 if Compile_Time_Known_Value
(Lbd
)
10540 Compile_Time_Known_Value
(Hbd
)
10542 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
10552 -- If no null indexes, then type is not fully initialized
10558 elsif Is_Record_Type
(Typ
) then
10559 if Has_Discriminants
(Typ
)
10561 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
10562 and then Is_Fully_Initialized_Variant
(Typ
)
10567 -- We consider bounded string types to be fully initialized, because
10568 -- otherwise we get false alarms when the Data component is not
10569 -- default-initialized.
10571 if Is_Bounded_String
(Typ
) then
10575 -- Controlled records are considered to be fully initialized if
10576 -- there is a user defined Initialize routine. This may not be
10577 -- entirely correct, but as the spec notes, we are guessing here
10578 -- what is best from the point of view of issuing warnings.
10580 if Is_Controlled
(Typ
) then
10582 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
10585 if Present
(Utyp
) then
10587 Init
: constant Entity_Id
:=
10589 (Underlying_Type
(Typ
), Name_Initialize
));
10593 and then Comes_From_Source
(Init
)
10595 Is_Predefined_File_Name
10596 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
10600 elsif Has_Null_Extension
(Typ
)
10602 Is_Fully_Initialized_Type
10603 (Etype
(Base_Type
(Typ
)))
10612 -- Otherwise see if all record components are initialized
10618 Ent
:= First_Entity
(Typ
);
10619 while Present
(Ent
) loop
10620 if Ekind
(Ent
) = E_Component
10621 and then (No
(Parent
(Ent
))
10622 or else No
(Expression
(Parent
(Ent
))))
10623 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
10625 -- Special VM case for tag components, which need to be
10626 -- defined in this case, but are never initialized as VMs
10627 -- are using other dispatching mechanisms. Ignore this
10628 -- uninitialized case. Note that this applies both to the
10629 -- uTag entry and the main vtable pointer (CPP_Class case).
10631 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
10640 -- No uninitialized components, so type is fully initialized.
10641 -- Note that this catches the case of no components as well.
10645 elsif Is_Concurrent_Type
(Typ
) then
10648 elsif Is_Private_Type
(Typ
) then
10650 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10656 return Is_Fully_Initialized_Type
(U
);
10663 end Is_Fully_Initialized_Type
;
10665 ----------------------------------
10666 -- Is_Fully_Initialized_Variant --
10667 ----------------------------------
10669 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
10670 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
10671 Constraints
: constant List_Id
:= New_List
;
10672 Components
: constant Elist_Id
:= New_Elmt_List
;
10673 Comp_Elmt
: Elmt_Id
;
10675 Comp_List
: Node_Id
;
10677 Discr_Val
: Node_Id
;
10679 Report_Errors
: Boolean;
10680 pragma Warnings
(Off
, Report_Errors
);
10683 if Serious_Errors_Detected
> 0 then
10687 if Is_Record_Type
(Typ
)
10688 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
10689 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
10691 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
10693 Discr
:= First_Discriminant
(Typ
);
10694 while Present
(Discr
) loop
10695 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
10696 Discr_Val
:= Expression
(Parent
(Discr
));
10698 if Present
(Discr_Val
)
10699 and then Is_OK_Static_Expression
(Discr_Val
)
10701 Append_To
(Constraints
,
10702 Make_Component_Association
(Loc
,
10703 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
10704 Expression
=> New_Copy
(Discr_Val
)));
10712 Next_Discriminant
(Discr
);
10717 Comp_List
=> Comp_List
,
10718 Governed_By
=> Constraints
,
10719 Into
=> Components
,
10720 Report_Errors
=> Report_Errors
);
10722 -- Check that each component present is fully initialized
10724 Comp_Elmt
:= First_Elmt
(Components
);
10725 while Present
(Comp_Elmt
) loop
10726 Comp_Id
:= Node
(Comp_Elmt
);
10728 if Ekind
(Comp_Id
) = E_Component
10729 and then (No
(Parent
(Comp_Id
))
10730 or else No
(Expression
(Parent
(Comp_Id
))))
10731 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
10736 Next_Elmt
(Comp_Elmt
);
10741 elsif Is_Private_Type
(Typ
) then
10743 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
10749 return Is_Fully_Initialized_Variant
(U
);
10756 end Is_Fully_Initialized_Variant
;
10758 ----------------------------
10759 -- Is_Inherited_Operation --
10760 ----------------------------
10762 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
10763 pragma Assert
(Is_Overloadable
(E
));
10764 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
10766 return Kind
= N_Full_Type_Declaration
10767 or else Kind
= N_Private_Extension_Declaration
10768 or else Kind
= N_Subtype_Declaration
10769 or else (Ekind
(E
) = E_Enumeration_Literal
10770 and then Is_Derived_Type
(Etype
(E
)));
10771 end Is_Inherited_Operation
;
10773 -------------------------------------
10774 -- Is_Inherited_Operation_For_Type --
10775 -------------------------------------
10777 function Is_Inherited_Operation_For_Type
10779 Typ
: Entity_Id
) return Boolean
10782 -- Check that the operation has been created by the type declaration
10784 return Is_Inherited_Operation
(E
)
10785 and then Defining_Identifier
(Parent
(E
)) = Typ
;
10786 end Is_Inherited_Operation_For_Type
;
10792 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
10793 Ifaces_List
: Elist_Id
;
10794 Iface_Elmt
: Elmt_Id
;
10798 if Is_Class_Wide_Type
(Typ
)
10799 and then Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
10800 Name_Reversible_Iterator
)
10802 Is_Predefined_File_Name
10803 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
10807 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
10810 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
10814 Collect_Interfaces
(Typ
, Ifaces_List
);
10816 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
10817 while Present
(Iface_Elmt
) loop
10818 Iface
:= Node
(Iface_Elmt
);
10819 if Chars
(Iface
) = Name_Forward_Iterator
10821 Is_Predefined_File_Name
10822 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
10827 Next_Elmt
(Iface_Elmt
);
10838 -- We seem to have a lot of overlapping functions that do similar things
10839 -- (testing for left hand sides or lvalues???).
10841 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
10842 P
: constant Node_Id
:= Parent
(N
);
10845 -- Return True if we are the left hand side of an assignment statement
10847 if Nkind
(P
) = N_Assignment_Statement
then
10848 if Name
(P
) = N
then
10854 -- Case of prefix of indexed or selected component or slice
10856 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
10857 and then N
= Prefix
(P
)
10859 -- Here we have the case where the parent P is N.Q or N(Q .. R).
10860 -- If P is an LHS, then N is also effectively an LHS, but there
10861 -- is an important exception. If N is of an access type, then
10862 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
10863 -- case this makes N.all a left hand side but not N itself.
10865 -- If we don't know the type yet, this is the case where we return
10866 -- Unknown, since the answer depends on the type which is unknown.
10868 if No
(Etype
(N
)) then
10871 -- We have an Etype set, so we can check it
10873 elsif Is_Access_Type
(Etype
(N
)) then
10876 -- OK, not access type case, so just test whole expression
10882 -- All other cases are not left hand sides
10889 -----------------------------
10890 -- Is_Library_Level_Entity --
10891 -----------------------------
10893 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
10895 -- The following is a small optimization, and it also properly handles
10896 -- discriminals, which in task bodies might appear in expressions before
10897 -- the corresponding procedure has been created, and which therefore do
10898 -- not have an assigned scope.
10900 if Is_Formal
(E
) then
10904 -- Normal test is simply that the enclosing dynamic scope is Standard
10906 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
10907 end Is_Library_Level_Entity
;
10909 --------------------------------
10910 -- Is_Limited_Class_Wide_Type --
10911 --------------------------------
10913 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
10916 Is_Class_Wide_Type
(Typ
)
10917 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
10918 end Is_Limited_Class_Wide_Type
;
10920 ---------------------------------
10921 -- Is_Local_Variable_Reference --
10922 ---------------------------------
10924 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
10926 if not Is_Entity_Name
(Expr
) then
10931 Ent
: constant Entity_Id
:= Entity
(Expr
);
10932 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
10934 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
10937 return Present
(Sub
) and then Sub
= Current_Subprogram
;
10941 end Is_Local_Variable_Reference
;
10943 -------------------------
10944 -- Is_Object_Reference --
10945 -------------------------
10947 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
10949 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
10950 -- Determine whether N is the name of an internally-generated renaming
10952 --------------------------------------
10953 -- Is_Internally_Generated_Renaming --
10954 --------------------------------------
10956 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
10961 while Present
(P
) loop
10962 if Nkind
(P
) = N_Object_Renaming_Declaration
then
10963 return not Comes_From_Source
(P
);
10964 elsif Is_List_Member
(P
) then
10972 end Is_Internally_Generated_Renaming
;
10974 -- Start of processing for Is_Object_Reference
10977 if Is_Entity_Name
(N
) then
10978 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
10982 when N_Indexed_Component | N_Slice
=>
10984 Is_Object_Reference
(Prefix
(N
))
10985 or else Is_Access_Type
(Etype
(Prefix
(N
)));
10987 -- In Ada 95, a function call is a constant object; a procedure
10990 when N_Function_Call
=>
10991 return Etype
(N
) /= Standard_Void_Type
;
10993 -- Attributes 'Input, 'Old and 'Result produce objects
10995 when N_Attribute_Reference
=>
10998 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
11000 when N_Selected_Component
=>
11002 Is_Object_Reference
(Selector_Name
(N
))
11004 (Is_Object_Reference
(Prefix
(N
))
11005 or else Is_Access_Type
(Etype
(Prefix
(N
))));
11007 when N_Explicit_Dereference
=>
11010 -- A view conversion of a tagged object is an object reference
11012 when N_Type_Conversion
=>
11013 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
11014 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
11015 and then Is_Object_Reference
(Expression
(N
));
11017 -- An unchecked type conversion is considered to be an object if
11018 -- the operand is an object (this construction arises only as a
11019 -- result of expansion activities).
11021 when N_Unchecked_Type_Conversion
=>
11024 -- Allow string literals to act as objects as long as they appear
11025 -- in internally-generated renamings. The expansion of iterators
11026 -- may generate such renamings when the range involves a string
11029 when N_String_Literal
=>
11030 return Is_Internally_Generated_Renaming
(Parent
(N
));
11032 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11033 -- This allows disambiguation of function calls and the use
11034 -- of aggregates in more contexts.
11036 when N_Qualified_Expression
=>
11037 if Ada_Version
< Ada_2012
then
11040 return Is_Object_Reference
(Expression
(N
))
11041 or else Nkind
(Expression
(N
)) = N_Aggregate
;
11048 end Is_Object_Reference
;
11050 -----------------------------------
11051 -- Is_OK_Variable_For_Out_Formal --
11052 -----------------------------------
11054 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
11056 Note_Possible_Modification
(AV
, Sure
=> True);
11058 -- We must reject parenthesized variable names. Comes_From_Source is
11059 -- checked because there are currently cases where the compiler violates
11060 -- this rule (e.g. passing a task object to its controlled Initialize
11061 -- routine). This should be properly documented in sinfo???
11063 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
11066 -- A variable is always allowed
11068 elsif Is_Variable
(AV
) then
11071 -- Unchecked conversions are allowed only if they come from the
11072 -- generated code, which sometimes uses unchecked conversions for out
11073 -- parameters in cases where code generation is unaffected. We tell
11074 -- source unchecked conversions by seeing if they are rewrites of
11075 -- an original Unchecked_Conversion function call, or of an explicit
11076 -- conversion of a function call or an aggregate (as may happen in the
11077 -- expansion of a packed array aggregate).
11079 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
11080 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
11083 elsif Comes_From_Source
(AV
)
11084 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
11088 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
11089 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
11095 -- Normal type conversions are allowed if argument is a variable
11097 elsif Nkind
(AV
) = N_Type_Conversion
then
11098 if Is_Variable
(Expression
(AV
))
11099 and then Paren_Count
(Expression
(AV
)) = 0
11101 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
11104 -- We also allow a non-parenthesized expression that raises
11105 -- constraint error if it rewrites what used to be a variable
11107 elsif Raises_Constraint_Error
(Expression
(AV
))
11108 and then Paren_Count
(Expression
(AV
)) = 0
11109 and then Is_Variable
(Original_Node
(Expression
(AV
)))
11113 -- Type conversion of something other than a variable
11119 -- If this node is rewritten, then test the original form, if that is
11120 -- OK, then we consider the rewritten node OK (for example, if the
11121 -- original node is a conversion, then Is_Variable will not be true
11122 -- but we still want to allow the conversion if it converts a variable).
11124 elsif Original_Node
(AV
) /= AV
then
11126 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11127 -- Reference function.
11129 if Ada_Version
>= Ada_2012
11130 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
11132 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
11137 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
11140 -- All other non-variables are rejected
11145 end Is_OK_Variable_For_Out_Formal
;
11147 -----------------------------------
11148 -- Is_Partially_Initialized_Type --
11149 -----------------------------------
11151 function Is_Partially_Initialized_Type
11153 Include_Implicit
: Boolean := True) return Boolean
11156 if Is_Scalar_Type
(Typ
) then
11159 elsif Is_Access_Type
(Typ
) then
11160 return Include_Implicit
;
11162 elsif Is_Array_Type
(Typ
) then
11164 -- If component type is partially initialized, so is array type
11166 if Is_Partially_Initialized_Type
11167 (Component_Type
(Typ
), Include_Implicit
)
11171 -- Otherwise we are only partially initialized if we are fully
11172 -- initialized (this is the empty array case, no point in us
11173 -- duplicating that code here).
11176 return Is_Fully_Initialized_Type
(Typ
);
11179 elsif Is_Record_Type
(Typ
) then
11181 -- A discriminated type is always partially initialized if in
11184 if Has_Discriminants
(Typ
) and then Include_Implicit
then
11187 -- A tagged type is always partially initialized
11189 elsif Is_Tagged_Type
(Typ
) then
11192 -- Case of non-discriminated record
11198 Component_Present
: Boolean := False;
11199 -- Set True if at least one component is present. If no
11200 -- components are present, then record type is fully
11201 -- initialized (another odd case, like the null array).
11204 -- Loop through components
11206 Ent
:= First_Entity
(Typ
);
11207 while Present
(Ent
) loop
11208 if Ekind
(Ent
) = E_Component
then
11209 Component_Present
:= True;
11211 -- If a component has an initialization expression then
11212 -- the enclosing record type is partially initialized
11214 if Present
(Parent
(Ent
))
11215 and then Present
(Expression
(Parent
(Ent
)))
11219 -- If a component is of a type which is itself partially
11220 -- initialized, then the enclosing record type is also.
11222 elsif Is_Partially_Initialized_Type
11223 (Etype
(Ent
), Include_Implicit
)
11232 -- No initialized components found. If we found any components
11233 -- they were all uninitialized so the result is false.
11235 if Component_Present
then
11238 -- But if we found no components, then all the components are
11239 -- initialized so we consider the type to be initialized.
11247 -- Concurrent types are always fully initialized
11249 elsif Is_Concurrent_Type
(Typ
) then
11252 -- For a private type, go to underlying type. If there is no underlying
11253 -- type then just assume this partially initialized. Not clear if this
11254 -- can happen in a non-error case, but no harm in testing for this.
11256 elsif Is_Private_Type
(Typ
) then
11258 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11263 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
11267 -- For any other type (are there any?) assume partially initialized
11272 end Is_Partially_Initialized_Type
;
11274 ------------------------------------
11275 -- Is_Potentially_Persistent_Type --
11276 ------------------------------------
11278 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
11283 -- For private type, test corresponding full type
11285 if Is_Private_Type
(T
) then
11286 return Is_Potentially_Persistent_Type
(Full_View
(T
));
11288 -- Scalar types are potentially persistent
11290 elsif Is_Scalar_Type
(T
) then
11293 -- Record type is potentially persistent if not tagged and the types of
11294 -- all it components are potentially persistent, and no component has
11295 -- an initialization expression.
11297 elsif Is_Record_Type
(T
)
11298 and then not Is_Tagged_Type
(T
)
11299 and then not Is_Partially_Initialized_Type
(T
)
11301 Comp
:= First_Component
(T
);
11302 while Present
(Comp
) loop
11303 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
11306 Next_Entity
(Comp
);
11312 -- Array type is potentially persistent if its component type is
11313 -- potentially persistent and if all its constraints are static.
11315 elsif Is_Array_Type
(T
) then
11316 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
11320 Indx
:= First_Index
(T
);
11321 while Present
(Indx
) loop
11322 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
11331 -- All other types are not potentially persistent
11336 end Is_Potentially_Persistent_Type
;
11338 --------------------------------
11339 -- Is_Potentially_Unevaluated --
11340 --------------------------------
11342 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
11350 -- A postcondition whose expression is a short-circuit is broken down
11351 -- into individual aspects for better exception reporting. The original
11352 -- short-circuit expression is rewritten as the second operand, and an
11353 -- occurrence of 'Old in that operand is potentially unevaluated.
11354 -- See Sem_ch13.adb for details of this transformation.
11356 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
11360 while not Nkind_In
(Par
, N_If_Expression
,
11368 Par
:= Parent
(Par
);
11370 -- If the context is not an expression, or if is the result of
11371 -- expansion of an enclosing construct (such as another attribute)
11372 -- the predicate does not apply.
11374 if Nkind
(Par
) not in N_Subexpr
11375 or else not Comes_From_Source
(Par
)
11381 if Nkind
(Par
) = N_If_Expression
then
11382 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
11384 elsif Nkind
(Par
) = N_Case_Expression
then
11385 return Expr
/= Expression
(Par
);
11387 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
11388 return Expr
= Right_Opnd
(Par
);
11390 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
11391 return Expr
/= Left_Opnd
(Par
);
11396 end Is_Potentially_Unevaluated
;
11398 ---------------------------------
11399 -- Is_Protected_Self_Reference --
11400 ---------------------------------
11402 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
11404 function In_Access_Definition
(N
: Node_Id
) return Boolean;
11405 -- Returns true if N belongs to an access definition
11407 --------------------------
11408 -- In_Access_Definition --
11409 --------------------------
11411 function In_Access_Definition
(N
: Node_Id
) return Boolean is
11416 while Present
(P
) loop
11417 if Nkind
(P
) = N_Access_Definition
then
11425 end In_Access_Definition
;
11427 -- Start of processing for Is_Protected_Self_Reference
11430 -- Verify that prefix is analyzed and has the proper form. Note that
11431 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
11432 -- which also produce the address of an entity, do not analyze their
11433 -- prefix because they denote entities that are not necessarily visible.
11434 -- Neither of them can apply to a protected type.
11436 return Ada_Version
>= Ada_2005
11437 and then Is_Entity_Name
(N
)
11438 and then Present
(Entity
(N
))
11439 and then Is_Protected_Type
(Entity
(N
))
11440 and then In_Open_Scopes
(Entity
(N
))
11441 and then not In_Access_Definition
(N
);
11442 end Is_Protected_Self_Reference
;
11444 -----------------------------
11445 -- Is_RCI_Pkg_Spec_Or_Body --
11446 -----------------------------
11448 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
11450 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
11451 -- Return True if the unit of Cunit is an RCI package declaration
11453 ---------------------------
11454 -- Is_RCI_Pkg_Decl_Cunit --
11455 ---------------------------
11457 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
11458 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
11461 if Nkind
(The_Unit
) /= N_Package_Declaration
then
11465 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
11466 end Is_RCI_Pkg_Decl_Cunit
;
11468 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
11471 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
11473 (Nkind
(Unit
(Cunit
)) = N_Package_Body
11474 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
11475 end Is_RCI_Pkg_Spec_Or_Body
;
11477 -----------------------------------------
11478 -- Is_Remote_Access_To_Class_Wide_Type --
11479 -----------------------------------------
11481 function Is_Remote_Access_To_Class_Wide_Type
11482 (E
: Entity_Id
) return Boolean
11485 -- A remote access to class-wide type is a general access to object type
11486 -- declared in the visible part of a Remote_Types or Remote_Call_
11489 return Ekind
(E
) = E_General_Access_Type
11490 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11491 end Is_Remote_Access_To_Class_Wide_Type
;
11493 -----------------------------------------
11494 -- Is_Remote_Access_To_Subprogram_Type --
11495 -----------------------------------------
11497 function Is_Remote_Access_To_Subprogram_Type
11498 (E
: Entity_Id
) return Boolean
11501 return (Ekind
(E
) = E_Access_Subprogram_Type
11502 or else (Ekind
(E
) = E_Record_Type
11503 and then Present
(Corresponding_Remote_Type
(E
))))
11504 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
11505 end Is_Remote_Access_To_Subprogram_Type
;
11507 --------------------
11508 -- Is_Remote_Call --
11509 --------------------
11511 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
11513 if Nkind
(N
) not in N_Subprogram_Call
then
11515 -- An entry call cannot be remote
11519 elsif Nkind
(Name
(N
)) in N_Has_Entity
11520 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
11522 -- A subprogram declared in the spec of a RCI package is remote
11526 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
11527 and then Is_Remote_Access_To_Subprogram_Type
11528 (Etype
(Prefix
(Name
(N
))))
11530 -- The dereference of a RAS is a remote call
11534 elsif Present
(Controlling_Argument
(N
))
11535 and then Is_Remote_Access_To_Class_Wide_Type
11536 (Etype
(Controlling_Argument
(N
)))
11538 -- Any primitive operation call with a controlling argument of
11539 -- a RACW type is a remote call.
11544 -- All other calls are local calls
11547 end Is_Remote_Call
;
11549 ----------------------
11550 -- Is_Renamed_Entry --
11551 ----------------------
11553 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
11554 Orig_Node
: Node_Id
:= Empty
;
11555 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
11557 function Is_Entry
(Nam
: Node_Id
) return Boolean;
11558 -- Determine whether Nam is an entry. Traverse selectors if there are
11559 -- nested selected components.
11565 function Is_Entry
(Nam
: Node_Id
) return Boolean is
11567 if Nkind
(Nam
) = N_Selected_Component
then
11568 return Is_Entry
(Selector_Name
(Nam
));
11571 return Ekind
(Entity
(Nam
)) = E_Entry
;
11574 -- Start of processing for Is_Renamed_Entry
11577 if Present
(Alias
(Proc_Nam
)) then
11578 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
11581 -- Look for a rewritten subprogram renaming declaration
11583 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
11584 and then Present
(Original_Node
(Subp_Decl
))
11586 Orig_Node
:= Original_Node
(Subp_Decl
);
11589 -- The rewritten subprogram is actually an entry
11591 if Present
(Orig_Node
)
11592 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
11593 and then Is_Entry
(Name
(Orig_Node
))
11599 end Is_Renamed_Entry
;
11601 ----------------------------
11602 -- Is_Reversible_Iterator --
11603 ----------------------------
11605 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
11606 Ifaces_List
: Elist_Id
;
11607 Iface_Elmt
: Elmt_Id
;
11611 if Is_Class_Wide_Type
(Typ
)
11612 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
11613 and then Is_Predefined_File_Name
11614 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
11618 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
11622 Collect_Interfaces
(Typ
, Ifaces_List
);
11624 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
11625 while Present
(Iface_Elmt
) loop
11626 Iface
:= Node
(Iface_Elmt
);
11627 if Chars
(Iface
) = Name_Reversible_Iterator
11629 Is_Predefined_File_Name
11630 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
11635 Next_Elmt
(Iface_Elmt
);
11640 end Is_Reversible_Iterator
;
11642 ----------------------
11643 -- Is_Selector_Name --
11644 ----------------------
11646 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
11648 if not Is_List_Member
(N
) then
11650 P
: constant Node_Id
:= Parent
(N
);
11652 return Nkind_In
(P
, N_Expanded_Name
,
11653 N_Generic_Association
,
11654 N_Parameter_Association
,
11655 N_Selected_Component
)
11656 and then Selector_Name
(P
) = N
;
11661 L
: constant List_Id
:= List_Containing
(N
);
11662 P
: constant Node_Id
:= Parent
(L
);
11664 return (Nkind
(P
) = N_Discriminant_Association
11665 and then Selector_Names
(P
) = L
)
11667 (Nkind
(P
) = N_Component_Association
11668 and then Choices
(P
) = L
);
11671 end Is_Selector_Name
;
11673 -------------------------------------
11674 -- Is_SPARK_05_Initialization_Expr --
11675 -------------------------------------
11677 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
11680 Comp_Assn
: Node_Id
;
11681 Orig_N
: constant Node_Id
:= Original_Node
(N
);
11686 if not Comes_From_Source
(Orig_N
) then
11690 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
11692 case Nkind
(Orig_N
) is
11693 when N_Character_Literal |
11694 N_Integer_Literal |
11696 N_String_Literal
=>
11699 when N_Identifier |
11701 if Is_Entity_Name
(Orig_N
)
11702 and then Present
(Entity
(Orig_N
)) -- needed in some cases
11704 case Ekind
(Entity
(Orig_N
)) is
11706 E_Enumeration_Literal |
11711 if Is_Type
(Entity
(Orig_N
)) then
11719 when N_Qualified_Expression |
11720 N_Type_Conversion
=>
11721 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
11724 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
11728 N_Membership_Test
=>
11729 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
11731 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
11734 N_Extension_Aggregate
=>
11735 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
11737 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
11740 Expr
:= First
(Expressions
(Orig_N
));
11741 while Present
(Expr
) loop
11742 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
11750 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
11751 while Present
(Comp_Assn
) loop
11752 Expr
:= Expression
(Comp_Assn
);
11753 if Present
(Expr
) -- needed for box association
11754 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
11763 when N_Attribute_Reference
=>
11764 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
11765 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
11768 Expr
:= First
(Expressions
(Orig_N
));
11769 while Present
(Expr
) loop
11770 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
11778 -- Selected components might be expanded named not yet resolved, so
11779 -- default on the safe side. (Eg on sparklex.ads)
11781 when N_Selected_Component
=>
11790 end Is_SPARK_05_Initialization_Expr
;
11792 ----------------------------------
11793 -- Is_SPARK_05_Object_Reference --
11794 ----------------------------------
11796 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
11798 if Is_Entity_Name
(N
) then
11799 return Present
(Entity
(N
))
11801 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
11802 or else Ekind
(Entity
(N
)) in Formal_Kind
);
11806 when N_Selected_Component
=>
11807 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
11813 end Is_SPARK_05_Object_Reference
;
11819 function Is_Statement
(N
: Node_Id
) return Boolean is
11822 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
11823 or else Nkind
(N
) = N_Procedure_Call_Statement
;
11826 --------------------------------------------------
11827 -- Is_Subprogram_Stub_Without_Prior_Declaration --
11828 --------------------------------------------------
11830 function Is_Subprogram_Stub_Without_Prior_Declaration
11831 (N
: Node_Id
) return Boolean
11834 -- A subprogram stub without prior declaration serves as declaration for
11835 -- the actual subprogram body. As such, it has an attached defining
11836 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
11838 return Nkind
(N
) = N_Subprogram_Body_Stub
11839 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
11840 end Is_Subprogram_Stub_Without_Prior_Declaration
;
11842 ---------------------------------
11843 -- Is_Synchronized_Tagged_Type --
11844 ---------------------------------
11846 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
11847 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
11850 -- A task or protected type derived from an interface is a tagged type.
11851 -- Such a tagged type is called a synchronized tagged type, as are
11852 -- synchronized interfaces and private extensions whose declaration
11853 -- includes the reserved word synchronized.
11855 return (Is_Tagged_Type
(E
)
11856 and then (Kind
= E_Task_Type
11857 or else Kind
= E_Protected_Type
))
11860 and then Is_Synchronized_Interface
(E
))
11862 (Ekind
(E
) = E_Record_Type_With_Private
11863 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
11864 and then (Synchronized_Present
(Parent
(E
))
11865 or else Is_Synchronized_Interface
(Etype
(E
))));
11866 end Is_Synchronized_Tagged_Type
;
11872 function Is_Transfer
(N
: Node_Id
) return Boolean is
11873 Kind
: constant Node_Kind
:= Nkind
(N
);
11876 if Kind
= N_Simple_Return_Statement
11878 Kind
= N_Extended_Return_Statement
11880 Kind
= N_Goto_Statement
11882 Kind
= N_Raise_Statement
11884 Kind
= N_Requeue_Statement
11888 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
11889 and then No
(Condition
(N
))
11893 elsif Kind
= N_Procedure_Call_Statement
11894 and then Is_Entity_Name
(Name
(N
))
11895 and then Present
(Entity
(Name
(N
)))
11896 and then No_Return
(Entity
(Name
(N
)))
11900 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
11912 function Is_True
(U
: Uint
) return Boolean is
11917 --------------------------------------
11918 -- Is_Unchecked_Conversion_Instance --
11919 --------------------------------------
11921 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
11922 Gen_Par
: Entity_Id
;
11925 -- Look for a function whose generic parent is the predefined intrinsic
11926 -- function Unchecked_Conversion.
11928 if Ekind
(Id
) = E_Function
then
11929 Gen_Par
:= Generic_Parent
(Parent
(Id
));
11933 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
11934 and then Is_Intrinsic_Subprogram
(Gen_Par
)
11935 and then Is_Predefined_File_Name
11936 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
11940 end Is_Unchecked_Conversion_Instance
;
11942 -------------------------------
11943 -- Is_Universal_Numeric_Type --
11944 -------------------------------
11946 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
11948 return T
= Universal_Integer
or else T
= Universal_Real
;
11949 end Is_Universal_Numeric_Type
;
11951 -------------------
11952 -- Is_Value_Type --
11953 -------------------
11955 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
11957 return VM_Target
= CLI_Target
11958 and then Nkind
(T
) in N_Has_Chars
11959 and then Chars
(T
) /= No_Name
11960 and then Get_Name_String
(Chars
(T
)) = "valuetype";
11963 ----------------------------
11964 -- Is_Variable_Size_Array --
11965 ----------------------------
11967 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
11971 pragma Assert
(Is_Array_Type
(E
));
11973 -- Check if some index is initialized with a non-constant value
11975 Idx
:= First_Index
(E
);
11976 while Present
(Idx
) loop
11977 if Nkind
(Idx
) = N_Range
then
11978 if not Is_Constant_Bound
(Low_Bound
(Idx
))
11979 or else not Is_Constant_Bound
(High_Bound
(Idx
))
11985 Idx
:= Next_Index
(Idx
);
11989 end Is_Variable_Size_Array
;
11991 -----------------------------
11992 -- Is_Variable_Size_Record --
11993 -----------------------------
11995 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
11997 Comp_Typ
: Entity_Id
;
12000 pragma Assert
(Is_Record_Type
(E
));
12002 Comp
:= First_Entity
(E
);
12003 while Present
(Comp
) loop
12004 Comp_Typ
:= Etype
(Comp
);
12006 -- Recursive call if the record type has discriminants
12008 if Is_Record_Type
(Comp_Typ
)
12009 and then Has_Discriminants
(Comp_Typ
)
12010 and then Is_Variable_Size_Record
(Comp_Typ
)
12014 elsif Is_Array_Type
(Comp_Typ
)
12015 and then Is_Variable_Size_Array
(Comp_Typ
)
12020 Next_Entity
(Comp
);
12024 end Is_Variable_Size_Record
;
12030 function Is_Variable
12032 Use_Original_Node
: Boolean := True) return Boolean
12034 Orig_Node
: Node_Id
;
12036 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
12037 -- Within a protected function, the private components of the enclosing
12038 -- protected type are constants. A function nested within a (protected)
12039 -- procedure is not itself protected. Within the body of a protected
12040 -- function the current instance of the protected type is a constant.
12042 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
12043 -- Prefixes can involve implicit dereferences, in which case we must
12044 -- test for the case of a reference of a constant access type, which can
12045 -- can never be a variable.
12047 ---------------------------
12048 -- In_Protected_Function --
12049 ---------------------------
12051 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
12056 -- E is the current instance of a type
12058 if Is_Type
(E
) then
12067 if not Is_Protected_Type
(Prot
) then
12071 S
:= Current_Scope
;
12072 while Present
(S
) and then S
/= Prot
loop
12073 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
12082 end In_Protected_Function
;
12084 ------------------------
12085 -- Is_Variable_Prefix --
12086 ------------------------
12088 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
12090 if Is_Access_Type
(Etype
(P
)) then
12091 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
12093 -- For the case of an indexed component whose prefix has a packed
12094 -- array type, the prefix has been rewritten into a type conversion.
12095 -- Determine variable-ness from the converted expression.
12097 elsif Nkind
(P
) = N_Type_Conversion
12098 and then not Comes_From_Source
(P
)
12099 and then Is_Array_Type
(Etype
(P
))
12100 and then Is_Packed
(Etype
(P
))
12102 return Is_Variable
(Expression
(P
));
12105 return Is_Variable
(P
);
12107 end Is_Variable_Prefix
;
12109 -- Start of processing for Is_Variable
12112 -- Check if we perform the test on the original node since this may be a
12113 -- test of syntactic categories which must not be disturbed by whatever
12114 -- rewriting might have occurred. For example, an aggregate, which is
12115 -- certainly NOT a variable, could be turned into a variable by
12118 if Use_Original_Node
then
12119 Orig_Node
:= Original_Node
(N
);
12124 -- Definitely OK if Assignment_OK is set. Since this is something that
12125 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12127 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
12130 -- Normally we go to the original node, but there is one exception where
12131 -- we use the rewritten node, namely when it is an explicit dereference.
12132 -- The generated code may rewrite a prefix which is an access type with
12133 -- an explicit dereference. The dereference is a variable, even though
12134 -- the original node may not be (since it could be a constant of the
12137 -- In Ada 2005 we have a further case to consider: the prefix may be a
12138 -- function call given in prefix notation. The original node appears to
12139 -- be a selected component, but we need to examine the call.
12141 elsif Nkind
(N
) = N_Explicit_Dereference
12142 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
12143 and then Present
(Etype
(Orig_Node
))
12144 and then Is_Access_Type
(Etype
(Orig_Node
))
12146 -- Note that if the prefix is an explicit dereference that does not
12147 -- come from source, we must check for a rewritten function call in
12148 -- prefixed notation before other forms of rewriting, to prevent a
12152 (Nkind
(Orig_Node
) = N_Function_Call
12153 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
12155 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
12157 -- in Ada 2012, the dereference may have been added for a type with
12158 -- a declared implicit dereference aspect.
12160 elsif Nkind
(N
) = N_Explicit_Dereference
12161 and then Present
(Etype
(Orig_Node
))
12162 and then Ada_Version
>= Ada_2012
12163 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
12167 -- A function call is never a variable
12169 elsif Nkind
(N
) = N_Function_Call
then
12172 -- All remaining checks use the original node
12174 elsif Is_Entity_Name
(Orig_Node
)
12175 and then Present
(Entity
(Orig_Node
))
12178 E
: constant Entity_Id
:= Entity
(Orig_Node
);
12179 K
: constant Entity_Kind
:= Ekind
(E
);
12182 return (K
= E_Variable
12183 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
12184 or else (K
= E_Component
12185 and then not In_Protected_Function
(E
))
12186 or else K
= E_Out_Parameter
12187 or else K
= E_In_Out_Parameter
12188 or else K
= E_Generic_In_Out_Parameter
12190 -- Current instance of type. If this is a protected type, check
12191 -- we are not within the body of one of its protected functions.
12193 or else (Is_Type
(E
)
12194 and then In_Open_Scopes
(E
)
12195 and then not In_Protected_Function
(E
))
12197 or else (Is_Incomplete_Or_Private_Type
(E
)
12198 and then In_Open_Scopes
(Full_View
(E
)));
12202 case Nkind
(Orig_Node
) is
12203 when N_Indexed_Component | N_Slice
=>
12204 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
12206 when N_Selected_Component
=>
12207 return (Is_Variable
(Selector_Name
(Orig_Node
))
12208 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
12210 (Nkind
(N
) = N_Expanded_Name
12211 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
12213 -- For an explicit dereference, the type of the prefix cannot
12214 -- be an access to constant or an access to subprogram.
12216 when N_Explicit_Dereference
=>
12218 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
12220 return Is_Access_Type
(Typ
)
12221 and then not Is_Access_Constant
(Root_Type
(Typ
))
12222 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
12225 -- The type conversion is the case where we do not deal with the
12226 -- context dependent special case of an actual parameter. Thus
12227 -- the type conversion is only considered a variable for the
12228 -- purposes of this routine if the target type is tagged. However,
12229 -- a type conversion is considered to be a variable if it does not
12230 -- come from source (this deals for example with the conversions
12231 -- of expressions to their actual subtypes).
12233 when N_Type_Conversion
=>
12234 return Is_Variable
(Expression
(Orig_Node
))
12236 (not Comes_From_Source
(Orig_Node
)
12238 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
12240 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
12242 -- GNAT allows an unchecked type conversion as a variable. This
12243 -- only affects the generation of internal expanded code, since
12244 -- calls to instantiations of Unchecked_Conversion are never
12245 -- considered variables (since they are function calls).
12247 when N_Unchecked_Type_Conversion
=>
12248 return Is_Variable
(Expression
(Orig_Node
));
12256 ---------------------------
12257 -- Is_Visibly_Controlled --
12258 ---------------------------
12260 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
12261 Root
: constant Entity_Id
:= Root_Type
(T
);
12263 return Chars
(Scope
(Root
)) = Name_Finalization
12264 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
12265 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
12266 end Is_Visibly_Controlled
;
12268 ------------------------
12269 -- Is_Volatile_Object --
12270 ------------------------
12272 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
12274 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
12275 -- If prefix is an implicit dereference, examine designated type
12277 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
12278 -- Determines if given object has volatile components
12280 ------------------------
12281 -- Is_Volatile_Prefix --
12282 ------------------------
12284 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
12285 Typ
: constant Entity_Id
:= Etype
(N
);
12288 if Is_Access_Type
(Typ
) then
12290 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
12293 return Is_Volatile
(Dtyp
)
12294 or else Has_Volatile_Components
(Dtyp
);
12298 return Object_Has_Volatile_Components
(N
);
12300 end Is_Volatile_Prefix
;
12302 ------------------------------------
12303 -- Object_Has_Volatile_Components --
12304 ------------------------------------
12306 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
12307 Typ
: constant Entity_Id
:= Etype
(N
);
12310 if Is_Volatile
(Typ
)
12311 or else Has_Volatile_Components
(Typ
)
12315 elsif Is_Entity_Name
(N
)
12316 and then (Has_Volatile_Components
(Entity
(N
))
12317 or else Is_Volatile
(Entity
(N
)))
12321 elsif Nkind
(N
) = N_Indexed_Component
12322 or else Nkind
(N
) = N_Selected_Component
12324 return Is_Volatile_Prefix
(Prefix
(N
));
12329 end Object_Has_Volatile_Components
;
12331 -- Start of processing for Is_Volatile_Object
12334 if Nkind
(N
) = N_Defining_Identifier
then
12335 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
12337 elsif Nkind
(N
) = N_Expanded_Name
then
12338 return Is_Volatile_Object
(Entity
(N
));
12340 elsif Is_Volatile
(Etype
(N
))
12341 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
12345 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
12346 and then Is_Volatile_Prefix
(Prefix
(N
))
12350 elsif Nkind
(N
) = N_Selected_Component
12351 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
12358 end Is_Volatile_Object
;
12360 ---------------------------
12361 -- Itype_Has_Declaration --
12362 ---------------------------
12364 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
12366 pragma Assert
(Is_Itype
(Id
));
12367 return Present
(Parent
(Id
))
12368 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
12369 N_Subtype_Declaration
)
12370 and then Defining_Entity
(Parent
(Id
)) = Id
;
12371 end Itype_Has_Declaration
;
12373 -------------------------
12374 -- Kill_Current_Values --
12375 -------------------------
12377 procedure Kill_Current_Values
12379 Last_Assignment_Only
: Boolean := False)
12382 if Is_Assignable
(Ent
) then
12383 Set_Last_Assignment
(Ent
, Empty
);
12386 if Is_Object
(Ent
) then
12387 if not Last_Assignment_Only
then
12389 Set_Current_Value
(Ent
, Empty
);
12391 if not Can_Never_Be_Null
(Ent
) then
12392 Set_Is_Known_Non_Null
(Ent
, False);
12395 Set_Is_Known_Null
(Ent
, False);
12397 -- Reset Is_Known_Valid unless type is always valid, or if we have
12398 -- a loop parameter (loop parameters are always valid, since their
12399 -- bounds are defined by the bounds given in the loop header).
12401 if not Is_Known_Valid
(Etype
(Ent
))
12402 and then Ekind
(Ent
) /= E_Loop_Parameter
12404 Set_Is_Known_Valid
(Ent
, False);
12408 end Kill_Current_Values
;
12410 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
12413 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
12414 -- Clear current value for entity E and all entities chained to E
12416 ------------------------------------------
12417 -- Kill_Current_Values_For_Entity_Chain --
12418 ------------------------------------------
12420 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
12424 while Present
(Ent
) loop
12425 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
12428 end Kill_Current_Values_For_Entity_Chain
;
12430 -- Start of processing for Kill_Current_Values
12433 -- Kill all saved checks, a special case of killing saved values
12435 if not Last_Assignment_Only
then
12439 -- Loop through relevant scopes, which includes the current scope and
12440 -- any parent scopes if the current scope is a block or a package.
12442 S
:= Current_Scope
;
12445 -- Clear current values of all entities in current scope
12447 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
12449 -- If scope is a package, also clear current values of all private
12450 -- entities in the scope.
12452 if Is_Package_Or_Generic_Package
(S
)
12453 or else Is_Concurrent_Type
(S
)
12455 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
12458 -- If this is a not a subprogram, deal with parents
12460 if not Is_Subprogram
(S
) then
12462 exit Scope_Loop
when S
= Standard_Standard
;
12466 end loop Scope_Loop
;
12467 end Kill_Current_Values
;
12469 --------------------------
12470 -- Kill_Size_Check_Code --
12471 --------------------------
12473 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
12475 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
12476 and then Present
(Size_Check_Code
(E
))
12478 Remove
(Size_Check_Code
(E
));
12479 Set_Size_Check_Code
(E
, Empty
);
12481 end Kill_Size_Check_Code
;
12483 --------------------------
12484 -- Known_To_Be_Assigned --
12485 --------------------------
12487 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
12488 P
: constant Node_Id
:= Parent
(N
);
12493 -- Test left side of assignment
12495 when N_Assignment_Statement
=>
12496 return N
= Name
(P
);
12498 -- Function call arguments are never lvalues
12500 when N_Function_Call
=>
12503 -- Positional parameter for procedure or accept call
12505 when N_Procedure_Call_Statement |
12514 Proc
:= Get_Subprogram_Entity
(P
);
12520 -- If we are not a list member, something is strange, so
12521 -- be conservative and return False.
12523 if not Is_List_Member
(N
) then
12527 -- We are going to find the right formal by stepping forward
12528 -- through the formals, as we step backwards in the actuals.
12530 Form
:= First_Formal
(Proc
);
12533 -- If no formal, something is weird, so be conservative
12534 -- and return False.
12541 exit when No
(Act
);
12542 Next_Formal
(Form
);
12545 return Ekind
(Form
) /= E_In_Parameter
;
12548 -- Named parameter for procedure or accept call
12550 when N_Parameter_Association
=>
12556 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
12562 -- Loop through formals to find the one that matches
12564 Form
:= First_Formal
(Proc
);
12566 -- If no matching formal, that's peculiar, some kind of
12567 -- previous error, so return False to be conservative.
12568 -- Actually this also happens in legal code in the case
12569 -- where P is a parameter association for an Extra_Formal???
12575 -- Else test for match
12577 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
12578 return Ekind
(Form
) /= E_In_Parameter
;
12581 Next_Formal
(Form
);
12585 -- Test for appearing in a conversion that itself appears
12586 -- in an lvalue context, since this should be an lvalue.
12588 when N_Type_Conversion
=>
12589 return Known_To_Be_Assigned
(P
);
12591 -- All other references are definitely not known to be modifications
12597 end Known_To_Be_Assigned
;
12599 ---------------------------
12600 -- Last_Source_Statement --
12601 ---------------------------
12603 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
12607 N
:= Last
(Statements
(HSS
));
12608 while Present
(N
) loop
12609 exit when Comes_From_Source
(N
);
12614 end Last_Source_Statement
;
12616 ----------------------------------
12617 -- Matching_Static_Array_Bounds --
12618 ----------------------------------
12620 function Matching_Static_Array_Bounds
12622 R_Typ
: Node_Id
) return Boolean
12624 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
12625 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
12637 if L_Ndims
/= R_Ndims
then
12641 -- Unconstrained types do not have static bounds
12643 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
12647 -- First treat specially the first dimension, as the lower bound and
12648 -- length of string literals are not stored like those of arrays.
12650 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
12651 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
12652 L_Len
:= String_Literal_Length
(L_Typ
);
12654 L_Index
:= First_Index
(L_Typ
);
12655 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
12657 if Is_OK_Static_Expression
(L_Low
)
12659 Is_OK_Static_Expression
(L_High
)
12661 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
12664 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
12671 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
12672 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
12673 R_Len
:= String_Literal_Length
(R_Typ
);
12675 R_Index
:= First_Index
(R_Typ
);
12676 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
12678 if Is_OK_Static_Expression
(R_Low
)
12680 Is_OK_Static_Expression
(R_High
)
12682 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
12685 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
12692 if (Is_OK_Static_Expression
(L_Low
)
12694 Is_OK_Static_Expression
(R_Low
))
12695 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
12696 and then L_Len
= R_Len
12703 -- Then treat all other dimensions
12705 for Indx
in 2 .. L_Ndims
loop
12709 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
12710 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
12712 if (Is_OK_Static_Expression
(L_Low
) and then
12713 Is_OK_Static_Expression
(L_High
) and then
12714 Is_OK_Static_Expression
(R_Low
) and then
12715 Is_OK_Static_Expression
(R_High
))
12716 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
12718 Expr_Value
(L_High
) = Expr_Value
(R_High
))
12726 -- If we fall through the loop, all indexes matched
12729 end Matching_Static_Array_Bounds
;
12731 -------------------
12732 -- May_Be_Lvalue --
12733 -------------------
12735 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
12736 P
: constant Node_Id
:= Parent
(N
);
12741 -- Test left side of assignment
12743 when N_Assignment_Statement
=>
12744 return N
= Name
(P
);
12746 -- Test prefix of component or attribute. Note that the prefix of an
12747 -- explicit or implicit dereference cannot be an l-value.
12749 when N_Attribute_Reference
=>
12750 return N
= Prefix
(P
)
12751 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
12753 -- For an expanded name, the name is an lvalue if the expanded name
12754 -- is an lvalue, but the prefix is never an lvalue, since it is just
12755 -- the scope where the name is found.
12757 when N_Expanded_Name
=>
12758 if N
= Prefix
(P
) then
12759 return May_Be_Lvalue
(P
);
12764 -- For a selected component A.B, A is certainly an lvalue if A.B is.
12765 -- B is a little interesting, if we have A.B := 3, there is some
12766 -- discussion as to whether B is an lvalue or not, we choose to say
12767 -- it is. Note however that A is not an lvalue if it is of an access
12768 -- type since this is an implicit dereference.
12770 when N_Selected_Component
=>
12772 and then Present
(Etype
(N
))
12773 and then Is_Access_Type
(Etype
(N
))
12777 return May_Be_Lvalue
(P
);
12780 -- For an indexed component or slice, the index or slice bounds is
12781 -- never an lvalue. The prefix is an lvalue if the indexed component
12782 -- or slice is an lvalue, except if it is an access type, where we
12783 -- have an implicit dereference.
12785 when N_Indexed_Component | N_Slice
=>
12787 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
12791 return May_Be_Lvalue
(P
);
12794 -- Prefix of a reference is an lvalue if the reference is an lvalue
12796 when N_Reference
=>
12797 return May_Be_Lvalue
(P
);
12799 -- Prefix of explicit dereference is never an lvalue
12801 when N_Explicit_Dereference
=>
12804 -- Positional parameter for subprogram, entry, or accept call.
12805 -- In older versions of Ada function call arguments are never
12806 -- lvalues. In Ada 2012 functions can have in-out parameters.
12808 when N_Subprogram_Call |
12809 N_Entry_Call_Statement |
12812 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
12816 -- The following mechanism is clumsy and fragile. A single flag
12817 -- set in Resolve_Actuals would be preferable ???
12825 Proc
:= Get_Subprogram_Entity
(P
);
12831 -- If we are not a list member, something is strange, so be
12832 -- conservative and return True.
12834 if not Is_List_Member
(N
) then
12838 -- We are going to find the right formal by stepping forward
12839 -- through the formals, as we step backwards in the actuals.
12841 Form
:= First_Formal
(Proc
);
12844 -- If no formal, something is weird, so be conservative and
12852 exit when No
(Act
);
12853 Next_Formal
(Form
);
12856 return Ekind
(Form
) /= E_In_Parameter
;
12859 -- Named parameter for procedure or accept call
12861 when N_Parameter_Association
=>
12867 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
12873 -- Loop through formals to find the one that matches
12875 Form
:= First_Formal
(Proc
);
12877 -- If no matching formal, that's peculiar, some kind of
12878 -- previous error, so return True to be conservative.
12879 -- Actually happens with legal code for an unresolved call
12880 -- where we may get the wrong homonym???
12886 -- Else test for match
12888 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
12889 return Ekind
(Form
) /= E_In_Parameter
;
12892 Next_Formal
(Form
);
12896 -- Test for appearing in a conversion that itself appears in an
12897 -- lvalue context, since this should be an lvalue.
12899 when N_Type_Conversion
=>
12900 return May_Be_Lvalue
(P
);
12902 -- Test for appearance in object renaming declaration
12904 when N_Object_Renaming_Declaration
=>
12907 -- All other references are definitely not lvalues
12915 -----------------------
12916 -- Mark_Coextensions --
12917 -----------------------
12919 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
12920 Is_Dynamic
: Boolean;
12921 -- Indicates whether the context causes nested coextensions to be
12922 -- dynamic or static
12924 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
12925 -- Recognize an allocator node and label it as a dynamic coextension
12927 --------------------
12928 -- Mark_Allocator --
12929 --------------------
12931 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
12933 if Nkind
(N
) = N_Allocator
then
12935 Set_Is_Dynamic_Coextension
(N
);
12937 -- If the allocator expression is potentially dynamic, it may
12938 -- be expanded out of order and require dynamic allocation
12939 -- anyway, so we treat the coextension itself as dynamic.
12940 -- Potential optimization ???
12942 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
12943 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
12945 Set_Is_Dynamic_Coextension
(N
);
12947 Set_Is_Static_Coextension
(N
);
12952 end Mark_Allocator
;
12954 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
12956 -- Start of processing Mark_Coextensions
12959 case Nkind
(Context_Nod
) is
12961 -- Comment here ???
12963 when N_Assignment_Statement
=>
12964 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
12966 -- An allocator that is a component of a returned aggregate
12967 -- must be dynamic.
12969 when N_Simple_Return_Statement
=>
12971 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
12974 Nkind
(Expr
) = N_Allocator
12976 (Nkind
(Expr
) = N_Qualified_Expression
12977 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
12980 -- An alloctor within an object declaration in an extended return
12981 -- statement is of necessity dynamic.
12983 when N_Object_Declaration
=>
12984 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
12986 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
12988 -- This routine should not be called for constructs which may not
12989 -- contain coextensions.
12992 raise Program_Error
;
12995 Mark_Allocators
(Root_Nod
);
12996 end Mark_Coextensions
;
13002 function Must_Inline
(Subp
: Entity_Id
) return Boolean is
13005 (Optimization_Level
= 0
13007 -- AAMP and VM targets have no support for inlining in the backend.
13008 -- Hence we do as much inlining as possible in the front end.
13010 or else AAMP_On_Target
13011 or else VM_Target
/= No_VM
)
13012 and then Has_Pragma_Inline
(Subp
)
13013 and then (Has_Pragma_Inline_Always
(Subp
) or else Front_End_Inlining
);
13016 ----------------------
13017 -- Needs_One_Actual --
13018 ----------------------
13020 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
13021 Formal
: Entity_Id
;
13024 -- Ada 2005 or later, and formals present
13026 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
13027 Formal
:= Next_Formal
(First_Formal
(E
));
13028 while Present
(Formal
) loop
13029 if No
(Default_Value
(Formal
)) then
13033 Next_Formal
(Formal
);
13038 -- Ada 83/95 or no formals
13043 end Needs_One_Actual
;
13045 ------------------------
13046 -- New_Copy_List_Tree --
13047 ------------------------
13049 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
13054 if List
= No_List
then
13061 while Present
(E
) loop
13062 Append
(New_Copy_Tree
(E
), NL
);
13068 end New_Copy_List_Tree
;
13070 -------------------
13071 -- New_Copy_Tree --
13072 -------------------
13074 use Atree
.Unchecked_Access
;
13075 use Atree_Private_Part
;
13077 -- Our approach here requires a two pass traversal of the tree. The
13078 -- first pass visits all nodes that eventually will be copied looking
13079 -- for defining Itypes. If any defining Itypes are found, then they are
13080 -- copied, and an entry is added to the replacement map. In the second
13081 -- phase, the tree is copied, using the replacement map to replace any
13082 -- Itype references within the copied tree.
13084 -- The following hash tables are used if the Map supplied has more
13085 -- than hash threshold entries to speed up access to the map. If
13086 -- there are fewer entries, then the map is searched sequentially
13087 -- (because setting up a hash table for only a few entries takes
13088 -- more time than it saves.
13090 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
13091 -- Hash function used for hash operations
13093 -------------------
13094 -- New_Copy_Hash --
13095 -------------------
13097 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
13099 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
13106 -- The hash table NCT_Assoc associates old entities in the table
13107 -- with their corresponding new entities (i.e. the pairs of entries
13108 -- presented in the original Map argument are Key-Element pairs).
13110 package NCT_Assoc
is new Simple_HTable
(
13111 Header_Num
=> NCT_Header_Num
,
13112 Element
=> Entity_Id
,
13113 No_Element
=> Empty
,
13115 Hash
=> New_Copy_Hash
,
13116 Equal
=> Types
."=");
13118 ---------------------
13119 -- NCT_Itype_Assoc --
13120 ---------------------
13122 -- The hash table NCT_Itype_Assoc contains entries only for those
13123 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13124 -- The key is the associated node, and the element is the new node
13125 -- itself (NOT the associated node for the new node).
13127 package NCT_Itype_Assoc
is new Simple_HTable
(
13128 Header_Num
=> NCT_Header_Num
,
13129 Element
=> Entity_Id
,
13130 No_Element
=> Empty
,
13132 Hash
=> New_Copy_Hash
,
13133 Equal
=> Types
."=");
13135 -- Start of processing for New_Copy_Tree function
13137 function New_Copy_Tree
13139 Map
: Elist_Id
:= No_Elist
;
13140 New_Sloc
: Source_Ptr
:= No_Location
;
13141 New_Scope
: Entity_Id
:= Empty
) return Node_Id
13143 Actual_Map
: Elist_Id
:= Map
;
13144 -- This is the actual map for the copy. It is initialized with the
13145 -- given elements, and then enlarged as required for Itypes that are
13146 -- copied during the first phase of the copy operation. The visit
13147 -- procedures add elements to this map as Itypes are encountered.
13148 -- The reason we cannot use Map directly, is that it may well be
13149 -- (and normally is) initialized to No_Elist, and if we have mapped
13150 -- entities, we have to reset it to point to a real Elist.
13152 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
13153 -- Called during second phase to map entities into their corresponding
13154 -- copies using Actual_Map. If the argument is not an entity, or is not
13155 -- in Actual_Map, then it is returned unchanged.
13157 procedure Build_NCT_Hash_Tables
;
13158 -- Builds hash tables (number of elements >= threshold value)
13160 function Copy_Elist_With_Replacement
13161 (Old_Elist
: Elist_Id
) return Elist_Id
;
13162 -- Called during second phase to copy element list doing replacements
13164 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
13165 -- Called during the second phase to process a copied Itype. The actual
13166 -- copy happened during the first phase (so that we could make the entry
13167 -- in the mapping), but we still have to deal with the descendents of
13168 -- the copied Itype and copy them where necessary.
13170 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
13171 -- Called during second phase to copy list doing replacements
13173 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
13174 -- Called during second phase to copy node doing replacements
13176 procedure Visit_Elist
(E
: Elist_Id
);
13177 -- Called during first phase to visit all elements of an Elist
13179 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
13180 -- Visit a single field, recursing to call Visit_Node or Visit_List
13181 -- if the field is a syntactic descendent of the current node (i.e.
13182 -- its parent is Node N).
13184 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
13185 -- Called during first phase to visit subsidiary fields of a defining
13186 -- Itype, and also create a copy and make an entry in the replacement
13187 -- map for the new copy.
13189 procedure Visit_List
(L
: List_Id
);
13190 -- Called during first phase to visit all elements of a List
13192 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
13193 -- Called during first phase to visit a node and all its subtrees
13199 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
13204 if not Has_Extension
(N
) or else No
(Actual_Map
) then
13207 elsif NCT_Hash_Tables_Used
then
13208 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
13210 if Present
(Ent
) then
13216 -- No hash table used, do serial search
13219 E
:= First_Elmt
(Actual_Map
);
13220 while Present
(E
) loop
13221 if Node
(E
) = N
then
13222 return Node
(Next_Elmt
(E
));
13224 E
:= Next_Elmt
(Next_Elmt
(E
));
13232 ---------------------------
13233 -- Build_NCT_Hash_Tables --
13234 ---------------------------
13236 procedure Build_NCT_Hash_Tables
is
13240 if NCT_Hash_Table_Setup
then
13242 NCT_Itype_Assoc
.Reset
;
13245 Elmt
:= First_Elmt
(Actual_Map
);
13246 while Present
(Elmt
) loop
13247 Ent
:= Node
(Elmt
);
13249 -- Get new entity, and associate old and new
13252 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
13254 if Is_Type
(Ent
) then
13256 Anode
: constant Entity_Id
:=
13257 Associated_Node_For_Itype
(Ent
);
13260 if Present
(Anode
) then
13262 -- Enter a link between the associated node of the
13263 -- old Itype and the new Itype, for updating later
13264 -- when node is copied.
13266 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
13274 NCT_Hash_Tables_Used
:= True;
13275 NCT_Hash_Table_Setup
:= True;
13276 end Build_NCT_Hash_Tables
;
13278 ---------------------------------
13279 -- Copy_Elist_With_Replacement --
13280 ---------------------------------
13282 function Copy_Elist_With_Replacement
13283 (Old_Elist
: Elist_Id
) return Elist_Id
13286 New_Elist
: Elist_Id
;
13289 if No
(Old_Elist
) then
13293 New_Elist
:= New_Elmt_List
;
13295 M
:= First_Elmt
(Old_Elist
);
13296 while Present
(M
) loop
13297 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
13303 end Copy_Elist_With_Replacement
;
13305 ---------------------------------
13306 -- Copy_Itype_With_Replacement --
13307 ---------------------------------
13309 -- This routine exactly parallels its phase one analog Visit_Itype,
13311 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
13313 -- Translate Next_Entity, Scope and Etype fields, in case they
13314 -- reference entities that have been mapped into copies.
13316 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
13317 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
13319 if Present
(New_Scope
) then
13320 Set_Scope
(New_Itype
, New_Scope
);
13322 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
13325 -- Copy referenced fields
13327 if Is_Discrete_Type
(New_Itype
) then
13328 Set_Scalar_Range
(New_Itype
,
13329 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
13331 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
13332 Set_Discriminant_Constraint
(New_Itype
,
13333 Copy_Elist_With_Replacement
13334 (Discriminant_Constraint
(New_Itype
)));
13336 elsif Is_Array_Type
(New_Itype
) then
13337 if Present
(First_Index
(New_Itype
)) then
13338 Set_First_Index
(New_Itype
,
13339 First
(Copy_List_With_Replacement
13340 (List_Containing
(First_Index
(New_Itype
)))));
13343 if Is_Packed
(New_Itype
) then
13344 Set_Packed_Array_Impl_Type
(New_Itype
,
13345 Copy_Node_With_Replacement
13346 (Packed_Array_Impl_Type
(New_Itype
)));
13349 end Copy_Itype_With_Replacement
;
13351 --------------------------------
13352 -- Copy_List_With_Replacement --
13353 --------------------------------
13355 function Copy_List_With_Replacement
13356 (Old_List
: List_Id
) return List_Id
13358 New_List
: List_Id
;
13362 if Old_List
= No_List
then
13366 New_List
:= Empty_List
;
13368 E
:= First
(Old_List
);
13369 while Present
(E
) loop
13370 Append
(Copy_Node_With_Replacement
(E
), New_List
);
13376 end Copy_List_With_Replacement
;
13378 --------------------------------
13379 -- Copy_Node_With_Replacement --
13380 --------------------------------
13382 function Copy_Node_With_Replacement
13383 (Old_Node
: Node_Id
) return Node_Id
13385 New_Node
: Node_Id
;
13387 procedure Adjust_Named_Associations
13388 (Old_Node
: Node_Id
;
13389 New_Node
: Node_Id
);
13390 -- If a call node has named associations, these are chained through
13391 -- the First_Named_Actual, Next_Named_Actual links. These must be
13392 -- propagated separately to the new parameter list, because these
13393 -- are not syntactic fields.
13395 function Copy_Field_With_Replacement
13396 (Field
: Union_Id
) return Union_Id
;
13397 -- Given Field, which is a field of Old_Node, return a copy of it
13398 -- if it is a syntactic field (i.e. its parent is Node), setting
13399 -- the parent of the copy to poit to New_Node. Otherwise returns
13400 -- the field (possibly mapped if it is an entity).
13402 -------------------------------
13403 -- Adjust_Named_Associations --
13404 -------------------------------
13406 procedure Adjust_Named_Associations
13407 (Old_Node
: Node_Id
;
13408 New_Node
: Node_Id
)
13413 Old_Next
: Node_Id
;
13414 New_Next
: Node_Id
;
13417 Old_E
:= First
(Parameter_Associations
(Old_Node
));
13418 New_E
:= First
(Parameter_Associations
(New_Node
));
13419 while Present
(Old_E
) loop
13420 if Nkind
(Old_E
) = N_Parameter_Association
13421 and then Present
(Next_Named_Actual
(Old_E
))
13423 if First_Named_Actual
(Old_Node
)
13424 = Explicit_Actual_Parameter
(Old_E
)
13426 Set_First_Named_Actual
13427 (New_Node
, Explicit_Actual_Parameter
(New_E
));
13430 -- Now scan parameter list from the beginning,to locate
13431 -- next named actual, which can be out of order.
13433 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
13434 New_Next
:= First
(Parameter_Associations
(New_Node
));
13436 while Nkind
(Old_Next
) /= N_Parameter_Association
13437 or else Explicit_Actual_Parameter
(Old_Next
)
13438 /= Next_Named_Actual
(Old_E
)
13444 Set_Next_Named_Actual
13445 (New_E
, Explicit_Actual_Parameter
(New_Next
));
13451 end Adjust_Named_Associations
;
13453 ---------------------------------
13454 -- Copy_Field_With_Replacement --
13455 ---------------------------------
13457 function Copy_Field_With_Replacement
13458 (Field
: Union_Id
) return Union_Id
13461 if Field
= Union_Id
(Empty
) then
13464 elsif Field
in Node_Range
then
13466 Old_N
: constant Node_Id
:= Node_Id
(Field
);
13470 -- If syntactic field, as indicated by the parent pointer
13471 -- being set, then copy the referenced node recursively.
13473 if Parent
(Old_N
) = Old_Node
then
13474 New_N
:= Copy_Node_With_Replacement
(Old_N
);
13476 if New_N
/= Old_N
then
13477 Set_Parent
(New_N
, New_Node
);
13480 -- For semantic fields, update possible entity reference
13481 -- from the replacement map.
13484 New_N
:= Assoc
(Old_N
);
13487 return Union_Id
(New_N
);
13490 elsif Field
in List_Range
then
13492 Old_L
: constant List_Id
:= List_Id
(Field
);
13496 -- If syntactic field, as indicated by the parent pointer,
13497 -- then recursively copy the entire referenced list.
13499 if Parent
(Old_L
) = Old_Node
then
13500 New_L
:= Copy_List_With_Replacement
(Old_L
);
13501 Set_Parent
(New_L
, New_Node
);
13503 -- For semantic list, just returned unchanged
13509 return Union_Id
(New_L
);
13512 -- Anything other than a list or a node is returned unchanged
13517 end Copy_Field_With_Replacement
;
13519 -- Start of processing for Copy_Node_With_Replacement
13522 if Old_Node
<= Empty_Or_Error
then
13525 elsif Has_Extension
(Old_Node
) then
13526 return Assoc
(Old_Node
);
13529 New_Node
:= New_Copy
(Old_Node
);
13531 -- If the node we are copying is the associated node of a
13532 -- previously copied Itype, then adjust the associated node
13533 -- of the copy of that Itype accordingly.
13535 if Present
(Actual_Map
) then
13541 -- Case of hash table used
13543 if NCT_Hash_Tables_Used
then
13544 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
13546 if Present
(Ent
) then
13547 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
13550 -- Case of no hash table used
13553 E
:= First_Elmt
(Actual_Map
);
13554 while Present
(E
) loop
13555 if Is_Itype
(Node
(E
))
13557 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
13559 Set_Associated_Node_For_Itype
13560 (Node
(Next_Elmt
(E
)), New_Node
);
13563 E
:= Next_Elmt
(Next_Elmt
(E
));
13569 -- Recursively copy descendents
13572 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
13574 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
13576 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
13578 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
13580 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
13582 -- Adjust Sloc of new node if necessary
13584 if New_Sloc
/= No_Location
then
13585 Set_Sloc
(New_Node
, New_Sloc
);
13587 -- If we adjust the Sloc, then we are essentially making
13588 -- a completely new node, so the Comes_From_Source flag
13589 -- should be reset to the proper default value.
13591 Nodes
.Table
(New_Node
).Comes_From_Source
:=
13592 Default_Node
.Comes_From_Source
;
13595 -- If the node is call and has named associations,
13596 -- set the corresponding links in the copy.
13598 if (Nkind
(Old_Node
) = N_Function_Call
13599 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
13601 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
13602 and then Present
(First_Named_Actual
(Old_Node
))
13604 Adjust_Named_Associations
(Old_Node
, New_Node
);
13607 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
13608 -- The replacement mechanism applies to entities, and is not used
13609 -- here. Eventually we may need a more general graph-copying
13610 -- routine. For now, do a sequential search to find desired node.
13612 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
13613 and then Present
(First_Real_Statement
(Old_Node
))
13616 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
13620 N1
:= First
(Statements
(Old_Node
));
13621 N2
:= First
(Statements
(New_Node
));
13623 while N1
/= Old_F
loop
13628 Set_First_Real_Statement
(New_Node
, N2
);
13633 -- All done, return copied node
13636 end Copy_Node_With_Replacement
;
13642 procedure Visit_Elist
(E
: Elist_Id
) is
13645 if Present
(E
) then
13646 Elmt
:= First_Elmt
(E
);
13648 while Elmt
/= No_Elmt
loop
13649 Visit_Node
(Node
(Elmt
));
13659 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
13661 if F
= Union_Id
(Empty
) then
13664 elsif F
in Node_Range
then
13666 -- Copy node if it is syntactic, i.e. its parent pointer is
13667 -- set to point to the field that referenced it (certain
13668 -- Itypes will also meet this criterion, which is fine, since
13669 -- these are clearly Itypes that do need to be copied, since
13670 -- we are copying their parent.)
13672 if Parent
(Node_Id
(F
)) = N
then
13673 Visit_Node
(Node_Id
(F
));
13676 -- Another case, if we are pointing to an Itype, then we want
13677 -- to copy it if its associated node is somewhere in the tree
13680 -- Note: the exclusion of self-referential copies is just an
13681 -- optimization, since the search of the already copied list
13682 -- would catch it, but it is a common case (Etype pointing
13683 -- to itself for an Itype that is a base type).
13685 elsif Has_Extension
(Node_Id
(F
))
13686 and then Is_Itype
(Entity_Id
(F
))
13687 and then Node_Id
(F
) /= N
13693 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
13694 while Present
(P
) loop
13696 Visit_Node
(Node_Id
(F
));
13703 -- An Itype whose parent is not being copied definitely
13704 -- should NOT be copied, since it does not belong in any
13705 -- sense to the copied subtree.
13711 elsif F
in List_Range
and then Parent
(List_Id
(F
)) = N
then
13712 Visit_List
(List_Id
(F
));
13721 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
13722 New_Itype
: Entity_Id
;
13727 -- Itypes that describe the designated type of access to subprograms
13728 -- have the structure of subprogram declarations, with signatures,
13729 -- etc. Either we duplicate the signatures completely, or choose to
13730 -- share such itypes, which is fine because their elaboration will
13731 -- have no side effects.
13733 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
13737 New_Itype
:= New_Copy
(Old_Itype
);
13739 -- The new Itype has all the attributes of the old one, and
13740 -- we just copy the contents of the entity. However, the back-end
13741 -- needs different names for debugging purposes, so we create a
13742 -- new internal name for it in all cases.
13744 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
13746 -- If our associated node is an entity that has already been copied,
13747 -- then set the associated node of the copy to point to the right
13748 -- copy. If we have copied an Itype that is itself the associated
13749 -- node of some previously copied Itype, then we set the right
13750 -- pointer in the other direction.
13752 if Present
(Actual_Map
) then
13754 -- Case of hash tables used
13756 if NCT_Hash_Tables_Used
then
13758 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
13760 if Present
(Ent
) then
13761 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
13764 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
13765 if Present
(Ent
) then
13766 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
13768 -- If the hash table has no association for this Itype and
13769 -- its associated node, enter one now.
13772 NCT_Itype_Assoc
.Set
13773 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
13776 -- Case of hash tables not used
13779 E
:= First_Elmt
(Actual_Map
);
13780 while Present
(E
) loop
13781 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
13782 Set_Associated_Node_For_Itype
13783 (New_Itype
, Node
(Next_Elmt
(E
)));
13786 if Is_Type
(Node
(E
))
13787 and then Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
13789 Set_Associated_Node_For_Itype
13790 (Node
(Next_Elmt
(E
)), New_Itype
);
13793 E
:= Next_Elmt
(Next_Elmt
(E
));
13798 if Present
(Freeze_Node
(New_Itype
)) then
13799 Set_Is_Frozen
(New_Itype
, False);
13800 Set_Freeze_Node
(New_Itype
, Empty
);
13803 -- Add new association to map
13805 if No
(Actual_Map
) then
13806 Actual_Map
:= New_Elmt_List
;
13809 Append_Elmt
(Old_Itype
, Actual_Map
);
13810 Append_Elmt
(New_Itype
, Actual_Map
);
13812 if NCT_Hash_Tables_Used
then
13813 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
13816 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13818 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13819 Build_NCT_Hash_Tables
;
13823 -- If a record subtype is simply copied, the entity list will be
13824 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
13826 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
13827 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
13830 -- Visit descendents that eventually get copied
13832 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
13834 if Is_Discrete_Type
(Old_Itype
) then
13835 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
13837 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
13838 -- ??? This should involve call to Visit_Field
13839 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
13841 elsif Is_Array_Type
(Old_Itype
) then
13842 if Present
(First_Index
(Old_Itype
)) then
13843 Visit_Field
(Union_Id
(List_Containing
13844 (First_Index
(Old_Itype
))),
13848 if Is_Packed
(Old_Itype
) then
13849 Visit_Field
(Union_Id
(Packed_Array_Impl_Type
(Old_Itype
)),
13859 procedure Visit_List
(L
: List_Id
) is
13862 if L
/= No_List
then
13865 while Present
(N
) loop
13876 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
13878 -- Start of processing for Visit_Node
13881 -- Handle case of an Itype, which must be copied
13883 if Has_Extension
(N
) and then Is_Itype
(N
) then
13885 -- Nothing to do if already in the list. This can happen with an
13886 -- Itype entity that appears more than once in the tree.
13887 -- Note that we do not want to visit descendents in this case.
13889 -- Test for already in list when hash table is used
13891 if NCT_Hash_Tables_Used
then
13892 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
13896 -- Test for already in list when hash table not used
13902 if Present
(Actual_Map
) then
13903 E
:= First_Elmt
(Actual_Map
);
13904 while Present
(E
) loop
13905 if Node
(E
) = N
then
13908 E
:= Next_Elmt
(Next_Elmt
(E
));
13918 -- Visit descendents
13920 Visit_Field
(Field1
(N
), N
);
13921 Visit_Field
(Field2
(N
), N
);
13922 Visit_Field
(Field3
(N
), N
);
13923 Visit_Field
(Field4
(N
), N
);
13924 Visit_Field
(Field5
(N
), N
);
13927 -- Start of processing for New_Copy_Tree
13932 -- See if we should use hash table
13934 if No
(Actual_Map
) then
13935 NCT_Hash_Tables_Used
:= False;
13942 NCT_Table_Entries
:= 0;
13944 Elmt
:= First_Elmt
(Actual_Map
);
13945 while Present
(Elmt
) loop
13946 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
13951 if NCT_Table_Entries
> NCT_Hash_Threshold
then
13952 Build_NCT_Hash_Tables
;
13954 NCT_Hash_Tables_Used
:= False;
13959 -- Hash table set up if required, now start phase one by visiting
13960 -- top node (we will recursively visit the descendents).
13962 Visit_Node
(Source
);
13964 -- Now the second phase of the copy can start. First we process
13965 -- all the mapped entities, copying their descendents.
13967 if Present
(Actual_Map
) then
13970 New_Itype
: Entity_Id
;
13972 Elmt
:= First_Elmt
(Actual_Map
);
13973 while Present
(Elmt
) loop
13975 New_Itype
:= Node
(Elmt
);
13976 Copy_Itype_With_Replacement
(New_Itype
);
13982 -- Now we can copy the actual tree
13984 return Copy_Node_With_Replacement
(Source
);
13987 -------------------------
13988 -- New_External_Entity --
13989 -------------------------
13991 function New_External_Entity
13992 (Kind
: Entity_Kind
;
13993 Scope_Id
: Entity_Id
;
13994 Sloc_Value
: Source_Ptr
;
13995 Related_Id
: Entity_Id
;
13996 Suffix
: Character;
13997 Suffix_Index
: Nat
:= 0;
13998 Prefix
: Character := ' ') return Entity_Id
14000 N
: constant Entity_Id
:=
14001 Make_Defining_Identifier
(Sloc_Value
,
14003 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
14006 Set_Ekind
(N
, Kind
);
14007 Set_Is_Internal
(N
, True);
14008 Append_Entity
(N
, Scope_Id
);
14009 Set_Public_Status
(N
);
14011 if Kind
in Type_Kind
then
14012 Init_Size_Align
(N
);
14016 end New_External_Entity
;
14018 -------------------------
14019 -- New_Internal_Entity --
14020 -------------------------
14022 function New_Internal_Entity
14023 (Kind
: Entity_Kind
;
14024 Scope_Id
: Entity_Id
;
14025 Sloc_Value
: Source_Ptr
;
14026 Id_Char
: Character) return Entity_Id
14028 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
14031 Set_Ekind
(N
, Kind
);
14032 Set_Is_Internal
(N
, True);
14033 Append_Entity
(N
, Scope_Id
);
14035 if Kind
in Type_Kind
then
14036 Init_Size_Align
(N
);
14040 end New_Internal_Entity
;
14046 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
14050 -- If we are pointing at a positional parameter, it is a member of a
14051 -- node list (the list of parameters), and the next parameter is the
14052 -- next node on the list, unless we hit a parameter association, then
14053 -- we shift to using the chain whose head is the First_Named_Actual in
14054 -- the parent, and then is threaded using the Next_Named_Actual of the
14055 -- Parameter_Association. All this fiddling is because the original node
14056 -- list is in the textual call order, and what we need is the
14057 -- declaration order.
14059 if Is_List_Member
(Actual_Id
) then
14060 N
:= Next
(Actual_Id
);
14062 if Nkind
(N
) = N_Parameter_Association
then
14063 return First_Named_Actual
(Parent
(Actual_Id
));
14069 return Next_Named_Actual
(Parent
(Actual_Id
));
14073 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
14075 Actual_Id
:= Next_Actual
(Actual_Id
);
14078 -----------------------
14079 -- Normalize_Actuals --
14080 -----------------------
14082 -- Chain actuals according to formals of subprogram. If there are no named
14083 -- associations, the chain is simply the list of Parameter Associations,
14084 -- since the order is the same as the declaration order. If there are named
14085 -- associations, then the First_Named_Actual field in the N_Function_Call
14086 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14087 -- node for the parameter that comes first in declaration order. The
14088 -- remaining named parameters are then chained in declaration order using
14089 -- Next_Named_Actual.
14091 -- This routine also verifies that the number of actuals is compatible with
14092 -- the number and default values of formals, but performs no type checking
14093 -- (type checking is done by the caller).
14095 -- If the matching succeeds, Success is set to True and the caller proceeds
14096 -- with type-checking. If the match is unsuccessful, then Success is set to
14097 -- False, and the caller attempts a different interpretation, if there is
14100 -- If the flag Report is on, the call is not overloaded, and a failure to
14101 -- match can be reported here, rather than in the caller.
14103 procedure Normalize_Actuals
14107 Success
: out Boolean)
14109 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
14110 Actual
: Node_Id
:= Empty
;
14111 Formal
: Entity_Id
;
14112 Last
: Node_Id
:= Empty
;
14113 First_Named
: Node_Id
:= Empty
;
14116 Formals_To_Match
: Integer := 0;
14117 Actuals_To_Match
: Integer := 0;
14119 procedure Chain
(A
: Node_Id
);
14120 -- Add named actual at the proper place in the list, using the
14121 -- Next_Named_Actual link.
14123 function Reporting
return Boolean;
14124 -- Determines if an error is to be reported. To report an error, we
14125 -- need Report to be True, and also we do not report errors caused
14126 -- by calls to init procs that occur within other init procs. Such
14127 -- errors must always be cascaded errors, since if all the types are
14128 -- declared correctly, the compiler will certainly build decent calls.
14134 procedure Chain
(A
: Node_Id
) is
14138 -- Call node points to first actual in list
14140 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
14143 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
14147 Set_Next_Named_Actual
(Last
, Empty
);
14154 function Reporting
return Boolean is
14159 elsif not Within_Init_Proc
then
14162 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
14170 -- Start of processing for Normalize_Actuals
14173 if Is_Access_Type
(S
) then
14175 -- The name in the call is a function call that returns an access
14176 -- to subprogram. The designated type has the list of formals.
14178 Formal
:= First_Formal
(Designated_Type
(S
));
14180 Formal
:= First_Formal
(S
);
14183 while Present
(Formal
) loop
14184 Formals_To_Match
:= Formals_To_Match
+ 1;
14185 Next_Formal
(Formal
);
14188 -- Find if there is a named association, and verify that no positional
14189 -- associations appear after named ones.
14191 if Present
(Actuals
) then
14192 Actual
:= First
(Actuals
);
14195 while Present
(Actual
)
14196 and then Nkind
(Actual
) /= N_Parameter_Association
14198 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14202 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
14204 -- Most common case: positional notation, no defaults
14209 elsif Actuals_To_Match
> Formals_To_Match
then
14211 -- Too many actuals: will not work
14214 if Is_Entity_Name
(Name
(N
)) then
14215 Error_Msg_N
("too many arguments in call to&", Name
(N
));
14217 Error_Msg_N
("too many arguments in call", N
);
14225 First_Named
:= Actual
;
14227 while Present
(Actual
) loop
14228 if Nkind
(Actual
) /= N_Parameter_Association
then
14230 ("positional parameters not allowed after named ones", Actual
);
14235 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14241 if Present
(Actuals
) then
14242 Actual
:= First
(Actuals
);
14245 Formal
:= First_Formal
(S
);
14246 while Present
(Formal
) loop
14248 -- Match the formals in order. If the corresponding actual is
14249 -- positional, nothing to do. Else scan the list of named actuals
14250 -- to find the one with the right name.
14252 if Present
(Actual
)
14253 and then Nkind
(Actual
) /= N_Parameter_Association
14256 Actuals_To_Match
:= Actuals_To_Match
- 1;
14257 Formals_To_Match
:= Formals_To_Match
- 1;
14260 -- For named parameters, search the list of actuals to find
14261 -- one that matches the next formal name.
14263 Actual
:= First_Named
;
14265 while Present
(Actual
) loop
14266 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
14269 Actuals_To_Match
:= Actuals_To_Match
- 1;
14270 Formals_To_Match
:= Formals_To_Match
- 1;
14278 if Ekind
(Formal
) /= E_In_Parameter
14279 or else No
(Default_Value
(Formal
))
14282 if (Comes_From_Source
(S
)
14283 or else Sloc
(S
) = Standard_Location
)
14284 and then Is_Overloadable
(S
)
14288 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
14290 N_Parameter_Association
)
14291 and then Ekind
(S
) /= E_Function
14293 Set_Etype
(N
, Etype
(S
));
14296 Error_Msg_Name_1
:= Chars
(S
);
14297 Error_Msg_Sloc
:= Sloc
(S
);
14299 ("missing argument for parameter & " &
14300 "in call to % declared #", N
, Formal
);
14303 elsif Is_Overloadable
(S
) then
14304 Error_Msg_Name_1
:= Chars
(S
);
14306 -- Point to type derivation that generated the
14309 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
14312 ("missing argument for parameter & " &
14313 "in call to % (inherited) #", N
, Formal
);
14317 ("missing argument for parameter &", N
, Formal
);
14325 Formals_To_Match
:= Formals_To_Match
- 1;
14330 Next_Formal
(Formal
);
14333 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
14340 -- Find some superfluous named actual that did not get
14341 -- attached to the list of associations.
14343 Actual
:= First
(Actuals
);
14344 while Present
(Actual
) loop
14345 if Nkind
(Actual
) = N_Parameter_Association
14346 and then Actual
/= Last
14347 and then No
(Next_Named_Actual
(Actual
))
14349 Error_Msg_N
("unmatched actual & in call",
14350 Selector_Name
(Actual
));
14361 end Normalize_Actuals
;
14363 --------------------------------
14364 -- Note_Possible_Modification --
14365 --------------------------------
14367 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
14368 Modification_Comes_From_Source
: constant Boolean :=
14369 Comes_From_Source
(Parent
(N
));
14375 -- Loop to find referenced entity, if there is one
14381 if Is_Entity_Name
(Exp
) then
14382 Ent
:= Entity
(Exp
);
14384 -- If the entity is missing, it is an undeclared identifier,
14385 -- and there is nothing to annotate.
14391 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
14393 P
: constant Node_Id
:= Prefix
(Exp
);
14396 -- In formal verification mode, keep track of all reads and
14397 -- writes through explicit dereferences.
14399 if GNATprove_Mode
then
14400 SPARK_Specific
.Generate_Dereference
(N
, 'm');
14403 if Nkind
(P
) = N_Selected_Component
14404 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
14406 -- Case of a reference to an entry formal
14408 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
14410 elsif Nkind
(P
) = N_Identifier
14411 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
14412 and then Present
(Expression
(Parent
(Entity
(P
))))
14413 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
14416 -- Case of a reference to a value on which side effects have
14419 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
14427 elsif Nkind_In
(Exp
, N_Type_Conversion
,
14428 N_Unchecked_Type_Conversion
)
14430 Exp
:= Expression
(Exp
);
14433 elsif Nkind_In
(Exp
, N_Slice
,
14434 N_Indexed_Component
,
14435 N_Selected_Component
)
14437 -- Special check, if the prefix is an access type, then return
14438 -- since we are modifying the thing pointed to, not the prefix.
14439 -- When we are expanding, most usually the prefix is replaced
14440 -- by an explicit dereference, and this test is not needed, but
14441 -- in some cases (notably -gnatc mode and generics) when we do
14442 -- not do full expansion, we need this special test.
14444 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
14447 -- Otherwise go to prefix and keep going
14450 Exp
:= Prefix
(Exp
);
14454 -- All other cases, not a modification
14460 -- Now look for entity being referenced
14462 if Present
(Ent
) then
14463 if Is_Object
(Ent
) then
14464 if Comes_From_Source
(Exp
)
14465 or else Modification_Comes_From_Source
14467 -- Give warning if pragma unmodified given and we are
14468 -- sure this is a modification.
14470 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
14472 ("??pragma Unmodified given for &!", N
, Ent
);
14475 Set_Never_Set_In_Source
(Ent
, False);
14478 Set_Is_True_Constant
(Ent
, False);
14479 Set_Current_Value
(Ent
, Empty
);
14480 Set_Is_Known_Null
(Ent
, False);
14482 if not Can_Never_Be_Null
(Ent
) then
14483 Set_Is_Known_Non_Null
(Ent
, False);
14486 -- Follow renaming chain
14488 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
14489 and then Present
(Renamed_Object
(Ent
))
14491 Exp
:= Renamed_Object
(Ent
);
14493 -- If the entity is the loop variable in an iteration over
14494 -- a container, retrieve container expression to indicate
14495 -- possible modificastion.
14497 if Present
(Related_Expression
(Ent
))
14498 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
14499 N_Iterator_Specification
14501 Exp
:= Original_Node
(Related_Expression
(Ent
));
14506 -- The expression may be the renaming of a subcomponent of an
14507 -- array or container. The assignment to the subcomponent is
14508 -- a modification of the container.
14510 elsif Comes_From_Source
(Original_Node
(Exp
))
14511 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
14512 N_Indexed_Component
)
14514 Exp
:= Prefix
(Original_Node
(Exp
));
14518 -- Generate a reference only if the assignment comes from
14519 -- source. This excludes, for example, calls to a dispatching
14520 -- assignment operation when the left-hand side is tagged. In
14521 -- GNATprove mode, we need those references also on generated
14522 -- code, as these are used to compute the local effects of
14525 if Modification_Comes_From_Source
or GNATprove_Mode
then
14526 Generate_Reference
(Ent
, Exp
, 'm');
14528 -- If the target of the assignment is the bound variable
14529 -- in an iterator, indicate that the corresponding array
14530 -- or container is also modified.
14532 if Ada_Version
>= Ada_2012
14533 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
14536 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
14539 -- TBD : in the full version of the construct, the
14540 -- domain of iteration can be given by an expression.
14542 if Is_Entity_Name
(Domain
) then
14543 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
14544 Set_Is_True_Constant
(Entity
(Domain
), False);
14545 Set_Never_Set_In_Source
(Entity
(Domain
), False);
14551 Check_Nested_Access
(Ent
);
14556 -- If we are sure this is a modification from source, and we know
14557 -- this modifies a constant, then give an appropriate warning.
14559 if Overlays_Constant
(Ent
)
14560 and then Modification_Comes_From_Source
14564 A
: constant Node_Id
:= Address_Clause
(Ent
);
14566 if Present
(A
) then
14568 Exp
: constant Node_Id
:= Expression
(A
);
14570 if Nkind
(Exp
) = N_Attribute_Reference
14571 and then Attribute_Name
(Exp
) = Name_Address
14572 and then Is_Entity_Name
(Prefix
(Exp
))
14574 Error_Msg_Sloc
:= Sloc
(A
);
14576 ("constant& may be modified via address "
14577 & "clause#??", N
, Entity
(Prefix
(Exp
)));
14590 end Note_Possible_Modification
;
14592 -------------------------
14593 -- Object_Access_Level --
14594 -------------------------
14596 -- Returns the static accessibility level of the view denoted by Obj. Note
14597 -- that the value returned is the result of a call to Scope_Depth. Only
14598 -- scope depths associated with dynamic scopes can actually be returned.
14599 -- Since only relative levels matter for accessibility checking, the fact
14600 -- that the distance between successive levels of accessibility is not
14601 -- always one is immaterial (invariant: if level(E2) is deeper than
14602 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
14604 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
14605 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
14606 -- Determine whether N is a construct of the form
14607 -- Some_Type (Operand._tag'Address)
14608 -- This construct appears in the context of dispatching calls.
14610 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
14611 -- An explicit dereference is created when removing side-effects from
14612 -- expressions for constraint checking purposes. In this case a local
14613 -- access type is created for it. The correct access level is that of
14614 -- the original source node. We detect this case by noting that the
14615 -- prefix of the dereference is created by an object declaration whose
14616 -- initial expression is a reference.
14618 -----------------------------
14619 -- Is_Interface_Conversion --
14620 -----------------------------
14622 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
14624 return Nkind
(N
) = N_Unchecked_Type_Conversion
14625 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
14626 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
14627 end Is_Interface_Conversion
;
14633 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
14634 Pref
: constant Node_Id
:= Prefix
(Obj
);
14636 if Is_Entity_Name
(Pref
)
14637 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
14638 and then Present
(Expression
(Parent
(Entity
(Pref
))))
14639 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
14641 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
14651 -- Start of processing for Object_Access_Level
14654 if Nkind
(Obj
) = N_Defining_Identifier
14655 or else Is_Entity_Name
(Obj
)
14657 if Nkind
(Obj
) = N_Defining_Identifier
then
14663 if Is_Prival
(E
) then
14664 E
:= Prival_Link
(E
);
14667 -- If E is a type then it denotes a current instance. For this case
14668 -- we add one to the normal accessibility level of the type to ensure
14669 -- that current instances are treated as always being deeper than
14670 -- than the level of any visible named access type (see 3.10.2(21)).
14672 if Is_Type
(E
) then
14673 return Type_Access_Level
(E
) + 1;
14675 elsif Present
(Renamed_Object
(E
)) then
14676 return Object_Access_Level
(Renamed_Object
(E
));
14678 -- Similarly, if E is a component of the current instance of a
14679 -- protected type, any instance of it is assumed to be at a deeper
14680 -- level than the type. For a protected object (whose type is an
14681 -- anonymous protected type) its components are at the same level
14682 -- as the type itself.
14684 elsif not Is_Overloadable
(E
)
14685 and then Ekind
(Scope
(E
)) = E_Protected_Type
14686 and then Comes_From_Source
(Scope
(E
))
14688 return Type_Access_Level
(Scope
(E
)) + 1;
14691 -- Aliased formals take their access level from the point of call.
14692 -- This is smaller than the level of the subprogram itself.
14694 if Is_Formal
(E
) and then Is_Aliased
(E
) then
14695 return Type_Access_Level
(Etype
(E
));
14698 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
14702 elsif Nkind
(Obj
) = N_Selected_Component
then
14703 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
14704 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14706 return Object_Access_Level
(Prefix
(Obj
));
14709 elsif Nkind
(Obj
) = N_Indexed_Component
then
14710 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
14711 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14713 return Object_Access_Level
(Prefix
(Obj
));
14716 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
14718 -- If the prefix is a selected access discriminant then we make a
14719 -- recursive call on the prefix, which will in turn check the level
14720 -- of the prefix object of the selected discriminant.
14722 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
14723 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
14725 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
14727 return Object_Access_Level
(Prefix
(Obj
));
14729 -- Detect an interface conversion in the context of a dispatching
14730 -- call. Use the original form of the conversion to find the access
14731 -- level of the operand.
14733 elsif Is_Interface
(Etype
(Obj
))
14734 and then Is_Interface_Conversion
(Prefix
(Obj
))
14735 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
14737 return Object_Access_Level
(Original_Node
(Obj
));
14739 elsif not Comes_From_Source
(Obj
) then
14741 Ref
: constant Node_Id
:= Reference_To
(Obj
);
14743 if Present
(Ref
) then
14744 return Object_Access_Level
(Ref
);
14746 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14751 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
14754 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
14755 return Object_Access_Level
(Expression
(Obj
));
14757 elsif Nkind
(Obj
) = N_Function_Call
then
14759 -- Function results are objects, so we get either the access level of
14760 -- the function or, in the case of an indirect call, the level of the
14761 -- access-to-subprogram type. (This code is used for Ada 95, but it
14762 -- looks wrong, because it seems that we should be checking the level
14763 -- of the call itself, even for Ada 95. However, using the Ada 2005
14764 -- version of the code causes regressions in several tests that are
14765 -- compiled with -gnat95. ???)
14767 if Ada_Version
< Ada_2005
then
14768 if Is_Entity_Name
(Name
(Obj
)) then
14769 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
14771 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
14774 -- For Ada 2005, the level of the result object of a function call is
14775 -- defined to be the level of the call's innermost enclosing master.
14776 -- We determine that by querying the depth of the innermost enclosing
14780 Return_Master_Scope_Depth_Of_Call
: declare
14782 function Innermost_Master_Scope_Depth
14783 (N
: Node_Id
) return Uint
;
14784 -- Returns the scope depth of the given node's innermost
14785 -- enclosing dynamic scope (effectively the accessibility
14786 -- level of the innermost enclosing master).
14788 ----------------------------------
14789 -- Innermost_Master_Scope_Depth --
14790 ----------------------------------
14792 function Innermost_Master_Scope_Depth
14793 (N
: Node_Id
) return Uint
14795 Node_Par
: Node_Id
:= Parent
(N
);
14798 -- Locate the nearest enclosing node (by traversing Parents)
14799 -- that Defining_Entity can be applied to, and return the
14800 -- depth of that entity's nearest enclosing dynamic scope.
14802 while Present
(Node_Par
) loop
14803 case Nkind
(Node_Par
) is
14804 when N_Component_Declaration |
14805 N_Entry_Declaration |
14806 N_Formal_Object_Declaration |
14807 N_Formal_Type_Declaration |
14808 N_Full_Type_Declaration |
14809 N_Incomplete_Type_Declaration |
14810 N_Loop_Parameter_Specification |
14811 N_Object_Declaration |
14812 N_Protected_Type_Declaration |
14813 N_Private_Extension_Declaration |
14814 N_Private_Type_Declaration |
14815 N_Subtype_Declaration |
14816 N_Function_Specification |
14817 N_Procedure_Specification |
14818 N_Task_Type_Declaration |
14820 N_Generic_Instantiation |
14822 N_Implicit_Label_Declaration |
14823 N_Package_Declaration |
14824 N_Single_Task_Declaration |
14825 N_Subprogram_Declaration |
14826 N_Generic_Declaration |
14827 N_Renaming_Declaration |
14828 N_Block_Statement |
14829 N_Formal_Subprogram_Declaration |
14830 N_Abstract_Subprogram_Declaration |
14832 N_Exception_Declaration |
14833 N_Formal_Package_Declaration |
14834 N_Number_Declaration |
14835 N_Package_Specification |
14836 N_Parameter_Specification |
14837 N_Single_Protected_Declaration |
14841 (Nearest_Dynamic_Scope
14842 (Defining_Entity
(Node_Par
)));
14848 Node_Par
:= Parent
(Node_Par
);
14851 pragma Assert
(False);
14853 -- Should never reach the following return
14855 return Scope_Depth
(Current_Scope
) + 1;
14856 end Innermost_Master_Scope_Depth
;
14858 -- Start of processing for Return_Master_Scope_Depth_Of_Call
14861 return Innermost_Master_Scope_Depth
(Obj
);
14862 end Return_Master_Scope_Depth_Of_Call
;
14865 -- For convenience we handle qualified expressions, even though they
14866 -- aren't technically object names.
14868 elsif Nkind
(Obj
) = N_Qualified_Expression
then
14869 return Object_Access_Level
(Expression
(Obj
));
14871 -- Ditto for aggregates. They have the level of the temporary that
14872 -- will hold their value.
14874 elsif Nkind
(Obj
) = N_Aggregate
then
14875 return Object_Access_Level
(Current_Scope
);
14877 -- Otherwise return the scope level of Standard. (If there are cases
14878 -- that fall through to this point they will be treated as having
14879 -- global accessibility for now. ???)
14882 return Scope_Depth
(Standard_Standard
);
14884 end Object_Access_Level
;
14886 --------------------------
14887 -- Original_Aspect_Name --
14888 --------------------------
14890 function Original_Aspect_Name
(N
: Node_Id
) return Name_Id
is
14895 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
14898 if Is_Rewrite_Substitution
(Pras
)
14899 and then Nkind
(Original_Node
(Pras
)) = N_Pragma
14901 Pras
:= Original_Node
(Pras
);
14904 -- Case where we came from aspect specication
14906 if Nkind
(Pras
) = N_Pragma
and then From_Aspect_Specification
(Pras
) then
14907 Pras
:= Corresponding_Aspect
(Pras
);
14910 -- Get name from aspect or pragma
14912 if Nkind
(Pras
) = N_Pragma
then
14913 Name
:= Pragma_Name
(Pras
);
14915 Name
:= Chars
(Identifier
(Pras
));
14918 -- Deal with 'Class
14920 if Class_Present
(Pras
) then
14923 -- Names that need converting to special _xxx form
14931 Name
:= Name_uPost
;
14933 when Name_Invariant
=>
14934 Name
:= Name_uInvariant
;
14936 when Name_Type_Invariant |
14937 Name_Type_Invariant_Class
=>
14938 Name
:= Name_uType_Invariant
;
14940 -- Nothing to do for other cases (e.g. a Check that derived
14941 -- from Pre_Class and has the flag set). Also we do nothing
14942 -- if the name is already in special _xxx form.
14950 end Original_Aspect_Name
;
14952 --------------------------------------
14953 -- Original_Corresponding_Operation --
14954 --------------------------------------
14956 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
14958 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
14961 -- If S is an inherited primitive S2 the original corresponding
14962 -- operation of S is the original corresponding operation of S2
14964 if Present
(Alias
(S
))
14965 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
14967 return Original_Corresponding_Operation
(Alias
(S
));
14969 -- If S overrides an inherited subprogram S2 the original corresponding
14970 -- operation of S is the original corresponding operation of S2
14972 elsif Present
(Overridden_Operation
(S
)) then
14973 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
14975 -- otherwise it is S itself
14980 end Original_Corresponding_Operation
;
14982 ----------------------------------
14983 -- Predicate_Tests_On_Arguments --
14984 ----------------------------------
14986 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
14988 -- Always test predicates on indirect call
14990 if Ekind
(Subp
) = E_Subprogram_Type
then
14993 -- Do not test predicates on call to generated default Finalize, since
14994 -- we are not interested in whether something we are finalizing (and
14995 -- typically destroying) satisfies its predicates.
14997 elsif Chars
(Subp
) = Name_Finalize
14998 and then not Comes_From_Source
(Subp
)
15002 -- Do not test predicates on any internally generated routines
15004 elsif Is_Internal_Name
(Chars
(Subp
)) then
15007 -- Do not test predicates on call to Init_Proc, since if needed the
15008 -- predicate test will occur at some other point.
15010 elsif Is_Init_Proc
(Subp
) then
15013 -- Do not test predicates on call to predicate function, since this
15014 -- would cause infinite recursion.
15016 elsif Ekind
(Subp
) = E_Function
15017 and then (Is_Predicate_Function
(Subp
)
15019 Is_Predicate_Function_M
(Subp
))
15023 -- For now, no other exceptions
15028 end Predicate_Tests_On_Arguments
;
15030 -----------------------
15031 -- Private_Component --
15032 -----------------------
15034 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
15035 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
15037 function Trace_Components
15039 Check
: Boolean) return Entity_Id
;
15040 -- Recursive function that does the work, and checks against circular
15041 -- definition for each subcomponent type.
15043 ----------------------
15044 -- Trace_Components --
15045 ----------------------
15047 function Trace_Components
15049 Check
: Boolean) return Entity_Id
15051 Btype
: constant Entity_Id
:= Base_Type
(T
);
15052 Component
: Entity_Id
;
15054 Candidate
: Entity_Id
:= Empty
;
15057 if Check
and then Btype
= Ancestor
then
15058 Error_Msg_N
("circular type definition", Type_Id
);
15062 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
15063 if Present
(Full_View
(Btype
))
15064 and then Is_Record_Type
(Full_View
(Btype
))
15065 and then not Is_Frozen
(Btype
)
15067 -- To indicate that the ancestor depends on a private type, the
15068 -- current Btype is sufficient. However, to check for circular
15069 -- definition we must recurse on the full view.
15071 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
15073 if Candidate
= Any_Type
then
15083 elsif Is_Array_Type
(Btype
) then
15084 return Trace_Components
(Component_Type
(Btype
), True);
15086 elsif Is_Record_Type
(Btype
) then
15087 Component
:= First_Entity
(Btype
);
15088 while Present
(Component
)
15089 and then Comes_From_Source
(Component
)
15091 -- Skip anonymous types generated by constrained components
15093 if not Is_Type
(Component
) then
15094 P
:= Trace_Components
(Etype
(Component
), True);
15096 if Present
(P
) then
15097 if P
= Any_Type
then
15105 Next_Entity
(Component
);
15113 end Trace_Components
;
15115 -- Start of processing for Private_Component
15118 return Trace_Components
(Type_Id
, False);
15119 end Private_Component
;
15121 ---------------------------
15122 -- Primitive_Names_Match --
15123 ---------------------------
15125 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
15127 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
15128 -- Given an internal name, returns the corresponding non-internal name
15130 ------------------------
15131 -- Non_Internal_Name --
15132 ------------------------
15134 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
15136 Get_Name_String
(Chars
(E
));
15137 Name_Len
:= Name_Len
- 1;
15139 end Non_Internal_Name
;
15141 -- Start of processing for Primitive_Names_Match
15144 pragma Assert
(Present
(E1
) and then Present
(E2
));
15146 return Chars
(E1
) = Chars
(E2
)
15148 (not Is_Internal_Name
(Chars
(E1
))
15149 and then Is_Internal_Name
(Chars
(E2
))
15150 and then Non_Internal_Name
(E2
) = Chars
(E1
))
15152 (not Is_Internal_Name
(Chars
(E2
))
15153 and then Is_Internal_Name
(Chars
(E1
))
15154 and then Non_Internal_Name
(E1
) = Chars
(E2
))
15156 (Is_Predefined_Dispatching_Operation
(E1
)
15157 and then Is_Predefined_Dispatching_Operation
(E2
)
15158 and then Same_TSS
(E1
, E2
))
15160 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
15161 end Primitive_Names_Match
;
15163 -----------------------
15164 -- Process_End_Label --
15165 -----------------------
15167 procedure Process_End_Label
15176 Label_Ref
: Boolean;
15177 -- Set True if reference to end label itself is required
15180 -- Gets set to the operator symbol or identifier that references the
15181 -- entity Ent. For the child unit case, this is the identifier from the
15182 -- designator. For other cases, this is simply Endl.
15184 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
15185 -- N is an identifier node that appears as a parent unit reference in
15186 -- the case where Ent is a child unit. This procedure generates an
15187 -- appropriate cross-reference entry. E is the corresponding entity.
15189 -------------------------
15190 -- Generate_Parent_Ref --
15191 -------------------------
15193 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
15195 -- If names do not match, something weird, skip reference
15197 if Chars
(E
) = Chars
(N
) then
15199 -- Generate the reference. We do NOT consider this as a reference
15200 -- for unreferenced symbol purposes.
15202 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
15204 if Style_Check
then
15205 Style
.Check_Identifier
(N
, E
);
15208 end Generate_Parent_Ref
;
15210 -- Start of processing for Process_End_Label
15213 -- If no node, ignore. This happens in some error situations, and
15214 -- also for some internally generated structures where no end label
15215 -- references are required in any case.
15221 -- Nothing to do if no End_Label, happens for internally generated
15222 -- constructs where we don't want an end label reference anyway. Also
15223 -- nothing to do if Endl is a string literal, which means there was
15224 -- some prior error (bad operator symbol)
15226 Endl
:= End_Label
(N
);
15228 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
15232 -- Reference node is not in extended main source unit
15234 if not In_Extended_Main_Source_Unit
(N
) then
15236 -- Generally we do not collect references except for the extended
15237 -- main source unit. The one exception is the 'e' entry for a
15238 -- package spec, where it is useful for a client to have the
15239 -- ending information to define scopes.
15245 Label_Ref
:= False;
15247 -- For this case, we can ignore any parent references, but we
15248 -- need the package name itself for the 'e' entry.
15250 if Nkind
(Endl
) = N_Designator
then
15251 Endl
:= Identifier
(Endl
);
15255 -- Reference is in extended main source unit
15260 -- For designator, generate references for the parent entries
15262 if Nkind
(Endl
) = N_Designator
then
15264 -- Generate references for the prefix if the END line comes from
15265 -- source (otherwise we do not need these references) We climb the
15266 -- scope stack to find the expected entities.
15268 if Comes_From_Source
(Endl
) then
15269 Nam
:= Name
(Endl
);
15270 Scop
:= Current_Scope
;
15271 while Nkind
(Nam
) = N_Selected_Component
loop
15272 Scop
:= Scope
(Scop
);
15273 exit when No
(Scop
);
15274 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
15275 Nam
:= Prefix
(Nam
);
15278 if Present
(Scop
) then
15279 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
15283 Endl
:= Identifier
(Endl
);
15287 -- If the end label is not for the given entity, then either we have
15288 -- some previous error, or this is a generic instantiation for which
15289 -- we do not need to make a cross-reference in this case anyway. In
15290 -- either case we simply ignore the call.
15292 if Chars
(Ent
) /= Chars
(Endl
) then
15296 -- If label was really there, then generate a normal reference and then
15297 -- adjust the location in the end label to point past the name (which
15298 -- should almost always be the semicolon).
15300 Loc
:= Sloc
(Endl
);
15302 if Comes_From_Source
(Endl
) then
15304 -- If a label reference is required, then do the style check and
15305 -- generate an l-type cross-reference entry for the label
15308 if Style_Check
then
15309 Style
.Check_Identifier
(Endl
, Ent
);
15312 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
15315 -- Set the location to point past the label (normally this will
15316 -- mean the semicolon immediately following the label). This is
15317 -- done for the sake of the 'e' or 't' entry generated below.
15319 Get_Decoded_Name_String
(Chars
(Endl
));
15320 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
15323 -- In SPARK mode, no missing label is allowed for packages and
15324 -- subprogram bodies. Detect those cases by testing whether
15325 -- Process_End_Label was called for a body (Typ = 't') or a package.
15327 if Restriction_Check_Required
(SPARK_05
)
15328 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
15330 Error_Msg_Node_1
:= Endl
;
15331 Check_SPARK_05_Restriction
15332 ("`END &` required", Endl
, Force
=> True);
15336 -- Now generate the e/t reference
15338 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
15340 -- Restore Sloc, in case modified above, since we have an identifier
15341 -- and the normal Sloc should be left set in the tree.
15343 Set_Sloc
(Endl
, Loc
);
15344 end Process_End_Label
;
15350 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
15351 Seen
: Boolean := False;
15353 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
15354 -- Determine whether node N denotes a reference to Id. If this is the
15355 -- case, set global flag Seen to True and stop the traversal.
15361 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
15363 if Is_Entity_Name
(N
)
15364 and then Present
(Entity
(N
))
15365 and then Entity
(N
) = Id
15374 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
15376 -- Start of processing for Referenced
15379 Inspect_Expression
(Expr
);
15383 ------------------------------------
15384 -- References_Generic_Formal_Type --
15385 ------------------------------------
15387 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
15389 function Process
(N
: Node_Id
) return Traverse_Result
;
15390 -- Process one node in search for generic formal type
15396 function Process
(N
: Node_Id
) return Traverse_Result
is
15398 if Nkind
(N
) in N_Has_Entity
then
15400 E
: constant Entity_Id
:= Entity
(N
);
15402 if Present
(E
) then
15403 if Is_Generic_Type
(E
) then
15405 elsif Present
(Etype
(E
))
15406 and then Is_Generic_Type
(Etype
(E
))
15417 function Traverse
is new Traverse_Func
(Process
);
15418 -- Traverse tree to look for generic type
15421 if Inside_A_Generic
then
15422 return Traverse
(N
) = Abandon
;
15426 end References_Generic_Formal_Type
;
15428 --------------------
15429 -- Remove_Homonym --
15430 --------------------
15432 procedure Remove_Homonym
(E
: Entity_Id
) is
15433 Prev
: Entity_Id
:= Empty
;
15437 if E
= Current_Entity
(E
) then
15438 if Present
(Homonym
(E
)) then
15439 Set_Current_Entity
(Homonym
(E
));
15441 Set_Name_Entity_Id
(Chars
(E
), Empty
);
15445 H
:= Current_Entity
(E
);
15446 while Present
(H
) and then H
/= E
loop
15451 -- If E is not on the homonym chain, nothing to do
15453 if Present
(H
) then
15454 Set_Homonym
(Prev
, Homonym
(E
));
15457 end Remove_Homonym
;
15459 ---------------------
15460 -- Rep_To_Pos_Flag --
15461 ---------------------
15463 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
15465 return New_Occurrence_Of
15466 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
15467 end Rep_To_Pos_Flag
;
15469 --------------------
15470 -- Require_Entity --
15471 --------------------
15473 procedure Require_Entity
(N
: Node_Id
) is
15475 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
15476 if Total_Errors_Detected
/= 0 then
15477 Set_Entity
(N
, Any_Id
);
15479 raise Program_Error
;
15482 end Require_Entity
;
15484 -------------------------------
15485 -- Requires_State_Refinement --
15486 -------------------------------
15488 function Requires_State_Refinement
15489 (Spec_Id
: Entity_Id
;
15490 Body_Id
: Entity_Id
) return Boolean
15492 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
15493 -- Given pragma SPARK_Mode, determine whether the mode is Off
15499 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
15503 -- The default SPARK mode is On
15509 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
15511 -- Then the pragma lacks an argument, the default mode is On
15516 return Chars
(Mode
) = Name_Off
;
15520 -- Start of processing for Requires_State_Refinement
15523 -- A package that does not define at least one abstract state cannot
15524 -- possibly require refinement.
15526 if No
(Abstract_States
(Spec_Id
)) then
15529 -- The package instroduces a single null state which does not merit
15532 elsif Has_Null_Abstract_State
(Spec_Id
) then
15535 -- Check whether the package body is subject to pragma SPARK_Mode. If
15536 -- it is and the mode is Off, the package body is considered to be in
15537 -- regular Ada and does not require refinement.
15539 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
15542 -- The body's SPARK_Mode may be inherited from a similar pragma that
15543 -- appears in the private declarations of the spec. The pragma we are
15544 -- interested appears as the second entry in SPARK_Pragma.
15546 elsif Present
(SPARK_Pragma
(Spec_Id
))
15547 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
15551 -- The spec defines at least one abstract state and the body has no way
15552 -- of circumventing the refinement.
15557 end Requires_State_Refinement
;
15559 ------------------------------
15560 -- Requires_Transient_Scope --
15561 ------------------------------
15563 -- A transient scope is required when variable-sized temporaries are
15564 -- allocated in the primary or secondary stack, or when finalization
15565 -- actions must be generated before the next instruction.
15567 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
15568 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
15570 -- Start of processing for Requires_Transient_Scope
15573 -- This is a private type which is not completed yet. This can only
15574 -- happen in a default expression (of a formal parameter or of a
15575 -- record component). Do not expand transient scope in this case
15580 -- Do not expand transient scope for non-existent procedure return
15582 elsif Typ
= Standard_Void_Type
then
15585 -- Elementary types do not require a transient scope
15587 elsif Is_Elementary_Type
(Typ
) then
15590 -- Generally, indefinite subtypes require a transient scope, since the
15591 -- back end cannot generate temporaries, since this is not a valid type
15592 -- for declaring an object. It might be possible to relax this in the
15593 -- future, e.g. by declaring the maximum possible space for the type.
15595 elsif Is_Indefinite_Subtype
(Typ
) then
15598 -- Functions returning tagged types may dispatch on result so their
15599 -- returned value is allocated on the secondary stack. Controlled
15600 -- type temporaries need finalization.
15602 elsif Is_Tagged_Type
(Typ
)
15603 or else Has_Controlled_Component
(Typ
)
15605 return not Is_Value_Type
(Typ
);
15609 elsif Is_Record_Type
(Typ
) then
15613 Comp
:= First_Entity
(Typ
);
15614 while Present
(Comp
) loop
15615 if Ekind
(Comp
) = E_Component
15616 and then Requires_Transient_Scope
(Etype
(Comp
))
15620 Next_Entity
(Comp
);
15627 -- String literal types never require transient scope
15629 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
15632 -- Array type. Note that we already know that this is a constrained
15633 -- array, since unconstrained arrays will fail the indefinite test.
15635 elsif Is_Array_Type
(Typ
) then
15637 -- If component type requires a transient scope, the array does too
15639 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
15642 -- Otherwise, we only need a transient scope if the size depends on
15643 -- the value of one or more discriminants.
15646 return Size_Depends_On_Discriminant
(Typ
);
15649 -- All other cases do not require a transient scope
15654 end Requires_Transient_Scope
;
15656 --------------------------
15657 -- Reset_Analyzed_Flags --
15658 --------------------------
15660 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
15662 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
15663 -- Function used to reset Analyzed flags in tree. Note that we do
15664 -- not reset Analyzed flags in entities, since there is no need to
15665 -- reanalyze entities, and indeed, it is wrong to do so, since it
15666 -- can result in generating auxiliary stuff more than once.
15668 --------------------
15669 -- Clear_Analyzed --
15670 --------------------
15672 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
15674 if not Has_Extension
(N
) then
15675 Set_Analyzed
(N
, False);
15679 end Clear_Analyzed
;
15681 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
15683 -- Start of processing for Reset_Analyzed_Flags
15686 Reset_Analyzed
(N
);
15687 end Reset_Analyzed_Flags
;
15689 ------------------------
15690 -- Restore_SPARK_Mode --
15691 ------------------------
15693 procedure Restore_SPARK_Mode
(Mode
: SPARK_Mode_Type
) is
15695 SPARK_Mode
:= Mode
;
15696 end Restore_SPARK_Mode
;
15698 --------------------------------
15699 -- Returns_Unconstrained_Type --
15700 --------------------------------
15702 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
15704 return Ekind
(Subp
) = E_Function
15705 and then not Is_Scalar_Type
(Etype
(Subp
))
15706 and then not Is_Access_Type
(Etype
(Subp
))
15707 and then not Is_Constrained
(Etype
(Subp
));
15708 end Returns_Unconstrained_Type
;
15710 ----------------------------
15711 -- Root_Type_Of_Full_View --
15712 ----------------------------
15714 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
15715 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
15718 -- The root type of the full view may itself be a private type. Keep
15719 -- looking for the ultimate derivation parent.
15721 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
15722 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
15726 end Root_Type_Of_Full_View
;
15728 ---------------------------
15729 -- Safe_To_Capture_Value --
15730 ---------------------------
15732 function Safe_To_Capture_Value
15735 Cond
: Boolean := False) return Boolean
15738 -- The only entities for which we track constant values are variables
15739 -- which are not renamings, constants, out parameters, and in out
15740 -- parameters, so check if we have this case.
15742 -- Note: it may seem odd to track constant values for constants, but in
15743 -- fact this routine is used for other purposes than simply capturing
15744 -- the value. In particular, the setting of Known[_Non]_Null.
15746 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
15748 Ekind
(Ent
) = E_Constant
15750 Ekind
(Ent
) = E_Out_Parameter
15752 Ekind
(Ent
) = E_In_Out_Parameter
15756 -- For conditionals, we also allow loop parameters and all formals,
15757 -- including in parameters.
15759 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
15762 -- For all other cases, not just unsafe, but impossible to capture
15763 -- Current_Value, since the above are the only entities which have
15764 -- Current_Value fields.
15770 -- Skip if volatile or aliased, since funny things might be going on in
15771 -- these cases which we cannot necessarily track. Also skip any variable
15772 -- for which an address clause is given, or whose address is taken. Also
15773 -- never capture value of library level variables (an attempt to do so
15774 -- can occur in the case of package elaboration code).
15776 if Treat_As_Volatile
(Ent
)
15777 or else Is_Aliased
(Ent
)
15778 or else Present
(Address_Clause
(Ent
))
15779 or else Address_Taken
(Ent
)
15780 or else (Is_Library_Level_Entity
(Ent
)
15781 and then Ekind
(Ent
) = E_Variable
)
15786 -- OK, all above conditions are met. We also require that the scope of
15787 -- the reference be the same as the scope of the entity, not counting
15788 -- packages and blocks and loops.
15791 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
15792 R_Scope
: Entity_Id
;
15795 R_Scope
:= Current_Scope
;
15796 while R_Scope
/= Standard_Standard
loop
15797 exit when R_Scope
= E_Scope
;
15799 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
15802 R_Scope
:= Scope
(R_Scope
);
15807 -- We also require that the reference does not appear in a context
15808 -- where it is not sure to be executed (i.e. a conditional context
15809 -- or an exception handler). We skip this if Cond is True, since the
15810 -- capturing of values from conditional tests handles this ok.
15823 -- Seems dubious that case expressions are not handled here ???
15826 while Present
(P
) loop
15827 if Nkind
(P
) = N_If_Statement
15828 or else Nkind
(P
) = N_Case_Statement
15829 or else (Nkind
(P
) in N_Short_Circuit
15830 and then Desc
= Right_Opnd
(P
))
15831 or else (Nkind
(P
) = N_If_Expression
15832 and then Desc
/= First
(Expressions
(P
)))
15833 or else Nkind
(P
) = N_Exception_Handler
15834 or else Nkind
(P
) = N_Selective_Accept
15835 or else Nkind
(P
) = N_Conditional_Entry_Call
15836 or else Nkind
(P
) = N_Timed_Entry_Call
15837 or else Nkind
(P
) = N_Asynchronous_Select
15845 -- A special Ada 2012 case: the original node may be part
15846 -- of the else_actions of a conditional expression, in which
15847 -- case it might not have been expanded yet, and appears in
15848 -- a non-syntactic list of actions. In that case it is clearly
15849 -- not safe to save a value.
15852 and then Is_List_Member
(Desc
)
15853 and then No
(Parent
(List_Containing
(Desc
)))
15861 -- OK, looks safe to set value
15864 end Safe_To_Capture_Value
;
15870 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
15871 K1
: constant Node_Kind
:= Nkind
(N1
);
15872 K2
: constant Node_Kind
:= Nkind
(N2
);
15875 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
15876 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
15878 return Chars
(N1
) = Chars
(N2
);
15880 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
15881 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
15883 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
15884 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
15895 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
15896 N1
: constant Node_Id
:= Original_Node
(Node1
);
15897 N2
: constant Node_Id
:= Original_Node
(Node2
);
15898 -- We do the tests on original nodes, since we are most interested
15899 -- in the original source, not any expansion that got in the way.
15901 K1
: constant Node_Kind
:= Nkind
(N1
);
15902 K2
: constant Node_Kind
:= Nkind
(N2
);
15905 -- First case, both are entities with same entity
15907 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
15909 EN1
: constant Entity_Id
:= Entity
(N1
);
15910 EN2
: constant Entity_Id
:= Entity
(N2
);
15912 if Present
(EN1
) and then Present
(EN2
)
15913 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
15914 or else Is_Formal
(EN1
))
15922 -- Second case, selected component with same selector, same record
15924 if K1
= N_Selected_Component
15925 and then K2
= N_Selected_Component
15926 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
15928 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
15930 -- Third case, indexed component with same subscripts, same array
15932 elsif K1
= N_Indexed_Component
15933 and then K2
= N_Indexed_Component
15934 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
15939 E1
:= First
(Expressions
(N1
));
15940 E2
:= First
(Expressions
(N2
));
15941 while Present
(E1
) loop
15942 if not Same_Value
(E1
, E2
) then
15953 -- Fourth case, slice of same array with same bounds
15956 and then K2
= N_Slice
15957 and then Nkind
(Discrete_Range
(N1
)) = N_Range
15958 and then Nkind
(Discrete_Range
(N2
)) = N_Range
15959 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
15960 Low_Bound
(Discrete_Range
(N2
)))
15961 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
15962 High_Bound
(Discrete_Range
(N2
)))
15964 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
15966 -- All other cases, not clearly the same object
15977 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
15982 elsif not Is_Constrained
(T1
)
15983 and then not Is_Constrained
(T2
)
15984 and then Base_Type
(T1
) = Base_Type
(T2
)
15988 -- For now don't bother with case of identical constraints, to be
15989 -- fiddled with later on perhaps (this is only used for optimization
15990 -- purposes, so it is not critical to do a best possible job)
16001 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
16003 if Compile_Time_Known_Value
(Node1
)
16004 and then Compile_Time_Known_Value
(Node2
)
16005 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
16008 elsif Same_Object
(Node1
, Node2
) then
16015 -----------------------------
16016 -- Save_SPARK_Mode_And_Set --
16017 -----------------------------
16019 procedure Save_SPARK_Mode_And_Set
16020 (Context
: Entity_Id
;
16021 Mode
: out SPARK_Mode_Type
)
16024 -- Save the current mode in effect
16026 Mode
:= SPARK_Mode
;
16028 -- Do not consider illegal or partially decorated constructs
16030 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
16033 elsif Present
(SPARK_Pragma
(Context
)) then
16034 SPARK_Mode
:= Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Context
));
16036 end Save_SPARK_Mode_And_Set
;
16038 -------------------------
16039 -- Scalar_Part_Present --
16040 -------------------------
16042 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
16046 if Is_Scalar_Type
(T
) then
16049 elsif Is_Array_Type
(T
) then
16050 return Scalar_Part_Present
(Component_Type
(T
));
16052 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
16053 C
:= First_Component_Or_Discriminant
(T
);
16054 while Present
(C
) loop
16055 if Scalar_Part_Present
(Etype
(C
)) then
16058 Next_Component_Or_Discriminant
(C
);
16064 end Scalar_Part_Present
;
16066 ------------------------
16067 -- Scope_Is_Transient --
16068 ------------------------
16070 function Scope_Is_Transient
return Boolean is
16072 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
16073 end Scope_Is_Transient
;
16079 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16084 while Scop
/= Standard_Standard
loop
16085 Scop
:= Scope
(Scop
);
16087 if Scop
= Scope2
then
16095 --------------------------
16096 -- Scope_Within_Or_Same --
16097 --------------------------
16099 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16104 while Scop
/= Standard_Standard
loop
16105 if Scop
= Scope2
then
16108 Scop
:= Scope
(Scop
);
16113 end Scope_Within_Or_Same
;
16115 --------------------
16116 -- Set_Convention --
16117 --------------------
16119 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
16121 Basic_Set_Convention
(E
, Val
);
16124 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
16125 and then Has_Foreign_Convention
(E
)
16127 Set_Can_Use_Internal_Rep
(E
, False);
16130 -- If E is an object or component, and the type of E is an anonymous
16131 -- access type with no convention set, then also set the convention of
16132 -- the anonymous access type. We do not do this for anonymous protected
16133 -- types, since protected types always have the default convention.
16135 if Present
(Etype
(E
))
16136 and then (Is_Object
(E
)
16137 or else Ekind
(E
) = E_Component
16139 -- Allow E_Void (happens for pragma Convention appearing
16140 -- in the middle of a record applying to a component)
16142 or else Ekind
(E
) = E_Void
)
16145 Typ
: constant Entity_Id
:= Etype
(E
);
16148 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
16149 E_Anonymous_Access_Subprogram_Type
)
16150 and then not Has_Convention_Pragma
(Typ
)
16152 Basic_Set_Convention
(Typ
, Val
);
16153 Set_Has_Convention_Pragma
(Typ
);
16155 -- And for the access subprogram type, deal similarly with the
16156 -- designated E_Subprogram_Type if it is also internal (which
16159 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
16161 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
16163 if Ekind
(Dtype
) = E_Subprogram_Type
16164 and then Is_Itype
(Dtype
)
16165 and then not Has_Convention_Pragma
(Dtype
)
16167 Basic_Set_Convention
(Dtype
, Val
);
16168 Set_Has_Convention_Pragma
(Dtype
);
16175 end Set_Convention
;
16177 ------------------------
16178 -- Set_Current_Entity --
16179 ------------------------
16181 -- The given entity is to be set as the currently visible definition of its
16182 -- associated name (i.e. the Node_Id associated with its name). All we have
16183 -- to do is to get the name from the identifier, and then set the
16184 -- associated Node_Id to point to the given entity.
16186 procedure Set_Current_Entity
(E
: Entity_Id
) is
16188 Set_Name_Entity_Id
(Chars
(E
), E
);
16189 end Set_Current_Entity
;
16191 ---------------------------
16192 -- Set_Debug_Info_Needed --
16193 ---------------------------
16195 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
16197 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
16198 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
16199 -- Used to set debug info in a related node if not set already
16201 --------------------------------------
16202 -- Set_Debug_Info_Needed_If_Not_Set --
16203 --------------------------------------
16205 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
16207 if Present
(E
) and then not Needs_Debug_Info
(E
) then
16208 Set_Debug_Info_Needed
(E
);
16210 -- For a private type, indicate that the full view also needs
16211 -- debug information.
16214 and then Is_Private_Type
(E
)
16215 and then Present
(Full_View
(E
))
16217 Set_Debug_Info_Needed
(Full_View
(E
));
16220 end Set_Debug_Info_Needed_If_Not_Set
;
16222 -- Start of processing for Set_Debug_Info_Needed
16225 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16226 -- indicates that Debug_Info_Needed is never required for the entity.
16229 or else Debug_Info_Off
(T
)
16234 -- Set flag in entity itself. Note that we will go through the following
16235 -- circuitry even if the flag is already set on T. That's intentional,
16236 -- it makes sure that the flag will be set in subsidiary entities.
16238 Set_Needs_Debug_Info
(T
);
16240 -- Set flag on subsidiary entities if not set already
16242 if Is_Object
(T
) then
16243 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16245 elsif Is_Type
(T
) then
16246 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16248 if Is_Record_Type
(T
) then
16250 Ent
: Entity_Id
:= First_Entity
(T
);
16252 while Present
(Ent
) loop
16253 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
16258 -- For a class wide subtype, we also need debug information
16259 -- for the equivalent type.
16261 if Ekind
(T
) = E_Class_Wide_Subtype
then
16262 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
16265 elsif Is_Array_Type
(T
) then
16266 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
16269 Indx
: Node_Id
:= First_Index
(T
);
16271 while Present
(Indx
) loop
16272 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
16273 Indx
:= Next_Index
(Indx
);
16277 -- For a packed array type, we also need debug information for
16278 -- the type used to represent the packed array. Conversely, we
16279 -- also need it for the former if we need it for the latter.
16281 if Is_Packed
(T
) then
16282 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
16285 if Is_Packed_Array_Impl_Type
(T
) then
16286 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
16289 elsif Is_Access_Type
(T
) then
16290 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
16292 elsif Is_Private_Type
(T
) then
16293 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
16295 elsif Is_Protected_Type
(T
) then
16296 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
16298 elsif Is_Scalar_Type
(T
) then
16300 -- If the subrange bounds are materialized by dedicated constant
16301 -- objects, also include them in the debug info to make sure the
16302 -- debugger can properly use them.
16304 if Present
(Scalar_Range
(T
))
16305 and then Nkind
(Scalar_Range
(T
)) = N_Range
16308 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
16309 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
16312 if Is_Entity_Name
(Low_Bnd
) then
16313 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
16316 if Is_Entity_Name
(High_Bnd
) then
16317 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
16323 end Set_Debug_Info_Needed
;
16325 ----------------------------
16326 -- Set_Entity_With_Checks --
16327 ----------------------------
16329 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
16330 Val_Actual
: Entity_Id
;
16332 Post_Node
: Node_Id
;
16335 -- Unconditionally set the entity
16337 Set_Entity
(N
, Val
);
16339 -- The node to post on is the selector in the case of an expanded name,
16340 -- and otherwise the node itself.
16342 if Nkind
(N
) = N_Expanded_Name
then
16343 Post_Node
:= Selector_Name
(N
);
16348 -- Check for violation of No_Fixed_IO
16350 if Restriction_Check_Required
(No_Fixed_IO
)
16352 ((RTU_Loaded
(Ada_Text_IO
)
16353 and then (Is_RTE
(Val
, RE_Decimal_IO
)
16355 Is_RTE
(Val
, RE_Fixed_IO
)))
16358 (RTU_Loaded
(Ada_Wide_Text_IO
)
16359 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
16361 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
16364 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
16365 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
16367 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
16369 -- A special extra check, don't complain about a reference from within
16370 -- the Ada.Interrupts package itself!
16372 and then not In_Same_Extended_Unit
(N
, Val
)
16374 Check_Restriction
(No_Fixed_IO
, Post_Node
);
16377 -- Remaining checks are only done on source nodes. Note that we test
16378 -- for violation of No_Fixed_IO even on non-source nodes, because the
16379 -- cases for checking violations of this restriction are instantiations
16380 -- where the reference in the instance has Comes_From_Source False.
16382 if not Comes_From_Source
(N
) then
16386 -- Check for violation of No_Abort_Statements, which is triggered by
16387 -- call to Ada.Task_Identification.Abort_Task.
16389 if Restriction_Check_Required
(No_Abort_Statements
)
16390 and then (Is_RTE
(Val
, RE_Abort_Task
))
16392 -- A special extra check, don't complain about a reference from within
16393 -- the Ada.Task_Identification package itself!
16395 and then not In_Same_Extended_Unit
(N
, Val
)
16397 Check_Restriction
(No_Abort_Statements
, Post_Node
);
16400 if Val
= Standard_Long_Long_Integer
then
16401 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
16404 -- Check for violation of No_Dynamic_Attachment
16406 if Restriction_Check_Required
(No_Dynamic_Attachment
)
16407 and then RTU_Loaded
(Ada_Interrupts
)
16408 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
16409 Is_RTE
(Val
, RE_Is_Attached
) or else
16410 Is_RTE
(Val
, RE_Current_Handler
) or else
16411 Is_RTE
(Val
, RE_Attach_Handler
) or else
16412 Is_RTE
(Val
, RE_Exchange_Handler
) or else
16413 Is_RTE
(Val
, RE_Detach_Handler
) or else
16414 Is_RTE
(Val
, RE_Reference
))
16416 -- A special extra check, don't complain about a reference from within
16417 -- the Ada.Interrupts package itself!
16419 and then not In_Same_Extended_Unit
(N
, Val
)
16421 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
16424 -- Check for No_Implementation_Identifiers
16426 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
16428 -- We have an implementation defined entity if it is marked as
16429 -- implementation defined, or is defined in a package marked as
16430 -- implementation defined. However, library packages themselves
16431 -- are excluded (we don't want to flag Interfaces itself, just
16432 -- the entities within it).
16434 if (Is_Implementation_Defined
(Val
)
16436 Is_Implementation_Defined
(Scope
(Val
)))
16437 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
16438 and then Is_Library_Level_Entity
(Val
))
16440 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
16444 -- Do the style check
16447 and then not Suppress_Style_Checks
(Val
)
16448 and then not In_Instance
16450 if Nkind
(N
) = N_Identifier
then
16452 elsif Nkind
(N
) = N_Expanded_Name
then
16453 Nod
:= Selector_Name
(N
);
16458 -- A special situation arises for derived operations, where we want
16459 -- to do the check against the parent (since the Sloc of the derived
16460 -- operation points to the derived type declaration itself).
16463 while not Comes_From_Source
(Val_Actual
)
16464 and then Nkind
(Val_Actual
) in N_Entity
16465 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
16466 or else Is_Subprogram
(Val_Actual
)
16467 or else Is_Generic_Subprogram
(Val_Actual
))
16468 and then Present
(Alias
(Val_Actual
))
16470 Val_Actual
:= Alias
(Val_Actual
);
16473 -- Renaming declarations for generic actuals do not come from source,
16474 -- and have a different name from that of the entity they rename, so
16475 -- there is no style check to perform here.
16477 if Chars
(Nod
) = Chars
(Val_Actual
) then
16478 Style
.Check_Identifier
(Nod
, Val_Actual
);
16482 Set_Entity
(N
, Val
);
16483 end Set_Entity_With_Checks
;
16485 ------------------------
16486 -- Set_Name_Entity_Id --
16487 ------------------------
16489 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
16491 Set_Name_Table_Info
(Id
, Int
(Val
));
16492 end Set_Name_Entity_Id
;
16494 ---------------------
16495 -- Set_Next_Actual --
16496 ---------------------
16498 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
16500 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
16501 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
16503 end Set_Next_Actual
;
16505 ----------------------------------
16506 -- Set_Optimize_Alignment_Flags --
16507 ----------------------------------
16509 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
16511 if Optimize_Alignment
= 'S' then
16512 Set_Optimize_Alignment_Space
(E
);
16513 elsif Optimize_Alignment
= 'T' then
16514 Set_Optimize_Alignment_Time
(E
);
16516 end Set_Optimize_Alignment_Flags
;
16518 -----------------------
16519 -- Set_Public_Status --
16520 -----------------------
16522 procedure Set_Public_Status
(Id
: Entity_Id
) is
16523 S
: constant Entity_Id
:= Current_Scope
;
16525 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
16526 -- Determines if E is defined within handled statement sequence or
16527 -- an if statement, returns True if so, False otherwise.
16529 ----------------------
16530 -- Within_HSS_Or_If --
16531 ----------------------
16533 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
16536 N
:= Declaration_Node
(E
);
16543 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
16549 end Within_HSS_Or_If
;
16551 -- Start of processing for Set_Public_Status
16554 -- Everything in the scope of Standard is public
16556 if S
= Standard_Standard
then
16557 Set_Is_Public
(Id
);
16559 -- Entity is definitely not public if enclosing scope is not public
16561 elsif not Is_Public
(S
) then
16564 -- An object or function declaration that occurs in a handled sequence
16565 -- of statements or within an if statement is the declaration for a
16566 -- temporary object or local subprogram generated by the expander. It
16567 -- never needs to be made public and furthermore, making it public can
16568 -- cause back end problems.
16570 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
16571 N_Function_Specification
)
16572 and then Within_HSS_Or_If
(Id
)
16576 -- Entities in public packages or records are public
16578 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
16579 Set_Is_Public
(Id
);
16581 -- The bounds of an entry family declaration can generate object
16582 -- declarations that are visible to the back-end, e.g. in the
16583 -- the declaration of a composite type that contains tasks.
16585 elsif Is_Concurrent_Type
(S
)
16586 and then not Has_Completion
(S
)
16587 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
16589 Set_Is_Public
(Id
);
16591 end Set_Public_Status
;
16593 -----------------------------
16594 -- Set_Referenced_Modified --
16595 -----------------------------
16597 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
16601 -- Deal with indexed or selected component where prefix is modified
16603 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
16604 Pref
:= Prefix
(N
);
16606 -- If prefix is access type, then it is the designated object that is
16607 -- being modified, which means we have no entity to set the flag on.
16609 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
16612 -- Otherwise chase the prefix
16615 Set_Referenced_Modified
(Pref
, Out_Param
);
16618 -- Otherwise see if we have an entity name (only other case to process)
16620 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
16621 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
16622 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
16624 end Set_Referenced_Modified
;
16626 ----------------------------
16627 -- Set_Scope_Is_Transient --
16628 ----------------------------
16630 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
16632 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
16633 end Set_Scope_Is_Transient
;
16635 -------------------
16636 -- Set_Size_Info --
16637 -------------------
16639 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
16641 -- We copy Esize, but not RM_Size, since in general RM_Size is
16642 -- subtype specific and does not get inherited by all subtypes.
16644 Set_Esize
(T1
, Esize
(T2
));
16645 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
16647 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
16649 Is_Discrete_Or_Fixed_Point_Type
(T2
)
16651 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
16654 Set_Alignment
(T1
, Alignment
(T2
));
16657 --------------------
16658 -- Static_Boolean --
16659 --------------------
16661 function Static_Boolean
(N
: Node_Id
) return Uint
is
16663 Analyze_And_Resolve
(N
, Standard_Boolean
);
16666 or else Error_Posted
(N
)
16667 or else Etype
(N
) = Any_Type
16672 if Is_OK_Static_Expression
(N
) then
16673 if not Raises_Constraint_Error
(N
) then
16674 return Expr_Value
(N
);
16679 elsif Etype
(N
) = Any_Type
then
16683 Flag_Non_Static_Expr
16684 ("static boolean expression required here", N
);
16687 end Static_Boolean
;
16689 --------------------
16690 -- Static_Integer --
16691 --------------------
16693 function Static_Integer
(N
: Node_Id
) return Uint
is
16695 Analyze_And_Resolve
(N
, Any_Integer
);
16698 or else Error_Posted
(N
)
16699 or else Etype
(N
) = Any_Type
16704 if Is_OK_Static_Expression
(N
) then
16705 if not Raises_Constraint_Error
(N
) then
16706 return Expr_Value
(N
);
16711 elsif Etype
(N
) = Any_Type
then
16715 Flag_Non_Static_Expr
16716 ("static integer expression required here", N
);
16719 end Static_Integer
;
16721 --------------------------
16722 -- Statically_Different --
16723 --------------------------
16725 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
16726 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
16727 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
16729 return Is_Entity_Name
(R1
)
16730 and then Is_Entity_Name
(R2
)
16731 and then Entity
(R1
) /= Entity
(R2
)
16732 and then not Is_Formal
(Entity
(R1
))
16733 and then not Is_Formal
(Entity
(R2
));
16734 end Statically_Different
;
16736 --------------------------------------
16737 -- Subject_To_Loop_Entry_Attributes --
16738 --------------------------------------
16740 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
16746 -- The expansion mechanism transform a loop subject to at least one
16747 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
16748 -- the conditional part.
16750 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
16751 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
16753 Stmt
:= Original_Node
(N
);
16757 Nkind
(Stmt
) = N_Loop_Statement
16758 and then Present
(Identifier
(Stmt
))
16759 and then Present
(Entity
(Identifier
(Stmt
)))
16760 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
16761 end Subject_To_Loop_Entry_Attributes
;
16763 -----------------------------
16764 -- Subprogram_Access_Level --
16765 -----------------------------
16767 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
16769 if Present
(Alias
(Subp
)) then
16770 return Subprogram_Access_Level
(Alias
(Subp
));
16772 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
16774 end Subprogram_Access_Level
;
16776 -------------------------------
16777 -- Support_Atomic_Primitives --
16778 -------------------------------
16780 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
16784 -- Verify the alignment of Typ is known
16786 if not Known_Alignment
(Typ
) then
16790 if Known_Static_Esize
(Typ
) then
16791 Size
:= UI_To_Int
(Esize
(Typ
));
16793 -- If the Esize (Object_Size) is unknown at compile time, look at the
16794 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
16796 elsif Known_Static_RM_Size
(Typ
) then
16797 Size
:= UI_To_Int
(RM_Size
(Typ
));
16799 -- Otherwise, the size is considered to be unknown.
16805 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
16806 -- Typ is properly aligned.
16809 when 8 |
16 |
32 |
64 =>
16810 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
16814 end Support_Atomic_Primitives
;
16820 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
16822 if Debug_Flag_W
then
16823 for J
in 0 .. Scope_Stack
.Last
loop
16828 Write_Name
(Chars
(E
));
16829 Write_Str
(" from ");
16830 Write_Location
(Sloc
(N
));
16835 -----------------------
16836 -- Transfer_Entities --
16837 -----------------------
16839 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
16840 Ent
: Entity_Id
:= First_Entity
(From
);
16847 if (Last_Entity
(To
)) = Empty
then
16848 Set_First_Entity
(To
, Ent
);
16850 Set_Next_Entity
(Last_Entity
(To
), Ent
);
16853 Set_Last_Entity
(To
, Last_Entity
(From
));
16855 while Present
(Ent
) loop
16856 Set_Scope
(Ent
, To
);
16858 if not Is_Public
(Ent
) then
16859 Set_Public_Status
(Ent
);
16861 if Is_Public
(Ent
) and then Ekind
(Ent
) = E_Record_Subtype
then
16863 -- The components of the propagated Itype must also be public
16868 Comp
:= First_Entity
(Ent
);
16869 while Present
(Comp
) loop
16870 Set_Is_Public
(Comp
);
16871 Next_Entity
(Comp
);
16880 Set_First_Entity
(From
, Empty
);
16881 Set_Last_Entity
(From
, Empty
);
16882 end Transfer_Entities
;
16884 -----------------------
16885 -- Type_Access_Level --
16886 -----------------------
16888 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
16892 Btyp
:= Base_Type
(Typ
);
16894 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
16895 -- simply use the level where the type is declared. This is true for
16896 -- stand-alone object declarations, and for anonymous access types
16897 -- associated with components the level is the same as that of the
16898 -- enclosing composite type. However, special treatment is needed for
16899 -- the cases of access parameters, return objects of an anonymous access
16900 -- type, and, in Ada 95, access discriminants of limited types.
16902 if Is_Access_Type
(Btyp
) then
16903 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
16905 -- If the type is a nonlocal anonymous access type (such as for
16906 -- an access parameter) we treat it as being declared at the
16907 -- library level to ensure that names such as X.all'access don't
16908 -- fail static accessibility checks.
16910 if not Is_Local_Anonymous_Access
(Typ
) then
16911 return Scope_Depth
(Standard_Standard
);
16913 -- If this is a return object, the accessibility level is that of
16914 -- the result subtype of the enclosing function. The test here is
16915 -- little complicated, because we have to account for extended
16916 -- return statements that have been rewritten as blocks, in which
16917 -- case we have to find and the Is_Return_Object attribute of the
16918 -- itype's associated object. It would be nice to find a way to
16919 -- simplify this test, but it doesn't seem worthwhile to add a new
16920 -- flag just for purposes of this test. ???
16922 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
16925 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
16926 N_Object_Declaration
16927 and then Is_Return_Object
16928 (Defining_Identifier
16929 (Associated_Node_For_Itype
(Btyp
))))
16935 Scop
:= Scope
(Scope
(Btyp
));
16936 while Present
(Scop
) loop
16937 exit when Ekind
(Scop
) = E_Function
;
16938 Scop
:= Scope
(Scop
);
16941 -- Treat the return object's type as having the level of the
16942 -- function's result subtype (as per RM05-6.5(5.3/2)).
16944 return Type_Access_Level
(Etype
(Scop
));
16949 Btyp
:= Root_Type
(Btyp
);
16951 -- The accessibility level of anonymous access types associated with
16952 -- discriminants is that of the current instance of the type, and
16953 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
16955 -- AI-402: access discriminants have accessibility based on the
16956 -- object rather than the type in Ada 2005, so the above paragraph
16959 -- ??? Needs completion with rules from AI-416
16961 if Ada_Version
<= Ada_95
16962 and then Ekind
(Typ
) = E_Anonymous_Access_Type
16963 and then Present
(Associated_Node_For_Itype
(Typ
))
16964 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
16965 N_Discriminant_Specification
16967 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
16971 -- Return library level for a generic formal type. This is done because
16972 -- RM(10.3.2) says that "The statically deeper relationship does not
16973 -- apply to ... a descendant of a generic formal type". Rather than
16974 -- checking at each point where a static accessibility check is
16975 -- performed to see if we are dealing with a formal type, this rule is
16976 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
16977 -- return extreme values for a formal type; Deepest_Type_Access_Level
16978 -- returns Int'Last. By calling the appropriate function from among the
16979 -- two, we ensure that the static accessibility check will pass if we
16980 -- happen to run into a formal type. More specifically, we should call
16981 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
16982 -- call occurs as part of a static accessibility check and the error
16983 -- case is the case where the type's level is too shallow (as opposed
16986 if Is_Generic_Type
(Root_Type
(Btyp
)) then
16987 return Scope_Depth
(Standard_Standard
);
16990 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
16991 end Type_Access_Level
;
16993 ------------------------------------
16994 -- Type_Without_Stream_Operation --
16995 ------------------------------------
16997 function Type_Without_Stream_Operation
16999 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
17001 BT
: constant Entity_Id
:= Base_Type
(T
);
17002 Op_Missing
: Boolean;
17005 if not Restriction_Active
(No_Default_Stream_Attributes
) then
17009 if Is_Elementary_Type
(T
) then
17010 if Op
= TSS_Null
then
17012 No
(TSS
(BT
, TSS_Stream_Read
))
17013 or else No
(TSS
(BT
, TSS_Stream_Write
));
17016 Op_Missing
:= No
(TSS
(BT
, Op
));
17025 elsif Is_Array_Type
(T
) then
17026 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
17028 elsif Is_Record_Type
(T
) then
17034 Comp
:= First_Component
(T
);
17035 while Present
(Comp
) loop
17036 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
17038 if Present
(C_Typ
) then
17042 Next_Component
(Comp
);
17048 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
17049 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
17053 end Type_Without_Stream_Operation
;
17055 ----------------------------
17056 -- Unique_Defining_Entity --
17057 ----------------------------
17059 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
17061 return Unique_Entity
(Defining_Entity
(N
));
17062 end Unique_Defining_Entity
;
17064 -------------------
17065 -- Unique_Entity --
17066 -------------------
17068 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
17069 U
: Entity_Id
:= E
;
17075 if Present
(Full_View
(E
)) then
17076 U
:= Full_View
(E
);
17080 if Present
(Full_View
(E
)) then
17081 U
:= Full_View
(E
);
17084 when E_Package_Body
=>
17087 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17091 U
:= Corresponding_Spec
(P
);
17093 when E_Subprogram_Body
=>
17096 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17102 if Nkind
(P
) = N_Subprogram_Body_Stub
then
17103 if Present
(Library_Unit
(P
)) then
17105 -- Get to the function or procedure (generic) entity through
17106 -- the body entity.
17109 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
17112 U
:= Corresponding_Spec
(P
);
17115 when Formal_Kind
=>
17116 if Present
(Spec_Entity
(E
)) then
17117 U
:= Spec_Entity
(E
);
17131 function Unique_Name
(E
: Entity_Id
) return String is
17133 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17134 -- reliable, as they may not include the overloading suffix. Instead,
17135 -- when looking for the name of E or one of its enclosing scope, we get
17136 -- the name of the corresponding Unique_Entity.
17138 function Get_Scoped_Name
(E
: Entity_Id
) return String;
17139 -- Return the name of E prefixed by all the names of the scopes to which
17140 -- E belongs, except for Standard.
17142 ---------------------
17143 -- Get_Scoped_Name --
17144 ---------------------
17146 function Get_Scoped_Name
(E
: Entity_Id
) return String is
17147 Name
: constant String := Get_Name_String
(Chars
(E
));
17149 if Has_Fully_Qualified_Name
(E
)
17150 or else Scope
(E
) = Standard_Standard
17154 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
17156 end Get_Scoped_Name
;
17158 -- Start of processing for Unique_Name
17161 if E
= Standard_Standard
then
17162 return Get_Name_String
(Name_Standard
);
17164 elsif Scope
(E
) = Standard_Standard
17165 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
17167 return Get_Name_String
(Name_Standard
) & "__" &
17168 Get_Name_String
(Chars
(E
));
17170 elsif Ekind
(E
) = E_Enumeration_Literal
then
17171 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
17174 return Get_Scoped_Name
(Unique_Entity
(E
));
17178 ---------------------
17179 -- Unit_Is_Visible --
17180 ---------------------
17182 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
17183 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
17184 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
17186 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
17187 -- For a child unit, check whether unit appears in a with_clause
17190 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
17191 -- Scan the context clause of one compilation unit looking for a
17192 -- with_clause for the unit in question.
17194 ----------------------------
17195 -- Unit_In_Parent_Context --
17196 ----------------------------
17198 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
17200 if Unit_In_Context
(Par_Unit
) then
17203 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
17204 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
17209 end Unit_In_Parent_Context
;
17211 ---------------------
17212 -- Unit_In_Context --
17213 ---------------------
17215 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
17219 Clause
:= First
(Context_Items
(Comp_Unit
));
17220 while Present
(Clause
) loop
17221 if Nkind
(Clause
) = N_With_Clause
then
17222 if Library_Unit
(Clause
) = U
then
17225 -- The with_clause may denote a renaming of the unit we are
17226 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17229 Renamed_Entity
(Entity
(Name
(Clause
))) =
17230 Defining_Entity
(Unit
(U
))
17240 end Unit_In_Context
;
17242 -- Start of processing for Unit_Is_Visible
17245 -- The currrent unit is directly visible
17250 elsif Unit_In_Context
(Curr
) then
17253 -- If the current unit is a body, check the context of the spec
17255 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
17257 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
17258 and then not Acts_As_Spec
(Unit
(Curr
)))
17260 if Unit_In_Context
(Library_Unit
(Curr
)) then
17265 -- If the spec is a child unit, examine the parents
17267 if Is_Child_Unit
(Curr_Entity
) then
17268 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
17270 Unit_In_Parent_Context
17271 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
17273 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
17279 end Unit_Is_Visible
;
17281 ------------------------------
17282 -- Universal_Interpretation --
17283 ------------------------------
17285 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
17286 Index
: Interp_Index
;
17290 -- The argument may be a formal parameter of an operator or subprogram
17291 -- with multiple interpretations, or else an expression for an actual.
17293 if Nkind
(Opnd
) = N_Defining_Identifier
17294 or else not Is_Overloaded
(Opnd
)
17296 if Etype
(Opnd
) = Universal_Integer
17297 or else Etype
(Opnd
) = Universal_Real
17299 return Etype
(Opnd
);
17305 Get_First_Interp
(Opnd
, Index
, It
);
17306 while Present
(It
.Typ
) loop
17307 if It
.Typ
= Universal_Integer
17308 or else It
.Typ
= Universal_Real
17313 Get_Next_Interp
(Index
, It
);
17318 end Universal_Interpretation
;
17324 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
17326 -- Recurse to handle unlikely case of multiple levels of qualification
17328 if Nkind
(Expr
) = N_Qualified_Expression
then
17329 return Unqualify
(Expression
(Expr
));
17331 -- Normal case, not a qualified expression
17338 -----------------------
17339 -- Visible_Ancestors --
17340 -----------------------
17342 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
17348 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
17350 -- Collect all the parents and progenitors of Typ. If the full-view of
17351 -- private parents and progenitors is available then it is used to
17352 -- generate the list of visible ancestors; otherwise their partial
17353 -- view is added to the resulting list.
17358 Use_Full_View
=> True);
17362 Ifaces_List
=> List_2
,
17363 Exclude_Parents
=> True,
17364 Use_Full_View
=> True);
17366 -- Join the two lists. Avoid duplications because an interface may
17367 -- simultaneously be parent and progenitor of a type.
17369 Elmt
:= First_Elmt
(List_2
);
17370 while Present
(Elmt
) loop
17371 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
17376 end Visible_Ancestors
;
17378 ----------------------
17379 -- Within_Init_Proc --
17380 ----------------------
17382 function Within_Init_Proc
return Boolean is
17386 S
:= Current_Scope
;
17387 while not Is_Overloadable
(S
) loop
17388 if S
= Standard_Standard
then
17395 return Is_Init_Proc
(S
);
17396 end Within_Init_Proc
;
17402 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
17409 elsif SE
= Standard_Standard
then
17421 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
17422 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
17423 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
17425 Matching_Field
: Entity_Id
;
17426 -- Entity to give a more precise suggestion on how to write a one-
17427 -- element positional aggregate.
17429 function Has_One_Matching_Field
return Boolean;
17430 -- Determines if Expec_Type is a record type with a single component or
17431 -- discriminant whose type matches the found type or is one dimensional
17432 -- array whose component type matches the found type. In the case of
17433 -- one discriminant, we ignore the variant parts. That's not accurate,
17434 -- but good enough for the warning.
17436 ----------------------------
17437 -- Has_One_Matching_Field --
17438 ----------------------------
17440 function Has_One_Matching_Field
return Boolean is
17444 Matching_Field
:= Empty
;
17446 if Is_Array_Type
(Expec_Type
)
17447 and then Number_Dimensions
(Expec_Type
) = 1
17448 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
17450 -- Use type name if available. This excludes multidimensional
17451 -- arrays and anonymous arrays.
17453 if Comes_From_Source
(Expec_Type
) then
17454 Matching_Field
:= Expec_Type
;
17456 -- For an assignment, use name of target
17458 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
17459 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
17461 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
17466 elsif not Is_Record_Type
(Expec_Type
) then
17470 E
:= First_Entity
(Expec_Type
);
17475 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
17476 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
17485 if not Covers
(Etype
(E
), Found_Type
) then
17488 elsif Present
(Next_Entity
(E
))
17489 and then (Ekind
(E
) = E_Component
17490 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
17495 Matching_Field
:= E
;
17499 end Has_One_Matching_Field
;
17501 -- Start of processing for Wrong_Type
17504 -- Don't output message if either type is Any_Type, or if a message
17505 -- has already been posted for this node. We need to do the latter
17506 -- check explicitly (it is ordinarily done in Errout), because we
17507 -- are using ! to force the output of the error messages.
17509 if Expec_Type
= Any_Type
17510 or else Found_Type
= Any_Type
17511 or else Error_Posted
(Expr
)
17515 -- If one of the types is a Taft-Amendment type and the other it its
17516 -- completion, it must be an illegal use of a TAT in the spec, for
17517 -- which an error was already emitted. Avoid cascaded errors.
17519 elsif Is_Incomplete_Type
(Expec_Type
)
17520 and then Has_Completion_In_Body
(Expec_Type
)
17521 and then Full_View
(Expec_Type
) = Etype
(Expr
)
17525 elsif Is_Incomplete_Type
(Etype
(Expr
))
17526 and then Has_Completion_In_Body
(Etype
(Expr
))
17527 and then Full_View
(Etype
(Expr
)) = Expec_Type
17531 -- In an instance, there is an ongoing problem with completion of
17532 -- type derived from private types. Their structure is what Gigi
17533 -- expects, but the Etype is the parent type rather than the
17534 -- derived private type itself. Do not flag error in this case. The
17535 -- private completion is an entity without a parent, like an Itype.
17536 -- Similarly, full and partial views may be incorrect in the instance.
17537 -- There is no simple way to insure that it is consistent ???
17539 -- A similar view discrepancy can happen in an inlined body, for the
17540 -- same reason: inserted body may be outside of the original package
17541 -- and only partial views are visible at the point of insertion.
17543 elsif In_Instance
or else In_Inlined_Body
then
17544 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
17546 (Has_Private_Declaration
(Expected_Type
)
17547 or else Has_Private_Declaration
(Etype
(Expr
)))
17548 and then No
(Parent
(Expected_Type
))
17552 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
17553 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
17557 elsif Is_Private_Type
(Expected_Type
)
17558 and then Present
(Full_View
(Expected_Type
))
17559 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
17565 -- An interesting special check. If the expression is parenthesized
17566 -- and its type corresponds to the type of the sole component of the
17567 -- expected record type, or to the component type of the expected one
17568 -- dimensional array type, then assume we have a bad aggregate attempt.
17570 if Nkind
(Expr
) in N_Subexpr
17571 and then Paren_Count
(Expr
) /= 0
17572 and then Has_One_Matching_Field
17574 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
17575 if Present
(Matching_Field
) then
17576 if Is_Array_Type
(Expec_Type
) then
17578 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
17582 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
17586 -- Another special check, if we are looking for a pool-specific access
17587 -- type and we found an E_Access_Attribute_Type, then we have the case
17588 -- of an Access attribute being used in a context which needs a pool-
17589 -- specific type, which is never allowed. The one extra check we make
17590 -- is that the expected designated type covers the Found_Type.
17592 elsif Is_Access_Type
(Expec_Type
)
17593 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
17594 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
17595 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
17597 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
17599 Error_Msg_N
-- CODEFIX
17600 ("result must be general access type!", Expr
);
17601 Error_Msg_NE
-- CODEFIX
17602 ("add ALL to }!", Expr
, Expec_Type
);
17604 -- Another special check, if the expected type is an integer type,
17605 -- but the expression is of type System.Address, and the parent is
17606 -- an addition or subtraction operation whose left operand is the
17607 -- expression in question and whose right operand is of an integral
17608 -- type, then this is an attempt at address arithmetic, so give
17609 -- appropriate message.
17611 elsif Is_Integer_Type
(Expec_Type
)
17612 and then Is_RTE
(Found_Type
, RE_Address
)
17613 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
17614 and then Expr
= Left_Opnd
(Parent
(Expr
))
17615 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
17618 ("address arithmetic not predefined in package System",
17621 ("\possible missing with/use of System.Storage_Elements",
17625 -- If the expected type is an anonymous access type, as for access
17626 -- parameters and discriminants, the error is on the designated types.
17628 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
17629 if Comes_From_Source
(Expec_Type
) then
17630 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
17633 ("expected an access type with designated}",
17634 Expr
, Designated_Type
(Expec_Type
));
17637 if Is_Access_Type
(Found_Type
)
17638 and then not Comes_From_Source
(Found_Type
)
17641 ("\\found an access type with designated}!",
17642 Expr
, Designated_Type
(Found_Type
));
17644 if From_Limited_With
(Found_Type
) then
17645 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
17646 Error_Msg_Qual_Level
:= 99;
17647 Error_Msg_NE
-- CODEFIX
17648 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
17649 Error_Msg_Qual_Level
:= 0;
17651 Error_Msg_NE
("found}!", Expr
, Found_Type
);
17655 -- Normal case of one type found, some other type expected
17658 -- If the names of the two types are the same, see if some number
17659 -- of levels of qualification will help. Don't try more than three
17660 -- levels, and if we get to standard, it's no use (and probably
17661 -- represents an error in the compiler) Also do not bother with
17662 -- internal scope names.
17665 Expec_Scope
: Entity_Id
;
17666 Found_Scope
: Entity_Id
;
17669 Expec_Scope
:= Expec_Type
;
17670 Found_Scope
:= Found_Type
;
17672 for Levels
in Int
range 0 .. 3 loop
17673 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
17674 Error_Msg_Qual_Level
:= Levels
;
17678 Expec_Scope
:= Scope
(Expec_Scope
);
17679 Found_Scope
:= Scope
(Found_Scope
);
17681 exit when Expec_Scope
= Standard_Standard
17682 or else Found_Scope
= Standard_Standard
17683 or else not Comes_From_Source
(Expec_Scope
)
17684 or else not Comes_From_Source
(Found_Scope
);
17688 if Is_Record_Type
(Expec_Type
)
17689 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
17691 Error_Msg_NE
("expected}!", Expr
,
17692 Corresponding_Remote_Type
(Expec_Type
));
17694 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
17697 if Is_Entity_Name
(Expr
)
17698 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
17700 Error_Msg_N
("\\found package name!", Expr
);
17702 elsif Is_Entity_Name
(Expr
)
17703 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
17705 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
17707 ("found procedure name, possibly missing Access attribute!",
17711 ("\\found procedure name instead of function!", Expr
);
17714 elsif Nkind
(Expr
) = N_Function_Call
17715 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
17716 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
17717 and then No
(Parameter_Associations
(Expr
))
17720 ("found function name, possibly missing Access attribute!",
17723 -- Catch common error: a prefix or infix operator which is not
17724 -- directly visible because the type isn't.
17726 elsif Nkind
(Expr
) in N_Op
17727 and then Is_Overloaded
(Expr
)
17728 and then not Is_Immediately_Visible
(Expec_Type
)
17729 and then not Is_Potentially_Use_Visible
(Expec_Type
)
17730 and then not In_Use
(Expec_Type
)
17731 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
17734 ("operator of the type is not directly visible!", Expr
);
17736 elsif Ekind
(Found_Type
) = E_Void
17737 and then Present
(Parent
(Found_Type
))
17738 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
17740 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
17743 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
17746 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
17747 -- of the same modular type, and (M1 and M2) = 0 was intended.
17749 if Expec_Type
= Standard_Boolean
17750 and then Is_Modular_Integer_Type
(Found_Type
)
17751 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
17752 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
17755 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
17756 L
: constant Node_Id
:= Left_Opnd
(Op
);
17757 R
: constant Node_Id
:= Right_Opnd
(Op
);
17759 -- The case for the message is when the left operand of the
17760 -- comparison is the same modular type, or when it is an
17761 -- integer literal (or other universal integer expression),
17762 -- which would have been typed as the modular type if the
17763 -- parens had been there.
17765 if (Etype
(L
) = Found_Type
17767 Etype
(L
) = Universal_Integer
)
17768 and then Is_Integer_Type
(Etype
(R
))
17771 ("\\possible missing parens for modular operation", Expr
);
17776 -- Reset error message qualification indication
17778 Error_Msg_Qual_Level
:= 0;