1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Unst
; use Exp_Unst
;
36 with Exp_Util
; use Exp_Util
;
37 with Fname
; use Fname
;
38 with Freeze
; use Freeze
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
.Sp
; use Namet
.Sp
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
44 with Output
; use Output
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Attr
; use Sem_Attr
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch13
; use Sem_Ch13
;
54 with Sem_Disp
; use Sem_Disp
;
55 with Sem_Eval
; use Sem_Eval
;
56 with Sem_Prag
; use Sem_Prag
;
57 with Sem_Res
; use Sem_Res
;
58 with Sem_Warn
; use Sem_Warn
;
59 with Sem_Type
; use Sem_Type
;
60 with Sinfo
; use Sinfo
;
61 with Sinput
; use Sinput
;
62 with Stand
; use Stand
;
64 with Stringt
; use Stringt
;
65 with Targparm
; use Targparm
;
66 with Tbuild
; use Tbuild
;
67 with Ttypes
; use Ttypes
;
68 with Uname
; use Uname
;
70 with GNAT
.HTable
; use GNAT
.HTable
;
72 package body Sem_Util
is
74 ----------------------------------------
75 -- Global Variables for New_Copy_Tree --
76 ----------------------------------------
78 -- These global variables are used by New_Copy_Tree. See description of the
79 -- body of this subprogram for details. Global variables can be safely used
80 -- by New_Copy_Tree, since there is no case of a recursive call from the
81 -- processing inside New_Copy_Tree.
83 NCT_Hash_Threshold
: constant := 20;
84 -- If there are more than this number of pairs of entries in the map, then
85 -- Hash_Tables_Used will be set, and the hash tables will be initialized
86 -- and used for the searches.
88 NCT_Hash_Tables_Used
: Boolean := False;
89 -- Set to True if hash tables are in use
91 NCT_Table_Entries
: Nat
:= 0;
92 -- Count entries in table to see if threshold is reached
94 NCT_Hash_Table_Setup
: Boolean := False;
95 -- Set to True if hash table contains data. We set this True if we setup
96 -- the hash table with data, and leave it set permanently from then on,
97 -- this is a signal that second and subsequent users of the hash table
98 -- must clear the old entries before reuse.
100 subtype NCT_Header_Num
is Int
range 0 .. 511;
101 -- Defines range of headers in hash tables (512 headers)
103 -----------------------
104 -- Local Subprograms --
105 -----------------------
107 function Build_Component_Subtype
110 T
: Entity_Id
) return Node_Id
;
111 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
112 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
113 -- Loc is the source location, T is the original subtype.
115 function Has_Enabled_Property
116 (Item_Id
: Entity_Id
;
117 Property
: Name_Id
) return Boolean;
118 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
119 -- Determine whether an abstract state or a variable denoted by entity
120 -- Item_Id has enabled property Property.
122 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
123 -- T is a derived tagged type. Check whether the type extension is null.
124 -- If the parent type is fully initialized, T can be treated as such.
126 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
127 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
128 -- with discriminants whose default values are static, examine only the
129 -- components in the selected variant to determine whether all of them
132 ------------------------------
133 -- Abstract_Interface_List --
134 ------------------------------
136 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
140 if Is_Concurrent_Type
(Typ
) then
142 -- If we are dealing with a synchronized subtype, go to the base
143 -- type, whose declaration has the interface list.
145 -- Shouldn't this be Declaration_Node???
147 Nod
:= Parent
(Base_Type
(Typ
));
149 if Nkind
(Nod
) = N_Full_Type_Declaration
then
153 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
154 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
155 Nod
:= Type_Definition
(Parent
(Typ
));
157 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
158 if Present
(Full_View
(Typ
))
160 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
162 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
164 -- If the full-view is not available we cannot do anything else
165 -- here (the source has errors).
171 -- Support for generic formals with interfaces is still missing ???
173 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
178 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
182 elsif Ekind
(Typ
) = E_Record_Subtype
then
183 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
185 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
187 -- Recurse, because parent may still be a private extension. Also
188 -- note that the full view of the subtype or the full view of its
189 -- base type may (both) be unavailable.
191 return Abstract_Interface_List
(Etype
(Typ
));
193 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
194 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
195 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
197 Nod
:= Type_Definition
(Parent
(Typ
));
201 return Interface_List
(Nod
);
202 end Abstract_Interface_List
;
204 --------------------------------
205 -- Add_Access_Type_To_Process --
206 --------------------------------
208 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
212 Ensure_Freeze_Node
(E
);
213 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
217 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
221 end Add_Access_Type_To_Process
;
223 --------------------------
224 -- Add_Block_Identifier --
225 --------------------------
227 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
228 Loc
: constant Source_Ptr
:= Sloc
(N
);
231 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
233 -- The block already has a label, return its entity
235 if Present
(Identifier
(N
)) then
236 Id
:= Entity
(Identifier
(N
));
238 -- Create a new block label and set its attributes
241 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
242 Set_Etype
(Id
, Standard_Void_Type
);
245 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
246 Set_Block_Node
(Id
, Identifier
(N
));
248 end Add_Block_Identifier
;
250 -----------------------
251 -- Add_Contract_Item --
252 -----------------------
254 procedure Add_Contract_Item
(Prag
: Node_Id
; Id
: Entity_Id
) is
255 Items
: Node_Id
:= Contract
(Id
);
257 procedure Add_Classification
;
258 -- Prepend Prag to the list of classifications
260 procedure Add_Contract_Test_Case
;
261 -- Prepend Prag to the list of contract and test cases
263 procedure Add_Pre_Post_Condition
;
264 -- Prepend Prag to the list of pre- and postconditions
266 ------------------------
267 -- Add_Classification --
268 ------------------------
270 procedure Add_Classification
is
272 Set_Next_Pragma
(Prag
, Classifications
(Items
));
273 Set_Classifications
(Items
, Prag
);
274 end Add_Classification
;
276 ----------------------------
277 -- Add_Contract_Test_Case --
278 ----------------------------
280 procedure Add_Contract_Test_Case
is
282 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
283 Set_Contract_Test_Cases
(Items
, Prag
);
284 end Add_Contract_Test_Case
;
286 ----------------------------
287 -- Add_Pre_Post_Condition --
288 ----------------------------
290 procedure Add_Pre_Post_Condition
is
292 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
293 Set_Pre_Post_Conditions
(Items
, Prag
);
294 end Add_Pre_Post_Condition
;
300 -- Start of processing for Add_Contract_Item
303 -- A contract must contain only pragmas
305 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
306 Prag_Nam
:= Pragma_Name
(Prag
);
308 -- Create a new contract when adding the first item
311 Items
:= Make_Contract
(Sloc
(Id
));
312 Set_Contract
(Id
, Items
);
315 -- Contract items related to [generic] packages or instantiations. The
316 -- applicable pragmas are:
320 -- Part_Of (instantiation only)
322 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
323 if Nam_In
(Prag_Nam
, Name_Abstract_State
,
324 Name_Initial_Condition
,
329 -- Indicator Part_Of must be associated with a package instantiation
331 elsif Prag_Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) then
334 -- The pragma is not a proper contract item
340 -- Contract items related to package bodies. The applicable pragmas are:
343 elsif Ekind
(Id
) = E_Package_Body
then
344 if Prag_Nam
= Name_Refined_State
then
347 -- The pragma is not a proper contract item
353 -- Contract items related to subprogram or entry declarations. The
354 -- applicable pragmas are:
357 -- Extensions_Visible
363 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
364 or else Is_Generic_Subprogram
(Id
)
365 or else Is_Subprogram
(Id
)
367 if Nam_In
(Prag_Nam
, Name_Postcondition
, Name_Precondition
) then
368 Add_Pre_Post_Condition
;
370 elsif Nam_In
(Prag_Nam
, Name_Contract_Cases
, Name_Test_Case
) then
371 Add_Contract_Test_Case
;
373 elsif Nam_In
(Prag_Nam
, Name_Depends
,
374 Name_Extensions_Visible
,
379 -- The pragma is not a proper contract item
385 -- Contract items related to subprogram bodies. Applicable pragmas are:
392 elsif Ekind
(Id
) = E_Subprogram_Body
then
393 if Nam_In
(Prag_Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
396 elsif Nam_In
(Prag_Nam
, Name_Postcondition
,
400 Add_Pre_Post_Condition
;
402 -- The pragma is not a proper contract item
408 -- Contract items related to variables. Applicable pragmas are:
415 elsif Ekind
(Id
) = E_Variable
then
416 if Nam_In
(Prag_Nam
, Name_Async_Readers
,
418 Name_Effective_Reads
,
419 Name_Effective_Writes
,
424 -- The pragma is not a proper contract item
430 end Add_Contract_Item
;
432 ----------------------------
433 -- Add_Global_Declaration --
434 ----------------------------
436 procedure Add_Global_Declaration
(N
: Node_Id
) is
437 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
440 if No
(Declarations
(Aux_Node
)) then
441 Set_Declarations
(Aux_Node
, New_List
);
444 Append_To
(Declarations
(Aux_Node
), N
);
446 end Add_Global_Declaration
;
448 --------------------------------
449 -- Address_Integer_Convert_OK --
450 --------------------------------
452 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
454 if Allow_Integer_Address
455 and then ((Is_Descendent_Of_Address
(T1
)
456 and then Is_Private_Type
(T1
)
457 and then Is_Integer_Type
(T2
))
459 (Is_Descendent_Of_Address
(T2
)
460 and then Is_Private_Type
(T2
)
461 and then Is_Integer_Type
(T1
)))
467 end Address_Integer_Convert_OK
;
473 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
475 function Addressable
(V
: Uint
) return Boolean is
477 return V
= Uint_8
or else
483 function Addressable
(V
: Int
) return Boolean is
491 ---------------------------------
492 -- Aggregate_Constraint_Checks --
493 ---------------------------------
495 procedure Aggregate_Constraint_Checks
497 Check_Typ
: Entity_Id
)
499 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
502 if Raises_Constraint_Error
(Exp
) then
506 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
507 -- component's type to force the appropriate accessibility checks.
509 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
510 -- type to force the corresponding run-time check
512 if Is_Access_Type
(Check_Typ
)
513 and then ((Is_Local_Anonymous_Access
(Check_Typ
))
514 or else (Can_Never_Be_Null
(Check_Typ
)
515 and then not Can_Never_Be_Null
(Exp_Typ
)))
517 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
518 Analyze_And_Resolve
(Exp
, Check_Typ
);
519 Check_Unset_Reference
(Exp
);
522 -- This is really expansion activity, so make sure that expansion is
523 -- on and is allowed. In GNATprove mode, we also want check flags to
524 -- be added in the tree, so that the formal verification can rely on
525 -- those to be present. In GNATprove mode for formal verification, some
526 -- treatment typically only done during expansion needs to be performed
527 -- on the tree, but it should not be applied inside generics. Otherwise,
528 -- this breaks the name resolution mechanism for generic instances.
530 if not Expander_Active
531 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
536 -- First check if we have to insert discriminant checks
538 if Has_Discriminants
(Exp_Typ
) then
539 Apply_Discriminant_Check
(Exp
, Check_Typ
);
541 -- Next emit length checks for array aggregates
543 elsif Is_Array_Type
(Exp_Typ
) then
544 Apply_Length_Check
(Exp
, Check_Typ
);
546 -- Finally emit scalar and string checks. If we are dealing with a
547 -- scalar literal we need to check by hand because the Etype of
548 -- literals is not necessarily correct.
550 elsif Is_Scalar_Type
(Exp_Typ
)
551 and then Compile_Time_Known_Value
(Exp
)
553 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
554 Apply_Compile_Time_Constraint_Error
555 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
556 Ent
=> Base_Type
(Check_Typ
),
557 Typ
=> Base_Type
(Check_Typ
));
559 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
560 Apply_Compile_Time_Constraint_Error
561 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
565 elsif not Range_Checks_Suppressed
(Check_Typ
) then
566 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
569 -- Verify that target type is also scalar, to prevent view anomalies
570 -- in instantiations.
572 elsif (Is_Scalar_Type
(Exp_Typ
)
573 or else Nkind
(Exp
) = N_String_Literal
)
574 and then Is_Scalar_Type
(Check_Typ
)
575 and then Exp_Typ
/= Check_Typ
577 if Is_Entity_Name
(Exp
)
578 and then Ekind
(Entity
(Exp
)) = E_Constant
580 -- If expression is a constant, it is worthwhile checking whether
581 -- it is a bound of the type.
583 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
584 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
586 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
587 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
592 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
593 Analyze_And_Resolve
(Exp
, Check_Typ
);
594 Check_Unset_Reference
(Exp
);
597 -- Could use a comment on this case ???
600 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
601 Analyze_And_Resolve
(Exp
, Check_Typ
);
602 Check_Unset_Reference
(Exp
);
606 end Aggregate_Constraint_Checks
;
608 -----------------------
609 -- Alignment_In_Bits --
610 -----------------------
612 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
614 return Alignment
(E
) * System_Storage_Unit
;
615 end Alignment_In_Bits
;
617 ---------------------------------
618 -- Append_Inherited_Subprogram --
619 ---------------------------------
621 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
622 Par
: constant Entity_Id
:= Alias
(S
);
623 -- The parent subprogram
625 Scop
: constant Entity_Id
:= Scope
(Par
);
626 -- The scope of definition of the parent subprogram
628 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
629 -- The derived type of which S is a primitive operation
635 if Ekind
(Current_Scope
) = E_Package
636 and then In_Private_Part
(Current_Scope
)
637 and then Has_Private_Declaration
(Typ
)
638 and then Is_Tagged_Type
(Typ
)
639 and then Scop
= Current_Scope
641 -- The inherited operation is available at the earliest place after
642 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
643 -- relevant for type extensions. If the parent operation appears
644 -- after the type extension, the operation is not visible.
647 (Visible_Declarations
648 (Package_Specification
(Current_Scope
)));
649 while Present
(Decl
) loop
650 if Nkind
(Decl
) = N_Private_Extension_Declaration
651 and then Defining_Entity
(Decl
) = Typ
653 if Sloc
(Decl
) > Sloc
(Par
) then
654 Next_E
:= Next_Entity
(Par
);
655 Set_Next_Entity
(Par
, S
);
656 Set_Next_Entity
(S
, Next_E
);
668 -- If partial view is not a type extension, or it appears before the
669 -- subprogram declaration, insert normally at end of entity list.
671 Append_Entity
(S
, Current_Scope
);
672 end Append_Inherited_Subprogram
;
674 -----------------------------------------
675 -- Apply_Compile_Time_Constraint_Error --
676 -----------------------------------------
678 procedure Apply_Compile_Time_Constraint_Error
681 Reason
: RT_Exception_Code
;
682 Ent
: Entity_Id
:= Empty
;
683 Typ
: Entity_Id
:= Empty
;
684 Loc
: Source_Ptr
:= No_Location
;
685 Rep
: Boolean := True;
686 Warn
: Boolean := False)
688 Stat
: constant Boolean := Is_Static_Expression
(N
);
689 R_Stat
: constant Node_Id
:=
690 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
701 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
707 -- Now we replace the node by an N_Raise_Constraint_Error node
708 -- This does not need reanalyzing, so set it as analyzed now.
711 Set_Analyzed
(N
, True);
714 Set_Raises_Constraint_Error
(N
);
716 -- Now deal with possible local raise handling
718 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
720 -- If the original expression was marked as static, the result is
721 -- still marked as static, but the Raises_Constraint_Error flag is
722 -- always set so that further static evaluation is not attempted.
725 Set_Is_Static_Expression
(N
);
727 end Apply_Compile_Time_Constraint_Error
;
729 ---------------------------
730 -- Async_Readers_Enabled --
731 ---------------------------
733 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
735 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
736 end Async_Readers_Enabled
;
738 ---------------------------
739 -- Async_Writers_Enabled --
740 ---------------------------
742 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
744 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
745 end Async_Writers_Enabled
;
747 --------------------------------------
748 -- Available_Full_View_Of_Component --
749 --------------------------------------
751 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
752 ST
: constant Entity_Id
:= Scope
(T
);
753 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
755 return In_Open_Scopes
(ST
)
756 and then In_Open_Scopes
(SCT
)
757 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
758 end Available_Full_View_Of_Component
;
764 procedure Bad_Attribute
767 Warn
: Boolean := False)
770 Error_Msg_Warn
:= Warn
;
771 Error_Msg_N
("unrecognized attribute&<<", N
);
773 -- Check for possible misspelling
775 Error_Msg_Name_1
:= First_Attribute_Name
;
776 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
777 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
778 Error_Msg_N
-- CODEFIX
779 ("\possible misspelling of %<<", N
);
783 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
787 --------------------------------
788 -- Bad_Predicated_Subtype_Use --
789 --------------------------------
791 procedure Bad_Predicated_Subtype_Use
795 Suggest_Static
: Boolean := False)
800 -- Avoid cascaded errors
802 if Error_Posted
(N
) then
806 if Inside_A_Generic
then
807 Gen
:= Current_Scope
;
808 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
816 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
817 Set_No_Predicate_On_Actual
(Typ
);
820 elsif Has_Predicates
(Typ
) then
821 if Is_Generic_Actual_Type
(Typ
) then
823 -- The restriction on loop parameters is only that the type
824 -- should have no dynamic predicates.
826 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
827 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
828 and then Is_OK_Static_Subtype
(Typ
)
833 Gen
:= Current_Scope
;
834 while not Is_Generic_Instance
(Gen
) loop
838 pragma Assert
(Present
(Gen
));
840 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
841 Error_Msg_Warn
:= SPARK_Mode
/= On
;
842 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
843 Error_Msg_F
("\Program_Error [<<", N
);
846 Make_Raise_Program_Error
(Sloc
(N
),
847 Reason
=> PE_Bad_Predicated_Generic_Type
));
850 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
854 Error_Msg_FE
(Msg
, N
, Typ
);
857 -- Emit an optional suggestion on how to remedy the error if the
858 -- context warrants it.
860 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
861 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
864 end Bad_Predicated_Subtype_Use
;
866 -----------------------------------------
867 -- Bad_Unordered_Enumeration_Reference --
868 -----------------------------------------
870 function Bad_Unordered_Enumeration_Reference
872 T
: Entity_Id
) return Boolean
875 return Is_Enumeration_Type
(T
)
876 and then Warn_On_Unordered_Enumeration_Type
877 and then not Is_Generic_Type
(T
)
878 and then Comes_From_Source
(N
)
879 and then not Has_Pragma_Ordered
(T
)
880 and then not In_Same_Extended_Unit
(N
, T
);
881 end Bad_Unordered_Enumeration_Reference
;
883 --------------------------
884 -- Build_Actual_Subtype --
885 --------------------------
887 function Build_Actual_Subtype
889 N
: Node_Or_Entity_Id
) return Node_Id
892 -- Normally Sloc (N), but may point to corresponding body in some cases
894 Constraints
: List_Id
;
900 Disc_Type
: Entity_Id
;
906 if Nkind
(N
) = N_Defining_Identifier
then
907 Obj
:= New_Occurrence_Of
(N
, Loc
);
909 -- If this is a formal parameter of a subprogram declaration, and
910 -- we are compiling the body, we want the declaration for the
911 -- actual subtype to carry the source position of the body, to
912 -- prevent anomalies in gdb when stepping through the code.
914 if Is_Formal
(N
) then
916 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
918 if Nkind
(Decl
) = N_Subprogram_Declaration
919 and then Present
(Corresponding_Body
(Decl
))
921 Loc
:= Sloc
(Corresponding_Body
(Decl
));
930 if Is_Array_Type
(T
) then
931 Constraints
:= New_List
;
932 for J
in 1 .. Number_Dimensions
(T
) loop
934 -- Build an array subtype declaration with the nominal subtype and
935 -- the bounds of the actual. Add the declaration in front of the
936 -- local declarations for the subprogram, for analysis before any
937 -- reference to the formal in the body.
940 Make_Attribute_Reference
(Loc
,
942 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
943 Attribute_Name
=> Name_First
,
944 Expressions
=> New_List
(
945 Make_Integer_Literal
(Loc
, J
)));
948 Make_Attribute_Reference
(Loc
,
950 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
951 Attribute_Name
=> Name_Last
,
952 Expressions
=> New_List
(
953 Make_Integer_Literal
(Loc
, J
)));
955 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
958 -- If the type has unknown discriminants there is no constrained
959 -- subtype to build. This is never called for a formal or for a
960 -- lhs, so returning the type is ok ???
962 elsif Has_Unknown_Discriminants
(T
) then
966 Constraints
:= New_List
;
968 -- Type T is a generic derived type, inherit the discriminants from
971 if Is_Private_Type
(T
)
972 and then No
(Full_View
(T
))
974 -- T was flagged as an error if it was declared as a formal
975 -- derived type with known discriminants. In this case there
976 -- is no need to look at the parent type since T already carries
977 -- its own discriminants.
979 and then not Error_Posted
(T
)
981 Disc_Type
:= Etype
(Base_Type
(T
));
986 Discr
:= First_Discriminant
(Disc_Type
);
987 while Present
(Discr
) loop
988 Append_To
(Constraints
,
989 Make_Selected_Component
(Loc
,
991 Duplicate_Subexpr_No_Checks
(Obj
),
992 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
993 Next_Discriminant
(Discr
);
997 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
998 Set_Is_Internal
(Subt
);
1001 Make_Subtype_Declaration
(Loc
,
1002 Defining_Identifier
=> Subt
,
1003 Subtype_Indication
=>
1004 Make_Subtype_Indication
(Loc
,
1005 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1007 Make_Index_Or_Discriminant_Constraint
(Loc
,
1008 Constraints
=> Constraints
)));
1010 Mark_Rewrite_Insertion
(Decl
);
1012 end Build_Actual_Subtype
;
1014 ---------------------------------------
1015 -- Build_Actual_Subtype_Of_Component --
1016 ---------------------------------------
1018 function Build_Actual_Subtype_Of_Component
1020 N
: Node_Id
) return Node_Id
1022 Loc
: constant Source_Ptr
:= Sloc
(N
);
1023 P
: constant Node_Id
:= Prefix
(N
);
1026 Index_Typ
: Entity_Id
;
1028 Desig_Typ
: Entity_Id
;
1029 -- This is either a copy of T, or if T is an access type, then it is
1030 -- the directly designated type of this access type.
1032 function Build_Actual_Array_Constraint
return List_Id
;
1033 -- If one or more of the bounds of the component depends on
1034 -- discriminants, build actual constraint using the discriminants
1037 function Build_Actual_Record_Constraint
return List_Id
;
1038 -- Similar to previous one, for discriminated components constrained
1039 -- by the discriminant of the enclosing object.
1041 -----------------------------------
1042 -- Build_Actual_Array_Constraint --
1043 -----------------------------------
1045 function Build_Actual_Array_Constraint
return List_Id
is
1046 Constraints
: constant List_Id
:= New_List
;
1054 Indx
:= First_Index
(Desig_Typ
);
1055 while Present
(Indx
) loop
1056 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1057 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1059 if Denotes_Discriminant
(Old_Lo
) then
1061 Make_Selected_Component
(Loc
,
1062 Prefix
=> New_Copy_Tree
(P
),
1063 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1066 Lo
:= New_Copy_Tree
(Old_Lo
);
1068 -- The new bound will be reanalyzed in the enclosing
1069 -- declaration. For literal bounds that come from a type
1070 -- declaration, the type of the context must be imposed, so
1071 -- insure that analysis will take place. For non-universal
1072 -- types this is not strictly necessary.
1074 Set_Analyzed
(Lo
, False);
1077 if Denotes_Discriminant
(Old_Hi
) then
1079 Make_Selected_Component
(Loc
,
1080 Prefix
=> New_Copy_Tree
(P
),
1081 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1084 Hi
:= New_Copy_Tree
(Old_Hi
);
1085 Set_Analyzed
(Hi
, False);
1088 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1093 end Build_Actual_Array_Constraint
;
1095 ------------------------------------
1096 -- Build_Actual_Record_Constraint --
1097 ------------------------------------
1099 function Build_Actual_Record_Constraint
return List_Id
is
1100 Constraints
: constant List_Id
:= New_List
;
1105 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1106 while Present
(D
) loop
1107 if Denotes_Discriminant
(Node
(D
)) then
1108 D_Val
:= Make_Selected_Component
(Loc
,
1109 Prefix
=> New_Copy_Tree
(P
),
1110 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1113 D_Val
:= New_Copy_Tree
(Node
(D
));
1116 Append
(D_Val
, Constraints
);
1121 end Build_Actual_Record_Constraint
;
1123 -- Start of processing for Build_Actual_Subtype_Of_Component
1126 -- Why the test for Spec_Expression mode here???
1128 if In_Spec_Expression
then
1131 -- More comments for the rest of this body would be good ???
1133 elsif Nkind
(N
) = N_Explicit_Dereference
then
1134 if Is_Composite_Type
(T
)
1135 and then not Is_Constrained
(T
)
1136 and then not (Is_Class_Wide_Type
(T
)
1137 and then Is_Constrained
(Root_Type
(T
)))
1138 and then not Has_Unknown_Discriminants
(T
)
1140 -- If the type of the dereference is already constrained, it is an
1143 if Is_Array_Type
(Etype
(N
))
1144 and then Is_Constrained
(Etype
(N
))
1148 Remove_Side_Effects
(P
);
1149 return Build_Actual_Subtype
(T
, N
);
1156 if Ekind
(T
) = E_Access_Subtype
then
1157 Desig_Typ
:= Designated_Type
(T
);
1162 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1163 Id
:= First_Index
(Desig_Typ
);
1164 while Present
(Id
) loop
1165 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1167 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1169 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1171 Remove_Side_Effects
(P
);
1173 Build_Component_Subtype
1174 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1180 elsif Is_Composite_Type
(Desig_Typ
)
1181 and then Has_Discriminants
(Desig_Typ
)
1182 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1184 if Is_Private_Type
(Desig_Typ
)
1185 and then No
(Discriminant_Constraint
(Desig_Typ
))
1187 Desig_Typ
:= Full_View
(Desig_Typ
);
1190 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1191 while Present
(D
) loop
1192 if Denotes_Discriminant
(Node
(D
)) then
1193 Remove_Side_Effects
(P
);
1195 Build_Component_Subtype
(
1196 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1203 -- If none of the above, the actual and nominal subtypes are the same
1206 end Build_Actual_Subtype_Of_Component
;
1208 -----------------------------
1209 -- Build_Component_Subtype --
1210 -----------------------------
1212 function Build_Component_Subtype
1215 T
: Entity_Id
) return Node_Id
1221 -- Unchecked_Union components do not require component subtypes
1223 if Is_Unchecked_Union
(T
) then
1227 Subt
:= Make_Temporary
(Loc
, 'S');
1228 Set_Is_Internal
(Subt
);
1231 Make_Subtype_Declaration
(Loc
,
1232 Defining_Identifier
=> Subt
,
1233 Subtype_Indication
=>
1234 Make_Subtype_Indication
(Loc
,
1235 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1237 Make_Index_Or_Discriminant_Constraint
(Loc
,
1238 Constraints
=> C
)));
1240 Mark_Rewrite_Insertion
(Decl
);
1242 end Build_Component_Subtype
;
1244 ----------------------------------
1245 -- Build_Default_Init_Cond_Call --
1246 ----------------------------------
1248 function Build_Default_Init_Cond_Call
1251 Typ
: Entity_Id
) return Node_Id
1253 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1254 Formal_Typ
: constant Entity_Id
:= Etype
(First_Formal
(Proc_Id
));
1258 Make_Procedure_Call_Statement
(Loc
,
1259 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
1260 Parameter_Associations
=> New_List
(
1261 Make_Unchecked_Type_Conversion
(Loc
,
1262 Subtype_Mark
=> New_Occurrence_Of
(Formal_Typ
, Loc
),
1263 Expression
=> New_Occurrence_Of
(Obj_Id
, Loc
))));
1264 end Build_Default_Init_Cond_Call
;
1266 ----------------------------------------------
1267 -- Build_Default_Init_Cond_Procedure_Bodies --
1268 ----------------------------------------------
1270 procedure Build_Default_Init_Cond_Procedure_Bodies
(Priv_Decls
: List_Id
) is
1271 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
);
1272 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1273 -- body of the procedure which verifies the assumption of the pragma at
1274 -- run time. The generated body is added after the type declaration.
1276 --------------------------------------------
1277 -- Build_Default_Init_Cond_Procedure_Body --
1278 --------------------------------------------
1280 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
) is
1281 Param_Id
: Entity_Id
;
1282 -- The entity of the sole formal parameter of the default initial
1283 -- condition procedure.
1285 procedure Replace_Type_Reference
(N
: Node_Id
);
1286 -- Replace a single reference to type Typ with a reference to formal
1287 -- parameter Param_Id.
1289 ----------------------------
1290 -- Replace_Type_Reference --
1291 ----------------------------
1293 procedure Replace_Type_Reference
(N
: Node_Id
) is
1295 Rewrite
(N
, New_Occurrence_Of
(Param_Id
, Sloc
(N
)));
1296 end Replace_Type_Reference
;
1298 procedure Replace_Type_References
is
1299 new Replace_Type_References_Generic
(Replace_Type_Reference
);
1303 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1304 Prag
: constant Node_Id
:=
1305 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1306 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1307 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Proc_Id
);
1308 Body_Decl
: Node_Id
;
1312 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1315 -- The procedure should be generated only for [sub]types subject to
1316 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1317 -- not get this specialized procedure.
1319 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1320 pragma Assert
(Present
(Prag
));
1321 pragma Assert
(Present
(Proc_Id
));
1323 -- Nothing to do if the body was already built
1325 if Present
(Corresponding_Body
(Spec_Decl
)) then
1329 Param_Id
:= First_Formal
(Proc_Id
);
1331 -- The pragma has an argument. Note that the argument is analyzed
1332 -- after all references to the current instance of the type are
1335 if Present
(Pragma_Argument_Associations
(Prag
)) then
1337 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
1339 if Nkind
(Expr
) = N_Null
then
1340 Stmt
:= Make_Null_Statement
(Loc
);
1342 -- Preserve the original argument of the pragma by replicating it.
1343 -- Replace all references to the current instance of the type with
1344 -- references to the formal parameter.
1347 Expr
:= New_Copy_Tree
(Expr
);
1348 Replace_Type_References
(Expr
, Typ
);
1351 -- pragma Check (Default_Initial_Condition, <Expr>);
1355 Pragma_Identifier
=>
1356 Make_Identifier
(Loc
, Name_Check
),
1358 Pragma_Argument_Associations
=> New_List
(
1359 Make_Pragma_Argument_Association
(Loc
,
1361 Make_Identifier
(Loc
,
1362 Chars
=> Name_Default_Initial_Condition
)),
1363 Make_Pragma_Argument_Association
(Loc
,
1364 Expression
=> Expr
)));
1367 -- Otherwise the pragma appears without an argument
1370 Stmt
:= Make_Null_Statement
(Loc
);
1374 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1377 -- end <Typ>Default_Init_Cond;
1380 Make_Subprogram_Body
(Loc
,
1382 Copy_Separate_Tree
(Specification
(Spec_Decl
)),
1383 Declarations
=> Empty_List
,
1384 Handled_Statement_Sequence
=>
1385 Make_Handled_Sequence_Of_Statements
(Loc
,
1386 Statements
=> New_List
(Stmt
)));
1388 -- Link the spec and body of the default initial condition procedure
1389 -- to prevent the generation of a duplicate body.
1391 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
1392 Set_Corresponding_Spec
(Body_Decl
, Proc_Id
);
1394 Insert_After_And_Analyze
(Declaration_Node
(Typ
), Body_Decl
);
1395 end Build_Default_Init_Cond_Procedure_Body
;
1402 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1405 -- Inspect the private declarations looking for [sub]type declarations
1407 Decl
:= First
(Priv_Decls
);
1408 while Present
(Decl
) loop
1409 if Nkind_In
(Decl
, N_Full_Type_Declaration
,
1410 N_Subtype_Declaration
)
1412 Typ
:= Defining_Entity
(Decl
);
1414 -- Guard against partially decorate types due to previous errors
1416 if Is_Type
(Typ
) then
1418 -- If the type is subject to pragma Default_Initial_Condition,
1419 -- generate the body of the internal procedure which verifies
1420 -- the assertion of the pragma at run time.
1422 if Has_Default_Init_Cond
(Typ
) then
1423 Build_Default_Init_Cond_Procedure_Body
(Typ
);
1425 -- A derived type inherits the default initial condition
1426 -- procedure from its parent type.
1428 elsif Has_Inherited_Default_Init_Cond
(Typ
) then
1429 Inherit_Default_Init_Cond_Procedure
(Typ
);
1436 end Build_Default_Init_Cond_Procedure_Bodies
;
1438 ---------------------------------------------------
1439 -- Build_Default_Init_Cond_Procedure_Declaration --
1440 ---------------------------------------------------
1442 procedure Build_Default_Init_Cond_Procedure_Declaration
(Typ
: Entity_Id
) is
1443 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1444 Prag
: constant Node_Id
:=
1445 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1446 Proc_Id
: Entity_Id
;
1449 -- The procedure should be generated only for types subject to pragma
1450 -- Default_Initial_Condition. Types that inherit the pragma do not get
1451 -- this specialized procedure.
1453 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1454 pragma Assert
(Present
(Prag
));
1456 -- Nothing to do if default initial condition procedure already built
1458 if Present
(Default_Init_Cond_Procedure
(Typ
)) then
1463 Make_Defining_Identifier
(Loc
,
1464 Chars
=> New_External_Name
(Chars
(Typ
), "Default_Init_Cond"));
1466 -- Associate default initial condition procedure with the private type
1468 Set_Ekind
(Proc_Id
, E_Procedure
);
1469 Set_Is_Default_Init_Cond_Procedure
(Proc_Id
);
1470 Set_Default_Init_Cond_Procedure
(Typ
, Proc_Id
);
1473 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1475 Insert_After_And_Analyze
(Prag
,
1476 Make_Subprogram_Declaration
(Loc
,
1478 Make_Procedure_Specification
(Loc
,
1479 Defining_Unit_Name
=> Proc_Id
,
1480 Parameter_Specifications
=> New_List
(
1481 Make_Parameter_Specification
(Loc
,
1482 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
1483 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))))));
1484 end Build_Default_Init_Cond_Procedure_Declaration
;
1486 ---------------------------
1487 -- Build_Default_Subtype --
1488 ---------------------------
1490 function Build_Default_Subtype
1492 N
: Node_Id
) return Entity_Id
1494 Loc
: constant Source_Ptr
:= Sloc
(N
);
1498 -- The base type that is to be constrained by the defaults
1501 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1505 Bas
:= Base_Type
(T
);
1507 -- If T is non-private but its base type is private, this is the
1508 -- completion of a subtype declaration whose parent type is private
1509 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1510 -- are to be found in the full view of the base. Check that the private
1511 -- status of T and its base differ.
1513 if Is_Private_Type
(Bas
)
1514 and then not Is_Private_Type
(T
)
1515 and then Present
(Full_View
(Bas
))
1517 Bas
:= Full_View
(Bas
);
1520 Disc
:= First_Discriminant
(T
);
1522 if No
(Discriminant_Default_Value
(Disc
)) then
1527 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1528 Constraints
: constant List_Id
:= New_List
;
1532 while Present
(Disc
) loop
1533 Append_To
(Constraints
,
1534 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1535 Next_Discriminant
(Disc
);
1539 Make_Subtype_Declaration
(Loc
,
1540 Defining_Identifier
=> Act
,
1541 Subtype_Indication
=>
1542 Make_Subtype_Indication
(Loc
,
1543 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1545 Make_Index_Or_Discriminant_Constraint
(Loc
,
1546 Constraints
=> Constraints
)));
1548 Insert_Action
(N
, Decl
);
1552 end Build_Default_Subtype
;
1554 --------------------------------------------
1555 -- Build_Discriminal_Subtype_Of_Component --
1556 --------------------------------------------
1558 function Build_Discriminal_Subtype_Of_Component
1559 (T
: Entity_Id
) return Node_Id
1561 Loc
: constant Source_Ptr
:= Sloc
(T
);
1565 function Build_Discriminal_Array_Constraint
return List_Id
;
1566 -- If one or more of the bounds of the component depends on
1567 -- discriminants, build actual constraint using the discriminants
1570 function Build_Discriminal_Record_Constraint
return List_Id
;
1571 -- Similar to previous one, for discriminated components constrained by
1572 -- the discriminant of the enclosing object.
1574 ----------------------------------------
1575 -- Build_Discriminal_Array_Constraint --
1576 ----------------------------------------
1578 function Build_Discriminal_Array_Constraint
return List_Id
is
1579 Constraints
: constant List_Id
:= New_List
;
1587 Indx
:= First_Index
(T
);
1588 while Present
(Indx
) loop
1589 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1590 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1592 if Denotes_Discriminant
(Old_Lo
) then
1593 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1596 Lo
:= New_Copy_Tree
(Old_Lo
);
1599 if Denotes_Discriminant
(Old_Hi
) then
1600 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1603 Hi
:= New_Copy_Tree
(Old_Hi
);
1606 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1611 end Build_Discriminal_Array_Constraint
;
1613 -----------------------------------------
1614 -- Build_Discriminal_Record_Constraint --
1615 -----------------------------------------
1617 function Build_Discriminal_Record_Constraint
return List_Id
is
1618 Constraints
: constant List_Id
:= New_List
;
1623 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1624 while Present
(D
) loop
1625 if Denotes_Discriminant
(Node
(D
)) then
1627 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1629 D_Val
:= New_Copy_Tree
(Node
(D
));
1632 Append
(D_Val
, Constraints
);
1637 end Build_Discriminal_Record_Constraint
;
1639 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1642 if Ekind
(T
) = E_Array_Subtype
then
1643 Id
:= First_Index
(T
);
1644 while Present
(Id
) loop
1645 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1647 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1649 return Build_Component_Subtype
1650 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1656 elsif Ekind
(T
) = E_Record_Subtype
1657 and then Has_Discriminants
(T
)
1658 and then not Has_Unknown_Discriminants
(T
)
1660 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1661 while Present
(D
) loop
1662 if Denotes_Discriminant
(Node
(D
)) then
1663 return Build_Component_Subtype
1664 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1671 -- If none of the above, the actual and nominal subtypes are the same
1674 end Build_Discriminal_Subtype_Of_Component
;
1676 ------------------------------
1677 -- Build_Elaboration_Entity --
1678 ------------------------------
1680 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1681 Loc
: constant Source_Ptr
:= Sloc
(N
);
1683 Elab_Ent
: Entity_Id
;
1685 procedure Set_Package_Name
(Ent
: Entity_Id
);
1686 -- Given an entity, sets the fully qualified name of the entity in
1687 -- Name_Buffer, with components separated by double underscores. This
1688 -- is a recursive routine that climbs the scope chain to Standard.
1690 ----------------------
1691 -- Set_Package_Name --
1692 ----------------------
1694 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1696 if Scope
(Ent
) /= Standard_Standard
then
1697 Set_Package_Name
(Scope
(Ent
));
1700 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1702 Name_Buffer
(Name_Len
+ 1) := '_';
1703 Name_Buffer
(Name_Len
+ 2) := '_';
1704 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1705 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1709 Get_Name_String
(Chars
(Ent
));
1711 end Set_Package_Name
;
1713 -- Start of processing for Build_Elaboration_Entity
1716 -- Ignore call if already constructed
1718 if Present
(Elaboration_Entity
(Spec_Id
)) then
1721 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1722 -- no role in analysis.
1724 elsif ASIS_Mode
then
1727 -- See if we need elaboration entity. We always need it for the dynamic
1728 -- elaboration model, since it is needed to properly generate the PE
1729 -- exception for access before elaboration.
1731 elsif Dynamic_Elaboration_Checks
then
1734 -- For the static model, we don't need the elaboration counter if this
1735 -- unit is sure to have no elaboration code, since that means there
1736 -- is no elaboration unit to be called. Note that we can't just decide
1737 -- after the fact by looking to see whether there was elaboration code,
1738 -- because that's too late to make this decision.
1740 elsif Restriction_Active
(No_Elaboration_Code
) then
1743 -- Similarly, for the static model, we can skip the elaboration counter
1744 -- if we have the No_Multiple_Elaboration restriction, since for the
1745 -- static model, that's the only purpose of the counter (to avoid
1746 -- multiple elaboration).
1748 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1752 -- Here we need the elaboration entity
1754 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1755 -- name with dots replaced by double underscore. We have to manually
1756 -- construct this name, since it will be elaborated in the outer scope,
1757 -- and thus will not have the unit name automatically prepended.
1759 Set_Package_Name
(Spec_Id
);
1760 Add_Str_To_Name_Buffer
("_E");
1762 -- Create elaboration counter
1764 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1765 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1768 Make_Object_Declaration
(Loc
,
1769 Defining_Identifier
=> Elab_Ent
,
1770 Object_Definition
=>
1771 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1772 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1774 Push_Scope
(Standard_Standard
);
1775 Add_Global_Declaration
(Decl
);
1778 -- Reset True_Constant indication, since we will indeed assign a value
1779 -- to the variable in the binder main. We also kill the Current_Value
1780 -- and Last_Assignment fields for the same reason.
1782 Set_Is_True_Constant
(Elab_Ent
, False);
1783 Set_Current_Value
(Elab_Ent
, Empty
);
1784 Set_Last_Assignment
(Elab_Ent
, Empty
);
1786 -- We do not want any further qualification of the name (if we did not
1787 -- do this, we would pick up the name of the generic package in the case
1788 -- of a library level generic instantiation).
1790 Set_Has_Qualified_Name
(Elab_Ent
);
1791 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1792 end Build_Elaboration_Entity
;
1794 --------------------------------
1795 -- Build_Explicit_Dereference --
1796 --------------------------------
1798 procedure Build_Explicit_Dereference
1802 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1805 -- An entity of a type with a reference aspect is overloaded with
1806 -- both interpretations: with and without the dereference. Now that
1807 -- the dereference is made explicit, set the type of the node properly,
1808 -- to prevent anomalies in the backend. Same if the expression is an
1809 -- overloaded function call whose return type has a reference aspect.
1811 if Is_Entity_Name
(Expr
) then
1812 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1814 elsif Nkind
(Expr
) = N_Function_Call
then
1815 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1818 Set_Is_Overloaded
(Expr
, False);
1820 -- The expression will often be a generalized indexing that yields a
1821 -- container element that is then dereferenced, in which case the
1822 -- generalized indexing call is also non-overloaded.
1824 if Nkind
(Expr
) = N_Indexed_Component
1825 and then Present
(Generalized_Indexing
(Expr
))
1827 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1831 Make_Explicit_Dereference
(Loc
,
1833 Make_Selected_Component
(Loc
,
1834 Prefix
=> Relocate_Node
(Expr
),
1835 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1836 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1837 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1838 end Build_Explicit_Dereference
;
1840 -----------------------------------
1841 -- Cannot_Raise_Constraint_Error --
1842 -----------------------------------
1844 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1846 if Compile_Time_Known_Value
(Expr
) then
1849 elsif Do_Range_Check
(Expr
) then
1852 elsif Raises_Constraint_Error
(Expr
) then
1856 case Nkind
(Expr
) is
1857 when N_Identifier
=>
1860 when N_Expanded_Name
=>
1863 when N_Selected_Component
=>
1864 return not Do_Discriminant_Check
(Expr
);
1866 when N_Attribute_Reference
=>
1867 if Do_Overflow_Check
(Expr
) then
1870 elsif No
(Expressions
(Expr
)) then
1878 N
:= First
(Expressions
(Expr
));
1879 while Present
(N
) loop
1880 if Cannot_Raise_Constraint_Error
(N
) then
1891 when N_Type_Conversion
=>
1892 if Do_Overflow_Check
(Expr
)
1893 or else Do_Length_Check
(Expr
)
1894 or else Do_Tag_Check
(Expr
)
1898 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1901 when N_Unchecked_Type_Conversion
=>
1902 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1905 if Do_Overflow_Check
(Expr
) then
1908 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1915 if Do_Division_Check
(Expr
)
1917 Do_Overflow_Check
(Expr
)
1922 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1924 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1943 N_Op_Shift_Right_Arithmetic |
1947 if Do_Overflow_Check
(Expr
) then
1951 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1953 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1960 end Cannot_Raise_Constraint_Error
;
1962 -----------------------------------------
1963 -- Check_Dynamically_Tagged_Expression --
1964 -----------------------------------------
1966 procedure Check_Dynamically_Tagged_Expression
1969 Related_Nod
: Node_Id
)
1972 pragma Assert
(Is_Tagged_Type
(Typ
));
1974 -- In order to avoid spurious errors when analyzing the expanded code,
1975 -- this check is done only for nodes that come from source and for
1976 -- actuals of generic instantiations.
1978 if (Comes_From_Source
(Related_Nod
)
1979 or else In_Generic_Actual
(Expr
))
1980 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1981 or else Is_Dynamically_Tagged
(Expr
))
1982 and then Is_Tagged_Type
(Typ
)
1983 and then not Is_Class_Wide_Type
(Typ
)
1985 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1987 end Check_Dynamically_Tagged_Expression
;
1989 --------------------------
1990 -- Check_Fully_Declared --
1991 --------------------------
1993 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1995 if Ekind
(T
) = E_Incomplete_Type
then
1997 -- Ada 2005 (AI-50217): If the type is available through a limited
1998 -- with_clause, verify that its full view has been analyzed.
2000 if From_Limited_With
(T
)
2001 and then Present
(Non_Limited_View
(T
))
2002 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2004 -- The non-limited view is fully declared
2010 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2013 -- Need comments for these tests ???
2015 elsif Has_Private_Component
(T
)
2016 and then not Is_Generic_Type
(Root_Type
(T
))
2017 and then not In_Spec_Expression
2019 -- Special case: if T is the anonymous type created for a single
2020 -- task or protected object, use the name of the source object.
2022 if Is_Concurrent_Type
(T
)
2023 and then not Comes_From_Source
(T
)
2024 and then Nkind
(N
) = N_Object_Declaration
2027 ("type of& has incomplete component",
2028 N
, Defining_Identifier
(N
));
2031 ("premature usage of incomplete}",
2032 N
, First_Subtype
(T
));
2035 end Check_Fully_Declared
;
2037 -------------------------------------
2038 -- Check_Function_Writable_Actuals --
2039 -------------------------------------
2041 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2042 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2043 Identifiers_List
: Elist_Id
:= No_Elist
;
2044 Error_Node
: Node_Id
:= Empty
;
2046 procedure Collect_Identifiers
(N
: Node_Id
);
2047 -- In a single traversal of subtree N collect in Writable_Actuals_List
2048 -- all the actuals of functions with writable actuals, and in the list
2049 -- Identifiers_List collect all the identifiers that are not actuals of
2050 -- functions with writable actuals. If a writable actual is referenced
2051 -- twice as writable actual then Error_Node is set to reference its
2052 -- second occurrence, the error is reported, and the tree traversal
2055 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
2056 -- Return the entity associated with the function call
2058 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2059 -- Preanalyze N without reporting errors. Very dubious, you can't just
2060 -- go analyzing things more than once???
2062 -------------------------
2063 -- Collect_Identifiers --
2064 -------------------------
2066 procedure Collect_Identifiers
(N
: Node_Id
) is
2068 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2069 -- Process a single node during the tree traversal to collect the
2070 -- writable actuals of functions and all the identifiers which are
2071 -- not writable actuals of functions.
2073 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2074 -- Returns True if List has a node whose Entity is Entity (N)
2076 -------------------------
2077 -- Check_Function_Call --
2078 -------------------------
2080 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2081 Is_Writable_Actual
: Boolean := False;
2085 if Nkind
(N
) = N_Identifier
then
2087 -- No analysis possible if the entity is not decorated
2089 if No
(Entity
(N
)) then
2092 -- Don't collect identifiers of packages, called functions, etc
2094 elsif Ekind_In
(Entity
(N
), E_Package
,
2101 -- Analyze if N is a writable actual of a function
2103 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2105 Call
: constant Node_Id
:= Parent
(N
);
2110 Id
:= Get_Function_Id
(Call
);
2112 -- In case of previous error, no check is possible
2118 Formal
:= First_Formal
(Id
);
2119 Actual
:= First_Actual
(Call
);
2120 while Present
(Actual
) and then Present
(Formal
) loop
2122 if Ekind_In
(Formal
, E_Out_Parameter
,
2125 Is_Writable_Actual
:= True;
2131 Next_Formal
(Formal
);
2132 Next_Actual
(Actual
);
2137 if Is_Writable_Actual
then
2138 if Contains
(Writable_Actuals_List
, N
) then
2140 ("value may be affected by call to& "
2141 & "because order of evaluation is arbitrary", N
, Id
);
2146 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2149 if Identifiers_List
= No_Elist
then
2150 Identifiers_List
:= New_Elmt_List
;
2153 Append_Unique_Elmt
(N
, Identifiers_List
);
2166 N
: Node_Id
) return Boolean
2168 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2173 if List
= No_Elist
then
2177 Elmt
:= First_Elmt
(List
);
2178 while Present
(Elmt
) loop
2179 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2193 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2194 -- The traversal procedure
2196 -- Start of processing for Collect_Identifiers
2199 if Present
(Error_Node
) then
2203 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2208 end Collect_Identifiers
;
2210 ---------------------
2211 -- Get_Function_Id --
2212 ---------------------
2214 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
2215 Nam
: constant Node_Id
:= Name
(Call
);
2219 if Nkind
(Nam
) = N_Explicit_Dereference
then
2221 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
2223 elsif Nkind
(Nam
) = N_Selected_Component
then
2224 Id
:= Entity
(Selector_Name
(Nam
));
2226 elsif Nkind
(Nam
) = N_Indexed_Component
then
2227 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
2234 end Get_Function_Id
;
2236 ---------------------------
2237 -- Preanalyze_Expression --
2238 ---------------------------
2240 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2241 Status
: constant Boolean := Get_Ignore_Errors
;
2243 Set_Ignore_Errors
(True);
2245 Set_Ignore_Errors
(Status
);
2246 end Preanalyze_Without_Errors
;
2248 -- Start of processing for Check_Function_Writable_Actuals
2251 -- The check only applies to Ada 2012 code, and only to constructs that
2252 -- have multiple constituents whose order of evaluation is not specified
2255 if Ada_Version
< Ada_2012
2256 or else (not (Nkind
(N
) in N_Op
)
2257 and then not (Nkind
(N
) in N_Membership_Test
)
2258 and then not Nkind_In
(N
, N_Range
,
2260 N_Extension_Aggregate
,
2261 N_Full_Type_Declaration
,
2263 N_Procedure_Call_Statement
,
2264 N_Entry_Call_Statement
))
2265 or else (Nkind
(N
) = N_Full_Type_Declaration
2266 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2268 -- In addition, this check only applies to source code, not to code
2269 -- generated by constraint checks.
2271 or else not Comes_From_Source
(N
)
2276 -- If a construct C has two or more direct constituents that are names
2277 -- or expressions whose evaluation may occur in an arbitrary order, at
2278 -- least one of which contains a function call with an in out or out
2279 -- parameter, then the construct is legal only if: for each name N that
2280 -- is passed as a parameter of mode in out or out to some inner function
2281 -- call C2 (not including the construct C itself), there is no other
2282 -- name anywhere within a direct constituent of the construct C other
2283 -- than the one containing C2, that is known to refer to the same
2284 -- object (RM 6.4.1(6.17/3)).
2288 Collect_Identifiers
(Low_Bound
(N
));
2289 Collect_Identifiers
(High_Bound
(N
));
2291 when N_Op | N_Membership_Test
=>
2296 Collect_Identifiers
(Left_Opnd
(N
));
2298 if Present
(Right_Opnd
(N
)) then
2299 Collect_Identifiers
(Right_Opnd
(N
));
2302 if Nkind_In
(N
, N_In
, N_Not_In
)
2303 and then Present
(Alternatives
(N
))
2305 Expr
:= First
(Alternatives
(N
));
2306 while Present
(Expr
) loop
2307 Collect_Identifiers
(Expr
);
2314 when N_Full_Type_Declaration
=>
2316 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2317 -- Return the record part of this record type definition
2319 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2320 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2322 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2323 return Record_Extension_Part
(Type_Def
);
2327 end Get_Record_Part
;
2330 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2331 Rec
: Node_Id
:= Get_Record_Part
(N
);
2334 -- No need to perform any analysis if the record has no
2337 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2341 -- Collect the identifiers starting from the deepest
2342 -- derivation. Done to report the error in the deepest
2346 if Present
(Component_List
(Rec
)) then
2347 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2348 while Present
(Comp
) loop
2349 if Nkind
(Comp
) = N_Component_Declaration
2350 and then Present
(Expression
(Comp
))
2352 Collect_Identifiers
(Expression
(Comp
));
2359 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2360 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2363 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2364 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2368 when N_Subprogram_Call |
2369 N_Entry_Call_Statement
=>
2371 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
2376 Formal
:= First_Formal
(Id
);
2377 Actual
:= First_Actual
(N
);
2378 while Present
(Actual
) and then Present
(Formal
) loop
2379 if Ekind_In
(Formal
, E_Out_Parameter
,
2382 Collect_Identifiers
(Actual
);
2385 Next_Formal
(Formal
);
2386 Next_Actual
(Actual
);
2391 N_Extension_Aggregate
=>
2395 Comp_Expr
: Node_Id
;
2398 -- Handle the N_Others_Choice of array aggregates with static
2399 -- bounds. There is no need to perform this analysis in
2400 -- aggregates without static bounds since we cannot evaluate
2401 -- if the N_Others_Choice covers several elements. There is
2402 -- no need to handle the N_Others choice of record aggregates
2403 -- since at this stage it has been already expanded by
2404 -- Resolve_Record_Aggregate.
2406 if Is_Array_Type
(Etype
(N
))
2407 and then Nkind
(N
) = N_Aggregate
2408 and then Present
(Aggregate_Bounds
(N
))
2409 and then Compile_Time_Known_Bounds
(Etype
(N
))
2410 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2412 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2415 Count_Components
: Uint
:= Uint_0
;
2416 Num_Components
: Uint
;
2417 Others_Assoc
: Node_Id
;
2418 Others_Choice
: Node_Id
:= Empty
;
2419 Others_Box_Present
: Boolean := False;
2422 -- Count positional associations
2424 if Present
(Expressions
(N
)) then
2425 Comp_Expr
:= First
(Expressions
(N
));
2426 while Present
(Comp_Expr
) loop
2427 Count_Components
:= Count_Components
+ 1;
2432 -- Count the rest of elements and locate the N_Others
2435 Assoc
:= First
(Component_Associations
(N
));
2436 while Present
(Assoc
) loop
2437 Choice
:= First
(Choices
(Assoc
));
2438 while Present
(Choice
) loop
2439 if Nkind
(Choice
) = N_Others_Choice
then
2440 Others_Assoc
:= Assoc
;
2441 Others_Choice
:= Choice
;
2442 Others_Box_Present
:= Box_Present
(Assoc
);
2444 -- Count several components
2446 elsif Nkind_In
(Choice
, N_Range
,
2447 N_Subtype_Indication
)
2448 or else (Is_Entity_Name
(Choice
)
2449 and then Is_Type
(Entity
(Choice
)))
2454 Get_Index_Bounds
(Choice
, L
, H
);
2456 (Compile_Time_Known_Value
(L
)
2457 and then Compile_Time_Known_Value
(H
));
2460 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2463 -- Count single component. No other case available
2464 -- since we are handling an aggregate with static
2468 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2469 or else Nkind
(Choice
) = N_Identifier
2470 or else Nkind
(Choice
) = N_Integer_Literal
);
2472 Count_Components
:= Count_Components
+ 1;
2482 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2483 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2485 pragma Assert
(Count_Components
<= Num_Components
);
2487 -- Handle the N_Others choice if it covers several
2490 if Present
(Others_Choice
)
2491 and then (Num_Components
- Count_Components
) > 1
2493 if not Others_Box_Present
then
2495 -- At this stage, if expansion is active, the
2496 -- expression of the others choice has not been
2497 -- analyzed. Hence we generate a duplicate and
2498 -- we analyze it silently to have available the
2499 -- minimum decoration required to collect the
2502 if not Expander_Active
then
2503 Comp_Expr
:= Expression
(Others_Assoc
);
2506 New_Copy_Tree
(Expression
(Others_Assoc
));
2507 Preanalyze_Without_Errors
(Comp_Expr
);
2510 Collect_Identifiers
(Comp_Expr
);
2512 if Writable_Actuals_List
/= No_Elist
then
2514 -- As suggested by Robert, at current stage we
2515 -- report occurrences of this case as warnings.
2518 ("writable function parameter may affect "
2519 & "value in other component because order "
2520 & "of evaluation is unspecified??",
2521 Node
(First_Elmt
(Writable_Actuals_List
)));
2528 -- Handle ancestor part of extension aggregates
2530 if Nkind
(N
) = N_Extension_Aggregate
then
2531 Collect_Identifiers
(Ancestor_Part
(N
));
2534 -- Handle positional associations
2536 if Present
(Expressions
(N
)) then
2537 Comp_Expr
:= First
(Expressions
(N
));
2538 while Present
(Comp_Expr
) loop
2539 if not Is_OK_Static_Expression
(Comp_Expr
) then
2540 Collect_Identifiers
(Comp_Expr
);
2547 -- Handle discrete associations
2549 if Present
(Component_Associations
(N
)) then
2550 Assoc
:= First
(Component_Associations
(N
));
2551 while Present
(Assoc
) loop
2553 if not Box_Present
(Assoc
) then
2554 Choice
:= First
(Choices
(Assoc
));
2555 while Present
(Choice
) loop
2557 -- For now we skip discriminants since it requires
2558 -- performing the analysis in two phases: first one
2559 -- analyzing discriminants and second one analyzing
2560 -- the rest of components since discriminants are
2561 -- evaluated prior to components: too much extra
2562 -- work to detect a corner case???
2564 if Nkind
(Choice
) in N_Has_Entity
2565 and then Present
(Entity
(Choice
))
2566 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2570 elsif Box_Present
(Assoc
) then
2574 if not Analyzed
(Expression
(Assoc
)) then
2576 New_Copy_Tree
(Expression
(Assoc
));
2577 Set_Parent
(Comp_Expr
, Parent
(N
));
2578 Preanalyze_Without_Errors
(Comp_Expr
);
2580 Comp_Expr
:= Expression
(Assoc
);
2583 Collect_Identifiers
(Comp_Expr
);
2599 -- No further action needed if we already reported an error
2601 if Present
(Error_Node
) then
2605 -- Check if some writable argument of a function is referenced
2607 if Writable_Actuals_List
/= No_Elist
2608 and then Identifiers_List
/= No_Elist
2615 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2616 while Present
(Elmt_1
) loop
2617 Elmt_2
:= First_Elmt
(Identifiers_List
);
2618 while Present
(Elmt_2
) loop
2619 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2620 case Nkind
(Parent
(Node
(Elmt_2
))) is
2622 N_Component_Association |
2623 N_Component_Declaration
=>
2625 ("value may be affected by call in other "
2626 & "component because they are evaluated "
2627 & "in unspecified order",
2630 when N_In | N_Not_In
=>
2632 ("value may be affected by call in other "
2633 & "alternative because they are evaluated "
2634 & "in unspecified order",
2639 ("value of actual may be affected by call in "
2640 & "other actual because they are evaluated "
2641 & "in unspecified order",
2653 end Check_Function_Writable_Actuals
;
2655 --------------------------------
2656 -- Check_Implicit_Dereference --
2657 --------------------------------
2659 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
2665 if Nkind
(N
) = N_Indexed_Component
2666 and then Present
(Generalized_Indexing
(N
))
2668 Nam
:= Generalized_Indexing
(N
);
2673 if Ada_Version
< Ada_2012
2674 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2678 elsif not Comes_From_Source
(N
)
2679 and then Nkind
(N
) /= N_Indexed_Component
2683 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2687 Disc
:= First_Discriminant
(Typ
);
2688 while Present
(Disc
) loop
2689 if Has_Implicit_Dereference
(Disc
) then
2690 Desig
:= Designated_Type
(Etype
(Disc
));
2691 Add_One_Interp
(Nam
, Disc
, Desig
);
2693 -- If the node is a generalized indexing, add interpretation
2694 -- to that node as well, for subsequent resolution.
2696 if Nkind
(N
) = N_Indexed_Component
then
2697 Add_One_Interp
(N
, Disc
, Desig
);
2700 -- If the operation comes from a generic unit and the context
2701 -- is a selected component, the selector name may be global
2702 -- and set in the instance already. Remove the entity to
2703 -- force resolution of the selected component, and the
2704 -- generation of an explicit dereference if needed.
2707 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
2709 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
2715 Next_Discriminant
(Disc
);
2718 end Check_Implicit_Dereference
;
2720 ----------------------------------
2721 -- Check_Internal_Protected_Use --
2722 ----------------------------------
2724 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2730 while Present
(S
) loop
2731 if S
= Standard_Standard
then
2734 elsif Ekind
(S
) = E_Function
2735 and then Ekind
(Scope
(S
)) = E_Protected_Type
2744 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2746 -- An indirect function call (e.g. a callback within a protected
2747 -- function body) is not statically illegal. If the access type is
2748 -- anonymous and is the type of an access parameter, the scope of Nam
2749 -- will be the protected type, but it is not a protected operation.
2751 if Ekind
(Nam
) = E_Subprogram_Type
2753 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2757 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2759 ("within protected function cannot use protected "
2760 & "procedure in renaming or as generic actual", N
);
2762 elsif Nkind
(N
) = N_Attribute_Reference
then
2764 ("within protected function cannot take access of "
2765 & " protected procedure", N
);
2769 ("within protected function, protected object is constant", N
);
2771 ("\cannot call operation that may modify it", N
);
2774 end Check_Internal_Protected_Use
;
2776 ---------------------------------------
2777 -- Check_Later_Vs_Basic_Declarations --
2778 ---------------------------------------
2780 procedure Check_Later_Vs_Basic_Declarations
2782 During_Parsing
: Boolean)
2784 Body_Sloc
: Source_Ptr
;
2787 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2788 -- Return whether Decl is considered as a declarative item.
2789 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2790 -- When During_Parsing is False, the semantics of SPARK is followed.
2792 -------------------------------
2793 -- Is_Later_Declarative_Item --
2794 -------------------------------
2796 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2798 if Nkind
(Decl
) in N_Later_Decl_Item
then
2801 elsif Nkind
(Decl
) = N_Pragma
then
2804 elsif During_Parsing
then
2807 -- In SPARK, a package declaration is not considered as a later
2808 -- declarative item.
2810 elsif Nkind
(Decl
) = N_Package_Declaration
then
2813 -- In SPARK, a renaming is considered as a later declarative item
2815 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2821 end Is_Later_Declarative_Item
;
2823 -- Start of Check_Later_Vs_Basic_Declarations
2826 Decl
:= First
(Decls
);
2828 -- Loop through sequence of basic declarative items
2830 Outer
: while Present
(Decl
) loop
2831 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2832 and then Nkind
(Decl
) not in N_Body_Stub
2836 -- Once a body is encountered, we only allow later declarative
2837 -- items. The inner loop checks the rest of the list.
2840 Body_Sloc
:= Sloc
(Decl
);
2842 Inner
: while Present
(Decl
) loop
2843 if not Is_Later_Declarative_Item
(Decl
) then
2844 if During_Parsing
then
2845 if Ada_Version
= Ada_83
then
2846 Error_Msg_Sloc
:= Body_Sloc
;
2848 ("(Ada 83) decl cannot appear after body#", Decl
);
2851 Error_Msg_Sloc
:= Body_Sloc
;
2852 Check_SPARK_05_Restriction
2853 ("decl cannot appear after body#", Decl
);
2861 end Check_Later_Vs_Basic_Declarations
;
2863 -------------------------
2864 -- Check_Nested_Access --
2865 -------------------------
2867 procedure Check_Nested_Access
(N
: Node_Id
; Ent
: Entity_Id
) is
2868 Scop
: constant Entity_Id
:= Current_Scope
;
2869 Current_Subp
: Entity_Id
;
2870 Enclosing
: Entity_Id
;
2873 -- Currently only enabled for VM back-ends for efficiency, should we
2874 -- enable it more systematically? Probably not unless someone actually
2875 -- needs it. It will be needed for C generation and is activated if the
2876 -- Opt.Unnest_Subprogram_Mode flag is set True.
2878 if (VM_Target
/= No_VM
or else Unnest_Subprogram_Mode
)
2879 and then Scope
(Ent
) /= Empty
2880 and then not Is_Library_Level_Entity
(Ent
)
2882 -- Comment the exclusion of imported entities ???
2884 and then not Is_Imported
(Ent
)
2886 -- For VM case, we are only interested in variables, constants,
2887 -- and loop parameters. For general nested procedure usage, we
2888 -- allow types as well.
2890 if Ekind_In
(Ent
, E_Variable
, E_Constant
, E_Loop_Parameter
) then
2892 elsif not (Unnest_Subprogram_Mode
and then Is_Type
(Ent
)) then
2896 -- Get current subprogram that is relevant
2898 if Is_Subprogram
(Scop
)
2899 or else Is_Generic_Subprogram
(Scop
)
2900 or else Is_Entry
(Scop
)
2902 Current_Subp
:= Scop
;
2904 Current_Subp
:= Current_Subprogram
;
2907 Enclosing
:= Enclosing_Subprogram
(Ent
);
2909 -- Set flag if uplevel reference
2911 if Enclosing
/= Empty
and then Enclosing
/= Current_Subp
then
2912 if Is_Type
(Ent
) then
2913 Check_Uplevel_Reference_To_Type
(Ent
);
2915 Set_Has_Uplevel_Reference
(Ent
, True);
2917 if Unnest_Subprogram_Mode
then
2918 Set_Has_Uplevel_Reference
(Current_Subp
, True);
2919 Note_Uplevel_Reference
(N
, Enclosing
);
2924 end Check_Nested_Access
;
2926 ---------------------------
2927 -- Check_No_Hidden_State --
2928 ---------------------------
2930 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2931 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2932 -- Determine whether the entity of a package denoted by Pkg has a null
2935 -----------------------------
2936 -- Has_Null_Abstract_State --
2937 -----------------------------
2939 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2940 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2943 -- Check first available state of related package. A null abstract
2944 -- state always appears as the sole element of the state list.
2948 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2949 end Has_Null_Abstract_State
;
2953 Context
: Entity_Id
:= Empty
;
2954 Not_Visible
: Boolean := False;
2957 -- Start of processing for Check_No_Hidden_State
2960 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2962 -- Find the proper context where the object or state appears
2965 while Present
(Scop
) loop
2968 -- Keep track of the context's visibility
2970 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2972 -- Prevent the search from going too far
2974 if Context
= Standard_Standard
then
2977 -- Objects and states that appear immediately within a subprogram or
2978 -- inside a construct nested within a subprogram do not introduce a
2979 -- hidden state. They behave as local variable declarations.
2981 elsif Is_Subprogram
(Context
) then
2984 -- When examining a package body, use the entity of the spec as it
2985 -- carries the abstract state declarations.
2987 elsif Ekind
(Context
) = E_Package_Body
then
2988 Context
:= Spec_Entity
(Context
);
2991 -- Stop the traversal when a package subject to a null abstract state
2994 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2995 and then Has_Null_Abstract_State
(Context
)
3000 Scop
:= Scope
(Scop
);
3003 -- At this point we know that there is at least one package with a null
3004 -- abstract state in visibility. Emit an error message unconditionally
3005 -- if the entity being processed is a state because the placement of the
3006 -- related package is irrelevant. This is not the case for objects as
3007 -- the intermediate context matters.
3009 if Present
(Context
)
3010 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
3012 Error_Msg_N
("cannot introduce hidden state &", Id
);
3013 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
3015 end Check_No_Hidden_State
;
3017 ------------------------------------------
3018 -- Check_Potentially_Blocking_Operation --
3019 ------------------------------------------
3021 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
3025 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3026 -- When pragma Detect_Blocking is active, the run time will raise
3027 -- Program_Error. Here we only issue a warning, since we generally
3028 -- support the use of potentially blocking operations in the absence
3031 -- Indirect blocking through a subprogram call cannot be diagnosed
3032 -- statically without interprocedural analysis, so we do not attempt
3035 S
:= Scope
(Current_Scope
);
3036 while Present
(S
) and then S
/= Standard_Standard
loop
3037 if Is_Protected_Type
(S
) then
3039 ("potentially blocking operation in protected operation??", N
);
3045 end Check_Potentially_Blocking_Operation
;
3047 ---------------------------------
3048 -- Check_Result_And_Post_State --
3049 ---------------------------------
3051 procedure Check_Result_And_Post_State
(Subp_Id
: Entity_Id
) is
3052 procedure Check_Result_And_Post_State_In_Pragma
3054 Result_Seen
: in out Boolean);
3055 -- Determine whether pragma Prag mentions attribute 'Result and whether
3056 -- the pragma contains an expression that evaluates differently in pre-
3057 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3058 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3060 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean;
3061 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3062 -- formal parameter.
3064 -------------------------------------------
3065 -- Check_Result_And_Post_State_In_Pragma --
3066 -------------------------------------------
3068 procedure Check_Result_And_Post_State_In_Pragma
3070 Result_Seen
: in out Boolean)
3072 procedure Check_Expression
(Expr
: Node_Id
);
3073 -- Perform the 'Result and post-state checks on a given expression
3075 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
3076 -- Attempt to find attribute 'Result in a subtree denoted by N
3078 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
3079 -- Determine whether source node N denotes "True" or "False"
3081 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
3082 -- Determine whether a subtree denoted by N mentions any construct
3083 -- that denotes a post-state.
3085 procedure Check_Function_Result
is
3086 new Traverse_Proc
(Is_Function_Result
);
3088 ----------------------
3089 -- Check_Expression --
3090 ----------------------
3092 procedure Check_Expression
(Expr
: Node_Id
) is
3094 if not Is_Trivial_Boolean
(Expr
) then
3095 Check_Function_Result
(Expr
);
3097 if not Mentions_Post_State
(Expr
) then
3098 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3100 ("contract case does not check the outcome of calling "
3101 & "&?T?", Expr
, Subp_Id
);
3103 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3105 ("refined postcondition does not check the outcome of "
3106 & "calling &?T?", Prag
, Subp_Id
);
3110 ("postcondition does not check the outcome of calling "
3111 & "&?T?", Prag
, Subp_Id
);
3115 end Check_Expression
;
3117 ------------------------
3118 -- Is_Function_Result --
3119 ------------------------
3121 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3123 if Is_Attribute_Result
(N
) then
3124 Result_Seen
:= True;
3127 -- Continue the traversal
3132 end Is_Function_Result
;
3134 ------------------------
3135 -- Is_Trivial_Boolean --
3136 ------------------------
3138 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3141 Comes_From_Source
(N
)
3142 and then Is_Entity_Name
(N
)
3143 and then (Entity
(N
) = Standard_True
3145 Entity
(N
) = Standard_False
);
3146 end Is_Trivial_Boolean
;
3148 -------------------------
3149 -- Mentions_Post_State --
3150 -------------------------
3152 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3153 Post_State_Seen
: Boolean := False;
3155 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3156 -- Attempt to find a construct that denotes a post-state. If this
3157 -- is the case, set flag Post_State_Seen.
3163 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3167 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3168 Post_State_Seen
:= True;
3171 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3174 -- The entity may be modifiable through an implicit
3178 or else Ekind
(Ent
) in Assignable_Kind
3179 or else (Is_Access_Type
(Etype
(Ent
))
3180 and then Nkind
(Parent
(N
)) =
3181 N_Selected_Component
)
3183 Post_State_Seen
:= True;
3187 elsif Nkind
(N
) = N_Attribute_Reference
then
3188 if Attribute_Name
(N
) = Name_Old
then
3191 elsif Attribute_Name
(N
) = Name_Result
then
3192 Post_State_Seen
:= True;
3200 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3202 -- Start of processing for Mentions_Post_State
3205 Find_Post_State
(N
);
3207 return Post_State_Seen
;
3208 end Mentions_Post_State
;
3212 Expr
: constant Node_Id
:=
3214 (First
(Pragma_Argument_Associations
(Prag
)));
3215 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3218 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3221 -- Examine all consequences
3223 if Nam
= Name_Contract_Cases
then
3224 CCase
:= First
(Component_Associations
(Expr
));
3225 while Present
(CCase
) loop
3226 Check_Expression
(Expression
(CCase
));
3231 -- Examine the expression of a postcondition
3233 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
,
3234 Name_Refined_Post
));
3235 Check_Expression
(Expr
);
3237 end Check_Result_And_Post_State_In_Pragma
;
3239 --------------------------
3240 -- Has_In_Out_Parameter --
3241 --------------------------
3243 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean is
3247 -- Traverse the formals looking for an IN OUT parameter
3249 Formal
:= First_Formal
(Subp_Id
);
3250 while Present
(Formal
) loop
3251 if Ekind
(Formal
) = E_In_Out_Parameter
then
3255 Next_Formal
(Formal
);
3259 end Has_In_Out_Parameter
;
3263 Items
: constant Node_Id
:= Contract
(Subp_Id
);
3264 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
3265 Case_Prag
: Node_Id
:= Empty
;
3266 Post_Prag
: Node_Id
:= Empty
;
3268 Seen_In_Case
: Boolean := False;
3269 Seen_In_Post
: Boolean := False;
3270 Spec_Id
: Entity_Id
;
3272 -- Start of processing for Check_Result_And_Post_State
3275 -- The lack of attribute 'Result or a post-state is classified as a
3276 -- suspicious contract. Do not perform the check if the corresponding
3277 -- swich is not set.
3279 if not Warn_On_Suspicious_Contract
then
3282 -- Nothing to do if there is no contract
3284 elsif No
(Items
) then
3288 -- Retrieve the entity of the subprogram spec (if any)
3290 if Nkind
(Subp_Decl
) = N_Subprogram_Body
3291 and then Present
(Corresponding_Spec
(Subp_Decl
))
3293 Spec_Id
:= Corresponding_Spec
(Subp_Decl
);
3295 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
3296 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
3298 Spec_Id
:= Corresponding_Spec_Of_Stub
(Subp_Decl
);
3304 -- Examine all postconditions for attribute 'Result and a post-state
3306 Prag
:= Pre_Post_Conditions
(Items
);
3307 while Present
(Prag
) loop
3308 if Nam_In
(Pragma_Name
(Prag
), Name_Postcondition
,
3310 and then not Error_Posted
(Prag
)
3313 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Post
);
3316 Prag
:= Next_Pragma
(Prag
);
3319 -- Examine the contract cases of the subprogram for attribute 'Result
3320 -- and a post-state.
3322 Prag
:= Contract_Test_Cases
(Items
);
3323 while Present
(Prag
) loop
3324 if Pragma_Name
(Prag
) = Name_Contract_Cases
3325 and then not Error_Posted
(Prag
)
3328 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Case
);
3331 Prag
:= Next_Pragma
(Prag
);
3334 -- Do not emit any errors if the subprogram is not a function
3336 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
3339 -- Regardless of whether the function has postconditions or contract
3340 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3341 -- parameter is always treated as a result.
3343 elsif Has_In_Out_Parameter
(Spec_Id
) then
3346 -- The function has both a postcondition and contract cases and they do
3347 -- not mention attribute 'Result.
3349 elsif Present
(Case_Prag
)
3350 and then not Seen_In_Case
3351 and then Present
(Post_Prag
)
3352 and then not Seen_In_Post
3355 ("neither postcondition nor contract cases mention function "
3356 & "result?T?", Post_Prag
);
3358 -- The function has contract cases only and they do not mention
3359 -- attribute 'Result.
3361 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
3362 Error_Msg_N
("contract cases do not mention result?T?", Case_Prag
);
3364 -- The function has postconditions only and they do not mention
3365 -- attribute 'Result.
3367 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
3369 ("postcondition does not mention function result?T?", Post_Prag
);
3371 end Check_Result_And_Post_State
;
3373 ------------------------------
3374 -- Check_Unprotected_Access --
3375 ------------------------------
3377 procedure Check_Unprotected_Access
3381 Cont_Encl_Typ
: Entity_Id
;
3382 Pref_Encl_Typ
: Entity_Id
;
3384 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
3385 -- Check whether Obj is a private component of a protected object.
3386 -- Return the protected type where the component resides, Empty
3389 function Is_Public_Operation
return Boolean;
3390 -- Verify that the enclosing operation is callable from outside the
3391 -- protected object, to minimize false positives.
3393 ------------------------------
3394 -- Enclosing_Protected_Type --
3395 ------------------------------
3397 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
3399 if Is_Entity_Name
(Obj
) then
3401 Ent
: Entity_Id
:= Entity
(Obj
);
3404 -- The object can be a renaming of a private component, use
3405 -- the original record component.
3407 if Is_Prival
(Ent
) then
3408 Ent
:= Prival_Link
(Ent
);
3411 if Is_Protected_Type
(Scope
(Ent
)) then
3417 -- For indexed and selected components, recursively check the prefix
3419 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
3420 return Enclosing_Protected_Type
(Prefix
(Obj
));
3422 -- The object does not denote a protected component
3427 end Enclosing_Protected_Type
;
3429 -------------------------
3430 -- Is_Public_Operation --
3431 -------------------------
3433 function Is_Public_Operation
return Boolean is
3439 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
3440 if Scope
(S
) = Pref_Encl_Typ
then
3441 E
:= First_Entity
(Pref_Encl_Typ
);
3443 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
3457 end Is_Public_Operation
;
3459 -- Start of processing for Check_Unprotected_Access
3462 if Nkind
(Expr
) = N_Attribute_Reference
3463 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
3465 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
3466 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
3468 -- Check whether we are trying to export a protected component to a
3469 -- context with an equal or lower access level.
3471 if Present
(Pref_Encl_Typ
)
3472 and then No
(Cont_Encl_Typ
)
3473 and then Is_Public_Operation
3474 and then Scope_Depth
(Pref_Encl_Typ
) >=
3475 Object_Access_Level
(Context
)
3478 ("??possible unprotected access to protected data", Expr
);
3481 end Check_Unprotected_Access
;
3483 ------------------------
3484 -- Collect_Interfaces --
3485 ------------------------
3487 procedure Collect_Interfaces
3489 Ifaces_List
: out Elist_Id
;
3490 Exclude_Parents
: Boolean := False;
3491 Use_Full_View
: Boolean := True)
3493 procedure Collect
(Typ
: Entity_Id
);
3494 -- Subsidiary subprogram used to traverse the whole list
3495 -- of directly and indirectly implemented interfaces
3501 procedure Collect
(Typ
: Entity_Id
) is
3502 Ancestor
: Entity_Id
;
3510 -- Handle private types
3513 and then Is_Private_Type
(Typ
)
3514 and then Present
(Full_View
(Typ
))
3516 Full_T
:= Full_View
(Typ
);
3519 -- Include the ancestor if we are generating the whole list of
3520 -- abstract interfaces.
3522 if Etype
(Full_T
) /= Typ
3524 -- Protect the frontend against wrong sources. For example:
3527 -- type A is tagged null record;
3528 -- type B is new A with private;
3529 -- type C is new A with private;
3531 -- type B is new C with null record;
3532 -- type C is new B with null record;
3535 and then Etype
(Full_T
) /= T
3537 Ancestor
:= Etype
(Full_T
);
3540 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
3541 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
3545 -- Traverse the graph of ancestor interfaces
3547 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
3548 Id
:= First
(Abstract_Interface_List
(Full_T
));
3549 while Present
(Id
) loop
3550 Iface
:= Etype
(Id
);
3552 -- Protect against wrong uses. For example:
3553 -- type I is interface;
3554 -- type O is tagged null record;
3555 -- type Wrong is new I and O with null record; -- ERROR
3557 if Is_Interface
(Iface
) then
3559 and then Etype
(T
) /= T
3560 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
3565 Append_Unique_Elmt
(Iface
, Ifaces_List
);
3574 -- Start of processing for Collect_Interfaces
3577 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
3578 Ifaces_List
:= New_Elmt_List
;
3580 end Collect_Interfaces
;
3582 ----------------------------------
3583 -- Collect_Interface_Components --
3584 ----------------------------------
3586 procedure Collect_Interface_Components
3587 (Tagged_Type
: Entity_Id
;
3588 Components_List
: out Elist_Id
)
3590 procedure Collect
(Typ
: Entity_Id
);
3591 -- Subsidiary subprogram used to climb to the parents
3597 procedure Collect
(Typ
: Entity_Id
) is
3598 Tag_Comp
: Entity_Id
;
3599 Parent_Typ
: Entity_Id
;
3602 -- Handle private types
3604 if Present
(Full_View
(Etype
(Typ
))) then
3605 Parent_Typ
:= Full_View
(Etype
(Typ
));
3607 Parent_Typ
:= Etype
(Typ
);
3610 if Parent_Typ
/= Typ
3612 -- Protect the frontend against wrong sources. For example:
3615 -- type A is tagged null record;
3616 -- type B is new A with private;
3617 -- type C is new A with private;
3619 -- type B is new C with null record;
3620 -- type C is new B with null record;
3623 and then Parent_Typ
/= Tagged_Type
3625 Collect
(Parent_Typ
);
3628 -- Collect the components containing tags of secondary dispatch
3631 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
3632 while Present
(Tag_Comp
) loop
3633 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
3634 Append_Elmt
(Tag_Comp
, Components_List
);
3636 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
3640 -- Start of processing for Collect_Interface_Components
3643 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
3644 and then Is_Tagged_Type
(Tagged_Type
));
3646 Components_List
:= New_Elmt_List
;
3647 Collect
(Tagged_Type
);
3648 end Collect_Interface_Components
;
3650 -----------------------------
3651 -- Collect_Interfaces_Info --
3652 -----------------------------
3654 procedure Collect_Interfaces_Info
3656 Ifaces_List
: out Elist_Id
;
3657 Components_List
: out Elist_Id
;
3658 Tags_List
: out Elist_Id
)
3660 Comps_List
: Elist_Id
;
3661 Comp_Elmt
: Elmt_Id
;
3662 Comp_Iface
: Entity_Id
;
3663 Iface_Elmt
: Elmt_Id
;
3666 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3667 -- Search for the secondary tag associated with the interface type
3668 -- Iface that is implemented by T.
3674 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3677 if not Is_CPP_Class
(T
) then
3678 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3680 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3684 and then Is_Tag
(Node
(ADT
))
3685 and then Related_Type
(Node
(ADT
)) /= Iface
3687 -- Skip secondary dispatch table referencing thunks to user
3688 -- defined primitives covered by this interface.
3690 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3693 -- Skip secondary dispatch tables of Ada types
3695 if not Is_CPP_Class
(T
) then
3697 -- Skip secondary dispatch table referencing thunks to
3698 -- predefined primitives.
3700 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3703 -- Skip secondary dispatch table referencing user-defined
3704 -- primitives covered by this interface.
3706 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3709 -- Skip secondary dispatch table referencing predefined
3712 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3717 pragma Assert
(Is_Tag
(Node
(ADT
)));
3721 -- Start of processing for Collect_Interfaces_Info
3724 Collect_Interfaces
(T
, Ifaces_List
);
3725 Collect_Interface_Components
(T
, Comps_List
);
3727 -- Search for the record component and tag associated with each
3728 -- interface type of T.
3730 Components_List
:= New_Elmt_List
;
3731 Tags_List
:= New_Elmt_List
;
3733 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3734 while Present
(Iface_Elmt
) loop
3735 Iface
:= Node
(Iface_Elmt
);
3737 -- Associate the primary tag component and the primary dispatch table
3738 -- with all the interfaces that are parents of T
3740 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3741 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3742 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3744 -- Otherwise search for the tag component and secondary dispatch
3748 Comp_Elmt
:= First_Elmt
(Comps_List
);
3749 while Present
(Comp_Elmt
) loop
3750 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3752 if Comp_Iface
= Iface
3753 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3755 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3756 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3760 Next_Elmt
(Comp_Elmt
);
3762 pragma Assert
(Present
(Comp_Elmt
));
3765 Next_Elmt
(Iface_Elmt
);
3767 end Collect_Interfaces_Info
;
3769 ---------------------
3770 -- Collect_Parents --
3771 ---------------------
3773 procedure Collect_Parents
3775 List
: out Elist_Id
;
3776 Use_Full_View
: Boolean := True)
3778 Current_Typ
: Entity_Id
:= T
;
3779 Parent_Typ
: Entity_Id
;
3782 List
:= New_Elmt_List
;
3784 -- No action if the if the type has no parents
3786 if T
= Etype
(T
) then
3791 Parent_Typ
:= Etype
(Current_Typ
);
3793 if Is_Private_Type
(Parent_Typ
)
3794 and then Present
(Full_View
(Parent_Typ
))
3795 and then Use_Full_View
3797 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3800 Append_Elmt
(Parent_Typ
, List
);
3802 exit when Parent_Typ
= Current_Typ
;
3803 Current_Typ
:= Parent_Typ
;
3805 end Collect_Parents
;
3807 ----------------------------------
3808 -- Collect_Primitive_Operations --
3809 ----------------------------------
3811 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3812 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3813 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3814 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3818 Is_Type_In_Pkg
: Boolean;
3819 Formal_Derived
: Boolean := False;
3822 function Match
(E
: Entity_Id
) return Boolean;
3823 -- True if E's base type is B_Type, or E is of an anonymous access type
3824 -- and the base type of its designated type is B_Type.
3830 function Match
(E
: Entity_Id
) return Boolean is
3831 Etyp
: Entity_Id
:= Etype
(E
);
3834 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
3835 Etyp
:= Designated_Type
(Etyp
);
3838 -- In Ada 2012 a primitive operation may have a formal of an
3839 -- incomplete view of the parent type.
3841 return Base_Type
(Etyp
) = B_Type
3843 (Ada_Version
>= Ada_2012
3844 and then Ekind
(Etyp
) = E_Incomplete_Type
3845 and then Full_View
(Etyp
) = B_Type
);
3848 -- Start of processing for Collect_Primitive_Operations
3851 -- For tagged types, the primitive operations are collected as they
3852 -- are declared, and held in an explicit list which is simply returned.
3854 if Is_Tagged_Type
(B_Type
) then
3855 return Primitive_Operations
(B_Type
);
3857 -- An untagged generic type that is a derived type inherits the
3858 -- primitive operations of its parent type. Other formal types only
3859 -- have predefined operators, which are not explicitly represented.
3861 elsif Is_Generic_Type
(B_Type
) then
3862 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
3863 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
3864 N_Formal_Derived_Type_Definition
3866 Formal_Derived
:= True;
3868 return New_Elmt_List
;
3872 Op_List
:= New_Elmt_List
;
3874 if B_Scope
= Standard_Standard
then
3875 if B_Type
= Standard_String
then
3876 Append_Elmt
(Standard_Op_Concat
, Op_List
);
3878 elsif B_Type
= Standard_Wide_String
then
3879 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
3885 -- Locate the primitive subprograms of the type
3888 -- The primitive operations appear after the base type, except
3889 -- if the derivation happens within the private part of B_Scope
3890 -- and the type is a private type, in which case both the type
3891 -- and some primitive operations may appear before the base
3892 -- type, and the list of candidates starts after the type.
3894 if In_Open_Scopes
(B_Scope
)
3895 and then Scope
(T
) = B_Scope
3896 and then In_Private_Part
(B_Scope
)
3898 Id
:= Next_Entity
(T
);
3900 -- In Ada 2012, If the type has an incomplete partial view, there
3901 -- may be primitive operations declared before the full view, so
3902 -- we need to start scanning from the incomplete view, which is
3903 -- earlier on the entity chain.
3905 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
3906 and then Present
(Incomplete_View
(Parent
(B_Type
)))
3908 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
3911 Id
:= Next_Entity
(B_Type
);
3914 -- Set flag if this is a type in a package spec
3917 Is_Package_Or_Generic_Package
(B_Scope
)
3919 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
3922 while Present
(Id
) loop
3924 -- Test whether the result type or any of the parameter types of
3925 -- each subprogram following the type match that type when the
3926 -- type is declared in a package spec, is a derived type, or the
3927 -- subprogram is marked as primitive. (The Is_Primitive test is
3928 -- needed to find primitives of nonderived types in declarative
3929 -- parts that happen to override the predefined "=" operator.)
3931 -- Note that generic formal subprograms are not considered to be
3932 -- primitive operations and thus are never inherited.
3934 if Is_Overloadable
(Id
)
3935 and then (Is_Type_In_Pkg
3936 or else Is_Derived_Type
(B_Type
)
3937 or else Is_Primitive
(Id
))
3938 and then Nkind
(Parent
(Parent
(Id
)))
3939 not in N_Formal_Subprogram_Declaration
3947 Formal
:= First_Formal
(Id
);
3948 while Present
(Formal
) loop
3949 if Match
(Formal
) then
3954 Next_Formal
(Formal
);
3958 -- For a formal derived type, the only primitives are the ones
3959 -- inherited from the parent type. Operations appearing in the
3960 -- package declaration are not primitive for it.
3963 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
3965 -- In the special case of an equality operator aliased to
3966 -- an overriding dispatching equality belonging to the same
3967 -- type, we don't include it in the list of primitives.
3968 -- This avoids inheriting multiple equality operators when
3969 -- deriving from untagged private types whose full type is
3970 -- tagged, which can otherwise cause ambiguities. Note that
3971 -- this should only happen for this kind of untagged parent
3972 -- type, since normally dispatching operations are inherited
3973 -- using the type's Primitive_Operations list.
3975 if Chars
(Id
) = Name_Op_Eq
3976 and then Is_Dispatching_Operation
(Id
)
3977 and then Present
(Alias
(Id
))
3978 and then Present
(Overridden_Operation
(Alias
(Id
)))
3979 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3980 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3984 -- Include the subprogram in the list of primitives
3987 Append_Elmt
(Id
, Op_List
);
3994 -- For a type declared in System, some of its operations may
3995 -- appear in the target-specific extension to System.
3998 and then B_Scope
= RTU_Entity
(System
)
3999 and then Present_System_Aux
4001 B_Scope
:= System_Aux_Id
;
4002 Id
:= First_Entity
(System_Aux_Id
);
4008 end Collect_Primitive_Operations
;
4010 -----------------------------------
4011 -- Compile_Time_Constraint_Error --
4012 -----------------------------------
4014 function Compile_Time_Constraint_Error
4017 Ent
: Entity_Id
:= Empty
;
4018 Loc
: Source_Ptr
:= No_Location
;
4019 Warn
: Boolean := False) return Node_Id
4021 Msgc
: String (1 .. Msg
'Length + 3);
4022 -- Copy of message, with room for possible ?? or << and ! at end
4028 -- Start of processing for Compile_Time_Constraint_Error
4031 -- If this is a warning, convert it into an error if we are in code
4032 -- subject to SPARK_Mode being set ON.
4034 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4036 -- A static constraint error in an instance body is not a fatal error.
4037 -- we choose to inhibit the message altogether, because there is no
4038 -- obvious node (for now) on which to post it. On the other hand the
4039 -- offending node must be replaced with a constraint_error in any case.
4041 -- No messages are generated if we already posted an error on this node
4043 if not Error_Posted
(N
) then
4044 if Loc
/= No_Location
then
4050 -- Copy message to Msgc, converting any ? in the message into
4051 -- < instead, so that we have an error in GNATprove mode.
4055 for J
in 1 .. Msgl
loop
4056 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
4059 Msgc
(J
) := Msg
(J
);
4063 -- Message is a warning, even in Ada 95 case
4065 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
4068 -- In Ada 83, all messages are warnings. In the private part and
4069 -- the body of an instance, constraint_checks are only warnings.
4070 -- We also make this a warning if the Warn parameter is set.
4073 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
4081 elsif In_Instance_Not_Visible
then
4088 -- Otherwise we have a real error message (Ada 95 static case)
4089 -- and we make this an unconditional message. Note that in the
4090 -- warning case we do not make the message unconditional, it seems
4091 -- quite reasonable to delete messages like this (about exceptions
4092 -- that will be raised) in dead code.
4100 -- One more test, skip the warning if the related expression is
4101 -- statically unevaluated, since we don't want to warn about what
4102 -- will happen when something is evaluated if it never will be
4105 if not Is_Statically_Unevaluated
(N
) then
4106 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4108 if Present
(Ent
) then
4109 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
4111 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
4116 -- Check whether the context is an Init_Proc
4118 if Inside_Init_Proc
then
4120 Conc_Typ
: constant Entity_Id
:=
4121 Corresponding_Concurrent_Type
4122 (Entity
(Parameter_Type
(First
4123 (Parameter_Specifications
4124 (Parent
(Current_Scope
))))));
4127 -- Don't complain if the corresponding concurrent type
4128 -- doesn't come from source (i.e. a single task/protected
4131 if Present
(Conc_Typ
)
4132 and then not Comes_From_Source
(Conc_Typ
)
4135 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4138 if GNATprove_Mode
then
4140 ("\& would have been raised for objects of this "
4141 & "type", N
, Standard_Constraint_Error
, Eloc
);
4144 ("\& will be raised for objects of this type??",
4145 N
, Standard_Constraint_Error
, Eloc
);
4151 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4155 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
4156 Set_Error_Posted
(N
);
4162 end Compile_Time_Constraint_Error
;
4164 -----------------------
4165 -- Conditional_Delay --
4166 -----------------------
4168 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
4170 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
4171 Set_Has_Delayed_Freeze
(New_Ent
);
4173 end Conditional_Delay
;
4175 ----------------------------
4176 -- Contains_Refined_State --
4177 ----------------------------
4179 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
4180 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
4181 -- Determine whether a dependency list mentions a state with a visible
4184 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
4185 -- Determine whether a global list mentions a state with a visible
4188 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
4189 -- Determine whether Item is a reference to an abstract state with a
4190 -- visible refinement.
4192 -----------------------------
4193 -- Has_State_In_Dependency --
4194 -----------------------------
4196 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
4201 -- A null dependency list does not mention any states
4203 if Nkind
(List
) = N_Null
then
4206 -- Dependency clauses appear as component associations of an
4209 elsif Nkind
(List
) = N_Aggregate
4210 and then Present
(Component_Associations
(List
))
4212 Clause
:= First
(Component_Associations
(List
));
4213 while Present
(Clause
) loop
4215 -- Inspect the outputs of a dependency clause
4217 Output
:= First
(Choices
(Clause
));
4218 while Present
(Output
) loop
4219 if Is_Refined_State
(Output
) then
4226 -- Inspect the outputs of a dependency clause
4228 if Is_Refined_State
(Expression
(Clause
)) then
4235 -- If we get here, then none of the dependency clauses mention a
4236 -- state with visible refinement.
4240 -- An illegal pragma managed to sneak in
4243 raise Program_Error
;
4245 end Has_State_In_Dependency
;
4247 -------------------------
4248 -- Has_State_In_Global --
4249 -------------------------
4251 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
4255 -- A null global list does not mention any states
4257 if Nkind
(List
) = N_Null
then
4260 -- Simple global list or moded global list declaration
4262 elsif Nkind
(List
) = N_Aggregate
then
4264 -- The declaration of a simple global list appear as a collection
4267 if Present
(Expressions
(List
)) then
4268 Item
:= First
(Expressions
(List
));
4269 while Present
(Item
) loop
4270 if Is_Refined_State
(Item
) then
4277 -- The declaration of a moded global list appears as a collection
4278 -- of component associations where individual choices denote
4282 Item
:= First
(Component_Associations
(List
));
4283 while Present
(Item
) loop
4284 if Has_State_In_Global
(Expression
(Item
)) then
4292 -- If we get here, then the simple/moded global list did not
4293 -- mention any states with a visible refinement.
4297 -- Single global item declaration
4299 elsif Is_Entity_Name
(List
) then
4300 return Is_Refined_State
(List
);
4302 -- An illegal pragma managed to sneak in
4305 raise Program_Error
;
4307 end Has_State_In_Global
;
4309 ----------------------
4310 -- Is_Refined_State --
4311 ----------------------
4313 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
4315 Item_Id
: Entity_Id
;
4318 if Nkind
(Item
) = N_Null
then
4321 -- States cannot be subject to attribute 'Result. This case arises
4322 -- in dependency relations.
4324 elsif Nkind
(Item
) = N_Attribute_Reference
4325 and then Attribute_Name
(Item
) = Name_Result
4329 -- Multiple items appear as an aggregate. This case arises in
4330 -- dependency relations.
4332 elsif Nkind
(Item
) = N_Aggregate
4333 and then Present
(Expressions
(Item
))
4335 Elmt
:= First
(Expressions
(Item
));
4336 while Present
(Elmt
) loop
4337 if Is_Refined_State
(Elmt
) then
4344 -- If we get here, then none of the inputs or outputs reference a
4345 -- state with visible refinement.
4352 Item_Id
:= Entity_Of
(Item
);
4356 and then Ekind
(Item_Id
) = E_Abstract_State
4357 and then Has_Visible_Refinement
(Item_Id
);
4359 end Is_Refined_State
;
4363 Arg
: constant Node_Id
:=
4364 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
4365 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4367 -- Start of processing for Contains_Refined_State
4370 if Nam
= Name_Depends
then
4371 return Has_State_In_Dependency
(Arg
);
4373 else pragma Assert
(Nam
= Name_Global
);
4374 return Has_State_In_Global
(Arg
);
4376 end Contains_Refined_State
;
4378 -------------------------
4379 -- Copy_Component_List --
4380 -------------------------
4382 function Copy_Component_List
4384 Loc
: Source_Ptr
) return List_Id
4387 Comps
: constant List_Id
:= New_List
;
4390 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
4391 while Present
(Comp
) loop
4392 if Comes_From_Source
(Comp
) then
4394 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
4397 Make_Component_Declaration
(Loc
,
4398 Defining_Identifier
=>
4399 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
4400 Component_Definition
=>
4402 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
4406 Next_Component
(Comp
);
4410 end Copy_Component_List
;
4412 -------------------------
4413 -- Copy_Parameter_List --
4414 -------------------------
4416 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
4417 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
4422 if No
(First_Formal
(Subp_Id
)) then
4426 Formal
:= First_Formal
(Subp_Id
);
4427 while Present
(Formal
) loop
4429 (Make_Parameter_Specification
(Loc
,
4430 Defining_Identifier
=>
4431 Make_Defining_Identifier
(Sloc
(Formal
),
4432 Chars
=> Chars
(Formal
)),
4433 In_Present
=> In_Present
(Parent
(Formal
)),
4434 Out_Present
=> Out_Present
(Parent
(Formal
)),
4436 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4438 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
4441 Next_Formal
(Formal
);
4446 end Copy_Parameter_List
;
4448 --------------------------------
4449 -- Corresponding_Generic_Type --
4450 --------------------------------
4452 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
4458 if not Is_Generic_Actual_Type
(T
) then
4461 -- If the actual is the actual of an enclosing instance, resolution
4462 -- was correct in the generic.
4464 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
4465 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
4467 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
4474 if Is_Wrapper_Package
(Inst
) then
4475 Inst
:= Related_Instance
(Inst
);
4480 (Specification
(Unit_Declaration_Node
(Inst
)));
4482 -- Generic actual has the same name as the corresponding formal
4484 Typ
:= First_Entity
(Gen
);
4485 while Present
(Typ
) loop
4486 if Chars
(Typ
) = Chars
(T
) then
4495 end Corresponding_Generic_Type
;
4497 ---------------------------
4498 -- Corresponding_Spec_Of --
4499 ---------------------------
4501 function Corresponding_Spec_Of
(Subp_Decl
: Node_Id
) return Entity_Id
is
4503 if Nkind
(Subp_Decl
) = N_Subprogram_Body
4504 and then Present
(Corresponding_Spec
(Subp_Decl
))
4506 return Corresponding_Spec
(Subp_Decl
);
4508 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4509 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
4511 return Corresponding_Spec_Of_Stub
(Subp_Decl
);
4514 return Defining_Entity
(Subp_Decl
);
4516 end Corresponding_Spec_Of
;
4518 --------------------
4519 -- Current_Entity --
4520 --------------------
4522 -- The currently visible definition for a given identifier is the
4523 -- one most chained at the start of the visibility chain, i.e. the
4524 -- one that is referenced by the Node_Id value of the name of the
4525 -- given identifier.
4527 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
4529 return Get_Name_Entity_Id
(Chars
(N
));
4532 -----------------------------
4533 -- Current_Entity_In_Scope --
4534 -----------------------------
4536 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
4538 CS
: constant Entity_Id
:= Current_Scope
;
4540 Transient_Case
: constant Boolean := Scope_Is_Transient
;
4543 E
:= Get_Name_Entity_Id
(Chars
(N
));
4545 and then Scope
(E
) /= CS
4546 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
4552 end Current_Entity_In_Scope
;
4558 function Current_Scope
return Entity_Id
is
4560 if Scope_Stack
.Last
= -1 then
4561 return Standard_Standard
;
4564 C
: constant Entity_Id
:=
4565 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
4570 return Standard_Standard
;
4576 ------------------------
4577 -- Current_Subprogram --
4578 ------------------------
4580 function Current_Subprogram
return Entity_Id
is
4581 Scop
: constant Entity_Id
:= Current_Scope
;
4583 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
4586 return Enclosing_Subprogram
(Scop
);
4588 end Current_Subprogram
;
4590 ----------------------------------
4591 -- Deepest_Type_Access_Level --
4592 ----------------------------------
4594 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
4596 if Ekind
(Typ
) = E_Anonymous_Access_Type
4597 and then not Is_Local_Anonymous_Access
(Typ
)
4598 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
4600 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4604 Scope_Depth
(Enclosing_Dynamic_Scope
4605 (Defining_Identifier
4606 (Associated_Node_For_Itype
(Typ
))));
4608 -- For generic formal type, return Int'Last (infinite).
4609 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4611 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
4612 return UI_From_Int
(Int
'Last);
4615 return Type_Access_Level
(Typ
);
4617 end Deepest_Type_Access_Level
;
4619 ---------------------
4620 -- Defining_Entity --
4621 ---------------------
4623 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4624 K
: constant Node_Kind
:= Nkind
(N
);
4625 Err
: Entity_Id
:= Empty
;
4630 N_Subprogram_Declaration |
4631 N_Abstract_Subprogram_Declaration |
4633 N_Package_Declaration |
4634 N_Subprogram_Renaming_Declaration |
4635 N_Subprogram_Body_Stub |
4636 N_Generic_Subprogram_Declaration |
4637 N_Generic_Package_Declaration |
4638 N_Formal_Subprogram_Declaration |
4639 N_Expression_Function
4641 return Defining_Entity
(Specification
(N
));
4644 N_Component_Declaration |
4645 N_Defining_Program_Unit_Name |
4646 N_Discriminant_Specification |
4648 N_Entry_Declaration |
4649 N_Entry_Index_Specification |
4650 N_Exception_Declaration |
4651 N_Exception_Renaming_Declaration |
4652 N_Formal_Object_Declaration |
4653 N_Formal_Package_Declaration |
4654 N_Formal_Type_Declaration |
4655 N_Full_Type_Declaration |
4656 N_Implicit_Label_Declaration |
4657 N_Incomplete_Type_Declaration |
4658 N_Loop_Parameter_Specification |
4659 N_Number_Declaration |
4660 N_Object_Declaration |
4661 N_Object_Renaming_Declaration |
4662 N_Package_Body_Stub |
4663 N_Parameter_Specification |
4664 N_Private_Extension_Declaration |
4665 N_Private_Type_Declaration |
4667 N_Protected_Body_Stub |
4668 N_Protected_Type_Declaration |
4669 N_Single_Protected_Declaration |
4670 N_Single_Task_Declaration |
4671 N_Subtype_Declaration |
4674 N_Task_Type_Declaration
4676 return Defining_Identifier
(N
);
4679 return Defining_Entity
(Proper_Body
(N
));
4682 N_Function_Instantiation |
4683 N_Function_Specification |
4684 N_Generic_Function_Renaming_Declaration |
4685 N_Generic_Package_Renaming_Declaration |
4686 N_Generic_Procedure_Renaming_Declaration |
4688 N_Package_Instantiation |
4689 N_Package_Renaming_Declaration |
4690 N_Package_Specification |
4691 N_Procedure_Instantiation |
4692 N_Procedure_Specification
4695 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
4698 if Nkind
(Nam
) in N_Entity
then
4701 -- For Error, make up a name and attach to declaration
4702 -- so we can continue semantic analysis
4704 elsif Nam
= Error
then
4705 Err
:= Make_Temporary
(Sloc
(N
), 'T');
4706 Set_Defining_Unit_Name
(N
, Err
);
4710 -- If not an entity, get defining identifier
4713 return Defining_Identifier
(Nam
);
4721 return Entity
(Identifier
(N
));
4724 raise Program_Error
;
4727 end Defining_Entity
;
4729 --------------------------
4730 -- Denotes_Discriminant --
4731 --------------------------
4733 function Denotes_Discriminant
4735 Check_Concurrent
: Boolean := False) return Boolean
4740 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
4746 -- If we are checking for a protected type, the discriminant may have
4747 -- been rewritten as the corresponding discriminal of the original type
4748 -- or of the corresponding concurrent record, depending on whether we
4749 -- are in the spec or body of the protected type.
4751 return Ekind
(E
) = E_Discriminant
4754 and then Ekind
(E
) = E_In_Parameter
4755 and then Present
(Discriminal_Link
(E
))
4757 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
4759 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
4761 end Denotes_Discriminant
;
4763 -------------------------
4764 -- Denotes_Same_Object --
4765 -------------------------
4767 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
4768 Obj1
: Node_Id
:= A1
;
4769 Obj2
: Node_Id
:= A2
;
4771 function Has_Prefix
(N
: Node_Id
) return Boolean;
4772 -- Return True if N has attribute Prefix
4774 function Is_Renaming
(N
: Node_Id
) return Boolean;
4775 -- Return true if N names a renaming entity
4777 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
4778 -- For renamings, return False if the prefix of any dereference within
4779 -- the renamed object_name is a variable, or any expression within the
4780 -- renamed object_name contains references to variables or calls on
4781 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4787 function Has_Prefix
(N
: Node_Id
) return Boolean is
4791 N_Attribute_Reference
,
4793 N_Explicit_Dereference
,
4794 N_Indexed_Component
,
4796 N_Selected_Component
,
4804 function Is_Renaming
(N
: Node_Id
) return Boolean is
4806 return Is_Entity_Name
(N
)
4807 and then Present
(Renamed_Entity
(Entity
(N
)));
4810 -----------------------
4811 -- Is_Valid_Renaming --
4812 -----------------------
4814 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
4816 function Check_Renaming
(N
: Node_Id
) return Boolean;
4817 -- Recursive function used to traverse all the prefixes of N
4819 function Check_Renaming
(N
: Node_Id
) return Boolean is
4822 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
4827 if Nkind
(N
) = N_Indexed_Component
then
4832 Indx
:= First
(Expressions
(N
));
4833 while Present
(Indx
) loop
4834 if not Is_OK_Static_Expression
(Indx
) then
4843 if Has_Prefix
(N
) then
4845 P
: constant Node_Id
:= Prefix
(N
);
4848 if Nkind
(N
) = N_Explicit_Dereference
4849 and then Is_Variable
(P
)
4853 elsif Is_Entity_Name
(P
)
4854 and then Ekind
(Entity
(P
)) = E_Function
4858 elsif Nkind
(P
) = N_Function_Call
then
4862 -- Recursion to continue traversing the prefix of the
4863 -- renaming expression
4865 return Check_Renaming
(P
);
4872 -- Start of processing for Is_Valid_Renaming
4875 return Check_Renaming
(N
);
4876 end Is_Valid_Renaming
;
4878 -- Start of processing for Denotes_Same_Object
4881 -- Both names statically denote the same stand-alone object or parameter
4882 -- (RM 6.4.1(6.5/3))
4884 if Is_Entity_Name
(Obj1
)
4885 and then Is_Entity_Name
(Obj2
)
4886 and then Entity
(Obj1
) = Entity
(Obj2
)
4891 -- For renamings, the prefix of any dereference within the renamed
4892 -- object_name is not a variable, and any expression within the
4893 -- renamed object_name contains no references to variables nor
4894 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4896 if Is_Renaming
(Obj1
) then
4897 if Is_Valid_Renaming
(Obj1
) then
4898 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
4904 if Is_Renaming
(Obj2
) then
4905 if Is_Valid_Renaming
(Obj2
) then
4906 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
4912 -- No match if not same node kind (such cases are handled by
4913 -- Denotes_Same_Prefix)
4915 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
4918 -- After handling valid renamings, one of the two names statically
4919 -- denoted a renaming declaration whose renamed object_name is known
4920 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4922 elsif Is_Entity_Name
(Obj1
) then
4923 if Is_Entity_Name
(Obj2
) then
4924 return Entity
(Obj1
) = Entity
(Obj2
);
4929 -- Both names are selected_components, their prefixes are known to
4930 -- denote the same object, and their selector_names denote the same
4931 -- component (RM 6.4.1(6.6/3)
4933 elsif Nkind
(Obj1
) = N_Selected_Component
then
4934 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4936 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
4938 -- Both names are dereferences and the dereferenced names are known to
4939 -- denote the same object (RM 6.4.1(6.7/3))
4941 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
4942 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
4944 -- Both names are indexed_components, their prefixes are known to denote
4945 -- the same object, and each of the pairs of corresponding index values
4946 -- are either both static expressions with the same static value or both
4947 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4949 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4950 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4958 Indx1
:= First
(Expressions
(Obj1
));
4959 Indx2
:= First
(Expressions
(Obj2
));
4960 while Present
(Indx1
) loop
4962 -- Indexes must denote the same static value or same object
4964 if Is_OK_Static_Expression
(Indx1
) then
4965 if not Is_OK_Static_Expression
(Indx2
) then
4968 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4972 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4984 -- Both names are slices, their prefixes are known to denote the same
4985 -- object, and the two slices have statically matching index constraints
4986 -- (RM 6.4.1(6.9/3))
4988 elsif Nkind
(Obj1
) = N_Slice
4989 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4992 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4995 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4996 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4998 -- Check whether bounds are statically identical. There is no
4999 -- attempt to detect partial overlap of slices.
5001 return Denotes_Same_Object
(Lo1
, Lo2
)
5003 Denotes_Same_Object
(Hi1
, Hi2
);
5006 -- In the recursion, literals appear as indexes
5008 elsif Nkind
(Obj1
) = N_Integer_Literal
5010 Nkind
(Obj2
) = N_Integer_Literal
5012 return Intval
(Obj1
) = Intval
(Obj2
);
5017 end Denotes_Same_Object
;
5019 -------------------------
5020 -- Denotes_Same_Prefix --
5021 -------------------------
5023 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
5026 if Is_Entity_Name
(A1
) then
5027 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
5028 and then not Is_Access_Type
(Etype
(A1
))
5030 return Denotes_Same_Object
(A1
, Prefix
(A2
))
5031 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
5036 elsif Is_Entity_Name
(A2
) then
5037 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
5039 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5041 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5044 Root1
, Root2
: Node_Id
;
5045 Depth1
, Depth2
: Int
:= 0;
5048 Root1
:= Prefix
(A1
);
5049 while not Is_Entity_Name
(Root1
) loop
5051 (Root1
, N_Selected_Component
, N_Indexed_Component
)
5055 Root1
:= Prefix
(Root1
);
5058 Depth1
:= Depth1
+ 1;
5061 Root2
:= Prefix
(A2
);
5062 while not Is_Entity_Name
(Root2
) loop
5063 if not Nkind_In
(Root2
, N_Selected_Component
,
5064 N_Indexed_Component
)
5068 Root2
:= Prefix
(Root2
);
5071 Depth2
:= Depth2
+ 1;
5074 -- If both have the same depth and they do not denote the same
5075 -- object, they are disjoint and no warning is needed.
5077 if Depth1
= Depth2
then
5080 elsif Depth1
> Depth2
then
5081 Root1
:= Prefix
(A1
);
5082 for J
in 1 .. Depth1
- Depth2
- 1 loop
5083 Root1
:= Prefix
(Root1
);
5086 return Denotes_Same_Object
(Root1
, A2
);
5089 Root2
:= Prefix
(A2
);
5090 for J
in 1 .. Depth2
- Depth1
- 1 loop
5091 Root2
:= Prefix
(Root2
);
5094 return Denotes_Same_Object
(A1
, Root2
);
5101 end Denotes_Same_Prefix
;
5103 ----------------------
5104 -- Denotes_Variable --
5105 ----------------------
5107 function Denotes_Variable
(N
: Node_Id
) return Boolean is
5109 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
5110 end Denotes_Variable
;
5112 -----------------------------
5113 -- Depends_On_Discriminant --
5114 -----------------------------
5116 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
5121 Get_Index_Bounds
(N
, L
, H
);
5122 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
5123 end Depends_On_Discriminant
;
5125 -------------------------
5126 -- Designate_Same_Unit --
5127 -------------------------
5129 function Designate_Same_Unit
5131 Name2
: Node_Id
) return Boolean
5133 K1
: constant Node_Kind
:= Nkind
(Name1
);
5134 K2
: constant Node_Kind
:= Nkind
(Name2
);
5136 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
5137 -- Returns the parent unit name node of a defining program unit name
5138 -- or the prefix if N is a selected component or an expanded name.
5140 function Select_Node
(N
: Node_Id
) return Node_Id
;
5141 -- Returns the defining identifier node of a defining program unit
5142 -- name or the selector node if N is a selected component or an
5149 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
5151 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
5162 function Select_Node
(N
: Node_Id
) return Node_Id
is
5164 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
5165 return Defining_Identifier
(N
);
5167 return Selector_Name
(N
);
5171 -- Start of processing for Designate_Same_Unit
5174 if Nkind_In
(K1
, N_Identifier
, N_Defining_Identifier
)
5176 Nkind_In
(K2
, N_Identifier
, N_Defining_Identifier
)
5178 return Chars
(Name1
) = Chars
(Name2
);
5180 elsif Nkind_In
(K1
, N_Expanded_Name
,
5181 N_Selected_Component
,
5182 N_Defining_Program_Unit_Name
)
5184 Nkind_In
(K2
, N_Expanded_Name
,
5185 N_Selected_Component
,
5186 N_Defining_Program_Unit_Name
)
5189 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
5191 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
5196 end Designate_Same_Unit
;
5198 ------------------------------------------
5199 -- function Dynamic_Accessibility_Level --
5200 ------------------------------------------
5202 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
5204 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5206 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
5207 -- Construct an integer literal representing an accessibility level
5208 -- with its type set to Natural.
5210 ------------------------
5211 -- Make_Level_Literal --
5212 ------------------------
5214 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
5215 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
5217 Set_Etype
(Result
, Standard_Natural
);
5219 end Make_Level_Literal
;
5221 -- Start of processing for Dynamic_Accessibility_Level
5224 if Is_Entity_Name
(Expr
) then
5227 if Present
(Renamed_Object
(E
)) then
5228 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
5231 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
5232 if Present
(Extra_Accessibility
(E
)) then
5233 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
5238 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5240 case Nkind
(Expr
) is
5242 -- For access discriminant, the level of the enclosing object
5244 when N_Selected_Component
=>
5245 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
5246 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
5247 E_Anonymous_Access_Type
5249 return Make_Level_Literal
(Object_Access_Level
(Expr
));
5252 when N_Attribute_Reference
=>
5253 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
5255 -- For X'Access, the level of the prefix X
5257 when Attribute_Access
=>
5258 return Make_Level_Literal
5259 (Object_Access_Level
(Prefix
(Expr
)));
5261 -- Treat the unchecked attributes as library-level
5263 when Attribute_Unchecked_Access |
5264 Attribute_Unrestricted_Access
=>
5265 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
5267 -- No other access-valued attributes
5270 raise Program_Error
;
5275 -- Unimplemented: depends on context. As an actual parameter where
5276 -- formal type is anonymous, use
5277 -- Scope_Depth (Current_Scope) + 1.
5278 -- For other cases, see 3.10.2(14/3) and following. ???
5282 when N_Type_Conversion
=>
5283 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
5285 -- Handle type conversions introduced for a rename of an
5286 -- Ada 2012 stand-alone object of an anonymous access type.
5288 return Dynamic_Accessibility_Level
(Expression
(Expr
));
5295 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
5296 end Dynamic_Accessibility_Level
;
5298 -----------------------------------
5299 -- Effective_Extra_Accessibility --
5300 -----------------------------------
5302 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
5304 if Present
(Renamed_Object
(Id
))
5305 and then Is_Entity_Name
(Renamed_Object
(Id
))
5307 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
5309 return Extra_Accessibility
(Id
);
5311 end Effective_Extra_Accessibility
;
5313 -----------------------------
5314 -- Effective_Reads_Enabled --
5315 -----------------------------
5317 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
5319 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
5320 end Effective_Reads_Enabled
;
5322 ------------------------------
5323 -- Effective_Writes_Enabled --
5324 ------------------------------
5326 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
5328 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
5329 end Effective_Writes_Enabled
;
5331 ------------------------------
5332 -- Enclosing_Comp_Unit_Node --
5333 ------------------------------
5335 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
5336 Current_Node
: Node_Id
;
5340 while Present
(Current_Node
)
5341 and then Nkind
(Current_Node
) /= N_Compilation_Unit
5343 Current_Node
:= Parent
(Current_Node
);
5346 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
5349 return Current_Node
;
5351 end Enclosing_Comp_Unit_Node
;
5353 --------------------------
5354 -- Enclosing_CPP_Parent --
5355 --------------------------
5357 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
5358 Parent_Typ
: Entity_Id
:= Typ
;
5361 while not Is_CPP_Class
(Parent_Typ
)
5362 and then Etype
(Parent_Typ
) /= Parent_Typ
5364 Parent_Typ
:= Etype
(Parent_Typ
);
5366 if Is_Private_Type
(Parent_Typ
) then
5367 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5371 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
5373 end Enclosing_CPP_Parent
;
5375 ----------------------------
5376 -- Enclosing_Generic_Body --
5377 ----------------------------
5379 function Enclosing_Generic_Body
5380 (N
: Node_Id
) return Node_Id
5388 while Present
(P
) loop
5389 if Nkind
(P
) = N_Package_Body
5390 or else Nkind
(P
) = N_Subprogram_Body
5392 Spec
:= Corresponding_Spec
(P
);
5394 if Present
(Spec
) then
5395 Decl
:= Unit_Declaration_Node
(Spec
);
5397 if Nkind
(Decl
) = N_Generic_Package_Declaration
5398 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5409 end Enclosing_Generic_Body
;
5411 ----------------------------
5412 -- Enclosing_Generic_Unit --
5413 ----------------------------
5415 function Enclosing_Generic_Unit
5416 (N
: Node_Id
) return Node_Id
5424 while Present
(P
) loop
5425 if Nkind
(P
) = N_Generic_Package_Declaration
5426 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
5430 elsif Nkind
(P
) = N_Package_Body
5431 or else Nkind
(P
) = N_Subprogram_Body
5433 Spec
:= Corresponding_Spec
(P
);
5435 if Present
(Spec
) then
5436 Decl
:= Unit_Declaration_Node
(Spec
);
5438 if Nkind
(Decl
) = N_Generic_Package_Declaration
5439 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5450 end Enclosing_Generic_Unit
;
5452 -------------------------------
5453 -- Enclosing_Lib_Unit_Entity --
5454 -------------------------------
5456 function Enclosing_Lib_Unit_Entity
5457 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
5459 Unit_Entity
: Entity_Id
;
5462 -- Look for enclosing library unit entity by following scope links.
5463 -- Equivalent to, but faster than indexing through the scope stack.
5466 while (Present
(Scope
(Unit_Entity
))
5467 and then Scope
(Unit_Entity
) /= Standard_Standard
)
5468 and not Is_Child_Unit
(Unit_Entity
)
5470 Unit_Entity
:= Scope
(Unit_Entity
);
5474 end Enclosing_Lib_Unit_Entity
;
5476 -----------------------
5477 -- Enclosing_Package --
5478 -----------------------
5480 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
5481 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5484 if Dynamic_Scope
= Standard_Standard
then
5485 return Standard_Standard
;
5487 elsif Dynamic_Scope
= Empty
then
5490 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
5493 return Dynamic_Scope
;
5496 return Enclosing_Package
(Dynamic_Scope
);
5498 end Enclosing_Package
;
5500 --------------------------
5501 -- Enclosing_Subprogram --
5502 --------------------------
5504 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5505 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5508 if Dynamic_Scope
= Standard_Standard
then
5511 elsif Dynamic_Scope
= Empty
then
5514 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
5515 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
5517 elsif Ekind
(Dynamic_Scope
) = E_Block
5518 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
5520 return Enclosing_Subprogram
(Dynamic_Scope
);
5522 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
5523 return Get_Task_Body_Procedure
(Dynamic_Scope
);
5525 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
5526 and then Present
(Full_View
(Dynamic_Scope
))
5527 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
5529 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
5531 -- No body is generated if the protected operation is eliminated
5533 elsif Convention
(Dynamic_Scope
) = Convention_Protected
5534 and then not Is_Eliminated
(Dynamic_Scope
)
5535 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
5537 return Protected_Body_Subprogram
(Dynamic_Scope
);
5540 return Dynamic_Scope
;
5542 end Enclosing_Subprogram
;
5544 ------------------------
5545 -- Ensure_Freeze_Node --
5546 ------------------------
5548 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
5551 if No
(Freeze_Node
(E
)) then
5552 FN
:= Make_Freeze_Entity
(Sloc
(E
));
5553 Set_Has_Delayed_Freeze
(E
);
5554 Set_Freeze_Node
(E
, FN
);
5555 Set_Access_Types_To_Process
(FN
, No_Elist
);
5556 Set_TSS_Elist
(FN
, No_Elist
);
5559 end Ensure_Freeze_Node
;
5565 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5566 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5567 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5568 S
: constant Entity_Id
:= Current_Scope
;
5571 Generate_Definition
(Def_Id
);
5573 -- Add new name to current scope declarations. Check for duplicate
5574 -- declaration, which may or may not be a genuine error.
5578 -- Case of previous entity entered because of a missing declaration
5579 -- or else a bad subtype indication. Best is to use the new entity,
5580 -- and make the previous one invisible.
5582 if Etype
(E
) = Any_Type
then
5583 Set_Is_Immediately_Visible
(E
, False);
5585 -- Case of renaming declaration constructed for package instances.
5586 -- if there is an explicit declaration with the same identifier,
5587 -- the renaming is not immediately visible any longer, but remains
5588 -- visible through selected component notation.
5590 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
5591 and then not Comes_From_Source
(E
)
5593 Set_Is_Immediately_Visible
(E
, False);
5595 -- The new entity may be the package renaming, which has the same
5596 -- same name as a generic formal which has been seen already.
5598 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
5599 and then not Comes_From_Source
(Def_Id
)
5601 Set_Is_Immediately_Visible
(E
, False);
5603 -- For a fat pointer corresponding to a remote access to subprogram,
5604 -- we use the same identifier as the RAS type, so that the proper
5605 -- name appears in the stub. This type is only retrieved through
5606 -- the RAS type and never by visibility, and is not added to the
5607 -- visibility list (see below).
5609 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
5610 and then Ekind
(Def_Id
) = E_Record_Type
5611 and then Present
(Corresponding_Remote_Type
(Def_Id
))
5615 -- Case of an implicit operation or derived literal. The new entity
5616 -- hides the implicit one, which is removed from all visibility,
5617 -- i.e. the entity list of its scope, and homonym chain of its name.
5619 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
5620 or else Is_Internal
(E
)
5624 Prev_Vis
: Entity_Id
;
5625 Decl
: constant Node_Id
:= Parent
(E
);
5628 -- If E is an implicit declaration, it cannot be the first
5629 -- entity in the scope.
5631 Prev
:= First_Entity
(Current_Scope
);
5632 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
5638 -- If E is not on the entity chain of the current scope,
5639 -- it is an implicit declaration in the generic formal
5640 -- part of a generic subprogram. When analyzing the body,
5641 -- the generic formals are visible but not on the entity
5642 -- chain of the subprogram. The new entity will become
5643 -- the visible one in the body.
5646 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
5650 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5652 if No
(Next_Entity
(Prev
)) then
5653 Set_Last_Entity
(Current_Scope
, Prev
);
5656 if E
= Current_Entity
(E
) then
5660 Prev_Vis
:= Current_Entity
(E
);
5661 while Homonym
(Prev_Vis
) /= E
loop
5662 Prev_Vis
:= Homonym
(Prev_Vis
);
5666 if Present
(Prev_Vis
) then
5668 -- Skip E in the visibility chain
5670 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5673 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5678 -- This section of code could use a comment ???
5680 elsif Present
(Etype
(E
))
5681 and then Is_Concurrent_Type
(Etype
(E
))
5686 -- If the homograph is a protected component renaming, it should not
5687 -- be hiding the current entity. Such renamings are treated as weak
5690 elsif Is_Prival
(E
) then
5691 Set_Is_Immediately_Visible
(E
, False);
5693 -- In this case the current entity is a protected component renaming.
5694 -- Perform minimal decoration by setting the scope and return since
5695 -- the prival should not be hiding other visible entities.
5697 elsif Is_Prival
(Def_Id
) then
5698 Set_Scope
(Def_Id
, Current_Scope
);
5701 -- Analogous to privals, the discriminal generated for an entry index
5702 -- parameter acts as a weak declaration. Perform minimal decoration
5703 -- to avoid bogus errors.
5705 elsif Is_Discriminal
(Def_Id
)
5706 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
5708 Set_Scope
(Def_Id
, Current_Scope
);
5711 -- In the body or private part of an instance, a type extension may
5712 -- introduce a component with the same name as that of an actual. The
5713 -- legality rule is not enforced, but the semantics of the full type
5714 -- with two components of same name are not clear at this point???
5716 elsif In_Instance_Not_Visible
then
5719 -- When compiling a package body, some child units may have become
5720 -- visible. They cannot conflict with local entities that hide them.
5722 elsif Is_Child_Unit
(E
)
5723 and then In_Open_Scopes
(Scope
(E
))
5724 and then not Is_Immediately_Visible
(E
)
5728 -- Conversely, with front-end inlining we may compile the parent body
5729 -- first, and a child unit subsequently. The context is now the
5730 -- parent spec, and body entities are not visible.
5732 elsif Is_Child_Unit
(Def_Id
)
5733 and then Is_Package_Body_Entity
(E
)
5734 and then not In_Package_Body
(Current_Scope
)
5738 -- Case of genuine duplicate declaration
5741 Error_Msg_Sloc
:= Sloc
(E
);
5743 -- If the previous declaration is an incomplete type declaration
5744 -- this may be an attempt to complete it with a private type. The
5745 -- following avoids confusing cascaded errors.
5747 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
5748 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
5751 ("incomplete type cannot be completed with a private " &
5752 "declaration", Parent
(Def_Id
));
5753 Set_Is_Immediately_Visible
(E
, False);
5754 Set_Full_View
(E
, Def_Id
);
5756 -- An inherited component of a record conflicts with a new
5757 -- discriminant. The discriminant is inserted first in the scope,
5758 -- but the error should be posted on it, not on the component.
5760 elsif Ekind
(E
) = E_Discriminant
5761 and then Present
(Scope
(Def_Id
))
5762 and then Scope
(Def_Id
) /= Current_Scope
5764 Error_Msg_Sloc
:= Sloc
(Def_Id
);
5765 Error_Msg_N
("& conflicts with declaration#", E
);
5768 -- If the name of the unit appears in its own context clause, a
5769 -- dummy package with the name has already been created, and the
5770 -- error emitted. Try to continue quietly.
5772 elsif Error_Posted
(E
)
5773 and then Sloc
(E
) = No_Location
5774 and then Nkind
(Parent
(E
)) = N_Package_Specification
5775 and then Current_Scope
= Standard_Standard
5777 Set_Scope
(Def_Id
, Current_Scope
);
5781 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
5783 -- Avoid cascaded messages with duplicate components in
5786 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
5791 if Nkind
(Parent
(Parent
(Def_Id
))) =
5792 N_Generic_Subprogram_Declaration
5794 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
5796 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
5799 -- If entity is in standard, then we are in trouble, because it
5800 -- means that we have a library package with a duplicated name.
5801 -- That's hard to recover from, so abort.
5803 if S
= Standard_Standard
then
5804 raise Unrecoverable_Error
;
5806 -- Otherwise we continue with the declaration. Having two
5807 -- identical declarations should not cause us too much trouble.
5815 -- If we fall through, declaration is OK, at least OK enough to continue
5817 -- If Def_Id is a discriminant or a record component we are in the midst
5818 -- of inheriting components in a derived record definition. Preserve
5819 -- their Ekind and Etype.
5821 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
5824 -- If a type is already set, leave it alone (happens when a type
5825 -- declaration is reanalyzed following a call to the optimizer).
5827 elsif Present
(Etype
(Def_Id
)) then
5830 -- Otherwise, the kind E_Void insures that premature uses of the entity
5831 -- will be detected. Any_Type insures that no cascaded errors will occur
5834 Set_Ekind
(Def_Id
, E_Void
);
5835 Set_Etype
(Def_Id
, Any_Type
);
5838 -- Inherited discriminants and components in derived record types are
5839 -- immediately visible. Itypes are not.
5841 -- Unless the Itype is for a record type with a corresponding remote
5842 -- type (what is that about, it was not commented ???)
5844 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
5846 ((not Is_Record_Type
(Def_Id
)
5847 or else No
(Corresponding_Remote_Type
(Def_Id
)))
5848 and then not Is_Itype
(Def_Id
))
5850 Set_Is_Immediately_Visible
(Def_Id
);
5851 Set_Current_Entity
(Def_Id
);
5854 Set_Homonym
(Def_Id
, C
);
5855 Append_Entity
(Def_Id
, S
);
5856 Set_Public_Status
(Def_Id
);
5858 -- Declaring a homonym is not allowed in SPARK ...
5860 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
5862 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
5863 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
5864 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
5867 -- ... unless the new declaration is in a subprogram, and the
5868 -- visible declaration is a variable declaration or a parameter
5869 -- specification outside that subprogram.
5871 if Present
(Enclosing_Subp
)
5872 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
5873 N_Parameter_Specification
)
5874 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
5878 -- ... or the new declaration is in a package, and the visible
5879 -- declaration occurs outside that package.
5881 elsif Present
(Enclosing_Pack
)
5882 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
5886 -- ... or the new declaration is a component declaration in a
5887 -- record type definition.
5889 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
5892 -- Don't issue error for non-source entities
5894 elsif Comes_From_Source
(Def_Id
)
5895 and then Comes_From_Source
(C
)
5897 Error_Msg_Sloc
:= Sloc
(C
);
5898 Check_SPARK_05_Restriction
5899 ("redeclaration of identifier &#", Def_Id
);
5904 -- Warn if new entity hides an old one
5906 if Warn_On_Hiding
and then Present
(C
)
5908 -- Don't warn for record components since they always have a well
5909 -- defined scope which does not confuse other uses. Note that in
5910 -- some cases, Ekind has not been set yet.
5912 and then Ekind
(C
) /= E_Component
5913 and then Ekind
(C
) /= E_Discriminant
5914 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
5915 and then Ekind
(Def_Id
) /= E_Component
5916 and then Ekind
(Def_Id
) /= E_Discriminant
5917 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
5919 -- Don't warn for one character variables. It is too common to use
5920 -- such variables as locals and will just cause too many false hits.
5922 and then Length_Of_Name
(Chars
(C
)) /= 1
5924 -- Don't warn for non-source entities
5926 and then Comes_From_Source
(C
)
5927 and then Comes_From_Source
(Def_Id
)
5929 -- Don't warn unless entity in question is in extended main source
5931 and then In_Extended_Main_Source_Unit
(Def_Id
)
5933 -- Finally, the hidden entity must be either immediately visible or
5934 -- use visible (i.e. from a used package).
5937 (Is_Immediately_Visible
(C
)
5939 Is_Potentially_Use_Visible
(C
))
5941 Error_Msg_Sloc
:= Sloc
(C
);
5942 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
5950 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
5956 if Is_Entity_Name
(N
) then
5959 -- Follow a possible chain of renamings to reach the root renamed
5962 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5963 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5964 Id
:= Entity
(Renamed_Object
(Id
));
5975 --------------------------
5976 -- Explain_Limited_Type --
5977 --------------------------
5979 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5983 -- For array, component type must be limited
5985 if Is_Array_Type
(T
) then
5986 Error_Msg_Node_2
:= T
;
5988 ("\component type& of type& is limited", N
, Component_Type
(T
));
5989 Explain_Limited_Type
(Component_Type
(T
), N
);
5991 elsif Is_Record_Type
(T
) then
5993 -- No need for extra messages if explicit limited record
5995 if Is_Limited_Record
(Base_Type
(T
)) then
5999 -- Otherwise find a limited component. Check only components that
6000 -- come from source, or inherited components that appear in the
6001 -- source of the ancestor.
6003 C
:= First_Component
(T
);
6004 while Present
(C
) loop
6005 if Is_Limited_Type
(Etype
(C
))
6007 (Comes_From_Source
(C
)
6009 (Present
(Original_Record_Component
(C
))
6011 Comes_From_Source
(Original_Record_Component
(C
))))
6013 Error_Msg_Node_2
:= T
;
6014 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
6015 Explain_Limited_Type
(Etype
(C
), N
);
6022 -- The type may be declared explicitly limited, even if no component
6023 -- of it is limited, in which case we fall out of the loop.
6026 end Explain_Limited_Type
;
6028 -------------------------------
6029 -- Extensions_Visible_Status --
6030 -------------------------------
6032 function Extensions_Visible_Status
6033 (Id
: Entity_Id
) return Extensions_Visible_Mode
6042 -- When a formal parameter is subject to Extensions_Visible, the pragma
6043 -- is stored in the contract of related subprogram.
6045 if Is_Formal
(Id
) then
6048 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
6051 -- No other construct carries this pragma
6054 return Extensions_Visible_None
;
6057 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
6059 -- In certain cases analysis may request the Extensions_Visible status
6060 -- of an expression function before the pragma has been analyzed yet.
6061 -- Inspect the declarative items after the expression function looking
6062 -- for the pragma (if any).
6064 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
6065 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
6066 while Present
(Decl
) loop
6067 if Nkind
(Decl
) = N_Pragma
6068 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
6073 -- A source construct ends the region where Extensions_Visible may
6074 -- appear, stop the traversal. An expanded expression function is
6075 -- no longer a source construct, but it must still be recognized.
6077 elsif Comes_From_Source
(Decl
)
6079 (Nkind_In
(Decl
, N_Subprogram_Body
,
6080 N_Subprogram_Declaration
)
6081 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
6090 -- Extract the value from the Boolean expression (if any)
6092 if Present
(Prag
) then
6093 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
6095 if Present
(Arg
) then
6096 Expr
:= Get_Pragma_Arg
(Arg
);
6098 -- When the associated subprogram is an expression function, the
6099 -- argument of the pragma may not have been analyzed.
6101 if not Analyzed
(Expr
) then
6102 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
6105 -- Guard against cascading errors when the argument of pragma
6106 -- Extensions_Visible is not a valid static Boolean expression.
6108 if Error_Posted
(Expr
) then
6109 return Extensions_Visible_None
;
6111 elsif Is_True
(Expr_Value
(Expr
)) then
6112 return Extensions_Visible_True
;
6115 return Extensions_Visible_False
;
6118 -- Otherwise the aspect or pragma defaults to True
6121 return Extensions_Visible_True
;
6124 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6125 -- directly specified. In SPARK code, its value defaults to "False".
6127 elsif SPARK_Mode
= On
then
6128 return Extensions_Visible_False
;
6130 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6134 return Extensions_Visible_True
;
6136 end Extensions_Visible_Status
;
6142 procedure Find_Actual
6144 Formal
: out Entity_Id
;
6147 Parnt
: constant Node_Id
:= Parent
(N
);
6151 if Nkind_In
(Parnt
, N_Indexed_Component
, N_Selected_Component
)
6152 and then N
= Prefix
(Parnt
)
6154 Find_Actual
(Parnt
, Formal
, Call
);
6157 elsif Nkind
(Parnt
) = N_Parameter_Association
6158 and then N
= Explicit_Actual_Parameter
(Parnt
)
6160 Call
:= Parent
(Parnt
);
6162 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
6171 -- If we have a call to a subprogram look for the parameter. Note that
6172 -- we exclude overloaded calls, since we don't know enough to be sure
6173 -- of giving the right answer in this case.
6175 if Nkind_In
(Call
, N_Function_Call
, N_Procedure_Call_Statement
)
6176 and then Is_Entity_Name
(Name
(Call
))
6177 and then Present
(Entity
(Name
(Call
)))
6178 and then Is_Overloadable
(Entity
(Name
(Call
)))
6179 and then not Is_Overloaded
(Name
(Call
))
6181 -- If node is name in call it is not an actual
6183 if N
= Name
(Call
) then
6189 -- Fall here if we are definitely a parameter
6191 Actual
:= First_Actual
(Call
);
6192 Formal
:= First_Formal
(Entity
(Name
(Call
)));
6193 while Present
(Formal
) and then Present
(Actual
) loop
6197 -- An actual that is the prefix in a prefixed call may have
6198 -- been rewritten in the call, after the deferred reference
6199 -- was collected. Check if sloc and kinds and names match.
6201 elsif Sloc
(Actual
) = Sloc
(N
)
6202 and then Nkind
(Actual
) = N_Identifier
6203 and then Nkind
(Actual
) = Nkind
(N
)
6204 and then Chars
(Actual
) = Chars
(N
)
6209 Actual
:= Next_Actual
(Actual
);
6210 Formal
:= Next_Formal
(Formal
);
6215 -- Fall through here if we did not find matching actual
6221 ---------------------------
6222 -- Find_Body_Discriminal --
6223 ---------------------------
6225 function Find_Body_Discriminal
6226 (Spec_Discriminant
: Entity_Id
) return Entity_Id
6232 -- If expansion is suppressed, then the scope can be the concurrent type
6233 -- itself rather than a corresponding concurrent record type.
6235 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
6236 Tsk
:= Scope
(Spec_Discriminant
);
6239 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
6241 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
6244 -- Find discriminant of original concurrent type, and use its current
6245 -- discriminal, which is the renaming within the task/protected body.
6247 Disc
:= First_Discriminant
(Tsk
);
6248 while Present
(Disc
) loop
6249 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
6250 return Discriminal
(Disc
);
6253 Next_Discriminant
(Disc
);
6256 -- That loop should always succeed in finding a matching entry and
6257 -- returning. Fatal error if not.
6259 raise Program_Error
;
6260 end Find_Body_Discriminal
;
6262 -------------------------------------
6263 -- Find_Corresponding_Discriminant --
6264 -------------------------------------
6266 function Find_Corresponding_Discriminant
6268 Typ
: Entity_Id
) return Entity_Id
6270 Par_Disc
: Entity_Id
;
6271 Old_Disc
: Entity_Id
;
6272 New_Disc
: Entity_Id
;
6275 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
6277 -- The original type may currently be private, and the discriminant
6278 -- only appear on its full view.
6280 if Is_Private_Type
(Scope
(Par_Disc
))
6281 and then not Has_Discriminants
(Scope
(Par_Disc
))
6282 and then Present
(Full_View
(Scope
(Par_Disc
)))
6284 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
6286 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
6289 if Is_Class_Wide_Type
(Typ
) then
6290 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
6292 New_Disc
:= First_Discriminant
(Typ
);
6295 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
6296 if Old_Disc
= Par_Disc
then
6300 Next_Discriminant
(Old_Disc
);
6301 Next_Discriminant
(New_Disc
);
6304 -- Should always find it
6306 raise Program_Error
;
6307 end Find_Corresponding_Discriminant
;
6309 ----------------------------------
6310 -- Find_Enclosing_Iterator_Loop --
6311 ----------------------------------
6313 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
6318 -- Traverse the scope chain looking for an iterator loop. Such loops are
6319 -- usually transformed into blocks, hence the use of Original_Node.
6322 while Present
(S
) and then S
/= Standard_Standard
loop
6323 if Ekind
(S
) = E_Loop
6324 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
6326 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
6328 if Nkind
(Constr
) = N_Loop_Statement
6329 and then Present
(Iteration_Scheme
(Constr
))
6330 and then Nkind
(Iterator_Specification
6331 (Iteration_Scheme
(Constr
))) =
6332 N_Iterator_Specification
6342 end Find_Enclosing_Iterator_Loop
;
6344 ------------------------------------
6345 -- Find_Loop_In_Conditional_Block --
6346 ------------------------------------
6348 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
6354 if Nkind
(Stmt
) = N_If_Statement
then
6355 Stmt
:= First
(Then_Statements
(Stmt
));
6358 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
6360 -- Inspect the statements of the conditional block. In general the loop
6361 -- should be the first statement in the statement sequence of the block,
6362 -- but the finalization machinery may have introduced extra object
6365 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
6366 while Present
(Stmt
) loop
6367 if Nkind
(Stmt
) = N_Loop_Statement
then
6374 -- The expansion of attribute 'Loop_Entry produced a malformed block
6376 raise Program_Error
;
6377 end Find_Loop_In_Conditional_Block
;
6379 --------------------------
6380 -- Find_Overlaid_Entity --
6381 --------------------------
6383 procedure Find_Overlaid_Entity
6385 Ent
: out Entity_Id
;
6391 -- We are looking for one of the two following forms:
6393 -- for X'Address use Y'Address
6397 -- Const : constant Address := expr;
6399 -- for X'Address use Const;
6401 -- In the second case, the expr is either Y'Address, or recursively a
6402 -- constant that eventually references Y'Address.
6407 if Nkind
(N
) = N_Attribute_Definition_Clause
6408 and then Chars
(N
) = Name_Address
6410 Expr
:= Expression
(N
);
6412 -- This loop checks the form of the expression for Y'Address,
6413 -- using recursion to deal with intermediate constants.
6416 -- Check for Y'Address
6418 if Nkind
(Expr
) = N_Attribute_Reference
6419 and then Attribute_Name
(Expr
) = Name_Address
6421 Expr
:= Prefix
(Expr
);
6424 -- Check for Const where Const is a constant entity
6426 elsif Is_Entity_Name
(Expr
)
6427 and then Ekind
(Entity
(Expr
)) = E_Constant
6429 Expr
:= Constant_Value
(Entity
(Expr
));
6431 -- Anything else does not need checking
6438 -- This loop checks the form of the prefix for an entity, using
6439 -- recursion to deal with intermediate components.
6442 -- Check for Y where Y is an entity
6444 if Is_Entity_Name
(Expr
) then
6445 Ent
:= Entity
(Expr
);
6448 -- Check for components
6451 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
6453 Expr
:= Prefix
(Expr
);
6456 -- Anything else does not need checking
6463 end Find_Overlaid_Entity
;
6465 -------------------------
6466 -- Find_Parameter_Type --
6467 -------------------------
6469 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
6471 if Nkind
(Param
) /= N_Parameter_Specification
then
6474 -- For an access parameter, obtain the type from the formal entity
6475 -- itself, because access to subprogram nodes do not carry a type.
6476 -- Shouldn't we always use the formal entity ???
6478 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
6479 return Etype
(Defining_Identifier
(Param
));
6482 return Etype
(Parameter_Type
(Param
));
6484 end Find_Parameter_Type
;
6486 -----------------------------------
6487 -- Find_Placement_In_State_Space --
6488 -----------------------------------
6490 procedure Find_Placement_In_State_Space
6491 (Item_Id
: Entity_Id
;
6492 Placement
: out State_Space_Kind
;
6493 Pack_Id
: out Entity_Id
)
6495 Context
: Entity_Id
;
6498 -- Assume that the item does not appear in the state space of a package
6500 Placement
:= Not_In_Package
;
6503 -- Climb the scope stack and examine the enclosing context
6505 Context
:= Scope
(Item_Id
);
6506 while Present
(Context
) and then Context
/= Standard_Standard
loop
6507 if Ekind
(Context
) = E_Package
then
6510 -- A package body is a cut off point for the traversal as the item
6511 -- cannot be visible to the outside from this point on. Note that
6512 -- this test must be done first as a body is also classified as a
6515 if In_Package_Body
(Context
) then
6516 Placement
:= Body_State_Space
;
6519 -- The private part of a package is a cut off point for the
6520 -- traversal as the item cannot be visible to the outside from
6523 elsif In_Private_Part
(Context
) then
6524 Placement
:= Private_State_Space
;
6527 -- When the item appears in the visible state space of a package,
6528 -- continue to climb the scope stack as this may not be the final
6532 Placement
:= Visible_State_Space
;
6534 -- The visible state space of a child unit acts as the proper
6535 -- placement of an item.
6537 if Is_Child_Unit
(Context
) then
6542 -- The item or its enclosing package appear in a construct that has
6546 Placement
:= Not_In_Package
;
6550 Context
:= Scope
(Context
);
6552 end Find_Placement_In_State_Space
;
6554 ------------------------
6555 -- Find_Specific_Type --
6556 ------------------------
6558 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
6559 Typ
: Entity_Id
:= Root_Type
(CW
);
6562 if Ekind
(Typ
) = E_Incomplete_Type
then
6563 if From_Limited_With
(Typ
) then
6564 Typ
:= Non_Limited_View
(Typ
);
6566 Typ
:= Full_View
(Typ
);
6570 if Is_Private_Type
(Typ
)
6571 and then not Is_Tagged_Type
(Typ
)
6572 and then Present
(Full_View
(Typ
))
6574 return Full_View
(Typ
);
6578 end Find_Specific_Type
;
6580 -----------------------------
6581 -- Find_Static_Alternative --
6582 -----------------------------
6584 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
6585 Expr
: constant Node_Id
:= Expression
(N
);
6586 Val
: constant Uint
:= Expr_Value
(Expr
);
6591 Alt
:= First
(Alternatives
(N
));
6594 if Nkind
(Alt
) /= N_Pragma
then
6595 Choice
:= First
(Discrete_Choices
(Alt
));
6596 while Present
(Choice
) loop
6598 -- Others choice, always matches
6600 if Nkind
(Choice
) = N_Others_Choice
then
6603 -- Range, check if value is in the range
6605 elsif Nkind
(Choice
) = N_Range
then
6607 Val
>= Expr_Value
(Low_Bound
(Choice
))
6609 Val
<= Expr_Value
(High_Bound
(Choice
));
6611 -- Choice is a subtype name. Note that we know it must
6612 -- be a static subtype, since otherwise it would have
6613 -- been diagnosed as illegal.
6615 elsif Is_Entity_Name
(Choice
)
6616 and then Is_Type
(Entity
(Choice
))
6618 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
6619 Assume_Valid
=> False);
6621 -- Choice is a subtype indication
6623 elsif Nkind
(Choice
) = N_Subtype_Indication
then
6625 C
: constant Node_Id
:= Constraint
(Choice
);
6626 R
: constant Node_Id
:= Range_Expression
(C
);
6630 Val
>= Expr_Value
(Low_Bound
(R
))
6632 Val
<= Expr_Value
(High_Bound
(R
));
6635 -- Choice is a simple expression
6638 exit Search
when Val
= Expr_Value
(Choice
);
6646 pragma Assert
(Present
(Alt
));
6649 -- The above loop *must* terminate by finding a match, since
6650 -- we know the case statement is valid, and the value of the
6651 -- expression is known at compile time. When we fall out of
6652 -- the loop, Alt points to the alternative that we know will
6653 -- be selected at run time.
6656 end Find_Static_Alternative
;
6662 function First_Actual
(Node
: Node_Id
) return Node_Id
is
6666 if No
(Parameter_Associations
(Node
)) then
6670 N
:= First
(Parameter_Associations
(Node
));
6672 if Nkind
(N
) = N_Parameter_Association
then
6673 return First_Named_Actual
(Node
);
6679 -----------------------
6680 -- Gather_Components --
6681 -----------------------
6683 procedure Gather_Components
6685 Comp_List
: Node_Id
;
6686 Governed_By
: List_Id
;
6688 Report_Errors
: out Boolean)
6692 Discrete_Choice
: Node_Id
;
6693 Comp_Item
: Node_Id
;
6695 Discrim
: Entity_Id
;
6696 Discrim_Name
: Node_Id
;
6697 Discrim_Value
: Node_Id
;
6700 Report_Errors
:= False;
6702 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
6705 elsif Present
(Component_Items
(Comp_List
)) then
6706 Comp_Item
:= First
(Component_Items
(Comp_List
));
6712 while Present
(Comp_Item
) loop
6714 -- Skip the tag of a tagged record, the interface tags, as well
6715 -- as all items that are not user components (anonymous types,
6716 -- rep clauses, Parent field, controller field).
6718 if Nkind
(Comp_Item
) = N_Component_Declaration
then
6720 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
6722 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
6723 Append_Elmt
(Comp
, Into
);
6731 if No
(Variant_Part
(Comp_List
)) then
6734 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
6735 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
6738 -- Look for the discriminant that governs this variant part.
6739 -- The discriminant *must* be in the Governed_By List
6741 Assoc
:= First
(Governed_By
);
6742 Find_Constraint
: loop
6743 Discrim
:= First
(Choices
(Assoc
));
6744 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
6745 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
6747 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
6748 Chars
(Discrim_Name
))
6749 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
6750 = Chars
(Discrim_Name
);
6752 if No
(Next
(Assoc
)) then
6753 if not Is_Constrained
(Typ
)
6754 and then Is_Derived_Type
(Typ
)
6755 and then Present
(Stored_Constraint
(Typ
))
6757 -- If the type is a tagged type with inherited discriminants,
6758 -- use the stored constraint on the parent in order to find
6759 -- the values of discriminants that are otherwise hidden by an
6760 -- explicit constraint. Renamed discriminants are handled in
6763 -- If several parent discriminants are renamed by a single
6764 -- discriminant of the derived type, the call to obtain the
6765 -- Corresponding_Discriminant field only retrieves the last
6766 -- of them. We recover the constraint on the others from the
6767 -- Stored_Constraint as well.
6774 D
:= First_Discriminant
(Etype
(Typ
));
6775 C
:= First_Elmt
(Stored_Constraint
(Typ
));
6776 while Present
(D
) and then Present
(C
) loop
6777 if Chars
(Discrim_Name
) = Chars
(D
) then
6778 if Is_Entity_Name
(Node
(C
))
6779 and then Entity
(Node
(C
)) = Entity
(Discrim
)
6781 -- D is renamed by Discrim, whose value is given in
6788 Make_Component_Association
(Sloc
(Typ
),
6790 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
6791 Duplicate_Subexpr_No_Checks
(Node
(C
)));
6793 exit Find_Constraint
;
6796 Next_Discriminant
(D
);
6803 if No
(Next
(Assoc
)) then
6804 Error_Msg_NE
(" missing value for discriminant&",
6805 First
(Governed_By
), Discrim_Name
);
6806 Report_Errors
:= True;
6811 end loop Find_Constraint
;
6813 Discrim_Value
:= Expression
(Assoc
);
6815 if not Is_OK_Static_Expression
(Discrim_Value
) then
6817 -- If the variant part is governed by a discriminant of the type
6818 -- this is an error. If the variant part and the discriminant are
6819 -- inherited from an ancestor this is legal (AI05-120) unless the
6820 -- components are being gathered for an aggregate, in which case
6821 -- the caller must check Report_Errors.
6823 if Scope
(Original_Record_Component
6824 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
6827 ("value for discriminant & must be static!",
6828 Discrim_Value
, Discrim
);
6829 Why_Not_Static
(Discrim_Value
);
6832 Report_Errors
:= True;
6836 Search_For_Discriminant_Value
: declare
6842 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
6845 Find_Discrete_Value
: while Present
(Variant
) loop
6846 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
6847 while Present
(Discrete_Choice
) loop
6848 exit Find_Discrete_Value
when
6849 Nkind
(Discrete_Choice
) = N_Others_Choice
;
6851 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
6853 UI_Low
:= Expr_Value
(Low
);
6854 UI_High
:= Expr_Value
(High
);
6856 exit Find_Discrete_Value
when
6857 UI_Low
<= UI_Discrim_Value
6859 UI_High
>= UI_Discrim_Value
;
6861 Next
(Discrete_Choice
);
6864 Next_Non_Pragma
(Variant
);
6865 end loop Find_Discrete_Value
;
6866 end Search_For_Discriminant_Value
;
6868 if No
(Variant
) then
6870 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
6871 Report_Errors
:= True;
6875 -- If we have found the corresponding choice, recursively add its
6876 -- components to the Into list.
6879 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
6880 end Gather_Components
;
6882 ------------------------
6883 -- Get_Actual_Subtype --
6884 ------------------------
6886 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
6887 Typ
: constant Entity_Id
:= Etype
(N
);
6888 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
6897 -- If what we have is an identifier that references a subprogram
6898 -- formal, or a variable or constant object, then we get the actual
6899 -- subtype from the referenced entity if one has been built.
6901 if Nkind
(N
) = N_Identifier
6903 (Is_Formal
(Entity
(N
))
6904 or else Ekind
(Entity
(N
)) = E_Constant
6905 or else Ekind
(Entity
(N
)) = E_Variable
)
6906 and then Present
(Actual_Subtype
(Entity
(N
)))
6908 return Actual_Subtype
(Entity
(N
));
6910 -- Actual subtype of unchecked union is always itself. We never need
6911 -- the "real" actual subtype. If we did, we couldn't get it anyway
6912 -- because the discriminant is not available. The restrictions on
6913 -- Unchecked_Union are designed to make sure that this is OK.
6915 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
6918 -- Here for the unconstrained case, we must find actual subtype
6919 -- No actual subtype is available, so we must build it on the fly.
6921 -- Checking the type, not the underlying type, for constrainedness
6922 -- seems to be necessary. Maybe all the tests should be on the type???
6924 elsif (not Is_Constrained
(Typ
))
6925 and then (Is_Array_Type
(Utyp
)
6926 or else (Is_Record_Type
(Utyp
)
6927 and then Has_Discriminants
(Utyp
)))
6928 and then not Has_Unknown_Discriminants
(Utyp
)
6929 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
6931 -- Nothing to do if in spec expression (why not???)
6933 if In_Spec_Expression
then
6936 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
6938 -- If the type has no discriminants, there is no subtype to
6939 -- build, even if the underlying type is discriminated.
6943 -- Else build the actual subtype
6946 Decl
:= Build_Actual_Subtype
(Typ
, N
);
6947 Atyp
:= Defining_Identifier
(Decl
);
6949 -- If Build_Actual_Subtype generated a new declaration then use it
6953 -- The actual subtype is an Itype, so analyze the declaration,
6954 -- but do not attach it to the tree, to get the type defined.
6956 Set_Parent
(Decl
, N
);
6957 Set_Is_Itype
(Atyp
);
6958 Analyze
(Decl
, Suppress
=> All_Checks
);
6959 Set_Associated_Node_For_Itype
(Atyp
, N
);
6960 Set_Has_Delayed_Freeze
(Atyp
, False);
6962 -- We need to freeze the actual subtype immediately. This is
6963 -- needed, because otherwise this Itype will not get frozen
6964 -- at all, and it is always safe to freeze on creation because
6965 -- any associated types must be frozen at this point.
6967 Freeze_Itype
(Atyp
, N
);
6970 -- Otherwise we did not build a declaration, so return original
6977 -- For all remaining cases, the actual subtype is the same as
6978 -- the nominal type.
6983 end Get_Actual_Subtype
;
6985 -------------------------------------
6986 -- Get_Actual_Subtype_If_Available --
6987 -------------------------------------
6989 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
6990 Typ
: constant Entity_Id
:= Etype
(N
);
6993 -- If what we have is an identifier that references a subprogram
6994 -- formal, or a variable or constant object, then we get the actual
6995 -- subtype from the referenced entity if one has been built.
6997 if Nkind
(N
) = N_Identifier
6999 (Is_Formal
(Entity
(N
))
7000 or else Ekind
(Entity
(N
)) = E_Constant
7001 or else Ekind
(Entity
(N
)) = E_Variable
)
7002 and then Present
(Actual_Subtype
(Entity
(N
)))
7004 return Actual_Subtype
(Entity
(N
));
7006 -- Otherwise the Etype of N is returned unchanged
7011 end Get_Actual_Subtype_If_Available
;
7013 ------------------------
7014 -- Get_Body_From_Stub --
7015 ------------------------
7017 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
7019 return Proper_Body
(Unit
(Library_Unit
(N
)));
7020 end Get_Body_From_Stub
;
7022 ---------------------
7023 -- Get_Cursor_Type --
7024 ---------------------
7026 function Get_Cursor_Type
7028 Typ
: Entity_Id
) return Entity_Id
7032 First_Op
: Entity_Id
;
7036 -- If error already detected, return
7038 if Error_Posted
(Aspect
) then
7042 -- The cursor type for an Iterable aspect is the return type of a
7043 -- non-overloaded First primitive operation. Locate association for
7046 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
7048 while Present
(Assoc
) loop
7049 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
7050 First_Op
:= Expression
(Assoc
);
7057 if First_Op
= Any_Id
then
7058 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
7064 -- Locate function with desired name and profile in scope of type
7066 Func
:= First_Entity
(Scope
(Typ
));
7067 while Present
(Func
) loop
7068 if Chars
(Func
) = Chars
(First_Op
)
7069 and then Ekind
(Func
) = E_Function
7070 and then Present
(First_Formal
(Func
))
7071 and then Etype
(First_Formal
(Func
)) = Typ
7072 and then No
(Next_Formal
(First_Formal
(Func
)))
7074 if Cursor
/= Any_Type
then
7076 ("Operation First for iterable type must be unique", Aspect
);
7079 Cursor
:= Etype
(Func
);
7086 -- If not found, no way to resolve remaining primitives.
7088 if Cursor
= Any_Type
then
7090 ("No legal primitive operation First for Iterable type", Aspect
);
7094 end Get_Cursor_Type
;
7096 -------------------------------
7097 -- Get_Default_External_Name --
7098 -------------------------------
7100 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
7102 Get_Decoded_Name_String
(Chars
(E
));
7104 if Opt
.External_Name_Imp_Casing
= Uppercase
then
7105 Set_Casing
(All_Upper_Case
);
7107 Set_Casing
(All_Lower_Case
);
7111 Make_String_Literal
(Sloc
(E
),
7112 Strval
=> String_From_Name_Buffer
);
7113 end Get_Default_External_Name
;
7115 --------------------------
7116 -- Get_Enclosing_Object --
7117 --------------------------
7119 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
7121 if Is_Entity_Name
(N
) then
7125 when N_Indexed_Component |
7127 N_Selected_Component
=>
7129 -- If not generating code, a dereference may be left implicit.
7130 -- In thoses cases, return Empty.
7132 if Is_Access_Type
(Etype
(Prefix
(N
))) then
7135 return Get_Enclosing_Object
(Prefix
(N
));
7138 when N_Type_Conversion
=>
7139 return Get_Enclosing_Object
(Expression
(N
));
7145 end Get_Enclosing_Object
;
7147 ---------------------------
7148 -- Get_Enum_Lit_From_Pos --
7149 ---------------------------
7151 function Get_Enum_Lit_From_Pos
7154 Loc
: Source_Ptr
) return Node_Id
7156 Btyp
: Entity_Id
:= Base_Type
(T
);
7160 -- In the case where the literal is of type Character, Wide_Character
7161 -- or Wide_Wide_Character or of a type derived from them, there needs
7162 -- to be some special handling since there is no explicit chain of
7163 -- literals to search. Instead, an N_Character_Literal node is created
7164 -- with the appropriate Char_Code and Chars fields.
7166 if Is_Standard_Character_Type
(T
) then
7167 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
7169 Make_Character_Literal
(Loc
,
7171 Char_Literal_Value
=> Pos
);
7173 -- For all other cases, we have a complete table of literals, and
7174 -- we simply iterate through the chain of literal until the one
7175 -- with the desired position value is found.
7178 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
7179 Btyp
:= Full_View
(Btyp
);
7182 Lit
:= First_Literal
(Btyp
);
7183 for J
in 1 .. UI_To_Int
(Pos
) loop
7187 return New_Occurrence_Of
(Lit
, Loc
);
7189 end Get_Enum_Lit_From_Pos
;
7191 ------------------------
7192 -- Get_Generic_Entity --
7193 ------------------------
7195 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
7196 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
7198 if Present
(Renamed_Object
(Ent
)) then
7199 return Renamed_Object
(Ent
);
7203 end Get_Generic_Entity
;
7205 -------------------------------------
7206 -- Get_Incomplete_View_Of_Ancestor --
7207 -------------------------------------
7209 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
7210 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
7211 Par_Scope
: Entity_Id
;
7212 Par_Type
: Entity_Id
;
7215 -- The incomplete view of an ancestor is only relevant for private
7216 -- derived types in child units.
7218 if not Is_Derived_Type
(E
)
7219 or else not Is_Child_Unit
(Cur_Unit
)
7224 Par_Scope
:= Scope
(Cur_Unit
);
7225 if No
(Par_Scope
) then
7229 Par_Type
:= Etype
(Base_Type
(E
));
7231 -- Traverse list of ancestor types until we find one declared in
7232 -- a parent or grandparent unit (two levels seem sufficient).
7234 while Present
(Par_Type
) loop
7235 if Scope
(Par_Type
) = Par_Scope
7236 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
7240 elsif not Is_Derived_Type
(Par_Type
) then
7244 Par_Type
:= Etype
(Base_Type
(Par_Type
));
7248 -- If none found, there is no relevant ancestor type.
7252 end Get_Incomplete_View_Of_Ancestor
;
7254 ----------------------
7255 -- Get_Index_Bounds --
7256 ----------------------
7258 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
7259 Kind
: constant Node_Kind
:= Nkind
(N
);
7263 if Kind
= N_Range
then
7265 H
:= High_Bound
(N
);
7267 elsif Kind
= N_Subtype_Indication
then
7268 R
:= Range_Expression
(Constraint
(N
));
7276 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
7277 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
7280 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
7281 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
7285 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
7286 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
7289 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
7290 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
7294 -- N is an expression, indicating a range with one value
7299 end Get_Index_Bounds
;
7301 ---------------------------------
7302 -- Get_Iterable_Type_Primitive --
7303 ---------------------------------
7305 function Get_Iterable_Type_Primitive
7307 Nam
: Name_Id
) return Entity_Id
7309 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
7317 Assoc
:= First
(Component_Associations
(Funcs
));
7318 while Present
(Assoc
) loop
7319 if Chars
(First
(Choices
(Assoc
))) = Nam
then
7320 return Entity
(Expression
(Assoc
));
7323 Assoc
:= Next
(Assoc
);
7328 end Get_Iterable_Type_Primitive
;
7330 ----------------------------------
7331 -- Get_Library_Unit_Name_string --
7332 ----------------------------------
7334 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
7335 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
7338 Get_Unit_Name_String
(Unit_Name_Id
);
7340 -- Remove seven last character (" (spec)" or " (body)")
7342 Name_Len
:= Name_Len
- 7;
7343 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
7344 end Get_Library_Unit_Name_String
;
7346 ------------------------
7347 -- Get_Name_Entity_Id --
7348 ------------------------
7350 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
7352 return Entity_Id
(Get_Name_Table_Int
(Id
));
7353 end Get_Name_Entity_Id
;
7355 ------------------------------
7356 -- Get_Name_From_CTC_Pragma --
7357 ------------------------------
7359 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
7360 Arg
: constant Node_Id
:=
7361 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
7363 return Strval
(Expr_Value_S
(Arg
));
7364 end Get_Name_From_CTC_Pragma
;
7366 -----------------------
7367 -- Get_Parent_Entity --
7368 -----------------------
7370 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
7372 if Nkind
(Unit
) = N_Package_Body
7373 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
7375 return Defining_Entity
7376 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
7377 elsif Nkind
(Unit
) = N_Package_Instantiation
then
7378 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
7380 return Defining_Entity
(Unit
);
7382 end Get_Parent_Entity
;
7387 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
7389 return Get_Pragma_Id
(Pragma_Name
(N
));
7392 -----------------------
7393 -- Get_Reason_String --
7394 -----------------------
7396 procedure Get_Reason_String
(N
: Node_Id
) is
7398 if Nkind
(N
) = N_String_Literal
then
7399 Store_String_Chars
(Strval
(N
));
7401 elsif Nkind
(N
) = N_Op_Concat
then
7402 Get_Reason_String
(Left_Opnd
(N
));
7403 Get_Reason_String
(Right_Opnd
(N
));
7405 -- If not of required form, error
7409 ("Reason for pragma Warnings has wrong form", N
);
7411 ("\must be string literal or concatenation of string literals", N
);
7414 end Get_Reason_String
;
7416 ---------------------------
7417 -- Get_Referenced_Object --
7418 ---------------------------
7420 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
7425 while Is_Entity_Name
(R
)
7426 and then Present
(Renamed_Object
(Entity
(R
)))
7428 R
:= Renamed_Object
(Entity
(R
));
7432 end Get_Referenced_Object
;
7434 ------------------------
7435 -- Get_Renamed_Entity --
7436 ------------------------
7438 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
7443 while Present
(Renamed_Entity
(R
)) loop
7444 R
:= Renamed_Entity
(R
);
7448 end Get_Renamed_Entity
;
7450 -------------------------
7451 -- Get_Subprogram_Body --
7452 -------------------------
7454 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
7458 Decl
:= Unit_Declaration_Node
(E
);
7460 if Nkind
(Decl
) = N_Subprogram_Body
then
7463 -- The below comment is bad, because it is possible for
7464 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7466 else -- Nkind (Decl) = N_Subprogram_Declaration
7468 if Present
(Corresponding_Body
(Decl
)) then
7469 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
7471 -- Imported subprogram case
7477 end Get_Subprogram_Body
;
7479 ---------------------------
7480 -- Get_Subprogram_Entity --
7481 ---------------------------
7483 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
7485 Subp_Id
: Entity_Id
;
7488 if Nkind
(Nod
) = N_Accept_Statement
then
7489 Subp
:= Entry_Direct_Name
(Nod
);
7491 elsif Nkind
(Nod
) = N_Slice
then
7492 Subp
:= Prefix
(Nod
);
7498 -- Strip the subprogram call
7501 if Nkind_In
(Subp
, N_Explicit_Dereference
,
7502 N_Indexed_Component
,
7503 N_Selected_Component
)
7505 Subp
:= Prefix
(Subp
);
7507 elsif Nkind_In
(Subp
, N_Type_Conversion
,
7508 N_Unchecked_Type_Conversion
)
7510 Subp
:= Expression
(Subp
);
7517 -- Extract the entity of the subprogram call
7519 if Is_Entity_Name
(Subp
) then
7520 Subp_Id
:= Entity
(Subp
);
7522 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
7523 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
7526 if Is_Subprogram
(Subp_Id
) then
7532 -- The search did not find a construct that denotes a subprogram
7537 end Get_Subprogram_Entity
;
7539 -----------------------------
7540 -- Get_Task_Body_Procedure --
7541 -----------------------------
7543 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
7545 -- Note: A task type may be the completion of a private type with
7546 -- discriminants. When performing elaboration checks on a task
7547 -- declaration, the current view of the type may be the private one,
7548 -- and the procedure that holds the body of the task is held in its
7551 -- This is an odd function, why not have Task_Body_Procedure do
7552 -- the following digging???
7554 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
7555 end Get_Task_Body_Procedure
;
7557 -----------------------
7558 -- Has_Access_Values --
7559 -----------------------
7561 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
7562 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
7565 -- Case of a private type which is not completed yet. This can only
7566 -- happen in the case of a generic format type appearing directly, or
7567 -- as a component of the type to which this function is being applied
7568 -- at the top level. Return False in this case, since we certainly do
7569 -- not know that the type contains access types.
7574 elsif Is_Access_Type
(Typ
) then
7577 elsif Is_Array_Type
(Typ
) then
7578 return Has_Access_Values
(Component_Type
(Typ
));
7580 elsif Is_Record_Type
(Typ
) then
7585 -- Loop to Check components
7587 Comp
:= First_Component_Or_Discriminant
(Typ
);
7588 while Present
(Comp
) loop
7590 -- Check for access component, tag field does not count, even
7591 -- though it is implemented internally using an access type.
7593 if Has_Access_Values
(Etype
(Comp
))
7594 and then Chars
(Comp
) /= Name_uTag
7599 Next_Component_Or_Discriminant
(Comp
);
7608 end Has_Access_Values
;
7610 ------------------------------
7611 -- Has_Compatible_Alignment --
7612 ------------------------------
7614 function Has_Compatible_Alignment
7616 Expr
: Node_Id
) return Alignment_Result
7618 function Has_Compatible_Alignment_Internal
7621 Default
: Alignment_Result
) return Alignment_Result
;
7622 -- This is the internal recursive function that actually does the work.
7623 -- There is one additional parameter, which says what the result should
7624 -- be if no alignment information is found, and there is no definite
7625 -- indication of compatible alignments. At the outer level, this is set
7626 -- to Unknown, but for internal recursive calls in the case where types
7627 -- are known to be correct, it is set to Known_Compatible.
7629 ---------------------------------------
7630 -- Has_Compatible_Alignment_Internal --
7631 ---------------------------------------
7633 function Has_Compatible_Alignment_Internal
7636 Default
: Alignment_Result
) return Alignment_Result
7638 Result
: Alignment_Result
:= Known_Compatible
;
7639 -- Holds the current status of the result. Note that once a value of
7640 -- Known_Incompatible is set, it is sticky and does not get changed
7641 -- to Unknown (the value in Result only gets worse as we go along,
7644 Offs
: Uint
:= No_Uint
;
7645 -- Set to a factor of the offset from the base object when Expr is a
7646 -- selected or indexed component, based on Component_Bit_Offset and
7647 -- Component_Size respectively. A negative value is used to represent
7648 -- a value which is not known at compile time.
7650 procedure Check_Prefix
;
7651 -- Checks the prefix recursively in the case where the expression
7652 -- is an indexed or selected component.
7654 procedure Set_Result
(R
: Alignment_Result
);
7655 -- If R represents a worse outcome (unknown instead of known
7656 -- compatible, or known incompatible), then set Result to R.
7662 procedure Check_Prefix
is
7664 -- The subtlety here is that in doing a recursive call to check
7665 -- the prefix, we have to decide what to do in the case where we
7666 -- don't find any specific indication of an alignment problem.
7668 -- At the outer level, we normally set Unknown as the result in
7669 -- this case, since we can only set Known_Compatible if we really
7670 -- know that the alignment value is OK, but for the recursive
7671 -- call, in the case where the types match, and we have not
7672 -- specified a peculiar alignment for the object, we are only
7673 -- concerned about suspicious rep clauses, the default case does
7674 -- not affect us, since the compiler will, in the absence of such
7675 -- rep clauses, ensure that the alignment is correct.
7677 if Default
= Known_Compatible
7679 (Etype
(Obj
) = Etype
(Expr
)
7680 and then (Unknown_Alignment
(Obj
)
7682 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
7685 (Has_Compatible_Alignment_Internal
7686 (Obj
, Prefix
(Expr
), Known_Compatible
));
7688 -- In all other cases, we need a full check on the prefix
7692 (Has_Compatible_Alignment_Internal
7693 (Obj
, Prefix
(Expr
), Unknown
));
7701 procedure Set_Result
(R
: Alignment_Result
) is
7708 -- Start of processing for Has_Compatible_Alignment_Internal
7711 -- If Expr is a selected component, we must make sure there is no
7712 -- potentially troublesome component clause, and that the record is
7715 if Nkind
(Expr
) = N_Selected_Component
then
7717 -- Packed record always generate unknown alignment
7719 if Is_Packed
(Etype
(Prefix
(Expr
))) then
7720 Set_Result
(Unknown
);
7723 -- Check prefix and component offset
7726 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
7728 -- If Expr is an indexed component, we must make sure there is no
7729 -- potentially troublesome Component_Size clause and that the array
7730 -- is not bit-packed.
7732 elsif Nkind
(Expr
) = N_Indexed_Component
then
7734 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
7735 Ind
: constant Node_Id
:= First_Index
(Typ
);
7738 -- Bit packed array always generates unknown alignment
7740 if Is_Bit_Packed_Array
(Typ
) then
7741 Set_Result
(Unknown
);
7744 -- Check prefix and component offset
7747 Offs
:= Component_Size
(Typ
);
7749 -- Small optimization: compute the full offset when possible
7752 and then Offs
> Uint_0
7753 and then Present
(Ind
)
7754 and then Nkind
(Ind
) = N_Range
7755 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
7756 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
7758 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
7759 - Expr_Value
(Low_Bound
((Ind
))));
7764 -- If we have a null offset, the result is entirely determined by
7765 -- the base object and has already been computed recursively.
7767 if Offs
= Uint_0
then
7770 -- Case where we know the alignment of the object
7772 elsif Known_Alignment
(Obj
) then
7774 ObjA
: constant Uint
:= Alignment
(Obj
);
7775 ExpA
: Uint
:= No_Uint
;
7776 SizA
: Uint
:= No_Uint
;
7779 -- If alignment of Obj is 1, then we are always OK
7782 Set_Result
(Known_Compatible
);
7784 -- Alignment of Obj is greater than 1, so we need to check
7787 -- If we have an offset, see if it is compatible
7789 if Offs
/= No_Uint
and Offs
> Uint_0
then
7790 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
7791 Set_Result
(Known_Incompatible
);
7794 -- See if Expr is an object with known alignment
7796 elsif Is_Entity_Name
(Expr
)
7797 and then Known_Alignment
(Entity
(Expr
))
7799 ExpA
:= Alignment
(Entity
(Expr
));
7801 -- Otherwise, we can use the alignment of the type of
7802 -- Expr given that we already checked for
7803 -- discombobulating rep clauses for the cases of indexed
7804 -- and selected components above.
7806 elsif Known_Alignment
(Etype
(Expr
)) then
7807 ExpA
:= Alignment
(Etype
(Expr
));
7809 -- Otherwise the alignment is unknown
7812 Set_Result
(Default
);
7815 -- If we got an alignment, see if it is acceptable
7817 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
7818 Set_Result
(Known_Incompatible
);
7821 -- If Expr is not a piece of a larger object, see if size
7822 -- is given. If so, check that it is not too small for the
7823 -- required alignment.
7825 if Offs
/= No_Uint
then
7828 -- See if Expr is an object with known size
7830 elsif Is_Entity_Name
(Expr
)
7831 and then Known_Static_Esize
(Entity
(Expr
))
7833 SizA
:= Esize
(Entity
(Expr
));
7835 -- Otherwise, we check the object size of the Expr type
7837 elsif Known_Static_Esize
(Etype
(Expr
)) then
7838 SizA
:= Esize
(Etype
(Expr
));
7841 -- If we got a size, see if it is a multiple of the Obj
7842 -- alignment, if not, then the alignment cannot be
7843 -- acceptable, since the size is always a multiple of the
7846 if SizA
/= No_Uint
then
7847 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
7848 Set_Result
(Known_Incompatible
);
7854 -- If we do not know required alignment, any non-zero offset is a
7855 -- potential problem (but certainly may be OK, so result is unknown).
7857 elsif Offs
/= No_Uint
then
7858 Set_Result
(Unknown
);
7860 -- If we can't find the result by direct comparison of alignment
7861 -- values, then there is still one case that we can determine known
7862 -- result, and that is when we can determine that the types are the
7863 -- same, and no alignments are specified. Then we known that the
7864 -- alignments are compatible, even if we don't know the alignment
7865 -- value in the front end.
7867 elsif Etype
(Obj
) = Etype
(Expr
) then
7869 -- Types are the same, but we have to check for possible size
7870 -- and alignments on the Expr object that may make the alignment
7871 -- different, even though the types are the same.
7873 if Is_Entity_Name
(Expr
) then
7875 -- First check alignment of the Expr object. Any alignment less
7876 -- than Maximum_Alignment is worrisome since this is the case
7877 -- where we do not know the alignment of Obj.
7879 if Known_Alignment
(Entity
(Expr
))
7880 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
7881 Ttypes
.Maximum_Alignment
7883 Set_Result
(Unknown
);
7885 -- Now check size of Expr object. Any size that is not an
7886 -- even multiple of Maximum_Alignment is also worrisome
7887 -- since it may cause the alignment of the object to be less
7888 -- than the alignment of the type.
7890 elsif Known_Static_Esize
(Entity
(Expr
))
7892 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
7893 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
7896 Set_Result
(Unknown
);
7898 -- Otherwise same type is decisive
7901 Set_Result
(Known_Compatible
);
7905 -- Another case to deal with is when there is an explicit size or
7906 -- alignment clause when the types are not the same. If so, then the
7907 -- result is Unknown. We don't need to do this test if the Default is
7908 -- Unknown, since that result will be set in any case.
7910 elsif Default
/= Unknown
7911 and then (Has_Size_Clause
(Etype
(Expr
))
7913 Has_Alignment_Clause
(Etype
(Expr
)))
7915 Set_Result
(Unknown
);
7917 -- If no indication found, set default
7920 Set_Result
(Default
);
7923 -- Return worst result found
7926 end Has_Compatible_Alignment_Internal
;
7928 -- Start of processing for Has_Compatible_Alignment
7931 -- If Obj has no specified alignment, then set alignment from the type
7932 -- alignment. Perhaps we should always do this, but for sure we should
7933 -- do it when there is an address clause since we can do more if the
7934 -- alignment is known.
7936 if Unknown_Alignment
(Obj
) then
7937 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
7940 -- Now do the internal call that does all the work
7942 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
7943 end Has_Compatible_Alignment
;
7945 ----------------------
7946 -- Has_Declarations --
7947 ----------------------
7949 function Has_Declarations
(N
: Node_Id
) return Boolean is
7951 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
7953 N_Compilation_Unit_Aux
,
7959 N_Package_Specification
);
7960 end Has_Declarations
;
7962 ---------------------------------
7963 -- Has_Defaulted_Discriminants --
7964 ---------------------------------
7966 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
7968 return Has_Discriminants
(Typ
)
7969 and then Present
(First_Discriminant
(Typ
))
7970 and then Present
(Discriminant_Default_Value
7971 (First_Discriminant
(Typ
)));
7972 end Has_Defaulted_Discriminants
;
7978 function Has_Denormals
(E
: Entity_Id
) return Boolean is
7980 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
7983 -------------------------------------------
7984 -- Has_Discriminant_Dependent_Constraint --
7985 -------------------------------------------
7987 function Has_Discriminant_Dependent_Constraint
7988 (Comp
: Entity_Id
) return Boolean
7990 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7991 Subt_Indic
: Node_Id
;
7996 -- Discriminants can't depend on discriminants
7998 if Ekind
(Comp
) = E_Discriminant
then
8002 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
8004 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
8005 Constr
:= Constraint
(Subt_Indic
);
8007 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
8008 Assn
:= First
(Constraints
(Constr
));
8009 while Present
(Assn
) loop
8010 case Nkind
(Assn
) is
8011 when N_Subtype_Indication |
8015 if Depends_On_Discriminant
(Assn
) then
8019 when N_Discriminant_Association
=>
8020 if Depends_On_Discriminant
(Expression
(Assn
)) then
8035 end Has_Discriminant_Dependent_Constraint
;
8037 --------------------------
8038 -- Has_Enabled_Property --
8039 --------------------------
8041 function Has_Enabled_Property
8042 (Item_Id
: Entity_Id
;
8043 Property
: Name_Id
) return Boolean
8045 function State_Has_Enabled_Property
return Boolean;
8046 -- Determine whether a state denoted by Item_Id has the property enabled
8048 function Variable_Has_Enabled_Property
return Boolean;
8049 -- Determine whether a variable denoted by Item_Id has the property
8052 --------------------------------
8053 -- State_Has_Enabled_Property --
8054 --------------------------------
8056 function State_Has_Enabled_Property
return Boolean is
8057 Decl
: constant Node_Id
:= Parent
(Item_Id
);
8065 -- The declaration of an external abstract state appears as an
8066 -- extension aggregate. If this is not the case, properties can never
8069 if Nkind
(Decl
) /= N_Extension_Aggregate
then
8073 -- When External appears as a simple option, it automatically enables
8076 Opt
:= First
(Expressions
(Decl
));
8077 while Present
(Opt
) loop
8078 if Nkind
(Opt
) = N_Identifier
8079 and then Chars
(Opt
) = Name_External
8087 -- When External specifies particular properties, inspect those and
8088 -- find the desired one (if any).
8090 Opt
:= First
(Component_Associations
(Decl
));
8091 while Present
(Opt
) loop
8092 Opt_Nam
:= First
(Choices
(Opt
));
8094 if Nkind
(Opt_Nam
) = N_Identifier
8095 and then Chars
(Opt_Nam
) = Name_External
8097 Props
:= Expression
(Opt
);
8099 -- Multiple properties appear as an aggregate
8101 if Nkind
(Props
) = N_Aggregate
then
8103 -- Simple property form
8105 Prop
:= First
(Expressions
(Props
));
8106 while Present
(Prop
) loop
8107 if Chars
(Prop
) = Property
then
8114 -- Property with expression form
8116 Prop
:= First
(Component_Associations
(Props
));
8117 while Present
(Prop
) loop
8118 Prop_Nam
:= First
(Choices
(Prop
));
8120 -- The property can be represented in two ways:
8121 -- others => <value>
8122 -- <property> => <value>
8124 if Nkind
(Prop_Nam
) = N_Others_Choice
8125 or else (Nkind
(Prop_Nam
) = N_Identifier
8126 and then Chars
(Prop_Nam
) = Property
)
8128 return Is_True
(Expr_Value
(Expression
(Prop
)));
8137 return Chars
(Props
) = Property
;
8145 end State_Has_Enabled_Property
;
8147 -----------------------------------
8148 -- Variable_Has_Enabled_Property --
8149 -----------------------------------
8151 function Variable_Has_Enabled_Property
return Boolean is
8152 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
8153 -- Determine whether property pragma Prag (if present) denotes an
8154 -- enabled property.
8160 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
8164 if Present
(Prag
) then
8165 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
8167 -- The pragma has an optional Boolean expression, the related
8168 -- property is enabled only when the expression evaluates to
8171 if Present
(Arg2
) then
8172 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg2
)));
8174 -- Otherwise the lack of expression enables the property by
8181 -- The property was never set in the first place
8190 AR
: constant Node_Id
:=
8191 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
8192 AW
: constant Node_Id
:=
8193 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
8194 ER
: constant Node_Id
:=
8195 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
8196 EW
: constant Node_Id
:=
8197 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
8199 -- Start of processing for Variable_Has_Enabled_Property
8202 -- A non-effectively volatile object can never possess external
8205 if not Is_Effectively_Volatile
(Item_Id
) then
8208 -- External properties related to variables come in two flavors -
8209 -- explicit and implicit. The explicit case is characterized by the
8210 -- presence of a property pragma with an optional Boolean flag. The
8211 -- property is enabled when the flag evaluates to True or the flag is
8212 -- missing altogether.
8214 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
8217 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
8220 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
8223 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
8226 -- The implicit case lacks all property pragmas
8228 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
8234 end Variable_Has_Enabled_Property
;
8236 -- Start of processing for Has_Enabled_Property
8239 -- Abstract states and variables have a flexible scheme of specifying
8240 -- external properties.
8242 if Ekind
(Item_Id
) = E_Abstract_State
then
8243 return State_Has_Enabled_Property
;
8245 elsif Ekind
(Item_Id
) = E_Variable
then
8246 return Variable_Has_Enabled_Property
;
8248 -- Otherwise a property is enabled when the related item is effectively
8252 return Is_Effectively_Volatile
(Item_Id
);
8254 end Has_Enabled_Property
;
8256 --------------------
8257 -- Has_Infinities --
8258 --------------------
8260 function Has_Infinities
(E
: Entity_Id
) return Boolean is
8263 Is_Floating_Point_Type
(E
)
8264 and then Nkind
(Scalar_Range
(E
)) = N_Range
8265 and then Includes_Infinities
(Scalar_Range
(E
));
8268 --------------------
8269 -- Has_Interfaces --
8270 --------------------
8272 function Has_Interfaces
8274 Use_Full_View
: Boolean := True) return Boolean
8276 Typ
: Entity_Id
:= Base_Type
(T
);
8279 -- Handle concurrent types
8281 if Is_Concurrent_Type
(Typ
) then
8282 Typ
:= Corresponding_Record_Type
(Typ
);
8285 if not Present
(Typ
)
8286 or else not Is_Record_Type
(Typ
)
8287 or else not Is_Tagged_Type
(Typ
)
8292 -- Handle private types
8294 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
8295 Typ
:= Full_View
(Typ
);
8298 -- Handle concurrent record types
8300 if Is_Concurrent_Record_Type
(Typ
)
8301 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
8307 if Is_Interface
(Typ
)
8309 (Is_Record_Type
(Typ
)
8310 and then Present
(Interfaces
(Typ
))
8311 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
8316 exit when Etype
(Typ
) = Typ
8318 -- Handle private types
8320 or else (Present
(Full_View
(Etype
(Typ
)))
8321 and then Full_View
(Etype
(Typ
)) = Typ
)
8323 -- Protect frontend against wrong sources with cyclic derivations
8325 or else Etype
(Typ
) = T
;
8327 -- Climb to the ancestor type handling private types
8329 if Present
(Full_View
(Etype
(Typ
))) then
8330 Typ
:= Full_View
(Etype
(Typ
));
8339 ---------------------------------
8340 -- Has_No_Obvious_Side_Effects --
8341 ---------------------------------
8343 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
8345 -- For now, just handle literals, constants, and non-volatile
8346 -- variables and expressions combining these with operators or
8347 -- short circuit forms.
8349 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
8352 elsif Nkind
(N
) = N_Character_Literal
then
8355 elsif Nkind
(N
) in N_Unary_Op
then
8356 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8358 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
8359 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
8361 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8363 elsif Nkind
(N
) = N_Expression_With_Actions
8364 and then Is_Empty_List
(Actions
(N
))
8366 return Has_No_Obvious_Side_Effects
(Expression
(N
));
8368 elsif Nkind
(N
) in N_Has_Entity
then
8369 return Present
(Entity
(N
))
8370 and then Ekind_In
(Entity
(N
), E_Variable
,
8372 E_Enumeration_Literal
,
8376 and then not Is_Volatile
(Entity
(N
));
8381 end Has_No_Obvious_Side_Effects
;
8383 ------------------------
8384 -- Has_Null_Exclusion --
8385 ------------------------
8387 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
8390 when N_Access_Definition |
8391 N_Access_Function_Definition |
8392 N_Access_Procedure_Definition |
8393 N_Access_To_Object_Definition |
8395 N_Derived_Type_Definition |
8396 N_Function_Specification |
8397 N_Subtype_Declaration
=>
8398 return Null_Exclusion_Present
(N
);
8400 when N_Component_Definition |
8401 N_Formal_Object_Declaration |
8402 N_Object_Renaming_Declaration
=>
8403 if Present
(Subtype_Mark
(N
)) then
8404 return Null_Exclusion_Present
(N
);
8405 else pragma Assert
(Present
(Access_Definition
(N
)));
8406 return Null_Exclusion_Present
(Access_Definition
(N
));
8409 when N_Discriminant_Specification
=>
8410 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
8411 return Null_Exclusion_Present
(Discriminant_Type
(N
));
8413 return Null_Exclusion_Present
(N
);
8416 when N_Object_Declaration
=>
8417 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
8418 return Null_Exclusion_Present
(Object_Definition
(N
));
8420 return Null_Exclusion_Present
(N
);
8423 when N_Parameter_Specification
=>
8424 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
8425 return Null_Exclusion_Present
(Parameter_Type
(N
));
8427 return Null_Exclusion_Present
(N
);
8434 end Has_Null_Exclusion
;
8436 ------------------------
8437 -- Has_Null_Extension --
8438 ------------------------
8440 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
8441 B
: constant Entity_Id
:= Base_Type
(T
);
8446 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
8447 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
8449 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
8451 if Present
(Ext
) then
8452 if Null_Present
(Ext
) then
8455 Comps
:= Component_List
(Ext
);
8457 -- The null component list is rewritten during analysis to
8458 -- include the parent component. Any other component indicates
8459 -- that the extension was not originally null.
8461 return Null_Present
(Comps
)
8462 or else No
(Next
(First
(Component_Items
(Comps
))));
8471 end Has_Null_Extension
;
8473 -------------------------------
8474 -- Has_Overriding_Initialize --
8475 -------------------------------
8477 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
8478 BT
: constant Entity_Id
:= Base_Type
(T
);
8482 if Is_Controlled
(BT
) then
8483 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
8486 elsif Present
(Primitive_Operations
(BT
)) then
8487 P
:= First_Elmt
(Primitive_Operations
(BT
));
8488 while Present
(P
) loop
8490 Init
: constant Entity_Id
:= Node
(P
);
8491 Formal
: constant Entity_Id
:= First_Formal
(Init
);
8493 if Ekind
(Init
) = E_Procedure
8494 and then Chars
(Init
) = Name_Initialize
8495 and then Comes_From_Source
(Init
)
8496 and then Present
(Formal
)
8497 and then Etype
(Formal
) = BT
8498 and then No
(Next_Formal
(Formal
))
8499 and then (Ada_Version
< Ada_2012
8500 or else not Null_Present
(Parent
(Init
)))
8510 -- Here if type itself does not have a non-null Initialize operation:
8511 -- check immediate ancestor.
8513 if Is_Derived_Type
(BT
)
8514 and then Has_Overriding_Initialize
(Etype
(BT
))
8521 end Has_Overriding_Initialize
;
8523 --------------------------------------
8524 -- Has_Preelaborable_Initialization --
8525 --------------------------------------
8527 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
8530 procedure Check_Components
(E
: Entity_Id
);
8531 -- Check component/discriminant chain, sets Has_PE False if a component
8532 -- or discriminant does not meet the preelaborable initialization rules.
8534 ----------------------
8535 -- Check_Components --
8536 ----------------------
8538 procedure Check_Components
(E
: Entity_Id
) is
8542 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
8543 -- Returns True if and only if the expression denoted by N does not
8544 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8546 ---------------------------------
8547 -- Is_Preelaborable_Expression --
8548 ---------------------------------
8550 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
8554 Comp_Type
: Entity_Id
;
8555 Is_Array_Aggr
: Boolean;
8558 if Is_OK_Static_Expression
(N
) then
8561 elsif Nkind
(N
) = N_Null
then
8564 -- Attributes are allowed in general, even if their prefix is a
8565 -- formal type. (It seems that certain attributes known not to be
8566 -- static might not be allowed, but there are no rules to prevent
8569 elsif Nkind
(N
) = N_Attribute_Reference
then
8572 -- The name of a discriminant evaluated within its parent type is
8573 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8574 -- names that denote discriminals as well as discriminants to
8575 -- catch references occurring within init procs.
8577 elsif Is_Entity_Name
(N
)
8579 (Ekind
(Entity
(N
)) = E_Discriminant
8580 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
8581 and then Present
(Discriminal_Link
(Entity
(N
)))))
8585 elsif Nkind
(N
) = N_Qualified_Expression
then
8586 return Is_Preelaborable_Expression
(Expression
(N
));
8588 -- For aggregates we have to check that each of the associations
8589 -- is preelaborable.
8591 elsif Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
8592 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
8594 if Is_Array_Aggr
then
8595 Comp_Type
:= Component_Type
(Etype
(N
));
8598 -- Check the ancestor part of extension aggregates, which must
8599 -- be either the name of a type that has preelaborable init or
8600 -- an expression that is preelaborable.
8602 if Nkind
(N
) = N_Extension_Aggregate
then
8604 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
8607 if Is_Entity_Name
(Anc_Part
)
8608 and then Is_Type
(Entity
(Anc_Part
))
8610 if not Has_Preelaborable_Initialization
8616 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
8622 -- Check positional associations
8624 Exp
:= First
(Expressions
(N
));
8625 while Present
(Exp
) loop
8626 if not Is_Preelaborable_Expression
(Exp
) then
8633 -- Check named associations
8635 Assn
:= First
(Component_Associations
(N
));
8636 while Present
(Assn
) loop
8637 Choice
:= First
(Choices
(Assn
));
8638 while Present
(Choice
) loop
8639 if Is_Array_Aggr
then
8640 if Nkind
(Choice
) = N_Others_Choice
then
8643 elsif Nkind
(Choice
) = N_Range
then
8644 if not Is_OK_Static_Range
(Choice
) then
8648 elsif not Is_OK_Static_Expression
(Choice
) then
8653 Comp_Type
:= Etype
(Choice
);
8659 -- If the association has a <> at this point, then we have
8660 -- to check whether the component's type has preelaborable
8661 -- initialization. Note that this only occurs when the
8662 -- association's corresponding component does not have a
8663 -- default expression, the latter case having already been
8664 -- expanded as an expression for the association.
8666 if Box_Present
(Assn
) then
8667 if not Has_Preelaborable_Initialization
(Comp_Type
) then
8671 -- In the expression case we check whether the expression
8672 -- is preelaborable.
8675 not Is_Preelaborable_Expression
(Expression
(Assn
))
8683 -- If we get here then aggregate as a whole is preelaborable
8687 -- All other cases are not preelaborable
8692 end Is_Preelaborable_Expression
;
8694 -- Start of processing for Check_Components
8697 -- Loop through entities of record or protected type
8700 while Present
(Ent
) loop
8702 -- We are interested only in components and discriminants
8709 -- Get default expression if any. If there is no declaration
8710 -- node, it means we have an internal entity. The parent and
8711 -- tag fields are examples of such entities. For such cases,
8712 -- we just test the type of the entity.
8714 if Present
(Declaration_Node
(Ent
)) then
8715 Exp
:= Expression
(Declaration_Node
(Ent
));
8718 when E_Discriminant
=>
8720 -- Note: for a renamed discriminant, the Declaration_Node
8721 -- may point to the one from the ancestor, and have a
8722 -- different expression, so use the proper attribute to
8723 -- retrieve the expression from the derived constraint.
8725 Exp
:= Discriminant_Default_Value
(Ent
);
8728 goto Check_Next_Entity
;
8731 -- A component has PI if it has no default expression and the
8732 -- component type has PI.
8735 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
8740 -- Require the default expression to be preelaborable
8742 elsif not Is_Preelaborable_Expression
(Exp
) then
8747 <<Check_Next_Entity
>>
8750 end Check_Components
;
8752 -- Start of processing for Has_Preelaborable_Initialization
8755 -- Immediate return if already marked as known preelaborable init. This
8756 -- covers types for which this function has already been called once
8757 -- and returned True (in which case the result is cached), and also
8758 -- types to which a pragma Preelaborable_Initialization applies.
8760 if Known_To_Have_Preelab_Init
(E
) then
8764 -- If the type is a subtype representing a generic actual type, then
8765 -- test whether its base type has preelaborable initialization since
8766 -- the subtype representing the actual does not inherit this attribute
8767 -- from the actual or formal. (but maybe it should???)
8769 if Is_Generic_Actual_Type
(E
) then
8770 return Has_Preelaborable_Initialization
(Base_Type
(E
));
8773 -- All elementary types have preelaborable initialization
8775 if Is_Elementary_Type
(E
) then
8778 -- Array types have PI if the component type has PI
8780 elsif Is_Array_Type
(E
) then
8781 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
8783 -- A derived type has preelaborable initialization if its parent type
8784 -- has preelaborable initialization and (in the case of a derived record
8785 -- extension) if the non-inherited components all have preelaborable
8786 -- initialization. However, a user-defined controlled type with an
8787 -- overriding Initialize procedure does not have preelaborable
8790 elsif Is_Derived_Type
(E
) then
8792 -- If the derived type is a private extension then it doesn't have
8793 -- preelaborable initialization.
8795 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
8799 -- First check whether ancestor type has preelaborable initialization
8801 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
8803 -- If OK, check extension components (if any)
8805 if Has_PE
and then Is_Record_Type
(E
) then
8806 Check_Components
(First_Entity
(E
));
8809 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8810 -- with a user defined Initialize procedure does not have PI. If
8811 -- the type is untagged, the control primitives come from a component
8812 -- that has already been checked.
8815 and then Is_Controlled
(E
)
8816 and then Is_Tagged_Type
(E
)
8817 and then Has_Overriding_Initialize
(E
)
8822 -- Private types not derived from a type having preelaborable init and
8823 -- that are not marked with pragma Preelaborable_Initialization do not
8824 -- have preelaborable initialization.
8826 elsif Is_Private_Type
(E
) then
8829 -- Record type has PI if it is non private and all components have PI
8831 elsif Is_Record_Type
(E
) then
8833 Check_Components
(First_Entity
(E
));
8835 -- Protected types must not have entries, and components must meet
8836 -- same set of rules as for record components.
8838 elsif Is_Protected_Type
(E
) then
8839 if Has_Entries
(E
) then
8843 Check_Components
(First_Entity
(E
));
8844 Check_Components
(First_Private_Entity
(E
));
8847 -- Type System.Address always has preelaborable initialization
8849 elsif Is_RTE
(E
, RE_Address
) then
8852 -- In all other cases, type does not have preelaborable initialization
8858 -- If type has preelaborable initialization, cache result
8861 Set_Known_To_Have_Preelab_Init
(E
);
8865 end Has_Preelaborable_Initialization
;
8867 ---------------------------
8868 -- Has_Private_Component --
8869 ---------------------------
8871 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
8872 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
8873 Component
: Entity_Id
;
8876 if Error_Posted
(Type_Id
)
8877 or else Error_Posted
(Btype
)
8882 if Is_Class_Wide_Type
(Btype
) then
8883 Btype
:= Root_Type
(Btype
);
8886 if Is_Private_Type
(Btype
) then
8888 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
8891 if No
(Full_View
(Btype
)) then
8892 return not Is_Generic_Type
(Btype
)
8894 not Is_Generic_Type
(Root_Type
(Btype
));
8896 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
8899 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
8903 elsif Is_Array_Type
(Btype
) then
8904 return Has_Private_Component
(Component_Type
(Btype
));
8906 elsif Is_Record_Type
(Btype
) then
8907 Component
:= First_Component
(Btype
);
8908 while Present
(Component
) loop
8909 if Has_Private_Component
(Etype
(Component
)) then
8913 Next_Component
(Component
);
8918 elsif Is_Protected_Type
(Btype
)
8919 and then Present
(Corresponding_Record_Type
(Btype
))
8921 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
8926 end Has_Private_Component
;
8928 ----------------------
8929 -- Has_Signed_Zeros --
8930 ----------------------
8932 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
8934 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
8935 end Has_Signed_Zeros
;
8937 ------------------------------
8938 -- Has_Significant_Contract --
8939 ------------------------------
8941 function Has_Significant_Contract
(Subp_Id
: Entity_Id
) return Boolean is
8942 Subp_Nam
: constant Name_Id
:= Chars
(Subp_Id
);
8945 -- _Finalizer procedure
8947 if Subp_Nam
= Name_uFinalizer
then
8950 -- _Postconditions procedure
8952 elsif Subp_Nam
= Name_uPostconditions
then
8955 -- Predicate function
8957 elsif Ekind
(Subp_Id
) = E_Function
8958 and then Is_Predicate_Function
(Subp_Id
)
8964 elsif Get_TSS_Name
(Subp_Id
) /= TSS_Null
then
8970 end Has_Significant_Contract
;
8972 -----------------------------
8973 -- Has_Static_Array_Bounds --
8974 -----------------------------
8976 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
8977 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
8984 -- Unconstrained types do not have static bounds
8986 if not Is_Constrained
(Typ
) then
8990 -- First treat string literals specially, as the lower bound and length
8991 -- of string literals are not stored like those of arrays.
8993 -- A string literal always has static bounds
8995 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8999 -- Treat all dimensions in turn
9001 Index
:= First_Index
(Typ
);
9002 for Indx
in 1 .. Ndims
loop
9004 -- In case of an illegal index which is not a discrete type, return
9005 -- that the type is not static.
9007 if not Is_Discrete_Type
(Etype
(Index
))
9008 or else Etype
(Index
) = Any_Type
9013 Get_Index_Bounds
(Index
, Low
, High
);
9015 if Error_Posted
(Low
) or else Error_Posted
(High
) then
9019 if Is_OK_Static_Expression
(Low
)
9021 Is_OK_Static_Expression
(High
)
9031 -- If we fall through the loop, all indexes matched
9034 end Has_Static_Array_Bounds
;
9040 function Has_Stream
(T
: Entity_Id
) return Boolean is
9047 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
9050 elsif Is_Array_Type
(T
) then
9051 return Has_Stream
(Component_Type
(T
));
9053 elsif Is_Record_Type
(T
) then
9054 E
:= First_Component
(T
);
9055 while Present
(E
) loop
9056 if Has_Stream
(Etype
(E
)) then
9065 elsif Is_Private_Type
(T
) then
9066 return Has_Stream
(Underlying_Type
(T
));
9077 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
9079 Get_Name_String
(Chars
(E
));
9080 return Name_Buffer
(Name_Len
) = Suffix
;
9087 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
9089 Get_Name_String
(Chars
(E
));
9090 Add_Char_To_Name_Buffer
(Suffix
);
9098 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
9100 pragma Assert
(Has_Suffix
(E
, Suffix
));
9101 Get_Name_String
(Chars
(E
));
9102 Name_Len
:= Name_Len
- 1;
9106 --------------------------
9107 -- Has_Tagged_Component --
9108 --------------------------
9110 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
9114 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
9115 return Has_Tagged_Component
(Underlying_Type
(Typ
));
9117 elsif Is_Array_Type
(Typ
) then
9118 return Has_Tagged_Component
(Component_Type
(Typ
));
9120 elsif Is_Tagged_Type
(Typ
) then
9123 elsif Is_Record_Type
(Typ
) then
9124 Comp
:= First_Component
(Typ
);
9125 while Present
(Comp
) loop
9126 if Has_Tagged_Component
(Etype
(Comp
)) then
9130 Next_Component
(Comp
);
9138 end Has_Tagged_Component
;
9140 ----------------------------
9141 -- Has_Volatile_Component --
9142 ----------------------------
9144 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
9148 if Has_Volatile_Components
(Typ
) then
9151 elsif Is_Array_Type
(Typ
) then
9152 return Is_Volatile
(Component_Type
(Typ
));
9154 elsif Is_Record_Type
(Typ
) then
9155 Comp
:= First_Component
(Typ
);
9156 while Present
(Comp
) loop
9157 if Is_Volatile_Object
(Comp
) then
9161 Comp
:= Next_Component
(Comp
);
9166 end Has_Volatile_Component
;
9168 -------------------------
9169 -- Implementation_Kind --
9170 -------------------------
9172 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
9173 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
9176 pragma Assert
(Present
(Impl_Prag
));
9177 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
9178 return Chars
(Get_Pragma_Arg
(Arg
));
9179 end Implementation_Kind
;
9181 --------------------------
9182 -- Implements_Interface --
9183 --------------------------
9185 function Implements_Interface
9186 (Typ_Ent
: Entity_Id
;
9187 Iface_Ent
: Entity_Id
;
9188 Exclude_Parents
: Boolean := False) return Boolean
9190 Ifaces_List
: Elist_Id
;
9192 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
9193 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
9196 if Is_Class_Wide_Type
(Typ
) then
9197 Typ
:= Root_Type
(Typ
);
9200 if not Has_Interfaces
(Typ
) then
9204 if Is_Class_Wide_Type
(Iface
) then
9205 Iface
:= Root_Type
(Iface
);
9208 Collect_Interfaces
(Typ
, Ifaces_List
);
9210 Elmt
:= First_Elmt
(Ifaces_List
);
9211 while Present
(Elmt
) loop
9212 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
9213 and then Exclude_Parents
9217 elsif Node
(Elmt
) = Iface
then
9225 end Implements_Interface
;
9227 ------------------------------------
9228 -- In_Assertion_Expression_Pragma --
9229 ------------------------------------
9231 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
9233 Prag
: Node_Id
:= Empty
;
9236 -- Climb the parent chain looking for an enclosing pragma
9239 while Present
(Par
) loop
9240 if Nkind
(Par
) = N_Pragma
then
9244 -- Precondition-like pragmas are expanded into if statements, check
9245 -- the original node instead.
9247 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
9248 Prag
:= Original_Node
(Par
);
9251 -- The expansion of attribute 'Old generates a constant to capture
9252 -- the result of the prefix. If the parent traversal reaches
9253 -- one of these constants, then the node technically came from a
9254 -- postcondition-like pragma. Note that the Ekind is not tested here
9255 -- because N may be the expression of an object declaration which is
9256 -- currently being analyzed. Such objects carry Ekind of E_Void.
9258 elsif Nkind
(Par
) = N_Object_Declaration
9259 and then Constant_Present
(Par
)
9260 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
9264 -- Prevent the search from going too far
9266 elsif Is_Body_Or_Package_Declaration
(Par
) then
9270 Par
:= Parent
(Par
);
9275 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
9276 end In_Assertion_Expression_Pragma
;
9282 function In_Instance
return Boolean is
9283 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
9288 while Present
(S
) and then S
/= Standard_Standard
loop
9289 if Ekind_In
(S
, E_Function
, E_Package
, E_Procedure
)
9290 and then Is_Generic_Instance
(S
)
9292 -- A child instance is always compiled in the context of a parent
9293 -- instance. Nevertheless, the actuals are not analyzed in an
9294 -- instance context. We detect this case by examining the current
9295 -- compilation unit, which must be a child instance, and checking
9296 -- that it is not currently on the scope stack.
9298 if Is_Child_Unit
(Curr_Unit
)
9299 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
9300 N_Package_Instantiation
9301 and then not In_Open_Scopes
(Curr_Unit
)
9315 ----------------------
9316 -- In_Instance_Body --
9317 ----------------------
9319 function In_Instance_Body
return Boolean is
9324 while Present
(S
) and then S
/= Standard_Standard
loop
9325 if Ekind_In
(S
, E_Function
, E_Procedure
)
9326 and then Is_Generic_Instance
(S
)
9330 elsif Ekind
(S
) = E_Package
9331 and then In_Package_Body
(S
)
9332 and then Is_Generic_Instance
(S
)
9341 end In_Instance_Body
;
9343 -----------------------------
9344 -- In_Instance_Not_Visible --
9345 -----------------------------
9347 function In_Instance_Not_Visible
return Boolean is
9352 while Present
(S
) and then S
/= Standard_Standard
loop
9353 if Ekind_In
(S
, E_Function
, E_Procedure
)
9354 and then Is_Generic_Instance
(S
)
9358 elsif Ekind
(S
) = E_Package
9359 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
9360 and then Is_Generic_Instance
(S
)
9369 end In_Instance_Not_Visible
;
9371 ------------------------------
9372 -- In_Instance_Visible_Part --
9373 ------------------------------
9375 function In_Instance_Visible_Part
return Boolean is
9380 while Present
(S
) and then S
/= Standard_Standard
loop
9381 if Ekind
(S
) = E_Package
9382 and then Is_Generic_Instance
(S
)
9383 and then not In_Package_Body
(S
)
9384 and then not In_Private_Part
(S
)
9393 end In_Instance_Visible_Part
;
9395 ---------------------
9396 -- In_Package_Body --
9397 ---------------------
9399 function In_Package_Body
return Boolean is
9404 while Present
(S
) and then S
/= Standard_Standard
loop
9405 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
9413 end In_Package_Body
;
9415 --------------------------------
9416 -- In_Parameter_Specification --
9417 --------------------------------
9419 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
9424 while Present
(PN
) loop
9425 if Nkind
(PN
) = N_Parameter_Specification
then
9433 end In_Parameter_Specification
;
9435 --------------------------
9436 -- In_Pragma_Expression --
9437 --------------------------
9439 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
9446 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
9452 end In_Pragma_Expression
;
9454 -------------------------------------
9455 -- In_Reverse_Storage_Order_Object --
9456 -------------------------------------
9458 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
9460 Btyp
: Entity_Id
:= Empty
;
9463 -- Climb up indexed components
9467 case Nkind
(Pref
) is
9468 when N_Selected_Component
=>
9469 Pref
:= Prefix
(Pref
);
9472 when N_Indexed_Component
=>
9473 Pref
:= Prefix
(Pref
);
9481 if Present
(Pref
) then
9482 Btyp
:= Base_Type
(Etype
(Pref
));
9485 return Present
(Btyp
)
9486 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
9487 and then Reverse_Storage_Order
(Btyp
);
9488 end In_Reverse_Storage_Order_Object
;
9490 --------------------------------------
9491 -- In_Subprogram_Or_Concurrent_Unit --
9492 --------------------------------------
9494 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
9499 -- Use scope chain to check successively outer scopes
9505 if K
in Subprogram_Kind
9506 or else K
in Concurrent_Kind
9507 or else K
in Generic_Subprogram_Kind
9511 elsif E
= Standard_Standard
then
9517 end In_Subprogram_Or_Concurrent_Unit
;
9519 ---------------------
9520 -- In_Visible_Part --
9521 ---------------------
9523 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
9525 return Is_Package_Or_Generic_Package
(Scope_Id
)
9526 and then In_Open_Scopes
(Scope_Id
)
9527 and then not In_Package_Body
(Scope_Id
)
9528 and then not In_Private_Part
(Scope_Id
);
9529 end In_Visible_Part
;
9531 --------------------------------
9532 -- Incomplete_Or_Partial_View --
9533 --------------------------------
9535 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
9536 function Inspect_Decls
9538 Taft
: Boolean := False) return Entity_Id
;
9539 -- Check whether a declarative region contains the incomplete or partial
9546 function Inspect_Decls
9548 Taft
: Boolean := False) return Entity_Id
9554 Decl
:= First
(Decls
);
9555 while Present
(Decl
) loop
9559 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
9560 Match
:= Defining_Identifier
(Decl
);
9564 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
9565 N_Private_Type_Declaration
)
9567 Match
:= Defining_Identifier
(Decl
);
9572 and then Present
(Full_View
(Match
))
9573 and then Full_View
(Match
) = Id
9588 -- Start of processing for Incomplete_Or_Partial_View
9591 -- Deferred constant or incomplete type case
9593 Prev
:= Current_Entity_In_Scope
(Id
);
9596 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
9597 and then Present
(Full_View
(Prev
))
9598 and then Full_View
(Prev
) = Id
9603 -- Private or Taft amendment type case
9606 Pkg
: constant Entity_Id
:= Scope
(Id
);
9607 Pkg_Decl
: Node_Id
:= Pkg
;
9610 if Present
(Pkg
) and then Ekind
(Pkg
) = E_Package
then
9611 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
9612 Pkg_Decl
:= Parent
(Pkg_Decl
);
9615 -- It is knows that Typ has a private view, look for it in the
9616 -- visible declarations of the enclosing scope. A special case
9617 -- of this is when the two views have been exchanged - the full
9618 -- appears earlier than the private.
9620 if Has_Private_Declaration
(Id
) then
9621 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
9623 -- Exchanged view case, look in the private declarations
9626 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
9631 -- Otherwise if this is the package body, then Typ is a potential
9632 -- Taft amendment type. The incomplete view should be located in
9633 -- the private declarations of the enclosing scope.
9635 elsif In_Package_Body
(Pkg
) then
9636 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
9641 -- The type has no incomplete or private view
9644 end Incomplete_Or_Partial_View
;
9646 -----------------------------------------
9647 -- Inherit_Default_Init_Cond_Procedure --
9648 -----------------------------------------
9650 procedure Inherit_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
9651 Par_Typ
: constant Entity_Id
:= Etype
(Typ
);
9654 -- A derived type inherits the default initial condition procedure of
9657 if No
(Default_Init_Cond_Procedure
(Typ
)) then
9658 Set_Default_Init_Cond_Procedure
9659 (Typ
, Default_Init_Cond_Procedure
(Par_Typ
));
9661 end Inherit_Default_Init_Cond_Procedure
;
9663 ----------------------------
9664 -- Inherit_Rep_Item_Chain --
9665 ----------------------------
9667 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
9668 From_Item
: constant Node_Id
:= First_Rep_Item
(From_Typ
);
9669 Item
: Node_Id
:= Empty
;
9670 Last_Item
: Node_Id
:= Empty
;
9673 -- Reach the end of the destination type's chain (if any) and capture
9676 Item
:= First_Rep_Item
(Typ
);
9677 while Present
(Item
) loop
9679 -- Do not inherit a chain that has been inherited already
9681 if Item
= From_Item
then
9686 Item
:= Next_Rep_Item
(Item
);
9689 -- When the destination type has a rep item chain, the chain of the
9690 -- source type is appended to it.
9692 if Present
(Last_Item
) then
9693 Set_Next_Rep_Item
(Last_Item
, From_Item
);
9695 -- Otherwise the destination type directly inherits the rep item chain
9696 -- of the source type (if any).
9699 Set_First_Rep_Item
(Typ
, From_Item
);
9701 end Inherit_Rep_Item_Chain
;
9703 ---------------------------------
9704 -- Inherit_Subprogram_Contract --
9705 ---------------------------------
9707 procedure Inherit_Subprogram_Contract
9709 From_Subp
: Entity_Id
)
9711 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
);
9712 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
9715 --------------------
9716 -- Inherit_Pragma --
9717 --------------------
9719 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
) is
9720 Prag
: constant Node_Id
:= Get_Pragma
(From_Subp
, Prag_Id
);
9724 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
9725 -- chains, therefore the node must be replicated. The new pragma is
9726 -- flagged is inherited for distrinction purposes.
9728 if Present
(Prag
) then
9729 New_Prag
:= New_Copy_Tree
(Prag
);
9730 Set_Is_Inherited
(New_Prag
);
9732 Add_Contract_Item
(New_Prag
, Subp
);
9736 -- Start of processing for Inherit_Subprogram_Contract
9739 -- Inheritance is carried out only when both entities are subprograms
9742 if Is_Subprogram_Or_Generic_Subprogram
(Subp
)
9743 and then Is_Subprogram_Or_Generic_Subprogram
(From_Subp
)
9744 and then Present
(Contract
(From_Subp
))
9746 Inherit_Pragma
(Pragma_Extensions_Visible
);
9748 end Inherit_Subprogram_Contract
;
9750 ---------------------------------
9751 -- Insert_Explicit_Dereference --
9752 ---------------------------------
9754 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
9755 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
9756 Ent
: Entity_Id
:= Empty
;
9763 Save_Interps
(N
, New_Prefix
);
9766 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
9767 Prefix
=> New_Prefix
));
9769 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
9771 if Is_Overloaded
(New_Prefix
) then
9773 -- The dereference is also overloaded, and its interpretations are
9774 -- the designated types of the interpretations of the original node.
9776 Set_Etype
(N
, Any_Type
);
9778 Get_First_Interp
(New_Prefix
, I
, It
);
9779 while Present
(It
.Nam
) loop
9782 if Is_Access_Type
(T
) then
9783 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
9786 Get_Next_Interp
(I
, It
);
9792 -- Prefix is unambiguous: mark the original prefix (which might
9793 -- Come_From_Source) as a reference, since the new (relocated) one
9794 -- won't be taken into account.
9796 if Is_Entity_Name
(New_Prefix
) then
9797 Ent
:= Entity
(New_Prefix
);
9800 -- For a retrieval of a subcomponent of some composite object,
9801 -- retrieve the ultimate entity if there is one.
9803 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
9804 N_Indexed_Component
)
9806 Pref
:= Prefix
(New_Prefix
);
9807 while Present
(Pref
)
9808 and then Nkind_In
(Pref
, N_Selected_Component
,
9809 N_Indexed_Component
)
9811 Pref
:= Prefix
(Pref
);
9814 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
9815 Ent
:= Entity
(Pref
);
9819 -- Place the reference on the entity node
9821 if Present
(Ent
) then
9822 Generate_Reference
(Ent
, Pref
);
9825 end Insert_Explicit_Dereference
;
9827 ------------------------------------------
9828 -- Inspect_Deferred_Constant_Completion --
9829 ------------------------------------------
9831 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
9835 Decl
:= First
(Decls
);
9836 while Present
(Decl
) loop
9838 -- Deferred constant signature
9840 if Nkind
(Decl
) = N_Object_Declaration
9841 and then Constant_Present
(Decl
)
9842 and then No
(Expression
(Decl
))
9844 -- No need to check internally generated constants
9846 and then Comes_From_Source
(Decl
)
9848 -- The constant is not completed. A full object declaration or a
9849 -- pragma Import complete a deferred constant.
9851 and then not Has_Completion
(Defining_Identifier
(Decl
))
9854 ("constant declaration requires initialization expression",
9855 Defining_Identifier
(Decl
));
9858 Decl
:= Next
(Decl
);
9860 end Inspect_Deferred_Constant_Completion
;
9862 -----------------------------
9863 -- Install_Generic_Formals --
9864 -----------------------------
9866 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
9870 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
9872 E
:= First_Entity
(Subp_Id
);
9873 while Present
(E
) loop
9877 end Install_Generic_Formals
;
9879 -----------------------------
9880 -- Is_Actual_Out_Parameter --
9881 -----------------------------
9883 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
9887 Find_Actual
(N
, Formal
, Call
);
9888 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
9889 end Is_Actual_Out_Parameter
;
9891 -------------------------
9892 -- Is_Actual_Parameter --
9893 -------------------------
9895 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
9896 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
9900 when N_Parameter_Association
=>
9901 return N
= Explicit_Actual_Parameter
(Parent
(N
));
9903 when N_Subprogram_Call
=>
9904 return Is_List_Member
(N
)
9906 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
9911 end Is_Actual_Parameter
;
9913 --------------------------------
9914 -- Is_Actual_Tagged_Parameter --
9915 --------------------------------
9917 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
9921 Find_Actual
(N
, Formal
, Call
);
9922 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
9923 end Is_Actual_Tagged_Parameter
;
9925 ---------------------
9926 -- Is_Aliased_View --
9927 ---------------------
9929 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
9933 if Is_Entity_Name
(Obj
) then
9940 or else (Present
(Renamed_Object
(E
))
9941 and then Is_Aliased_View
(Renamed_Object
(E
)))))
9943 or else ((Is_Formal
(E
)
9944 or else Ekind_In
(E
, E_Generic_In_Out_Parameter
,
9945 E_Generic_In_Parameter
))
9946 and then Is_Tagged_Type
(Etype
(E
)))
9948 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
9950 -- Current instance of type, either directly or as rewritten
9951 -- reference to the current object.
9953 or else (Is_Entity_Name
(Original_Node
(Obj
))
9954 and then Present
(Entity
(Original_Node
(Obj
)))
9955 and then Is_Type
(Entity
(Original_Node
(Obj
))))
9957 or else (Is_Type
(E
) and then E
= Current_Scope
)
9959 or else (Is_Incomplete_Or_Private_Type
(E
)
9960 and then Full_View
(E
) = Current_Scope
)
9962 -- Ada 2012 AI05-0053: the return object of an extended return
9963 -- statement is aliased if its type is immutably limited.
9965 or else (Is_Return_Object
(E
)
9966 and then Is_Limited_View
(Etype
(E
)));
9968 elsif Nkind
(Obj
) = N_Selected_Component
then
9969 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
9971 elsif Nkind
(Obj
) = N_Indexed_Component
then
9972 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
9974 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
9975 and then Has_Aliased_Components
9976 (Designated_Type
(Etype
(Prefix
(Obj
)))));
9978 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
9979 return Is_Tagged_Type
(Etype
(Obj
))
9980 and then Is_Aliased_View
(Expression
(Obj
));
9982 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
9983 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
9988 end Is_Aliased_View
;
9990 -------------------------
9991 -- Is_Ancestor_Package --
9992 -------------------------
9994 function Is_Ancestor_Package
9996 E2
: Entity_Id
) return Boolean
10002 while Present
(Par
) and then Par
/= Standard_Standard
loop
10007 Par
:= Scope
(Par
);
10011 end Is_Ancestor_Package
;
10013 ----------------------
10014 -- Is_Atomic_Object --
10015 ----------------------
10017 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
10019 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
10020 -- Determines if given object has atomic components
10022 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
10023 -- If prefix is an implicit dereference, examine designated type
10025 ----------------------
10026 -- Is_Atomic_Prefix --
10027 ----------------------
10029 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
10031 if Is_Access_Type
(Etype
(N
)) then
10033 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
10035 return Object_Has_Atomic_Components
(N
);
10037 end Is_Atomic_Prefix
;
10039 ----------------------------------
10040 -- Object_Has_Atomic_Components --
10041 ----------------------------------
10043 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
10045 if Has_Atomic_Components
(Etype
(N
))
10046 or else Is_Atomic
(Etype
(N
))
10050 elsif Is_Entity_Name
(N
)
10051 and then (Has_Atomic_Components
(Entity
(N
))
10052 or else Is_Atomic
(Entity
(N
)))
10056 elsif Nkind
(N
) = N_Selected_Component
10057 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
10061 elsif Nkind
(N
) = N_Indexed_Component
10062 or else Nkind
(N
) = N_Selected_Component
10064 return Is_Atomic_Prefix
(Prefix
(N
));
10069 end Object_Has_Atomic_Components
;
10071 -- Start of processing for Is_Atomic_Object
10074 -- Predicate is not relevant to subprograms
10076 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
10079 elsif Is_Atomic
(Etype
(N
))
10080 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
10084 elsif Nkind
(N
) = N_Selected_Component
10085 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
10089 elsif Nkind
(N
) = N_Indexed_Component
10090 or else Nkind
(N
) = N_Selected_Component
10092 return Is_Atomic_Prefix
(Prefix
(N
));
10097 end Is_Atomic_Object
;
10099 -------------------------
10100 -- Is_Attribute_Result --
10101 -------------------------
10103 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
10105 return Nkind
(N
) = N_Attribute_Reference
10106 and then Attribute_Name
(N
) = Name_Result
;
10107 end Is_Attribute_Result
;
10109 ------------------------------------
10110 -- Is_Body_Or_Package_Declaration --
10111 ------------------------------------
10113 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
10115 return Nkind_In
(N
, N_Entry_Body
,
10117 N_Package_Declaration
,
10121 end Is_Body_Or_Package_Declaration
;
10123 -----------------------
10124 -- Is_Bounded_String --
10125 -----------------------
10127 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
10128 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
10131 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10132 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10133 -- be True for all the Bounded_String types in instances of the
10134 -- Generic_Bounded_Length generics, and for types derived from those.
10136 return Present
(Under
)
10137 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
10138 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
10139 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
10140 end Is_Bounded_String
;
10142 -------------------------
10143 -- Is_Child_Or_Sibling --
10144 -------------------------
10146 function Is_Child_Or_Sibling
10147 (Pack_1
: Entity_Id
;
10148 Pack_2
: Entity_Id
) return Boolean
10150 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
10151 -- Given an arbitrary package, return the number of "climbs" necessary
10152 -- to reach scope Standard_Standard.
10154 procedure Equalize_Depths
10155 (Pack
: in out Entity_Id
;
10156 Depth
: in out Nat
;
10157 Depth_To_Reach
: Nat
);
10158 -- Given an arbitrary package, its depth and a target depth to reach,
10159 -- climb the scope chain until the said depth is reached. The pointer
10160 -- to the package and its depth a modified during the climb.
10162 ----------------------------
10163 -- Distance_From_Standard --
10164 ----------------------------
10166 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
10173 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
10175 Scop
:= Scope
(Scop
);
10179 end Distance_From_Standard
;
10181 ---------------------
10182 -- Equalize_Depths --
10183 ---------------------
10185 procedure Equalize_Depths
10186 (Pack
: in out Entity_Id
;
10187 Depth
: in out Nat
;
10188 Depth_To_Reach
: Nat
)
10191 -- The package must be at a greater or equal depth
10193 if Depth
< Depth_To_Reach
then
10194 raise Program_Error
;
10197 -- Climb the scope chain until the desired depth is reached
10199 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
10200 Pack
:= Scope
(Pack
);
10201 Depth
:= Depth
- 1;
10203 end Equalize_Depths
;
10207 P_1
: Entity_Id
:= Pack_1
;
10208 P_1_Child
: Boolean := False;
10209 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
10210 P_2
: Entity_Id
:= Pack_2
;
10211 P_2_Child
: Boolean := False;
10212 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
10214 -- Start of processing for Is_Child_Or_Sibling
10218 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
10220 -- Both packages denote the same entity, therefore they cannot be
10221 -- children or siblings.
10226 -- One of the packages is at a deeper level than the other. Note that
10227 -- both may still come from differen hierarchies.
10235 elsif P_1_Depth
> P_2_Depth
then
10238 Depth
=> P_1_Depth
,
10239 Depth_To_Reach
=> P_2_Depth
);
10248 elsif P_2_Depth
> P_1_Depth
then
10251 Depth
=> P_2_Depth
,
10252 Depth_To_Reach
=> P_1_Depth
);
10256 -- At this stage the package pointers have been elevated to the same
10257 -- depth. If the related entities are the same, then one package is a
10258 -- potential child of the other:
10262 -- X became P_1 P_2 or vica versa
10268 return Is_Child_Unit
(Pack_1
);
10270 else pragma Assert
(P_2_Child
);
10271 return Is_Child_Unit
(Pack_2
);
10274 -- The packages may come from the same package chain or from entirely
10275 -- different hierarcies. To determine this, climb the scope stack until
10276 -- a common root is found.
10278 -- (root) (root 1) (root 2)
10283 while Present
(P_1
) and then Present
(P_2
) loop
10285 -- The two packages may be siblings
10288 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
10291 P_1
:= Scope
(P_1
);
10292 P_2
:= Scope
(P_2
);
10297 end Is_Child_Or_Sibling
;
10299 -----------------------------
10300 -- Is_Concurrent_Interface --
10301 -----------------------------
10303 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
10305 return Is_Interface
(T
)
10307 (Is_Protected_Interface
(T
)
10308 or else Is_Synchronized_Interface
(T
)
10309 or else Is_Task_Interface
(T
));
10310 end Is_Concurrent_Interface
;
10312 ---------------------------
10313 -- Is_Container_Element --
10314 ---------------------------
10316 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
10317 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
10318 Pref
: constant Node_Id
:= Prefix
(Exp
);
10321 -- Call to an indexing aspect
10323 Cont_Typ
: Entity_Id
;
10324 -- The type of the container being accessed
10326 Elem_Typ
: Entity_Id
;
10327 -- Its element type
10329 Indexing
: Entity_Id
;
10330 Is_Const
: Boolean;
10331 -- Indicates that constant indexing is used, and the element is thus
10334 Ref_Typ
: Entity_Id
;
10335 -- The reference type returned by the indexing operation
10338 -- If C is a container, in a context that imposes the element type of
10339 -- that container, the indexing notation C (X) is rewritten as:
10341 -- Indexing (C, X).Discr.all
10343 -- where Indexing is one of the indexing aspects of the container.
10344 -- If the context does not require a reference, the construct can be
10349 -- First, verify that the construct has the proper form
10351 if not Expander_Active
then
10354 elsif Nkind
(Pref
) /= N_Selected_Component
then
10357 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
10361 Call
:= Prefix
(Pref
);
10362 Ref_Typ
:= Etype
(Call
);
10365 if not Has_Implicit_Dereference
(Ref_Typ
)
10366 or else No
(First
(Parameter_Associations
(Call
)))
10367 or else not Is_Entity_Name
(Name
(Call
))
10372 -- Retrieve type of container object, and its iterator aspects
10374 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
10375 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
10378 if No
(Indexing
) then
10380 -- Container should have at least one indexing operation
10384 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
10386 -- This may be a variable indexing operation
10388 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
10391 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
10400 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
10402 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
10406 -- Check that the expression is not the target of an assignment, in
10407 -- which case the rewriting is not possible.
10409 if not Is_Const
then
10415 while Present
(Par
)
10417 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
10418 and then Par
= Name
(Parent
(Par
))
10422 -- A renaming produces a reference, and the transformation
10425 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
10429 (Nkind
(Parent
(Par
)), N_Function_Call
,
10430 N_Procedure_Call_Statement
,
10431 N_Entry_Call_Statement
)
10433 -- Check that the element is not part of an actual for an
10434 -- in-out parameter.
10441 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
10442 A
:= First
(Parameter_Associations
(Parent
(Par
)));
10443 while Present
(F
) loop
10444 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
10453 -- E_In_Parameter in a call: element is not modified.
10458 Par
:= Parent
(Par
);
10463 -- The expression has the proper form and the context requires the
10464 -- element type. Retrieve the Element function of the container and
10465 -- rewrite the construct as a call to it.
10471 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
10472 while Present
(Op
) loop
10473 exit when Chars
(Node
(Op
)) = Name_Element
;
10482 Make_Function_Call
(Loc
,
10483 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
10484 Parameter_Associations
=> Parameter_Associations
(Call
)));
10485 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
10489 end Is_Container_Element
;
10491 -----------------------
10492 -- Is_Constant_Bound --
10493 -----------------------
10495 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
10497 if Compile_Time_Known_Value
(Exp
) then
10500 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
10501 return Is_Constant_Object
(Entity
(Exp
))
10502 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
10504 elsif Nkind
(Exp
) in N_Binary_Op
then
10505 return Is_Constant_Bound
(Left_Opnd
(Exp
))
10506 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
10507 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
10512 end Is_Constant_Bound
;
10514 --------------------------------------
10515 -- Is_Controlling_Limited_Procedure --
10516 --------------------------------------
10518 function Is_Controlling_Limited_Procedure
10519 (Proc_Nam
: Entity_Id
) return Boolean
10521 Param_Typ
: Entity_Id
:= Empty
;
10524 if Ekind
(Proc_Nam
) = E_Procedure
10525 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
10527 Param_Typ
:= Etype
(Parameter_Type
(First
(
10528 Parameter_Specifications
(Parent
(Proc_Nam
)))));
10530 -- In this case where an Itype was created, the procedure call has been
10533 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
10534 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
10536 Present
(Parameter_Associations
10537 (Associated_Node_For_Itype
(Proc_Nam
)))
10540 Etype
(First
(Parameter_Associations
10541 (Associated_Node_For_Itype
(Proc_Nam
))));
10544 if Present
(Param_Typ
) then
10546 Is_Interface
(Param_Typ
)
10547 and then Is_Limited_Record
(Param_Typ
);
10551 end Is_Controlling_Limited_Procedure
;
10553 -----------------------------
10554 -- Is_CPP_Constructor_Call --
10555 -----------------------------
10557 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
10559 return Nkind
(N
) = N_Function_Call
10560 and then Is_CPP_Class
(Etype
(Etype
(N
)))
10561 and then Is_Constructor
(Entity
(Name
(N
)))
10562 and then Is_Imported
(Entity
(Name
(N
)));
10563 end Is_CPP_Constructor_Call
;
10565 --------------------
10566 -- Is_Declaration --
10567 --------------------
10569 function Is_Declaration
(N
: Node_Id
) return Boolean is
10572 when N_Abstract_Subprogram_Declaration |
10573 N_Exception_Declaration |
10574 N_Exception_Renaming_Declaration |
10575 N_Full_Type_Declaration |
10576 N_Generic_Function_Renaming_Declaration |
10577 N_Generic_Package_Declaration |
10578 N_Generic_Package_Renaming_Declaration |
10579 N_Generic_Procedure_Renaming_Declaration |
10580 N_Generic_Subprogram_Declaration |
10581 N_Number_Declaration |
10582 N_Object_Declaration |
10583 N_Object_Renaming_Declaration |
10584 N_Package_Declaration |
10585 N_Package_Renaming_Declaration |
10586 N_Private_Extension_Declaration |
10587 N_Private_Type_Declaration |
10588 N_Subprogram_Declaration |
10589 N_Subprogram_Renaming_Declaration |
10590 N_Subtype_Declaration
=>
10596 end Is_Declaration
;
10602 function Is_Delegate
(T
: Entity_Id
) return Boolean is
10603 Desig_Type
: Entity_Id
;
10606 if VM_Target
/= CLI_Target
then
10610 -- Access-to-subprograms are delegates in CIL
10612 if Ekind
(T
) = E_Access_Subprogram_Type
then
10616 if not Is_Access_Type
(T
) then
10618 -- A delegate is a managed pointer. If no designated type is defined
10619 -- it means that it's not a delegate.
10624 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
10626 if not Is_Tagged_Type
(Desig_Type
) then
10630 -- Test if the type is inherited from [mscorlib]System.Delegate
10632 while Etype
(Desig_Type
) /= Desig_Type
loop
10633 if Chars
(Scope
(Desig_Type
)) /= No_Name
10634 and then Is_Imported
(Scope
(Desig_Type
))
10635 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
10640 Desig_Type
:= Etype
(Desig_Type
);
10646 ----------------------------------------------
10647 -- Is_Dependent_Component_Of_Mutable_Object --
10648 ----------------------------------------------
10650 function Is_Dependent_Component_Of_Mutable_Object
10651 (Object
: Node_Id
) return Boolean
10653 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
10654 -- Returns True if and only if Comp is declared within a variant part
10656 --------------------------------
10657 -- Is_Declared_Within_Variant --
10658 --------------------------------
10660 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
10661 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
10662 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
10664 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
10665 end Is_Declared_Within_Variant
;
10668 Prefix_Type
: Entity_Id
;
10669 P_Aliased
: Boolean := False;
10672 Deref
: Node_Id
:= Object
;
10673 -- Dereference node, in something like X.all.Y(2)
10675 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10678 -- Find the dereference node if any
10680 while Nkind_In
(Deref
, N_Indexed_Component
,
10681 N_Selected_Component
,
10684 Deref
:= Prefix
(Deref
);
10687 -- Ada 2005: If we have a component or slice of a dereference,
10688 -- something like X.all.Y (2), and the type of X is access-to-constant,
10689 -- Is_Variable will return False, because it is indeed a constant
10690 -- view. But it might be a view of a variable object, so we want the
10691 -- following condition to be True in that case.
10693 if Is_Variable
(Object
)
10694 or else (Ada_Version
>= Ada_2005
10695 and then Nkind
(Deref
) = N_Explicit_Dereference
)
10697 if Nkind
(Object
) = N_Selected_Component
then
10698 P
:= Prefix
(Object
);
10699 Prefix_Type
:= Etype
(P
);
10701 if Is_Entity_Name
(P
) then
10702 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
10703 Prefix_Type
:= Base_Type
(Prefix_Type
);
10706 if Is_Aliased
(Entity
(P
)) then
10710 -- A discriminant check on a selected component may be expanded
10711 -- into a dereference when removing side-effects. Recover the
10712 -- original node and its type, which may be unconstrained.
10714 elsif Nkind
(P
) = N_Explicit_Dereference
10715 and then not (Comes_From_Source
(P
))
10717 P
:= Original_Node
(P
);
10718 Prefix_Type
:= Etype
(P
);
10721 -- Check for prefix being an aliased component???
10727 -- A heap object is constrained by its initial value
10729 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10730 -- the dereferenced case, since the access value might denote an
10731 -- unconstrained aliased object, whereas in Ada 95 the designated
10732 -- object is guaranteed to be constrained. A worst-case assumption
10733 -- has to apply in Ada 2005 because we can't tell at compile
10734 -- time whether the object is "constrained by its initial value"
10735 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10736 -- rules (these rules are acknowledged to need fixing).
10738 if Ada_Version
< Ada_2005
then
10739 if Is_Access_Type
(Prefix_Type
)
10740 or else Nkind
(P
) = N_Explicit_Dereference
10745 else pragma Assert
(Ada_Version
>= Ada_2005
);
10746 if Is_Access_Type
(Prefix_Type
) then
10748 -- If the access type is pool-specific, and there is no
10749 -- constrained partial view of the designated type, then the
10750 -- designated object is known to be constrained.
10752 if Ekind
(Prefix_Type
) = E_Access_Type
10753 and then not Object_Type_Has_Constrained_Partial_View
10754 (Typ
=> Designated_Type
(Prefix_Type
),
10755 Scop
=> Current_Scope
)
10759 -- Otherwise (general access type, or there is a constrained
10760 -- partial view of the designated type), we need to check
10761 -- based on the designated type.
10764 Prefix_Type
:= Designated_Type
(Prefix_Type
);
10770 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
10772 -- As per AI-0017, the renaming is illegal in a generic body, even
10773 -- if the subtype is indefinite.
10775 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10777 if not Is_Constrained
(Prefix_Type
)
10778 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
10780 (Is_Generic_Type
(Prefix_Type
)
10781 and then Ekind
(Current_Scope
) = E_Generic_Package
10782 and then In_Package_Body
(Current_Scope
)))
10784 and then (Is_Declared_Within_Variant
(Comp
)
10785 or else Has_Discriminant_Dependent_Constraint
(Comp
))
10786 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
10790 -- If the prefix is of an access type at this point, then we want
10791 -- to return False, rather than calling this function recursively
10792 -- on the access object (which itself might be a discriminant-
10793 -- dependent component of some other object, but that isn't
10794 -- relevant to checking the object passed to us). This avoids
10795 -- issuing wrong errors when compiling with -gnatc, where there
10796 -- can be implicit dereferences that have not been expanded.
10798 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
10803 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10806 elsif Nkind
(Object
) = N_Indexed_Component
10807 or else Nkind
(Object
) = N_Slice
10809 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10811 -- A type conversion that Is_Variable is a view conversion:
10812 -- go back to the denoted object.
10814 elsif Nkind
(Object
) = N_Type_Conversion
then
10816 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
10821 end Is_Dependent_Component_Of_Mutable_Object
;
10823 ---------------------
10824 -- Is_Dereferenced --
10825 ---------------------
10827 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
10828 P
: constant Node_Id
:= Parent
(N
);
10830 return Nkind_In
(P
, N_Selected_Component
,
10831 N_Explicit_Dereference
,
10832 N_Indexed_Component
,
10834 and then Prefix
(P
) = N
;
10835 end Is_Dereferenced
;
10837 ----------------------
10838 -- Is_Descendent_Of --
10839 ----------------------
10841 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
10846 pragma Assert
(Nkind
(T1
) in N_Entity
);
10847 pragma Assert
(Nkind
(T2
) in N_Entity
);
10849 T
:= Base_Type
(T1
);
10851 -- Immediate return if the types match
10856 -- Comment needed here ???
10858 elsif Ekind
(T
) = E_Class_Wide_Type
then
10859 return Etype
(T
) = T2
;
10867 -- Done if we found the type we are looking for
10872 -- Done if no more derivations to check
10879 -- Following test catches error cases resulting from prev errors
10881 elsif No
(Etyp
) then
10884 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
10887 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
10891 T
:= Base_Type
(Etyp
);
10894 end Is_Descendent_Of
;
10896 -----------------------------
10897 -- Is_Effectively_Volatile --
10898 -----------------------------
10900 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
10902 if Is_Type
(Id
) then
10904 -- An arbitrary type is effectively volatile when it is subject to
10905 -- pragma Atomic or Volatile.
10907 if Is_Volatile
(Id
) then
10910 -- An array type is effectively volatile when it is subject to pragma
10911 -- Atomic_Components or Volatile_Components or its compolent type is
10912 -- effectively volatile.
10914 elsif Is_Array_Type
(Id
) then
10916 Has_Volatile_Components
(Id
)
10918 Is_Effectively_Volatile
(Component_Type
(Base_Type
(Id
)));
10924 -- Otherwise Id denotes an object
10929 or else Has_Volatile_Components
(Id
)
10930 or else Is_Effectively_Volatile
(Etype
(Id
));
10932 end Is_Effectively_Volatile
;
10934 ------------------------------------
10935 -- Is_Effectively_Volatile_Object --
10936 ------------------------------------
10938 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
10940 if Is_Entity_Name
(N
) then
10941 return Is_Effectively_Volatile
(Entity
(N
));
10943 elsif Nkind
(N
) = N_Expanded_Name
then
10944 return Is_Effectively_Volatile
(Entity
(N
));
10946 elsif Nkind
(N
) = N_Indexed_Component
then
10947 return Is_Effectively_Volatile_Object
(Prefix
(N
));
10949 elsif Nkind
(N
) = N_Selected_Component
then
10951 Is_Effectively_Volatile_Object
(Prefix
(N
))
10953 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
10958 end Is_Effectively_Volatile_Object
;
10960 ----------------------------
10961 -- Is_Expression_Function --
10962 ----------------------------
10964 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
10968 if Ekind
(Subp
) /= E_Function
then
10972 Decl
:= Unit_Declaration_Node
(Subp
);
10973 return Nkind
(Decl
) = N_Subprogram_Declaration
10975 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
10977 (Present
(Corresponding_Body
(Decl
))
10979 Nkind
(Original_Node
10980 (Unit_Declaration_Node
10981 (Corresponding_Body
(Decl
)))) =
10982 N_Expression_Function
));
10984 end Is_Expression_Function
;
10986 -----------------------
10987 -- Is_EVF_Expression --
10988 -----------------------
10990 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
10991 Orig_N
: constant Node_Id
:= Original_Node
(N
);
10997 -- Detect a reference to a formal parameter of a specific tagged type
10998 -- whose related subprogram is subject to pragma Expresions_Visible with
11001 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
11006 and then Is_Specific_Tagged_Type
(Etype
(Id
))
11007 and then Extensions_Visible_Status
(Id
) =
11008 Extensions_Visible_False
;
11010 -- A case expression is an EVF expression when it contains at least one
11011 -- EVF dependent_expression. Note that a case expression may have been
11012 -- expanded, hence the use of Original_Node.
11014 elsif Nkind
(Orig_N
) = N_Case_Expression
then
11015 Alt
:= First
(Alternatives
(Orig_N
));
11016 while Present
(Alt
) loop
11017 if Is_EVF_Expression
(Expression
(Alt
)) then
11024 -- An if expression is an EVF expression when it contains at least one
11025 -- EVF dependent_expression. Note that an if expression may have been
11026 -- expanded, hence the use of Original_Node.
11028 elsif Nkind
(Orig_N
) = N_If_Expression
then
11029 Expr
:= Next
(First
(Expressions
(Orig_N
)));
11030 while Present
(Expr
) loop
11031 if Is_EVF_Expression
(Expr
) then
11038 -- A qualified expression or a type conversion is an EVF expression when
11039 -- its operand is an EVF expression.
11041 elsif Nkind_In
(N
, N_Qualified_Expression
,
11042 N_Unchecked_Type_Conversion
,
11045 return Is_EVF_Expression
(Expression
(N
));
11047 -- Attributes 'Loop_Entry, 'Old and 'Update are an EVF expression when
11048 -- their prefix denotes an EVF expression.
11050 elsif Nkind
(N
) = N_Attribute_Reference
11051 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
11055 return Is_EVF_Expression
(Prefix
(N
));
11059 end Is_EVF_Expression
;
11065 function Is_False
(U
: Uint
) return Boolean is
11070 ---------------------------
11071 -- Is_Fixed_Model_Number --
11072 ---------------------------
11074 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
11075 S
: constant Ureal
:= Small_Value
(T
);
11076 M
: Urealp
.Save_Mark
;
11080 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
11081 Urealp
.Release
(M
);
11083 end Is_Fixed_Model_Number
;
11085 -------------------------------
11086 -- Is_Fully_Initialized_Type --
11087 -------------------------------
11089 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
11093 if Is_Scalar_Type
(Typ
) then
11095 -- A scalar type with an aspect Default_Value is fully initialized
11097 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
11098 -- of a scalar type, but we don't take that into account here, since
11099 -- we don't want these to affect warnings.
11101 return Has_Default_Aspect
(Typ
);
11103 elsif Is_Access_Type
(Typ
) then
11106 elsif Is_Array_Type
(Typ
) then
11107 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
11108 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
11113 -- An interesting case, if we have a constrained type one of whose
11114 -- bounds is known to be null, then there are no elements to be
11115 -- initialized, so all the elements are initialized.
11117 if Is_Constrained
(Typ
) then
11120 Indx_Typ
: Entity_Id
;
11121 Lbd
, Hbd
: Node_Id
;
11124 Indx
:= First_Index
(Typ
);
11125 while Present
(Indx
) loop
11126 if Etype
(Indx
) = Any_Type
then
11129 -- If index is a range, use directly
11131 elsif Nkind
(Indx
) = N_Range
then
11132 Lbd
:= Low_Bound
(Indx
);
11133 Hbd
:= High_Bound
(Indx
);
11136 Indx_Typ
:= Etype
(Indx
);
11138 if Is_Private_Type
(Indx_Typ
) then
11139 Indx_Typ
:= Full_View
(Indx_Typ
);
11142 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
11145 Lbd
:= Type_Low_Bound
(Indx_Typ
);
11146 Hbd
:= Type_High_Bound
(Indx_Typ
);
11150 if Compile_Time_Known_Value
(Lbd
)
11152 Compile_Time_Known_Value
(Hbd
)
11154 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
11164 -- If no null indexes, then type is not fully initialized
11170 elsif Is_Record_Type
(Typ
) then
11171 if Has_Discriminants
(Typ
)
11173 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
11174 and then Is_Fully_Initialized_Variant
(Typ
)
11179 -- We consider bounded string types to be fully initialized, because
11180 -- otherwise we get false alarms when the Data component is not
11181 -- default-initialized.
11183 if Is_Bounded_String
(Typ
) then
11187 -- Controlled records are considered to be fully initialized if
11188 -- there is a user defined Initialize routine. This may not be
11189 -- entirely correct, but as the spec notes, we are guessing here
11190 -- what is best from the point of view of issuing warnings.
11192 if Is_Controlled
(Typ
) then
11194 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
11197 if Present
(Utyp
) then
11199 Init
: constant Entity_Id
:=
11201 (Underlying_Type
(Typ
), Name_Initialize
));
11205 and then Comes_From_Source
(Init
)
11207 Is_Predefined_File_Name
11208 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
11212 elsif Has_Null_Extension
(Typ
)
11214 Is_Fully_Initialized_Type
11215 (Etype
(Base_Type
(Typ
)))
11224 -- Otherwise see if all record components are initialized
11230 Ent
:= First_Entity
(Typ
);
11231 while Present
(Ent
) loop
11232 if Ekind
(Ent
) = E_Component
11233 and then (No
(Parent
(Ent
))
11234 or else No
(Expression
(Parent
(Ent
))))
11235 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
11237 -- Special VM case for tag components, which need to be
11238 -- defined in this case, but are never initialized as VMs
11239 -- are using other dispatching mechanisms. Ignore this
11240 -- uninitialized case. Note that this applies both to the
11241 -- uTag entry and the main vtable pointer (CPP_Class case).
11243 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
11252 -- No uninitialized components, so type is fully initialized.
11253 -- Note that this catches the case of no components as well.
11257 elsif Is_Concurrent_Type
(Typ
) then
11260 elsif Is_Private_Type
(Typ
) then
11262 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11268 return Is_Fully_Initialized_Type
(U
);
11275 end Is_Fully_Initialized_Type
;
11277 ----------------------------------
11278 -- Is_Fully_Initialized_Variant --
11279 ----------------------------------
11281 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
11282 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
11283 Constraints
: constant List_Id
:= New_List
;
11284 Components
: constant Elist_Id
:= New_Elmt_List
;
11285 Comp_Elmt
: Elmt_Id
;
11287 Comp_List
: Node_Id
;
11289 Discr_Val
: Node_Id
;
11291 Report_Errors
: Boolean;
11292 pragma Warnings
(Off
, Report_Errors
);
11295 if Serious_Errors_Detected
> 0 then
11299 if Is_Record_Type
(Typ
)
11300 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
11301 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
11303 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
11305 Discr
:= First_Discriminant
(Typ
);
11306 while Present
(Discr
) loop
11307 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
11308 Discr_Val
:= Expression
(Parent
(Discr
));
11310 if Present
(Discr_Val
)
11311 and then Is_OK_Static_Expression
(Discr_Val
)
11313 Append_To
(Constraints
,
11314 Make_Component_Association
(Loc
,
11315 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
11316 Expression
=> New_Copy
(Discr_Val
)));
11324 Next_Discriminant
(Discr
);
11329 Comp_List
=> Comp_List
,
11330 Governed_By
=> Constraints
,
11331 Into
=> Components
,
11332 Report_Errors
=> Report_Errors
);
11334 -- Check that each component present is fully initialized
11336 Comp_Elmt
:= First_Elmt
(Components
);
11337 while Present
(Comp_Elmt
) loop
11338 Comp_Id
:= Node
(Comp_Elmt
);
11340 if Ekind
(Comp_Id
) = E_Component
11341 and then (No
(Parent
(Comp_Id
))
11342 or else No
(Expression
(Parent
(Comp_Id
))))
11343 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
11348 Next_Elmt
(Comp_Elmt
);
11353 elsif Is_Private_Type
(Typ
) then
11355 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11361 return Is_Fully_Initialized_Variant
(U
);
11368 end Is_Fully_Initialized_Variant
;
11370 ----------------------------
11371 -- Is_Inherited_Operation --
11372 ----------------------------
11374 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
11375 pragma Assert
(Is_Overloadable
(E
));
11376 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
11378 return Kind
= N_Full_Type_Declaration
11379 or else Kind
= N_Private_Extension_Declaration
11380 or else Kind
= N_Subtype_Declaration
11381 or else (Ekind
(E
) = E_Enumeration_Literal
11382 and then Is_Derived_Type
(Etype
(E
)));
11383 end Is_Inherited_Operation
;
11385 -------------------------------------
11386 -- Is_Inherited_Operation_For_Type --
11387 -------------------------------------
11389 function Is_Inherited_Operation_For_Type
11391 Typ
: Entity_Id
) return Boolean
11394 -- Check that the operation has been created by the type declaration
11396 return Is_Inherited_Operation
(E
)
11397 and then Defining_Identifier
(Parent
(E
)) = Typ
;
11398 end Is_Inherited_Operation_For_Type
;
11404 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
11405 Ifaces_List
: Elist_Id
;
11406 Iface_Elmt
: Elmt_Id
;
11410 if Is_Class_Wide_Type
(Typ
)
11411 and then Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
11412 Name_Reversible_Iterator
)
11414 Is_Predefined_File_Name
11415 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
11419 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
11422 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
11426 Collect_Interfaces
(Typ
, Ifaces_List
);
11428 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
11429 while Present
(Iface_Elmt
) loop
11430 Iface
:= Node
(Iface_Elmt
);
11431 if Chars
(Iface
) = Name_Forward_Iterator
11433 Is_Predefined_File_Name
11434 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
11439 Next_Elmt
(Iface_Elmt
);
11450 -- We seem to have a lot of overlapping functions that do similar things
11451 -- (testing for left hand sides or lvalues???).
11453 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
11454 P
: constant Node_Id
:= Parent
(N
);
11457 -- Return True if we are the left hand side of an assignment statement
11459 if Nkind
(P
) = N_Assignment_Statement
then
11460 if Name
(P
) = N
then
11466 -- Case of prefix of indexed or selected component or slice
11468 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
11469 and then N
= Prefix
(P
)
11471 -- Here we have the case where the parent P is N.Q or N(Q .. R).
11472 -- If P is an LHS, then N is also effectively an LHS, but there
11473 -- is an important exception. If N is of an access type, then
11474 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
11475 -- case this makes N.all a left hand side but not N itself.
11477 -- If we don't know the type yet, this is the case where we return
11478 -- Unknown, since the answer depends on the type which is unknown.
11480 if No
(Etype
(N
)) then
11483 -- We have an Etype set, so we can check it
11485 elsif Is_Access_Type
(Etype
(N
)) then
11488 -- OK, not access type case, so just test whole expression
11494 -- All other cases are not left hand sides
11501 -----------------------------
11502 -- Is_Library_Level_Entity --
11503 -----------------------------
11505 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
11507 -- The following is a small optimization, and it also properly handles
11508 -- discriminals, which in task bodies might appear in expressions before
11509 -- the corresponding procedure has been created, and which therefore do
11510 -- not have an assigned scope.
11512 if Is_Formal
(E
) then
11516 -- Normal test is simply that the enclosing dynamic scope is Standard
11518 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
11519 end Is_Library_Level_Entity
;
11521 --------------------------------
11522 -- Is_Limited_Class_Wide_Type --
11523 --------------------------------
11525 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
11528 Is_Class_Wide_Type
(Typ
)
11529 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
11530 end Is_Limited_Class_Wide_Type
;
11532 ---------------------------------
11533 -- Is_Local_Variable_Reference --
11534 ---------------------------------
11536 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
11538 if not Is_Entity_Name
(Expr
) then
11543 Ent
: constant Entity_Id
:= Entity
(Expr
);
11544 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
11546 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
11549 return Present
(Sub
) and then Sub
= Current_Subprogram
;
11553 end Is_Local_Variable_Reference
;
11555 -------------------------
11556 -- Is_Object_Reference --
11557 -------------------------
11559 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
11561 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
11562 -- Determine whether N is the name of an internally-generated renaming
11564 --------------------------------------
11565 -- Is_Internally_Generated_Renaming --
11566 --------------------------------------
11568 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
11573 while Present
(P
) loop
11574 if Nkind
(P
) = N_Object_Renaming_Declaration
then
11575 return not Comes_From_Source
(P
);
11576 elsif Is_List_Member
(P
) then
11584 end Is_Internally_Generated_Renaming
;
11586 -- Start of processing for Is_Object_Reference
11589 if Is_Entity_Name
(N
) then
11590 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
11594 when N_Indexed_Component | N_Slice
=>
11596 Is_Object_Reference
(Prefix
(N
))
11597 or else Is_Access_Type
(Etype
(Prefix
(N
)));
11599 -- In Ada 95, a function call is a constant object; a procedure
11602 when N_Function_Call
=>
11603 return Etype
(N
) /= Standard_Void_Type
;
11605 -- Attributes 'Input, 'Old and 'Result produce objects
11607 when N_Attribute_Reference
=>
11610 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
11612 when N_Selected_Component
=>
11614 Is_Object_Reference
(Selector_Name
(N
))
11616 (Is_Object_Reference
(Prefix
(N
))
11617 or else Is_Access_Type
(Etype
(Prefix
(N
))));
11619 when N_Explicit_Dereference
=>
11622 -- A view conversion of a tagged object is an object reference
11624 when N_Type_Conversion
=>
11625 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
11626 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
11627 and then Is_Object_Reference
(Expression
(N
));
11629 -- An unchecked type conversion is considered to be an object if
11630 -- the operand is an object (this construction arises only as a
11631 -- result of expansion activities).
11633 when N_Unchecked_Type_Conversion
=>
11636 -- Allow string literals to act as objects as long as they appear
11637 -- in internally-generated renamings. The expansion of iterators
11638 -- may generate such renamings when the range involves a string
11641 when N_String_Literal
=>
11642 return Is_Internally_Generated_Renaming
(Parent
(N
));
11644 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11645 -- This allows disambiguation of function calls and the use
11646 -- of aggregates in more contexts.
11648 when N_Qualified_Expression
=>
11649 if Ada_Version
< Ada_2012
then
11652 return Is_Object_Reference
(Expression
(N
))
11653 or else Nkind
(Expression
(N
)) = N_Aggregate
;
11660 end Is_Object_Reference
;
11662 -----------------------------------
11663 -- Is_OK_Variable_For_Out_Formal --
11664 -----------------------------------
11666 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
11668 Note_Possible_Modification
(AV
, Sure
=> True);
11670 -- We must reject parenthesized variable names. Comes_From_Source is
11671 -- checked because there are currently cases where the compiler violates
11672 -- this rule (e.g. passing a task object to its controlled Initialize
11673 -- routine). This should be properly documented in sinfo???
11675 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
11678 -- A variable is always allowed
11680 elsif Is_Variable
(AV
) then
11683 -- Generalized indexing operations are rewritten as explicit
11684 -- dereferences, and it is only during resolution that we can
11685 -- check whether the context requires an access_to_variable type.
11687 elsif Nkind
(AV
) = N_Explicit_Dereference
11688 and then Ada_Version
>= Ada_2012
11689 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
11690 and then Present
(Etype
(Original_Node
(AV
)))
11691 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
11693 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
11695 -- Unchecked conversions are allowed only if they come from the
11696 -- generated code, which sometimes uses unchecked conversions for out
11697 -- parameters in cases where code generation is unaffected. We tell
11698 -- source unchecked conversions by seeing if they are rewrites of
11699 -- an original Unchecked_Conversion function call, or of an explicit
11700 -- conversion of a function call or an aggregate (as may happen in the
11701 -- expansion of a packed array aggregate).
11703 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
11704 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
11707 elsif Comes_From_Source
(AV
)
11708 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
11712 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
11713 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
11719 -- Normal type conversions are allowed if argument is a variable
11721 elsif Nkind
(AV
) = N_Type_Conversion
then
11722 if Is_Variable
(Expression
(AV
))
11723 and then Paren_Count
(Expression
(AV
)) = 0
11725 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
11728 -- We also allow a non-parenthesized expression that raises
11729 -- constraint error if it rewrites what used to be a variable
11731 elsif Raises_Constraint_Error
(Expression
(AV
))
11732 and then Paren_Count
(Expression
(AV
)) = 0
11733 and then Is_Variable
(Original_Node
(Expression
(AV
)))
11737 -- Type conversion of something other than a variable
11743 -- If this node is rewritten, then test the original form, if that is
11744 -- OK, then we consider the rewritten node OK (for example, if the
11745 -- original node is a conversion, then Is_Variable will not be true
11746 -- but we still want to allow the conversion if it converts a variable).
11748 elsif Original_Node
(AV
) /= AV
then
11750 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11751 -- Reference function.
11753 if Ada_Version
>= Ada_2012
11754 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
11756 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
11761 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
11764 -- All other non-variables are rejected
11769 end Is_OK_Variable_For_Out_Formal
;
11771 -----------------------------------
11772 -- Is_Partially_Initialized_Type --
11773 -----------------------------------
11775 function Is_Partially_Initialized_Type
11777 Include_Implicit
: Boolean := True) return Boolean
11780 if Is_Scalar_Type
(Typ
) then
11783 elsif Is_Access_Type
(Typ
) then
11784 return Include_Implicit
;
11786 elsif Is_Array_Type
(Typ
) then
11788 -- If component type is partially initialized, so is array type
11790 if Is_Partially_Initialized_Type
11791 (Component_Type
(Typ
), Include_Implicit
)
11795 -- Otherwise we are only partially initialized if we are fully
11796 -- initialized (this is the empty array case, no point in us
11797 -- duplicating that code here).
11800 return Is_Fully_Initialized_Type
(Typ
);
11803 elsif Is_Record_Type
(Typ
) then
11805 -- A discriminated type is always partially initialized if in
11808 if Has_Discriminants
(Typ
) and then Include_Implicit
then
11811 -- A tagged type is always partially initialized
11813 elsif Is_Tagged_Type
(Typ
) then
11816 -- Case of non-discriminated record
11822 Component_Present
: Boolean := False;
11823 -- Set True if at least one component is present. If no
11824 -- components are present, then record type is fully
11825 -- initialized (another odd case, like the null array).
11828 -- Loop through components
11830 Ent
:= First_Entity
(Typ
);
11831 while Present
(Ent
) loop
11832 if Ekind
(Ent
) = E_Component
then
11833 Component_Present
:= True;
11835 -- If a component has an initialization expression then
11836 -- the enclosing record type is partially initialized
11838 if Present
(Parent
(Ent
))
11839 and then Present
(Expression
(Parent
(Ent
)))
11843 -- If a component is of a type which is itself partially
11844 -- initialized, then the enclosing record type is also.
11846 elsif Is_Partially_Initialized_Type
11847 (Etype
(Ent
), Include_Implicit
)
11856 -- No initialized components found. If we found any components
11857 -- they were all uninitialized so the result is false.
11859 if Component_Present
then
11862 -- But if we found no components, then all the components are
11863 -- initialized so we consider the type to be initialized.
11871 -- Concurrent types are always fully initialized
11873 elsif Is_Concurrent_Type
(Typ
) then
11876 -- For a private type, go to underlying type. If there is no underlying
11877 -- type then just assume this partially initialized. Not clear if this
11878 -- can happen in a non-error case, but no harm in testing for this.
11880 elsif Is_Private_Type
(Typ
) then
11882 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11887 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
11891 -- For any other type (are there any?) assume partially initialized
11896 end Is_Partially_Initialized_Type
;
11898 ------------------------------------
11899 -- Is_Potentially_Persistent_Type --
11900 ------------------------------------
11902 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
11907 -- For private type, test corresponding full type
11909 if Is_Private_Type
(T
) then
11910 return Is_Potentially_Persistent_Type
(Full_View
(T
));
11912 -- Scalar types are potentially persistent
11914 elsif Is_Scalar_Type
(T
) then
11917 -- Record type is potentially persistent if not tagged and the types of
11918 -- all it components are potentially persistent, and no component has
11919 -- an initialization expression.
11921 elsif Is_Record_Type
(T
)
11922 and then not Is_Tagged_Type
(T
)
11923 and then not Is_Partially_Initialized_Type
(T
)
11925 Comp
:= First_Component
(T
);
11926 while Present
(Comp
) loop
11927 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
11930 Next_Entity
(Comp
);
11936 -- Array type is potentially persistent if its component type is
11937 -- potentially persistent and if all its constraints are static.
11939 elsif Is_Array_Type
(T
) then
11940 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
11944 Indx
:= First_Index
(T
);
11945 while Present
(Indx
) loop
11946 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
11955 -- All other types are not potentially persistent
11960 end Is_Potentially_Persistent_Type
;
11962 --------------------------------
11963 -- Is_Potentially_Unevaluated --
11964 --------------------------------
11966 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
11974 -- A postcondition whose expression is a short-circuit is broken down
11975 -- into individual aspects for better exception reporting. The original
11976 -- short-circuit expression is rewritten as the second operand, and an
11977 -- occurrence of 'Old in that operand is potentially unevaluated.
11978 -- See Sem_ch13.adb for details of this transformation.
11980 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
11984 while not Nkind_In
(Par
, N_If_Expression
,
11992 Par
:= Parent
(Par
);
11994 -- If the context is not an expression, or if is the result of
11995 -- expansion of an enclosing construct (such as another attribute)
11996 -- the predicate does not apply.
11998 if Nkind
(Par
) not in N_Subexpr
11999 or else not Comes_From_Source
(Par
)
12005 if Nkind
(Par
) = N_If_Expression
then
12006 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
12008 elsif Nkind
(Par
) = N_Case_Expression
then
12009 return Expr
/= Expression
(Par
);
12011 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
12012 return Expr
= Right_Opnd
(Par
);
12014 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
12015 return Expr
/= Left_Opnd
(Par
);
12020 end Is_Potentially_Unevaluated
;
12022 ---------------------------------
12023 -- Is_Protected_Self_Reference --
12024 ---------------------------------
12026 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
12028 function In_Access_Definition
(N
: Node_Id
) return Boolean;
12029 -- Returns true if N belongs to an access definition
12031 --------------------------
12032 -- In_Access_Definition --
12033 --------------------------
12035 function In_Access_Definition
(N
: Node_Id
) return Boolean is
12040 while Present
(P
) loop
12041 if Nkind
(P
) = N_Access_Definition
then
12049 end In_Access_Definition
;
12051 -- Start of processing for Is_Protected_Self_Reference
12054 -- Verify that prefix is analyzed and has the proper form. Note that
12055 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
12056 -- which also produce the address of an entity, do not analyze their
12057 -- prefix because they denote entities that are not necessarily visible.
12058 -- Neither of them can apply to a protected type.
12060 return Ada_Version
>= Ada_2005
12061 and then Is_Entity_Name
(N
)
12062 and then Present
(Entity
(N
))
12063 and then Is_Protected_Type
(Entity
(N
))
12064 and then In_Open_Scopes
(Entity
(N
))
12065 and then not In_Access_Definition
(N
);
12066 end Is_Protected_Self_Reference
;
12068 -----------------------------
12069 -- Is_RCI_Pkg_Spec_Or_Body --
12070 -----------------------------
12072 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
12074 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
12075 -- Return True if the unit of Cunit is an RCI package declaration
12077 ---------------------------
12078 -- Is_RCI_Pkg_Decl_Cunit --
12079 ---------------------------
12081 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
12082 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
12085 if Nkind
(The_Unit
) /= N_Package_Declaration
then
12089 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
12090 end Is_RCI_Pkg_Decl_Cunit
;
12092 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12095 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
12097 (Nkind
(Unit
(Cunit
)) = N_Package_Body
12098 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
12099 end Is_RCI_Pkg_Spec_Or_Body
;
12101 -----------------------------------------
12102 -- Is_Remote_Access_To_Class_Wide_Type --
12103 -----------------------------------------
12105 function Is_Remote_Access_To_Class_Wide_Type
12106 (E
: Entity_Id
) return Boolean
12109 -- A remote access to class-wide type is a general access to object type
12110 -- declared in the visible part of a Remote_Types or Remote_Call_
12113 return Ekind
(E
) = E_General_Access_Type
12114 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
12115 end Is_Remote_Access_To_Class_Wide_Type
;
12117 -----------------------------------------
12118 -- Is_Remote_Access_To_Subprogram_Type --
12119 -----------------------------------------
12121 function Is_Remote_Access_To_Subprogram_Type
12122 (E
: Entity_Id
) return Boolean
12125 return (Ekind
(E
) = E_Access_Subprogram_Type
12126 or else (Ekind
(E
) = E_Record_Type
12127 and then Present
(Corresponding_Remote_Type
(E
))))
12128 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
12129 end Is_Remote_Access_To_Subprogram_Type
;
12131 --------------------
12132 -- Is_Remote_Call --
12133 --------------------
12135 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
12137 if Nkind
(N
) not in N_Subprogram_Call
then
12139 -- An entry call cannot be remote
12143 elsif Nkind
(Name
(N
)) in N_Has_Entity
12144 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
12146 -- A subprogram declared in the spec of a RCI package is remote
12150 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
12151 and then Is_Remote_Access_To_Subprogram_Type
12152 (Etype
(Prefix
(Name
(N
))))
12154 -- The dereference of a RAS is a remote call
12158 elsif Present
(Controlling_Argument
(N
))
12159 and then Is_Remote_Access_To_Class_Wide_Type
12160 (Etype
(Controlling_Argument
(N
)))
12162 -- Any primitive operation call with a controlling argument of
12163 -- a RACW type is a remote call.
12168 -- All other calls are local calls
12171 end Is_Remote_Call
;
12173 ----------------------
12174 -- Is_Renamed_Entry --
12175 ----------------------
12177 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
12178 Orig_Node
: Node_Id
:= Empty
;
12179 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
12181 function Is_Entry
(Nam
: Node_Id
) return Boolean;
12182 -- Determine whether Nam is an entry. Traverse selectors if there are
12183 -- nested selected components.
12189 function Is_Entry
(Nam
: Node_Id
) return Boolean is
12191 if Nkind
(Nam
) = N_Selected_Component
then
12192 return Is_Entry
(Selector_Name
(Nam
));
12195 return Ekind
(Entity
(Nam
)) = E_Entry
;
12198 -- Start of processing for Is_Renamed_Entry
12201 if Present
(Alias
(Proc_Nam
)) then
12202 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
12205 -- Look for a rewritten subprogram renaming declaration
12207 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
12208 and then Present
(Original_Node
(Subp_Decl
))
12210 Orig_Node
:= Original_Node
(Subp_Decl
);
12213 -- The rewritten subprogram is actually an entry
12215 if Present
(Orig_Node
)
12216 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
12217 and then Is_Entry
(Name
(Orig_Node
))
12223 end Is_Renamed_Entry
;
12225 ----------------------------
12226 -- Is_Reversible_Iterator --
12227 ----------------------------
12229 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
12230 Ifaces_List
: Elist_Id
;
12231 Iface_Elmt
: Elmt_Id
;
12235 if Is_Class_Wide_Type
(Typ
)
12236 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
12237 and then Is_Predefined_File_Name
12238 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
12242 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
12246 Collect_Interfaces
(Typ
, Ifaces_List
);
12248 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
12249 while Present
(Iface_Elmt
) loop
12250 Iface
:= Node
(Iface_Elmt
);
12251 if Chars
(Iface
) = Name_Reversible_Iterator
12253 Is_Predefined_File_Name
12254 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
12259 Next_Elmt
(Iface_Elmt
);
12264 end Is_Reversible_Iterator
;
12266 ----------------------
12267 -- Is_Selector_Name --
12268 ----------------------
12270 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
12272 if not Is_List_Member
(N
) then
12274 P
: constant Node_Id
:= Parent
(N
);
12276 return Nkind_In
(P
, N_Expanded_Name
,
12277 N_Generic_Association
,
12278 N_Parameter_Association
,
12279 N_Selected_Component
)
12280 and then Selector_Name
(P
) = N
;
12285 L
: constant List_Id
:= List_Containing
(N
);
12286 P
: constant Node_Id
:= Parent
(L
);
12288 return (Nkind
(P
) = N_Discriminant_Association
12289 and then Selector_Names
(P
) = L
)
12291 (Nkind
(P
) = N_Component_Association
12292 and then Choices
(P
) = L
);
12295 end Is_Selector_Name
;
12297 -------------------------------------
12298 -- Is_SPARK_05_Initialization_Expr --
12299 -------------------------------------
12301 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
12304 Comp_Assn
: Node_Id
;
12305 Orig_N
: constant Node_Id
:= Original_Node
(N
);
12310 if not Comes_From_Source
(Orig_N
) then
12314 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
12316 case Nkind
(Orig_N
) is
12317 when N_Character_Literal |
12318 N_Integer_Literal |
12320 N_String_Literal
=>
12323 when N_Identifier |
12325 if Is_Entity_Name
(Orig_N
)
12326 and then Present
(Entity
(Orig_N
)) -- needed in some cases
12328 case Ekind
(Entity
(Orig_N
)) is
12330 E_Enumeration_Literal |
12335 if Is_Type
(Entity
(Orig_N
)) then
12343 when N_Qualified_Expression |
12344 N_Type_Conversion
=>
12345 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
12348 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12352 N_Membership_Test
=>
12353 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
12355 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12358 N_Extension_Aggregate
=>
12359 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
12361 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
12364 Expr
:= First
(Expressions
(Orig_N
));
12365 while Present
(Expr
) loop
12366 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
12374 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
12375 while Present
(Comp_Assn
) loop
12376 Expr
:= Expression
(Comp_Assn
);
12378 -- Note: test for Present here needed for box assocation
12381 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
12390 when N_Attribute_Reference
=>
12391 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
12392 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
12395 Expr
:= First
(Expressions
(Orig_N
));
12396 while Present
(Expr
) loop
12397 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
12405 -- Selected components might be expanded named not yet resolved, so
12406 -- default on the safe side. (Eg on sparklex.ads)
12408 when N_Selected_Component
=>
12417 end Is_SPARK_05_Initialization_Expr
;
12419 ----------------------------------
12420 -- Is_SPARK_05_Object_Reference --
12421 ----------------------------------
12423 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
12425 if Is_Entity_Name
(N
) then
12426 return Present
(Entity
(N
))
12428 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
12429 or else Ekind
(Entity
(N
)) in Formal_Kind
);
12433 when N_Selected_Component
=>
12434 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
12440 end Is_SPARK_05_Object_Reference
;
12442 -----------------------------
12443 -- Is_Specific_Tagged_Type --
12444 -----------------------------
12446 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
12447 Full_Typ
: Entity_Id
;
12450 -- Handle private types
12452 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
12453 Full_Typ
:= Full_View
(Typ
);
12458 -- A specific tagged type is a non-class-wide tagged type
12460 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
12461 end Is_Specific_Tagged_Type
;
12467 function Is_Statement
(N
: Node_Id
) return Boolean is
12470 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
12471 or else Nkind
(N
) = N_Procedure_Call_Statement
;
12474 --------------------------------------------------
12475 -- Is_Subprogram_Stub_Without_Prior_Declaration --
12476 --------------------------------------------------
12478 function Is_Subprogram_Stub_Without_Prior_Declaration
12479 (N
: Node_Id
) return Boolean
12482 -- A subprogram stub without prior declaration serves as declaration for
12483 -- the actual subprogram body. As such, it has an attached defining
12484 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
12486 return Nkind
(N
) = N_Subprogram_Body_Stub
12487 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
12488 end Is_Subprogram_Stub_Without_Prior_Declaration
;
12490 ---------------------------------
12491 -- Is_Synchronized_Tagged_Type --
12492 ---------------------------------
12494 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
12495 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
12498 -- A task or protected type derived from an interface is a tagged type.
12499 -- Such a tagged type is called a synchronized tagged type, as are
12500 -- synchronized interfaces and private extensions whose declaration
12501 -- includes the reserved word synchronized.
12503 return (Is_Tagged_Type
(E
)
12504 and then (Kind
= E_Task_Type
12506 Kind
= E_Protected_Type
))
12509 and then Is_Synchronized_Interface
(E
))
12511 (Ekind
(E
) = E_Record_Type_With_Private
12512 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
12513 and then (Synchronized_Present
(Parent
(E
))
12514 or else Is_Synchronized_Interface
(Etype
(E
))));
12515 end Is_Synchronized_Tagged_Type
;
12521 function Is_Transfer
(N
: Node_Id
) return Boolean is
12522 Kind
: constant Node_Kind
:= Nkind
(N
);
12525 if Kind
= N_Simple_Return_Statement
12527 Kind
= N_Extended_Return_Statement
12529 Kind
= N_Goto_Statement
12531 Kind
= N_Raise_Statement
12533 Kind
= N_Requeue_Statement
12537 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
12538 and then No
(Condition
(N
))
12542 elsif Kind
= N_Procedure_Call_Statement
12543 and then Is_Entity_Name
(Name
(N
))
12544 and then Present
(Entity
(Name
(N
)))
12545 and then No_Return
(Entity
(Name
(N
)))
12549 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
12561 function Is_True
(U
: Uint
) return Boolean is
12566 --------------------------------------
12567 -- Is_Unchecked_Conversion_Instance --
12568 --------------------------------------
12570 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
12571 Gen_Par
: Entity_Id
;
12574 -- Look for a function whose generic parent is the predefined intrinsic
12575 -- function Unchecked_Conversion.
12577 if Ekind
(Id
) = E_Function
then
12578 Gen_Par
:= Generic_Parent
(Parent
(Id
));
12582 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
12583 and then Is_Intrinsic_Subprogram
(Gen_Par
)
12584 and then Is_Predefined_File_Name
12585 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
12589 end Is_Unchecked_Conversion_Instance
;
12591 -------------------------------
12592 -- Is_Universal_Numeric_Type --
12593 -------------------------------
12595 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
12597 return T
= Universal_Integer
or else T
= Universal_Real
;
12598 end Is_Universal_Numeric_Type
;
12600 -------------------
12601 -- Is_Value_Type --
12602 -------------------
12604 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
12606 return VM_Target
= CLI_Target
12607 and then Nkind
(T
) in N_Has_Chars
12608 and then Chars
(T
) /= No_Name
12609 and then Get_Name_String
(Chars
(T
)) = "valuetype";
12612 ----------------------------
12613 -- Is_Variable_Size_Array --
12614 ----------------------------
12616 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
12620 pragma Assert
(Is_Array_Type
(E
));
12622 -- Check if some index is initialized with a non-constant value
12624 Idx
:= First_Index
(E
);
12625 while Present
(Idx
) loop
12626 if Nkind
(Idx
) = N_Range
then
12627 if not Is_Constant_Bound
(Low_Bound
(Idx
))
12628 or else not Is_Constant_Bound
(High_Bound
(Idx
))
12634 Idx
:= Next_Index
(Idx
);
12638 end Is_Variable_Size_Array
;
12640 -----------------------------
12641 -- Is_Variable_Size_Record --
12642 -----------------------------
12644 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
12646 Comp_Typ
: Entity_Id
;
12649 pragma Assert
(Is_Record_Type
(E
));
12651 Comp
:= First_Entity
(E
);
12652 while Present
(Comp
) loop
12653 Comp_Typ
:= Etype
(Comp
);
12655 -- Recursive call if the record type has discriminants
12657 if Is_Record_Type
(Comp_Typ
)
12658 and then Has_Discriminants
(Comp_Typ
)
12659 and then Is_Variable_Size_Record
(Comp_Typ
)
12663 elsif Is_Array_Type
(Comp_Typ
)
12664 and then Is_Variable_Size_Array
(Comp_Typ
)
12669 Next_Entity
(Comp
);
12673 end Is_Variable_Size_Record
;
12679 function Is_Variable
12681 Use_Original_Node
: Boolean := True) return Boolean
12683 Orig_Node
: Node_Id
;
12685 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
12686 -- Within a protected function, the private components of the enclosing
12687 -- protected type are constants. A function nested within a (protected)
12688 -- procedure is not itself protected. Within the body of a protected
12689 -- function the current instance of the protected type is a constant.
12691 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
12692 -- Prefixes can involve implicit dereferences, in which case we must
12693 -- test for the case of a reference of a constant access type, which can
12694 -- can never be a variable.
12696 ---------------------------
12697 -- In_Protected_Function --
12698 ---------------------------
12700 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
12705 -- E is the current instance of a type
12707 if Is_Type
(E
) then
12716 if not Is_Protected_Type
(Prot
) then
12720 S
:= Current_Scope
;
12721 while Present
(S
) and then S
/= Prot
loop
12722 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
12731 end In_Protected_Function
;
12733 ------------------------
12734 -- Is_Variable_Prefix --
12735 ------------------------
12737 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
12739 if Is_Access_Type
(Etype
(P
)) then
12740 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
12742 -- For the case of an indexed component whose prefix has a packed
12743 -- array type, the prefix has been rewritten into a type conversion.
12744 -- Determine variable-ness from the converted expression.
12746 elsif Nkind
(P
) = N_Type_Conversion
12747 and then not Comes_From_Source
(P
)
12748 and then Is_Array_Type
(Etype
(P
))
12749 and then Is_Packed
(Etype
(P
))
12751 return Is_Variable
(Expression
(P
));
12754 return Is_Variable
(P
);
12756 end Is_Variable_Prefix
;
12758 -- Start of processing for Is_Variable
12761 -- Check if we perform the test on the original node since this may be a
12762 -- test of syntactic categories which must not be disturbed by whatever
12763 -- rewriting might have occurred. For example, an aggregate, which is
12764 -- certainly NOT a variable, could be turned into a variable by
12767 if Use_Original_Node
then
12768 Orig_Node
:= Original_Node
(N
);
12773 -- Definitely OK if Assignment_OK is set. Since this is something that
12774 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12776 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
12779 -- Normally we go to the original node, but there is one exception where
12780 -- we use the rewritten node, namely when it is an explicit dereference.
12781 -- The generated code may rewrite a prefix which is an access type with
12782 -- an explicit dereference. The dereference is a variable, even though
12783 -- the original node may not be (since it could be a constant of the
12786 -- In Ada 2005 we have a further case to consider: the prefix may be a
12787 -- function call given in prefix notation. The original node appears to
12788 -- be a selected component, but we need to examine the call.
12790 elsif Nkind
(N
) = N_Explicit_Dereference
12791 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
12792 and then Present
(Etype
(Orig_Node
))
12793 and then Is_Access_Type
(Etype
(Orig_Node
))
12795 -- Note that if the prefix is an explicit dereference that does not
12796 -- come from source, we must check for a rewritten function call in
12797 -- prefixed notation before other forms of rewriting, to prevent a
12801 (Nkind
(Orig_Node
) = N_Function_Call
12802 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
12804 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
12806 -- in Ada 2012, the dereference may have been added for a type with
12807 -- a declared implicit dereference aspect. Check that it is not an
12808 -- access to constant.
12810 elsif Nkind
(N
) = N_Explicit_Dereference
12811 and then Present
(Etype
(Orig_Node
))
12812 and then Ada_Version
>= Ada_2012
12813 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
12815 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
12817 -- A function call is never a variable
12819 elsif Nkind
(N
) = N_Function_Call
then
12822 -- All remaining checks use the original node
12824 elsif Is_Entity_Name
(Orig_Node
)
12825 and then Present
(Entity
(Orig_Node
))
12828 E
: constant Entity_Id
:= Entity
(Orig_Node
);
12829 K
: constant Entity_Kind
:= Ekind
(E
);
12832 return (K
= E_Variable
12833 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
12834 or else (K
= E_Component
12835 and then not In_Protected_Function
(E
))
12836 or else K
= E_Out_Parameter
12837 or else K
= E_In_Out_Parameter
12838 or else K
= E_Generic_In_Out_Parameter
12840 -- Current instance of type. If this is a protected type, check
12841 -- we are not within the body of one of its protected functions.
12843 or else (Is_Type
(E
)
12844 and then In_Open_Scopes
(E
)
12845 and then not In_Protected_Function
(E
))
12847 or else (Is_Incomplete_Or_Private_Type
(E
)
12848 and then In_Open_Scopes
(Full_View
(E
)));
12852 case Nkind
(Orig_Node
) is
12853 when N_Indexed_Component | N_Slice
=>
12854 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
12856 when N_Selected_Component
=>
12857 return (Is_Variable
(Selector_Name
(Orig_Node
))
12858 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
12860 (Nkind
(N
) = N_Expanded_Name
12861 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
12863 -- For an explicit dereference, the type of the prefix cannot
12864 -- be an access to constant or an access to subprogram.
12866 when N_Explicit_Dereference
=>
12868 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
12870 return Is_Access_Type
(Typ
)
12871 and then not Is_Access_Constant
(Root_Type
(Typ
))
12872 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
12875 -- The type conversion is the case where we do not deal with the
12876 -- context dependent special case of an actual parameter. Thus
12877 -- the type conversion is only considered a variable for the
12878 -- purposes of this routine if the target type is tagged. However,
12879 -- a type conversion is considered to be a variable if it does not
12880 -- come from source (this deals for example with the conversions
12881 -- of expressions to their actual subtypes).
12883 when N_Type_Conversion
=>
12884 return Is_Variable
(Expression
(Orig_Node
))
12886 (not Comes_From_Source
(Orig_Node
)
12888 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
12890 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
12892 -- GNAT allows an unchecked type conversion as a variable. This
12893 -- only affects the generation of internal expanded code, since
12894 -- calls to instantiations of Unchecked_Conversion are never
12895 -- considered variables (since they are function calls).
12897 when N_Unchecked_Type_Conversion
=>
12898 return Is_Variable
(Expression
(Orig_Node
));
12906 ---------------------------
12907 -- Is_Visibly_Controlled --
12908 ---------------------------
12910 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
12911 Root
: constant Entity_Id
:= Root_Type
(T
);
12913 return Chars
(Scope
(Root
)) = Name_Finalization
12914 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
12915 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
12916 end Is_Visibly_Controlled
;
12918 ------------------------
12919 -- Is_Volatile_Object --
12920 ------------------------
12922 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
12924 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
12925 -- If prefix is an implicit dereference, examine designated type
12927 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
12928 -- Determines if given object has volatile components
12930 ------------------------
12931 -- Is_Volatile_Prefix --
12932 ------------------------
12934 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
12935 Typ
: constant Entity_Id
:= Etype
(N
);
12938 if Is_Access_Type
(Typ
) then
12940 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
12943 return Is_Volatile
(Dtyp
)
12944 or else Has_Volatile_Components
(Dtyp
);
12948 return Object_Has_Volatile_Components
(N
);
12950 end Is_Volatile_Prefix
;
12952 ------------------------------------
12953 -- Object_Has_Volatile_Components --
12954 ------------------------------------
12956 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
12957 Typ
: constant Entity_Id
:= Etype
(N
);
12960 if Is_Volatile
(Typ
)
12961 or else Has_Volatile_Components
(Typ
)
12965 elsif Is_Entity_Name
(N
)
12966 and then (Has_Volatile_Components
(Entity
(N
))
12967 or else Is_Volatile
(Entity
(N
)))
12971 elsif Nkind
(N
) = N_Indexed_Component
12972 or else Nkind
(N
) = N_Selected_Component
12974 return Is_Volatile_Prefix
(Prefix
(N
));
12979 end Object_Has_Volatile_Components
;
12981 -- Start of processing for Is_Volatile_Object
12984 if Nkind
(N
) = N_Defining_Identifier
then
12985 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
12987 elsif Nkind
(N
) = N_Expanded_Name
then
12988 return Is_Volatile_Object
(Entity
(N
));
12990 elsif Is_Volatile
(Etype
(N
))
12991 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
12995 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
12996 and then Is_Volatile_Prefix
(Prefix
(N
))
13000 elsif Nkind
(N
) = N_Selected_Component
13001 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
13008 end Is_Volatile_Object
;
13010 ---------------------------
13011 -- Itype_Has_Declaration --
13012 ---------------------------
13014 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
13016 pragma Assert
(Is_Itype
(Id
));
13017 return Present
(Parent
(Id
))
13018 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
13019 N_Subtype_Declaration
)
13020 and then Defining_Entity
(Parent
(Id
)) = Id
;
13021 end Itype_Has_Declaration
;
13023 -------------------------
13024 -- Kill_Current_Values --
13025 -------------------------
13027 procedure Kill_Current_Values
13029 Last_Assignment_Only
: Boolean := False)
13032 if Is_Assignable
(Ent
) then
13033 Set_Last_Assignment
(Ent
, Empty
);
13036 if Is_Object
(Ent
) then
13037 if not Last_Assignment_Only
then
13039 Set_Current_Value
(Ent
, Empty
);
13041 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
13042 -- for a constant. Once the constant is elaborated, its value is
13043 -- not changed, therefore the associated flags that describe the
13044 -- value should not be modified either.
13046 if Ekind
(Ent
) = E_Constant
then
13049 -- Non-constant entities
13052 if not Can_Never_Be_Null
(Ent
) then
13053 Set_Is_Known_Non_Null
(Ent
, False);
13056 Set_Is_Known_Null
(Ent
, False);
13058 -- Reset the Is_Known_Valid flag unless the type is always
13059 -- valid. This does not apply to a loop parameter because its
13060 -- bounds are defined by the loop header and therefore always
13063 if not Is_Known_Valid
(Etype
(Ent
))
13064 and then Ekind
(Ent
) /= E_Loop_Parameter
13066 Set_Is_Known_Valid
(Ent
, False);
13071 end Kill_Current_Values
;
13073 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
13076 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
13077 -- Clear current value for entity E and all entities chained to E
13079 ------------------------------------------
13080 -- Kill_Current_Values_For_Entity_Chain --
13081 ------------------------------------------
13083 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
13087 while Present
(Ent
) loop
13088 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
13091 end Kill_Current_Values_For_Entity_Chain
;
13093 -- Start of processing for Kill_Current_Values
13096 -- Kill all saved checks, a special case of killing saved values
13098 if not Last_Assignment_Only
then
13102 -- Loop through relevant scopes, which includes the current scope and
13103 -- any parent scopes if the current scope is a block or a package.
13105 S
:= Current_Scope
;
13108 -- Clear current values of all entities in current scope
13110 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
13112 -- If scope is a package, also clear current values of all private
13113 -- entities in the scope.
13115 if Is_Package_Or_Generic_Package
(S
)
13116 or else Is_Concurrent_Type
(S
)
13118 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
13121 -- If this is a not a subprogram, deal with parents
13123 if not Is_Subprogram
(S
) then
13125 exit Scope_Loop
when S
= Standard_Standard
;
13129 end loop Scope_Loop
;
13130 end Kill_Current_Values
;
13132 --------------------------
13133 -- Kill_Size_Check_Code --
13134 --------------------------
13136 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
13138 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
13139 and then Present
(Size_Check_Code
(E
))
13141 Remove
(Size_Check_Code
(E
));
13142 Set_Size_Check_Code
(E
, Empty
);
13144 end Kill_Size_Check_Code
;
13146 --------------------------
13147 -- Known_To_Be_Assigned --
13148 --------------------------
13150 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
13151 P
: constant Node_Id
:= Parent
(N
);
13156 -- Test left side of assignment
13158 when N_Assignment_Statement
=>
13159 return N
= Name
(P
);
13161 -- Function call arguments are never lvalues
13163 when N_Function_Call
=>
13166 -- Positional parameter for procedure or accept call
13168 when N_Procedure_Call_Statement |
13177 Proc
:= Get_Subprogram_Entity
(P
);
13183 -- If we are not a list member, something is strange, so
13184 -- be conservative and return False.
13186 if not Is_List_Member
(N
) then
13190 -- We are going to find the right formal by stepping forward
13191 -- through the formals, as we step backwards in the actuals.
13193 Form
:= First_Formal
(Proc
);
13196 -- If no formal, something is weird, so be conservative
13197 -- and return False.
13204 exit when No
(Act
);
13205 Next_Formal
(Form
);
13208 return Ekind
(Form
) /= E_In_Parameter
;
13211 -- Named parameter for procedure or accept call
13213 when N_Parameter_Association
=>
13219 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
13225 -- Loop through formals to find the one that matches
13227 Form
:= First_Formal
(Proc
);
13229 -- If no matching formal, that's peculiar, some kind of
13230 -- previous error, so return False to be conservative.
13231 -- Actually this also happens in legal code in the case
13232 -- where P is a parameter association for an Extra_Formal???
13238 -- Else test for match
13240 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
13241 return Ekind
(Form
) /= E_In_Parameter
;
13244 Next_Formal
(Form
);
13248 -- Test for appearing in a conversion that itself appears
13249 -- in an lvalue context, since this should be an lvalue.
13251 when N_Type_Conversion
=>
13252 return Known_To_Be_Assigned
(P
);
13254 -- All other references are definitely not known to be modifications
13260 end Known_To_Be_Assigned
;
13262 ---------------------------
13263 -- Last_Source_Statement --
13264 ---------------------------
13266 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
13270 N
:= Last
(Statements
(HSS
));
13271 while Present
(N
) loop
13272 exit when Comes_From_Source
(N
);
13277 end Last_Source_Statement
;
13279 ----------------------------------
13280 -- Matching_Static_Array_Bounds --
13281 ----------------------------------
13283 function Matching_Static_Array_Bounds
13285 R_Typ
: Node_Id
) return Boolean
13287 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
13288 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
13300 if L_Ndims
/= R_Ndims
then
13304 -- Unconstrained types do not have static bounds
13306 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
13310 -- First treat specially the first dimension, as the lower bound and
13311 -- length of string literals are not stored like those of arrays.
13313 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
13314 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
13315 L_Len
:= String_Literal_Length
(L_Typ
);
13317 L_Index
:= First_Index
(L_Typ
);
13318 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
13320 if Is_OK_Static_Expression
(L_Low
)
13322 Is_OK_Static_Expression
(L_High
)
13324 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
13327 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
13334 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
13335 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
13336 R_Len
:= String_Literal_Length
(R_Typ
);
13338 R_Index
:= First_Index
(R_Typ
);
13339 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
13341 if Is_OK_Static_Expression
(R_Low
)
13343 Is_OK_Static_Expression
(R_High
)
13345 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
13348 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
13355 if (Is_OK_Static_Expression
(L_Low
)
13357 Is_OK_Static_Expression
(R_Low
))
13358 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
13359 and then L_Len
= R_Len
13366 -- Then treat all other dimensions
13368 for Indx
in 2 .. L_Ndims
loop
13372 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
13373 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
13375 if (Is_OK_Static_Expression
(L_Low
) and then
13376 Is_OK_Static_Expression
(L_High
) and then
13377 Is_OK_Static_Expression
(R_Low
) and then
13378 Is_OK_Static_Expression
(R_High
))
13379 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
13381 Expr_Value
(L_High
) = Expr_Value
(R_High
))
13389 -- If we fall through the loop, all indexes matched
13392 end Matching_Static_Array_Bounds
;
13394 -------------------
13395 -- May_Be_Lvalue --
13396 -------------------
13398 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
13399 P
: constant Node_Id
:= Parent
(N
);
13404 -- Test left side of assignment
13406 when N_Assignment_Statement
=>
13407 return N
= Name
(P
);
13409 -- Test prefix of component or attribute. Note that the prefix of an
13410 -- explicit or implicit dereference cannot be an l-value.
13412 when N_Attribute_Reference
=>
13413 return N
= Prefix
(P
)
13414 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
13416 -- For an expanded name, the name is an lvalue if the expanded name
13417 -- is an lvalue, but the prefix is never an lvalue, since it is just
13418 -- the scope where the name is found.
13420 when N_Expanded_Name
=>
13421 if N
= Prefix
(P
) then
13422 return May_Be_Lvalue
(P
);
13427 -- For a selected component A.B, A is certainly an lvalue if A.B is.
13428 -- B is a little interesting, if we have A.B := 3, there is some
13429 -- discussion as to whether B is an lvalue or not, we choose to say
13430 -- it is. Note however that A is not an lvalue if it is of an access
13431 -- type since this is an implicit dereference.
13433 when N_Selected_Component
=>
13435 and then Present
(Etype
(N
))
13436 and then Is_Access_Type
(Etype
(N
))
13440 return May_Be_Lvalue
(P
);
13443 -- For an indexed component or slice, the index or slice bounds is
13444 -- never an lvalue. The prefix is an lvalue if the indexed component
13445 -- or slice is an lvalue, except if it is an access type, where we
13446 -- have an implicit dereference.
13448 when N_Indexed_Component | N_Slice
=>
13450 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
13454 return May_Be_Lvalue
(P
);
13457 -- Prefix of a reference is an lvalue if the reference is an lvalue
13459 when N_Reference
=>
13460 return May_Be_Lvalue
(P
);
13462 -- Prefix of explicit dereference is never an lvalue
13464 when N_Explicit_Dereference
=>
13467 -- Positional parameter for subprogram, entry, or accept call.
13468 -- In older versions of Ada function call arguments are never
13469 -- lvalues. In Ada 2012 functions can have in-out parameters.
13471 when N_Subprogram_Call |
13472 N_Entry_Call_Statement |
13475 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
13479 -- The following mechanism is clumsy and fragile. A single flag
13480 -- set in Resolve_Actuals would be preferable ???
13488 Proc
:= Get_Subprogram_Entity
(P
);
13494 -- If we are not a list member, something is strange, so be
13495 -- conservative and return True.
13497 if not Is_List_Member
(N
) then
13501 -- We are going to find the right formal by stepping forward
13502 -- through the formals, as we step backwards in the actuals.
13504 Form
:= First_Formal
(Proc
);
13507 -- If no formal, something is weird, so be conservative and
13515 exit when No
(Act
);
13516 Next_Formal
(Form
);
13519 return Ekind
(Form
) /= E_In_Parameter
;
13522 -- Named parameter for procedure or accept call
13524 when N_Parameter_Association
=>
13530 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
13536 -- Loop through formals to find the one that matches
13538 Form
:= First_Formal
(Proc
);
13540 -- If no matching formal, that's peculiar, some kind of
13541 -- previous error, so return True to be conservative.
13542 -- Actually happens with legal code for an unresolved call
13543 -- where we may get the wrong homonym???
13549 -- Else test for match
13551 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
13552 return Ekind
(Form
) /= E_In_Parameter
;
13555 Next_Formal
(Form
);
13559 -- Test for appearing in a conversion that itself appears in an
13560 -- lvalue context, since this should be an lvalue.
13562 when N_Type_Conversion
=>
13563 return May_Be_Lvalue
(P
);
13565 -- Test for appearance in object renaming declaration
13567 when N_Object_Renaming_Declaration
=>
13570 -- All other references are definitely not lvalues
13578 -----------------------
13579 -- Mark_Coextensions --
13580 -----------------------
13582 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
13583 Is_Dynamic
: Boolean;
13584 -- Indicates whether the context causes nested coextensions to be
13585 -- dynamic or static
13587 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
13588 -- Recognize an allocator node and label it as a dynamic coextension
13590 --------------------
13591 -- Mark_Allocator --
13592 --------------------
13594 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
13596 if Nkind
(N
) = N_Allocator
then
13598 Set_Is_Dynamic_Coextension
(N
);
13600 -- If the allocator expression is potentially dynamic, it may
13601 -- be expanded out of order and require dynamic allocation
13602 -- anyway, so we treat the coextension itself as dynamic.
13603 -- Potential optimization ???
13605 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
13606 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
13608 Set_Is_Dynamic_Coextension
(N
);
13610 Set_Is_Static_Coextension
(N
);
13615 end Mark_Allocator
;
13617 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
13619 -- Start of processing Mark_Coextensions
13622 case Nkind
(Context_Nod
) is
13624 -- Comment here ???
13626 when N_Assignment_Statement
=>
13627 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
13629 -- An allocator that is a component of a returned aggregate
13630 -- must be dynamic.
13632 when N_Simple_Return_Statement
=>
13634 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
13637 Nkind
(Expr
) = N_Allocator
13639 (Nkind
(Expr
) = N_Qualified_Expression
13640 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
13643 -- An alloctor within an object declaration in an extended return
13644 -- statement is of necessity dynamic.
13646 when N_Object_Declaration
=>
13647 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
13649 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
13651 -- This routine should not be called for constructs which may not
13652 -- contain coextensions.
13655 raise Program_Error
;
13658 Mark_Allocators
(Root_Nod
);
13659 end Mark_Coextensions
;
13661 ----------------------
13662 -- Needs_One_Actual --
13663 ----------------------
13665 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
13666 Formal
: Entity_Id
;
13669 -- Ada 2005 or later, and formals present
13671 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
13672 Formal
:= Next_Formal
(First_Formal
(E
));
13673 while Present
(Formal
) loop
13674 if No
(Default_Value
(Formal
)) then
13678 Next_Formal
(Formal
);
13683 -- Ada 83/95 or no formals
13688 end Needs_One_Actual
;
13690 ------------------------
13691 -- New_Copy_List_Tree --
13692 ------------------------
13694 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
13699 if List
= No_List
then
13706 while Present
(E
) loop
13707 Append
(New_Copy_Tree
(E
), NL
);
13713 end New_Copy_List_Tree
;
13715 --------------------------------------------------
13716 -- New_Copy_Tree Auxiliary Data and Subprograms --
13717 --------------------------------------------------
13719 use Atree
.Unchecked_Access
;
13720 use Atree_Private_Part
;
13722 -- Our approach here requires a two pass traversal of the tree. The
13723 -- first pass visits all nodes that eventually will be copied looking
13724 -- for defining Itypes. If any defining Itypes are found, then they are
13725 -- copied, and an entry is added to the replacement map. In the second
13726 -- phase, the tree is copied, using the replacement map to replace any
13727 -- Itype references within the copied tree.
13729 -- The following hash tables are used if the Map supplied has more
13730 -- than hash threshold entries to speed up access to the map. If
13731 -- there are fewer entries, then the map is searched sequentially
13732 -- (because setting up a hash table for only a few entries takes
13733 -- more time than it saves.
13735 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
13736 -- Hash function used for hash operations
13738 -------------------
13739 -- New_Copy_Hash --
13740 -------------------
13742 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
13744 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
13751 -- The hash table NCT_Assoc associates old entities in the table
13752 -- with their corresponding new entities (i.e. the pairs of entries
13753 -- presented in the original Map argument are Key-Element pairs).
13755 package NCT_Assoc
is new Simple_HTable
(
13756 Header_Num
=> NCT_Header_Num
,
13757 Element
=> Entity_Id
,
13758 No_Element
=> Empty
,
13760 Hash
=> New_Copy_Hash
,
13761 Equal
=> Types
."=");
13763 ---------------------
13764 -- NCT_Itype_Assoc --
13765 ---------------------
13767 -- The hash table NCT_Itype_Assoc contains entries only for those
13768 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13769 -- The key is the associated node, and the element is the new node
13770 -- itself (NOT the associated node for the new node).
13772 package NCT_Itype_Assoc
is new Simple_HTable
(
13773 Header_Num
=> NCT_Header_Num
,
13774 Element
=> Entity_Id
,
13775 No_Element
=> Empty
,
13777 Hash
=> New_Copy_Hash
,
13778 Equal
=> Types
."=");
13780 -------------------
13781 -- New_Copy_Tree --
13782 -------------------
13784 function New_Copy_Tree
13786 Map
: Elist_Id
:= No_Elist
;
13787 New_Sloc
: Source_Ptr
:= No_Location
;
13788 New_Scope
: Entity_Id
:= Empty
) return Node_Id
13790 Actual_Map
: Elist_Id
:= Map
;
13791 -- This is the actual map for the copy. It is initialized with the
13792 -- given elements, and then enlarged as required for Itypes that are
13793 -- copied during the first phase of the copy operation. The visit
13794 -- procedures add elements to this map as Itypes are encountered.
13795 -- The reason we cannot use Map directly, is that it may well be
13796 -- (and normally is) initialized to No_Elist, and if we have mapped
13797 -- entities, we have to reset it to point to a real Elist.
13799 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
13800 -- Called during second phase to map entities into their corresponding
13801 -- copies using Actual_Map. If the argument is not an entity, or is not
13802 -- in Actual_Map, then it is returned unchanged.
13804 procedure Build_NCT_Hash_Tables
;
13805 -- Builds hash tables (number of elements >= threshold value)
13807 function Copy_Elist_With_Replacement
13808 (Old_Elist
: Elist_Id
) return Elist_Id
;
13809 -- Called during second phase to copy element list doing replacements
13811 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
13812 -- Called during the second phase to process a copied Itype. The actual
13813 -- copy happened during the first phase (so that we could make the entry
13814 -- in the mapping), but we still have to deal with the descendents of
13815 -- the copied Itype and copy them where necessary.
13817 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
13818 -- Called during second phase to copy list doing replacements
13820 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
13821 -- Called during second phase to copy node doing replacements
13823 procedure Visit_Elist
(E
: Elist_Id
);
13824 -- Called during first phase to visit all elements of an Elist
13826 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
13827 -- Visit a single field, recursing to call Visit_Node or Visit_List
13828 -- if the field is a syntactic descendent of the current node (i.e.
13829 -- its parent is Node N).
13831 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
13832 -- Called during first phase to visit subsidiary fields of a defining
13833 -- Itype, and also create a copy and make an entry in the replacement
13834 -- map for the new copy.
13836 procedure Visit_List
(L
: List_Id
);
13837 -- Called during first phase to visit all elements of a List
13839 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
13840 -- Called during first phase to visit a node and all its subtrees
13846 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
13851 if not Has_Extension
(N
) or else No
(Actual_Map
) then
13854 elsif NCT_Hash_Tables_Used
then
13855 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
13857 if Present
(Ent
) then
13863 -- No hash table used, do serial search
13866 E
:= First_Elmt
(Actual_Map
);
13867 while Present
(E
) loop
13868 if Node
(E
) = N
then
13869 return Node
(Next_Elmt
(E
));
13871 E
:= Next_Elmt
(Next_Elmt
(E
));
13879 ---------------------------
13880 -- Build_NCT_Hash_Tables --
13881 ---------------------------
13883 procedure Build_NCT_Hash_Tables
is
13887 if NCT_Hash_Table_Setup
then
13889 NCT_Itype_Assoc
.Reset
;
13892 Elmt
:= First_Elmt
(Actual_Map
);
13893 while Present
(Elmt
) loop
13894 Ent
:= Node
(Elmt
);
13896 -- Get new entity, and associate old and new
13899 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
13901 if Is_Type
(Ent
) then
13903 Anode
: constant Entity_Id
:=
13904 Associated_Node_For_Itype
(Ent
);
13907 if Present
(Anode
) then
13909 -- Enter a link between the associated node of the
13910 -- old Itype and the new Itype, for updating later
13911 -- when node is copied.
13913 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
13921 NCT_Hash_Tables_Used
:= True;
13922 NCT_Hash_Table_Setup
:= True;
13923 end Build_NCT_Hash_Tables
;
13925 ---------------------------------
13926 -- Copy_Elist_With_Replacement --
13927 ---------------------------------
13929 function Copy_Elist_With_Replacement
13930 (Old_Elist
: Elist_Id
) return Elist_Id
13933 New_Elist
: Elist_Id
;
13936 if No
(Old_Elist
) then
13940 New_Elist
:= New_Elmt_List
;
13942 M
:= First_Elmt
(Old_Elist
);
13943 while Present
(M
) loop
13944 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
13950 end Copy_Elist_With_Replacement
;
13952 ---------------------------------
13953 -- Copy_Itype_With_Replacement --
13954 ---------------------------------
13956 -- This routine exactly parallels its phase one analog Visit_Itype,
13958 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
13960 -- Translate Next_Entity, Scope and Etype fields, in case they
13961 -- reference entities that have been mapped into copies.
13963 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
13964 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
13966 if Present
(New_Scope
) then
13967 Set_Scope
(New_Itype
, New_Scope
);
13969 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
13972 -- Copy referenced fields
13974 if Is_Discrete_Type
(New_Itype
) then
13975 Set_Scalar_Range
(New_Itype
,
13976 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
13978 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
13979 Set_Discriminant_Constraint
(New_Itype
,
13980 Copy_Elist_With_Replacement
13981 (Discriminant_Constraint
(New_Itype
)));
13983 elsif Is_Array_Type
(New_Itype
) then
13984 if Present
(First_Index
(New_Itype
)) then
13985 Set_First_Index
(New_Itype
,
13986 First
(Copy_List_With_Replacement
13987 (List_Containing
(First_Index
(New_Itype
)))));
13990 if Is_Packed
(New_Itype
) then
13991 Set_Packed_Array_Impl_Type
(New_Itype
,
13992 Copy_Node_With_Replacement
13993 (Packed_Array_Impl_Type
(New_Itype
)));
13996 end Copy_Itype_With_Replacement
;
13998 --------------------------------
13999 -- Copy_List_With_Replacement --
14000 --------------------------------
14002 function Copy_List_With_Replacement
14003 (Old_List
: List_Id
) return List_Id
14005 New_List
: List_Id
;
14009 if Old_List
= No_List
then
14013 New_List
:= Empty_List
;
14015 E
:= First
(Old_List
);
14016 while Present
(E
) loop
14017 Append
(Copy_Node_With_Replacement
(E
), New_List
);
14023 end Copy_List_With_Replacement
;
14025 --------------------------------
14026 -- Copy_Node_With_Replacement --
14027 --------------------------------
14029 function Copy_Node_With_Replacement
14030 (Old_Node
: Node_Id
) return Node_Id
14032 New_Node
: Node_Id
;
14034 procedure Adjust_Named_Associations
14035 (Old_Node
: Node_Id
;
14036 New_Node
: Node_Id
);
14037 -- If a call node has named associations, these are chained through
14038 -- the First_Named_Actual, Next_Named_Actual links. These must be
14039 -- propagated separately to the new parameter list, because these
14040 -- are not syntactic fields.
14042 function Copy_Field_With_Replacement
14043 (Field
: Union_Id
) return Union_Id
;
14044 -- Given Field, which is a field of Old_Node, return a copy of it
14045 -- if it is a syntactic field (i.e. its parent is Node), setting
14046 -- the parent of the copy to poit to New_Node. Otherwise returns
14047 -- the field (possibly mapped if it is an entity).
14049 -------------------------------
14050 -- Adjust_Named_Associations --
14051 -------------------------------
14053 procedure Adjust_Named_Associations
14054 (Old_Node
: Node_Id
;
14055 New_Node
: Node_Id
)
14060 Old_Next
: Node_Id
;
14061 New_Next
: Node_Id
;
14064 Old_E
:= First
(Parameter_Associations
(Old_Node
));
14065 New_E
:= First
(Parameter_Associations
(New_Node
));
14066 while Present
(Old_E
) loop
14067 if Nkind
(Old_E
) = N_Parameter_Association
14068 and then Present
(Next_Named_Actual
(Old_E
))
14070 if First_Named_Actual
(Old_Node
)
14071 = Explicit_Actual_Parameter
(Old_E
)
14073 Set_First_Named_Actual
14074 (New_Node
, Explicit_Actual_Parameter
(New_E
));
14077 -- Now scan parameter list from the beginning,to locate
14078 -- next named actual, which can be out of order.
14080 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
14081 New_Next
:= First
(Parameter_Associations
(New_Node
));
14083 while Nkind
(Old_Next
) /= N_Parameter_Association
14084 or else Explicit_Actual_Parameter
(Old_Next
)
14085 /= Next_Named_Actual
(Old_E
)
14091 Set_Next_Named_Actual
14092 (New_E
, Explicit_Actual_Parameter
(New_Next
));
14098 end Adjust_Named_Associations
;
14100 ---------------------------------
14101 -- Copy_Field_With_Replacement --
14102 ---------------------------------
14104 function Copy_Field_With_Replacement
14105 (Field
: Union_Id
) return Union_Id
14108 if Field
= Union_Id
(Empty
) then
14111 elsif Field
in Node_Range
then
14113 Old_N
: constant Node_Id
:= Node_Id
(Field
);
14117 -- If syntactic field, as indicated by the parent pointer
14118 -- being set, then copy the referenced node recursively.
14120 if Parent
(Old_N
) = Old_Node
then
14121 New_N
:= Copy_Node_With_Replacement
(Old_N
);
14123 if New_N
/= Old_N
then
14124 Set_Parent
(New_N
, New_Node
);
14127 -- For semantic fields, update possible entity reference
14128 -- from the replacement map.
14131 New_N
:= Assoc
(Old_N
);
14134 return Union_Id
(New_N
);
14137 elsif Field
in List_Range
then
14139 Old_L
: constant List_Id
:= List_Id
(Field
);
14143 -- If syntactic field, as indicated by the parent pointer,
14144 -- then recursively copy the entire referenced list.
14146 if Parent
(Old_L
) = Old_Node
then
14147 New_L
:= Copy_List_With_Replacement
(Old_L
);
14148 Set_Parent
(New_L
, New_Node
);
14150 -- For semantic list, just returned unchanged
14156 return Union_Id
(New_L
);
14159 -- Anything other than a list or a node is returned unchanged
14164 end Copy_Field_With_Replacement
;
14166 -- Start of processing for Copy_Node_With_Replacement
14169 if Old_Node
<= Empty_Or_Error
then
14172 elsif Has_Extension
(Old_Node
) then
14173 return Assoc
(Old_Node
);
14176 New_Node
:= New_Copy
(Old_Node
);
14178 -- If the node we are copying is the associated node of a
14179 -- previously copied Itype, then adjust the associated node
14180 -- of the copy of that Itype accordingly.
14182 if Present
(Actual_Map
) then
14188 -- Case of hash table used
14190 if NCT_Hash_Tables_Used
then
14191 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
14193 if Present
(Ent
) then
14194 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
14197 -- Case of no hash table used
14200 E
:= First_Elmt
(Actual_Map
);
14201 while Present
(E
) loop
14202 if Is_Itype
(Node
(E
))
14204 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
14206 Set_Associated_Node_For_Itype
14207 (Node
(Next_Elmt
(E
)), New_Node
);
14210 E
:= Next_Elmt
(Next_Elmt
(E
));
14216 -- Recursively copy descendents
14219 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
14221 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
14223 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
14225 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
14227 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
14229 -- Adjust Sloc of new node if necessary
14231 if New_Sloc
/= No_Location
then
14232 Set_Sloc
(New_Node
, New_Sloc
);
14234 -- If we adjust the Sloc, then we are essentially making
14235 -- a completely new node, so the Comes_From_Source flag
14236 -- should be reset to the proper default value.
14238 Nodes
.Table
(New_Node
).Comes_From_Source
:=
14239 Default_Node
.Comes_From_Source
;
14242 -- If the node is call and has named associations,
14243 -- set the corresponding links in the copy.
14245 if (Nkind
(Old_Node
) = N_Function_Call
14246 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
14248 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
14249 and then Present
(First_Named_Actual
(Old_Node
))
14251 Adjust_Named_Associations
(Old_Node
, New_Node
);
14254 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14255 -- The replacement mechanism applies to entities, and is not used
14256 -- here. Eventually we may need a more general graph-copying
14257 -- routine. For now, do a sequential search to find desired node.
14259 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
14260 and then Present
(First_Real_Statement
(Old_Node
))
14263 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
14267 N1
:= First
(Statements
(Old_Node
));
14268 N2
:= First
(Statements
(New_Node
));
14270 while N1
/= Old_F
loop
14275 Set_First_Real_Statement
(New_Node
, N2
);
14280 -- All done, return copied node
14283 end Copy_Node_With_Replacement
;
14289 procedure Visit_Elist
(E
: Elist_Id
) is
14292 if Present
(E
) then
14293 Elmt
:= First_Elmt
(E
);
14295 while Elmt
/= No_Elmt
loop
14296 Visit_Node
(Node
(Elmt
));
14306 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
14308 if F
= Union_Id
(Empty
) then
14311 elsif F
in Node_Range
then
14313 -- Copy node if it is syntactic, i.e. its parent pointer is
14314 -- set to point to the field that referenced it (certain
14315 -- Itypes will also meet this criterion, which is fine, since
14316 -- these are clearly Itypes that do need to be copied, since
14317 -- we are copying their parent.)
14319 if Parent
(Node_Id
(F
)) = N
then
14320 Visit_Node
(Node_Id
(F
));
14323 -- Another case, if we are pointing to an Itype, then we want
14324 -- to copy it if its associated node is somewhere in the tree
14327 -- Note: the exclusion of self-referential copies is just an
14328 -- optimization, since the search of the already copied list
14329 -- would catch it, but it is a common case (Etype pointing
14330 -- to itself for an Itype that is a base type).
14332 elsif Has_Extension
(Node_Id
(F
))
14333 and then Is_Itype
(Entity_Id
(F
))
14334 and then Node_Id
(F
) /= N
14340 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
14341 while Present
(P
) loop
14343 Visit_Node
(Node_Id
(F
));
14350 -- An Itype whose parent is not being copied definitely
14351 -- should NOT be copied, since it does not belong in any
14352 -- sense to the copied subtree.
14358 elsif F
in List_Range
and then Parent
(List_Id
(F
)) = N
then
14359 Visit_List
(List_Id
(F
));
14368 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
14369 New_Itype
: Entity_Id
;
14374 -- Itypes that describe the designated type of access to subprograms
14375 -- have the structure of subprogram declarations, with signatures,
14376 -- etc. Either we duplicate the signatures completely, or choose to
14377 -- share such itypes, which is fine because their elaboration will
14378 -- have no side effects.
14380 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
14384 New_Itype
:= New_Copy
(Old_Itype
);
14386 -- The new Itype has all the attributes of the old one, and
14387 -- we just copy the contents of the entity. However, the back-end
14388 -- needs different names for debugging purposes, so we create a
14389 -- new internal name for it in all cases.
14391 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
14393 -- If our associated node is an entity that has already been copied,
14394 -- then set the associated node of the copy to point to the right
14395 -- copy. If we have copied an Itype that is itself the associated
14396 -- node of some previously copied Itype, then we set the right
14397 -- pointer in the other direction.
14399 if Present
(Actual_Map
) then
14401 -- Case of hash tables used
14403 if NCT_Hash_Tables_Used
then
14405 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
14407 if Present
(Ent
) then
14408 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
14411 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
14412 if Present
(Ent
) then
14413 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
14415 -- If the hash table has no association for this Itype and
14416 -- its associated node, enter one now.
14419 NCT_Itype_Assoc
.Set
14420 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
14423 -- Case of hash tables not used
14426 E
:= First_Elmt
(Actual_Map
);
14427 while Present
(E
) loop
14428 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
14429 Set_Associated_Node_For_Itype
14430 (New_Itype
, Node
(Next_Elmt
(E
)));
14433 if Is_Type
(Node
(E
))
14434 and then Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
14436 Set_Associated_Node_For_Itype
14437 (Node
(Next_Elmt
(E
)), New_Itype
);
14440 E
:= Next_Elmt
(Next_Elmt
(E
));
14445 if Present
(Freeze_Node
(New_Itype
)) then
14446 Set_Is_Frozen
(New_Itype
, False);
14447 Set_Freeze_Node
(New_Itype
, Empty
);
14450 -- Add new association to map
14452 if No
(Actual_Map
) then
14453 Actual_Map
:= New_Elmt_List
;
14456 Append_Elmt
(Old_Itype
, Actual_Map
);
14457 Append_Elmt
(New_Itype
, Actual_Map
);
14459 if NCT_Hash_Tables_Used
then
14460 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
14463 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
14465 if NCT_Table_Entries
> NCT_Hash_Threshold
then
14466 Build_NCT_Hash_Tables
;
14470 -- If a record subtype is simply copied, the entity list will be
14471 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
14473 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
14474 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
14477 -- Visit descendents that eventually get copied
14479 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
14481 if Is_Discrete_Type
(Old_Itype
) then
14482 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
14484 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
14485 -- ??? This should involve call to Visit_Field
14486 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
14488 elsif Is_Array_Type
(Old_Itype
) then
14489 if Present
(First_Index
(Old_Itype
)) then
14490 Visit_Field
(Union_Id
(List_Containing
14491 (First_Index
(Old_Itype
))),
14495 if Is_Packed
(Old_Itype
) then
14496 Visit_Field
(Union_Id
(Packed_Array_Impl_Type
(Old_Itype
)),
14506 procedure Visit_List
(L
: List_Id
) is
14509 if L
/= No_List
then
14512 while Present
(N
) loop
14523 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
14525 -- Start of processing for Visit_Node
14528 -- Handle case of an Itype, which must be copied
14530 if Has_Extension
(N
) and then Is_Itype
(N
) then
14532 -- Nothing to do if already in the list. This can happen with an
14533 -- Itype entity that appears more than once in the tree.
14534 -- Note that we do not want to visit descendents in this case.
14536 -- Test for already in list when hash table is used
14538 if NCT_Hash_Tables_Used
then
14539 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
14543 -- Test for already in list when hash table not used
14549 if Present
(Actual_Map
) then
14550 E
:= First_Elmt
(Actual_Map
);
14551 while Present
(E
) loop
14552 if Node
(E
) = N
then
14555 E
:= Next_Elmt
(Next_Elmt
(E
));
14565 -- Visit descendents
14567 Visit_Field
(Field1
(N
), N
);
14568 Visit_Field
(Field2
(N
), N
);
14569 Visit_Field
(Field3
(N
), N
);
14570 Visit_Field
(Field4
(N
), N
);
14571 Visit_Field
(Field5
(N
), N
);
14574 -- Start of processing for New_Copy_Tree
14579 -- See if we should use hash table
14581 if No
(Actual_Map
) then
14582 NCT_Hash_Tables_Used
:= False;
14589 NCT_Table_Entries
:= 0;
14591 Elmt
:= First_Elmt
(Actual_Map
);
14592 while Present
(Elmt
) loop
14593 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
14598 if NCT_Table_Entries
> NCT_Hash_Threshold
then
14599 Build_NCT_Hash_Tables
;
14601 NCT_Hash_Tables_Used
:= False;
14606 -- Hash table set up if required, now start phase one by visiting
14607 -- top node (we will recursively visit the descendents).
14609 Visit_Node
(Source
);
14611 -- Now the second phase of the copy can start. First we process
14612 -- all the mapped entities, copying their descendents.
14614 if Present
(Actual_Map
) then
14617 New_Itype
: Entity_Id
;
14619 Elmt
:= First_Elmt
(Actual_Map
);
14620 while Present
(Elmt
) loop
14622 New_Itype
:= Node
(Elmt
);
14623 Copy_Itype_With_Replacement
(New_Itype
);
14629 -- Now we can copy the actual tree
14631 return Copy_Node_With_Replacement
(Source
);
14634 -------------------------
14635 -- New_External_Entity --
14636 -------------------------
14638 function New_External_Entity
14639 (Kind
: Entity_Kind
;
14640 Scope_Id
: Entity_Id
;
14641 Sloc_Value
: Source_Ptr
;
14642 Related_Id
: Entity_Id
;
14643 Suffix
: Character;
14644 Suffix_Index
: Nat
:= 0;
14645 Prefix
: Character := ' ') return Entity_Id
14647 N
: constant Entity_Id
:=
14648 Make_Defining_Identifier
(Sloc_Value
,
14650 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
14653 Set_Ekind
(N
, Kind
);
14654 Set_Is_Internal
(N
, True);
14655 Append_Entity
(N
, Scope_Id
);
14656 Set_Public_Status
(N
);
14658 if Kind
in Type_Kind
then
14659 Init_Size_Align
(N
);
14663 end New_External_Entity
;
14665 -------------------------
14666 -- New_Internal_Entity --
14667 -------------------------
14669 function New_Internal_Entity
14670 (Kind
: Entity_Kind
;
14671 Scope_Id
: Entity_Id
;
14672 Sloc_Value
: Source_Ptr
;
14673 Id_Char
: Character) return Entity_Id
14675 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
14678 Set_Ekind
(N
, Kind
);
14679 Set_Is_Internal
(N
, True);
14680 Append_Entity
(N
, Scope_Id
);
14682 if Kind
in Type_Kind
then
14683 Init_Size_Align
(N
);
14687 end New_Internal_Entity
;
14693 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
14697 -- If we are pointing at a positional parameter, it is a member of a
14698 -- node list (the list of parameters), and the next parameter is the
14699 -- next node on the list, unless we hit a parameter association, then
14700 -- we shift to using the chain whose head is the First_Named_Actual in
14701 -- the parent, and then is threaded using the Next_Named_Actual of the
14702 -- Parameter_Association. All this fiddling is because the original node
14703 -- list is in the textual call order, and what we need is the
14704 -- declaration order.
14706 if Is_List_Member
(Actual_Id
) then
14707 N
:= Next
(Actual_Id
);
14709 if Nkind
(N
) = N_Parameter_Association
then
14710 return First_Named_Actual
(Parent
(Actual_Id
));
14716 return Next_Named_Actual
(Parent
(Actual_Id
));
14720 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
14722 Actual_Id
:= Next_Actual
(Actual_Id
);
14725 -----------------------
14726 -- Normalize_Actuals --
14727 -----------------------
14729 -- Chain actuals according to formals of subprogram. If there are no named
14730 -- associations, the chain is simply the list of Parameter Associations,
14731 -- since the order is the same as the declaration order. If there are named
14732 -- associations, then the First_Named_Actual field in the N_Function_Call
14733 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14734 -- node for the parameter that comes first in declaration order. The
14735 -- remaining named parameters are then chained in declaration order using
14736 -- Next_Named_Actual.
14738 -- This routine also verifies that the number of actuals is compatible with
14739 -- the number and default values of formals, but performs no type checking
14740 -- (type checking is done by the caller).
14742 -- If the matching succeeds, Success is set to True and the caller proceeds
14743 -- with type-checking. If the match is unsuccessful, then Success is set to
14744 -- False, and the caller attempts a different interpretation, if there is
14747 -- If the flag Report is on, the call is not overloaded, and a failure to
14748 -- match can be reported here, rather than in the caller.
14750 procedure Normalize_Actuals
14754 Success
: out Boolean)
14756 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
14757 Actual
: Node_Id
:= Empty
;
14758 Formal
: Entity_Id
;
14759 Last
: Node_Id
:= Empty
;
14760 First_Named
: Node_Id
:= Empty
;
14763 Formals_To_Match
: Integer := 0;
14764 Actuals_To_Match
: Integer := 0;
14766 procedure Chain
(A
: Node_Id
);
14767 -- Add named actual at the proper place in the list, using the
14768 -- Next_Named_Actual link.
14770 function Reporting
return Boolean;
14771 -- Determines if an error is to be reported. To report an error, we
14772 -- need Report to be True, and also we do not report errors caused
14773 -- by calls to init procs that occur within other init procs. Such
14774 -- errors must always be cascaded errors, since if all the types are
14775 -- declared correctly, the compiler will certainly build decent calls.
14781 procedure Chain
(A
: Node_Id
) is
14785 -- Call node points to first actual in list
14787 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
14790 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
14794 Set_Next_Named_Actual
(Last
, Empty
);
14801 function Reporting
return Boolean is
14806 elsif not Within_Init_Proc
then
14809 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
14817 -- Start of processing for Normalize_Actuals
14820 if Is_Access_Type
(S
) then
14822 -- The name in the call is a function call that returns an access
14823 -- to subprogram. The designated type has the list of formals.
14825 Formal
:= First_Formal
(Designated_Type
(S
));
14827 Formal
:= First_Formal
(S
);
14830 while Present
(Formal
) loop
14831 Formals_To_Match
:= Formals_To_Match
+ 1;
14832 Next_Formal
(Formal
);
14835 -- Find if there is a named association, and verify that no positional
14836 -- associations appear after named ones.
14838 if Present
(Actuals
) then
14839 Actual
:= First
(Actuals
);
14842 while Present
(Actual
)
14843 and then Nkind
(Actual
) /= N_Parameter_Association
14845 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14849 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
14851 -- Most common case: positional notation, no defaults
14856 elsif Actuals_To_Match
> Formals_To_Match
then
14858 -- Too many actuals: will not work
14861 if Is_Entity_Name
(Name
(N
)) then
14862 Error_Msg_N
("too many arguments in call to&", Name
(N
));
14864 Error_Msg_N
("too many arguments in call", N
);
14872 First_Named
:= Actual
;
14874 while Present
(Actual
) loop
14875 if Nkind
(Actual
) /= N_Parameter_Association
then
14877 ("positional parameters not allowed after named ones", Actual
);
14882 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14888 if Present
(Actuals
) then
14889 Actual
:= First
(Actuals
);
14892 Formal
:= First_Formal
(S
);
14893 while Present
(Formal
) loop
14895 -- Match the formals in order. If the corresponding actual is
14896 -- positional, nothing to do. Else scan the list of named actuals
14897 -- to find the one with the right name.
14899 if Present
(Actual
)
14900 and then Nkind
(Actual
) /= N_Parameter_Association
14903 Actuals_To_Match
:= Actuals_To_Match
- 1;
14904 Formals_To_Match
:= Formals_To_Match
- 1;
14907 -- For named parameters, search the list of actuals to find
14908 -- one that matches the next formal name.
14910 Actual
:= First_Named
;
14912 while Present
(Actual
) loop
14913 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
14916 Actuals_To_Match
:= Actuals_To_Match
- 1;
14917 Formals_To_Match
:= Formals_To_Match
- 1;
14925 if Ekind
(Formal
) /= E_In_Parameter
14926 or else No
(Default_Value
(Formal
))
14929 if (Comes_From_Source
(S
)
14930 or else Sloc
(S
) = Standard_Location
)
14931 and then Is_Overloadable
(S
)
14935 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
14937 N_Parameter_Association
)
14938 and then Ekind
(S
) /= E_Function
14940 Set_Etype
(N
, Etype
(S
));
14943 Error_Msg_Name_1
:= Chars
(S
);
14944 Error_Msg_Sloc
:= Sloc
(S
);
14946 ("missing argument for parameter & "
14947 & "in call to % declared #", N
, Formal
);
14950 elsif Is_Overloadable
(S
) then
14951 Error_Msg_Name_1
:= Chars
(S
);
14953 -- Point to type derivation that generated the
14956 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
14959 ("missing argument for parameter & "
14960 & "in call to % (inherited) #", N
, Formal
);
14964 ("missing argument for parameter &", N
, Formal
);
14972 Formals_To_Match
:= Formals_To_Match
- 1;
14977 Next_Formal
(Formal
);
14980 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
14987 -- Find some superfluous named actual that did not get
14988 -- attached to the list of associations.
14990 Actual
:= First
(Actuals
);
14991 while Present
(Actual
) loop
14992 if Nkind
(Actual
) = N_Parameter_Association
14993 and then Actual
/= Last
14994 and then No
(Next_Named_Actual
(Actual
))
14996 Error_Msg_N
("unmatched actual & in call",
14997 Selector_Name
(Actual
));
15008 end Normalize_Actuals
;
15010 --------------------------------
15011 -- Note_Possible_Modification --
15012 --------------------------------
15014 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
15015 Modification_Comes_From_Source
: constant Boolean :=
15016 Comes_From_Source
(Parent
(N
));
15022 -- Loop to find referenced entity, if there is one
15028 if Is_Entity_Name
(Exp
) then
15029 Ent
:= Entity
(Exp
);
15031 -- If the entity is missing, it is an undeclared identifier,
15032 -- and there is nothing to annotate.
15038 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
15040 P
: constant Node_Id
:= Prefix
(Exp
);
15043 -- In formal verification mode, keep track of all reads and
15044 -- writes through explicit dereferences.
15046 if GNATprove_Mode
then
15047 SPARK_Specific
.Generate_Dereference
(N
, 'm');
15050 if Nkind
(P
) = N_Selected_Component
15051 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
15053 -- Case of a reference to an entry formal
15055 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
15057 elsif Nkind
(P
) = N_Identifier
15058 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
15059 and then Present
(Expression
(Parent
(Entity
(P
))))
15060 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
15063 -- Case of a reference to a value on which side effects have
15066 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
15074 elsif Nkind_In
(Exp
, N_Type_Conversion
,
15075 N_Unchecked_Type_Conversion
)
15077 Exp
:= Expression
(Exp
);
15080 elsif Nkind_In
(Exp
, N_Slice
,
15081 N_Indexed_Component
,
15082 N_Selected_Component
)
15084 -- Special check, if the prefix is an access type, then return
15085 -- since we are modifying the thing pointed to, not the prefix.
15086 -- When we are expanding, most usually the prefix is replaced
15087 -- by an explicit dereference, and this test is not needed, but
15088 -- in some cases (notably -gnatc mode and generics) when we do
15089 -- not do full expansion, we need this special test.
15091 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
15094 -- Otherwise go to prefix and keep going
15097 Exp
:= Prefix
(Exp
);
15101 -- All other cases, not a modification
15107 -- Now look for entity being referenced
15109 if Present
(Ent
) then
15110 if Is_Object
(Ent
) then
15111 if Comes_From_Source
(Exp
)
15112 or else Modification_Comes_From_Source
15114 -- Give warning if pragma unmodified given and we are
15115 -- sure this is a modification.
15117 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
15118 Error_Msg_NE
("??pragma Unmodified given for &!", N
, Ent
);
15121 Set_Never_Set_In_Source
(Ent
, False);
15124 Set_Is_True_Constant
(Ent
, False);
15125 Set_Current_Value
(Ent
, Empty
);
15126 Set_Is_Known_Null
(Ent
, False);
15128 if not Can_Never_Be_Null
(Ent
) then
15129 Set_Is_Known_Non_Null
(Ent
, False);
15132 -- Follow renaming chain
15134 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
15135 and then Present
(Renamed_Object
(Ent
))
15137 Exp
:= Renamed_Object
(Ent
);
15139 -- If the entity is the loop variable in an iteration over
15140 -- a container, retrieve container expression to indicate
15141 -- possible modificastion.
15143 if Present
(Related_Expression
(Ent
))
15144 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
15145 N_Iterator_Specification
15147 Exp
:= Original_Node
(Related_Expression
(Ent
));
15152 -- The expression may be the renaming of a subcomponent of an
15153 -- array or container. The assignment to the subcomponent is
15154 -- a modification of the container.
15156 elsif Comes_From_Source
(Original_Node
(Exp
))
15157 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
15158 N_Indexed_Component
)
15160 Exp
:= Prefix
(Original_Node
(Exp
));
15164 -- Generate a reference only if the assignment comes from
15165 -- source. This excludes, for example, calls to a dispatching
15166 -- assignment operation when the left-hand side is tagged. In
15167 -- GNATprove mode, we need those references also on generated
15168 -- code, as these are used to compute the local effects of
15171 if Modification_Comes_From_Source
or GNATprove_Mode
then
15172 Generate_Reference
(Ent
, Exp
, 'm');
15174 -- If the target of the assignment is the bound variable
15175 -- in an iterator, indicate that the corresponding array
15176 -- or container is also modified.
15178 if Ada_Version
>= Ada_2012
15179 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
15182 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
15185 -- TBD : in the full version of the construct, the
15186 -- domain of iteration can be given by an expression.
15188 if Is_Entity_Name
(Domain
) then
15189 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
15190 Set_Is_True_Constant
(Entity
(Domain
), False);
15191 Set_Never_Set_In_Source
(Entity
(Domain
), False);
15197 Check_Nested_Access
(N
, Ent
);
15202 -- If we are sure this is a modification from source, and we know
15203 -- this modifies a constant, then give an appropriate warning.
15205 if Overlays_Constant
(Ent
)
15206 and then (Modification_Comes_From_Source
and Sure
)
15209 A
: constant Node_Id
:= Address_Clause
(Ent
);
15211 if Present
(A
) then
15213 Exp
: constant Node_Id
:= Expression
(A
);
15215 if Nkind
(Exp
) = N_Attribute_Reference
15216 and then Attribute_Name
(Exp
) = Name_Address
15217 and then Is_Entity_Name
(Prefix
(Exp
))
15219 Error_Msg_Sloc
:= Sloc
(A
);
15221 ("constant& may be modified via address "
15222 & "clause#??", N
, Entity
(Prefix
(Exp
)));
15235 end Note_Possible_Modification
;
15237 -------------------------
15238 -- Object_Access_Level --
15239 -------------------------
15241 -- Returns the static accessibility level of the view denoted by Obj. Note
15242 -- that the value returned is the result of a call to Scope_Depth. Only
15243 -- scope depths associated with dynamic scopes can actually be returned.
15244 -- Since only relative levels matter for accessibility checking, the fact
15245 -- that the distance between successive levels of accessibility is not
15246 -- always one is immaterial (invariant: if level(E2) is deeper than
15247 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15249 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
15250 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
15251 -- Determine whether N is a construct of the form
15252 -- Some_Type (Operand._tag'Address)
15253 -- This construct appears in the context of dispatching calls.
15255 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
15256 -- An explicit dereference is created when removing side-effects from
15257 -- expressions for constraint checking purposes. In this case a local
15258 -- access type is created for it. The correct access level is that of
15259 -- the original source node. We detect this case by noting that the
15260 -- prefix of the dereference is created by an object declaration whose
15261 -- initial expression is a reference.
15263 -----------------------------
15264 -- Is_Interface_Conversion --
15265 -----------------------------
15267 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
15269 return Nkind
(N
) = N_Unchecked_Type_Conversion
15270 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
15271 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
15272 end Is_Interface_Conversion
;
15278 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
15279 Pref
: constant Node_Id
:= Prefix
(Obj
);
15281 if Is_Entity_Name
(Pref
)
15282 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
15283 and then Present
(Expression
(Parent
(Entity
(Pref
))))
15284 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
15286 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
15296 -- Start of processing for Object_Access_Level
15299 if Nkind
(Obj
) = N_Defining_Identifier
15300 or else Is_Entity_Name
(Obj
)
15302 if Nkind
(Obj
) = N_Defining_Identifier
then
15308 if Is_Prival
(E
) then
15309 E
:= Prival_Link
(E
);
15312 -- If E is a type then it denotes a current instance. For this case
15313 -- we add one to the normal accessibility level of the type to ensure
15314 -- that current instances are treated as always being deeper than
15315 -- than the level of any visible named access type (see 3.10.2(21)).
15317 if Is_Type
(E
) then
15318 return Type_Access_Level
(E
) + 1;
15320 elsif Present
(Renamed_Object
(E
)) then
15321 return Object_Access_Level
(Renamed_Object
(E
));
15323 -- Similarly, if E is a component of the current instance of a
15324 -- protected type, any instance of it is assumed to be at a deeper
15325 -- level than the type. For a protected object (whose type is an
15326 -- anonymous protected type) its components are at the same level
15327 -- as the type itself.
15329 elsif not Is_Overloadable
(E
)
15330 and then Ekind
(Scope
(E
)) = E_Protected_Type
15331 and then Comes_From_Source
(Scope
(E
))
15333 return Type_Access_Level
(Scope
(E
)) + 1;
15336 -- Aliased formals take their access level from the point of call.
15337 -- This is smaller than the level of the subprogram itself.
15339 if Is_Formal
(E
) and then Is_Aliased
(E
) then
15340 return Type_Access_Level
(Etype
(E
));
15343 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
15347 elsif Nkind
(Obj
) = N_Selected_Component
then
15348 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
15349 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15351 return Object_Access_Level
(Prefix
(Obj
));
15354 elsif Nkind
(Obj
) = N_Indexed_Component
then
15355 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
15356 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15358 return Object_Access_Level
(Prefix
(Obj
));
15361 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
15363 -- If the prefix is a selected access discriminant then we make a
15364 -- recursive call on the prefix, which will in turn check the level
15365 -- of the prefix object of the selected discriminant.
15367 -- In Ada 2012, if the discriminant has implicit dereference and
15368 -- the context is a selected component, treat this as an object of
15369 -- unknown scope (see below). This is necessary in compile-only mode;
15370 -- otherwise expansion will already have transformed the prefix into
15373 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
15374 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
15376 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
15378 (not Has_Implicit_Dereference
15379 (Entity
(Selector_Name
(Prefix
(Obj
))))
15380 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
15382 return Object_Access_Level
(Prefix
(Obj
));
15384 -- Detect an interface conversion in the context of a dispatching
15385 -- call. Use the original form of the conversion to find the access
15386 -- level of the operand.
15388 elsif Is_Interface
(Etype
(Obj
))
15389 and then Is_Interface_Conversion
(Prefix
(Obj
))
15390 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
15392 return Object_Access_Level
(Original_Node
(Obj
));
15394 elsif not Comes_From_Source
(Obj
) then
15396 Ref
: constant Node_Id
:= Reference_To
(Obj
);
15398 if Present
(Ref
) then
15399 return Object_Access_Level
(Ref
);
15401 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15406 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15409 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
15410 return Object_Access_Level
(Expression
(Obj
));
15412 elsif Nkind
(Obj
) = N_Function_Call
then
15414 -- Function results are objects, so we get either the access level of
15415 -- the function or, in the case of an indirect call, the level of the
15416 -- access-to-subprogram type. (This code is used for Ada 95, but it
15417 -- looks wrong, because it seems that we should be checking the level
15418 -- of the call itself, even for Ada 95. However, using the Ada 2005
15419 -- version of the code causes regressions in several tests that are
15420 -- compiled with -gnat95. ???)
15422 if Ada_Version
< Ada_2005
then
15423 if Is_Entity_Name
(Name
(Obj
)) then
15424 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
15426 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
15429 -- For Ada 2005, the level of the result object of a function call is
15430 -- defined to be the level of the call's innermost enclosing master.
15431 -- We determine that by querying the depth of the innermost enclosing
15435 Return_Master_Scope_Depth_Of_Call
: declare
15437 function Innermost_Master_Scope_Depth
15438 (N
: Node_Id
) return Uint
;
15439 -- Returns the scope depth of the given node's innermost
15440 -- enclosing dynamic scope (effectively the accessibility
15441 -- level of the innermost enclosing master).
15443 ----------------------------------
15444 -- Innermost_Master_Scope_Depth --
15445 ----------------------------------
15447 function Innermost_Master_Scope_Depth
15448 (N
: Node_Id
) return Uint
15450 Node_Par
: Node_Id
:= Parent
(N
);
15453 -- Locate the nearest enclosing node (by traversing Parents)
15454 -- that Defining_Entity can be applied to, and return the
15455 -- depth of that entity's nearest enclosing dynamic scope.
15457 while Present
(Node_Par
) loop
15458 case Nkind
(Node_Par
) is
15459 when N_Component_Declaration |
15460 N_Entry_Declaration |
15461 N_Formal_Object_Declaration |
15462 N_Formal_Type_Declaration |
15463 N_Full_Type_Declaration |
15464 N_Incomplete_Type_Declaration |
15465 N_Loop_Parameter_Specification |
15466 N_Object_Declaration |
15467 N_Protected_Type_Declaration |
15468 N_Private_Extension_Declaration |
15469 N_Private_Type_Declaration |
15470 N_Subtype_Declaration |
15471 N_Function_Specification |
15472 N_Procedure_Specification |
15473 N_Task_Type_Declaration |
15475 N_Generic_Instantiation |
15477 N_Implicit_Label_Declaration |
15478 N_Package_Declaration |
15479 N_Single_Task_Declaration |
15480 N_Subprogram_Declaration |
15481 N_Generic_Declaration |
15482 N_Renaming_Declaration |
15483 N_Block_Statement |
15484 N_Formal_Subprogram_Declaration |
15485 N_Abstract_Subprogram_Declaration |
15487 N_Exception_Declaration |
15488 N_Formal_Package_Declaration |
15489 N_Number_Declaration |
15490 N_Package_Specification |
15491 N_Parameter_Specification |
15492 N_Single_Protected_Declaration |
15496 (Nearest_Dynamic_Scope
15497 (Defining_Entity
(Node_Par
)));
15503 Node_Par
:= Parent
(Node_Par
);
15506 pragma Assert
(False);
15508 -- Should never reach the following return
15510 return Scope_Depth
(Current_Scope
) + 1;
15511 end Innermost_Master_Scope_Depth
;
15513 -- Start of processing for Return_Master_Scope_Depth_Of_Call
15516 return Innermost_Master_Scope_Depth
(Obj
);
15517 end Return_Master_Scope_Depth_Of_Call
;
15520 -- For convenience we handle qualified expressions, even though they
15521 -- aren't technically object names.
15523 elsif Nkind
(Obj
) = N_Qualified_Expression
then
15524 return Object_Access_Level
(Expression
(Obj
));
15526 -- Ditto for aggregates. They have the level of the temporary that
15527 -- will hold their value.
15529 elsif Nkind
(Obj
) = N_Aggregate
then
15530 return Object_Access_Level
(Current_Scope
);
15532 -- Otherwise return the scope level of Standard. (If there are cases
15533 -- that fall through to this point they will be treated as having
15534 -- global accessibility for now. ???)
15537 return Scope_Depth
(Standard_Standard
);
15539 end Object_Access_Level
;
15541 ---------------------------------
15542 -- Original_Aspect_Pragma_Name --
15543 ---------------------------------
15545 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
15547 Item_Nam
: Name_Id
;
15550 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
15554 -- The pragma was generated to emulate an aspect, use the original
15555 -- aspect specification.
15557 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
15558 Item
:= Corresponding_Aspect
(Item
);
15561 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
15562 -- Post and Post_Class rewrite their pragma identifier to preserve the
15564 -- ??? this is kludgey
15566 if Nkind
(Item
) = N_Pragma
then
15567 Item_Nam
:= Chars
(Original_Node
(Pragma_Identifier
(Item
)));
15570 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
15571 Item_Nam
:= Chars
(Identifier
(Item
));
15574 -- Deal with 'Class by converting the name to its _XXX form
15576 if Class_Present
(Item
) then
15577 if Item_Nam
= Name_Invariant
then
15578 Item_Nam
:= Name_uInvariant
;
15580 elsif Item_Nam
= Name_Post
then
15581 Item_Nam
:= Name_uPost
;
15583 elsif Item_Nam
= Name_Pre
then
15584 Item_Nam
:= Name_uPre
;
15586 elsif Nam_In
(Item_Nam
, Name_Type_Invariant
,
15587 Name_Type_Invariant_Class
)
15589 Item_Nam
:= Name_uType_Invariant
;
15591 -- Nothing to do for other cases (e.g. a Check that derived from
15592 -- Pre_Class and has the flag set). Also we do nothing if the name
15593 -- is already in special _xxx form.
15599 end Original_Aspect_Pragma_Name
;
15601 --------------------------------------
15602 -- Original_Corresponding_Operation --
15603 --------------------------------------
15605 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
15607 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
15610 -- If S is an inherited primitive S2 the original corresponding
15611 -- operation of S is the original corresponding operation of S2
15613 if Present
(Alias
(S
))
15614 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
15616 return Original_Corresponding_Operation
(Alias
(S
));
15618 -- If S overrides an inherited subprogram S2 the original corresponding
15619 -- operation of S is the original corresponding operation of S2
15621 elsif Present
(Overridden_Operation
(S
)) then
15622 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
15624 -- otherwise it is S itself
15629 end Original_Corresponding_Operation
;
15631 ----------------------
15632 -- Policy_In_Effect --
15633 ----------------------
15635 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
15636 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
15637 -- Determine the the mode of a policy in a N_Pragma list
15639 --------------------
15640 -- Policy_In_List --
15641 --------------------
15643 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
15650 while Present
(Prag
) loop
15651 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
15652 Expr
:= Get_Pragma_Arg
(Arg
);
15654 -- The current Check_Policy pragma matches the requested policy,
15655 -- return the second argument which denotes the policy identifier.
15657 if Chars
(Expr
) = Policy
then
15658 return Chars
(Get_Pragma_Arg
(Next
(Arg
)));
15661 Prag
:= Next_Pragma
(Prag
);
15665 end Policy_In_List
;
15671 -- Start of processing for Policy_In_Effect
15674 if not Is_Valid_Assertion_Kind
(Policy
) then
15675 raise Program_Error
;
15678 -- Inspect all policy pragmas that appear within scopes (if any)
15680 Kind
:= Policy_In_List
(Check_Policy_List
);
15682 -- Inspect all configuration policy pragmas (if any)
15684 if Kind
= No_Name
then
15685 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
15688 -- The context lacks policy pragmas, determine the mode based on whether
15689 -- assertions are enabled at the configuration level. This ensures that
15690 -- the policy is preserved when analyzing generics.
15692 if Kind
= No_Name
then
15693 if Assertions_Enabled_Config
then
15694 Kind
:= Name_Check
;
15696 Kind
:= Name_Ignore
;
15701 end Policy_In_Effect
;
15703 ----------------------------------
15704 -- Predicate_Tests_On_Arguments --
15705 ----------------------------------
15707 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
15709 -- Always test predicates on indirect call
15711 if Ekind
(Subp
) = E_Subprogram_Type
then
15714 -- Do not test predicates on call to generated default Finalize, since
15715 -- we are not interested in whether something we are finalizing (and
15716 -- typically destroying) satisfies its predicates.
15718 elsif Chars
(Subp
) = Name_Finalize
15719 and then not Comes_From_Source
(Subp
)
15723 -- Do not test predicates on any internally generated routines
15725 elsif Is_Internal_Name
(Chars
(Subp
)) then
15728 -- Do not test predicates on call to Init_Proc, since if needed the
15729 -- predicate test will occur at some other point.
15731 elsif Is_Init_Proc
(Subp
) then
15734 -- Do not test predicates on call to predicate function, since this
15735 -- would cause infinite recursion.
15737 elsif Ekind
(Subp
) = E_Function
15738 and then (Is_Predicate_Function
(Subp
)
15740 Is_Predicate_Function_M
(Subp
))
15744 -- For now, no other exceptions
15749 end Predicate_Tests_On_Arguments
;
15751 -----------------------
15752 -- Private_Component --
15753 -----------------------
15755 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
15756 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
15758 function Trace_Components
15760 Check
: Boolean) return Entity_Id
;
15761 -- Recursive function that does the work, and checks against circular
15762 -- definition for each subcomponent type.
15764 ----------------------
15765 -- Trace_Components --
15766 ----------------------
15768 function Trace_Components
15770 Check
: Boolean) return Entity_Id
15772 Btype
: constant Entity_Id
:= Base_Type
(T
);
15773 Component
: Entity_Id
;
15775 Candidate
: Entity_Id
:= Empty
;
15778 if Check
and then Btype
= Ancestor
then
15779 Error_Msg_N
("circular type definition", Type_Id
);
15783 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
15784 if Present
(Full_View
(Btype
))
15785 and then Is_Record_Type
(Full_View
(Btype
))
15786 and then not Is_Frozen
(Btype
)
15788 -- To indicate that the ancestor depends on a private type, the
15789 -- current Btype is sufficient. However, to check for circular
15790 -- definition we must recurse on the full view.
15792 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
15794 if Candidate
= Any_Type
then
15804 elsif Is_Array_Type
(Btype
) then
15805 return Trace_Components
(Component_Type
(Btype
), True);
15807 elsif Is_Record_Type
(Btype
) then
15808 Component
:= First_Entity
(Btype
);
15809 while Present
(Component
)
15810 and then Comes_From_Source
(Component
)
15812 -- Skip anonymous types generated by constrained components
15814 if not Is_Type
(Component
) then
15815 P
:= Trace_Components
(Etype
(Component
), True);
15817 if Present
(P
) then
15818 if P
= Any_Type
then
15826 Next_Entity
(Component
);
15834 end Trace_Components
;
15836 -- Start of processing for Private_Component
15839 return Trace_Components
(Type_Id
, False);
15840 end Private_Component
;
15842 ---------------------------
15843 -- Primitive_Names_Match --
15844 ---------------------------
15846 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
15848 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
15849 -- Given an internal name, returns the corresponding non-internal name
15851 ------------------------
15852 -- Non_Internal_Name --
15853 ------------------------
15855 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
15857 Get_Name_String
(Chars
(E
));
15858 Name_Len
:= Name_Len
- 1;
15860 end Non_Internal_Name
;
15862 -- Start of processing for Primitive_Names_Match
15865 pragma Assert
(Present
(E1
) and then Present
(E2
));
15867 return Chars
(E1
) = Chars
(E2
)
15869 (not Is_Internal_Name
(Chars
(E1
))
15870 and then Is_Internal_Name
(Chars
(E2
))
15871 and then Non_Internal_Name
(E2
) = Chars
(E1
))
15873 (not Is_Internal_Name
(Chars
(E2
))
15874 and then Is_Internal_Name
(Chars
(E1
))
15875 and then Non_Internal_Name
(E1
) = Chars
(E2
))
15877 (Is_Predefined_Dispatching_Operation
(E1
)
15878 and then Is_Predefined_Dispatching_Operation
(E2
)
15879 and then Same_TSS
(E1
, E2
))
15881 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
15882 end Primitive_Names_Match
;
15884 -----------------------
15885 -- Process_End_Label --
15886 -----------------------
15888 procedure Process_End_Label
15897 Label_Ref
: Boolean;
15898 -- Set True if reference to end label itself is required
15901 -- Gets set to the operator symbol or identifier that references the
15902 -- entity Ent. For the child unit case, this is the identifier from the
15903 -- designator. For other cases, this is simply Endl.
15905 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
15906 -- N is an identifier node that appears as a parent unit reference in
15907 -- the case where Ent is a child unit. This procedure generates an
15908 -- appropriate cross-reference entry. E is the corresponding entity.
15910 -------------------------
15911 -- Generate_Parent_Ref --
15912 -------------------------
15914 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
15916 -- If names do not match, something weird, skip reference
15918 if Chars
(E
) = Chars
(N
) then
15920 -- Generate the reference. We do NOT consider this as a reference
15921 -- for unreferenced symbol purposes.
15923 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
15925 if Style_Check
then
15926 Style
.Check_Identifier
(N
, E
);
15929 end Generate_Parent_Ref
;
15931 -- Start of processing for Process_End_Label
15934 -- If no node, ignore. This happens in some error situations, and
15935 -- also for some internally generated structures where no end label
15936 -- references are required in any case.
15942 -- Nothing to do if no End_Label, happens for internally generated
15943 -- constructs where we don't want an end label reference anyway. Also
15944 -- nothing to do if Endl is a string literal, which means there was
15945 -- some prior error (bad operator symbol)
15947 Endl
:= End_Label
(N
);
15949 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
15953 -- Reference node is not in extended main source unit
15955 if not In_Extended_Main_Source_Unit
(N
) then
15957 -- Generally we do not collect references except for the extended
15958 -- main source unit. The one exception is the 'e' entry for a
15959 -- package spec, where it is useful for a client to have the
15960 -- ending information to define scopes.
15966 Label_Ref
:= False;
15968 -- For this case, we can ignore any parent references, but we
15969 -- need the package name itself for the 'e' entry.
15971 if Nkind
(Endl
) = N_Designator
then
15972 Endl
:= Identifier
(Endl
);
15976 -- Reference is in extended main source unit
15981 -- For designator, generate references for the parent entries
15983 if Nkind
(Endl
) = N_Designator
then
15985 -- Generate references for the prefix if the END line comes from
15986 -- source (otherwise we do not need these references) We climb the
15987 -- scope stack to find the expected entities.
15989 if Comes_From_Source
(Endl
) then
15990 Nam
:= Name
(Endl
);
15991 Scop
:= Current_Scope
;
15992 while Nkind
(Nam
) = N_Selected_Component
loop
15993 Scop
:= Scope
(Scop
);
15994 exit when No
(Scop
);
15995 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
15996 Nam
:= Prefix
(Nam
);
15999 if Present
(Scop
) then
16000 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
16004 Endl
:= Identifier
(Endl
);
16008 -- If the end label is not for the given entity, then either we have
16009 -- some previous error, or this is a generic instantiation for which
16010 -- we do not need to make a cross-reference in this case anyway. In
16011 -- either case we simply ignore the call.
16013 if Chars
(Ent
) /= Chars
(Endl
) then
16017 -- If label was really there, then generate a normal reference and then
16018 -- adjust the location in the end label to point past the name (which
16019 -- should almost always be the semicolon).
16021 Loc
:= Sloc
(Endl
);
16023 if Comes_From_Source
(Endl
) then
16025 -- If a label reference is required, then do the style check and
16026 -- generate an l-type cross-reference entry for the label
16029 if Style_Check
then
16030 Style
.Check_Identifier
(Endl
, Ent
);
16033 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
16036 -- Set the location to point past the label (normally this will
16037 -- mean the semicolon immediately following the label). This is
16038 -- done for the sake of the 'e' or 't' entry generated below.
16040 Get_Decoded_Name_String
(Chars
(Endl
));
16041 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
16044 -- In SPARK mode, no missing label is allowed for packages and
16045 -- subprogram bodies. Detect those cases by testing whether
16046 -- Process_End_Label was called for a body (Typ = 't') or a package.
16048 if Restriction_Check_Required
(SPARK_05
)
16049 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
16051 Error_Msg_Node_1
:= Endl
;
16052 Check_SPARK_05_Restriction
16053 ("`END &` required", Endl
, Force
=> True);
16057 -- Now generate the e/t reference
16059 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
16061 -- Restore Sloc, in case modified above, since we have an identifier
16062 -- and the normal Sloc should be left set in the tree.
16064 Set_Sloc
(Endl
, Loc
);
16065 end Process_End_Label
;
16071 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
16072 Seen
: Boolean := False;
16074 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
16075 -- Determine whether node N denotes a reference to Id. If this is the
16076 -- case, set global flag Seen to True and stop the traversal.
16082 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
16084 if Is_Entity_Name
(N
)
16085 and then Present
(Entity
(N
))
16086 and then Entity
(N
) = Id
16095 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
16097 -- Start of processing for Referenced
16100 Inspect_Expression
(Expr
);
16104 ------------------------------------
16105 -- References_Generic_Formal_Type --
16106 ------------------------------------
16108 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
16110 function Process
(N
: Node_Id
) return Traverse_Result
;
16111 -- Process one node in search for generic formal type
16117 function Process
(N
: Node_Id
) return Traverse_Result
is
16119 if Nkind
(N
) in N_Has_Entity
then
16121 E
: constant Entity_Id
:= Entity
(N
);
16123 if Present
(E
) then
16124 if Is_Generic_Type
(E
) then
16126 elsif Present
(Etype
(E
))
16127 and then Is_Generic_Type
(Etype
(E
))
16138 function Traverse
is new Traverse_Func
(Process
);
16139 -- Traverse tree to look for generic type
16142 if Inside_A_Generic
then
16143 return Traverse
(N
) = Abandon
;
16147 end References_Generic_Formal_Type
;
16149 --------------------
16150 -- Remove_Homonym --
16151 --------------------
16153 procedure Remove_Homonym
(E
: Entity_Id
) is
16154 Prev
: Entity_Id
:= Empty
;
16158 if E
= Current_Entity
(E
) then
16159 if Present
(Homonym
(E
)) then
16160 Set_Current_Entity
(Homonym
(E
));
16162 Set_Name_Entity_Id
(Chars
(E
), Empty
);
16166 H
:= Current_Entity
(E
);
16167 while Present
(H
) and then H
/= E
loop
16172 -- If E is not on the homonym chain, nothing to do
16174 if Present
(H
) then
16175 Set_Homonym
(Prev
, Homonym
(E
));
16178 end Remove_Homonym
;
16180 ---------------------
16181 -- Rep_To_Pos_Flag --
16182 ---------------------
16184 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
16186 return New_Occurrence_Of
16187 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
16188 end Rep_To_Pos_Flag
;
16190 --------------------
16191 -- Require_Entity --
16192 --------------------
16194 procedure Require_Entity
(N
: Node_Id
) is
16196 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
16197 if Total_Errors_Detected
/= 0 then
16198 Set_Entity
(N
, Any_Id
);
16200 raise Program_Error
;
16203 end Require_Entity
;
16205 -------------------------------
16206 -- Requires_State_Refinement --
16207 -------------------------------
16209 function Requires_State_Refinement
16210 (Spec_Id
: Entity_Id
;
16211 Body_Id
: Entity_Id
) return Boolean
16213 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
16214 -- Given pragma SPARK_Mode, determine whether the mode is Off
16220 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
16224 -- The default SPARK mode is On
16230 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
16232 -- Then the pragma lacks an argument, the default mode is On
16237 return Chars
(Mode
) = Name_Off
;
16241 -- Start of processing for Requires_State_Refinement
16244 -- A package that does not define at least one abstract state cannot
16245 -- possibly require refinement.
16247 if No
(Abstract_States
(Spec_Id
)) then
16250 -- The package instroduces a single null state which does not merit
16253 elsif Has_Null_Abstract_State
(Spec_Id
) then
16256 -- Check whether the package body is subject to pragma SPARK_Mode. If
16257 -- it is and the mode is Off, the package body is considered to be in
16258 -- regular Ada and does not require refinement.
16260 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
16263 -- The body's SPARK_Mode may be inherited from a similar pragma that
16264 -- appears in the private declarations of the spec. The pragma we are
16265 -- interested appears as the second entry in SPARK_Pragma.
16267 elsif Present
(SPARK_Pragma
(Spec_Id
))
16268 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
16272 -- The spec defines at least one abstract state and the body has no way
16273 -- of circumventing the refinement.
16278 end Requires_State_Refinement
;
16280 ------------------------------
16281 -- Requires_Transient_Scope --
16282 ------------------------------
16284 -- A transient scope is required when variable-sized temporaries are
16285 -- allocated in the primary or secondary stack, or when finalization
16286 -- actions must be generated before the next instruction.
16288 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
16289 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
16291 -- Start of processing for Requires_Transient_Scope
16294 -- This is a private type which is not completed yet. This can only
16295 -- happen in a default expression (of a formal parameter or of a
16296 -- record component). Do not expand transient scope in this case
16301 -- Do not expand transient scope for non-existent procedure return
16303 elsif Typ
= Standard_Void_Type
then
16306 -- Elementary types do not require a transient scope
16308 elsif Is_Elementary_Type
(Typ
) then
16311 -- Generally, indefinite subtypes require a transient scope, since the
16312 -- back end cannot generate temporaries, since this is not a valid type
16313 -- for declaring an object. It might be possible to relax this in the
16314 -- future, e.g. by declaring the maximum possible space for the type.
16316 elsif Is_Indefinite_Subtype
(Typ
) then
16319 -- Functions returning tagged types may dispatch on result so their
16320 -- returned value is allocated on the secondary stack. Controlled
16321 -- type temporaries need finalization.
16323 elsif Is_Tagged_Type
(Typ
)
16324 or else Has_Controlled_Component
(Typ
)
16326 return not Is_Value_Type
(Typ
);
16330 elsif Is_Record_Type
(Typ
) then
16334 Comp
:= First_Entity
(Typ
);
16335 while Present
(Comp
) loop
16336 if Ekind
(Comp
) = E_Component
16337 and then Requires_Transient_Scope
(Etype
(Comp
))
16341 Next_Entity
(Comp
);
16348 -- String literal types never require transient scope
16350 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
16353 -- Array type. Note that we already know that this is a constrained
16354 -- array, since unconstrained arrays will fail the indefinite test.
16356 elsif Is_Array_Type
(Typ
) then
16358 -- If component type requires a transient scope, the array does too
16360 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
16363 -- Otherwise, we only need a transient scope if the size depends on
16364 -- the value of one or more discriminants.
16367 return Size_Depends_On_Discriminant
(Typ
);
16370 -- All other cases do not require a transient scope
16375 end Requires_Transient_Scope
;
16377 --------------------------
16378 -- Reset_Analyzed_Flags --
16379 --------------------------
16381 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
16383 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
16384 -- Function used to reset Analyzed flags in tree. Note that we do
16385 -- not reset Analyzed flags in entities, since there is no need to
16386 -- reanalyze entities, and indeed, it is wrong to do so, since it
16387 -- can result in generating auxiliary stuff more than once.
16389 --------------------
16390 -- Clear_Analyzed --
16391 --------------------
16393 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
16395 if not Has_Extension
(N
) then
16396 Set_Analyzed
(N
, False);
16400 end Clear_Analyzed
;
16402 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
16404 -- Start of processing for Reset_Analyzed_Flags
16407 Reset_Analyzed
(N
);
16408 end Reset_Analyzed_Flags
;
16410 ------------------------
16411 -- Restore_SPARK_Mode --
16412 ------------------------
16414 procedure Restore_SPARK_Mode
(Mode
: SPARK_Mode_Type
) is
16416 SPARK_Mode
:= Mode
;
16417 end Restore_SPARK_Mode
;
16419 --------------------------------
16420 -- Returns_Unconstrained_Type --
16421 --------------------------------
16423 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
16425 return Ekind
(Subp
) = E_Function
16426 and then not Is_Scalar_Type
(Etype
(Subp
))
16427 and then not Is_Access_Type
(Etype
(Subp
))
16428 and then not Is_Constrained
(Etype
(Subp
));
16429 end Returns_Unconstrained_Type
;
16431 ----------------------------
16432 -- Root_Type_Of_Full_View --
16433 ----------------------------
16435 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
16436 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
16439 -- The root type of the full view may itself be a private type. Keep
16440 -- looking for the ultimate derivation parent.
16442 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
16443 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
16447 end Root_Type_Of_Full_View
;
16449 ---------------------------
16450 -- Safe_To_Capture_Value --
16451 ---------------------------
16453 function Safe_To_Capture_Value
16456 Cond
: Boolean := False) return Boolean
16459 -- The only entities for which we track constant values are variables
16460 -- which are not renamings, constants, out parameters, and in out
16461 -- parameters, so check if we have this case.
16463 -- Note: it may seem odd to track constant values for constants, but in
16464 -- fact this routine is used for other purposes than simply capturing
16465 -- the value. In particular, the setting of Known[_Non]_Null.
16467 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
16469 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
16473 -- For conditionals, we also allow loop parameters and all formals,
16474 -- including in parameters.
16476 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
16479 -- For all other cases, not just unsafe, but impossible to capture
16480 -- Current_Value, since the above are the only entities which have
16481 -- Current_Value fields.
16487 -- Skip if volatile or aliased, since funny things might be going on in
16488 -- these cases which we cannot necessarily track. Also skip any variable
16489 -- for which an address clause is given, or whose address is taken. Also
16490 -- never capture value of library level variables (an attempt to do so
16491 -- can occur in the case of package elaboration code).
16493 if Treat_As_Volatile
(Ent
)
16494 or else Is_Aliased
(Ent
)
16495 or else Present
(Address_Clause
(Ent
))
16496 or else Address_Taken
(Ent
)
16497 or else (Is_Library_Level_Entity
(Ent
)
16498 and then Ekind
(Ent
) = E_Variable
)
16503 -- OK, all above conditions are met. We also require that the scope of
16504 -- the reference be the same as the scope of the entity, not counting
16505 -- packages and blocks and loops.
16508 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
16509 R_Scope
: Entity_Id
;
16512 R_Scope
:= Current_Scope
;
16513 while R_Scope
/= Standard_Standard
loop
16514 exit when R_Scope
= E_Scope
;
16516 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
16519 R_Scope
:= Scope
(R_Scope
);
16524 -- We also require that the reference does not appear in a context
16525 -- where it is not sure to be executed (i.e. a conditional context
16526 -- or an exception handler). We skip this if Cond is True, since the
16527 -- capturing of values from conditional tests handles this ok.
16540 -- Seems dubious that case expressions are not handled here ???
16543 while Present
(P
) loop
16544 if Nkind
(P
) = N_If_Statement
16545 or else Nkind
(P
) = N_Case_Statement
16546 or else (Nkind
(P
) in N_Short_Circuit
16547 and then Desc
= Right_Opnd
(P
))
16548 or else (Nkind
(P
) = N_If_Expression
16549 and then Desc
/= First
(Expressions
(P
)))
16550 or else Nkind
(P
) = N_Exception_Handler
16551 or else Nkind
(P
) = N_Selective_Accept
16552 or else Nkind
(P
) = N_Conditional_Entry_Call
16553 or else Nkind
(P
) = N_Timed_Entry_Call
16554 or else Nkind
(P
) = N_Asynchronous_Select
16562 -- A special Ada 2012 case: the original node may be part
16563 -- of the else_actions of a conditional expression, in which
16564 -- case it might not have been expanded yet, and appears in
16565 -- a non-syntactic list of actions. In that case it is clearly
16566 -- not safe to save a value.
16569 and then Is_List_Member
(Desc
)
16570 and then No
(Parent
(List_Containing
(Desc
)))
16578 -- OK, looks safe to set value
16581 end Safe_To_Capture_Value
;
16587 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
16588 K1
: constant Node_Kind
:= Nkind
(N1
);
16589 K2
: constant Node_Kind
:= Nkind
(N2
);
16592 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
16593 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
16595 return Chars
(N1
) = Chars
(N2
);
16597 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
16598 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
16600 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
16601 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
16612 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
16613 N1
: constant Node_Id
:= Original_Node
(Node1
);
16614 N2
: constant Node_Id
:= Original_Node
(Node2
);
16615 -- We do the tests on original nodes, since we are most interested
16616 -- in the original source, not any expansion that got in the way.
16618 K1
: constant Node_Kind
:= Nkind
(N1
);
16619 K2
: constant Node_Kind
:= Nkind
(N2
);
16622 -- First case, both are entities with same entity
16624 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
16626 EN1
: constant Entity_Id
:= Entity
(N1
);
16627 EN2
: constant Entity_Id
:= Entity
(N2
);
16629 if Present
(EN1
) and then Present
(EN2
)
16630 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
16631 or else Is_Formal
(EN1
))
16639 -- Second case, selected component with same selector, same record
16641 if K1
= N_Selected_Component
16642 and then K2
= N_Selected_Component
16643 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
16645 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
16647 -- Third case, indexed component with same subscripts, same array
16649 elsif K1
= N_Indexed_Component
16650 and then K2
= N_Indexed_Component
16651 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
16656 E1
:= First
(Expressions
(N1
));
16657 E2
:= First
(Expressions
(N2
));
16658 while Present
(E1
) loop
16659 if not Same_Value
(E1
, E2
) then
16670 -- Fourth case, slice of same array with same bounds
16673 and then K2
= N_Slice
16674 and then Nkind
(Discrete_Range
(N1
)) = N_Range
16675 and then Nkind
(Discrete_Range
(N2
)) = N_Range
16676 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
16677 Low_Bound
(Discrete_Range
(N2
)))
16678 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
16679 High_Bound
(Discrete_Range
(N2
)))
16681 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
16683 -- All other cases, not clearly the same object
16694 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
16699 elsif not Is_Constrained
(T1
)
16700 and then not Is_Constrained
(T2
)
16701 and then Base_Type
(T1
) = Base_Type
(T2
)
16705 -- For now don't bother with case of identical constraints, to be
16706 -- fiddled with later on perhaps (this is only used for optimization
16707 -- purposes, so it is not critical to do a best possible job)
16718 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
16720 if Compile_Time_Known_Value
(Node1
)
16721 and then Compile_Time_Known_Value
(Node2
)
16722 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
16725 elsif Same_Object
(Node1
, Node2
) then
16732 -----------------------------
16733 -- Save_SPARK_Mode_And_Set --
16734 -----------------------------
16736 procedure Save_SPARK_Mode_And_Set
16737 (Context
: Entity_Id
;
16738 Mode
: out SPARK_Mode_Type
)
16741 -- Save the current mode in effect
16743 Mode
:= SPARK_Mode
;
16745 -- Do not consider illegal or partially decorated constructs
16747 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
16750 elsif Present
(SPARK_Pragma
(Context
)) then
16751 SPARK_Mode
:= Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Context
));
16753 end Save_SPARK_Mode_And_Set
;
16755 -------------------------
16756 -- Scalar_Part_Present --
16757 -------------------------
16759 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
16763 if Is_Scalar_Type
(T
) then
16766 elsif Is_Array_Type
(T
) then
16767 return Scalar_Part_Present
(Component_Type
(T
));
16769 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
16770 C
:= First_Component_Or_Discriminant
(T
);
16771 while Present
(C
) loop
16772 if Scalar_Part_Present
(Etype
(C
)) then
16775 Next_Component_Or_Discriminant
(C
);
16781 end Scalar_Part_Present
;
16783 ------------------------
16784 -- Scope_Is_Transient --
16785 ------------------------
16787 function Scope_Is_Transient
return Boolean is
16789 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
16790 end Scope_Is_Transient
;
16796 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16801 while Scop
/= Standard_Standard
loop
16802 Scop
:= Scope
(Scop
);
16804 if Scop
= Scope2
then
16812 --------------------------
16813 -- Scope_Within_Or_Same --
16814 --------------------------
16816 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16821 while Scop
/= Standard_Standard
loop
16822 if Scop
= Scope2
then
16825 Scop
:= Scope
(Scop
);
16830 end Scope_Within_Or_Same
;
16832 --------------------
16833 -- Set_Convention --
16834 --------------------
16836 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
16838 Basic_Set_Convention
(E
, Val
);
16841 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
16842 and then Has_Foreign_Convention
(E
)
16844 Set_Can_Use_Internal_Rep
(E
, False);
16847 -- If E is an object or component, and the type of E is an anonymous
16848 -- access type with no convention set, then also set the convention of
16849 -- the anonymous access type. We do not do this for anonymous protected
16850 -- types, since protected types always have the default convention.
16852 if Present
(Etype
(E
))
16853 and then (Is_Object
(E
)
16854 or else Ekind
(E
) = E_Component
16856 -- Allow E_Void (happens for pragma Convention appearing
16857 -- in the middle of a record applying to a component)
16859 or else Ekind
(E
) = E_Void
)
16862 Typ
: constant Entity_Id
:= Etype
(E
);
16865 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
16866 E_Anonymous_Access_Subprogram_Type
)
16867 and then not Has_Convention_Pragma
(Typ
)
16869 Basic_Set_Convention
(Typ
, Val
);
16870 Set_Has_Convention_Pragma
(Typ
);
16872 -- And for the access subprogram type, deal similarly with the
16873 -- designated E_Subprogram_Type if it is also internal (which
16876 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
16878 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
16880 if Ekind
(Dtype
) = E_Subprogram_Type
16881 and then Is_Itype
(Dtype
)
16882 and then not Has_Convention_Pragma
(Dtype
)
16884 Basic_Set_Convention
(Dtype
, Val
);
16885 Set_Has_Convention_Pragma
(Dtype
);
16892 end Set_Convention
;
16894 ------------------------
16895 -- Set_Current_Entity --
16896 ------------------------
16898 -- The given entity is to be set as the currently visible definition of its
16899 -- associated name (i.e. the Node_Id associated with its name). All we have
16900 -- to do is to get the name from the identifier, and then set the
16901 -- associated Node_Id to point to the given entity.
16903 procedure Set_Current_Entity
(E
: Entity_Id
) is
16905 Set_Name_Entity_Id
(Chars
(E
), E
);
16906 end Set_Current_Entity
;
16908 ---------------------------
16909 -- Set_Debug_Info_Needed --
16910 ---------------------------
16912 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
16914 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
16915 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
16916 -- Used to set debug info in a related node if not set already
16918 --------------------------------------
16919 -- Set_Debug_Info_Needed_If_Not_Set --
16920 --------------------------------------
16922 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
16924 if Present
(E
) and then not Needs_Debug_Info
(E
) then
16925 Set_Debug_Info_Needed
(E
);
16927 -- For a private type, indicate that the full view also needs
16928 -- debug information.
16931 and then Is_Private_Type
(E
)
16932 and then Present
(Full_View
(E
))
16934 Set_Debug_Info_Needed
(Full_View
(E
));
16937 end Set_Debug_Info_Needed_If_Not_Set
;
16939 -- Start of processing for Set_Debug_Info_Needed
16942 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16943 -- indicates that Debug_Info_Needed is never required for the entity.
16944 -- Nothing to do if entity comes from a predefined file. Library files
16945 -- are compiled without debug information, but inlined bodies of these
16946 -- routines may appear in user code, and debug information on them ends
16947 -- up complicating debugging the user code.
16950 or else Debug_Info_Off
(T
)
16954 elsif In_Inlined_Body
16955 and then Is_Predefined_File_Name
16956 (Unit_File_Name
(Get_Source_Unit
(Sloc
(T
))))
16958 Set_Needs_Debug_Info
(T
, False);
16961 -- Set flag in entity itself. Note that we will go through the following
16962 -- circuitry even if the flag is already set on T. That's intentional,
16963 -- it makes sure that the flag will be set in subsidiary entities.
16965 Set_Needs_Debug_Info
(T
);
16967 -- Set flag on subsidiary entities if not set already
16969 if Is_Object
(T
) then
16970 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16972 elsif Is_Type
(T
) then
16973 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16975 if Is_Record_Type
(T
) then
16977 Ent
: Entity_Id
:= First_Entity
(T
);
16979 while Present
(Ent
) loop
16980 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
16985 -- For a class wide subtype, we also need debug information
16986 -- for the equivalent type.
16988 if Ekind
(T
) = E_Class_Wide_Subtype
then
16989 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
16992 elsif Is_Array_Type
(T
) then
16993 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
16996 Indx
: Node_Id
:= First_Index
(T
);
16998 while Present
(Indx
) loop
16999 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
17000 Indx
:= Next_Index
(Indx
);
17004 -- For a packed array type, we also need debug information for
17005 -- the type used to represent the packed array. Conversely, we
17006 -- also need it for the former if we need it for the latter.
17008 if Is_Packed
(T
) then
17009 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
17012 if Is_Packed_Array_Impl_Type
(T
) then
17013 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
17016 elsif Is_Access_Type
(T
) then
17017 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
17019 elsif Is_Private_Type
(T
) then
17020 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
17022 elsif Is_Protected_Type
(T
) then
17023 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
17025 elsif Is_Scalar_Type
(T
) then
17027 -- If the subrange bounds are materialized by dedicated constant
17028 -- objects, also include them in the debug info to make sure the
17029 -- debugger can properly use them.
17031 if Present
(Scalar_Range
(T
))
17032 and then Nkind
(Scalar_Range
(T
)) = N_Range
17035 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
17036 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
17039 if Is_Entity_Name
(Low_Bnd
) then
17040 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
17043 if Is_Entity_Name
(High_Bnd
) then
17044 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
17050 end Set_Debug_Info_Needed
;
17052 ----------------------------
17053 -- Set_Entity_With_Checks --
17054 ----------------------------
17056 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
17057 Val_Actual
: Entity_Id
;
17059 Post_Node
: Node_Id
;
17062 -- Unconditionally set the entity
17064 Set_Entity
(N
, Val
);
17066 -- The node to post on is the selector in the case of an expanded name,
17067 -- and otherwise the node itself.
17069 if Nkind
(N
) = N_Expanded_Name
then
17070 Post_Node
:= Selector_Name
(N
);
17075 -- Check for violation of No_Fixed_IO
17077 if Restriction_Check_Required
(No_Fixed_IO
)
17079 ((RTU_Loaded
(Ada_Text_IO
)
17080 and then (Is_RTE
(Val
, RE_Decimal_IO
)
17082 Is_RTE
(Val
, RE_Fixed_IO
)))
17085 (RTU_Loaded
(Ada_Wide_Text_IO
)
17086 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
17088 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
17091 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
17092 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
17094 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
17096 -- A special extra check, don't complain about a reference from within
17097 -- the Ada.Interrupts package itself!
17099 and then not In_Same_Extended_Unit
(N
, Val
)
17101 Check_Restriction
(No_Fixed_IO
, Post_Node
);
17104 -- Remaining checks are only done on source nodes. Note that we test
17105 -- for violation of No_Fixed_IO even on non-source nodes, because the
17106 -- cases for checking violations of this restriction are instantiations
17107 -- where the reference in the instance has Comes_From_Source False.
17109 if not Comes_From_Source
(N
) then
17113 -- Check for violation of No_Abort_Statements, which is triggered by
17114 -- call to Ada.Task_Identification.Abort_Task.
17116 if Restriction_Check_Required
(No_Abort_Statements
)
17117 and then (Is_RTE
(Val
, RE_Abort_Task
))
17119 -- A special extra check, don't complain about a reference from within
17120 -- the Ada.Task_Identification package itself!
17122 and then not In_Same_Extended_Unit
(N
, Val
)
17124 Check_Restriction
(No_Abort_Statements
, Post_Node
);
17127 if Val
= Standard_Long_Long_Integer
then
17128 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
17131 -- Check for violation of No_Dynamic_Attachment
17133 if Restriction_Check_Required
(No_Dynamic_Attachment
)
17134 and then RTU_Loaded
(Ada_Interrupts
)
17135 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
17136 Is_RTE
(Val
, RE_Is_Attached
) or else
17137 Is_RTE
(Val
, RE_Current_Handler
) or else
17138 Is_RTE
(Val
, RE_Attach_Handler
) or else
17139 Is_RTE
(Val
, RE_Exchange_Handler
) or else
17140 Is_RTE
(Val
, RE_Detach_Handler
) or else
17141 Is_RTE
(Val
, RE_Reference
))
17143 -- A special extra check, don't complain about a reference from within
17144 -- the Ada.Interrupts package itself!
17146 and then not In_Same_Extended_Unit
(N
, Val
)
17148 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
17151 -- Check for No_Implementation_Identifiers
17153 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
17155 -- We have an implementation defined entity if it is marked as
17156 -- implementation defined, or is defined in a package marked as
17157 -- implementation defined. However, library packages themselves
17158 -- are excluded (we don't want to flag Interfaces itself, just
17159 -- the entities within it).
17161 if (Is_Implementation_Defined
(Val
)
17163 (Present
(Scope
(Val
))
17164 and then Is_Implementation_Defined
(Scope
(Val
))))
17165 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
17166 and then Is_Library_Level_Entity
(Val
))
17168 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
17172 -- Do the style check
17175 and then not Suppress_Style_Checks
(Val
)
17176 and then not In_Instance
17178 if Nkind
(N
) = N_Identifier
then
17180 elsif Nkind
(N
) = N_Expanded_Name
then
17181 Nod
:= Selector_Name
(N
);
17186 -- A special situation arises for derived operations, where we want
17187 -- to do the check against the parent (since the Sloc of the derived
17188 -- operation points to the derived type declaration itself).
17191 while not Comes_From_Source
(Val_Actual
)
17192 and then Nkind
(Val_Actual
) in N_Entity
17193 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
17194 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
17195 and then Present
(Alias
(Val_Actual
))
17197 Val_Actual
:= Alias
(Val_Actual
);
17200 -- Renaming declarations for generic actuals do not come from source,
17201 -- and have a different name from that of the entity they rename, so
17202 -- there is no style check to perform here.
17204 if Chars
(Nod
) = Chars
(Val_Actual
) then
17205 Style
.Check_Identifier
(Nod
, Val_Actual
);
17209 Set_Entity
(N
, Val
);
17210 end Set_Entity_With_Checks
;
17212 ------------------------
17213 -- Set_Name_Entity_Id --
17214 ------------------------
17216 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
17218 Set_Name_Table_Int
(Id
, Int
(Val
));
17219 end Set_Name_Entity_Id
;
17221 ---------------------
17222 -- Set_Next_Actual --
17223 ---------------------
17225 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
17227 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
17228 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
17230 end Set_Next_Actual
;
17232 ----------------------------------
17233 -- Set_Optimize_Alignment_Flags --
17234 ----------------------------------
17236 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
17238 if Optimize_Alignment
= 'S' then
17239 Set_Optimize_Alignment_Space
(E
);
17240 elsif Optimize_Alignment
= 'T' then
17241 Set_Optimize_Alignment_Time
(E
);
17243 end Set_Optimize_Alignment_Flags
;
17245 -----------------------
17246 -- Set_Public_Status --
17247 -----------------------
17249 procedure Set_Public_Status
(Id
: Entity_Id
) is
17250 S
: constant Entity_Id
:= Current_Scope
;
17252 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
17253 -- Determines if E is defined within handled statement sequence or
17254 -- an if statement, returns True if so, False otherwise.
17256 ----------------------
17257 -- Within_HSS_Or_If --
17258 ----------------------
17260 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
17263 N
:= Declaration_Node
(E
);
17270 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
17276 end Within_HSS_Or_If
;
17278 -- Start of processing for Set_Public_Status
17281 -- Everything in the scope of Standard is public
17283 if S
= Standard_Standard
then
17284 Set_Is_Public
(Id
);
17286 -- Entity is definitely not public if enclosing scope is not public
17288 elsif not Is_Public
(S
) then
17291 -- An object or function declaration that occurs in a handled sequence
17292 -- of statements or within an if statement is the declaration for a
17293 -- temporary object or local subprogram generated by the expander. It
17294 -- never needs to be made public and furthermore, making it public can
17295 -- cause back end problems.
17297 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
17298 N_Function_Specification
)
17299 and then Within_HSS_Or_If
(Id
)
17303 -- Entities in public packages or records are public
17305 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
17306 Set_Is_Public
(Id
);
17308 -- The bounds of an entry family declaration can generate object
17309 -- declarations that are visible to the back-end, e.g. in the
17310 -- the declaration of a composite type that contains tasks.
17312 elsif Is_Concurrent_Type
(S
)
17313 and then not Has_Completion
(S
)
17314 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
17316 Set_Is_Public
(Id
);
17318 end Set_Public_Status
;
17320 -----------------------------
17321 -- Set_Referenced_Modified --
17322 -----------------------------
17324 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
17328 -- Deal with indexed or selected component where prefix is modified
17330 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
17331 Pref
:= Prefix
(N
);
17333 -- If prefix is access type, then it is the designated object that is
17334 -- being modified, which means we have no entity to set the flag on.
17336 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
17339 -- Otherwise chase the prefix
17342 Set_Referenced_Modified
(Pref
, Out_Param
);
17345 -- Otherwise see if we have an entity name (only other case to process)
17347 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
17348 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
17349 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
17351 end Set_Referenced_Modified
;
17353 ----------------------------
17354 -- Set_Scope_Is_Transient --
17355 ----------------------------
17357 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
17359 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
17360 end Set_Scope_Is_Transient
;
17362 -------------------
17363 -- Set_Size_Info --
17364 -------------------
17366 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
17368 -- We copy Esize, but not RM_Size, since in general RM_Size is
17369 -- subtype specific and does not get inherited by all subtypes.
17371 Set_Esize
(T1
, Esize
(T2
));
17372 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
17374 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
17376 Is_Discrete_Or_Fixed_Point_Type
(T2
)
17378 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
17381 Set_Alignment
(T1
, Alignment
(T2
));
17384 --------------------
17385 -- Static_Boolean --
17386 --------------------
17388 function Static_Boolean
(N
: Node_Id
) return Uint
is
17390 Analyze_And_Resolve
(N
, Standard_Boolean
);
17393 or else Error_Posted
(N
)
17394 or else Etype
(N
) = Any_Type
17399 if Is_OK_Static_Expression
(N
) then
17400 if not Raises_Constraint_Error
(N
) then
17401 return Expr_Value
(N
);
17406 elsif Etype
(N
) = Any_Type
then
17410 Flag_Non_Static_Expr
17411 ("static boolean expression required here", N
);
17414 end Static_Boolean
;
17416 --------------------
17417 -- Static_Integer --
17418 --------------------
17420 function Static_Integer
(N
: Node_Id
) return Uint
is
17422 Analyze_And_Resolve
(N
, Any_Integer
);
17425 or else Error_Posted
(N
)
17426 or else Etype
(N
) = Any_Type
17431 if Is_OK_Static_Expression
(N
) then
17432 if not Raises_Constraint_Error
(N
) then
17433 return Expr_Value
(N
);
17438 elsif Etype
(N
) = Any_Type
then
17442 Flag_Non_Static_Expr
17443 ("static integer expression required here", N
);
17446 end Static_Integer
;
17448 --------------------------
17449 -- Statically_Different --
17450 --------------------------
17452 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
17453 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
17454 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
17456 return Is_Entity_Name
(R1
)
17457 and then Is_Entity_Name
(R2
)
17458 and then Entity
(R1
) /= Entity
(R2
)
17459 and then not Is_Formal
(Entity
(R1
))
17460 and then not Is_Formal
(Entity
(R2
));
17461 end Statically_Different
;
17463 --------------------------------------
17464 -- Subject_To_Loop_Entry_Attributes --
17465 --------------------------------------
17467 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
17473 -- The expansion mechanism transform a loop subject to at least one
17474 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
17475 -- the conditional part.
17477 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
17478 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
17480 Stmt
:= Original_Node
(N
);
17484 Nkind
(Stmt
) = N_Loop_Statement
17485 and then Present
(Identifier
(Stmt
))
17486 and then Present
(Entity
(Identifier
(Stmt
)))
17487 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
17488 end Subject_To_Loop_Entry_Attributes
;
17490 -----------------------------
17491 -- Subprogram_Access_Level --
17492 -----------------------------
17494 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
17496 if Present
(Alias
(Subp
)) then
17497 return Subprogram_Access_Level
(Alias
(Subp
));
17499 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
17501 end Subprogram_Access_Level
;
17503 -------------------------------
17504 -- Support_Atomic_Primitives --
17505 -------------------------------
17507 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
17511 -- Verify the alignment of Typ is known
17513 if not Known_Alignment
(Typ
) then
17517 if Known_Static_Esize
(Typ
) then
17518 Size
:= UI_To_Int
(Esize
(Typ
));
17520 -- If the Esize (Object_Size) is unknown at compile time, look at the
17521 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
17523 elsif Known_Static_RM_Size
(Typ
) then
17524 Size
:= UI_To_Int
(RM_Size
(Typ
));
17526 -- Otherwise, the size is considered to be unknown.
17532 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
17533 -- Typ is properly aligned.
17536 when 8 |
16 |
32 |
64 =>
17537 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
17541 end Support_Atomic_Primitives
;
17547 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
17549 if Debug_Flag_W
then
17550 for J
in 0 .. Scope_Stack
.Last
loop
17555 Write_Name
(Chars
(E
));
17556 Write_Str
(" from ");
17557 Write_Location
(Sloc
(N
));
17562 -----------------------
17563 -- Transfer_Entities --
17564 -----------------------
17566 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
17567 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
17568 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
17569 -- Set_Public_Status. If successfull and Id denotes a record type, set
17570 -- the Is_Public attribute of its fields.
17572 --------------------------
17573 -- Set_Public_Status_Of --
17574 --------------------------
17576 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
17580 if not Is_Public
(Id
) then
17581 Set_Public_Status
(Id
);
17583 -- When the input entity is a public record type, ensure that all
17584 -- its internal fields are also exposed to the linker. The fields
17585 -- of a class-wide type are never made public.
17588 and then Is_Record_Type
(Id
)
17589 and then not Is_Class_Wide_Type
(Id
)
17591 Field
:= First_Entity
(Id
);
17592 while Present
(Field
) loop
17593 Set_Is_Public
(Field
);
17594 Next_Entity
(Field
);
17598 end Set_Public_Status_Of
;
17602 Full_Id
: Entity_Id
;
17605 -- Start of processing for Transfer_Entities
17608 Id
:= First_Entity
(From
);
17610 if Present
(Id
) then
17612 -- Merge the entity chain of the source scope with that of the
17613 -- destination scope.
17615 if Present
(Last_Entity
(To
)) then
17616 Set_Next_Entity
(Last_Entity
(To
), Id
);
17618 Set_First_Entity
(To
, Id
);
17621 Set_Last_Entity
(To
, Last_Entity
(From
));
17623 -- Inspect the entities of the source scope and update their Scope
17626 while Present
(Id
) loop
17627 Set_Scope
(Id
, To
);
17628 Set_Public_Status_Of
(Id
);
17630 -- Handle an internally generated full view for a private type
17632 if Is_Private_Type
(Id
)
17633 and then Present
(Full_View
(Id
))
17634 and then Is_Itype
(Full_View
(Id
))
17636 Full_Id
:= Full_View
(Id
);
17638 Set_Scope
(Full_Id
, To
);
17639 Set_Public_Status_Of
(Full_Id
);
17645 Set_First_Entity
(From
, Empty
);
17646 Set_Last_Entity
(From
, Empty
);
17648 end Transfer_Entities
;
17650 -----------------------
17651 -- Type_Access_Level --
17652 -----------------------
17654 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
17658 Btyp
:= Base_Type
(Typ
);
17660 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
17661 -- simply use the level where the type is declared. This is true for
17662 -- stand-alone object declarations, and for anonymous access types
17663 -- associated with components the level is the same as that of the
17664 -- enclosing composite type. However, special treatment is needed for
17665 -- the cases of access parameters, return objects of an anonymous access
17666 -- type, and, in Ada 95, access discriminants of limited types.
17668 if Is_Access_Type
(Btyp
) then
17669 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
17671 -- If the type is a nonlocal anonymous access type (such as for
17672 -- an access parameter) we treat it as being declared at the
17673 -- library level to ensure that names such as X.all'access don't
17674 -- fail static accessibility checks.
17676 if not Is_Local_Anonymous_Access
(Typ
) then
17677 return Scope_Depth
(Standard_Standard
);
17679 -- If this is a return object, the accessibility level is that of
17680 -- the result subtype of the enclosing function. The test here is
17681 -- little complicated, because we have to account for extended
17682 -- return statements that have been rewritten as blocks, in which
17683 -- case we have to find and the Is_Return_Object attribute of the
17684 -- itype's associated object. It would be nice to find a way to
17685 -- simplify this test, but it doesn't seem worthwhile to add a new
17686 -- flag just for purposes of this test. ???
17688 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
17691 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
17692 N_Object_Declaration
17693 and then Is_Return_Object
17694 (Defining_Identifier
17695 (Associated_Node_For_Itype
(Btyp
))))
17701 Scop
:= Scope
(Scope
(Btyp
));
17702 while Present
(Scop
) loop
17703 exit when Ekind
(Scop
) = E_Function
;
17704 Scop
:= Scope
(Scop
);
17707 -- Treat the return object's type as having the level of the
17708 -- function's result subtype (as per RM05-6.5(5.3/2)).
17710 return Type_Access_Level
(Etype
(Scop
));
17715 Btyp
:= Root_Type
(Btyp
);
17717 -- The accessibility level of anonymous access types associated with
17718 -- discriminants is that of the current instance of the type, and
17719 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
17721 -- AI-402: access discriminants have accessibility based on the
17722 -- object rather than the type in Ada 2005, so the above paragraph
17725 -- ??? Needs completion with rules from AI-416
17727 if Ada_Version
<= Ada_95
17728 and then Ekind
(Typ
) = E_Anonymous_Access_Type
17729 and then Present
(Associated_Node_For_Itype
(Typ
))
17730 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
17731 N_Discriminant_Specification
17733 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
17737 -- Return library level for a generic formal type. This is done because
17738 -- RM(10.3.2) says that "The statically deeper relationship does not
17739 -- apply to ... a descendant of a generic formal type". Rather than
17740 -- checking at each point where a static accessibility check is
17741 -- performed to see if we are dealing with a formal type, this rule is
17742 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17743 -- return extreme values for a formal type; Deepest_Type_Access_Level
17744 -- returns Int'Last. By calling the appropriate function from among the
17745 -- two, we ensure that the static accessibility check will pass if we
17746 -- happen to run into a formal type. More specifically, we should call
17747 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17748 -- call occurs as part of a static accessibility check and the error
17749 -- case is the case where the type's level is too shallow (as opposed
17752 if Is_Generic_Type
(Root_Type
(Btyp
)) then
17753 return Scope_Depth
(Standard_Standard
);
17756 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
17757 end Type_Access_Level
;
17759 ------------------------------------
17760 -- Type_Without_Stream_Operation --
17761 ------------------------------------
17763 function Type_Without_Stream_Operation
17765 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
17767 BT
: constant Entity_Id
:= Base_Type
(T
);
17768 Op_Missing
: Boolean;
17771 if not Restriction_Active
(No_Default_Stream_Attributes
) then
17775 if Is_Elementary_Type
(T
) then
17776 if Op
= TSS_Null
then
17778 No
(TSS
(BT
, TSS_Stream_Read
))
17779 or else No
(TSS
(BT
, TSS_Stream_Write
));
17782 Op_Missing
:= No
(TSS
(BT
, Op
));
17791 elsif Is_Array_Type
(T
) then
17792 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
17794 elsif Is_Record_Type
(T
) then
17800 Comp
:= First_Component
(T
);
17801 while Present
(Comp
) loop
17802 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
17804 if Present
(C_Typ
) then
17808 Next_Component
(Comp
);
17814 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
17815 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
17819 end Type_Without_Stream_Operation
;
17821 ----------------------------
17822 -- Unique_Defining_Entity --
17823 ----------------------------
17825 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
17827 return Unique_Entity
(Defining_Entity
(N
));
17828 end Unique_Defining_Entity
;
17830 -------------------
17831 -- Unique_Entity --
17832 -------------------
17834 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
17835 U
: Entity_Id
:= E
;
17841 if Present
(Full_View
(E
)) then
17842 U
:= Full_View
(E
);
17846 if Present
(Full_View
(E
)) then
17847 U
:= Full_View
(E
);
17850 when E_Package_Body
=>
17853 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17857 U
:= Corresponding_Spec
(P
);
17859 when E_Subprogram_Body
=>
17862 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17868 if Nkind
(P
) = N_Subprogram_Body_Stub
then
17869 if Present
(Library_Unit
(P
)) then
17871 -- Get to the function or procedure (generic) entity through
17872 -- the body entity.
17875 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
17878 U
:= Corresponding_Spec
(P
);
17881 when Formal_Kind
=>
17882 if Present
(Spec_Entity
(E
)) then
17883 U
:= Spec_Entity
(E
);
17897 function Unique_Name
(E
: Entity_Id
) return String is
17899 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17900 -- reliable, as they may not include the overloading suffix. Instead,
17901 -- when looking for the name of E or one of its enclosing scope, we get
17902 -- the name of the corresponding Unique_Entity.
17904 function Get_Scoped_Name
(E
: Entity_Id
) return String;
17905 -- Return the name of E prefixed by all the names of the scopes to which
17906 -- E belongs, except for Standard.
17908 ---------------------
17909 -- Get_Scoped_Name --
17910 ---------------------
17912 function Get_Scoped_Name
(E
: Entity_Id
) return String is
17913 Name
: constant String := Get_Name_String
(Chars
(E
));
17915 if Has_Fully_Qualified_Name
(E
)
17916 or else Scope
(E
) = Standard_Standard
17920 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
17922 end Get_Scoped_Name
;
17924 -- Start of processing for Unique_Name
17927 if E
= Standard_Standard
then
17928 return Get_Name_String
(Name_Standard
);
17930 elsif Scope
(E
) = Standard_Standard
17931 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
17933 return Get_Name_String
(Name_Standard
) & "__" &
17934 Get_Name_String
(Chars
(E
));
17936 elsif Ekind
(E
) = E_Enumeration_Literal
then
17937 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
17940 return Get_Scoped_Name
(Unique_Entity
(E
));
17944 ---------------------
17945 -- Unit_Is_Visible --
17946 ---------------------
17948 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
17949 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
17950 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
17952 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
17953 -- For a child unit, check whether unit appears in a with_clause
17956 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
17957 -- Scan the context clause of one compilation unit looking for a
17958 -- with_clause for the unit in question.
17960 ----------------------------
17961 -- Unit_In_Parent_Context --
17962 ----------------------------
17964 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
17966 if Unit_In_Context
(Par_Unit
) then
17969 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
17970 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
17975 end Unit_In_Parent_Context
;
17977 ---------------------
17978 -- Unit_In_Context --
17979 ---------------------
17981 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
17985 Clause
:= First
(Context_Items
(Comp_Unit
));
17986 while Present
(Clause
) loop
17987 if Nkind
(Clause
) = N_With_Clause
then
17988 if Library_Unit
(Clause
) = U
then
17991 -- The with_clause may denote a renaming of the unit we are
17992 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17995 Renamed_Entity
(Entity
(Name
(Clause
))) =
17996 Defining_Entity
(Unit
(U
))
18006 end Unit_In_Context
;
18008 -- Start of processing for Unit_Is_Visible
18011 -- The currrent unit is directly visible
18016 elsif Unit_In_Context
(Curr
) then
18019 -- If the current unit is a body, check the context of the spec
18021 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
18023 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
18024 and then not Acts_As_Spec
(Unit
(Curr
)))
18026 if Unit_In_Context
(Library_Unit
(Curr
)) then
18031 -- If the spec is a child unit, examine the parents
18033 if Is_Child_Unit
(Curr_Entity
) then
18034 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
18036 Unit_In_Parent_Context
18037 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
18039 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
18045 end Unit_Is_Visible
;
18047 ------------------------------
18048 -- Universal_Interpretation --
18049 ------------------------------
18051 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
18052 Index
: Interp_Index
;
18056 -- The argument may be a formal parameter of an operator or subprogram
18057 -- with multiple interpretations, or else an expression for an actual.
18059 if Nkind
(Opnd
) = N_Defining_Identifier
18060 or else not Is_Overloaded
(Opnd
)
18062 if Etype
(Opnd
) = Universal_Integer
18063 or else Etype
(Opnd
) = Universal_Real
18065 return Etype
(Opnd
);
18071 Get_First_Interp
(Opnd
, Index
, It
);
18072 while Present
(It
.Typ
) loop
18073 if It
.Typ
= Universal_Integer
18074 or else It
.Typ
= Universal_Real
18079 Get_Next_Interp
(Index
, It
);
18084 end Universal_Interpretation
;
18090 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
18092 -- Recurse to handle unlikely case of multiple levels of qualification
18094 if Nkind
(Expr
) = N_Qualified_Expression
then
18095 return Unqualify
(Expression
(Expr
));
18097 -- Normal case, not a qualified expression
18104 -----------------------
18105 -- Visible_Ancestors --
18106 -----------------------
18108 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
18114 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
18116 -- Collect all the parents and progenitors of Typ. If the full-view of
18117 -- private parents and progenitors is available then it is used to
18118 -- generate the list of visible ancestors; otherwise their partial
18119 -- view is added to the resulting list.
18124 Use_Full_View
=> True);
18128 Ifaces_List
=> List_2
,
18129 Exclude_Parents
=> True,
18130 Use_Full_View
=> True);
18132 -- Join the two lists. Avoid duplications because an interface may
18133 -- simultaneously be parent and progenitor of a type.
18135 Elmt
:= First_Elmt
(List_2
);
18136 while Present
(Elmt
) loop
18137 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
18142 end Visible_Ancestors
;
18144 ----------------------
18145 -- Within_Init_Proc --
18146 ----------------------
18148 function Within_Init_Proc
return Boolean is
18152 S
:= Current_Scope
;
18153 while not Is_Overloadable
(S
) loop
18154 if S
= Standard_Standard
then
18161 return Is_Init_Proc
(S
);
18162 end Within_Init_Proc
;
18168 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
18175 elsif SE
= Standard_Standard
then
18187 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
18188 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
18189 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
18191 Matching_Field
: Entity_Id
;
18192 -- Entity to give a more precise suggestion on how to write a one-
18193 -- element positional aggregate.
18195 function Has_One_Matching_Field
return Boolean;
18196 -- Determines if Expec_Type is a record type with a single component or
18197 -- discriminant whose type matches the found type or is one dimensional
18198 -- array whose component type matches the found type. In the case of
18199 -- one discriminant, we ignore the variant parts. That's not accurate,
18200 -- but good enough for the warning.
18202 ----------------------------
18203 -- Has_One_Matching_Field --
18204 ----------------------------
18206 function Has_One_Matching_Field
return Boolean is
18210 Matching_Field
:= Empty
;
18212 if Is_Array_Type
(Expec_Type
)
18213 and then Number_Dimensions
(Expec_Type
) = 1
18214 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
18216 -- Use type name if available. This excludes multidimensional
18217 -- arrays and anonymous arrays.
18219 if Comes_From_Source
(Expec_Type
) then
18220 Matching_Field
:= Expec_Type
;
18222 -- For an assignment, use name of target
18224 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
18225 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
18227 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
18232 elsif not Is_Record_Type
(Expec_Type
) then
18236 E
:= First_Entity
(Expec_Type
);
18241 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
18242 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
18251 if not Covers
(Etype
(E
), Found_Type
) then
18254 elsif Present
(Next_Entity
(E
))
18255 and then (Ekind
(E
) = E_Component
18256 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
18261 Matching_Field
:= E
;
18265 end Has_One_Matching_Field
;
18267 -- Start of processing for Wrong_Type
18270 -- Don't output message if either type is Any_Type, or if a message
18271 -- has already been posted for this node. We need to do the latter
18272 -- check explicitly (it is ordinarily done in Errout), because we
18273 -- are using ! to force the output of the error messages.
18275 if Expec_Type
= Any_Type
18276 or else Found_Type
= Any_Type
18277 or else Error_Posted
(Expr
)
18281 -- If one of the types is a Taft-Amendment type and the other it its
18282 -- completion, it must be an illegal use of a TAT in the spec, for
18283 -- which an error was already emitted. Avoid cascaded errors.
18285 elsif Is_Incomplete_Type
(Expec_Type
)
18286 and then Has_Completion_In_Body
(Expec_Type
)
18287 and then Full_View
(Expec_Type
) = Etype
(Expr
)
18291 elsif Is_Incomplete_Type
(Etype
(Expr
))
18292 and then Has_Completion_In_Body
(Etype
(Expr
))
18293 and then Full_View
(Etype
(Expr
)) = Expec_Type
18297 -- In an instance, there is an ongoing problem with completion of
18298 -- type derived from private types. Their structure is what Gigi
18299 -- expects, but the Etype is the parent type rather than the
18300 -- derived private type itself. Do not flag error in this case. The
18301 -- private completion is an entity without a parent, like an Itype.
18302 -- Similarly, full and partial views may be incorrect in the instance.
18303 -- There is no simple way to insure that it is consistent ???
18305 -- A similar view discrepancy can happen in an inlined body, for the
18306 -- same reason: inserted body may be outside of the original package
18307 -- and only partial views are visible at the point of insertion.
18309 elsif In_Instance
or else In_Inlined_Body
then
18310 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
18312 (Has_Private_Declaration
(Expected_Type
)
18313 or else Has_Private_Declaration
(Etype
(Expr
)))
18314 and then No
(Parent
(Expected_Type
))
18318 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
18319 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
18323 elsif Is_Private_Type
(Expected_Type
)
18324 and then Present
(Full_View
(Expected_Type
))
18325 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
18331 -- An interesting special check. If the expression is parenthesized
18332 -- and its type corresponds to the type of the sole component of the
18333 -- expected record type, or to the component type of the expected one
18334 -- dimensional array type, then assume we have a bad aggregate attempt.
18336 if Nkind
(Expr
) in N_Subexpr
18337 and then Paren_Count
(Expr
) /= 0
18338 and then Has_One_Matching_Field
18340 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
18341 if Present
(Matching_Field
) then
18342 if Is_Array_Type
(Expec_Type
) then
18344 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
18348 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
18352 -- Another special check, if we are looking for a pool-specific access
18353 -- type and we found an E_Access_Attribute_Type, then we have the case
18354 -- of an Access attribute being used in a context which needs a pool-
18355 -- specific type, which is never allowed. The one extra check we make
18356 -- is that the expected designated type covers the Found_Type.
18358 elsif Is_Access_Type
(Expec_Type
)
18359 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
18360 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
18361 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
18363 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
18365 Error_Msg_N
-- CODEFIX
18366 ("result must be general access type!", Expr
);
18367 Error_Msg_NE
-- CODEFIX
18368 ("add ALL to }!", Expr
, Expec_Type
);
18370 -- Another special check, if the expected type is an integer type,
18371 -- but the expression is of type System.Address, and the parent is
18372 -- an addition or subtraction operation whose left operand is the
18373 -- expression in question and whose right operand is of an integral
18374 -- type, then this is an attempt at address arithmetic, so give
18375 -- appropriate message.
18377 elsif Is_Integer_Type
(Expec_Type
)
18378 and then Is_RTE
(Found_Type
, RE_Address
)
18379 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
18380 and then Expr
= Left_Opnd
(Parent
(Expr
))
18381 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
18384 ("address arithmetic not predefined in package System",
18387 ("\possible missing with/use of System.Storage_Elements",
18391 -- If the expected type is an anonymous access type, as for access
18392 -- parameters and discriminants, the error is on the designated types.
18394 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
18395 if Comes_From_Source
(Expec_Type
) then
18396 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
18399 ("expected an access type with designated}",
18400 Expr
, Designated_Type
(Expec_Type
));
18403 if Is_Access_Type
(Found_Type
)
18404 and then not Comes_From_Source
(Found_Type
)
18407 ("\\found an access type with designated}!",
18408 Expr
, Designated_Type
(Found_Type
));
18410 if From_Limited_With
(Found_Type
) then
18411 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
18412 Error_Msg_Qual_Level
:= 99;
18413 Error_Msg_NE
-- CODEFIX
18414 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
18415 Error_Msg_Qual_Level
:= 0;
18417 Error_Msg_NE
("found}!", Expr
, Found_Type
);
18421 -- Normal case of one type found, some other type expected
18424 -- If the names of the two types are the same, see if some number
18425 -- of levels of qualification will help. Don't try more than three
18426 -- levels, and if we get to standard, it's no use (and probably
18427 -- represents an error in the compiler) Also do not bother with
18428 -- internal scope names.
18431 Expec_Scope
: Entity_Id
;
18432 Found_Scope
: Entity_Id
;
18435 Expec_Scope
:= Expec_Type
;
18436 Found_Scope
:= Found_Type
;
18438 for Levels
in Int
range 0 .. 3 loop
18439 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
18440 Error_Msg_Qual_Level
:= Levels
;
18444 Expec_Scope
:= Scope
(Expec_Scope
);
18445 Found_Scope
:= Scope
(Found_Scope
);
18447 exit when Expec_Scope
= Standard_Standard
18448 or else Found_Scope
= Standard_Standard
18449 or else not Comes_From_Source
(Expec_Scope
)
18450 or else not Comes_From_Source
(Found_Scope
);
18454 if Is_Record_Type
(Expec_Type
)
18455 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
18457 Error_Msg_NE
("expected}!", Expr
,
18458 Corresponding_Remote_Type
(Expec_Type
));
18460 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
18463 if Is_Entity_Name
(Expr
)
18464 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
18466 Error_Msg_N
("\\found package name!", Expr
);
18468 elsif Is_Entity_Name
(Expr
)
18469 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
18471 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
18473 ("found procedure name, possibly missing Access attribute!",
18477 ("\\found procedure name instead of function!", Expr
);
18480 elsif Nkind
(Expr
) = N_Function_Call
18481 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
18482 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
18483 and then No
(Parameter_Associations
(Expr
))
18486 ("found function name, possibly missing Access attribute!",
18489 -- Catch common error: a prefix or infix operator which is not
18490 -- directly visible because the type isn't.
18492 elsif Nkind
(Expr
) in N_Op
18493 and then Is_Overloaded
(Expr
)
18494 and then not Is_Immediately_Visible
(Expec_Type
)
18495 and then not Is_Potentially_Use_Visible
(Expec_Type
)
18496 and then not In_Use
(Expec_Type
)
18497 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
18500 ("operator of the type is not directly visible!", Expr
);
18502 elsif Ekind
(Found_Type
) = E_Void
18503 and then Present
(Parent
(Found_Type
))
18504 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
18506 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
18509 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
18512 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
18513 -- of the same modular type, and (M1 and M2) = 0 was intended.
18515 if Expec_Type
= Standard_Boolean
18516 and then Is_Modular_Integer_Type
(Found_Type
)
18517 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
18518 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
18521 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
18522 L
: constant Node_Id
:= Left_Opnd
(Op
);
18523 R
: constant Node_Id
:= Right_Opnd
(Op
);
18526 -- The case for the message is when the left operand of the
18527 -- comparison is the same modular type, or when it is an
18528 -- integer literal (or other universal integer expression),
18529 -- which would have been typed as the modular type if the
18530 -- parens had been there.
18532 if (Etype
(L
) = Found_Type
18534 Etype
(L
) = Universal_Integer
)
18535 and then Is_Integer_Type
(Etype
(R
))
18538 ("\\possible missing parens for modular operation", Expr
);
18543 -- Reset error message qualification indication
18545 Error_Msg_Qual_Level
:= 0;