1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2015, Free Software Foundation, Inc. --
11 -- GNAT is free software; you can redistribute it and/or modify it under --
12 -- terms of the GNU General Public License as published by the Free Soft- --
13 -- ware Foundation; either version 3, or (at your option) any later ver- --
14 -- sion. GNAT is distributed in the hope that it will be useful, but WITH- --
15 -- OUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY --
16 -- or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License --
17 -- for more details. You should have received a copy of the GNU General --
18 -- Public License distributed with GNAT; see file COPYING3. If not, go to --
19 -- http://www.gnu.org/licenses for a complete copy of the license. --
21 -- GNAT was originally developed by the GNAT team at New York University. --
22 -- Extensive contributions were provided by Ada Core Technologies Inc. --
24 ------------------------------------------------------------------------------
26 with Aspects
; use Aspects
;
27 with Atree
; use Atree
;
28 with Casing
; use Casing
;
29 with Checks
; use Checks
;
30 with Debug
; use Debug
;
31 with Elists
; use Elists
;
32 with Errout
; use Errout
;
33 with Exp_Ch11
; use Exp_Ch11
;
34 with Exp_Disp
; use Exp_Disp
;
35 with Exp_Util
; use Exp_Util
;
36 with Fname
; use Fname
;
37 with Freeze
; use Freeze
;
39 with Lib
.Xref
; use Lib
.Xref
;
40 with Namet
.Sp
; use Namet
.Sp
;
41 with Nlists
; use Nlists
;
42 with Nmake
; use Nmake
;
43 with Output
; use Output
;
44 with Restrict
; use Restrict
;
45 with Rident
; use Rident
;
46 with Rtsfind
; use Rtsfind
;
48 with Sem_Aux
; use Sem_Aux
;
49 with Sem_Attr
; use Sem_Attr
;
50 with Sem_Ch6
; use Sem_Ch6
;
51 with Sem_Ch8
; use Sem_Ch8
;
52 with Sem_Ch13
; use Sem_Ch13
;
53 with Sem_Disp
; use Sem_Disp
;
54 with Sem_Eval
; use Sem_Eval
;
55 with Sem_Prag
; use Sem_Prag
;
56 with Sem_Res
; use Sem_Res
;
57 with Sem_Warn
; use Sem_Warn
;
58 with Sem_Type
; use Sem_Type
;
59 with Sinfo
; use Sinfo
;
60 with Sinput
; use Sinput
;
61 with Stand
; use Stand
;
63 with Stringt
; use Stringt
;
64 with Targparm
; use Targparm
;
65 with Tbuild
; use Tbuild
;
66 with Ttypes
; use Ttypes
;
67 with Uname
; use Uname
;
69 with GNAT
.HTable
; use GNAT
.HTable
;
71 package body Sem_Util
is
73 ----------------------------------------
74 -- Global Variables for New_Copy_Tree --
75 ----------------------------------------
77 -- These global variables are used by New_Copy_Tree. See description of the
78 -- body of this subprogram for details. Global variables can be safely used
79 -- by New_Copy_Tree, since there is no case of a recursive call from the
80 -- processing inside New_Copy_Tree.
82 NCT_Hash_Threshold
: constant := 20;
83 -- If there are more than this number of pairs of entries in the map, then
84 -- Hash_Tables_Used will be set, and the hash tables will be initialized
85 -- and used for the searches.
87 NCT_Hash_Tables_Used
: Boolean := False;
88 -- Set to True if hash tables are in use
90 NCT_Table_Entries
: Nat
:= 0;
91 -- Count entries in table to see if threshold is reached
93 NCT_Hash_Table_Setup
: Boolean := False;
94 -- Set to True if hash table contains data. We set this True if we setup
95 -- the hash table with data, and leave it set permanently from then on,
96 -- this is a signal that second and subsequent users of the hash table
97 -- must clear the old entries before reuse.
99 subtype NCT_Header_Num
is Int
range 0 .. 511;
100 -- Defines range of headers in hash tables (512 headers)
102 -----------------------
103 -- Local Subprograms --
104 -----------------------
106 function Build_Component_Subtype
109 T
: Entity_Id
) return Node_Id
;
110 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
111 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
112 -- Loc is the source location, T is the original subtype.
114 function Has_Enabled_Property
115 (Item_Id
: Entity_Id
;
116 Property
: Name_Id
) return Boolean;
117 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
118 -- Determine whether an abstract state or a variable denoted by entity
119 -- Item_Id has enabled property Property.
121 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
122 -- T is a derived tagged type. Check whether the type extension is null.
123 -- If the parent type is fully initialized, T can be treated as such.
125 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
126 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
127 -- with discriminants whose default values are static, examine only the
128 -- components in the selected variant to determine whether all of them
131 ------------------------------
132 -- Abstract_Interface_List --
133 ------------------------------
135 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
139 if Is_Concurrent_Type
(Typ
) then
141 -- If we are dealing with a synchronized subtype, go to the base
142 -- type, whose declaration has the interface list.
144 -- Shouldn't this be Declaration_Node???
146 Nod
:= Parent
(Base_Type
(Typ
));
148 if Nkind
(Nod
) = N_Full_Type_Declaration
then
152 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
153 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
154 Nod
:= Type_Definition
(Parent
(Typ
));
156 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
157 if Present
(Full_View
(Typ
))
159 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
161 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
163 -- If the full-view is not available we cannot do anything else
164 -- here (the source has errors).
170 -- Support for generic formals with interfaces is still missing ???
172 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
177 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
181 elsif Ekind
(Typ
) = E_Record_Subtype
then
182 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
184 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
186 -- Recurse, because parent may still be a private extension. Also
187 -- note that the full view of the subtype or the full view of its
188 -- base type may (both) be unavailable.
190 return Abstract_Interface_List
(Etype
(Typ
));
192 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
193 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
194 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
196 Nod
:= Type_Definition
(Parent
(Typ
));
200 return Interface_List
(Nod
);
201 end Abstract_Interface_List
;
203 --------------------------------
204 -- Add_Access_Type_To_Process --
205 --------------------------------
207 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
211 Ensure_Freeze_Node
(E
);
212 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
216 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
220 end Add_Access_Type_To_Process
;
222 --------------------------
223 -- Add_Block_Identifier --
224 --------------------------
226 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
227 Loc
: constant Source_Ptr
:= Sloc
(N
);
230 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
232 -- The block already has a label, return its entity
234 if Present
(Identifier
(N
)) then
235 Id
:= Entity
(Identifier
(N
));
237 -- Create a new block label and set its attributes
240 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
241 Set_Etype
(Id
, Standard_Void_Type
);
244 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
245 Set_Block_Node
(Id
, Identifier
(N
));
247 end Add_Block_Identifier
;
249 -----------------------
250 -- Add_Contract_Item --
251 -----------------------
253 procedure Add_Contract_Item
(Prag
: Node_Id
; Id
: Entity_Id
) is
254 Items
: Node_Id
:= Contract
(Id
);
256 procedure Add_Classification
;
257 -- Prepend Prag to the list of classifications
259 procedure Add_Contract_Test_Case
;
260 -- Prepend Prag to the list of contract and test cases
262 procedure Add_Pre_Post_Condition
;
263 -- Prepend Prag to the list of pre- and postconditions
265 ------------------------
266 -- Add_Classification --
267 ------------------------
269 procedure Add_Classification
is
271 Set_Next_Pragma
(Prag
, Classifications
(Items
));
272 Set_Classifications
(Items
, Prag
);
273 end Add_Classification
;
275 ----------------------------
276 -- Add_Contract_Test_Case --
277 ----------------------------
279 procedure Add_Contract_Test_Case
is
281 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
282 Set_Contract_Test_Cases
(Items
, Prag
);
283 end Add_Contract_Test_Case
;
285 ----------------------------
286 -- Add_Pre_Post_Condition --
287 ----------------------------
289 procedure Add_Pre_Post_Condition
is
291 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
292 Set_Pre_Post_Conditions
(Items
, Prag
);
293 end Add_Pre_Post_Condition
;
299 -- Start of processing for Add_Contract_Item
302 -- A contract must contain only pragmas
304 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
305 Prag_Nam
:= Pragma_Name
(Prag
);
307 -- Create a new contract when adding the first item
310 Items
:= Make_Contract
(Sloc
(Id
));
311 Set_Contract
(Id
, Items
);
314 -- Contract items related to [generic] packages or instantiations. The
315 -- applicable pragmas are:
319 -- Part_Of (instantiation only)
321 if Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
322 if Nam_In
(Prag_Nam
, Name_Abstract_State
,
323 Name_Initial_Condition
,
328 -- Indicator Part_Of must be associated with a package instantiation
330 elsif Prag_Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) then
333 -- The pragma is not a proper contract item
339 -- Contract items related to package bodies. The applicable pragmas are:
342 elsif Ekind
(Id
) = E_Package_Body
then
343 if Prag_Nam
= Name_Refined_State
then
346 -- The pragma is not a proper contract item
352 -- Contract items related to subprogram or entry declarations. The
353 -- applicable pragmas are:
356 -- Extensions_Visible
362 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
363 or else Is_Generic_Subprogram
(Id
)
364 or else Is_Subprogram
(Id
)
366 if Nam_In
(Prag_Nam
, Name_Postcondition
, Name_Precondition
) then
367 Add_Pre_Post_Condition
;
369 elsif Nam_In
(Prag_Nam
, Name_Contract_Cases
, Name_Test_Case
) then
370 Add_Contract_Test_Case
;
372 elsif Nam_In
(Prag_Nam
, Name_Depends
,
373 Name_Extensions_Visible
,
378 -- The pragma is not a proper contract item
384 -- Contract items related to subprogram bodies. Applicable pragmas are:
391 elsif Ekind
(Id
) = E_Subprogram_Body
then
392 if Nam_In
(Prag_Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
395 elsif Nam_In
(Prag_Nam
, Name_Postcondition
,
399 Add_Pre_Post_Condition
;
401 -- The pragma is not a proper contract item
407 -- Contract items related to variables. Applicable pragmas are:
414 elsif Ekind
(Id
) = E_Variable
then
415 if Nam_In
(Prag_Nam
, Name_Async_Readers
,
417 Name_Effective_Reads
,
418 Name_Effective_Writes
,
423 -- The pragma is not a proper contract item
429 end Add_Contract_Item
;
431 ----------------------------
432 -- Add_Global_Declaration --
433 ----------------------------
435 procedure Add_Global_Declaration
(N
: Node_Id
) is
436 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
439 if No
(Declarations
(Aux_Node
)) then
440 Set_Declarations
(Aux_Node
, New_List
);
443 Append_To
(Declarations
(Aux_Node
), N
);
445 end Add_Global_Declaration
;
447 --------------------------------
448 -- Address_Integer_Convert_OK --
449 --------------------------------
451 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
453 if Allow_Integer_Address
454 and then ((Is_Descendent_Of_Address
(T1
)
455 and then Is_Private_Type
(T1
)
456 and then Is_Integer_Type
(T2
))
458 (Is_Descendent_Of_Address
(T2
)
459 and then Is_Private_Type
(T2
)
460 and then Is_Integer_Type
(T1
)))
466 end Address_Integer_Convert_OK
;
472 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
474 function Addressable
(V
: Uint
) return Boolean is
476 return V
= Uint_8
or else
482 function Addressable
(V
: Int
) return Boolean is
490 ---------------------------------
491 -- Aggregate_Constraint_Checks --
492 ---------------------------------
494 procedure Aggregate_Constraint_Checks
496 Check_Typ
: Entity_Id
)
498 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
501 if Raises_Constraint_Error
(Exp
) then
505 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
506 -- component's type to force the appropriate accessibility checks.
508 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
509 -- type to force the corresponding run-time check
511 if Is_Access_Type
(Check_Typ
)
512 and then ((Is_Local_Anonymous_Access
(Check_Typ
))
513 or else (Can_Never_Be_Null
(Check_Typ
)
514 and then not Can_Never_Be_Null
(Exp_Typ
)))
516 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
517 Analyze_And_Resolve
(Exp
, Check_Typ
);
518 Check_Unset_Reference
(Exp
);
521 -- This is really expansion activity, so make sure that expansion is
522 -- on and is allowed. In GNATprove mode, we also want check flags to
523 -- be added in the tree, so that the formal verification can rely on
524 -- those to be present. In GNATprove mode for formal verification, some
525 -- treatment typically only done during expansion needs to be performed
526 -- on the tree, but it should not be applied inside generics. Otherwise,
527 -- this breaks the name resolution mechanism for generic instances.
529 if not Expander_Active
530 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
535 -- First check if we have to insert discriminant checks
537 if Has_Discriminants
(Exp_Typ
) then
538 Apply_Discriminant_Check
(Exp
, Check_Typ
);
540 -- Next emit length checks for array aggregates
542 elsif Is_Array_Type
(Exp_Typ
) then
543 Apply_Length_Check
(Exp
, Check_Typ
);
545 -- Finally emit scalar and string checks. If we are dealing with a
546 -- scalar literal we need to check by hand because the Etype of
547 -- literals is not necessarily correct.
549 elsif Is_Scalar_Type
(Exp_Typ
)
550 and then Compile_Time_Known_Value
(Exp
)
552 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
553 Apply_Compile_Time_Constraint_Error
554 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
555 Ent
=> Base_Type
(Check_Typ
),
556 Typ
=> Base_Type
(Check_Typ
));
558 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
559 Apply_Compile_Time_Constraint_Error
560 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
564 elsif not Range_Checks_Suppressed
(Check_Typ
) then
565 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
568 -- Verify that target type is also scalar, to prevent view anomalies
569 -- in instantiations.
571 elsif (Is_Scalar_Type
(Exp_Typ
)
572 or else Nkind
(Exp
) = N_String_Literal
)
573 and then Is_Scalar_Type
(Check_Typ
)
574 and then Exp_Typ
/= Check_Typ
576 if Is_Entity_Name
(Exp
)
577 and then Ekind
(Entity
(Exp
)) = E_Constant
579 -- If expression is a constant, it is worthwhile checking whether
580 -- it is a bound of the type.
582 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
583 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
585 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
586 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
591 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
592 Analyze_And_Resolve
(Exp
, Check_Typ
);
593 Check_Unset_Reference
(Exp
);
596 -- Could use a comment on this case ???
599 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
600 Analyze_And_Resolve
(Exp
, Check_Typ
);
601 Check_Unset_Reference
(Exp
);
605 end Aggregate_Constraint_Checks
;
607 -----------------------
608 -- Alignment_In_Bits --
609 -----------------------
611 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
613 return Alignment
(E
) * System_Storage_Unit
;
614 end Alignment_In_Bits
;
616 ---------------------------------
617 -- Append_Inherited_Subprogram --
618 ---------------------------------
620 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
621 Par
: constant Entity_Id
:= Alias
(S
);
622 -- The parent subprogram
624 Scop
: constant Entity_Id
:= Scope
(Par
);
625 -- The scope of definition of the parent subprogram
627 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
628 -- The derived type of which S is a primitive operation
634 if Ekind
(Current_Scope
) = E_Package
635 and then In_Private_Part
(Current_Scope
)
636 and then Has_Private_Declaration
(Typ
)
637 and then Is_Tagged_Type
(Typ
)
638 and then Scop
= Current_Scope
640 -- The inherited operation is available at the earliest place after
641 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
642 -- relevant for type extensions. If the parent operation appears
643 -- after the type extension, the operation is not visible.
646 (Visible_Declarations
647 (Package_Specification
(Current_Scope
)));
648 while Present
(Decl
) loop
649 if Nkind
(Decl
) = N_Private_Extension_Declaration
650 and then Defining_Entity
(Decl
) = Typ
652 if Sloc
(Decl
) > Sloc
(Par
) then
653 Next_E
:= Next_Entity
(Par
);
654 Set_Next_Entity
(Par
, S
);
655 Set_Next_Entity
(S
, Next_E
);
667 -- If partial view is not a type extension, or it appears before the
668 -- subprogram declaration, insert normally at end of entity list.
670 Append_Entity
(S
, Current_Scope
);
671 end Append_Inherited_Subprogram
;
673 -----------------------------------------
674 -- Apply_Compile_Time_Constraint_Error --
675 -----------------------------------------
677 procedure Apply_Compile_Time_Constraint_Error
680 Reason
: RT_Exception_Code
;
681 Ent
: Entity_Id
:= Empty
;
682 Typ
: Entity_Id
:= Empty
;
683 Loc
: Source_Ptr
:= No_Location
;
684 Rep
: Boolean := True;
685 Warn
: Boolean := False)
687 Stat
: constant Boolean := Is_Static_Expression
(N
);
688 R_Stat
: constant Node_Id
:=
689 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
700 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
706 -- Now we replace the node by an N_Raise_Constraint_Error node
707 -- This does not need reanalyzing, so set it as analyzed now.
710 Set_Analyzed
(N
, True);
713 Set_Raises_Constraint_Error
(N
);
715 -- Now deal with possible local raise handling
717 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
719 -- If the original expression was marked as static, the result is
720 -- still marked as static, but the Raises_Constraint_Error flag is
721 -- always set so that further static evaluation is not attempted.
724 Set_Is_Static_Expression
(N
);
726 end Apply_Compile_Time_Constraint_Error
;
728 ---------------------------
729 -- Async_Readers_Enabled --
730 ---------------------------
732 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
734 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
735 end Async_Readers_Enabled
;
737 ---------------------------
738 -- Async_Writers_Enabled --
739 ---------------------------
741 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
743 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
744 end Async_Writers_Enabled
;
746 --------------------------------------
747 -- Available_Full_View_Of_Component --
748 --------------------------------------
750 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
751 ST
: constant Entity_Id
:= Scope
(T
);
752 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
754 return In_Open_Scopes
(ST
)
755 and then In_Open_Scopes
(SCT
)
756 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
757 end Available_Full_View_Of_Component
;
763 procedure Bad_Attribute
766 Warn
: Boolean := False)
769 Error_Msg_Warn
:= Warn
;
770 Error_Msg_N
("unrecognized attribute&<<", N
);
772 -- Check for possible misspelling
774 Error_Msg_Name_1
:= First_Attribute_Name
;
775 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
776 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
777 Error_Msg_N
-- CODEFIX
778 ("\possible misspelling of %<<", N
);
782 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
786 --------------------------------
787 -- Bad_Predicated_Subtype_Use --
788 --------------------------------
790 procedure Bad_Predicated_Subtype_Use
794 Suggest_Static
: Boolean := False)
799 -- Avoid cascaded errors
801 if Error_Posted
(N
) then
805 if Inside_A_Generic
then
806 Gen
:= Current_Scope
;
807 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
815 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
816 Set_No_Predicate_On_Actual
(Typ
);
819 elsif Has_Predicates
(Typ
) then
820 if Is_Generic_Actual_Type
(Typ
) then
822 -- The restriction on loop parameters is only that the type
823 -- should have no dynamic predicates.
825 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
826 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
827 and then Is_OK_Static_Subtype
(Typ
)
832 Gen
:= Current_Scope
;
833 while not Is_Generic_Instance
(Gen
) loop
837 pragma Assert
(Present
(Gen
));
839 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
840 Error_Msg_Warn
:= SPARK_Mode
/= On
;
841 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
842 Error_Msg_F
("\Program_Error [<<", N
);
845 Make_Raise_Program_Error
(Sloc
(N
),
846 Reason
=> PE_Bad_Predicated_Generic_Type
));
849 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
853 Error_Msg_FE
(Msg
, N
, Typ
);
856 -- Emit an optional suggestion on how to remedy the error if the
857 -- context warrants it.
859 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
860 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
863 end Bad_Predicated_Subtype_Use
;
865 -----------------------------------------
866 -- Bad_Unordered_Enumeration_Reference --
867 -----------------------------------------
869 function Bad_Unordered_Enumeration_Reference
871 T
: Entity_Id
) return Boolean
874 return Is_Enumeration_Type
(T
)
875 and then Warn_On_Unordered_Enumeration_Type
876 and then not Is_Generic_Type
(T
)
877 and then Comes_From_Source
(N
)
878 and then not Has_Pragma_Ordered
(T
)
879 and then not In_Same_Extended_Unit
(N
, T
);
880 end Bad_Unordered_Enumeration_Reference
;
882 --------------------------
883 -- Build_Actual_Subtype --
884 --------------------------
886 function Build_Actual_Subtype
888 N
: Node_Or_Entity_Id
) return Node_Id
891 -- Normally Sloc (N), but may point to corresponding body in some cases
893 Constraints
: List_Id
;
899 Disc_Type
: Entity_Id
;
905 if Nkind
(N
) = N_Defining_Identifier
then
906 Obj
:= New_Occurrence_Of
(N
, Loc
);
908 -- If this is a formal parameter of a subprogram declaration, and
909 -- we are compiling the body, we want the declaration for the
910 -- actual subtype to carry the source position of the body, to
911 -- prevent anomalies in gdb when stepping through the code.
913 if Is_Formal
(N
) then
915 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
917 if Nkind
(Decl
) = N_Subprogram_Declaration
918 and then Present
(Corresponding_Body
(Decl
))
920 Loc
:= Sloc
(Corresponding_Body
(Decl
));
929 if Is_Array_Type
(T
) then
930 Constraints
:= New_List
;
931 for J
in 1 .. Number_Dimensions
(T
) loop
933 -- Build an array subtype declaration with the nominal subtype and
934 -- the bounds of the actual. Add the declaration in front of the
935 -- local declarations for the subprogram, for analysis before any
936 -- reference to the formal in the body.
939 Make_Attribute_Reference
(Loc
,
941 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
942 Attribute_Name
=> Name_First
,
943 Expressions
=> New_List
(
944 Make_Integer_Literal
(Loc
, J
)));
947 Make_Attribute_Reference
(Loc
,
949 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
950 Attribute_Name
=> Name_Last
,
951 Expressions
=> New_List
(
952 Make_Integer_Literal
(Loc
, J
)));
954 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
957 -- If the type has unknown discriminants there is no constrained
958 -- subtype to build. This is never called for a formal or for a
959 -- lhs, so returning the type is ok ???
961 elsif Has_Unknown_Discriminants
(T
) then
965 Constraints
:= New_List
;
967 -- Type T is a generic derived type, inherit the discriminants from
970 if Is_Private_Type
(T
)
971 and then No
(Full_View
(T
))
973 -- T was flagged as an error if it was declared as a formal
974 -- derived type with known discriminants. In this case there
975 -- is no need to look at the parent type since T already carries
976 -- its own discriminants.
978 and then not Error_Posted
(T
)
980 Disc_Type
:= Etype
(Base_Type
(T
));
985 Discr
:= First_Discriminant
(Disc_Type
);
986 while Present
(Discr
) loop
987 Append_To
(Constraints
,
988 Make_Selected_Component
(Loc
,
990 Duplicate_Subexpr_No_Checks
(Obj
),
991 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
992 Next_Discriminant
(Discr
);
996 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
997 Set_Is_Internal
(Subt
);
1000 Make_Subtype_Declaration
(Loc
,
1001 Defining_Identifier
=> Subt
,
1002 Subtype_Indication
=>
1003 Make_Subtype_Indication
(Loc
,
1004 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1006 Make_Index_Or_Discriminant_Constraint
(Loc
,
1007 Constraints
=> Constraints
)));
1009 Mark_Rewrite_Insertion
(Decl
);
1011 end Build_Actual_Subtype
;
1013 ---------------------------------------
1014 -- Build_Actual_Subtype_Of_Component --
1015 ---------------------------------------
1017 function Build_Actual_Subtype_Of_Component
1019 N
: Node_Id
) return Node_Id
1021 Loc
: constant Source_Ptr
:= Sloc
(N
);
1022 P
: constant Node_Id
:= Prefix
(N
);
1025 Index_Typ
: Entity_Id
;
1027 Desig_Typ
: Entity_Id
;
1028 -- This is either a copy of T, or if T is an access type, then it is
1029 -- the directly designated type of this access type.
1031 function Build_Actual_Array_Constraint
return List_Id
;
1032 -- If one or more of the bounds of the component depends on
1033 -- discriminants, build actual constraint using the discriminants
1036 function Build_Actual_Record_Constraint
return List_Id
;
1037 -- Similar to previous one, for discriminated components constrained
1038 -- by the discriminant of the enclosing object.
1040 -----------------------------------
1041 -- Build_Actual_Array_Constraint --
1042 -----------------------------------
1044 function Build_Actual_Array_Constraint
return List_Id
is
1045 Constraints
: constant List_Id
:= New_List
;
1053 Indx
:= First_Index
(Desig_Typ
);
1054 while Present
(Indx
) loop
1055 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1056 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1058 if Denotes_Discriminant
(Old_Lo
) then
1060 Make_Selected_Component
(Loc
,
1061 Prefix
=> New_Copy_Tree
(P
),
1062 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1065 Lo
:= New_Copy_Tree
(Old_Lo
);
1067 -- The new bound will be reanalyzed in the enclosing
1068 -- declaration. For literal bounds that come from a type
1069 -- declaration, the type of the context must be imposed, so
1070 -- insure that analysis will take place. For non-universal
1071 -- types this is not strictly necessary.
1073 Set_Analyzed
(Lo
, False);
1076 if Denotes_Discriminant
(Old_Hi
) then
1078 Make_Selected_Component
(Loc
,
1079 Prefix
=> New_Copy_Tree
(P
),
1080 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1083 Hi
:= New_Copy_Tree
(Old_Hi
);
1084 Set_Analyzed
(Hi
, False);
1087 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1092 end Build_Actual_Array_Constraint
;
1094 ------------------------------------
1095 -- Build_Actual_Record_Constraint --
1096 ------------------------------------
1098 function Build_Actual_Record_Constraint
return List_Id
is
1099 Constraints
: constant List_Id
:= New_List
;
1104 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1105 while Present
(D
) loop
1106 if Denotes_Discriminant
(Node
(D
)) then
1107 D_Val
:= Make_Selected_Component
(Loc
,
1108 Prefix
=> New_Copy_Tree
(P
),
1109 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1112 D_Val
:= New_Copy_Tree
(Node
(D
));
1115 Append
(D_Val
, Constraints
);
1120 end Build_Actual_Record_Constraint
;
1122 -- Start of processing for Build_Actual_Subtype_Of_Component
1125 -- Why the test for Spec_Expression mode here???
1127 if In_Spec_Expression
then
1130 -- More comments for the rest of this body would be good ???
1132 elsif Nkind
(N
) = N_Explicit_Dereference
then
1133 if Is_Composite_Type
(T
)
1134 and then not Is_Constrained
(T
)
1135 and then not (Is_Class_Wide_Type
(T
)
1136 and then Is_Constrained
(Root_Type
(T
)))
1137 and then not Has_Unknown_Discriminants
(T
)
1139 -- If the type of the dereference is already constrained, it is an
1142 if Is_Array_Type
(Etype
(N
))
1143 and then Is_Constrained
(Etype
(N
))
1147 Remove_Side_Effects
(P
);
1148 return Build_Actual_Subtype
(T
, N
);
1155 if Ekind
(T
) = E_Access_Subtype
then
1156 Desig_Typ
:= Designated_Type
(T
);
1161 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1162 Id
:= First_Index
(Desig_Typ
);
1163 while Present
(Id
) loop
1164 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1166 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1168 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1170 Remove_Side_Effects
(P
);
1172 Build_Component_Subtype
1173 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1179 elsif Is_Composite_Type
(Desig_Typ
)
1180 and then Has_Discriminants
(Desig_Typ
)
1181 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1183 if Is_Private_Type
(Desig_Typ
)
1184 and then No
(Discriminant_Constraint
(Desig_Typ
))
1186 Desig_Typ
:= Full_View
(Desig_Typ
);
1189 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1190 while Present
(D
) loop
1191 if Denotes_Discriminant
(Node
(D
)) then
1192 Remove_Side_Effects
(P
);
1194 Build_Component_Subtype
(
1195 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1202 -- If none of the above, the actual and nominal subtypes are the same
1205 end Build_Actual_Subtype_Of_Component
;
1207 -----------------------------
1208 -- Build_Component_Subtype --
1209 -----------------------------
1211 function Build_Component_Subtype
1214 T
: Entity_Id
) return Node_Id
1220 -- Unchecked_Union components do not require component subtypes
1222 if Is_Unchecked_Union
(T
) then
1226 Subt
:= Make_Temporary
(Loc
, 'S');
1227 Set_Is_Internal
(Subt
);
1230 Make_Subtype_Declaration
(Loc
,
1231 Defining_Identifier
=> Subt
,
1232 Subtype_Indication
=>
1233 Make_Subtype_Indication
(Loc
,
1234 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1236 Make_Index_Or_Discriminant_Constraint
(Loc
,
1237 Constraints
=> C
)));
1239 Mark_Rewrite_Insertion
(Decl
);
1241 end Build_Component_Subtype
;
1243 ----------------------------------
1244 -- Build_Default_Init_Cond_Call --
1245 ----------------------------------
1247 function Build_Default_Init_Cond_Call
1250 Typ
: Entity_Id
) return Node_Id
1252 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1253 Formal_Typ
: constant Entity_Id
:= Etype
(First_Formal
(Proc_Id
));
1257 Make_Procedure_Call_Statement
(Loc
,
1258 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
1259 Parameter_Associations
=> New_List
(
1260 Make_Unchecked_Type_Conversion
(Loc
,
1261 Subtype_Mark
=> New_Occurrence_Of
(Formal_Typ
, Loc
),
1262 Expression
=> New_Occurrence_Of
(Obj_Id
, Loc
))));
1263 end Build_Default_Init_Cond_Call
;
1265 ----------------------------------------------
1266 -- Build_Default_Init_Cond_Procedure_Bodies --
1267 ----------------------------------------------
1269 procedure Build_Default_Init_Cond_Procedure_Bodies
(Priv_Decls
: List_Id
) is
1270 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
);
1271 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1272 -- body of the procedure which verifies the assumption of the pragma at
1273 -- run time. The generated body is added after the type declaration.
1275 --------------------------------------------
1276 -- Build_Default_Init_Cond_Procedure_Body --
1277 --------------------------------------------
1279 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
) is
1280 Param_Id
: Entity_Id
;
1281 -- The entity of the sole formal parameter of the default initial
1282 -- condition procedure.
1284 procedure Replace_Type_Reference
(N
: Node_Id
);
1285 -- Replace a single reference to type Typ with a reference to formal
1286 -- parameter Param_Id.
1288 ----------------------------
1289 -- Replace_Type_Reference --
1290 ----------------------------
1292 procedure Replace_Type_Reference
(N
: Node_Id
) is
1294 Rewrite
(N
, New_Occurrence_Of
(Param_Id
, Sloc
(N
)));
1295 end Replace_Type_Reference
;
1297 procedure Replace_Type_References
is
1298 new Replace_Type_References_Generic
(Replace_Type_Reference
);
1302 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1303 Prag
: constant Node_Id
:=
1304 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1305 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1306 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Proc_Id
);
1307 Body_Decl
: Node_Id
;
1311 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1314 -- The procedure should be generated only for [sub]types subject to
1315 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1316 -- not get this specialized procedure.
1318 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1319 pragma Assert
(Present
(Prag
));
1320 pragma Assert
(Present
(Proc_Id
));
1322 -- Nothing to do if the body was already built
1324 if Present
(Corresponding_Body
(Spec_Decl
)) then
1328 Param_Id
:= First_Formal
(Proc_Id
);
1330 -- The pragma has an argument. Note that the argument is analyzed
1331 -- after all references to the current instance of the type are
1334 if Present
(Pragma_Argument_Associations
(Prag
)) then
1336 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
1338 if Nkind
(Expr
) = N_Null
then
1339 Stmt
:= Make_Null_Statement
(Loc
);
1341 -- Preserve the original argument of the pragma by replicating it.
1342 -- Replace all references to the current instance of the type with
1343 -- references to the formal parameter.
1346 Expr
:= New_Copy_Tree
(Expr
);
1347 Replace_Type_References
(Expr
, Typ
);
1350 -- pragma Check (Default_Initial_Condition, <Expr>);
1354 Pragma_Identifier
=>
1355 Make_Identifier
(Loc
, Name_Check
),
1357 Pragma_Argument_Associations
=> New_List
(
1358 Make_Pragma_Argument_Association
(Loc
,
1360 Make_Identifier
(Loc
,
1361 Chars
=> Name_Default_Initial_Condition
)),
1362 Make_Pragma_Argument_Association
(Loc
,
1363 Expression
=> Expr
)));
1366 -- Otherwise the pragma appears without an argument
1369 Stmt
:= Make_Null_Statement
(Loc
);
1373 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1376 -- end <Typ>Default_Init_Cond;
1379 Make_Subprogram_Body
(Loc
,
1381 Copy_Separate_Tree
(Specification
(Spec_Decl
)),
1382 Declarations
=> Empty_List
,
1383 Handled_Statement_Sequence
=>
1384 Make_Handled_Sequence_Of_Statements
(Loc
,
1385 Statements
=> New_List
(Stmt
)));
1387 -- Link the spec and body of the default initial condition procedure
1388 -- to prevent the generation of a duplicate body.
1390 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
1391 Set_Corresponding_Spec
(Body_Decl
, Proc_Id
);
1393 Insert_After_And_Analyze
(Declaration_Node
(Typ
), Body_Decl
);
1394 end Build_Default_Init_Cond_Procedure_Body
;
1401 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1404 -- Inspect the private declarations looking for [sub]type declarations
1406 Decl
:= First
(Priv_Decls
);
1407 while Present
(Decl
) loop
1408 if Nkind_In
(Decl
, N_Full_Type_Declaration
,
1409 N_Subtype_Declaration
)
1411 Typ
:= Defining_Entity
(Decl
);
1413 -- Guard against partially decorate types due to previous errors
1415 if Is_Type
(Typ
) then
1417 -- If the type is subject to pragma Default_Initial_Condition,
1418 -- generate the body of the internal procedure which verifies
1419 -- the assertion of the pragma at run time.
1421 if Has_Default_Init_Cond
(Typ
) then
1422 Build_Default_Init_Cond_Procedure_Body
(Typ
);
1424 -- A derived type inherits the default initial condition
1425 -- procedure from its parent type.
1427 elsif Has_Inherited_Default_Init_Cond
(Typ
) then
1428 Inherit_Default_Init_Cond_Procedure
(Typ
);
1435 end Build_Default_Init_Cond_Procedure_Bodies
;
1437 ---------------------------------------------------
1438 -- Build_Default_Init_Cond_Procedure_Declaration --
1439 ---------------------------------------------------
1441 procedure Build_Default_Init_Cond_Procedure_Declaration
(Typ
: Entity_Id
) is
1442 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1443 Prag
: constant Node_Id
:=
1444 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1445 Proc_Id
: Entity_Id
;
1448 -- The procedure should be generated only for types subject to pragma
1449 -- Default_Initial_Condition. Types that inherit the pragma do not get
1450 -- this specialized procedure.
1452 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1453 pragma Assert
(Present
(Prag
));
1455 -- Nothing to do if default initial condition procedure already built
1457 if Present
(Default_Init_Cond_Procedure
(Typ
)) then
1462 Make_Defining_Identifier
(Loc
,
1463 Chars
=> New_External_Name
(Chars
(Typ
), "Default_Init_Cond"));
1465 -- Associate default initial condition procedure with the private type
1467 Set_Ekind
(Proc_Id
, E_Procedure
);
1468 Set_Is_Default_Init_Cond_Procedure
(Proc_Id
);
1469 Set_Default_Init_Cond_Procedure
(Typ
, Proc_Id
);
1472 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1474 Insert_After_And_Analyze
(Prag
,
1475 Make_Subprogram_Declaration
(Loc
,
1477 Make_Procedure_Specification
(Loc
,
1478 Defining_Unit_Name
=> Proc_Id
,
1479 Parameter_Specifications
=> New_List
(
1480 Make_Parameter_Specification
(Loc
,
1481 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
1482 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))))));
1483 end Build_Default_Init_Cond_Procedure_Declaration
;
1485 ---------------------------
1486 -- Build_Default_Subtype --
1487 ---------------------------
1489 function Build_Default_Subtype
1491 N
: Node_Id
) return Entity_Id
1493 Loc
: constant Source_Ptr
:= Sloc
(N
);
1497 -- The base type that is to be constrained by the defaults
1500 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1504 Bas
:= Base_Type
(T
);
1506 -- If T is non-private but its base type is private, this is the
1507 -- completion of a subtype declaration whose parent type is private
1508 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1509 -- are to be found in the full view of the base. Check that the private
1510 -- status of T and its base differ.
1512 if Is_Private_Type
(Bas
)
1513 and then not Is_Private_Type
(T
)
1514 and then Present
(Full_View
(Bas
))
1516 Bas
:= Full_View
(Bas
);
1519 Disc
:= First_Discriminant
(T
);
1521 if No
(Discriminant_Default_Value
(Disc
)) then
1526 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1527 Constraints
: constant List_Id
:= New_List
;
1531 while Present
(Disc
) loop
1532 Append_To
(Constraints
,
1533 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1534 Next_Discriminant
(Disc
);
1538 Make_Subtype_Declaration
(Loc
,
1539 Defining_Identifier
=> Act
,
1540 Subtype_Indication
=>
1541 Make_Subtype_Indication
(Loc
,
1542 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1544 Make_Index_Or_Discriminant_Constraint
(Loc
,
1545 Constraints
=> Constraints
)));
1547 Insert_Action
(N
, Decl
);
1551 end Build_Default_Subtype
;
1553 --------------------------------------------
1554 -- Build_Discriminal_Subtype_Of_Component --
1555 --------------------------------------------
1557 function Build_Discriminal_Subtype_Of_Component
1558 (T
: Entity_Id
) return Node_Id
1560 Loc
: constant Source_Ptr
:= Sloc
(T
);
1564 function Build_Discriminal_Array_Constraint
return List_Id
;
1565 -- If one or more of the bounds of the component depends on
1566 -- discriminants, build actual constraint using the discriminants
1569 function Build_Discriminal_Record_Constraint
return List_Id
;
1570 -- Similar to previous one, for discriminated components constrained by
1571 -- the discriminant of the enclosing object.
1573 ----------------------------------------
1574 -- Build_Discriminal_Array_Constraint --
1575 ----------------------------------------
1577 function Build_Discriminal_Array_Constraint
return List_Id
is
1578 Constraints
: constant List_Id
:= New_List
;
1586 Indx
:= First_Index
(T
);
1587 while Present
(Indx
) loop
1588 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1589 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1591 if Denotes_Discriminant
(Old_Lo
) then
1592 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1595 Lo
:= New_Copy_Tree
(Old_Lo
);
1598 if Denotes_Discriminant
(Old_Hi
) then
1599 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1602 Hi
:= New_Copy_Tree
(Old_Hi
);
1605 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1610 end Build_Discriminal_Array_Constraint
;
1612 -----------------------------------------
1613 -- Build_Discriminal_Record_Constraint --
1614 -----------------------------------------
1616 function Build_Discriminal_Record_Constraint
return List_Id
is
1617 Constraints
: constant List_Id
:= New_List
;
1622 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1623 while Present
(D
) loop
1624 if Denotes_Discriminant
(Node
(D
)) then
1626 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1628 D_Val
:= New_Copy_Tree
(Node
(D
));
1631 Append
(D_Val
, Constraints
);
1636 end Build_Discriminal_Record_Constraint
;
1638 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1641 if Ekind
(T
) = E_Array_Subtype
then
1642 Id
:= First_Index
(T
);
1643 while Present
(Id
) loop
1644 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1646 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1648 return Build_Component_Subtype
1649 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1655 elsif Ekind
(T
) = E_Record_Subtype
1656 and then Has_Discriminants
(T
)
1657 and then not Has_Unknown_Discriminants
(T
)
1659 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1660 while Present
(D
) loop
1661 if Denotes_Discriminant
(Node
(D
)) then
1662 return Build_Component_Subtype
1663 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1670 -- If none of the above, the actual and nominal subtypes are the same
1673 end Build_Discriminal_Subtype_Of_Component
;
1675 ------------------------------
1676 -- Build_Elaboration_Entity --
1677 ------------------------------
1679 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1680 Loc
: constant Source_Ptr
:= Sloc
(N
);
1682 Elab_Ent
: Entity_Id
;
1684 procedure Set_Package_Name
(Ent
: Entity_Id
);
1685 -- Given an entity, sets the fully qualified name of the entity in
1686 -- Name_Buffer, with components separated by double underscores. This
1687 -- is a recursive routine that climbs the scope chain to Standard.
1689 ----------------------
1690 -- Set_Package_Name --
1691 ----------------------
1693 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1695 if Scope
(Ent
) /= Standard_Standard
then
1696 Set_Package_Name
(Scope
(Ent
));
1699 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1701 Name_Buffer
(Name_Len
+ 1) := '_';
1702 Name_Buffer
(Name_Len
+ 2) := '_';
1703 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1704 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1708 Get_Name_String
(Chars
(Ent
));
1710 end Set_Package_Name
;
1712 -- Start of processing for Build_Elaboration_Entity
1715 -- Ignore call if already constructed
1717 if Present
(Elaboration_Entity
(Spec_Id
)) then
1720 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1721 -- no role in analysis.
1723 elsif ASIS_Mode
then
1726 -- See if we need elaboration entity. We always need it for the dynamic
1727 -- elaboration model, since it is needed to properly generate the PE
1728 -- exception for access before elaboration.
1730 elsif Dynamic_Elaboration_Checks
then
1733 -- For the static model, we don't need the elaboration counter if this
1734 -- unit is sure to have no elaboration code, since that means there
1735 -- is no elaboration unit to be called. Note that we can't just decide
1736 -- after the fact by looking to see whether there was elaboration code,
1737 -- because that's too late to make this decision.
1739 elsif Restriction_Active
(No_Elaboration_Code
) then
1742 -- Similarly, for the static model, we can skip the elaboration counter
1743 -- if we have the No_Multiple_Elaboration restriction, since for the
1744 -- static model, that's the only purpose of the counter (to avoid
1745 -- multiple elaboration).
1747 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1751 -- Here we need the elaboration entity
1753 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1754 -- name with dots replaced by double underscore. We have to manually
1755 -- construct this name, since it will be elaborated in the outer scope,
1756 -- and thus will not have the unit name automatically prepended.
1758 Set_Package_Name
(Spec_Id
);
1759 Add_Str_To_Name_Buffer
("_E");
1761 -- Create elaboration counter
1763 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1764 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1767 Make_Object_Declaration
(Loc
,
1768 Defining_Identifier
=> Elab_Ent
,
1769 Object_Definition
=>
1770 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1771 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1773 Push_Scope
(Standard_Standard
);
1774 Add_Global_Declaration
(Decl
);
1777 -- Reset True_Constant indication, since we will indeed assign a value
1778 -- to the variable in the binder main. We also kill the Current_Value
1779 -- and Last_Assignment fields for the same reason.
1781 Set_Is_True_Constant
(Elab_Ent
, False);
1782 Set_Current_Value
(Elab_Ent
, Empty
);
1783 Set_Last_Assignment
(Elab_Ent
, Empty
);
1785 -- We do not want any further qualification of the name (if we did not
1786 -- do this, we would pick up the name of the generic package in the case
1787 -- of a library level generic instantiation).
1789 Set_Has_Qualified_Name
(Elab_Ent
);
1790 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1791 end Build_Elaboration_Entity
;
1793 --------------------------------
1794 -- Build_Explicit_Dereference --
1795 --------------------------------
1797 procedure Build_Explicit_Dereference
1801 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1804 -- An entity of a type with a reference aspect is overloaded with
1805 -- both interpretations: with and without the dereference. Now that
1806 -- the dereference is made explicit, set the type of the node properly,
1807 -- to prevent anomalies in the backend. Same if the expression is an
1808 -- overloaded function call whose return type has a reference aspect.
1810 if Is_Entity_Name
(Expr
) then
1811 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1813 elsif Nkind
(Expr
) = N_Function_Call
then
1814 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1817 Set_Is_Overloaded
(Expr
, False);
1819 -- The expression will often be a generalized indexing that yields a
1820 -- container element that is then dereferenced, in which case the
1821 -- generalized indexing call is also non-overloaded.
1823 if Nkind
(Expr
) = N_Indexed_Component
1824 and then Present
(Generalized_Indexing
(Expr
))
1826 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1830 Make_Explicit_Dereference
(Loc
,
1832 Make_Selected_Component
(Loc
,
1833 Prefix
=> Relocate_Node
(Expr
),
1834 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1835 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1836 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1837 end Build_Explicit_Dereference
;
1839 -----------------------------------
1840 -- Cannot_Raise_Constraint_Error --
1841 -----------------------------------
1843 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1845 if Compile_Time_Known_Value
(Expr
) then
1848 elsif Do_Range_Check
(Expr
) then
1851 elsif Raises_Constraint_Error
(Expr
) then
1855 case Nkind
(Expr
) is
1856 when N_Identifier
=>
1859 when N_Expanded_Name
=>
1862 when N_Selected_Component
=>
1863 return not Do_Discriminant_Check
(Expr
);
1865 when N_Attribute_Reference
=>
1866 if Do_Overflow_Check
(Expr
) then
1869 elsif No
(Expressions
(Expr
)) then
1877 N
:= First
(Expressions
(Expr
));
1878 while Present
(N
) loop
1879 if Cannot_Raise_Constraint_Error
(N
) then
1890 when N_Type_Conversion
=>
1891 if Do_Overflow_Check
(Expr
)
1892 or else Do_Length_Check
(Expr
)
1893 or else Do_Tag_Check
(Expr
)
1897 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1900 when N_Unchecked_Type_Conversion
=>
1901 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1904 if Do_Overflow_Check
(Expr
) then
1907 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1914 if Do_Division_Check
(Expr
)
1916 Do_Overflow_Check
(Expr
)
1921 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1923 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1942 N_Op_Shift_Right_Arithmetic |
1946 if Do_Overflow_Check
(Expr
) then
1950 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1952 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1959 end Cannot_Raise_Constraint_Error
;
1961 -----------------------------------------
1962 -- Check_Dynamically_Tagged_Expression --
1963 -----------------------------------------
1965 procedure Check_Dynamically_Tagged_Expression
1968 Related_Nod
: Node_Id
)
1971 pragma Assert
(Is_Tagged_Type
(Typ
));
1973 -- In order to avoid spurious errors when analyzing the expanded code,
1974 -- this check is done only for nodes that come from source and for
1975 -- actuals of generic instantiations.
1977 if (Comes_From_Source
(Related_Nod
)
1978 or else In_Generic_Actual
(Expr
))
1979 and then (Is_Class_Wide_Type
(Etype
(Expr
))
1980 or else Is_Dynamically_Tagged
(Expr
))
1981 and then Is_Tagged_Type
(Typ
)
1982 and then not Is_Class_Wide_Type
(Typ
)
1984 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
1986 end Check_Dynamically_Tagged_Expression
;
1988 --------------------------
1989 -- Check_Fully_Declared --
1990 --------------------------
1992 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
1994 if Ekind
(T
) = E_Incomplete_Type
then
1996 -- Ada 2005 (AI-50217): If the type is available through a limited
1997 -- with_clause, verify that its full view has been analyzed.
1999 if From_Limited_With
(T
)
2000 and then Present
(Non_Limited_View
(T
))
2001 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2003 -- The non-limited view is fully declared
2009 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2012 -- Need comments for these tests ???
2014 elsif Has_Private_Component
(T
)
2015 and then not Is_Generic_Type
(Root_Type
(T
))
2016 and then not In_Spec_Expression
2018 -- Special case: if T is the anonymous type created for a single
2019 -- task or protected object, use the name of the source object.
2021 if Is_Concurrent_Type
(T
)
2022 and then not Comes_From_Source
(T
)
2023 and then Nkind
(N
) = N_Object_Declaration
2026 ("type of& has incomplete component",
2027 N
, Defining_Identifier
(N
));
2030 ("premature usage of incomplete}",
2031 N
, First_Subtype
(T
));
2034 end Check_Fully_Declared
;
2036 -------------------------------------
2037 -- Check_Function_Writable_Actuals --
2038 -------------------------------------
2040 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2041 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2042 Identifiers_List
: Elist_Id
:= No_Elist
;
2043 Error_Node
: Node_Id
:= Empty
;
2045 procedure Collect_Identifiers
(N
: Node_Id
);
2046 -- In a single traversal of subtree N collect in Writable_Actuals_List
2047 -- all the actuals of functions with writable actuals, and in the list
2048 -- Identifiers_List collect all the identifiers that are not actuals of
2049 -- functions with writable actuals. If a writable actual is referenced
2050 -- twice as writable actual then Error_Node is set to reference its
2051 -- second occurrence, the error is reported, and the tree traversal
2054 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
2055 -- Return the entity associated with the function call
2057 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2058 -- Preanalyze N without reporting errors. Very dubious, you can't just
2059 -- go analyzing things more than once???
2061 -------------------------
2062 -- Collect_Identifiers --
2063 -------------------------
2065 procedure Collect_Identifiers
(N
: Node_Id
) is
2067 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2068 -- Process a single node during the tree traversal to collect the
2069 -- writable actuals of functions and all the identifiers which are
2070 -- not writable actuals of functions.
2072 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2073 -- Returns True if List has a node whose Entity is Entity (N)
2075 -------------------------
2076 -- Check_Function_Call --
2077 -------------------------
2079 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2080 Is_Writable_Actual
: Boolean := False;
2084 if Nkind
(N
) = N_Identifier
then
2086 -- No analysis possible if the entity is not decorated
2088 if No
(Entity
(N
)) then
2091 -- Don't collect identifiers of packages, called functions, etc
2093 elsif Ekind_In
(Entity
(N
), E_Package
,
2100 -- Analyze if N is a writable actual of a function
2102 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2104 Call
: constant Node_Id
:= Parent
(N
);
2109 Id
:= Get_Function_Id
(Call
);
2111 -- In case of previous error, no check is possible
2117 Formal
:= First_Formal
(Id
);
2118 Actual
:= First_Actual
(Call
);
2119 while Present
(Actual
) and then Present
(Formal
) loop
2121 if Ekind_In
(Formal
, E_Out_Parameter
,
2124 Is_Writable_Actual
:= True;
2130 Next_Formal
(Formal
);
2131 Next_Actual
(Actual
);
2136 if Is_Writable_Actual
then
2137 if Contains
(Writable_Actuals_List
, N
) then
2139 ("value may be affected by call to& "
2140 & "because order of evaluation is arbitrary", N
, Id
);
2145 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2148 if Identifiers_List
= No_Elist
then
2149 Identifiers_List
:= New_Elmt_List
;
2152 Append_Unique_Elmt
(N
, Identifiers_List
);
2165 N
: Node_Id
) return Boolean
2167 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2172 if List
= No_Elist
then
2176 Elmt
:= First_Elmt
(List
);
2177 while Present
(Elmt
) loop
2178 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2192 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2193 -- The traversal procedure
2195 -- Start of processing for Collect_Identifiers
2198 if Present
(Error_Node
) then
2202 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2207 end Collect_Identifiers
;
2209 ---------------------
2210 -- Get_Function_Id --
2211 ---------------------
2213 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
2214 Nam
: constant Node_Id
:= Name
(Call
);
2218 if Nkind
(Nam
) = N_Explicit_Dereference
then
2220 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
2222 elsif Nkind
(Nam
) = N_Selected_Component
then
2223 Id
:= Entity
(Selector_Name
(Nam
));
2225 elsif Nkind
(Nam
) = N_Indexed_Component
then
2226 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
2233 end Get_Function_Id
;
2235 ---------------------------
2236 -- Preanalyze_Expression --
2237 ---------------------------
2239 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2240 Status
: constant Boolean := Get_Ignore_Errors
;
2242 Set_Ignore_Errors
(True);
2244 Set_Ignore_Errors
(Status
);
2245 end Preanalyze_Without_Errors
;
2247 -- Start of processing for Check_Function_Writable_Actuals
2250 -- The check only applies to Ada 2012 code, and only to constructs that
2251 -- have multiple constituents whose order of evaluation is not specified
2254 if Ada_Version
< Ada_2012
2255 or else (not (Nkind
(N
) in N_Op
)
2256 and then not (Nkind
(N
) in N_Membership_Test
)
2257 and then not Nkind_In
(N
, N_Range
,
2259 N_Extension_Aggregate
,
2260 N_Full_Type_Declaration
,
2262 N_Procedure_Call_Statement
,
2263 N_Entry_Call_Statement
))
2264 or else (Nkind
(N
) = N_Full_Type_Declaration
2265 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2267 -- In addition, this check only applies to source code, not to code
2268 -- generated by constraint checks.
2270 or else not Comes_From_Source
(N
)
2275 -- If a construct C has two or more direct constituents that are names
2276 -- or expressions whose evaluation may occur in an arbitrary order, at
2277 -- least one of which contains a function call with an in out or out
2278 -- parameter, then the construct is legal only if: for each name N that
2279 -- is passed as a parameter of mode in out or out to some inner function
2280 -- call C2 (not including the construct C itself), there is no other
2281 -- name anywhere within a direct constituent of the construct C other
2282 -- than the one containing C2, that is known to refer to the same
2283 -- object (RM 6.4.1(6.17/3)).
2287 Collect_Identifiers
(Low_Bound
(N
));
2288 Collect_Identifiers
(High_Bound
(N
));
2290 when N_Op | N_Membership_Test
=>
2295 Collect_Identifiers
(Left_Opnd
(N
));
2297 if Present
(Right_Opnd
(N
)) then
2298 Collect_Identifiers
(Right_Opnd
(N
));
2301 if Nkind_In
(N
, N_In
, N_Not_In
)
2302 and then Present
(Alternatives
(N
))
2304 Expr
:= First
(Alternatives
(N
));
2305 while Present
(Expr
) loop
2306 Collect_Identifiers
(Expr
);
2313 when N_Full_Type_Declaration
=>
2315 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2316 -- Return the record part of this record type definition
2318 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2319 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2321 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2322 return Record_Extension_Part
(Type_Def
);
2326 end Get_Record_Part
;
2329 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2330 Rec
: Node_Id
:= Get_Record_Part
(N
);
2333 -- No need to perform any analysis if the record has no
2336 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2340 -- Collect the identifiers starting from the deepest
2341 -- derivation. Done to report the error in the deepest
2345 if Present
(Component_List
(Rec
)) then
2346 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2347 while Present
(Comp
) loop
2348 if Nkind
(Comp
) = N_Component_Declaration
2349 and then Present
(Expression
(Comp
))
2351 Collect_Identifiers
(Expression
(Comp
));
2358 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2359 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2362 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2363 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2367 when N_Subprogram_Call |
2368 N_Entry_Call_Statement
=>
2370 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
2375 Formal
:= First_Formal
(Id
);
2376 Actual
:= First_Actual
(N
);
2377 while Present
(Actual
) and then Present
(Formal
) loop
2378 if Ekind_In
(Formal
, E_Out_Parameter
,
2381 Collect_Identifiers
(Actual
);
2384 Next_Formal
(Formal
);
2385 Next_Actual
(Actual
);
2390 N_Extension_Aggregate
=>
2394 Comp_Expr
: Node_Id
;
2397 -- Handle the N_Others_Choice of array aggregates with static
2398 -- bounds. There is no need to perform this analysis in
2399 -- aggregates without static bounds since we cannot evaluate
2400 -- if the N_Others_Choice covers several elements. There is
2401 -- no need to handle the N_Others choice of record aggregates
2402 -- since at this stage it has been already expanded by
2403 -- Resolve_Record_Aggregate.
2405 if Is_Array_Type
(Etype
(N
))
2406 and then Nkind
(N
) = N_Aggregate
2407 and then Present
(Aggregate_Bounds
(N
))
2408 and then Compile_Time_Known_Bounds
(Etype
(N
))
2409 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2411 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2414 Count_Components
: Uint
:= Uint_0
;
2415 Num_Components
: Uint
;
2416 Others_Assoc
: Node_Id
;
2417 Others_Choice
: Node_Id
:= Empty
;
2418 Others_Box_Present
: Boolean := False;
2421 -- Count positional associations
2423 if Present
(Expressions
(N
)) then
2424 Comp_Expr
:= First
(Expressions
(N
));
2425 while Present
(Comp_Expr
) loop
2426 Count_Components
:= Count_Components
+ 1;
2431 -- Count the rest of elements and locate the N_Others
2434 Assoc
:= First
(Component_Associations
(N
));
2435 while Present
(Assoc
) loop
2436 Choice
:= First
(Choices
(Assoc
));
2437 while Present
(Choice
) loop
2438 if Nkind
(Choice
) = N_Others_Choice
then
2439 Others_Assoc
:= Assoc
;
2440 Others_Choice
:= Choice
;
2441 Others_Box_Present
:= Box_Present
(Assoc
);
2443 -- Count several components
2445 elsif Nkind_In
(Choice
, N_Range
,
2446 N_Subtype_Indication
)
2447 or else (Is_Entity_Name
(Choice
)
2448 and then Is_Type
(Entity
(Choice
)))
2453 Get_Index_Bounds
(Choice
, L
, H
);
2455 (Compile_Time_Known_Value
(L
)
2456 and then Compile_Time_Known_Value
(H
));
2459 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2462 -- Count single component. No other case available
2463 -- since we are handling an aggregate with static
2467 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2468 or else Nkind
(Choice
) = N_Identifier
2469 or else Nkind
(Choice
) = N_Integer_Literal
);
2471 Count_Components
:= Count_Components
+ 1;
2481 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2482 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2484 pragma Assert
(Count_Components
<= Num_Components
);
2486 -- Handle the N_Others choice if it covers several
2489 if Present
(Others_Choice
)
2490 and then (Num_Components
- Count_Components
) > 1
2492 if not Others_Box_Present
then
2494 -- At this stage, if expansion is active, the
2495 -- expression of the others choice has not been
2496 -- analyzed. Hence we generate a duplicate and
2497 -- we analyze it silently to have available the
2498 -- minimum decoration required to collect the
2501 if not Expander_Active
then
2502 Comp_Expr
:= Expression
(Others_Assoc
);
2505 New_Copy_Tree
(Expression
(Others_Assoc
));
2506 Preanalyze_Without_Errors
(Comp_Expr
);
2509 Collect_Identifiers
(Comp_Expr
);
2511 if Writable_Actuals_List
/= No_Elist
then
2513 -- As suggested by Robert, at current stage we
2514 -- report occurrences of this case as warnings.
2517 ("writable function parameter may affect "
2518 & "value in other component because order "
2519 & "of evaluation is unspecified??",
2520 Node
(First_Elmt
(Writable_Actuals_List
)));
2527 -- Handle ancestor part of extension aggregates
2529 if Nkind
(N
) = N_Extension_Aggregate
then
2530 Collect_Identifiers
(Ancestor_Part
(N
));
2533 -- Handle positional associations
2535 if Present
(Expressions
(N
)) then
2536 Comp_Expr
:= First
(Expressions
(N
));
2537 while Present
(Comp_Expr
) loop
2538 if not Is_OK_Static_Expression
(Comp_Expr
) then
2539 Collect_Identifiers
(Comp_Expr
);
2546 -- Handle discrete associations
2548 if Present
(Component_Associations
(N
)) then
2549 Assoc
:= First
(Component_Associations
(N
));
2550 while Present
(Assoc
) loop
2552 if not Box_Present
(Assoc
) then
2553 Choice
:= First
(Choices
(Assoc
));
2554 while Present
(Choice
) loop
2556 -- For now we skip discriminants since it requires
2557 -- performing the analysis in two phases: first one
2558 -- analyzing discriminants and second one analyzing
2559 -- the rest of components since discriminants are
2560 -- evaluated prior to components: too much extra
2561 -- work to detect a corner case???
2563 if Nkind
(Choice
) in N_Has_Entity
2564 and then Present
(Entity
(Choice
))
2565 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2569 elsif Box_Present
(Assoc
) then
2573 if not Analyzed
(Expression
(Assoc
)) then
2575 New_Copy_Tree
(Expression
(Assoc
));
2576 Set_Parent
(Comp_Expr
, Parent
(N
));
2577 Preanalyze_Without_Errors
(Comp_Expr
);
2579 Comp_Expr
:= Expression
(Assoc
);
2582 Collect_Identifiers
(Comp_Expr
);
2598 -- No further action needed if we already reported an error
2600 if Present
(Error_Node
) then
2604 -- Check if some writable argument of a function is referenced
2606 if Writable_Actuals_List
/= No_Elist
2607 and then Identifiers_List
/= No_Elist
2614 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2615 while Present
(Elmt_1
) loop
2616 Elmt_2
:= First_Elmt
(Identifiers_List
);
2617 while Present
(Elmt_2
) loop
2618 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2619 case Nkind
(Parent
(Node
(Elmt_2
))) is
2621 N_Component_Association |
2622 N_Component_Declaration
=>
2624 ("value may be affected by call in other "
2625 & "component because they are evaluated "
2626 & "in unspecified order",
2629 when N_In | N_Not_In
=>
2631 ("value may be affected by call in other "
2632 & "alternative because they are evaluated "
2633 & "in unspecified order",
2638 ("value of actual may be affected by call in "
2639 & "other actual because they are evaluated "
2640 & "in unspecified order",
2652 end Check_Function_Writable_Actuals
;
2654 --------------------------------
2655 -- Check_Implicit_Dereference --
2656 --------------------------------
2658 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
2664 if Nkind
(N
) = N_Indexed_Component
2665 and then Present
(Generalized_Indexing
(N
))
2667 Nam
:= Generalized_Indexing
(N
);
2672 if Ada_Version
< Ada_2012
2673 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2677 elsif not Comes_From_Source
(N
)
2678 and then Nkind
(N
) /= N_Indexed_Component
2682 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2686 Disc
:= First_Discriminant
(Typ
);
2687 while Present
(Disc
) loop
2688 if Has_Implicit_Dereference
(Disc
) then
2689 Desig
:= Designated_Type
(Etype
(Disc
));
2690 Add_One_Interp
(Nam
, Disc
, Desig
);
2692 -- If the node is a generalized indexing, add interpretation
2693 -- to that node as well, for subsequent resolution.
2695 if Nkind
(N
) = N_Indexed_Component
then
2696 Add_One_Interp
(N
, Disc
, Desig
);
2699 -- If the operation comes from a generic unit and the context
2700 -- is a selected component, the selector name may be global
2701 -- and set in the instance already. Remove the entity to
2702 -- force resolution of the selected component, and the
2703 -- generation of an explicit dereference if needed.
2706 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
2708 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
2714 Next_Discriminant
(Disc
);
2717 end Check_Implicit_Dereference
;
2719 ----------------------------------
2720 -- Check_Internal_Protected_Use --
2721 ----------------------------------
2723 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2729 while Present
(S
) loop
2730 if S
= Standard_Standard
then
2733 elsif Ekind
(S
) = E_Function
2734 and then Ekind
(Scope
(S
)) = E_Protected_Type
2743 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2745 -- An indirect function call (e.g. a callback within a protected
2746 -- function body) is not statically illegal. If the access type is
2747 -- anonymous and is the type of an access parameter, the scope of Nam
2748 -- will be the protected type, but it is not a protected operation.
2750 if Ekind
(Nam
) = E_Subprogram_Type
2752 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2756 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2758 ("within protected function cannot use protected "
2759 & "procedure in renaming or as generic actual", N
);
2761 elsif Nkind
(N
) = N_Attribute_Reference
then
2763 ("within protected function cannot take access of "
2764 & " protected procedure", N
);
2768 ("within protected function, protected object is constant", N
);
2770 ("\cannot call operation that may modify it", N
);
2773 end Check_Internal_Protected_Use
;
2775 ---------------------------------------
2776 -- Check_Later_Vs_Basic_Declarations --
2777 ---------------------------------------
2779 procedure Check_Later_Vs_Basic_Declarations
2781 During_Parsing
: Boolean)
2783 Body_Sloc
: Source_Ptr
;
2786 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2787 -- Return whether Decl is considered as a declarative item.
2788 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2789 -- When During_Parsing is False, the semantics of SPARK is followed.
2791 -------------------------------
2792 -- Is_Later_Declarative_Item --
2793 -------------------------------
2795 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2797 if Nkind
(Decl
) in N_Later_Decl_Item
then
2800 elsif Nkind
(Decl
) = N_Pragma
then
2803 elsif During_Parsing
then
2806 -- In SPARK, a package declaration is not considered as a later
2807 -- declarative item.
2809 elsif Nkind
(Decl
) = N_Package_Declaration
then
2812 -- In SPARK, a renaming is considered as a later declarative item
2814 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
2820 end Is_Later_Declarative_Item
;
2822 -- Start of Check_Later_Vs_Basic_Declarations
2825 Decl
:= First
(Decls
);
2827 -- Loop through sequence of basic declarative items
2829 Outer
: while Present
(Decl
) loop
2830 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
2831 and then Nkind
(Decl
) not in N_Body_Stub
2835 -- Once a body is encountered, we only allow later declarative
2836 -- items. The inner loop checks the rest of the list.
2839 Body_Sloc
:= Sloc
(Decl
);
2841 Inner
: while Present
(Decl
) loop
2842 if not Is_Later_Declarative_Item
(Decl
) then
2843 if During_Parsing
then
2844 if Ada_Version
= Ada_83
then
2845 Error_Msg_Sloc
:= Body_Sloc
;
2847 ("(Ada 83) decl cannot appear after body#", Decl
);
2850 Error_Msg_Sloc
:= Body_Sloc
;
2851 Check_SPARK_05_Restriction
2852 ("decl cannot appear after body#", Decl
);
2860 end Check_Later_Vs_Basic_Declarations
;
2862 -------------------------
2863 -- Check_Nested_Access --
2864 -------------------------
2866 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
2867 Scop
: constant Entity_Id
:= Current_Scope
;
2868 Current_Subp
: Entity_Id
;
2869 Enclosing
: Entity_Id
;
2872 -- Currently only enabled for VM back-ends for efficiency, should we
2873 -- enable it more systematically ???
2875 -- Check for Is_Imported needs commenting below ???
2877 if VM_Target
/= No_VM
2878 and then Ekind_In
(Ent
, E_Variable
, E_Constant
, E_Loop_Parameter
)
2879 and then Scope
(Ent
) /= Empty
2880 and then not Is_Library_Level_Entity
(Ent
)
2881 and then not Is_Imported
(Ent
)
2883 if Is_Subprogram
(Scop
)
2884 or else Is_Generic_Subprogram
(Scop
)
2885 or else Is_Entry
(Scop
)
2887 Current_Subp
:= Scop
;
2889 Current_Subp
:= Current_Subprogram
;
2892 Enclosing
:= Enclosing_Subprogram
(Ent
);
2894 if Enclosing
/= Empty
and then Enclosing
/= Current_Subp
then
2895 Set_Has_Up_Level_Access
(Ent
, True);
2898 end Check_Nested_Access
;
2900 ---------------------------
2901 -- Check_No_Hidden_State --
2902 ---------------------------
2904 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
2905 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
2906 -- Determine whether the entity of a package denoted by Pkg has a null
2909 -----------------------------
2910 -- Has_Null_Abstract_State --
2911 -----------------------------
2913 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
2914 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
2917 -- Check first available state of related package. A null abstract
2918 -- state always appears as the sole element of the state list.
2922 and then Is_Null_State
(Node
(First_Elmt
(States
)));
2923 end Has_Null_Abstract_State
;
2927 Context
: Entity_Id
:= Empty
;
2928 Not_Visible
: Boolean := False;
2931 -- Start of processing for Check_No_Hidden_State
2934 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
2936 -- Find the proper context where the object or state appears
2939 while Present
(Scop
) loop
2942 -- Keep track of the context's visibility
2944 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
2946 -- Prevent the search from going too far
2948 if Context
= Standard_Standard
then
2951 -- Objects and states that appear immediately within a subprogram or
2952 -- inside a construct nested within a subprogram do not introduce a
2953 -- hidden state. They behave as local variable declarations.
2955 elsif Is_Subprogram
(Context
) then
2958 -- When examining a package body, use the entity of the spec as it
2959 -- carries the abstract state declarations.
2961 elsif Ekind
(Context
) = E_Package_Body
then
2962 Context
:= Spec_Entity
(Context
);
2965 -- Stop the traversal when a package subject to a null abstract state
2968 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
2969 and then Has_Null_Abstract_State
(Context
)
2974 Scop
:= Scope
(Scop
);
2977 -- At this point we know that there is at least one package with a null
2978 -- abstract state in visibility. Emit an error message unconditionally
2979 -- if the entity being processed is a state because the placement of the
2980 -- related package is irrelevant. This is not the case for objects as
2981 -- the intermediate context matters.
2983 if Present
(Context
)
2984 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
2986 Error_Msg_N
("cannot introduce hidden state &", Id
);
2987 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
2989 end Check_No_Hidden_State
;
2991 ------------------------------------------
2992 -- Check_Potentially_Blocking_Operation --
2993 ------------------------------------------
2995 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
2999 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3000 -- When pragma Detect_Blocking is active, the run time will raise
3001 -- Program_Error. Here we only issue a warning, since we generally
3002 -- support the use of potentially blocking operations in the absence
3005 -- Indirect blocking through a subprogram call cannot be diagnosed
3006 -- statically without interprocedural analysis, so we do not attempt
3009 S
:= Scope
(Current_Scope
);
3010 while Present
(S
) and then S
/= Standard_Standard
loop
3011 if Is_Protected_Type
(S
) then
3013 ("potentially blocking operation in protected operation??", N
);
3019 end Check_Potentially_Blocking_Operation
;
3021 ---------------------------------
3022 -- Check_Result_And_Post_State --
3023 ---------------------------------
3025 procedure Check_Result_And_Post_State
(Subp_Id
: Entity_Id
) is
3026 procedure Check_Result_And_Post_State_In_Pragma
3028 Result_Seen
: in out Boolean);
3029 -- Determine whether pragma Prag mentions attribute 'Result and whether
3030 -- the pragma contains an expression that evaluates differently in pre-
3031 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3032 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3034 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean;
3035 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3036 -- formal parameter.
3038 -------------------------------------------
3039 -- Check_Result_And_Post_State_In_Pragma --
3040 -------------------------------------------
3042 procedure Check_Result_And_Post_State_In_Pragma
3044 Result_Seen
: in out Boolean)
3046 procedure Check_Expression
(Expr
: Node_Id
);
3047 -- Perform the 'Result and post-state checks on a given expression
3049 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
3050 -- Attempt to find attribute 'Result in a subtree denoted by N
3052 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
3053 -- Determine whether source node N denotes "True" or "False"
3055 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
3056 -- Determine whether a subtree denoted by N mentions any construct
3057 -- that denotes a post-state.
3059 procedure Check_Function_Result
is
3060 new Traverse_Proc
(Is_Function_Result
);
3062 ----------------------
3063 -- Check_Expression --
3064 ----------------------
3066 procedure Check_Expression
(Expr
: Node_Id
) is
3068 if not Is_Trivial_Boolean
(Expr
) then
3069 Check_Function_Result
(Expr
);
3071 if not Mentions_Post_State
(Expr
) then
3072 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3074 ("contract case does not check the outcome of calling "
3075 & "&?T?", Expr
, Subp_Id
);
3077 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3079 ("refined postcondition does not check the outcome of "
3080 & "calling &?T?", Prag
, Subp_Id
);
3084 ("postcondition does not check the outcome of calling "
3085 & "&?T?", Prag
, Subp_Id
);
3089 end Check_Expression
;
3091 ------------------------
3092 -- Is_Function_Result --
3093 ------------------------
3095 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3097 if Is_Attribute_Result
(N
) then
3098 Result_Seen
:= True;
3101 -- Continue the traversal
3106 end Is_Function_Result
;
3108 ------------------------
3109 -- Is_Trivial_Boolean --
3110 ------------------------
3112 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3115 Comes_From_Source
(N
)
3116 and then Is_Entity_Name
(N
)
3117 and then (Entity
(N
) = Standard_True
3119 Entity
(N
) = Standard_False
);
3120 end Is_Trivial_Boolean
;
3122 -------------------------
3123 -- Mentions_Post_State --
3124 -------------------------
3126 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3127 Post_State_Seen
: Boolean := False;
3129 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3130 -- Attempt to find a construct that denotes a post-state. If this
3131 -- is the case, set flag Post_State_Seen.
3137 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3141 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3142 Post_State_Seen
:= True;
3145 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3148 -- The entity may be modifiable through an implicit
3152 or else Ekind
(Ent
) in Assignable_Kind
3153 or else (Is_Access_Type
(Etype
(Ent
))
3154 and then Nkind
(Parent
(N
)) =
3155 N_Selected_Component
)
3157 Post_State_Seen
:= True;
3161 elsif Nkind
(N
) = N_Attribute_Reference
then
3162 if Attribute_Name
(N
) = Name_Old
then
3165 elsif Attribute_Name
(N
) = Name_Result
then
3166 Post_State_Seen
:= True;
3174 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3176 -- Start of processing for Mentions_Post_State
3179 Find_Post_State
(N
);
3181 return Post_State_Seen
;
3182 end Mentions_Post_State
;
3186 Expr
: constant Node_Id
:=
3188 (First
(Pragma_Argument_Associations
(Prag
)));
3189 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3192 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3195 -- Examine all consequences
3197 if Nam
= Name_Contract_Cases
then
3198 CCase
:= First
(Component_Associations
(Expr
));
3199 while Present
(CCase
) loop
3200 Check_Expression
(Expression
(CCase
));
3205 -- Examine the expression of a postcondition
3207 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
,
3208 Name_Refined_Post
));
3209 Check_Expression
(Expr
);
3211 end Check_Result_And_Post_State_In_Pragma
;
3213 --------------------------
3214 -- Has_In_Out_Parameter --
3215 --------------------------
3217 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean is
3221 -- Traverse the formals looking for an IN OUT parameter
3223 Formal
:= First_Formal
(Subp_Id
);
3224 while Present
(Formal
) loop
3225 if Ekind
(Formal
) = E_In_Out_Parameter
then
3229 Next_Formal
(Formal
);
3233 end Has_In_Out_Parameter
;
3237 Items
: constant Node_Id
:= Contract
(Subp_Id
);
3238 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
3239 Case_Prag
: Node_Id
:= Empty
;
3240 Post_Prag
: Node_Id
:= Empty
;
3242 Seen_In_Case
: Boolean := False;
3243 Seen_In_Post
: Boolean := False;
3244 Spec_Id
: Entity_Id
;
3246 -- Start of processing for Check_Result_And_Post_State
3249 -- The lack of attribute 'Result or a post-state is classified as a
3250 -- suspicious contract. Do not perform the check if the corresponding
3251 -- swich is not set.
3253 if not Warn_On_Suspicious_Contract
then
3256 -- Nothing to do if there is no contract
3258 elsif No
(Items
) then
3262 -- Retrieve the entity of the subprogram spec (if any)
3264 if Nkind
(Subp_Decl
) = N_Subprogram_Body
3265 and then Present
(Corresponding_Spec
(Subp_Decl
))
3267 Spec_Id
:= Corresponding_Spec
(Subp_Decl
);
3269 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
3270 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
3272 Spec_Id
:= Corresponding_Spec_Of_Stub
(Subp_Decl
);
3278 -- Examine all postconditions for attribute 'Result and a post-state
3280 Prag
:= Pre_Post_Conditions
(Items
);
3281 while Present
(Prag
) loop
3282 if Nam_In
(Pragma_Name
(Prag
), Name_Postcondition
,
3284 and then not Error_Posted
(Prag
)
3287 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Post
);
3290 Prag
:= Next_Pragma
(Prag
);
3293 -- Examine the contract cases of the subprogram for attribute 'Result
3294 -- and a post-state.
3296 Prag
:= Contract_Test_Cases
(Items
);
3297 while Present
(Prag
) loop
3298 if Pragma_Name
(Prag
) = Name_Contract_Cases
3299 and then not Error_Posted
(Prag
)
3302 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Case
);
3305 Prag
:= Next_Pragma
(Prag
);
3308 -- Do not emit any errors if the subprogram is not a function
3310 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
3313 -- Regardless of whether the function has postconditions or contract
3314 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3315 -- parameter is always treated as a result.
3317 elsif Has_In_Out_Parameter
(Spec_Id
) then
3320 -- The function has both a postcondition and contract cases and they do
3321 -- not mention attribute 'Result.
3323 elsif Present
(Case_Prag
)
3324 and then not Seen_In_Case
3325 and then Present
(Post_Prag
)
3326 and then not Seen_In_Post
3329 ("neither postcondition nor contract cases mention function "
3330 & "result?T?", Post_Prag
);
3332 -- The function has contract cases only and they do not mention
3333 -- attribute 'Result.
3335 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
3336 Error_Msg_N
("contract cases do not mention result?T?", Case_Prag
);
3338 -- The function has postconditions only and they do not mention
3339 -- attribute 'Result.
3341 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
3343 ("postcondition does not mention function result?T?", Post_Prag
);
3345 end Check_Result_And_Post_State
;
3347 ------------------------------
3348 -- Check_Unprotected_Access --
3349 ------------------------------
3351 procedure Check_Unprotected_Access
3355 Cont_Encl_Typ
: Entity_Id
;
3356 Pref_Encl_Typ
: Entity_Id
;
3358 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
3359 -- Check whether Obj is a private component of a protected object.
3360 -- Return the protected type where the component resides, Empty
3363 function Is_Public_Operation
return Boolean;
3364 -- Verify that the enclosing operation is callable from outside the
3365 -- protected object, to minimize false positives.
3367 ------------------------------
3368 -- Enclosing_Protected_Type --
3369 ------------------------------
3371 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
3373 if Is_Entity_Name
(Obj
) then
3375 Ent
: Entity_Id
:= Entity
(Obj
);
3378 -- The object can be a renaming of a private component, use
3379 -- the original record component.
3381 if Is_Prival
(Ent
) then
3382 Ent
:= Prival_Link
(Ent
);
3385 if Is_Protected_Type
(Scope
(Ent
)) then
3391 -- For indexed and selected components, recursively check the prefix
3393 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
3394 return Enclosing_Protected_Type
(Prefix
(Obj
));
3396 -- The object does not denote a protected component
3401 end Enclosing_Protected_Type
;
3403 -------------------------
3404 -- Is_Public_Operation --
3405 -------------------------
3407 function Is_Public_Operation
return Boolean is
3413 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
3414 if Scope
(S
) = Pref_Encl_Typ
then
3415 E
:= First_Entity
(Pref_Encl_Typ
);
3417 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
3431 end Is_Public_Operation
;
3433 -- Start of processing for Check_Unprotected_Access
3436 if Nkind
(Expr
) = N_Attribute_Reference
3437 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
3439 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
3440 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
3442 -- Check whether we are trying to export a protected component to a
3443 -- context with an equal or lower access level.
3445 if Present
(Pref_Encl_Typ
)
3446 and then No
(Cont_Encl_Typ
)
3447 and then Is_Public_Operation
3448 and then Scope_Depth
(Pref_Encl_Typ
) >=
3449 Object_Access_Level
(Context
)
3452 ("??possible unprotected access to protected data", Expr
);
3455 end Check_Unprotected_Access
;
3457 ------------------------
3458 -- Collect_Interfaces --
3459 ------------------------
3461 procedure Collect_Interfaces
3463 Ifaces_List
: out Elist_Id
;
3464 Exclude_Parents
: Boolean := False;
3465 Use_Full_View
: Boolean := True)
3467 procedure Collect
(Typ
: Entity_Id
);
3468 -- Subsidiary subprogram used to traverse the whole list
3469 -- of directly and indirectly implemented interfaces
3475 procedure Collect
(Typ
: Entity_Id
) is
3476 Ancestor
: Entity_Id
;
3484 -- Handle private types
3487 and then Is_Private_Type
(Typ
)
3488 and then Present
(Full_View
(Typ
))
3490 Full_T
:= Full_View
(Typ
);
3493 -- Include the ancestor if we are generating the whole list of
3494 -- abstract interfaces.
3496 if Etype
(Full_T
) /= Typ
3498 -- Protect the frontend against wrong sources. For example:
3501 -- type A is tagged null record;
3502 -- type B is new A with private;
3503 -- type C is new A with private;
3505 -- type B is new C with null record;
3506 -- type C is new B with null record;
3509 and then Etype
(Full_T
) /= T
3511 Ancestor
:= Etype
(Full_T
);
3514 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
3515 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
3519 -- Traverse the graph of ancestor interfaces
3521 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
3522 Id
:= First
(Abstract_Interface_List
(Full_T
));
3523 while Present
(Id
) loop
3524 Iface
:= Etype
(Id
);
3526 -- Protect against wrong uses. For example:
3527 -- type I is interface;
3528 -- type O is tagged null record;
3529 -- type Wrong is new I and O with null record; -- ERROR
3531 if Is_Interface
(Iface
) then
3533 and then Etype
(T
) /= T
3534 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
3539 Append_Unique_Elmt
(Iface
, Ifaces_List
);
3548 -- Start of processing for Collect_Interfaces
3551 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
3552 Ifaces_List
:= New_Elmt_List
;
3554 end Collect_Interfaces
;
3556 ----------------------------------
3557 -- Collect_Interface_Components --
3558 ----------------------------------
3560 procedure Collect_Interface_Components
3561 (Tagged_Type
: Entity_Id
;
3562 Components_List
: out Elist_Id
)
3564 procedure Collect
(Typ
: Entity_Id
);
3565 -- Subsidiary subprogram used to climb to the parents
3571 procedure Collect
(Typ
: Entity_Id
) is
3572 Tag_Comp
: Entity_Id
;
3573 Parent_Typ
: Entity_Id
;
3576 -- Handle private types
3578 if Present
(Full_View
(Etype
(Typ
))) then
3579 Parent_Typ
:= Full_View
(Etype
(Typ
));
3581 Parent_Typ
:= Etype
(Typ
);
3584 if Parent_Typ
/= Typ
3586 -- Protect the frontend against wrong sources. For example:
3589 -- type A is tagged null record;
3590 -- type B is new A with private;
3591 -- type C is new A with private;
3593 -- type B is new C with null record;
3594 -- type C is new B with null record;
3597 and then Parent_Typ
/= Tagged_Type
3599 Collect
(Parent_Typ
);
3602 -- Collect the components containing tags of secondary dispatch
3605 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
3606 while Present
(Tag_Comp
) loop
3607 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
3608 Append_Elmt
(Tag_Comp
, Components_List
);
3610 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
3614 -- Start of processing for Collect_Interface_Components
3617 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
3618 and then Is_Tagged_Type
(Tagged_Type
));
3620 Components_List
:= New_Elmt_List
;
3621 Collect
(Tagged_Type
);
3622 end Collect_Interface_Components
;
3624 -----------------------------
3625 -- Collect_Interfaces_Info --
3626 -----------------------------
3628 procedure Collect_Interfaces_Info
3630 Ifaces_List
: out Elist_Id
;
3631 Components_List
: out Elist_Id
;
3632 Tags_List
: out Elist_Id
)
3634 Comps_List
: Elist_Id
;
3635 Comp_Elmt
: Elmt_Id
;
3636 Comp_Iface
: Entity_Id
;
3637 Iface_Elmt
: Elmt_Id
;
3640 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3641 -- Search for the secondary tag associated with the interface type
3642 -- Iface that is implemented by T.
3648 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3651 if not Is_CPP_Class
(T
) then
3652 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3654 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3658 and then Is_Tag
(Node
(ADT
))
3659 and then Related_Type
(Node
(ADT
)) /= Iface
3661 -- Skip secondary dispatch table referencing thunks to user
3662 -- defined primitives covered by this interface.
3664 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3667 -- Skip secondary dispatch tables of Ada types
3669 if not Is_CPP_Class
(T
) then
3671 -- Skip secondary dispatch table referencing thunks to
3672 -- predefined primitives.
3674 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3677 -- Skip secondary dispatch table referencing user-defined
3678 -- primitives covered by this interface.
3680 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3683 -- Skip secondary dispatch table referencing predefined
3686 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3691 pragma Assert
(Is_Tag
(Node
(ADT
)));
3695 -- Start of processing for Collect_Interfaces_Info
3698 Collect_Interfaces
(T
, Ifaces_List
);
3699 Collect_Interface_Components
(T
, Comps_List
);
3701 -- Search for the record component and tag associated with each
3702 -- interface type of T.
3704 Components_List
:= New_Elmt_List
;
3705 Tags_List
:= New_Elmt_List
;
3707 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3708 while Present
(Iface_Elmt
) loop
3709 Iface
:= Node
(Iface_Elmt
);
3711 -- Associate the primary tag component and the primary dispatch table
3712 -- with all the interfaces that are parents of T
3714 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3715 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3716 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3718 -- Otherwise search for the tag component and secondary dispatch
3722 Comp_Elmt
:= First_Elmt
(Comps_List
);
3723 while Present
(Comp_Elmt
) loop
3724 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3726 if Comp_Iface
= Iface
3727 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3729 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3730 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3734 Next_Elmt
(Comp_Elmt
);
3736 pragma Assert
(Present
(Comp_Elmt
));
3739 Next_Elmt
(Iface_Elmt
);
3741 end Collect_Interfaces_Info
;
3743 ---------------------
3744 -- Collect_Parents --
3745 ---------------------
3747 procedure Collect_Parents
3749 List
: out Elist_Id
;
3750 Use_Full_View
: Boolean := True)
3752 Current_Typ
: Entity_Id
:= T
;
3753 Parent_Typ
: Entity_Id
;
3756 List
:= New_Elmt_List
;
3758 -- No action if the if the type has no parents
3760 if T
= Etype
(T
) then
3765 Parent_Typ
:= Etype
(Current_Typ
);
3767 if Is_Private_Type
(Parent_Typ
)
3768 and then Present
(Full_View
(Parent_Typ
))
3769 and then Use_Full_View
3771 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3774 Append_Elmt
(Parent_Typ
, List
);
3776 exit when Parent_Typ
= Current_Typ
;
3777 Current_Typ
:= Parent_Typ
;
3779 end Collect_Parents
;
3781 ----------------------------------
3782 -- Collect_Primitive_Operations --
3783 ----------------------------------
3785 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3786 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3787 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3788 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3792 Is_Type_In_Pkg
: Boolean;
3793 Formal_Derived
: Boolean := False;
3796 function Match
(E
: Entity_Id
) return Boolean;
3797 -- True if E's base type is B_Type, or E is of an anonymous access type
3798 -- and the base type of its designated type is B_Type.
3804 function Match
(E
: Entity_Id
) return Boolean is
3805 Etyp
: Entity_Id
:= Etype
(E
);
3808 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
3809 Etyp
:= Designated_Type
(Etyp
);
3812 -- In Ada 2012 a primitive operation may have a formal of an
3813 -- incomplete view of the parent type.
3815 return Base_Type
(Etyp
) = B_Type
3817 (Ada_Version
>= Ada_2012
3818 and then Ekind
(Etyp
) = E_Incomplete_Type
3819 and then Full_View
(Etyp
) = B_Type
);
3822 -- Start of processing for Collect_Primitive_Operations
3825 -- For tagged types, the primitive operations are collected as they
3826 -- are declared, and held in an explicit list which is simply returned.
3828 if Is_Tagged_Type
(B_Type
) then
3829 return Primitive_Operations
(B_Type
);
3831 -- An untagged generic type that is a derived type inherits the
3832 -- primitive operations of its parent type. Other formal types only
3833 -- have predefined operators, which are not explicitly represented.
3835 elsif Is_Generic_Type
(B_Type
) then
3836 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
3837 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
3838 N_Formal_Derived_Type_Definition
3840 Formal_Derived
:= True;
3842 return New_Elmt_List
;
3846 Op_List
:= New_Elmt_List
;
3848 if B_Scope
= Standard_Standard
then
3849 if B_Type
= Standard_String
then
3850 Append_Elmt
(Standard_Op_Concat
, Op_List
);
3852 elsif B_Type
= Standard_Wide_String
then
3853 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
3859 -- Locate the primitive subprograms of the type
3862 -- The primitive operations appear after the base type, except
3863 -- if the derivation happens within the private part of B_Scope
3864 -- and the type is a private type, in which case both the type
3865 -- and some primitive operations may appear before the base
3866 -- type, and the list of candidates starts after the type.
3868 if In_Open_Scopes
(B_Scope
)
3869 and then Scope
(T
) = B_Scope
3870 and then In_Private_Part
(B_Scope
)
3872 Id
:= Next_Entity
(T
);
3874 -- In Ada 2012, If the type has an incomplete partial view, there
3875 -- may be primitive operations declared before the full view, so
3876 -- we need to start scanning from the incomplete view, which is
3877 -- earlier on the entity chain.
3879 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
3880 and then Present
(Incomplete_View
(Parent
(B_Type
)))
3882 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
3885 Id
:= Next_Entity
(B_Type
);
3888 -- Set flag if this is a type in a package spec
3891 Is_Package_Or_Generic_Package
(B_Scope
)
3893 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
3896 while Present
(Id
) loop
3898 -- Test whether the result type or any of the parameter types of
3899 -- each subprogram following the type match that type when the
3900 -- type is declared in a package spec, is a derived type, or the
3901 -- subprogram is marked as primitive. (The Is_Primitive test is
3902 -- needed to find primitives of nonderived types in declarative
3903 -- parts that happen to override the predefined "=" operator.)
3905 -- Note that generic formal subprograms are not considered to be
3906 -- primitive operations and thus are never inherited.
3908 if Is_Overloadable
(Id
)
3909 and then (Is_Type_In_Pkg
3910 or else Is_Derived_Type
(B_Type
)
3911 or else Is_Primitive
(Id
))
3912 and then Nkind
(Parent
(Parent
(Id
)))
3913 not in N_Formal_Subprogram_Declaration
3921 Formal
:= First_Formal
(Id
);
3922 while Present
(Formal
) loop
3923 if Match
(Formal
) then
3928 Next_Formal
(Formal
);
3932 -- For a formal derived type, the only primitives are the ones
3933 -- inherited from the parent type. Operations appearing in the
3934 -- package declaration are not primitive for it.
3937 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
3939 -- In the special case of an equality operator aliased to
3940 -- an overriding dispatching equality belonging to the same
3941 -- type, we don't include it in the list of primitives.
3942 -- This avoids inheriting multiple equality operators when
3943 -- deriving from untagged private types whose full type is
3944 -- tagged, which can otherwise cause ambiguities. Note that
3945 -- this should only happen for this kind of untagged parent
3946 -- type, since normally dispatching operations are inherited
3947 -- using the type's Primitive_Operations list.
3949 if Chars
(Id
) = Name_Op_Eq
3950 and then Is_Dispatching_Operation
(Id
)
3951 and then Present
(Alias
(Id
))
3952 and then Present
(Overridden_Operation
(Alias
(Id
)))
3953 and then Base_Type
(Etype
(First_Entity
(Id
))) =
3954 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
3958 -- Include the subprogram in the list of primitives
3961 Append_Elmt
(Id
, Op_List
);
3968 -- For a type declared in System, some of its operations may
3969 -- appear in the target-specific extension to System.
3972 and then B_Scope
= RTU_Entity
(System
)
3973 and then Present_System_Aux
3975 B_Scope
:= System_Aux_Id
;
3976 Id
:= First_Entity
(System_Aux_Id
);
3982 end Collect_Primitive_Operations
;
3984 -----------------------------------
3985 -- Compile_Time_Constraint_Error --
3986 -----------------------------------
3988 function Compile_Time_Constraint_Error
3991 Ent
: Entity_Id
:= Empty
;
3992 Loc
: Source_Ptr
:= No_Location
;
3993 Warn
: Boolean := False) return Node_Id
3995 Msgc
: String (1 .. Msg
'Length + 3);
3996 -- Copy of message, with room for possible ?? or << and ! at end
4002 -- Start of processing for Compile_Time_Constraint_Error
4005 -- If this is a warning, convert it into an error if we are in code
4006 -- subject to SPARK_Mode being set ON.
4008 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4010 -- A static constraint error in an instance body is not a fatal error.
4011 -- we choose to inhibit the message altogether, because there is no
4012 -- obvious node (for now) on which to post it. On the other hand the
4013 -- offending node must be replaced with a constraint_error in any case.
4015 -- No messages are generated if we already posted an error on this node
4017 if not Error_Posted
(N
) then
4018 if Loc
/= No_Location
then
4024 -- Copy message to Msgc, converting any ? in the message into
4025 -- < instead, so that we have an error in GNATprove mode.
4029 for J
in 1 .. Msgl
loop
4030 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
4033 Msgc
(J
) := Msg
(J
);
4037 -- Message is a warning, even in Ada 95 case
4039 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
4042 -- In Ada 83, all messages are warnings. In the private part and
4043 -- the body of an instance, constraint_checks are only warnings.
4044 -- We also make this a warning if the Warn parameter is set.
4047 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
4055 elsif In_Instance_Not_Visible
then
4062 -- Otherwise we have a real error message (Ada 95 static case)
4063 -- and we make this an unconditional message. Note that in the
4064 -- warning case we do not make the message unconditional, it seems
4065 -- quite reasonable to delete messages like this (about exceptions
4066 -- that will be raised) in dead code.
4074 -- One more test, skip the warning if the related expression is
4075 -- statically unevaluated, since we don't want to warn about what
4076 -- will happen when something is evaluated if it never will be
4079 if not Is_Statically_Unevaluated
(N
) then
4080 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4082 if Present
(Ent
) then
4083 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
4085 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
4090 -- Check whether the context is an Init_Proc
4092 if Inside_Init_Proc
then
4094 Conc_Typ
: constant Entity_Id
:=
4095 Corresponding_Concurrent_Type
4096 (Entity
(Parameter_Type
(First
4097 (Parameter_Specifications
4098 (Parent
(Current_Scope
))))));
4101 -- Don't complain if the corresponding concurrent type
4102 -- doesn't come from source (i.e. a single task/protected
4105 if Present
(Conc_Typ
)
4106 and then not Comes_From_Source
(Conc_Typ
)
4109 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4112 if GNATprove_Mode
then
4114 ("\& would have been raised for objects of this "
4115 & "type", N
, Standard_Constraint_Error
, Eloc
);
4118 ("\& will be raised for objects of this type??",
4119 N
, Standard_Constraint_Error
, Eloc
);
4125 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4129 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
4130 Set_Error_Posted
(N
);
4136 end Compile_Time_Constraint_Error
;
4138 -----------------------
4139 -- Conditional_Delay --
4140 -----------------------
4142 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
4144 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
4145 Set_Has_Delayed_Freeze
(New_Ent
);
4147 end Conditional_Delay
;
4149 ----------------------------
4150 -- Contains_Refined_State --
4151 ----------------------------
4153 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
4154 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
4155 -- Determine whether a dependency list mentions a state with a visible
4158 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
4159 -- Determine whether a global list mentions a state with a visible
4162 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
4163 -- Determine whether Item is a reference to an abstract state with a
4164 -- visible refinement.
4166 -----------------------------
4167 -- Has_State_In_Dependency --
4168 -----------------------------
4170 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
4175 -- A null dependency list does not mention any states
4177 if Nkind
(List
) = N_Null
then
4180 -- Dependency clauses appear as component associations of an
4183 elsif Nkind
(List
) = N_Aggregate
4184 and then Present
(Component_Associations
(List
))
4186 Clause
:= First
(Component_Associations
(List
));
4187 while Present
(Clause
) loop
4189 -- Inspect the outputs of a dependency clause
4191 Output
:= First
(Choices
(Clause
));
4192 while Present
(Output
) loop
4193 if Is_Refined_State
(Output
) then
4200 -- Inspect the outputs of a dependency clause
4202 if Is_Refined_State
(Expression
(Clause
)) then
4209 -- If we get here, then none of the dependency clauses mention a
4210 -- state with visible refinement.
4214 -- An illegal pragma managed to sneak in
4217 raise Program_Error
;
4219 end Has_State_In_Dependency
;
4221 -------------------------
4222 -- Has_State_In_Global --
4223 -------------------------
4225 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
4229 -- A null global list does not mention any states
4231 if Nkind
(List
) = N_Null
then
4234 -- Simple global list or moded global list declaration
4236 elsif Nkind
(List
) = N_Aggregate
then
4238 -- The declaration of a simple global list appear as a collection
4241 if Present
(Expressions
(List
)) then
4242 Item
:= First
(Expressions
(List
));
4243 while Present
(Item
) loop
4244 if Is_Refined_State
(Item
) then
4251 -- The declaration of a moded global list appears as a collection
4252 -- of component associations where individual choices denote
4256 Item
:= First
(Component_Associations
(List
));
4257 while Present
(Item
) loop
4258 if Has_State_In_Global
(Expression
(Item
)) then
4266 -- If we get here, then the simple/moded global list did not
4267 -- mention any states with a visible refinement.
4271 -- Single global item declaration
4273 elsif Is_Entity_Name
(List
) then
4274 return Is_Refined_State
(List
);
4276 -- An illegal pragma managed to sneak in
4279 raise Program_Error
;
4281 end Has_State_In_Global
;
4283 ----------------------
4284 -- Is_Refined_State --
4285 ----------------------
4287 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
4289 Item_Id
: Entity_Id
;
4292 if Nkind
(Item
) = N_Null
then
4295 -- States cannot be subject to attribute 'Result. This case arises
4296 -- in dependency relations.
4298 elsif Nkind
(Item
) = N_Attribute_Reference
4299 and then Attribute_Name
(Item
) = Name_Result
4303 -- Multiple items appear as an aggregate. This case arises in
4304 -- dependency relations.
4306 elsif Nkind
(Item
) = N_Aggregate
4307 and then Present
(Expressions
(Item
))
4309 Elmt
:= First
(Expressions
(Item
));
4310 while Present
(Elmt
) loop
4311 if Is_Refined_State
(Elmt
) then
4318 -- If we get here, then none of the inputs or outputs reference a
4319 -- state with visible refinement.
4326 Item_Id
:= Entity_Of
(Item
);
4330 and then Ekind
(Item_Id
) = E_Abstract_State
4331 and then Has_Visible_Refinement
(Item_Id
);
4333 end Is_Refined_State
;
4337 Arg
: constant Node_Id
:=
4338 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
4339 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4341 -- Start of processing for Contains_Refined_State
4344 if Nam
= Name_Depends
then
4345 return Has_State_In_Dependency
(Arg
);
4347 else pragma Assert
(Nam
= Name_Global
);
4348 return Has_State_In_Global
(Arg
);
4350 end Contains_Refined_State
;
4352 -------------------------
4353 -- Copy_Component_List --
4354 -------------------------
4356 function Copy_Component_List
4358 Loc
: Source_Ptr
) return List_Id
4361 Comps
: constant List_Id
:= New_List
;
4364 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
4365 while Present
(Comp
) loop
4366 if Comes_From_Source
(Comp
) then
4368 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
4371 Make_Component_Declaration
(Loc
,
4372 Defining_Identifier
=>
4373 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
4374 Component_Definition
=>
4376 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
4380 Next_Component
(Comp
);
4384 end Copy_Component_List
;
4386 -------------------------
4387 -- Copy_Parameter_List --
4388 -------------------------
4390 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
4391 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
4396 if No
(First_Formal
(Subp_Id
)) then
4400 Formal
:= First_Formal
(Subp_Id
);
4401 while Present
(Formal
) loop
4403 (Make_Parameter_Specification
(Loc
,
4404 Defining_Identifier
=>
4405 Make_Defining_Identifier
(Sloc
(Formal
),
4406 Chars
=> Chars
(Formal
)),
4407 In_Present
=> In_Present
(Parent
(Formal
)),
4408 Out_Present
=> Out_Present
(Parent
(Formal
)),
4410 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4412 New_Copy_Tree
(Expression
(Parent
(Formal
)))),
4415 Next_Formal
(Formal
);
4420 end Copy_Parameter_List
;
4422 --------------------------------
4423 -- Corresponding_Generic_Type --
4424 --------------------------------
4426 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
4432 if not Is_Generic_Actual_Type
(T
) then
4435 -- If the actual is the actual of an enclosing instance, resolution
4436 -- was correct in the generic.
4438 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
4439 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
4441 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
4448 if Is_Wrapper_Package
(Inst
) then
4449 Inst
:= Related_Instance
(Inst
);
4454 (Specification
(Unit_Declaration_Node
(Inst
)));
4456 -- Generic actual has the same name as the corresponding formal
4458 Typ
:= First_Entity
(Gen
);
4459 while Present
(Typ
) loop
4460 if Chars
(Typ
) = Chars
(T
) then
4469 end Corresponding_Generic_Type
;
4471 ---------------------------
4472 -- Corresponding_Spec_Of --
4473 ---------------------------
4475 function Corresponding_Spec_Of
(Subp_Decl
: Node_Id
) return Entity_Id
is
4477 if Nkind
(Subp_Decl
) = N_Subprogram_Body
4478 and then Present
(Corresponding_Spec
(Subp_Decl
))
4480 return Corresponding_Spec
(Subp_Decl
);
4482 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
4483 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
4485 return Corresponding_Spec_Of_Stub
(Subp_Decl
);
4488 return Defining_Entity
(Subp_Decl
);
4490 end Corresponding_Spec_Of
;
4492 --------------------
4493 -- Current_Entity --
4494 --------------------
4496 -- The currently visible definition for a given identifier is the
4497 -- one most chained at the start of the visibility chain, i.e. the
4498 -- one that is referenced by the Node_Id value of the name of the
4499 -- given identifier.
4501 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
4503 return Get_Name_Entity_Id
(Chars
(N
));
4506 -----------------------------
4507 -- Current_Entity_In_Scope --
4508 -----------------------------
4510 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
4512 CS
: constant Entity_Id
:= Current_Scope
;
4514 Transient_Case
: constant Boolean := Scope_Is_Transient
;
4517 E
:= Get_Name_Entity_Id
(Chars
(N
));
4519 and then Scope
(E
) /= CS
4520 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
4526 end Current_Entity_In_Scope
;
4532 function Current_Scope
return Entity_Id
is
4534 if Scope_Stack
.Last
= -1 then
4535 return Standard_Standard
;
4538 C
: constant Entity_Id
:=
4539 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
4544 return Standard_Standard
;
4550 ------------------------
4551 -- Current_Subprogram --
4552 ------------------------
4554 function Current_Subprogram
return Entity_Id
is
4555 Scop
: constant Entity_Id
:= Current_Scope
;
4557 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
4560 return Enclosing_Subprogram
(Scop
);
4562 end Current_Subprogram
;
4564 ----------------------------------
4565 -- Deepest_Type_Access_Level --
4566 ----------------------------------
4568 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
4570 if Ekind
(Typ
) = E_Anonymous_Access_Type
4571 and then not Is_Local_Anonymous_Access
(Typ
)
4572 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
4574 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4578 Scope_Depth
(Enclosing_Dynamic_Scope
4579 (Defining_Identifier
4580 (Associated_Node_For_Itype
(Typ
))));
4582 -- For generic formal type, return Int'Last (infinite).
4583 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4585 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
4586 return UI_From_Int
(Int
'Last);
4589 return Type_Access_Level
(Typ
);
4591 end Deepest_Type_Access_Level
;
4593 ---------------------
4594 -- Defining_Entity --
4595 ---------------------
4597 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4598 K
: constant Node_Kind
:= Nkind
(N
);
4599 Err
: Entity_Id
:= Empty
;
4604 N_Subprogram_Declaration |
4605 N_Abstract_Subprogram_Declaration |
4607 N_Package_Declaration |
4608 N_Subprogram_Renaming_Declaration |
4609 N_Subprogram_Body_Stub |
4610 N_Generic_Subprogram_Declaration |
4611 N_Generic_Package_Declaration |
4612 N_Formal_Subprogram_Declaration |
4613 N_Expression_Function
4615 return Defining_Entity
(Specification
(N
));
4618 N_Component_Declaration |
4619 N_Defining_Program_Unit_Name |
4620 N_Discriminant_Specification |
4622 N_Entry_Declaration |
4623 N_Entry_Index_Specification |
4624 N_Exception_Declaration |
4625 N_Exception_Renaming_Declaration |
4626 N_Formal_Object_Declaration |
4627 N_Formal_Package_Declaration |
4628 N_Formal_Type_Declaration |
4629 N_Full_Type_Declaration |
4630 N_Implicit_Label_Declaration |
4631 N_Incomplete_Type_Declaration |
4632 N_Loop_Parameter_Specification |
4633 N_Number_Declaration |
4634 N_Object_Declaration |
4635 N_Object_Renaming_Declaration |
4636 N_Package_Body_Stub |
4637 N_Parameter_Specification |
4638 N_Private_Extension_Declaration |
4639 N_Private_Type_Declaration |
4641 N_Protected_Body_Stub |
4642 N_Protected_Type_Declaration |
4643 N_Single_Protected_Declaration |
4644 N_Single_Task_Declaration |
4645 N_Subtype_Declaration |
4648 N_Task_Type_Declaration
4650 return Defining_Identifier
(N
);
4653 return Defining_Entity
(Proper_Body
(N
));
4656 N_Function_Instantiation |
4657 N_Function_Specification |
4658 N_Generic_Function_Renaming_Declaration |
4659 N_Generic_Package_Renaming_Declaration |
4660 N_Generic_Procedure_Renaming_Declaration |
4662 N_Package_Instantiation |
4663 N_Package_Renaming_Declaration |
4664 N_Package_Specification |
4665 N_Procedure_Instantiation |
4666 N_Procedure_Specification
4669 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
4672 if Nkind
(Nam
) in N_Entity
then
4675 -- For Error, make up a name and attach to declaration
4676 -- so we can continue semantic analysis
4678 elsif Nam
= Error
then
4679 Err
:= Make_Temporary
(Sloc
(N
), 'T');
4680 Set_Defining_Unit_Name
(N
, Err
);
4684 -- If not an entity, get defining identifier
4687 return Defining_Identifier
(Nam
);
4695 return Entity
(Identifier
(N
));
4698 raise Program_Error
;
4701 end Defining_Entity
;
4703 --------------------------
4704 -- Denotes_Discriminant --
4705 --------------------------
4707 function Denotes_Discriminant
4709 Check_Concurrent
: Boolean := False) return Boolean
4714 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
4720 -- If we are checking for a protected type, the discriminant may have
4721 -- been rewritten as the corresponding discriminal of the original type
4722 -- or of the corresponding concurrent record, depending on whether we
4723 -- are in the spec or body of the protected type.
4725 return Ekind
(E
) = E_Discriminant
4728 and then Ekind
(E
) = E_In_Parameter
4729 and then Present
(Discriminal_Link
(E
))
4731 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
4733 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
4735 end Denotes_Discriminant
;
4737 -------------------------
4738 -- Denotes_Same_Object --
4739 -------------------------
4741 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
4742 Obj1
: Node_Id
:= A1
;
4743 Obj2
: Node_Id
:= A2
;
4745 function Has_Prefix
(N
: Node_Id
) return Boolean;
4746 -- Return True if N has attribute Prefix
4748 function Is_Renaming
(N
: Node_Id
) return Boolean;
4749 -- Return true if N names a renaming entity
4751 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
4752 -- For renamings, return False if the prefix of any dereference within
4753 -- the renamed object_name is a variable, or any expression within the
4754 -- renamed object_name contains references to variables or calls on
4755 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
4761 function Has_Prefix
(N
: Node_Id
) return Boolean is
4765 N_Attribute_Reference
,
4767 N_Explicit_Dereference
,
4768 N_Indexed_Component
,
4770 N_Selected_Component
,
4778 function Is_Renaming
(N
: Node_Id
) return Boolean is
4780 return Is_Entity_Name
(N
)
4781 and then Present
(Renamed_Entity
(Entity
(N
)));
4784 -----------------------
4785 -- Is_Valid_Renaming --
4786 -----------------------
4788 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
4790 function Check_Renaming
(N
: Node_Id
) return Boolean;
4791 -- Recursive function used to traverse all the prefixes of N
4793 function Check_Renaming
(N
: Node_Id
) return Boolean is
4796 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
4801 if Nkind
(N
) = N_Indexed_Component
then
4806 Indx
:= First
(Expressions
(N
));
4807 while Present
(Indx
) loop
4808 if not Is_OK_Static_Expression
(Indx
) then
4817 if Has_Prefix
(N
) then
4819 P
: constant Node_Id
:= Prefix
(N
);
4822 if Nkind
(N
) = N_Explicit_Dereference
4823 and then Is_Variable
(P
)
4827 elsif Is_Entity_Name
(P
)
4828 and then Ekind
(Entity
(P
)) = E_Function
4832 elsif Nkind
(P
) = N_Function_Call
then
4836 -- Recursion to continue traversing the prefix of the
4837 -- renaming expression
4839 return Check_Renaming
(P
);
4846 -- Start of processing for Is_Valid_Renaming
4849 return Check_Renaming
(N
);
4850 end Is_Valid_Renaming
;
4852 -- Start of processing for Denotes_Same_Object
4855 -- Both names statically denote the same stand-alone object or parameter
4856 -- (RM 6.4.1(6.5/3))
4858 if Is_Entity_Name
(Obj1
)
4859 and then Is_Entity_Name
(Obj2
)
4860 and then Entity
(Obj1
) = Entity
(Obj2
)
4865 -- For renamings, the prefix of any dereference within the renamed
4866 -- object_name is not a variable, and any expression within the
4867 -- renamed object_name contains no references to variables nor
4868 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
4870 if Is_Renaming
(Obj1
) then
4871 if Is_Valid_Renaming
(Obj1
) then
4872 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
4878 if Is_Renaming
(Obj2
) then
4879 if Is_Valid_Renaming
(Obj2
) then
4880 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
4886 -- No match if not same node kind (such cases are handled by
4887 -- Denotes_Same_Prefix)
4889 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
4892 -- After handling valid renamings, one of the two names statically
4893 -- denoted a renaming declaration whose renamed object_name is known
4894 -- to denote the same object as the other (RM 6.4.1(6.10/3))
4896 elsif Is_Entity_Name
(Obj1
) then
4897 if Is_Entity_Name
(Obj2
) then
4898 return Entity
(Obj1
) = Entity
(Obj2
);
4903 -- Both names are selected_components, their prefixes are known to
4904 -- denote the same object, and their selector_names denote the same
4905 -- component (RM 6.4.1(6.6/3)
4907 elsif Nkind
(Obj1
) = N_Selected_Component
then
4908 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4910 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
4912 -- Both names are dereferences and the dereferenced names are known to
4913 -- denote the same object (RM 6.4.1(6.7/3))
4915 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
4916 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
4918 -- Both names are indexed_components, their prefixes are known to denote
4919 -- the same object, and each of the pairs of corresponding index values
4920 -- are either both static expressions with the same static value or both
4921 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
4923 elsif Nkind
(Obj1
) = N_Indexed_Component
then
4924 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
4932 Indx1
:= First
(Expressions
(Obj1
));
4933 Indx2
:= First
(Expressions
(Obj2
));
4934 while Present
(Indx1
) loop
4936 -- Indexes must denote the same static value or same object
4938 if Is_OK_Static_Expression
(Indx1
) then
4939 if not Is_OK_Static_Expression
(Indx2
) then
4942 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
4946 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
4958 -- Both names are slices, their prefixes are known to denote the same
4959 -- object, and the two slices have statically matching index constraints
4960 -- (RM 6.4.1(6.9/3))
4962 elsif Nkind
(Obj1
) = N_Slice
4963 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
4966 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
4969 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
4970 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
4972 -- Check whether bounds are statically identical. There is no
4973 -- attempt to detect partial overlap of slices.
4975 return Denotes_Same_Object
(Lo1
, Lo2
)
4977 Denotes_Same_Object
(Hi1
, Hi2
);
4980 -- In the recursion, literals appear as indexes
4982 elsif Nkind
(Obj1
) = N_Integer_Literal
4984 Nkind
(Obj2
) = N_Integer_Literal
4986 return Intval
(Obj1
) = Intval
(Obj2
);
4991 end Denotes_Same_Object
;
4993 -------------------------
4994 -- Denotes_Same_Prefix --
4995 -------------------------
4997 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
5000 if Is_Entity_Name
(A1
) then
5001 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
5002 and then not Is_Access_Type
(Etype
(A1
))
5004 return Denotes_Same_Object
(A1
, Prefix
(A2
))
5005 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
5010 elsif Is_Entity_Name
(A2
) then
5011 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
5013 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5015 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5018 Root1
, Root2
: Node_Id
;
5019 Depth1
, Depth2
: Int
:= 0;
5022 Root1
:= Prefix
(A1
);
5023 while not Is_Entity_Name
(Root1
) loop
5025 (Root1
, N_Selected_Component
, N_Indexed_Component
)
5029 Root1
:= Prefix
(Root1
);
5032 Depth1
:= Depth1
+ 1;
5035 Root2
:= Prefix
(A2
);
5036 while not Is_Entity_Name
(Root2
) loop
5037 if not Nkind_In
(Root2
, N_Selected_Component
,
5038 N_Indexed_Component
)
5042 Root2
:= Prefix
(Root2
);
5045 Depth2
:= Depth2
+ 1;
5048 -- If both have the same depth and they do not denote the same
5049 -- object, they are disjoint and no warning is needed.
5051 if Depth1
= Depth2
then
5054 elsif Depth1
> Depth2
then
5055 Root1
:= Prefix
(A1
);
5056 for J
in 1 .. Depth1
- Depth2
- 1 loop
5057 Root1
:= Prefix
(Root1
);
5060 return Denotes_Same_Object
(Root1
, A2
);
5063 Root2
:= Prefix
(A2
);
5064 for J
in 1 .. Depth2
- Depth1
- 1 loop
5065 Root2
:= Prefix
(Root2
);
5068 return Denotes_Same_Object
(A1
, Root2
);
5075 end Denotes_Same_Prefix
;
5077 ----------------------
5078 -- Denotes_Variable --
5079 ----------------------
5081 function Denotes_Variable
(N
: Node_Id
) return Boolean is
5083 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
5084 end Denotes_Variable
;
5086 -----------------------------
5087 -- Depends_On_Discriminant --
5088 -----------------------------
5090 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
5095 Get_Index_Bounds
(N
, L
, H
);
5096 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
5097 end Depends_On_Discriminant
;
5099 -------------------------
5100 -- Designate_Same_Unit --
5101 -------------------------
5103 function Designate_Same_Unit
5105 Name2
: Node_Id
) return Boolean
5107 K1
: constant Node_Kind
:= Nkind
(Name1
);
5108 K2
: constant Node_Kind
:= Nkind
(Name2
);
5110 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
5111 -- Returns the parent unit name node of a defining program unit name
5112 -- or the prefix if N is a selected component or an expanded name.
5114 function Select_Node
(N
: Node_Id
) return Node_Id
;
5115 -- Returns the defining identifier node of a defining program unit
5116 -- name or the selector node if N is a selected component or an
5123 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
5125 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
5136 function Select_Node
(N
: Node_Id
) return Node_Id
is
5138 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
5139 return Defining_Identifier
(N
);
5141 return Selector_Name
(N
);
5145 -- Start of processing for Designate_Same_Unit
5148 if Nkind_In
(K1
, N_Identifier
, N_Defining_Identifier
)
5150 Nkind_In
(K2
, N_Identifier
, N_Defining_Identifier
)
5152 return Chars
(Name1
) = Chars
(Name2
);
5154 elsif Nkind_In
(K1
, N_Expanded_Name
,
5155 N_Selected_Component
,
5156 N_Defining_Program_Unit_Name
)
5158 Nkind_In
(K2
, N_Expanded_Name
,
5159 N_Selected_Component
,
5160 N_Defining_Program_Unit_Name
)
5163 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
5165 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
5170 end Designate_Same_Unit
;
5172 ------------------------------------------
5173 -- function Dynamic_Accessibility_Level --
5174 ------------------------------------------
5176 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
5178 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5180 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
5181 -- Construct an integer literal representing an accessibility level
5182 -- with its type set to Natural.
5184 ------------------------
5185 -- Make_Level_Literal --
5186 ------------------------
5188 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
5189 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
5191 Set_Etype
(Result
, Standard_Natural
);
5193 end Make_Level_Literal
;
5195 -- Start of processing for Dynamic_Accessibility_Level
5198 if Is_Entity_Name
(Expr
) then
5201 if Present
(Renamed_Object
(E
)) then
5202 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
5205 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
5206 if Present
(Extra_Accessibility
(E
)) then
5207 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
5212 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5214 case Nkind
(Expr
) is
5216 -- For access discriminant, the level of the enclosing object
5218 when N_Selected_Component
=>
5219 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
5220 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
5221 E_Anonymous_Access_Type
5223 return Make_Level_Literal
(Object_Access_Level
(Expr
));
5226 when N_Attribute_Reference
=>
5227 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
5229 -- For X'Access, the level of the prefix X
5231 when Attribute_Access
=>
5232 return Make_Level_Literal
5233 (Object_Access_Level
(Prefix
(Expr
)));
5235 -- Treat the unchecked attributes as library-level
5237 when Attribute_Unchecked_Access |
5238 Attribute_Unrestricted_Access
=>
5239 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
5241 -- No other access-valued attributes
5244 raise Program_Error
;
5249 -- Unimplemented: depends on context. As an actual parameter where
5250 -- formal type is anonymous, use
5251 -- Scope_Depth (Current_Scope) + 1.
5252 -- For other cases, see 3.10.2(14/3) and following. ???
5256 when N_Type_Conversion
=>
5257 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
5259 -- Handle type conversions introduced for a rename of an
5260 -- Ada 2012 stand-alone object of an anonymous access type.
5262 return Dynamic_Accessibility_Level
(Expression
(Expr
));
5269 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
5270 end Dynamic_Accessibility_Level
;
5272 -----------------------------------
5273 -- Effective_Extra_Accessibility --
5274 -----------------------------------
5276 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
5278 if Present
(Renamed_Object
(Id
))
5279 and then Is_Entity_Name
(Renamed_Object
(Id
))
5281 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
5283 return Extra_Accessibility
(Id
);
5285 end Effective_Extra_Accessibility
;
5287 -----------------------------
5288 -- Effective_Reads_Enabled --
5289 -----------------------------
5291 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
5293 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
5294 end Effective_Reads_Enabled
;
5296 ------------------------------
5297 -- Effective_Writes_Enabled --
5298 ------------------------------
5300 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
5302 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
5303 end Effective_Writes_Enabled
;
5305 ------------------------------
5306 -- Enclosing_Comp_Unit_Node --
5307 ------------------------------
5309 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
5310 Current_Node
: Node_Id
;
5314 while Present
(Current_Node
)
5315 and then Nkind
(Current_Node
) /= N_Compilation_Unit
5317 Current_Node
:= Parent
(Current_Node
);
5320 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
5323 return Current_Node
;
5325 end Enclosing_Comp_Unit_Node
;
5327 --------------------------
5328 -- Enclosing_CPP_Parent --
5329 --------------------------
5331 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
5332 Parent_Typ
: Entity_Id
:= Typ
;
5335 while not Is_CPP_Class
(Parent_Typ
)
5336 and then Etype
(Parent_Typ
) /= Parent_Typ
5338 Parent_Typ
:= Etype
(Parent_Typ
);
5340 if Is_Private_Type
(Parent_Typ
) then
5341 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5345 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
5347 end Enclosing_CPP_Parent
;
5349 ----------------------------
5350 -- Enclosing_Generic_Body --
5351 ----------------------------
5353 function Enclosing_Generic_Body
5354 (N
: Node_Id
) return Node_Id
5362 while Present
(P
) loop
5363 if Nkind
(P
) = N_Package_Body
5364 or else Nkind
(P
) = N_Subprogram_Body
5366 Spec
:= Corresponding_Spec
(P
);
5368 if Present
(Spec
) then
5369 Decl
:= Unit_Declaration_Node
(Spec
);
5371 if Nkind
(Decl
) = N_Generic_Package_Declaration
5372 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5383 end Enclosing_Generic_Body
;
5385 ----------------------------
5386 -- Enclosing_Generic_Unit --
5387 ----------------------------
5389 function Enclosing_Generic_Unit
5390 (N
: Node_Id
) return Node_Id
5398 while Present
(P
) loop
5399 if Nkind
(P
) = N_Generic_Package_Declaration
5400 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
5404 elsif Nkind
(P
) = N_Package_Body
5405 or else Nkind
(P
) = N_Subprogram_Body
5407 Spec
:= Corresponding_Spec
(P
);
5409 if Present
(Spec
) then
5410 Decl
:= Unit_Declaration_Node
(Spec
);
5412 if Nkind
(Decl
) = N_Generic_Package_Declaration
5413 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5424 end Enclosing_Generic_Unit
;
5426 -------------------------------
5427 -- Enclosing_Lib_Unit_Entity --
5428 -------------------------------
5430 function Enclosing_Lib_Unit_Entity
5431 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
5433 Unit_Entity
: Entity_Id
;
5436 -- Look for enclosing library unit entity by following scope links.
5437 -- Equivalent to, but faster than indexing through the scope stack.
5440 while (Present
(Scope
(Unit_Entity
))
5441 and then Scope
(Unit_Entity
) /= Standard_Standard
)
5442 and not Is_Child_Unit
(Unit_Entity
)
5444 Unit_Entity
:= Scope
(Unit_Entity
);
5448 end Enclosing_Lib_Unit_Entity
;
5450 -----------------------
5451 -- Enclosing_Package --
5452 -----------------------
5454 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
5455 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5458 if Dynamic_Scope
= Standard_Standard
then
5459 return Standard_Standard
;
5461 elsif Dynamic_Scope
= Empty
then
5464 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
5467 return Dynamic_Scope
;
5470 return Enclosing_Package
(Dynamic_Scope
);
5472 end Enclosing_Package
;
5474 --------------------------
5475 -- Enclosing_Subprogram --
5476 --------------------------
5478 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5479 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5482 if Dynamic_Scope
= Standard_Standard
then
5485 elsif Dynamic_Scope
= Empty
then
5488 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
5489 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
5491 elsif Ekind
(Dynamic_Scope
) = E_Block
5492 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
5494 return Enclosing_Subprogram
(Dynamic_Scope
);
5496 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
5497 return Get_Task_Body_Procedure
(Dynamic_Scope
);
5499 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
5500 and then Present
(Full_View
(Dynamic_Scope
))
5501 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
5503 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
5505 -- No body is generated if the protected operation is eliminated
5507 elsif Convention
(Dynamic_Scope
) = Convention_Protected
5508 and then not Is_Eliminated
(Dynamic_Scope
)
5509 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
5511 return Protected_Body_Subprogram
(Dynamic_Scope
);
5514 return Dynamic_Scope
;
5516 end Enclosing_Subprogram
;
5518 ------------------------
5519 -- Ensure_Freeze_Node --
5520 ------------------------
5522 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
5525 if No
(Freeze_Node
(E
)) then
5526 FN
:= Make_Freeze_Entity
(Sloc
(E
));
5527 Set_Has_Delayed_Freeze
(E
);
5528 Set_Freeze_Node
(E
, FN
);
5529 Set_Access_Types_To_Process
(FN
, No_Elist
);
5530 Set_TSS_Elist
(FN
, No_Elist
);
5533 end Ensure_Freeze_Node
;
5539 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5540 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5541 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5542 S
: constant Entity_Id
:= Current_Scope
;
5545 Generate_Definition
(Def_Id
);
5547 -- Add new name to current scope declarations. Check for duplicate
5548 -- declaration, which may or may not be a genuine error.
5552 -- Case of previous entity entered because of a missing declaration
5553 -- or else a bad subtype indication. Best is to use the new entity,
5554 -- and make the previous one invisible.
5556 if Etype
(E
) = Any_Type
then
5557 Set_Is_Immediately_Visible
(E
, False);
5559 -- Case of renaming declaration constructed for package instances.
5560 -- if there is an explicit declaration with the same identifier,
5561 -- the renaming is not immediately visible any longer, but remains
5562 -- visible through selected component notation.
5564 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
5565 and then not Comes_From_Source
(E
)
5567 Set_Is_Immediately_Visible
(E
, False);
5569 -- The new entity may be the package renaming, which has the same
5570 -- same name as a generic formal which has been seen already.
5572 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
5573 and then not Comes_From_Source
(Def_Id
)
5575 Set_Is_Immediately_Visible
(E
, False);
5577 -- For a fat pointer corresponding to a remote access to subprogram,
5578 -- we use the same identifier as the RAS type, so that the proper
5579 -- name appears in the stub. This type is only retrieved through
5580 -- the RAS type and never by visibility, and is not added to the
5581 -- visibility list (see below).
5583 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
5584 and then Ekind
(Def_Id
) = E_Record_Type
5585 and then Present
(Corresponding_Remote_Type
(Def_Id
))
5589 -- Case of an implicit operation or derived literal. The new entity
5590 -- hides the implicit one, which is removed from all visibility,
5591 -- i.e. the entity list of its scope, and homonym chain of its name.
5593 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
5594 or else Is_Internal
(E
)
5598 Prev_Vis
: Entity_Id
;
5599 Decl
: constant Node_Id
:= Parent
(E
);
5602 -- If E is an implicit declaration, it cannot be the first
5603 -- entity in the scope.
5605 Prev
:= First_Entity
(Current_Scope
);
5606 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
5612 -- If E is not on the entity chain of the current scope,
5613 -- it is an implicit declaration in the generic formal
5614 -- part of a generic subprogram. When analyzing the body,
5615 -- the generic formals are visible but not on the entity
5616 -- chain of the subprogram. The new entity will become
5617 -- the visible one in the body.
5620 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
5624 Set_Next_Entity
(Prev
, Next_Entity
(E
));
5626 if No
(Next_Entity
(Prev
)) then
5627 Set_Last_Entity
(Current_Scope
, Prev
);
5630 if E
= Current_Entity
(E
) then
5634 Prev_Vis
:= Current_Entity
(E
);
5635 while Homonym
(Prev_Vis
) /= E
loop
5636 Prev_Vis
:= Homonym
(Prev_Vis
);
5640 if Present
(Prev_Vis
) then
5642 -- Skip E in the visibility chain
5644 Set_Homonym
(Prev_Vis
, Homonym
(E
));
5647 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
5652 -- This section of code could use a comment ???
5654 elsif Present
(Etype
(E
))
5655 and then Is_Concurrent_Type
(Etype
(E
))
5660 -- If the homograph is a protected component renaming, it should not
5661 -- be hiding the current entity. Such renamings are treated as weak
5664 elsif Is_Prival
(E
) then
5665 Set_Is_Immediately_Visible
(E
, False);
5667 -- In this case the current entity is a protected component renaming.
5668 -- Perform minimal decoration by setting the scope and return since
5669 -- the prival should not be hiding other visible entities.
5671 elsif Is_Prival
(Def_Id
) then
5672 Set_Scope
(Def_Id
, Current_Scope
);
5675 -- Analogous to privals, the discriminal generated for an entry index
5676 -- parameter acts as a weak declaration. Perform minimal decoration
5677 -- to avoid bogus errors.
5679 elsif Is_Discriminal
(Def_Id
)
5680 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
5682 Set_Scope
(Def_Id
, Current_Scope
);
5685 -- In the body or private part of an instance, a type extension may
5686 -- introduce a component with the same name as that of an actual. The
5687 -- legality rule is not enforced, but the semantics of the full type
5688 -- with two components of same name are not clear at this point???
5690 elsif In_Instance_Not_Visible
then
5693 -- When compiling a package body, some child units may have become
5694 -- visible. They cannot conflict with local entities that hide them.
5696 elsif Is_Child_Unit
(E
)
5697 and then In_Open_Scopes
(Scope
(E
))
5698 and then not Is_Immediately_Visible
(E
)
5702 -- Conversely, with front-end inlining we may compile the parent body
5703 -- first, and a child unit subsequently. The context is now the
5704 -- parent spec, and body entities are not visible.
5706 elsif Is_Child_Unit
(Def_Id
)
5707 and then Is_Package_Body_Entity
(E
)
5708 and then not In_Package_Body
(Current_Scope
)
5712 -- Case of genuine duplicate declaration
5715 Error_Msg_Sloc
:= Sloc
(E
);
5717 -- If the previous declaration is an incomplete type declaration
5718 -- this may be an attempt to complete it with a private type. The
5719 -- following avoids confusing cascaded errors.
5721 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
5722 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
5725 ("incomplete type cannot be completed with a private " &
5726 "declaration", Parent
(Def_Id
));
5727 Set_Is_Immediately_Visible
(E
, False);
5728 Set_Full_View
(E
, Def_Id
);
5730 -- An inherited component of a record conflicts with a new
5731 -- discriminant. The discriminant is inserted first in the scope,
5732 -- but the error should be posted on it, not on the component.
5734 elsif Ekind
(E
) = E_Discriminant
5735 and then Present
(Scope
(Def_Id
))
5736 and then Scope
(Def_Id
) /= Current_Scope
5738 Error_Msg_Sloc
:= Sloc
(Def_Id
);
5739 Error_Msg_N
("& conflicts with declaration#", E
);
5742 -- If the name of the unit appears in its own context clause, a
5743 -- dummy package with the name has already been created, and the
5744 -- error emitted. Try to continue quietly.
5746 elsif Error_Posted
(E
)
5747 and then Sloc
(E
) = No_Location
5748 and then Nkind
(Parent
(E
)) = N_Package_Specification
5749 and then Current_Scope
= Standard_Standard
5751 Set_Scope
(Def_Id
, Current_Scope
);
5755 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
5757 -- Avoid cascaded messages with duplicate components in
5760 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
5765 if Nkind
(Parent
(Parent
(Def_Id
))) =
5766 N_Generic_Subprogram_Declaration
5768 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
5770 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
5773 -- If entity is in standard, then we are in trouble, because it
5774 -- means that we have a library package with a duplicated name.
5775 -- That's hard to recover from, so abort.
5777 if S
= Standard_Standard
then
5778 raise Unrecoverable_Error
;
5780 -- Otherwise we continue with the declaration. Having two
5781 -- identical declarations should not cause us too much trouble.
5789 -- If we fall through, declaration is OK, at least OK enough to continue
5791 -- If Def_Id is a discriminant or a record component we are in the midst
5792 -- of inheriting components in a derived record definition. Preserve
5793 -- their Ekind and Etype.
5795 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
5798 -- If a type is already set, leave it alone (happens when a type
5799 -- declaration is reanalyzed following a call to the optimizer).
5801 elsif Present
(Etype
(Def_Id
)) then
5804 -- Otherwise, the kind E_Void insures that premature uses of the entity
5805 -- will be detected. Any_Type insures that no cascaded errors will occur
5808 Set_Ekind
(Def_Id
, E_Void
);
5809 Set_Etype
(Def_Id
, Any_Type
);
5812 -- Inherited discriminants and components in derived record types are
5813 -- immediately visible. Itypes are not.
5815 -- Unless the Itype is for a record type with a corresponding remote
5816 -- type (what is that about, it was not commented ???)
5818 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
5820 ((not Is_Record_Type
(Def_Id
)
5821 or else No
(Corresponding_Remote_Type
(Def_Id
)))
5822 and then not Is_Itype
(Def_Id
))
5824 Set_Is_Immediately_Visible
(Def_Id
);
5825 Set_Current_Entity
(Def_Id
);
5828 Set_Homonym
(Def_Id
, C
);
5829 Append_Entity
(Def_Id
, S
);
5830 Set_Public_Status
(Def_Id
);
5832 -- Declaring a homonym is not allowed in SPARK ...
5834 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
5836 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
5837 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
5838 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
5841 -- ... unless the new declaration is in a subprogram, and the
5842 -- visible declaration is a variable declaration or a parameter
5843 -- specification outside that subprogram.
5845 if Present
(Enclosing_Subp
)
5846 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
5847 N_Parameter_Specification
)
5848 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
5852 -- ... or the new declaration is in a package, and the visible
5853 -- declaration occurs outside that package.
5855 elsif Present
(Enclosing_Pack
)
5856 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
5860 -- ... or the new declaration is a component declaration in a
5861 -- record type definition.
5863 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
5866 -- Don't issue error for non-source entities
5868 elsif Comes_From_Source
(Def_Id
)
5869 and then Comes_From_Source
(C
)
5871 Error_Msg_Sloc
:= Sloc
(C
);
5872 Check_SPARK_05_Restriction
5873 ("redeclaration of identifier &#", Def_Id
);
5878 -- Warn if new entity hides an old one
5880 if Warn_On_Hiding
and then Present
(C
)
5882 -- Don't warn for record components since they always have a well
5883 -- defined scope which does not confuse other uses. Note that in
5884 -- some cases, Ekind has not been set yet.
5886 and then Ekind
(C
) /= E_Component
5887 and then Ekind
(C
) /= E_Discriminant
5888 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
5889 and then Ekind
(Def_Id
) /= E_Component
5890 and then Ekind
(Def_Id
) /= E_Discriminant
5891 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
5893 -- Don't warn for one character variables. It is too common to use
5894 -- such variables as locals and will just cause too many false hits.
5896 and then Length_Of_Name
(Chars
(C
)) /= 1
5898 -- Don't warn for non-source entities
5900 and then Comes_From_Source
(C
)
5901 and then Comes_From_Source
(Def_Id
)
5903 -- Don't warn unless entity in question is in extended main source
5905 and then In_Extended_Main_Source_Unit
(Def_Id
)
5907 -- Finally, the hidden entity must be either immediately visible or
5908 -- use visible (i.e. from a used package).
5911 (Is_Immediately_Visible
(C
)
5913 Is_Potentially_Use_Visible
(C
))
5915 Error_Msg_Sloc
:= Sloc
(C
);
5916 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
5924 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
5930 if Is_Entity_Name
(N
) then
5933 -- Follow a possible chain of renamings to reach the root renamed
5936 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
5937 if Is_Entity_Name
(Renamed_Object
(Id
)) then
5938 Id
:= Entity
(Renamed_Object
(Id
));
5949 --------------------------
5950 -- Explain_Limited_Type --
5951 --------------------------
5953 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
5957 -- For array, component type must be limited
5959 if Is_Array_Type
(T
) then
5960 Error_Msg_Node_2
:= T
;
5962 ("\component type& of type& is limited", N
, Component_Type
(T
));
5963 Explain_Limited_Type
(Component_Type
(T
), N
);
5965 elsif Is_Record_Type
(T
) then
5967 -- No need for extra messages if explicit limited record
5969 if Is_Limited_Record
(Base_Type
(T
)) then
5973 -- Otherwise find a limited component. Check only components that
5974 -- come from source, or inherited components that appear in the
5975 -- source of the ancestor.
5977 C
:= First_Component
(T
);
5978 while Present
(C
) loop
5979 if Is_Limited_Type
(Etype
(C
))
5981 (Comes_From_Source
(C
)
5983 (Present
(Original_Record_Component
(C
))
5985 Comes_From_Source
(Original_Record_Component
(C
))))
5987 Error_Msg_Node_2
:= T
;
5988 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
5989 Explain_Limited_Type
(Etype
(C
), N
);
5996 -- The type may be declared explicitly limited, even if no component
5997 -- of it is limited, in which case we fall out of the loop.
6000 end Explain_Limited_Type
;
6002 -------------------------------
6003 -- Extensions_Visible_Status --
6004 -------------------------------
6006 function Extensions_Visible_Status
6007 (Id
: Entity_Id
) return Extensions_Visible_Mode
6016 -- When a formal parameter is subject to Extensions_Visible, the pragma
6017 -- is stored in the contract of related subprogram.
6019 if Is_Formal
(Id
) then
6022 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
6025 -- No other construct carries this pragma
6028 return Extensions_Visible_None
;
6031 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
6033 -- In certain cases analysis may request the Extensions_Visible status
6034 -- of an expression function before the pragma has been analyzed yet.
6035 -- Inspect the declarative items after the expression function looking
6036 -- for the pragma (if any).
6038 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
6039 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
6040 while Present
(Decl
) loop
6041 if Nkind
(Decl
) = N_Pragma
6042 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
6047 -- A source construct ends the region where Extensions_Visible may
6048 -- appear, stop the traversal. An expanded expression function is
6049 -- no longer a source construct, but it must still be recognized.
6051 elsif Comes_From_Source
(Decl
)
6053 (Nkind_In
(Decl
, N_Subprogram_Body
,
6054 N_Subprogram_Declaration
)
6055 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
6064 -- Extract the value from the Boolean expression (if any)
6066 if Present
(Prag
) then
6067 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
6069 if Present
(Arg
) then
6070 Expr
:= Get_Pragma_Arg
(Arg
);
6072 -- When the associated subprogram is an expression function, the
6073 -- argument of the pragma may not have been analyzed.
6075 if not Analyzed
(Expr
) then
6076 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
6079 -- Guard against cascading errors when the argument of pragma
6080 -- Extensions_Visible is not a valid static Boolean expression.
6082 if Error_Posted
(Expr
) then
6083 return Extensions_Visible_None
;
6085 elsif Is_True
(Expr_Value
(Expr
)) then
6086 return Extensions_Visible_True
;
6089 return Extensions_Visible_False
;
6092 -- Otherwise the aspect or pragma defaults to True
6095 return Extensions_Visible_True
;
6098 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6099 -- directly specified. In SPARK code, its value defaults to "False".
6101 elsif SPARK_Mode
= On
then
6102 return Extensions_Visible_False
;
6104 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6108 return Extensions_Visible_True
;
6110 end Extensions_Visible_Status
;
6116 procedure Find_Actual
6118 Formal
: out Entity_Id
;
6121 Parnt
: constant Node_Id
:= Parent
(N
);
6125 if Nkind_In
(Parnt
, N_Indexed_Component
, N_Selected_Component
)
6126 and then N
= Prefix
(Parnt
)
6128 Find_Actual
(Parnt
, Formal
, Call
);
6131 elsif Nkind
(Parnt
) = N_Parameter_Association
6132 and then N
= Explicit_Actual_Parameter
(Parnt
)
6134 Call
:= Parent
(Parnt
);
6136 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
6145 -- If we have a call to a subprogram look for the parameter. Note that
6146 -- we exclude overloaded calls, since we don't know enough to be sure
6147 -- of giving the right answer in this case.
6149 if Nkind_In
(Call
, N_Function_Call
, N_Procedure_Call_Statement
)
6150 and then Is_Entity_Name
(Name
(Call
))
6151 and then Present
(Entity
(Name
(Call
)))
6152 and then Is_Overloadable
(Entity
(Name
(Call
)))
6153 and then not Is_Overloaded
(Name
(Call
))
6155 -- If node is name in call it is not an actual
6157 if N
= Name
(Call
) then
6163 -- Fall here if we are definitely a parameter
6165 Actual
:= First_Actual
(Call
);
6166 Formal
:= First_Formal
(Entity
(Name
(Call
)));
6167 while Present
(Formal
) and then Present
(Actual
) loop
6171 -- An actual that is the prefix in a prefixed call may have
6172 -- been rewritten in the call, after the deferred reference
6173 -- was collected. Check if sloc and kinds and names match.
6175 elsif Sloc
(Actual
) = Sloc
(N
)
6176 and then Nkind
(Actual
) = N_Identifier
6177 and then Nkind
(Actual
) = Nkind
(N
)
6178 and then Chars
(Actual
) = Chars
(N
)
6183 Actual
:= Next_Actual
(Actual
);
6184 Formal
:= Next_Formal
(Formal
);
6189 -- Fall through here if we did not find matching actual
6195 ---------------------------
6196 -- Find_Body_Discriminal --
6197 ---------------------------
6199 function Find_Body_Discriminal
6200 (Spec_Discriminant
: Entity_Id
) return Entity_Id
6206 -- If expansion is suppressed, then the scope can be the concurrent type
6207 -- itself rather than a corresponding concurrent record type.
6209 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
6210 Tsk
:= Scope
(Spec_Discriminant
);
6213 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
6215 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
6218 -- Find discriminant of original concurrent type, and use its current
6219 -- discriminal, which is the renaming within the task/protected body.
6221 Disc
:= First_Discriminant
(Tsk
);
6222 while Present
(Disc
) loop
6223 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
6224 return Discriminal
(Disc
);
6227 Next_Discriminant
(Disc
);
6230 -- That loop should always succeed in finding a matching entry and
6231 -- returning. Fatal error if not.
6233 raise Program_Error
;
6234 end Find_Body_Discriminal
;
6236 -------------------------------------
6237 -- Find_Corresponding_Discriminant --
6238 -------------------------------------
6240 function Find_Corresponding_Discriminant
6242 Typ
: Entity_Id
) return Entity_Id
6244 Par_Disc
: Entity_Id
;
6245 Old_Disc
: Entity_Id
;
6246 New_Disc
: Entity_Id
;
6249 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
6251 -- The original type may currently be private, and the discriminant
6252 -- only appear on its full view.
6254 if Is_Private_Type
(Scope
(Par_Disc
))
6255 and then not Has_Discriminants
(Scope
(Par_Disc
))
6256 and then Present
(Full_View
(Scope
(Par_Disc
)))
6258 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
6260 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
6263 if Is_Class_Wide_Type
(Typ
) then
6264 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
6266 New_Disc
:= First_Discriminant
(Typ
);
6269 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
6270 if Old_Disc
= Par_Disc
then
6274 Next_Discriminant
(Old_Disc
);
6275 Next_Discriminant
(New_Disc
);
6278 -- Should always find it
6280 raise Program_Error
;
6281 end Find_Corresponding_Discriminant
;
6283 ----------------------------------
6284 -- Find_Enclosing_Iterator_Loop --
6285 ----------------------------------
6287 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
6292 -- Traverse the scope chain looking for an iterator loop. Such loops are
6293 -- usually transformed into blocks, hence the use of Original_Node.
6296 while Present
(S
) and then S
/= Standard_Standard
loop
6297 if Ekind
(S
) = E_Loop
6298 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
6300 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
6302 if Nkind
(Constr
) = N_Loop_Statement
6303 and then Present
(Iteration_Scheme
(Constr
))
6304 and then Nkind
(Iterator_Specification
6305 (Iteration_Scheme
(Constr
))) =
6306 N_Iterator_Specification
6316 end Find_Enclosing_Iterator_Loop
;
6318 ------------------------------------
6319 -- Find_Loop_In_Conditional_Block --
6320 ------------------------------------
6322 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
6328 if Nkind
(Stmt
) = N_If_Statement
then
6329 Stmt
:= First
(Then_Statements
(Stmt
));
6332 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
6334 -- Inspect the statements of the conditional block. In general the loop
6335 -- should be the first statement in the statement sequence of the block,
6336 -- but the finalization machinery may have introduced extra object
6339 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
6340 while Present
(Stmt
) loop
6341 if Nkind
(Stmt
) = N_Loop_Statement
then
6348 -- The expansion of attribute 'Loop_Entry produced a malformed block
6350 raise Program_Error
;
6351 end Find_Loop_In_Conditional_Block
;
6353 --------------------------
6354 -- Find_Overlaid_Entity --
6355 --------------------------
6357 procedure Find_Overlaid_Entity
6359 Ent
: out Entity_Id
;
6365 -- We are looking for one of the two following forms:
6367 -- for X'Address use Y'Address
6371 -- Const : constant Address := expr;
6373 -- for X'Address use Const;
6375 -- In the second case, the expr is either Y'Address, or recursively a
6376 -- constant that eventually references Y'Address.
6381 if Nkind
(N
) = N_Attribute_Definition_Clause
6382 and then Chars
(N
) = Name_Address
6384 Expr
:= Expression
(N
);
6386 -- This loop checks the form of the expression for Y'Address,
6387 -- using recursion to deal with intermediate constants.
6390 -- Check for Y'Address
6392 if Nkind
(Expr
) = N_Attribute_Reference
6393 and then Attribute_Name
(Expr
) = Name_Address
6395 Expr
:= Prefix
(Expr
);
6398 -- Check for Const where Const is a constant entity
6400 elsif Is_Entity_Name
(Expr
)
6401 and then Ekind
(Entity
(Expr
)) = E_Constant
6403 Expr
:= Constant_Value
(Entity
(Expr
));
6405 -- Anything else does not need checking
6412 -- This loop checks the form of the prefix for an entity, using
6413 -- recursion to deal with intermediate components.
6416 -- Check for Y where Y is an entity
6418 if Is_Entity_Name
(Expr
) then
6419 Ent
:= Entity
(Expr
);
6422 -- Check for components
6425 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
6427 Expr
:= Prefix
(Expr
);
6430 -- Anything else does not need checking
6437 end Find_Overlaid_Entity
;
6439 -------------------------
6440 -- Find_Parameter_Type --
6441 -------------------------
6443 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
6445 if Nkind
(Param
) /= N_Parameter_Specification
then
6448 -- For an access parameter, obtain the type from the formal entity
6449 -- itself, because access to subprogram nodes do not carry a type.
6450 -- Shouldn't we always use the formal entity ???
6452 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
6453 return Etype
(Defining_Identifier
(Param
));
6456 return Etype
(Parameter_Type
(Param
));
6458 end Find_Parameter_Type
;
6460 -----------------------------------
6461 -- Find_Placement_In_State_Space --
6462 -----------------------------------
6464 procedure Find_Placement_In_State_Space
6465 (Item_Id
: Entity_Id
;
6466 Placement
: out State_Space_Kind
;
6467 Pack_Id
: out Entity_Id
)
6469 Context
: Entity_Id
;
6472 -- Assume that the item does not appear in the state space of a package
6474 Placement
:= Not_In_Package
;
6477 -- Climb the scope stack and examine the enclosing context
6479 Context
:= Scope
(Item_Id
);
6480 while Present
(Context
) and then Context
/= Standard_Standard
loop
6481 if Ekind
(Context
) = E_Package
then
6484 -- A package body is a cut off point for the traversal as the item
6485 -- cannot be visible to the outside from this point on. Note that
6486 -- this test must be done first as a body is also classified as a
6489 if In_Package_Body
(Context
) then
6490 Placement
:= Body_State_Space
;
6493 -- The private part of a package is a cut off point for the
6494 -- traversal as the item cannot be visible to the outside from
6497 elsif In_Private_Part
(Context
) then
6498 Placement
:= Private_State_Space
;
6501 -- When the item appears in the visible state space of a package,
6502 -- continue to climb the scope stack as this may not be the final
6506 Placement
:= Visible_State_Space
;
6508 -- The visible state space of a child unit acts as the proper
6509 -- placement of an item.
6511 if Is_Child_Unit
(Context
) then
6516 -- The item or its enclosing package appear in a construct that has
6520 Placement
:= Not_In_Package
;
6524 Context
:= Scope
(Context
);
6526 end Find_Placement_In_State_Space
;
6528 ------------------------
6529 -- Find_Specific_Type --
6530 ------------------------
6532 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
6533 Typ
: Entity_Id
:= Root_Type
(CW
);
6536 if Ekind
(Typ
) = E_Incomplete_Type
then
6537 if From_Limited_With
(Typ
) then
6538 Typ
:= Non_Limited_View
(Typ
);
6540 Typ
:= Full_View
(Typ
);
6544 if Is_Private_Type
(Typ
)
6545 and then not Is_Tagged_Type
(Typ
)
6546 and then Present
(Full_View
(Typ
))
6548 return Full_View
(Typ
);
6552 end Find_Specific_Type
;
6554 -----------------------------
6555 -- Find_Static_Alternative --
6556 -----------------------------
6558 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
6559 Expr
: constant Node_Id
:= Expression
(N
);
6560 Val
: constant Uint
:= Expr_Value
(Expr
);
6565 Alt
:= First
(Alternatives
(N
));
6568 if Nkind
(Alt
) /= N_Pragma
then
6569 Choice
:= First
(Discrete_Choices
(Alt
));
6570 while Present
(Choice
) loop
6572 -- Others choice, always matches
6574 if Nkind
(Choice
) = N_Others_Choice
then
6577 -- Range, check if value is in the range
6579 elsif Nkind
(Choice
) = N_Range
then
6581 Val
>= Expr_Value
(Low_Bound
(Choice
))
6583 Val
<= Expr_Value
(High_Bound
(Choice
));
6585 -- Choice is a subtype name. Note that we know it must
6586 -- be a static subtype, since otherwise it would have
6587 -- been diagnosed as illegal.
6589 elsif Is_Entity_Name
(Choice
)
6590 and then Is_Type
(Entity
(Choice
))
6592 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
6593 Assume_Valid
=> False);
6595 -- Choice is a subtype indication
6597 elsif Nkind
(Choice
) = N_Subtype_Indication
then
6599 C
: constant Node_Id
:= Constraint
(Choice
);
6600 R
: constant Node_Id
:= Range_Expression
(C
);
6604 Val
>= Expr_Value
(Low_Bound
(R
))
6606 Val
<= Expr_Value
(High_Bound
(R
));
6609 -- Choice is a simple expression
6612 exit Search
when Val
= Expr_Value
(Choice
);
6620 pragma Assert
(Present
(Alt
));
6623 -- The above loop *must* terminate by finding a match, since
6624 -- we know the case statement is valid, and the value of the
6625 -- expression is known at compile time. When we fall out of
6626 -- the loop, Alt points to the alternative that we know will
6627 -- be selected at run time.
6630 end Find_Static_Alternative
;
6636 function First_Actual
(Node
: Node_Id
) return Node_Id
is
6640 if No
(Parameter_Associations
(Node
)) then
6644 N
:= First
(Parameter_Associations
(Node
));
6646 if Nkind
(N
) = N_Parameter_Association
then
6647 return First_Named_Actual
(Node
);
6653 -----------------------
6654 -- Gather_Components --
6655 -----------------------
6657 procedure Gather_Components
6659 Comp_List
: Node_Id
;
6660 Governed_By
: List_Id
;
6662 Report_Errors
: out Boolean)
6666 Discrete_Choice
: Node_Id
;
6667 Comp_Item
: Node_Id
;
6669 Discrim
: Entity_Id
;
6670 Discrim_Name
: Node_Id
;
6671 Discrim_Value
: Node_Id
;
6674 Report_Errors
:= False;
6676 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
6679 elsif Present
(Component_Items
(Comp_List
)) then
6680 Comp_Item
:= First
(Component_Items
(Comp_List
));
6686 while Present
(Comp_Item
) loop
6688 -- Skip the tag of a tagged record, the interface tags, as well
6689 -- as all items that are not user components (anonymous types,
6690 -- rep clauses, Parent field, controller field).
6692 if Nkind
(Comp_Item
) = N_Component_Declaration
then
6694 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
6696 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
6697 Append_Elmt
(Comp
, Into
);
6705 if No
(Variant_Part
(Comp_List
)) then
6708 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
6709 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
6712 -- Look for the discriminant that governs this variant part.
6713 -- The discriminant *must* be in the Governed_By List
6715 Assoc
:= First
(Governed_By
);
6716 Find_Constraint
: loop
6717 Discrim
:= First
(Choices
(Assoc
));
6718 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
6719 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
6721 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
6722 Chars
(Discrim_Name
))
6723 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
6724 = Chars
(Discrim_Name
);
6726 if No
(Next
(Assoc
)) then
6727 if not Is_Constrained
(Typ
)
6728 and then Is_Derived_Type
(Typ
)
6729 and then Present
(Stored_Constraint
(Typ
))
6731 -- If the type is a tagged type with inherited discriminants,
6732 -- use the stored constraint on the parent in order to find
6733 -- the values of discriminants that are otherwise hidden by an
6734 -- explicit constraint. Renamed discriminants are handled in
6737 -- If several parent discriminants are renamed by a single
6738 -- discriminant of the derived type, the call to obtain the
6739 -- Corresponding_Discriminant field only retrieves the last
6740 -- of them. We recover the constraint on the others from the
6741 -- Stored_Constraint as well.
6748 D
:= First_Discriminant
(Etype
(Typ
));
6749 C
:= First_Elmt
(Stored_Constraint
(Typ
));
6750 while Present
(D
) and then Present
(C
) loop
6751 if Chars
(Discrim_Name
) = Chars
(D
) then
6752 if Is_Entity_Name
(Node
(C
))
6753 and then Entity
(Node
(C
)) = Entity
(Discrim
)
6755 -- D is renamed by Discrim, whose value is given in
6762 Make_Component_Association
(Sloc
(Typ
),
6764 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
6765 Duplicate_Subexpr_No_Checks
(Node
(C
)));
6767 exit Find_Constraint
;
6770 Next_Discriminant
(D
);
6777 if No
(Next
(Assoc
)) then
6778 Error_Msg_NE
(" missing value for discriminant&",
6779 First
(Governed_By
), Discrim_Name
);
6780 Report_Errors
:= True;
6785 end loop Find_Constraint
;
6787 Discrim_Value
:= Expression
(Assoc
);
6789 if not Is_OK_Static_Expression
(Discrim_Value
) then
6791 -- If the variant part is governed by a discriminant of the type
6792 -- this is an error. If the variant part and the discriminant are
6793 -- inherited from an ancestor this is legal (AI05-120) unless the
6794 -- components are being gathered for an aggregate, in which case
6795 -- the caller must check Report_Errors.
6797 if Scope
(Original_Record_Component
6798 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
6801 ("value for discriminant & must be static!",
6802 Discrim_Value
, Discrim
);
6803 Why_Not_Static
(Discrim_Value
);
6806 Report_Errors
:= True;
6810 Search_For_Discriminant_Value
: declare
6816 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
6819 Find_Discrete_Value
: while Present
(Variant
) loop
6820 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
6821 while Present
(Discrete_Choice
) loop
6822 exit Find_Discrete_Value
when
6823 Nkind
(Discrete_Choice
) = N_Others_Choice
;
6825 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
6827 UI_Low
:= Expr_Value
(Low
);
6828 UI_High
:= Expr_Value
(High
);
6830 exit Find_Discrete_Value
when
6831 UI_Low
<= UI_Discrim_Value
6833 UI_High
>= UI_Discrim_Value
;
6835 Next
(Discrete_Choice
);
6838 Next_Non_Pragma
(Variant
);
6839 end loop Find_Discrete_Value
;
6840 end Search_For_Discriminant_Value
;
6842 if No
(Variant
) then
6844 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
6845 Report_Errors
:= True;
6849 -- If we have found the corresponding choice, recursively add its
6850 -- components to the Into list.
6853 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
6854 end Gather_Components
;
6856 ------------------------
6857 -- Get_Actual_Subtype --
6858 ------------------------
6860 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
6861 Typ
: constant Entity_Id
:= Etype
(N
);
6862 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
6871 -- If what we have is an identifier that references a subprogram
6872 -- formal, or a variable or constant object, then we get the actual
6873 -- subtype from the referenced entity if one has been built.
6875 if Nkind
(N
) = N_Identifier
6877 (Is_Formal
(Entity
(N
))
6878 or else Ekind
(Entity
(N
)) = E_Constant
6879 or else Ekind
(Entity
(N
)) = E_Variable
)
6880 and then Present
(Actual_Subtype
(Entity
(N
)))
6882 return Actual_Subtype
(Entity
(N
));
6884 -- Actual subtype of unchecked union is always itself. We never need
6885 -- the "real" actual subtype. If we did, we couldn't get it anyway
6886 -- because the discriminant is not available. The restrictions on
6887 -- Unchecked_Union are designed to make sure that this is OK.
6889 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
6892 -- Here for the unconstrained case, we must find actual subtype
6893 -- No actual subtype is available, so we must build it on the fly.
6895 -- Checking the type, not the underlying type, for constrainedness
6896 -- seems to be necessary. Maybe all the tests should be on the type???
6898 elsif (not Is_Constrained
(Typ
))
6899 and then (Is_Array_Type
(Utyp
)
6900 or else (Is_Record_Type
(Utyp
)
6901 and then Has_Discriminants
(Utyp
)))
6902 and then not Has_Unknown_Discriminants
(Utyp
)
6903 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
6905 -- Nothing to do if in spec expression (why not???)
6907 if In_Spec_Expression
then
6910 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
6912 -- If the type has no discriminants, there is no subtype to
6913 -- build, even if the underlying type is discriminated.
6917 -- Else build the actual subtype
6920 Decl
:= Build_Actual_Subtype
(Typ
, N
);
6921 Atyp
:= Defining_Identifier
(Decl
);
6923 -- If Build_Actual_Subtype generated a new declaration then use it
6927 -- The actual subtype is an Itype, so analyze the declaration,
6928 -- but do not attach it to the tree, to get the type defined.
6930 Set_Parent
(Decl
, N
);
6931 Set_Is_Itype
(Atyp
);
6932 Analyze
(Decl
, Suppress
=> All_Checks
);
6933 Set_Associated_Node_For_Itype
(Atyp
, N
);
6934 Set_Has_Delayed_Freeze
(Atyp
, False);
6936 -- We need to freeze the actual subtype immediately. This is
6937 -- needed, because otherwise this Itype will not get frozen
6938 -- at all, and it is always safe to freeze on creation because
6939 -- any associated types must be frozen at this point.
6941 Freeze_Itype
(Atyp
, N
);
6944 -- Otherwise we did not build a declaration, so return original
6951 -- For all remaining cases, the actual subtype is the same as
6952 -- the nominal type.
6957 end Get_Actual_Subtype
;
6959 -------------------------------------
6960 -- Get_Actual_Subtype_If_Available --
6961 -------------------------------------
6963 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
6964 Typ
: constant Entity_Id
:= Etype
(N
);
6967 -- If what we have is an identifier that references a subprogram
6968 -- formal, or a variable or constant object, then we get the actual
6969 -- subtype from the referenced entity if one has been built.
6971 if Nkind
(N
) = N_Identifier
6973 (Is_Formal
(Entity
(N
))
6974 or else Ekind
(Entity
(N
)) = E_Constant
6975 or else Ekind
(Entity
(N
)) = E_Variable
)
6976 and then Present
(Actual_Subtype
(Entity
(N
)))
6978 return Actual_Subtype
(Entity
(N
));
6980 -- Otherwise the Etype of N is returned unchanged
6985 end Get_Actual_Subtype_If_Available
;
6987 ------------------------
6988 -- Get_Body_From_Stub --
6989 ------------------------
6991 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
6993 return Proper_Body
(Unit
(Library_Unit
(N
)));
6994 end Get_Body_From_Stub
;
6996 ---------------------
6997 -- Get_Cursor_Type --
6998 ---------------------
7000 function Get_Cursor_Type
7002 Typ
: Entity_Id
) return Entity_Id
7006 First_Op
: Entity_Id
;
7010 -- If error already detected, return
7012 if Error_Posted
(Aspect
) then
7016 -- The cursor type for an Iterable aspect is the return type of a
7017 -- non-overloaded First primitive operation. Locate association for
7020 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
7022 while Present
(Assoc
) loop
7023 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
7024 First_Op
:= Expression
(Assoc
);
7031 if First_Op
= Any_Id
then
7032 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
7038 -- Locate function with desired name and profile in scope of type
7040 Func
:= First_Entity
(Scope
(Typ
));
7041 while Present
(Func
) loop
7042 if Chars
(Func
) = Chars
(First_Op
)
7043 and then Ekind
(Func
) = E_Function
7044 and then Present
(First_Formal
(Func
))
7045 and then Etype
(First_Formal
(Func
)) = Typ
7046 and then No
(Next_Formal
(First_Formal
(Func
)))
7048 if Cursor
/= Any_Type
then
7050 ("Operation First for iterable type must be unique", Aspect
);
7053 Cursor
:= Etype
(Func
);
7060 -- If not found, no way to resolve remaining primitives.
7062 if Cursor
= Any_Type
then
7064 ("No legal primitive operation First for Iterable type", Aspect
);
7068 end Get_Cursor_Type
;
7070 -------------------------------
7071 -- Get_Default_External_Name --
7072 -------------------------------
7074 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
7076 Get_Decoded_Name_String
(Chars
(E
));
7078 if Opt
.External_Name_Imp_Casing
= Uppercase
then
7079 Set_Casing
(All_Upper_Case
);
7081 Set_Casing
(All_Lower_Case
);
7085 Make_String_Literal
(Sloc
(E
),
7086 Strval
=> String_From_Name_Buffer
);
7087 end Get_Default_External_Name
;
7089 --------------------------
7090 -- Get_Enclosing_Object --
7091 --------------------------
7093 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
7095 if Is_Entity_Name
(N
) then
7099 when N_Indexed_Component |
7101 N_Selected_Component
=>
7103 -- If not generating code, a dereference may be left implicit.
7104 -- In thoses cases, return Empty.
7106 if Is_Access_Type
(Etype
(Prefix
(N
))) then
7109 return Get_Enclosing_Object
(Prefix
(N
));
7112 when N_Type_Conversion
=>
7113 return Get_Enclosing_Object
(Expression
(N
));
7119 end Get_Enclosing_Object
;
7121 ---------------------------
7122 -- Get_Enum_Lit_From_Pos --
7123 ---------------------------
7125 function Get_Enum_Lit_From_Pos
7128 Loc
: Source_Ptr
) return Node_Id
7130 Btyp
: Entity_Id
:= Base_Type
(T
);
7134 -- In the case where the literal is of type Character, Wide_Character
7135 -- or Wide_Wide_Character or of a type derived from them, there needs
7136 -- to be some special handling since there is no explicit chain of
7137 -- literals to search. Instead, an N_Character_Literal node is created
7138 -- with the appropriate Char_Code and Chars fields.
7140 if Is_Standard_Character_Type
(T
) then
7141 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
7143 Make_Character_Literal
(Loc
,
7145 Char_Literal_Value
=> Pos
);
7147 -- For all other cases, we have a complete table of literals, and
7148 -- we simply iterate through the chain of literal until the one
7149 -- with the desired position value is found.
7152 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
7153 Btyp
:= Full_View
(Btyp
);
7156 Lit
:= First_Literal
(Btyp
);
7157 for J
in 1 .. UI_To_Int
(Pos
) loop
7161 return New_Occurrence_Of
(Lit
, Loc
);
7163 end Get_Enum_Lit_From_Pos
;
7165 ------------------------
7166 -- Get_Generic_Entity --
7167 ------------------------
7169 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
7170 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
7172 if Present
(Renamed_Object
(Ent
)) then
7173 return Renamed_Object
(Ent
);
7177 end Get_Generic_Entity
;
7179 -------------------------------------
7180 -- Get_Incomplete_View_Of_Ancestor --
7181 -------------------------------------
7183 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
7184 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
7185 Par_Scope
: Entity_Id
;
7186 Par_Type
: Entity_Id
;
7189 -- The incomplete view of an ancestor is only relevant for private
7190 -- derived types in child units.
7192 if not Is_Derived_Type
(E
)
7193 or else not Is_Child_Unit
(Cur_Unit
)
7198 Par_Scope
:= Scope
(Cur_Unit
);
7199 if No
(Par_Scope
) then
7203 Par_Type
:= Etype
(Base_Type
(E
));
7205 -- Traverse list of ancestor types until we find one declared in
7206 -- a parent or grandparent unit (two levels seem sufficient).
7208 while Present
(Par_Type
) loop
7209 if Scope
(Par_Type
) = Par_Scope
7210 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
7214 elsif not Is_Derived_Type
(Par_Type
) then
7218 Par_Type
:= Etype
(Base_Type
(Par_Type
));
7222 -- If none found, there is no relevant ancestor type.
7226 end Get_Incomplete_View_Of_Ancestor
;
7228 ----------------------
7229 -- Get_Index_Bounds --
7230 ----------------------
7232 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
7233 Kind
: constant Node_Kind
:= Nkind
(N
);
7237 if Kind
= N_Range
then
7239 H
:= High_Bound
(N
);
7241 elsif Kind
= N_Subtype_Indication
then
7242 R
:= Range_Expression
(Constraint
(N
));
7250 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
7251 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
7254 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
7255 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
7259 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
7260 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
7263 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
7264 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
7268 -- N is an expression, indicating a range with one value
7273 end Get_Index_Bounds
;
7275 ---------------------------------
7276 -- Get_Iterable_Type_Primitive --
7277 ---------------------------------
7279 function Get_Iterable_Type_Primitive
7281 Nam
: Name_Id
) return Entity_Id
7283 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
7291 Assoc
:= First
(Component_Associations
(Funcs
));
7292 while Present
(Assoc
) loop
7293 if Chars
(First
(Choices
(Assoc
))) = Nam
then
7294 return Entity
(Expression
(Assoc
));
7297 Assoc
:= Next
(Assoc
);
7302 end Get_Iterable_Type_Primitive
;
7304 ----------------------------------
7305 -- Get_Library_Unit_Name_string --
7306 ----------------------------------
7308 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
7309 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
7312 Get_Unit_Name_String
(Unit_Name_Id
);
7314 -- Remove seven last character (" (spec)" or " (body)")
7316 Name_Len
:= Name_Len
- 7;
7317 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
7318 end Get_Library_Unit_Name_String
;
7320 ------------------------
7321 -- Get_Name_Entity_Id --
7322 ------------------------
7324 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
7326 return Entity_Id
(Get_Name_Table_Int
(Id
));
7327 end Get_Name_Entity_Id
;
7329 ------------------------------
7330 -- Get_Name_From_CTC_Pragma --
7331 ------------------------------
7333 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
7334 Arg
: constant Node_Id
:=
7335 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
7337 return Strval
(Expr_Value_S
(Arg
));
7338 end Get_Name_From_CTC_Pragma
;
7340 -----------------------
7341 -- Get_Parent_Entity --
7342 -----------------------
7344 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
7346 if Nkind
(Unit
) = N_Package_Body
7347 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
7349 return Defining_Entity
7350 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
7351 elsif Nkind
(Unit
) = N_Package_Instantiation
then
7352 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
7354 return Defining_Entity
(Unit
);
7356 end Get_Parent_Entity
;
7361 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
7363 return Get_Pragma_Id
(Pragma_Name
(N
));
7366 -----------------------
7367 -- Get_Reason_String --
7368 -----------------------
7370 procedure Get_Reason_String
(N
: Node_Id
) is
7372 if Nkind
(N
) = N_String_Literal
then
7373 Store_String_Chars
(Strval
(N
));
7375 elsif Nkind
(N
) = N_Op_Concat
then
7376 Get_Reason_String
(Left_Opnd
(N
));
7377 Get_Reason_String
(Right_Opnd
(N
));
7379 -- If not of required form, error
7383 ("Reason for pragma Warnings has wrong form", N
);
7385 ("\must be string literal or concatenation of string literals", N
);
7388 end Get_Reason_String
;
7390 ---------------------------
7391 -- Get_Referenced_Object --
7392 ---------------------------
7394 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
7399 while Is_Entity_Name
(R
)
7400 and then Present
(Renamed_Object
(Entity
(R
)))
7402 R
:= Renamed_Object
(Entity
(R
));
7406 end Get_Referenced_Object
;
7408 ------------------------
7409 -- Get_Renamed_Entity --
7410 ------------------------
7412 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
7417 while Present
(Renamed_Entity
(R
)) loop
7418 R
:= Renamed_Entity
(R
);
7422 end Get_Renamed_Entity
;
7424 -------------------------
7425 -- Get_Subprogram_Body --
7426 -------------------------
7428 function Get_Subprogram_Body
(E
: Entity_Id
) return Node_Id
is
7432 Decl
:= Unit_Declaration_Node
(E
);
7434 if Nkind
(Decl
) = N_Subprogram_Body
then
7437 -- The below comment is bad, because it is possible for
7438 -- Nkind (Decl) to be an N_Subprogram_Body_Stub ???
7440 else -- Nkind (Decl) = N_Subprogram_Declaration
7442 if Present
(Corresponding_Body
(Decl
)) then
7443 return Unit_Declaration_Node
(Corresponding_Body
(Decl
));
7445 -- Imported subprogram case
7451 end Get_Subprogram_Body
;
7453 ---------------------------
7454 -- Get_Subprogram_Entity --
7455 ---------------------------
7457 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
7459 Subp_Id
: Entity_Id
;
7462 if Nkind
(Nod
) = N_Accept_Statement
then
7463 Subp
:= Entry_Direct_Name
(Nod
);
7465 elsif Nkind
(Nod
) = N_Slice
then
7466 Subp
:= Prefix
(Nod
);
7472 -- Strip the subprogram call
7475 if Nkind_In
(Subp
, N_Explicit_Dereference
,
7476 N_Indexed_Component
,
7477 N_Selected_Component
)
7479 Subp
:= Prefix
(Subp
);
7481 elsif Nkind_In
(Subp
, N_Type_Conversion
,
7482 N_Unchecked_Type_Conversion
)
7484 Subp
:= Expression
(Subp
);
7491 -- Extract the entity of the subprogram call
7493 if Is_Entity_Name
(Subp
) then
7494 Subp_Id
:= Entity
(Subp
);
7496 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
7497 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
7500 if Is_Subprogram
(Subp_Id
) then
7506 -- The search did not find a construct that denotes a subprogram
7511 end Get_Subprogram_Entity
;
7513 -----------------------------
7514 -- Get_Task_Body_Procedure --
7515 -----------------------------
7517 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
7519 -- Note: A task type may be the completion of a private type with
7520 -- discriminants. When performing elaboration checks on a task
7521 -- declaration, the current view of the type may be the private one,
7522 -- and the procedure that holds the body of the task is held in its
7525 -- This is an odd function, why not have Task_Body_Procedure do
7526 -- the following digging???
7528 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
7529 end Get_Task_Body_Procedure
;
7531 -----------------------
7532 -- Has_Access_Values --
7533 -----------------------
7535 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
7536 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
7539 -- Case of a private type which is not completed yet. This can only
7540 -- happen in the case of a generic format type appearing directly, or
7541 -- as a component of the type to which this function is being applied
7542 -- at the top level. Return False in this case, since we certainly do
7543 -- not know that the type contains access types.
7548 elsif Is_Access_Type
(Typ
) then
7551 elsif Is_Array_Type
(Typ
) then
7552 return Has_Access_Values
(Component_Type
(Typ
));
7554 elsif Is_Record_Type
(Typ
) then
7559 -- Loop to Check components
7561 Comp
:= First_Component_Or_Discriminant
(Typ
);
7562 while Present
(Comp
) loop
7564 -- Check for access component, tag field does not count, even
7565 -- though it is implemented internally using an access type.
7567 if Has_Access_Values
(Etype
(Comp
))
7568 and then Chars
(Comp
) /= Name_uTag
7573 Next_Component_Or_Discriminant
(Comp
);
7582 end Has_Access_Values
;
7584 ------------------------------
7585 -- Has_Compatible_Alignment --
7586 ------------------------------
7588 function Has_Compatible_Alignment
7590 Expr
: Node_Id
) return Alignment_Result
7592 function Has_Compatible_Alignment_Internal
7595 Default
: Alignment_Result
) return Alignment_Result
;
7596 -- This is the internal recursive function that actually does the work.
7597 -- There is one additional parameter, which says what the result should
7598 -- be if no alignment information is found, and there is no definite
7599 -- indication of compatible alignments. At the outer level, this is set
7600 -- to Unknown, but for internal recursive calls in the case where types
7601 -- are known to be correct, it is set to Known_Compatible.
7603 ---------------------------------------
7604 -- Has_Compatible_Alignment_Internal --
7605 ---------------------------------------
7607 function Has_Compatible_Alignment_Internal
7610 Default
: Alignment_Result
) return Alignment_Result
7612 Result
: Alignment_Result
:= Known_Compatible
;
7613 -- Holds the current status of the result. Note that once a value of
7614 -- Known_Incompatible is set, it is sticky and does not get changed
7615 -- to Unknown (the value in Result only gets worse as we go along,
7618 Offs
: Uint
:= No_Uint
;
7619 -- Set to a factor of the offset from the base object when Expr is a
7620 -- selected or indexed component, based on Component_Bit_Offset and
7621 -- Component_Size respectively. A negative value is used to represent
7622 -- a value which is not known at compile time.
7624 procedure Check_Prefix
;
7625 -- Checks the prefix recursively in the case where the expression
7626 -- is an indexed or selected component.
7628 procedure Set_Result
(R
: Alignment_Result
);
7629 -- If R represents a worse outcome (unknown instead of known
7630 -- compatible, or known incompatible), then set Result to R.
7636 procedure Check_Prefix
is
7638 -- The subtlety here is that in doing a recursive call to check
7639 -- the prefix, we have to decide what to do in the case where we
7640 -- don't find any specific indication of an alignment problem.
7642 -- At the outer level, we normally set Unknown as the result in
7643 -- this case, since we can only set Known_Compatible if we really
7644 -- know that the alignment value is OK, but for the recursive
7645 -- call, in the case where the types match, and we have not
7646 -- specified a peculiar alignment for the object, we are only
7647 -- concerned about suspicious rep clauses, the default case does
7648 -- not affect us, since the compiler will, in the absence of such
7649 -- rep clauses, ensure that the alignment is correct.
7651 if Default
= Known_Compatible
7653 (Etype
(Obj
) = Etype
(Expr
)
7654 and then (Unknown_Alignment
(Obj
)
7656 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
7659 (Has_Compatible_Alignment_Internal
7660 (Obj
, Prefix
(Expr
), Known_Compatible
));
7662 -- In all other cases, we need a full check on the prefix
7666 (Has_Compatible_Alignment_Internal
7667 (Obj
, Prefix
(Expr
), Unknown
));
7675 procedure Set_Result
(R
: Alignment_Result
) is
7682 -- Start of processing for Has_Compatible_Alignment_Internal
7685 -- If Expr is a selected component, we must make sure there is no
7686 -- potentially troublesome component clause, and that the record is
7689 if Nkind
(Expr
) = N_Selected_Component
then
7691 -- Packed record always generate unknown alignment
7693 if Is_Packed
(Etype
(Prefix
(Expr
))) then
7694 Set_Result
(Unknown
);
7697 -- Check prefix and component offset
7700 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
7702 -- If Expr is an indexed component, we must make sure there is no
7703 -- potentially troublesome Component_Size clause and that the array
7704 -- is not bit-packed.
7706 elsif Nkind
(Expr
) = N_Indexed_Component
then
7708 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
7709 Ind
: constant Node_Id
:= First_Index
(Typ
);
7712 -- Bit packed array always generates unknown alignment
7714 if Is_Bit_Packed_Array
(Typ
) then
7715 Set_Result
(Unknown
);
7718 -- Check prefix and component offset
7721 Offs
:= Component_Size
(Typ
);
7723 -- Small optimization: compute the full offset when possible
7726 and then Offs
> Uint_0
7727 and then Present
(Ind
)
7728 and then Nkind
(Ind
) = N_Range
7729 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
7730 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
7732 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
7733 - Expr_Value
(Low_Bound
((Ind
))));
7738 -- If we have a null offset, the result is entirely determined by
7739 -- the base object and has already been computed recursively.
7741 if Offs
= Uint_0
then
7744 -- Case where we know the alignment of the object
7746 elsif Known_Alignment
(Obj
) then
7748 ObjA
: constant Uint
:= Alignment
(Obj
);
7749 ExpA
: Uint
:= No_Uint
;
7750 SizA
: Uint
:= No_Uint
;
7753 -- If alignment of Obj is 1, then we are always OK
7756 Set_Result
(Known_Compatible
);
7758 -- Alignment of Obj is greater than 1, so we need to check
7761 -- If we have an offset, see if it is compatible
7763 if Offs
/= No_Uint
and Offs
> Uint_0
then
7764 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
7765 Set_Result
(Known_Incompatible
);
7768 -- See if Expr is an object with known alignment
7770 elsif Is_Entity_Name
(Expr
)
7771 and then Known_Alignment
(Entity
(Expr
))
7773 ExpA
:= Alignment
(Entity
(Expr
));
7775 -- Otherwise, we can use the alignment of the type of
7776 -- Expr given that we already checked for
7777 -- discombobulating rep clauses for the cases of indexed
7778 -- and selected components above.
7780 elsif Known_Alignment
(Etype
(Expr
)) then
7781 ExpA
:= Alignment
(Etype
(Expr
));
7783 -- Otherwise the alignment is unknown
7786 Set_Result
(Default
);
7789 -- If we got an alignment, see if it is acceptable
7791 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
7792 Set_Result
(Known_Incompatible
);
7795 -- If Expr is not a piece of a larger object, see if size
7796 -- is given. If so, check that it is not too small for the
7797 -- required alignment.
7799 if Offs
/= No_Uint
then
7802 -- See if Expr is an object with known size
7804 elsif Is_Entity_Name
(Expr
)
7805 and then Known_Static_Esize
(Entity
(Expr
))
7807 SizA
:= Esize
(Entity
(Expr
));
7809 -- Otherwise, we check the object size of the Expr type
7811 elsif Known_Static_Esize
(Etype
(Expr
)) then
7812 SizA
:= Esize
(Etype
(Expr
));
7815 -- If we got a size, see if it is a multiple of the Obj
7816 -- alignment, if not, then the alignment cannot be
7817 -- acceptable, since the size is always a multiple of the
7820 if SizA
/= No_Uint
then
7821 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
7822 Set_Result
(Known_Incompatible
);
7828 -- If we do not know required alignment, any non-zero offset is a
7829 -- potential problem (but certainly may be OK, so result is unknown).
7831 elsif Offs
/= No_Uint
then
7832 Set_Result
(Unknown
);
7834 -- If we can't find the result by direct comparison of alignment
7835 -- values, then there is still one case that we can determine known
7836 -- result, and that is when we can determine that the types are the
7837 -- same, and no alignments are specified. Then we known that the
7838 -- alignments are compatible, even if we don't know the alignment
7839 -- value in the front end.
7841 elsif Etype
(Obj
) = Etype
(Expr
) then
7843 -- Types are the same, but we have to check for possible size
7844 -- and alignments on the Expr object that may make the alignment
7845 -- different, even though the types are the same.
7847 if Is_Entity_Name
(Expr
) then
7849 -- First check alignment of the Expr object. Any alignment less
7850 -- than Maximum_Alignment is worrisome since this is the case
7851 -- where we do not know the alignment of Obj.
7853 if Known_Alignment
(Entity
(Expr
))
7854 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
7855 Ttypes
.Maximum_Alignment
7857 Set_Result
(Unknown
);
7859 -- Now check size of Expr object. Any size that is not an
7860 -- even multiple of Maximum_Alignment is also worrisome
7861 -- since it may cause the alignment of the object to be less
7862 -- than the alignment of the type.
7864 elsif Known_Static_Esize
(Entity
(Expr
))
7866 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
7867 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
7870 Set_Result
(Unknown
);
7872 -- Otherwise same type is decisive
7875 Set_Result
(Known_Compatible
);
7879 -- Another case to deal with is when there is an explicit size or
7880 -- alignment clause when the types are not the same. If so, then the
7881 -- result is Unknown. We don't need to do this test if the Default is
7882 -- Unknown, since that result will be set in any case.
7884 elsif Default
/= Unknown
7885 and then (Has_Size_Clause
(Etype
(Expr
))
7887 Has_Alignment_Clause
(Etype
(Expr
)))
7889 Set_Result
(Unknown
);
7891 -- If no indication found, set default
7894 Set_Result
(Default
);
7897 -- Return worst result found
7900 end Has_Compatible_Alignment_Internal
;
7902 -- Start of processing for Has_Compatible_Alignment
7905 -- If Obj has no specified alignment, then set alignment from the type
7906 -- alignment. Perhaps we should always do this, but for sure we should
7907 -- do it when there is an address clause since we can do more if the
7908 -- alignment is known.
7910 if Unknown_Alignment
(Obj
) then
7911 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
7914 -- Now do the internal call that does all the work
7916 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
7917 end Has_Compatible_Alignment
;
7919 ----------------------
7920 -- Has_Declarations --
7921 ----------------------
7923 function Has_Declarations
(N
: Node_Id
) return Boolean is
7925 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
7927 N_Compilation_Unit_Aux
,
7933 N_Package_Specification
);
7934 end Has_Declarations
;
7936 ---------------------------------
7937 -- Has_Defaulted_Discriminants --
7938 ---------------------------------
7940 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
7942 return Has_Discriminants
(Typ
)
7943 and then Present
(First_Discriminant
(Typ
))
7944 and then Present
(Discriminant_Default_Value
7945 (First_Discriminant
(Typ
)));
7946 end Has_Defaulted_Discriminants
;
7952 function Has_Denormals
(E
: Entity_Id
) return Boolean is
7954 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
7957 -------------------------------------------
7958 -- Has_Discriminant_Dependent_Constraint --
7959 -------------------------------------------
7961 function Has_Discriminant_Dependent_Constraint
7962 (Comp
: Entity_Id
) return Boolean
7964 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
7965 Subt_Indic
: Node_Id
;
7970 -- Discriminants can't depend on discriminants
7972 if Ekind
(Comp
) = E_Discriminant
then
7976 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
7978 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
7979 Constr
:= Constraint
(Subt_Indic
);
7981 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
7982 Assn
:= First
(Constraints
(Constr
));
7983 while Present
(Assn
) loop
7984 case Nkind
(Assn
) is
7985 when N_Subtype_Indication |
7989 if Depends_On_Discriminant
(Assn
) then
7993 when N_Discriminant_Association
=>
7994 if Depends_On_Discriminant
(Expression
(Assn
)) then
8009 end Has_Discriminant_Dependent_Constraint
;
8011 --------------------------
8012 -- Has_Enabled_Property --
8013 --------------------------
8015 function Has_Enabled_Property
8016 (Item_Id
: Entity_Id
;
8017 Property
: Name_Id
) return Boolean
8019 function State_Has_Enabled_Property
return Boolean;
8020 -- Determine whether a state denoted by Item_Id has the property enabled
8022 function Variable_Has_Enabled_Property
return Boolean;
8023 -- Determine whether a variable denoted by Item_Id has the property
8026 --------------------------------
8027 -- State_Has_Enabled_Property --
8028 --------------------------------
8030 function State_Has_Enabled_Property
return Boolean is
8031 Decl
: constant Node_Id
:= Parent
(Item_Id
);
8039 -- The declaration of an external abstract state appears as an
8040 -- extension aggregate. If this is not the case, properties can never
8043 if Nkind
(Decl
) /= N_Extension_Aggregate
then
8047 -- When External appears as a simple option, it automatically enables
8050 Opt
:= First
(Expressions
(Decl
));
8051 while Present
(Opt
) loop
8052 if Nkind
(Opt
) = N_Identifier
8053 and then Chars
(Opt
) = Name_External
8061 -- When External specifies particular properties, inspect those and
8062 -- find the desired one (if any).
8064 Opt
:= First
(Component_Associations
(Decl
));
8065 while Present
(Opt
) loop
8066 Opt_Nam
:= First
(Choices
(Opt
));
8068 if Nkind
(Opt_Nam
) = N_Identifier
8069 and then Chars
(Opt_Nam
) = Name_External
8071 Props
:= Expression
(Opt
);
8073 -- Multiple properties appear as an aggregate
8075 if Nkind
(Props
) = N_Aggregate
then
8077 -- Simple property form
8079 Prop
:= First
(Expressions
(Props
));
8080 while Present
(Prop
) loop
8081 if Chars
(Prop
) = Property
then
8088 -- Property with expression form
8090 Prop
:= First
(Component_Associations
(Props
));
8091 while Present
(Prop
) loop
8092 Prop_Nam
:= First
(Choices
(Prop
));
8094 -- The property can be represented in two ways:
8095 -- others => <value>
8096 -- <property> => <value>
8098 if Nkind
(Prop_Nam
) = N_Others_Choice
8099 or else (Nkind
(Prop_Nam
) = N_Identifier
8100 and then Chars
(Prop_Nam
) = Property
)
8102 return Is_True
(Expr_Value
(Expression
(Prop
)));
8111 return Chars
(Props
) = Property
;
8119 end State_Has_Enabled_Property
;
8121 -----------------------------------
8122 -- Variable_Has_Enabled_Property --
8123 -----------------------------------
8125 function Variable_Has_Enabled_Property
return Boolean is
8126 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
8127 -- Determine whether property pragma Prag (if present) denotes an
8128 -- enabled property.
8134 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
8138 if Present
(Prag
) then
8139 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
8141 -- The pragma has an optional Boolean expression, the related
8142 -- property is enabled only when the expression evaluates to
8145 if Present
(Arg2
) then
8146 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg2
)));
8148 -- Otherwise the lack of expression enables the property by
8155 -- The property was never set in the first place
8164 AR
: constant Node_Id
:=
8165 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
8166 AW
: constant Node_Id
:=
8167 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
8168 ER
: constant Node_Id
:=
8169 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
8170 EW
: constant Node_Id
:=
8171 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
8173 -- Start of processing for Variable_Has_Enabled_Property
8176 -- A non-effectively volatile object can never possess external
8179 if not Is_Effectively_Volatile
(Item_Id
) then
8182 -- External properties related to variables come in two flavors -
8183 -- explicit and implicit. The explicit case is characterized by the
8184 -- presence of a property pragma with an optional Boolean flag. The
8185 -- property is enabled when the flag evaluates to True or the flag is
8186 -- missing altogether.
8188 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
8191 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
8194 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
8197 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
8200 -- The implicit case lacks all property pragmas
8202 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
8208 end Variable_Has_Enabled_Property
;
8210 -- Start of processing for Has_Enabled_Property
8213 -- Abstract states and variables have a flexible scheme of specifying
8214 -- external properties.
8216 if Ekind
(Item_Id
) = E_Abstract_State
then
8217 return State_Has_Enabled_Property
;
8219 elsif Ekind
(Item_Id
) = E_Variable
then
8220 return Variable_Has_Enabled_Property
;
8222 -- Otherwise a property is enabled when the related item is effectively
8226 return Is_Effectively_Volatile
(Item_Id
);
8228 end Has_Enabled_Property
;
8230 --------------------
8231 -- Has_Infinities --
8232 --------------------
8234 function Has_Infinities
(E
: Entity_Id
) return Boolean is
8237 Is_Floating_Point_Type
(E
)
8238 and then Nkind
(Scalar_Range
(E
)) = N_Range
8239 and then Includes_Infinities
(Scalar_Range
(E
));
8242 --------------------
8243 -- Has_Interfaces --
8244 --------------------
8246 function Has_Interfaces
8248 Use_Full_View
: Boolean := True) return Boolean
8250 Typ
: Entity_Id
:= Base_Type
(T
);
8253 -- Handle concurrent types
8255 if Is_Concurrent_Type
(Typ
) then
8256 Typ
:= Corresponding_Record_Type
(Typ
);
8259 if not Present
(Typ
)
8260 or else not Is_Record_Type
(Typ
)
8261 or else not Is_Tagged_Type
(Typ
)
8266 -- Handle private types
8268 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
8269 Typ
:= Full_View
(Typ
);
8272 -- Handle concurrent record types
8274 if Is_Concurrent_Record_Type
(Typ
)
8275 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
8281 if Is_Interface
(Typ
)
8283 (Is_Record_Type
(Typ
)
8284 and then Present
(Interfaces
(Typ
))
8285 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
8290 exit when Etype
(Typ
) = Typ
8292 -- Handle private types
8294 or else (Present
(Full_View
(Etype
(Typ
)))
8295 and then Full_View
(Etype
(Typ
)) = Typ
)
8297 -- Protect frontend against wrong sources with cyclic derivations
8299 or else Etype
(Typ
) = T
;
8301 -- Climb to the ancestor type handling private types
8303 if Present
(Full_View
(Etype
(Typ
))) then
8304 Typ
:= Full_View
(Etype
(Typ
));
8313 ---------------------------------
8314 -- Has_No_Obvious_Side_Effects --
8315 ---------------------------------
8317 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
8319 -- For now, just handle literals, constants, and non-volatile
8320 -- variables and expressions combining these with operators or
8321 -- short circuit forms.
8323 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
8326 elsif Nkind
(N
) = N_Character_Literal
then
8329 elsif Nkind
(N
) in N_Unary_Op
then
8330 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8332 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
8333 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
8335 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8337 elsif Nkind
(N
) = N_Expression_With_Actions
8338 and then Is_Empty_List
(Actions
(N
))
8340 return Has_No_Obvious_Side_Effects
(Expression
(N
));
8342 elsif Nkind
(N
) in N_Has_Entity
then
8343 return Present
(Entity
(N
))
8344 and then Ekind_In
(Entity
(N
), E_Variable
,
8346 E_Enumeration_Literal
,
8350 and then not Is_Volatile
(Entity
(N
));
8355 end Has_No_Obvious_Side_Effects
;
8357 ------------------------
8358 -- Has_Null_Exclusion --
8359 ------------------------
8361 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
8364 when N_Access_Definition |
8365 N_Access_Function_Definition |
8366 N_Access_Procedure_Definition |
8367 N_Access_To_Object_Definition |
8369 N_Derived_Type_Definition |
8370 N_Function_Specification |
8371 N_Subtype_Declaration
=>
8372 return Null_Exclusion_Present
(N
);
8374 when N_Component_Definition |
8375 N_Formal_Object_Declaration |
8376 N_Object_Renaming_Declaration
=>
8377 if Present
(Subtype_Mark
(N
)) then
8378 return Null_Exclusion_Present
(N
);
8379 else pragma Assert
(Present
(Access_Definition
(N
)));
8380 return Null_Exclusion_Present
(Access_Definition
(N
));
8383 when N_Discriminant_Specification
=>
8384 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
8385 return Null_Exclusion_Present
(Discriminant_Type
(N
));
8387 return Null_Exclusion_Present
(N
);
8390 when N_Object_Declaration
=>
8391 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
8392 return Null_Exclusion_Present
(Object_Definition
(N
));
8394 return Null_Exclusion_Present
(N
);
8397 when N_Parameter_Specification
=>
8398 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
8399 return Null_Exclusion_Present
(Parameter_Type
(N
));
8401 return Null_Exclusion_Present
(N
);
8408 end Has_Null_Exclusion
;
8410 ------------------------
8411 -- Has_Null_Extension --
8412 ------------------------
8414 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
8415 B
: constant Entity_Id
:= Base_Type
(T
);
8420 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
8421 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
8423 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
8425 if Present
(Ext
) then
8426 if Null_Present
(Ext
) then
8429 Comps
:= Component_List
(Ext
);
8431 -- The null component list is rewritten during analysis to
8432 -- include the parent component. Any other component indicates
8433 -- that the extension was not originally null.
8435 return Null_Present
(Comps
)
8436 or else No
(Next
(First
(Component_Items
(Comps
))));
8445 end Has_Null_Extension
;
8447 -------------------------------
8448 -- Has_Overriding_Initialize --
8449 -------------------------------
8451 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
8452 BT
: constant Entity_Id
:= Base_Type
(T
);
8456 if Is_Controlled
(BT
) then
8457 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
8460 elsif Present
(Primitive_Operations
(BT
)) then
8461 P
:= First_Elmt
(Primitive_Operations
(BT
));
8462 while Present
(P
) loop
8464 Init
: constant Entity_Id
:= Node
(P
);
8465 Formal
: constant Entity_Id
:= First_Formal
(Init
);
8467 if Ekind
(Init
) = E_Procedure
8468 and then Chars
(Init
) = Name_Initialize
8469 and then Comes_From_Source
(Init
)
8470 and then Present
(Formal
)
8471 and then Etype
(Formal
) = BT
8472 and then No
(Next_Formal
(Formal
))
8473 and then (Ada_Version
< Ada_2012
8474 or else not Null_Present
(Parent
(Init
)))
8484 -- Here if type itself does not have a non-null Initialize operation:
8485 -- check immediate ancestor.
8487 if Is_Derived_Type
(BT
)
8488 and then Has_Overriding_Initialize
(Etype
(BT
))
8495 end Has_Overriding_Initialize
;
8497 --------------------------------------
8498 -- Has_Preelaborable_Initialization --
8499 --------------------------------------
8501 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
8504 procedure Check_Components
(E
: Entity_Id
);
8505 -- Check component/discriminant chain, sets Has_PE False if a component
8506 -- or discriminant does not meet the preelaborable initialization rules.
8508 ----------------------
8509 -- Check_Components --
8510 ----------------------
8512 procedure Check_Components
(E
: Entity_Id
) is
8516 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
8517 -- Returns True if and only if the expression denoted by N does not
8518 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8520 ---------------------------------
8521 -- Is_Preelaborable_Expression --
8522 ---------------------------------
8524 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
8528 Comp_Type
: Entity_Id
;
8529 Is_Array_Aggr
: Boolean;
8532 if Is_OK_Static_Expression
(N
) then
8535 elsif Nkind
(N
) = N_Null
then
8538 -- Attributes are allowed in general, even if their prefix is a
8539 -- formal type. (It seems that certain attributes known not to be
8540 -- static might not be allowed, but there are no rules to prevent
8543 elsif Nkind
(N
) = N_Attribute_Reference
then
8546 -- The name of a discriminant evaluated within its parent type is
8547 -- defined to be preelaborable (10.2.1(8)). Note that we test for
8548 -- names that denote discriminals as well as discriminants to
8549 -- catch references occurring within init procs.
8551 elsif Is_Entity_Name
(N
)
8553 (Ekind
(Entity
(N
)) = E_Discriminant
8554 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
8555 and then Present
(Discriminal_Link
(Entity
(N
)))))
8559 elsif Nkind
(N
) = N_Qualified_Expression
then
8560 return Is_Preelaborable_Expression
(Expression
(N
));
8562 -- For aggregates we have to check that each of the associations
8563 -- is preelaborable.
8565 elsif Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
8566 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
8568 if Is_Array_Aggr
then
8569 Comp_Type
:= Component_Type
(Etype
(N
));
8572 -- Check the ancestor part of extension aggregates, which must
8573 -- be either the name of a type that has preelaborable init or
8574 -- an expression that is preelaborable.
8576 if Nkind
(N
) = N_Extension_Aggregate
then
8578 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
8581 if Is_Entity_Name
(Anc_Part
)
8582 and then Is_Type
(Entity
(Anc_Part
))
8584 if not Has_Preelaborable_Initialization
8590 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
8596 -- Check positional associations
8598 Exp
:= First
(Expressions
(N
));
8599 while Present
(Exp
) loop
8600 if not Is_Preelaborable_Expression
(Exp
) then
8607 -- Check named associations
8609 Assn
:= First
(Component_Associations
(N
));
8610 while Present
(Assn
) loop
8611 Choice
:= First
(Choices
(Assn
));
8612 while Present
(Choice
) loop
8613 if Is_Array_Aggr
then
8614 if Nkind
(Choice
) = N_Others_Choice
then
8617 elsif Nkind
(Choice
) = N_Range
then
8618 if not Is_OK_Static_Range
(Choice
) then
8622 elsif not Is_OK_Static_Expression
(Choice
) then
8627 Comp_Type
:= Etype
(Choice
);
8633 -- If the association has a <> at this point, then we have
8634 -- to check whether the component's type has preelaborable
8635 -- initialization. Note that this only occurs when the
8636 -- association's corresponding component does not have a
8637 -- default expression, the latter case having already been
8638 -- expanded as an expression for the association.
8640 if Box_Present
(Assn
) then
8641 if not Has_Preelaborable_Initialization
(Comp_Type
) then
8645 -- In the expression case we check whether the expression
8646 -- is preelaborable.
8649 not Is_Preelaborable_Expression
(Expression
(Assn
))
8657 -- If we get here then aggregate as a whole is preelaborable
8661 -- All other cases are not preelaborable
8666 end Is_Preelaborable_Expression
;
8668 -- Start of processing for Check_Components
8671 -- Loop through entities of record or protected type
8674 while Present
(Ent
) loop
8676 -- We are interested only in components and discriminants
8683 -- Get default expression if any. If there is no declaration
8684 -- node, it means we have an internal entity. The parent and
8685 -- tag fields are examples of such entities. For such cases,
8686 -- we just test the type of the entity.
8688 if Present
(Declaration_Node
(Ent
)) then
8689 Exp
:= Expression
(Declaration_Node
(Ent
));
8692 when E_Discriminant
=>
8694 -- Note: for a renamed discriminant, the Declaration_Node
8695 -- may point to the one from the ancestor, and have a
8696 -- different expression, so use the proper attribute to
8697 -- retrieve the expression from the derived constraint.
8699 Exp
:= Discriminant_Default_Value
(Ent
);
8702 goto Check_Next_Entity
;
8705 -- A component has PI if it has no default expression and the
8706 -- component type has PI.
8709 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
8714 -- Require the default expression to be preelaborable
8716 elsif not Is_Preelaborable_Expression
(Exp
) then
8721 <<Check_Next_Entity
>>
8724 end Check_Components
;
8726 -- Start of processing for Has_Preelaborable_Initialization
8729 -- Immediate return if already marked as known preelaborable init. This
8730 -- covers types for which this function has already been called once
8731 -- and returned True (in which case the result is cached), and also
8732 -- types to which a pragma Preelaborable_Initialization applies.
8734 if Known_To_Have_Preelab_Init
(E
) then
8738 -- If the type is a subtype representing a generic actual type, then
8739 -- test whether its base type has preelaborable initialization since
8740 -- the subtype representing the actual does not inherit this attribute
8741 -- from the actual or formal. (but maybe it should???)
8743 if Is_Generic_Actual_Type
(E
) then
8744 return Has_Preelaborable_Initialization
(Base_Type
(E
));
8747 -- All elementary types have preelaborable initialization
8749 if Is_Elementary_Type
(E
) then
8752 -- Array types have PI if the component type has PI
8754 elsif Is_Array_Type
(E
) then
8755 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
8757 -- A derived type has preelaborable initialization if its parent type
8758 -- has preelaborable initialization and (in the case of a derived record
8759 -- extension) if the non-inherited components all have preelaborable
8760 -- initialization. However, a user-defined controlled type with an
8761 -- overriding Initialize procedure does not have preelaborable
8764 elsif Is_Derived_Type
(E
) then
8766 -- If the derived type is a private extension then it doesn't have
8767 -- preelaborable initialization.
8769 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
8773 -- First check whether ancestor type has preelaborable initialization
8775 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
8777 -- If OK, check extension components (if any)
8779 if Has_PE
and then Is_Record_Type
(E
) then
8780 Check_Components
(First_Entity
(E
));
8783 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
8784 -- with a user defined Initialize procedure does not have PI. If
8785 -- the type is untagged, the control primitives come from a component
8786 -- that has already been checked.
8789 and then Is_Controlled
(E
)
8790 and then Is_Tagged_Type
(E
)
8791 and then Has_Overriding_Initialize
(E
)
8796 -- Private types not derived from a type having preelaborable init and
8797 -- that are not marked with pragma Preelaborable_Initialization do not
8798 -- have preelaborable initialization.
8800 elsif Is_Private_Type
(E
) then
8803 -- Record type has PI if it is non private and all components have PI
8805 elsif Is_Record_Type
(E
) then
8807 Check_Components
(First_Entity
(E
));
8809 -- Protected types must not have entries, and components must meet
8810 -- same set of rules as for record components.
8812 elsif Is_Protected_Type
(E
) then
8813 if Has_Entries
(E
) then
8817 Check_Components
(First_Entity
(E
));
8818 Check_Components
(First_Private_Entity
(E
));
8821 -- Type System.Address always has preelaborable initialization
8823 elsif Is_RTE
(E
, RE_Address
) then
8826 -- In all other cases, type does not have preelaborable initialization
8832 -- If type has preelaborable initialization, cache result
8835 Set_Known_To_Have_Preelab_Init
(E
);
8839 end Has_Preelaborable_Initialization
;
8841 ---------------------------
8842 -- Has_Private_Component --
8843 ---------------------------
8845 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
8846 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
8847 Component
: Entity_Id
;
8850 if Error_Posted
(Type_Id
)
8851 or else Error_Posted
(Btype
)
8856 if Is_Class_Wide_Type
(Btype
) then
8857 Btype
:= Root_Type
(Btype
);
8860 if Is_Private_Type
(Btype
) then
8862 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
8865 if No
(Full_View
(Btype
)) then
8866 return not Is_Generic_Type
(Btype
)
8868 not Is_Generic_Type
(Root_Type
(Btype
));
8870 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
8873 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
8877 elsif Is_Array_Type
(Btype
) then
8878 return Has_Private_Component
(Component_Type
(Btype
));
8880 elsif Is_Record_Type
(Btype
) then
8881 Component
:= First_Component
(Btype
);
8882 while Present
(Component
) loop
8883 if Has_Private_Component
(Etype
(Component
)) then
8887 Next_Component
(Component
);
8892 elsif Is_Protected_Type
(Btype
)
8893 and then Present
(Corresponding_Record_Type
(Btype
))
8895 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
8900 end Has_Private_Component
;
8902 ----------------------
8903 -- Has_Signed_Zeros --
8904 ----------------------
8906 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
8908 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
8909 end Has_Signed_Zeros
;
8911 ------------------------------
8912 -- Has_Significant_Contract --
8913 ------------------------------
8915 function Has_Significant_Contract
(Subp_Id
: Entity_Id
) return Boolean is
8916 Subp_Nam
: constant Name_Id
:= Chars
(Subp_Id
);
8919 -- _Finalizer procedure
8921 if Subp_Nam
= Name_uFinalizer
then
8924 -- _Postconditions procedure
8926 elsif Subp_Nam
= Name_uPostconditions
then
8929 -- Predicate function
8931 elsif Ekind
(Subp_Id
) = E_Function
8932 and then Is_Predicate_Function
(Subp_Id
)
8938 elsif Get_TSS_Name
(Subp_Id
) /= TSS_Null
then
8944 end Has_Significant_Contract
;
8946 -----------------------------
8947 -- Has_Static_Array_Bounds --
8948 -----------------------------
8950 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
8951 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
8958 -- Unconstrained types do not have static bounds
8960 if not Is_Constrained
(Typ
) then
8964 -- First treat string literals specially, as the lower bound and length
8965 -- of string literals are not stored like those of arrays.
8967 -- A string literal always has static bounds
8969 if Ekind
(Typ
) = E_String_Literal_Subtype
then
8973 -- Treat all dimensions in turn
8975 Index
:= First_Index
(Typ
);
8976 for Indx
in 1 .. Ndims
loop
8978 -- In case of an illegal index which is not a discrete type, return
8979 -- that the type is not static.
8981 if not Is_Discrete_Type
(Etype
(Index
))
8982 or else Etype
(Index
) = Any_Type
8987 Get_Index_Bounds
(Index
, Low
, High
);
8989 if Error_Posted
(Low
) or else Error_Posted
(High
) then
8993 if Is_OK_Static_Expression
(Low
)
8995 Is_OK_Static_Expression
(High
)
9005 -- If we fall through the loop, all indexes matched
9008 end Has_Static_Array_Bounds
;
9014 function Has_Stream
(T
: Entity_Id
) return Boolean is
9021 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
9024 elsif Is_Array_Type
(T
) then
9025 return Has_Stream
(Component_Type
(T
));
9027 elsif Is_Record_Type
(T
) then
9028 E
:= First_Component
(T
);
9029 while Present
(E
) loop
9030 if Has_Stream
(Etype
(E
)) then
9039 elsif Is_Private_Type
(T
) then
9040 return Has_Stream
(Underlying_Type
(T
));
9051 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
9053 Get_Name_String
(Chars
(E
));
9054 return Name_Buffer
(Name_Len
) = Suffix
;
9061 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
9063 Get_Name_String
(Chars
(E
));
9064 Add_Char_To_Name_Buffer
(Suffix
);
9072 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
9074 pragma Assert
(Has_Suffix
(E
, Suffix
));
9075 Get_Name_String
(Chars
(E
));
9076 Name_Len
:= Name_Len
- 1;
9080 --------------------------
9081 -- Has_Tagged_Component --
9082 --------------------------
9084 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
9088 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
9089 return Has_Tagged_Component
(Underlying_Type
(Typ
));
9091 elsif Is_Array_Type
(Typ
) then
9092 return Has_Tagged_Component
(Component_Type
(Typ
));
9094 elsif Is_Tagged_Type
(Typ
) then
9097 elsif Is_Record_Type
(Typ
) then
9098 Comp
:= First_Component
(Typ
);
9099 while Present
(Comp
) loop
9100 if Has_Tagged_Component
(Etype
(Comp
)) then
9104 Next_Component
(Comp
);
9112 end Has_Tagged_Component
;
9114 ----------------------------
9115 -- Has_Volatile_Component --
9116 ----------------------------
9118 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
9122 if Has_Volatile_Components
(Typ
) then
9125 elsif Is_Array_Type
(Typ
) then
9126 return Is_Volatile
(Component_Type
(Typ
));
9128 elsif Is_Record_Type
(Typ
) then
9129 Comp
:= First_Component
(Typ
);
9130 while Present
(Comp
) loop
9131 if Is_Volatile_Object
(Comp
) then
9135 Comp
:= Next_Component
(Comp
);
9140 end Has_Volatile_Component
;
9142 -------------------------
9143 -- Implementation_Kind --
9144 -------------------------
9146 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
9147 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
9150 pragma Assert
(Present
(Impl_Prag
));
9151 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
9152 return Chars
(Get_Pragma_Arg
(Arg
));
9153 end Implementation_Kind
;
9155 --------------------------
9156 -- Implements_Interface --
9157 --------------------------
9159 function Implements_Interface
9160 (Typ_Ent
: Entity_Id
;
9161 Iface_Ent
: Entity_Id
;
9162 Exclude_Parents
: Boolean := False) return Boolean
9164 Ifaces_List
: Elist_Id
;
9166 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
9167 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
9170 if Is_Class_Wide_Type
(Typ
) then
9171 Typ
:= Root_Type
(Typ
);
9174 if not Has_Interfaces
(Typ
) then
9178 if Is_Class_Wide_Type
(Iface
) then
9179 Iface
:= Root_Type
(Iface
);
9182 Collect_Interfaces
(Typ
, Ifaces_List
);
9184 Elmt
:= First_Elmt
(Ifaces_List
);
9185 while Present
(Elmt
) loop
9186 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
9187 and then Exclude_Parents
9191 elsif Node
(Elmt
) = Iface
then
9199 end Implements_Interface
;
9201 ------------------------------------
9202 -- In_Assertion_Expression_Pragma --
9203 ------------------------------------
9205 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
9207 Prag
: Node_Id
:= Empty
;
9210 -- Climb the parent chain looking for an enclosing pragma
9213 while Present
(Par
) loop
9214 if Nkind
(Par
) = N_Pragma
then
9218 -- Precondition-like pragmas are expanded into if statements, check
9219 -- the original node instead.
9221 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
9222 Prag
:= Original_Node
(Par
);
9225 -- The expansion of attribute 'Old generates a constant to capture
9226 -- the result of the prefix. If the parent traversal reaches
9227 -- one of these constants, then the node technically came from a
9228 -- postcondition-like pragma. Note that the Ekind is not tested here
9229 -- because N may be the expression of an object declaration which is
9230 -- currently being analyzed. Such objects carry Ekind of E_Void.
9232 elsif Nkind
(Par
) = N_Object_Declaration
9233 and then Constant_Present
(Par
)
9234 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
9238 -- Prevent the search from going too far
9240 elsif Is_Body_Or_Package_Declaration
(Par
) then
9244 Par
:= Parent
(Par
);
9249 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
9250 end In_Assertion_Expression_Pragma
;
9256 function In_Instance
return Boolean is
9257 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
9262 while Present
(S
) and then S
/= Standard_Standard
loop
9263 if Ekind_In
(S
, E_Function
, E_Package
, E_Procedure
)
9264 and then Is_Generic_Instance
(S
)
9266 -- A child instance is always compiled in the context of a parent
9267 -- instance. Nevertheless, the actuals are not analyzed in an
9268 -- instance context. We detect this case by examining the current
9269 -- compilation unit, which must be a child instance, and checking
9270 -- that it is not currently on the scope stack.
9272 if Is_Child_Unit
(Curr_Unit
)
9273 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
9274 N_Package_Instantiation
9275 and then not In_Open_Scopes
(Curr_Unit
)
9289 ----------------------
9290 -- In_Instance_Body --
9291 ----------------------
9293 function In_Instance_Body
return Boolean is
9298 while Present
(S
) and then S
/= Standard_Standard
loop
9299 if Ekind_In
(S
, E_Function
, E_Procedure
)
9300 and then Is_Generic_Instance
(S
)
9304 elsif Ekind
(S
) = E_Package
9305 and then In_Package_Body
(S
)
9306 and then Is_Generic_Instance
(S
)
9315 end In_Instance_Body
;
9317 -----------------------------
9318 -- In_Instance_Not_Visible --
9319 -----------------------------
9321 function In_Instance_Not_Visible
return Boolean is
9326 while Present
(S
) and then S
/= Standard_Standard
loop
9327 if Ekind_In
(S
, E_Function
, E_Procedure
)
9328 and then Is_Generic_Instance
(S
)
9332 elsif Ekind
(S
) = E_Package
9333 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
9334 and then Is_Generic_Instance
(S
)
9343 end In_Instance_Not_Visible
;
9345 ------------------------------
9346 -- In_Instance_Visible_Part --
9347 ------------------------------
9349 function In_Instance_Visible_Part
return Boolean is
9354 while Present
(S
) and then S
/= Standard_Standard
loop
9355 if Ekind
(S
) = E_Package
9356 and then Is_Generic_Instance
(S
)
9357 and then not In_Package_Body
(S
)
9358 and then not In_Private_Part
(S
)
9367 end In_Instance_Visible_Part
;
9369 ---------------------
9370 -- In_Package_Body --
9371 ---------------------
9373 function In_Package_Body
return Boolean is
9378 while Present
(S
) and then S
/= Standard_Standard
loop
9379 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
9387 end In_Package_Body
;
9389 --------------------------------
9390 -- In_Parameter_Specification --
9391 --------------------------------
9393 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
9398 while Present
(PN
) loop
9399 if Nkind
(PN
) = N_Parameter_Specification
then
9407 end In_Parameter_Specification
;
9409 --------------------------
9410 -- In_Pragma_Expression --
9411 --------------------------
9413 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
9420 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
9426 end In_Pragma_Expression
;
9428 -------------------------------------
9429 -- In_Reverse_Storage_Order_Object --
9430 -------------------------------------
9432 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
9434 Btyp
: Entity_Id
:= Empty
;
9437 -- Climb up indexed components
9441 case Nkind
(Pref
) is
9442 when N_Selected_Component
=>
9443 Pref
:= Prefix
(Pref
);
9446 when N_Indexed_Component
=>
9447 Pref
:= Prefix
(Pref
);
9455 if Present
(Pref
) then
9456 Btyp
:= Base_Type
(Etype
(Pref
));
9459 return Present
(Btyp
)
9460 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
9461 and then Reverse_Storage_Order
(Btyp
);
9462 end In_Reverse_Storage_Order_Object
;
9464 --------------------------------------
9465 -- In_Subprogram_Or_Concurrent_Unit --
9466 --------------------------------------
9468 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
9473 -- Use scope chain to check successively outer scopes
9479 if K
in Subprogram_Kind
9480 or else K
in Concurrent_Kind
9481 or else K
in Generic_Subprogram_Kind
9485 elsif E
= Standard_Standard
then
9491 end In_Subprogram_Or_Concurrent_Unit
;
9493 ---------------------
9494 -- In_Visible_Part --
9495 ---------------------
9497 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
9499 return Is_Package_Or_Generic_Package
(Scope_Id
)
9500 and then In_Open_Scopes
(Scope_Id
)
9501 and then not In_Package_Body
(Scope_Id
)
9502 and then not In_Private_Part
(Scope_Id
);
9503 end In_Visible_Part
;
9505 --------------------------------
9506 -- Incomplete_Or_Partial_View --
9507 --------------------------------
9509 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
9510 function Inspect_Decls
9512 Taft
: Boolean := False) return Entity_Id
;
9513 -- Check whether a declarative region contains the incomplete or partial
9520 function Inspect_Decls
9522 Taft
: Boolean := False) return Entity_Id
9528 Decl
:= First
(Decls
);
9529 while Present
(Decl
) loop
9533 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
9534 Match
:= Defining_Identifier
(Decl
);
9538 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
9539 N_Private_Type_Declaration
)
9541 Match
:= Defining_Identifier
(Decl
);
9546 and then Present
(Full_View
(Match
))
9547 and then Full_View
(Match
) = Id
9562 -- Start of processing for Incomplete_Or_Partial_View
9565 -- Deferred constant or incomplete type case
9567 Prev
:= Current_Entity_In_Scope
(Id
);
9570 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
9571 and then Present
(Full_View
(Prev
))
9572 and then Full_View
(Prev
) = Id
9577 -- Private or Taft amendment type case
9580 Pkg
: constant Entity_Id
:= Scope
(Id
);
9581 Pkg_Decl
: Node_Id
:= Pkg
;
9584 if Present
(Pkg
) and then Ekind
(Pkg
) = E_Package
then
9585 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
9586 Pkg_Decl
:= Parent
(Pkg_Decl
);
9589 -- It is knows that Typ has a private view, look for it in the
9590 -- visible declarations of the enclosing scope. A special case
9591 -- of this is when the two views have been exchanged - the full
9592 -- appears earlier than the private.
9594 if Has_Private_Declaration
(Id
) then
9595 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
9597 -- Exchanged view case, look in the private declarations
9600 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
9605 -- Otherwise if this is the package body, then Typ is a potential
9606 -- Taft amendment type. The incomplete view should be located in
9607 -- the private declarations of the enclosing scope.
9609 elsif In_Package_Body
(Pkg
) then
9610 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
9615 -- The type has no incomplete or private view
9618 end Incomplete_Or_Partial_View
;
9620 -----------------------------------------
9621 -- Inherit_Default_Init_Cond_Procedure --
9622 -----------------------------------------
9624 procedure Inherit_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
9625 Par_Typ
: constant Entity_Id
:= Etype
(Typ
);
9628 -- A derived type inherits the default initial condition procedure of
9631 if No
(Default_Init_Cond_Procedure
(Typ
)) then
9632 Set_Default_Init_Cond_Procedure
9633 (Typ
, Default_Init_Cond_Procedure
(Par_Typ
));
9635 end Inherit_Default_Init_Cond_Procedure
;
9637 ----------------------------
9638 -- Inherit_Rep_Item_Chain --
9639 ----------------------------
9641 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
9642 From_Item
: constant Node_Id
:= First_Rep_Item
(From_Typ
);
9643 Item
: Node_Id
:= Empty
;
9644 Last_Item
: Node_Id
:= Empty
;
9647 -- Reach the end of the destination type's chain (if any) and capture
9650 Item
:= First_Rep_Item
(Typ
);
9651 while Present
(Item
) loop
9653 -- Do not inherit a chain that has been inherited already
9655 if Item
= From_Item
then
9660 Item
:= Next_Rep_Item
(Item
);
9663 -- When the destination type has a rep item chain, the chain of the
9664 -- source type is appended to it.
9666 if Present
(Last_Item
) then
9667 Set_Next_Rep_Item
(Last_Item
, From_Item
);
9669 -- Otherwise the destination type directly inherits the rep item chain
9670 -- of the source type (if any).
9673 Set_First_Rep_Item
(Typ
, From_Item
);
9675 end Inherit_Rep_Item_Chain
;
9677 ---------------------------------
9678 -- Inherit_Subprogram_Contract --
9679 ---------------------------------
9681 procedure Inherit_Subprogram_Contract
9683 From_Subp
: Entity_Id
)
9685 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
);
9686 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
9689 --------------------
9690 -- Inherit_Pragma --
9691 --------------------
9693 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
) is
9694 Prag
: constant Node_Id
:= Get_Pragma
(From_Subp
, Prag_Id
);
9698 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
9699 -- chains, therefore the node must be replicated. The new pragma is
9700 -- flagged is inherited for distrinction purposes.
9702 if Present
(Prag
) then
9703 New_Prag
:= New_Copy_Tree
(Prag
);
9704 Set_Is_Inherited
(New_Prag
);
9706 Add_Contract_Item
(New_Prag
, Subp
);
9710 -- Start of processing for Inherit_Subprogram_Contract
9713 -- Inheritance is carried out only when both entities are subprograms
9716 if Is_Subprogram_Or_Generic_Subprogram
(Subp
)
9717 and then Is_Subprogram_Or_Generic_Subprogram
(From_Subp
)
9718 and then Present
(Contract
(From_Subp
))
9720 Inherit_Pragma
(Pragma_Extensions_Visible
);
9722 end Inherit_Subprogram_Contract
;
9724 ---------------------------------
9725 -- Insert_Explicit_Dereference --
9726 ---------------------------------
9728 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
9729 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
9730 Ent
: Entity_Id
:= Empty
;
9737 Save_Interps
(N
, New_Prefix
);
9740 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
9741 Prefix
=> New_Prefix
));
9743 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
9745 if Is_Overloaded
(New_Prefix
) then
9747 -- The dereference is also overloaded, and its interpretations are
9748 -- the designated types of the interpretations of the original node.
9750 Set_Etype
(N
, Any_Type
);
9752 Get_First_Interp
(New_Prefix
, I
, It
);
9753 while Present
(It
.Nam
) loop
9756 if Is_Access_Type
(T
) then
9757 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
9760 Get_Next_Interp
(I
, It
);
9766 -- Prefix is unambiguous: mark the original prefix (which might
9767 -- Come_From_Source) as a reference, since the new (relocated) one
9768 -- won't be taken into account.
9770 if Is_Entity_Name
(New_Prefix
) then
9771 Ent
:= Entity
(New_Prefix
);
9774 -- For a retrieval of a subcomponent of some composite object,
9775 -- retrieve the ultimate entity if there is one.
9777 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
9778 N_Indexed_Component
)
9780 Pref
:= Prefix
(New_Prefix
);
9781 while Present
(Pref
)
9782 and then Nkind_In
(Pref
, N_Selected_Component
,
9783 N_Indexed_Component
)
9785 Pref
:= Prefix
(Pref
);
9788 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
9789 Ent
:= Entity
(Pref
);
9793 -- Place the reference on the entity node
9795 if Present
(Ent
) then
9796 Generate_Reference
(Ent
, Pref
);
9799 end Insert_Explicit_Dereference
;
9801 ------------------------------------------
9802 -- Inspect_Deferred_Constant_Completion --
9803 ------------------------------------------
9805 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
9809 Decl
:= First
(Decls
);
9810 while Present
(Decl
) loop
9812 -- Deferred constant signature
9814 if Nkind
(Decl
) = N_Object_Declaration
9815 and then Constant_Present
(Decl
)
9816 and then No
(Expression
(Decl
))
9818 -- No need to check internally generated constants
9820 and then Comes_From_Source
(Decl
)
9822 -- The constant is not completed. A full object declaration or a
9823 -- pragma Import complete a deferred constant.
9825 and then not Has_Completion
(Defining_Identifier
(Decl
))
9828 ("constant declaration requires initialization expression",
9829 Defining_Identifier
(Decl
));
9832 Decl
:= Next
(Decl
);
9834 end Inspect_Deferred_Constant_Completion
;
9836 -----------------------------
9837 -- Install_Generic_Formals --
9838 -----------------------------
9840 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
9844 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
9846 E
:= First_Entity
(Subp_Id
);
9847 while Present
(E
) loop
9851 end Install_Generic_Formals
;
9853 -----------------------------
9854 -- Is_Actual_Out_Parameter --
9855 -----------------------------
9857 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
9861 Find_Actual
(N
, Formal
, Call
);
9862 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
9863 end Is_Actual_Out_Parameter
;
9865 -------------------------
9866 -- Is_Actual_Parameter --
9867 -------------------------
9869 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
9870 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
9874 when N_Parameter_Association
=>
9875 return N
= Explicit_Actual_Parameter
(Parent
(N
));
9877 when N_Subprogram_Call
=>
9878 return Is_List_Member
(N
)
9880 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
9885 end Is_Actual_Parameter
;
9887 --------------------------------
9888 -- Is_Actual_Tagged_Parameter --
9889 --------------------------------
9891 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
9895 Find_Actual
(N
, Formal
, Call
);
9896 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
9897 end Is_Actual_Tagged_Parameter
;
9899 ---------------------
9900 -- Is_Aliased_View --
9901 ---------------------
9903 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
9907 if Is_Entity_Name
(Obj
) then
9914 or else (Present
(Renamed_Object
(E
))
9915 and then Is_Aliased_View
(Renamed_Object
(E
)))))
9917 or else ((Is_Formal
(E
)
9918 or else Ekind_In
(E
, E_Generic_In_Out_Parameter
,
9919 E_Generic_In_Parameter
))
9920 and then Is_Tagged_Type
(Etype
(E
)))
9922 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
9924 -- Current instance of type, either directly or as rewritten
9925 -- reference to the current object.
9927 or else (Is_Entity_Name
(Original_Node
(Obj
))
9928 and then Present
(Entity
(Original_Node
(Obj
)))
9929 and then Is_Type
(Entity
(Original_Node
(Obj
))))
9931 or else (Is_Type
(E
) and then E
= Current_Scope
)
9933 or else (Is_Incomplete_Or_Private_Type
(E
)
9934 and then Full_View
(E
) = Current_Scope
)
9936 -- Ada 2012 AI05-0053: the return object of an extended return
9937 -- statement is aliased if its type is immutably limited.
9939 or else (Is_Return_Object
(E
)
9940 and then Is_Limited_View
(Etype
(E
)));
9942 elsif Nkind
(Obj
) = N_Selected_Component
then
9943 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
9945 elsif Nkind
(Obj
) = N_Indexed_Component
then
9946 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
9948 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
9949 and then Has_Aliased_Components
9950 (Designated_Type
(Etype
(Prefix
(Obj
)))));
9952 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
9953 return Is_Tagged_Type
(Etype
(Obj
))
9954 and then Is_Aliased_View
(Expression
(Obj
));
9956 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
9957 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
9962 end Is_Aliased_View
;
9964 -------------------------
9965 -- Is_Ancestor_Package --
9966 -------------------------
9968 function Is_Ancestor_Package
9970 E2
: Entity_Id
) return Boolean
9976 while Present
(Par
) and then Par
/= Standard_Standard
loop
9985 end Is_Ancestor_Package
;
9987 ----------------------
9988 -- Is_Atomic_Object --
9989 ----------------------
9991 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
9993 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
9994 -- Determines if given object has atomic components
9996 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
9997 -- If prefix is an implicit dereference, examine designated type
9999 ----------------------
10000 -- Is_Atomic_Prefix --
10001 ----------------------
10003 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
10005 if Is_Access_Type
(Etype
(N
)) then
10007 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
10009 return Object_Has_Atomic_Components
(N
);
10011 end Is_Atomic_Prefix
;
10013 ----------------------------------
10014 -- Object_Has_Atomic_Components --
10015 ----------------------------------
10017 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
10019 if Has_Atomic_Components
(Etype
(N
))
10020 or else Is_Atomic
(Etype
(N
))
10024 elsif Is_Entity_Name
(N
)
10025 and then (Has_Atomic_Components
(Entity
(N
))
10026 or else Is_Atomic
(Entity
(N
)))
10030 elsif Nkind
(N
) = N_Selected_Component
10031 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
10035 elsif Nkind
(N
) = N_Indexed_Component
10036 or else Nkind
(N
) = N_Selected_Component
10038 return Is_Atomic_Prefix
(Prefix
(N
));
10043 end Object_Has_Atomic_Components
;
10045 -- Start of processing for Is_Atomic_Object
10048 -- Predicate is not relevant to subprograms
10050 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
10053 elsif Is_Atomic
(Etype
(N
))
10054 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
10058 elsif Nkind
(N
) = N_Selected_Component
10059 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
10063 elsif Nkind
(N
) = N_Indexed_Component
10064 or else Nkind
(N
) = N_Selected_Component
10066 return Is_Atomic_Prefix
(Prefix
(N
));
10071 end Is_Atomic_Object
;
10073 -------------------------
10074 -- Is_Attribute_Result --
10075 -------------------------
10077 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
10079 return Nkind
(N
) = N_Attribute_Reference
10080 and then Attribute_Name
(N
) = Name_Result
;
10081 end Is_Attribute_Result
;
10083 ------------------------------------
10084 -- Is_Body_Or_Package_Declaration --
10085 ------------------------------------
10087 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
10089 return Nkind_In
(N
, N_Entry_Body
,
10091 N_Package_Declaration
,
10095 end Is_Body_Or_Package_Declaration
;
10097 -----------------------
10098 -- Is_Bounded_String --
10099 -----------------------
10101 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
10102 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
10105 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10106 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10107 -- be True for all the Bounded_String types in instances of the
10108 -- Generic_Bounded_Length generics, and for types derived from those.
10110 return Present
(Under
)
10111 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
10112 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
10113 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
10114 end Is_Bounded_String
;
10116 -------------------------
10117 -- Is_Child_Or_Sibling --
10118 -------------------------
10120 function Is_Child_Or_Sibling
10121 (Pack_1
: Entity_Id
;
10122 Pack_2
: Entity_Id
) return Boolean
10124 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
10125 -- Given an arbitrary package, return the number of "climbs" necessary
10126 -- to reach scope Standard_Standard.
10128 procedure Equalize_Depths
10129 (Pack
: in out Entity_Id
;
10130 Depth
: in out Nat
;
10131 Depth_To_Reach
: Nat
);
10132 -- Given an arbitrary package, its depth and a target depth to reach,
10133 -- climb the scope chain until the said depth is reached. The pointer
10134 -- to the package and its depth a modified during the climb.
10136 ----------------------------
10137 -- Distance_From_Standard --
10138 ----------------------------
10140 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
10147 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
10149 Scop
:= Scope
(Scop
);
10153 end Distance_From_Standard
;
10155 ---------------------
10156 -- Equalize_Depths --
10157 ---------------------
10159 procedure Equalize_Depths
10160 (Pack
: in out Entity_Id
;
10161 Depth
: in out Nat
;
10162 Depth_To_Reach
: Nat
)
10165 -- The package must be at a greater or equal depth
10167 if Depth
< Depth_To_Reach
then
10168 raise Program_Error
;
10171 -- Climb the scope chain until the desired depth is reached
10173 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
10174 Pack
:= Scope
(Pack
);
10175 Depth
:= Depth
- 1;
10177 end Equalize_Depths
;
10181 P_1
: Entity_Id
:= Pack_1
;
10182 P_1_Child
: Boolean := False;
10183 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
10184 P_2
: Entity_Id
:= Pack_2
;
10185 P_2_Child
: Boolean := False;
10186 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
10188 -- Start of processing for Is_Child_Or_Sibling
10192 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
10194 -- Both packages denote the same entity, therefore they cannot be
10195 -- children or siblings.
10200 -- One of the packages is at a deeper level than the other. Note that
10201 -- both may still come from differen hierarchies.
10209 elsif P_1_Depth
> P_2_Depth
then
10212 Depth
=> P_1_Depth
,
10213 Depth_To_Reach
=> P_2_Depth
);
10222 elsif P_2_Depth
> P_1_Depth
then
10225 Depth
=> P_2_Depth
,
10226 Depth_To_Reach
=> P_1_Depth
);
10230 -- At this stage the package pointers have been elevated to the same
10231 -- depth. If the related entities are the same, then one package is a
10232 -- potential child of the other:
10236 -- X became P_1 P_2 or vica versa
10242 return Is_Child_Unit
(Pack_1
);
10244 else pragma Assert
(P_2_Child
);
10245 return Is_Child_Unit
(Pack_2
);
10248 -- The packages may come from the same package chain or from entirely
10249 -- different hierarcies. To determine this, climb the scope stack until
10250 -- a common root is found.
10252 -- (root) (root 1) (root 2)
10257 while Present
(P_1
) and then Present
(P_2
) loop
10259 -- The two packages may be siblings
10262 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
10265 P_1
:= Scope
(P_1
);
10266 P_2
:= Scope
(P_2
);
10271 end Is_Child_Or_Sibling
;
10273 -----------------------------
10274 -- Is_Concurrent_Interface --
10275 -----------------------------
10277 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
10279 return Is_Interface
(T
)
10281 (Is_Protected_Interface
(T
)
10282 or else Is_Synchronized_Interface
(T
)
10283 or else Is_Task_Interface
(T
));
10284 end Is_Concurrent_Interface
;
10286 ---------------------------
10287 -- Is_Container_Element --
10288 ---------------------------
10290 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
10291 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
10292 Pref
: constant Node_Id
:= Prefix
(Exp
);
10295 -- Call to an indexing aspect
10297 Cont_Typ
: Entity_Id
;
10298 -- The type of the container being accessed
10300 Elem_Typ
: Entity_Id
;
10301 -- Its element type
10303 Indexing
: Entity_Id
;
10304 Is_Const
: Boolean;
10305 -- Indicates that constant indexing is used, and the element is thus
10308 Ref_Typ
: Entity_Id
;
10309 -- The reference type returned by the indexing operation
10312 -- If C is a container, in a context that imposes the element type of
10313 -- that container, the indexing notation C (X) is rewritten as:
10315 -- Indexing (C, X).Discr.all
10317 -- where Indexing is one of the indexing aspects of the container.
10318 -- If the context does not require a reference, the construct can be
10323 -- First, verify that the construct has the proper form
10325 if not Expander_Active
then
10328 elsif Nkind
(Pref
) /= N_Selected_Component
then
10331 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
10335 Call
:= Prefix
(Pref
);
10336 Ref_Typ
:= Etype
(Call
);
10339 if not Has_Implicit_Dereference
(Ref_Typ
)
10340 or else No
(First
(Parameter_Associations
(Call
)))
10341 or else not Is_Entity_Name
(Name
(Call
))
10346 -- Retrieve type of container object, and its iterator aspects
10348 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
10349 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
10352 if No
(Indexing
) then
10354 -- Container should have at least one indexing operation
10358 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
10360 -- This may be a variable indexing operation
10362 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
10365 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
10374 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
10376 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
10380 -- Check that the expression is not the target of an assignment, in
10381 -- which case the rewriting is not possible.
10383 if not Is_Const
then
10389 while Present
(Par
)
10391 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
10392 and then Par
= Name
(Parent
(Par
))
10396 -- A renaming produces a reference, and the transformation
10399 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
10403 (Nkind
(Parent
(Par
)), N_Function_Call
,
10404 N_Procedure_Call_Statement
,
10405 N_Entry_Call_Statement
)
10407 -- Check that the element is not part of an actual for an
10408 -- in-out parameter.
10415 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
10416 A
:= First
(Parameter_Associations
(Parent
(Par
)));
10417 while Present
(F
) loop
10418 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
10427 -- E_In_Parameter in a call: element is not modified.
10432 Par
:= Parent
(Par
);
10437 -- The expression has the proper form and the context requires the
10438 -- element type. Retrieve the Element function of the container and
10439 -- rewrite the construct as a call to it.
10445 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
10446 while Present
(Op
) loop
10447 exit when Chars
(Node
(Op
)) = Name_Element
;
10456 Make_Function_Call
(Loc
,
10457 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
10458 Parameter_Associations
=> Parameter_Associations
(Call
)));
10459 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
10463 end Is_Container_Element
;
10465 -----------------------
10466 -- Is_Constant_Bound --
10467 -----------------------
10469 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
10471 if Compile_Time_Known_Value
(Exp
) then
10474 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
10475 return Is_Constant_Object
(Entity
(Exp
))
10476 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
10478 elsif Nkind
(Exp
) in N_Binary_Op
then
10479 return Is_Constant_Bound
(Left_Opnd
(Exp
))
10480 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
10481 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
10486 end Is_Constant_Bound
;
10488 --------------------------------------
10489 -- Is_Controlling_Limited_Procedure --
10490 --------------------------------------
10492 function Is_Controlling_Limited_Procedure
10493 (Proc_Nam
: Entity_Id
) return Boolean
10495 Param_Typ
: Entity_Id
:= Empty
;
10498 if Ekind
(Proc_Nam
) = E_Procedure
10499 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
10501 Param_Typ
:= Etype
(Parameter_Type
(First
(
10502 Parameter_Specifications
(Parent
(Proc_Nam
)))));
10504 -- In this case where an Itype was created, the procedure call has been
10507 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
10508 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
10510 Present
(Parameter_Associations
10511 (Associated_Node_For_Itype
(Proc_Nam
)))
10514 Etype
(First
(Parameter_Associations
10515 (Associated_Node_For_Itype
(Proc_Nam
))));
10518 if Present
(Param_Typ
) then
10520 Is_Interface
(Param_Typ
)
10521 and then Is_Limited_Record
(Param_Typ
);
10525 end Is_Controlling_Limited_Procedure
;
10527 -----------------------------
10528 -- Is_CPP_Constructor_Call --
10529 -----------------------------
10531 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
10533 return Nkind
(N
) = N_Function_Call
10534 and then Is_CPP_Class
(Etype
(Etype
(N
)))
10535 and then Is_Constructor
(Entity
(Name
(N
)))
10536 and then Is_Imported
(Entity
(Name
(N
)));
10537 end Is_CPP_Constructor_Call
;
10539 --------------------
10540 -- Is_Declaration --
10541 --------------------
10543 function Is_Declaration
(N
: Node_Id
) return Boolean is
10546 when N_Abstract_Subprogram_Declaration |
10547 N_Exception_Declaration |
10548 N_Exception_Renaming_Declaration |
10549 N_Full_Type_Declaration |
10550 N_Generic_Function_Renaming_Declaration |
10551 N_Generic_Package_Declaration |
10552 N_Generic_Package_Renaming_Declaration |
10553 N_Generic_Procedure_Renaming_Declaration |
10554 N_Generic_Subprogram_Declaration |
10555 N_Number_Declaration |
10556 N_Object_Declaration |
10557 N_Object_Renaming_Declaration |
10558 N_Package_Declaration |
10559 N_Package_Renaming_Declaration |
10560 N_Private_Extension_Declaration |
10561 N_Private_Type_Declaration |
10562 N_Subprogram_Declaration |
10563 N_Subprogram_Renaming_Declaration |
10564 N_Subtype_Declaration
=>
10570 end Is_Declaration
;
10576 function Is_Delegate
(T
: Entity_Id
) return Boolean is
10577 Desig_Type
: Entity_Id
;
10580 if VM_Target
/= CLI_Target
then
10584 -- Access-to-subprograms are delegates in CIL
10586 if Ekind
(T
) = E_Access_Subprogram_Type
then
10590 if not Is_Access_Type
(T
) then
10592 -- A delegate is a managed pointer. If no designated type is defined
10593 -- it means that it's not a delegate.
10598 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
10600 if not Is_Tagged_Type
(Desig_Type
) then
10604 -- Test if the type is inherited from [mscorlib]System.Delegate
10606 while Etype
(Desig_Type
) /= Desig_Type
loop
10607 if Chars
(Scope
(Desig_Type
)) /= No_Name
10608 and then Is_Imported
(Scope
(Desig_Type
))
10609 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
10614 Desig_Type
:= Etype
(Desig_Type
);
10620 ----------------------------------------------
10621 -- Is_Dependent_Component_Of_Mutable_Object --
10622 ----------------------------------------------
10624 function Is_Dependent_Component_Of_Mutable_Object
10625 (Object
: Node_Id
) return Boolean
10627 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
10628 -- Returns True if and only if Comp is declared within a variant part
10630 --------------------------------
10631 -- Is_Declared_Within_Variant --
10632 --------------------------------
10634 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
10635 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
10636 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
10638 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
10639 end Is_Declared_Within_Variant
;
10642 Prefix_Type
: Entity_Id
;
10643 P_Aliased
: Boolean := False;
10646 Deref
: Node_Id
:= Object
;
10647 -- Dereference node, in something like X.all.Y(2)
10649 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
10652 -- Find the dereference node if any
10654 while Nkind_In
(Deref
, N_Indexed_Component
,
10655 N_Selected_Component
,
10658 Deref
:= Prefix
(Deref
);
10661 -- Ada 2005: If we have a component or slice of a dereference,
10662 -- something like X.all.Y (2), and the type of X is access-to-constant,
10663 -- Is_Variable will return False, because it is indeed a constant
10664 -- view. But it might be a view of a variable object, so we want the
10665 -- following condition to be True in that case.
10667 if Is_Variable
(Object
)
10668 or else (Ada_Version
>= Ada_2005
10669 and then Nkind
(Deref
) = N_Explicit_Dereference
)
10671 if Nkind
(Object
) = N_Selected_Component
then
10672 P
:= Prefix
(Object
);
10673 Prefix_Type
:= Etype
(P
);
10675 if Is_Entity_Name
(P
) then
10676 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
10677 Prefix_Type
:= Base_Type
(Prefix_Type
);
10680 if Is_Aliased
(Entity
(P
)) then
10684 -- A discriminant check on a selected component may be expanded
10685 -- into a dereference when removing side-effects. Recover the
10686 -- original node and its type, which may be unconstrained.
10688 elsif Nkind
(P
) = N_Explicit_Dereference
10689 and then not (Comes_From_Source
(P
))
10691 P
:= Original_Node
(P
);
10692 Prefix_Type
:= Etype
(P
);
10695 -- Check for prefix being an aliased component???
10701 -- A heap object is constrained by its initial value
10703 -- Ada 2005 (AI-363): Always assume the object could be mutable in
10704 -- the dereferenced case, since the access value might denote an
10705 -- unconstrained aliased object, whereas in Ada 95 the designated
10706 -- object is guaranteed to be constrained. A worst-case assumption
10707 -- has to apply in Ada 2005 because we can't tell at compile
10708 -- time whether the object is "constrained by its initial value"
10709 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
10710 -- rules (these rules are acknowledged to need fixing).
10712 if Ada_Version
< Ada_2005
then
10713 if Is_Access_Type
(Prefix_Type
)
10714 or else Nkind
(P
) = N_Explicit_Dereference
10719 else pragma Assert
(Ada_Version
>= Ada_2005
);
10720 if Is_Access_Type
(Prefix_Type
) then
10722 -- If the access type is pool-specific, and there is no
10723 -- constrained partial view of the designated type, then the
10724 -- designated object is known to be constrained.
10726 if Ekind
(Prefix_Type
) = E_Access_Type
10727 and then not Object_Type_Has_Constrained_Partial_View
10728 (Typ
=> Designated_Type
(Prefix_Type
),
10729 Scop
=> Current_Scope
)
10733 -- Otherwise (general access type, or there is a constrained
10734 -- partial view of the designated type), we need to check
10735 -- based on the designated type.
10738 Prefix_Type
:= Designated_Type
(Prefix_Type
);
10744 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
10746 -- As per AI-0017, the renaming is illegal in a generic body, even
10747 -- if the subtype is indefinite.
10749 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
10751 if not Is_Constrained
(Prefix_Type
)
10752 and then (not Is_Indefinite_Subtype
(Prefix_Type
)
10754 (Is_Generic_Type
(Prefix_Type
)
10755 and then Ekind
(Current_Scope
) = E_Generic_Package
10756 and then In_Package_Body
(Current_Scope
)))
10758 and then (Is_Declared_Within_Variant
(Comp
)
10759 or else Has_Discriminant_Dependent_Constraint
(Comp
))
10760 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
10764 -- If the prefix is of an access type at this point, then we want
10765 -- to return False, rather than calling this function recursively
10766 -- on the access object (which itself might be a discriminant-
10767 -- dependent component of some other object, but that isn't
10768 -- relevant to checking the object passed to us). This avoids
10769 -- issuing wrong errors when compiling with -gnatc, where there
10770 -- can be implicit dereferences that have not been expanded.
10772 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
10777 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10780 elsif Nkind
(Object
) = N_Indexed_Component
10781 or else Nkind
(Object
) = N_Slice
10783 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
10785 -- A type conversion that Is_Variable is a view conversion:
10786 -- go back to the denoted object.
10788 elsif Nkind
(Object
) = N_Type_Conversion
then
10790 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
10795 end Is_Dependent_Component_Of_Mutable_Object
;
10797 ---------------------
10798 -- Is_Dereferenced --
10799 ---------------------
10801 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
10802 P
: constant Node_Id
:= Parent
(N
);
10804 return Nkind_In
(P
, N_Selected_Component
,
10805 N_Explicit_Dereference
,
10806 N_Indexed_Component
,
10808 and then Prefix
(P
) = N
;
10809 end Is_Dereferenced
;
10811 ----------------------
10812 -- Is_Descendent_Of --
10813 ----------------------
10815 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
10820 pragma Assert
(Nkind
(T1
) in N_Entity
);
10821 pragma Assert
(Nkind
(T2
) in N_Entity
);
10823 T
:= Base_Type
(T1
);
10825 -- Immediate return if the types match
10830 -- Comment needed here ???
10832 elsif Ekind
(T
) = E_Class_Wide_Type
then
10833 return Etype
(T
) = T2
;
10841 -- Done if we found the type we are looking for
10846 -- Done if no more derivations to check
10853 -- Following test catches error cases resulting from prev errors
10855 elsif No
(Etyp
) then
10858 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
10861 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
10865 T
:= Base_Type
(Etyp
);
10868 end Is_Descendent_Of
;
10870 -----------------------------
10871 -- Is_Effectively_Volatile --
10872 -----------------------------
10874 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
10876 if Is_Type
(Id
) then
10878 -- An arbitrary type is effectively volatile when it is subject to
10879 -- pragma Atomic or Volatile.
10881 if Is_Volatile
(Id
) then
10884 -- An array type is effectively volatile when it is subject to pragma
10885 -- Atomic_Components or Volatile_Components or its compolent type is
10886 -- effectively volatile.
10888 elsif Is_Array_Type
(Id
) then
10890 Has_Volatile_Components
(Id
)
10892 Is_Effectively_Volatile
(Component_Type
(Base_Type
(Id
)));
10898 -- Otherwise Id denotes an object
10903 or else Has_Volatile_Components
(Id
)
10904 or else Is_Effectively_Volatile
(Etype
(Id
));
10906 end Is_Effectively_Volatile
;
10908 ------------------------------------
10909 -- Is_Effectively_Volatile_Object --
10910 ------------------------------------
10912 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
10914 if Is_Entity_Name
(N
) then
10915 return Is_Effectively_Volatile
(Entity
(N
));
10917 elsif Nkind
(N
) = N_Expanded_Name
then
10918 return Is_Effectively_Volatile
(Entity
(N
));
10920 elsif Nkind
(N
) = N_Indexed_Component
then
10921 return Is_Effectively_Volatile_Object
(Prefix
(N
));
10923 elsif Nkind
(N
) = N_Selected_Component
then
10925 Is_Effectively_Volatile_Object
(Prefix
(N
))
10927 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
10932 end Is_Effectively_Volatile_Object
;
10934 ----------------------------
10935 -- Is_Expression_Function --
10936 ----------------------------
10938 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
10942 if Ekind
(Subp
) /= E_Function
then
10946 Decl
:= Unit_Declaration_Node
(Subp
);
10947 return Nkind
(Decl
) = N_Subprogram_Declaration
10949 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
10951 (Present
(Corresponding_Body
(Decl
))
10953 Nkind
(Original_Node
10954 (Unit_Declaration_Node
10955 (Corresponding_Body
(Decl
)))) =
10956 N_Expression_Function
));
10958 end Is_Expression_Function
;
10960 -----------------------
10961 -- Is_EVF_Expression --
10962 -----------------------
10964 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
10965 Orig_N
: constant Node_Id
:= Original_Node
(N
);
10971 -- Detect a reference to a formal parameter of a specific tagged type
10972 -- whose related subprogram is subject to pragma Expresions_Visible with
10975 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
10980 and then Is_Specific_Tagged_Type
(Etype
(Id
))
10981 and then Extensions_Visible_Status
(Id
) =
10982 Extensions_Visible_False
;
10984 -- A case expression is an EVF expression when it contains at least one
10985 -- EVF dependent_expression. Note that a case expression may have been
10986 -- expanded, hence the use of Original_Node.
10988 elsif Nkind
(Orig_N
) = N_Case_Expression
then
10989 Alt
:= First
(Alternatives
(Orig_N
));
10990 while Present
(Alt
) loop
10991 if Is_EVF_Expression
(Expression
(Alt
)) then
10998 -- An if expression is an EVF expression when it contains at least one
10999 -- EVF dependent_expression. Note that an if expression may have been
11000 -- expanded, hence the use of Original_Node.
11002 elsif Nkind
(Orig_N
) = N_If_Expression
then
11003 Expr
:= Next
(First
(Expressions
(Orig_N
)));
11004 while Present
(Expr
) loop
11005 if Is_EVF_Expression
(Expr
) then
11012 -- A qualified expression or a type conversion is an EVF expression when
11013 -- its operand is an EVF expression.
11015 elsif Nkind_In
(N
, N_Qualified_Expression
,
11016 N_Unchecked_Type_Conversion
,
11019 return Is_EVF_Expression
(Expression
(N
));
11021 -- Attributes 'Loop_Entry, 'Old and 'Update are an EVF expression when
11022 -- their prefix denotes an EVF expression.
11024 elsif Nkind
(N
) = N_Attribute_Reference
11025 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
11029 return Is_EVF_Expression
(Prefix
(N
));
11033 end Is_EVF_Expression
;
11039 function Is_False
(U
: Uint
) return Boolean is
11044 ---------------------------
11045 -- Is_Fixed_Model_Number --
11046 ---------------------------
11048 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
11049 S
: constant Ureal
:= Small_Value
(T
);
11050 M
: Urealp
.Save_Mark
;
11054 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
11055 Urealp
.Release
(M
);
11057 end Is_Fixed_Model_Number
;
11059 -------------------------------
11060 -- Is_Fully_Initialized_Type --
11061 -------------------------------
11063 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
11067 if Is_Scalar_Type
(Typ
) then
11069 -- A scalar type with an aspect Default_Value is fully initialized
11071 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
11072 -- of a scalar type, but we don't take that into account here, since
11073 -- we don't want these to affect warnings.
11075 return Has_Default_Aspect
(Typ
);
11077 elsif Is_Access_Type
(Typ
) then
11080 elsif Is_Array_Type
(Typ
) then
11081 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
11082 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
11087 -- An interesting case, if we have a constrained type one of whose
11088 -- bounds is known to be null, then there are no elements to be
11089 -- initialized, so all the elements are initialized.
11091 if Is_Constrained
(Typ
) then
11094 Indx_Typ
: Entity_Id
;
11095 Lbd
, Hbd
: Node_Id
;
11098 Indx
:= First_Index
(Typ
);
11099 while Present
(Indx
) loop
11100 if Etype
(Indx
) = Any_Type
then
11103 -- If index is a range, use directly
11105 elsif Nkind
(Indx
) = N_Range
then
11106 Lbd
:= Low_Bound
(Indx
);
11107 Hbd
:= High_Bound
(Indx
);
11110 Indx_Typ
:= Etype
(Indx
);
11112 if Is_Private_Type
(Indx_Typ
) then
11113 Indx_Typ
:= Full_View
(Indx_Typ
);
11116 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
11119 Lbd
:= Type_Low_Bound
(Indx_Typ
);
11120 Hbd
:= Type_High_Bound
(Indx_Typ
);
11124 if Compile_Time_Known_Value
(Lbd
)
11126 Compile_Time_Known_Value
(Hbd
)
11128 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
11138 -- If no null indexes, then type is not fully initialized
11144 elsif Is_Record_Type
(Typ
) then
11145 if Has_Discriminants
(Typ
)
11147 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
11148 and then Is_Fully_Initialized_Variant
(Typ
)
11153 -- We consider bounded string types to be fully initialized, because
11154 -- otherwise we get false alarms when the Data component is not
11155 -- default-initialized.
11157 if Is_Bounded_String
(Typ
) then
11161 -- Controlled records are considered to be fully initialized if
11162 -- there is a user defined Initialize routine. This may not be
11163 -- entirely correct, but as the spec notes, we are guessing here
11164 -- what is best from the point of view of issuing warnings.
11166 if Is_Controlled
(Typ
) then
11168 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
11171 if Present
(Utyp
) then
11173 Init
: constant Entity_Id
:=
11175 (Underlying_Type
(Typ
), Name_Initialize
));
11179 and then Comes_From_Source
(Init
)
11181 Is_Predefined_File_Name
11182 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
11186 elsif Has_Null_Extension
(Typ
)
11188 Is_Fully_Initialized_Type
11189 (Etype
(Base_Type
(Typ
)))
11198 -- Otherwise see if all record components are initialized
11204 Ent
:= First_Entity
(Typ
);
11205 while Present
(Ent
) loop
11206 if Ekind
(Ent
) = E_Component
11207 and then (No
(Parent
(Ent
))
11208 or else No
(Expression
(Parent
(Ent
))))
11209 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
11211 -- Special VM case for tag components, which need to be
11212 -- defined in this case, but are never initialized as VMs
11213 -- are using other dispatching mechanisms. Ignore this
11214 -- uninitialized case. Note that this applies both to the
11215 -- uTag entry and the main vtable pointer (CPP_Class case).
11217 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
11226 -- No uninitialized components, so type is fully initialized.
11227 -- Note that this catches the case of no components as well.
11231 elsif Is_Concurrent_Type
(Typ
) then
11234 elsif Is_Private_Type
(Typ
) then
11236 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11242 return Is_Fully_Initialized_Type
(U
);
11249 end Is_Fully_Initialized_Type
;
11251 ----------------------------------
11252 -- Is_Fully_Initialized_Variant --
11253 ----------------------------------
11255 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
11256 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
11257 Constraints
: constant List_Id
:= New_List
;
11258 Components
: constant Elist_Id
:= New_Elmt_List
;
11259 Comp_Elmt
: Elmt_Id
;
11261 Comp_List
: Node_Id
;
11263 Discr_Val
: Node_Id
;
11265 Report_Errors
: Boolean;
11266 pragma Warnings
(Off
, Report_Errors
);
11269 if Serious_Errors_Detected
> 0 then
11273 if Is_Record_Type
(Typ
)
11274 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
11275 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
11277 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
11279 Discr
:= First_Discriminant
(Typ
);
11280 while Present
(Discr
) loop
11281 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
11282 Discr_Val
:= Expression
(Parent
(Discr
));
11284 if Present
(Discr_Val
)
11285 and then Is_OK_Static_Expression
(Discr_Val
)
11287 Append_To
(Constraints
,
11288 Make_Component_Association
(Loc
,
11289 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
11290 Expression
=> New_Copy
(Discr_Val
)));
11298 Next_Discriminant
(Discr
);
11303 Comp_List
=> Comp_List
,
11304 Governed_By
=> Constraints
,
11305 Into
=> Components
,
11306 Report_Errors
=> Report_Errors
);
11308 -- Check that each component present is fully initialized
11310 Comp_Elmt
:= First_Elmt
(Components
);
11311 while Present
(Comp_Elmt
) loop
11312 Comp_Id
:= Node
(Comp_Elmt
);
11314 if Ekind
(Comp_Id
) = E_Component
11315 and then (No
(Parent
(Comp_Id
))
11316 or else No
(Expression
(Parent
(Comp_Id
))))
11317 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
11322 Next_Elmt
(Comp_Elmt
);
11327 elsif Is_Private_Type
(Typ
) then
11329 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11335 return Is_Fully_Initialized_Variant
(U
);
11342 end Is_Fully_Initialized_Variant
;
11344 ----------------------------
11345 -- Is_Inherited_Operation --
11346 ----------------------------
11348 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
11349 pragma Assert
(Is_Overloadable
(E
));
11350 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
11352 return Kind
= N_Full_Type_Declaration
11353 or else Kind
= N_Private_Extension_Declaration
11354 or else Kind
= N_Subtype_Declaration
11355 or else (Ekind
(E
) = E_Enumeration_Literal
11356 and then Is_Derived_Type
(Etype
(E
)));
11357 end Is_Inherited_Operation
;
11359 -------------------------------------
11360 -- Is_Inherited_Operation_For_Type --
11361 -------------------------------------
11363 function Is_Inherited_Operation_For_Type
11365 Typ
: Entity_Id
) return Boolean
11368 -- Check that the operation has been created by the type declaration
11370 return Is_Inherited_Operation
(E
)
11371 and then Defining_Identifier
(Parent
(E
)) = Typ
;
11372 end Is_Inherited_Operation_For_Type
;
11378 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
11379 Ifaces_List
: Elist_Id
;
11380 Iface_Elmt
: Elmt_Id
;
11384 if Is_Class_Wide_Type
(Typ
)
11385 and then Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
11386 Name_Reversible_Iterator
)
11388 Is_Predefined_File_Name
11389 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
11393 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
11396 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
11400 Collect_Interfaces
(Typ
, Ifaces_List
);
11402 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
11403 while Present
(Iface_Elmt
) loop
11404 Iface
:= Node
(Iface_Elmt
);
11405 if Chars
(Iface
) = Name_Forward_Iterator
11407 Is_Predefined_File_Name
11408 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
11413 Next_Elmt
(Iface_Elmt
);
11424 -- We seem to have a lot of overlapping functions that do similar things
11425 -- (testing for left hand sides or lvalues???).
11427 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
11428 P
: constant Node_Id
:= Parent
(N
);
11431 -- Return True if we are the left hand side of an assignment statement
11433 if Nkind
(P
) = N_Assignment_Statement
then
11434 if Name
(P
) = N
then
11440 -- Case of prefix of indexed or selected component or slice
11442 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
11443 and then N
= Prefix
(P
)
11445 -- Here we have the case where the parent P is N.Q or N(Q .. R).
11446 -- If P is an LHS, then N is also effectively an LHS, but there
11447 -- is an important exception. If N is of an access type, then
11448 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
11449 -- case this makes N.all a left hand side but not N itself.
11451 -- If we don't know the type yet, this is the case where we return
11452 -- Unknown, since the answer depends on the type which is unknown.
11454 if No
(Etype
(N
)) then
11457 -- We have an Etype set, so we can check it
11459 elsif Is_Access_Type
(Etype
(N
)) then
11462 -- OK, not access type case, so just test whole expression
11468 -- All other cases are not left hand sides
11475 -----------------------------
11476 -- Is_Library_Level_Entity --
11477 -----------------------------
11479 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
11481 -- The following is a small optimization, and it also properly handles
11482 -- discriminals, which in task bodies might appear in expressions before
11483 -- the corresponding procedure has been created, and which therefore do
11484 -- not have an assigned scope.
11486 if Is_Formal
(E
) then
11490 -- Normal test is simply that the enclosing dynamic scope is Standard
11492 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
11493 end Is_Library_Level_Entity
;
11495 --------------------------------
11496 -- Is_Limited_Class_Wide_Type --
11497 --------------------------------
11499 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
11502 Is_Class_Wide_Type
(Typ
)
11503 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
11504 end Is_Limited_Class_Wide_Type
;
11506 ---------------------------------
11507 -- Is_Local_Variable_Reference --
11508 ---------------------------------
11510 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
11512 if not Is_Entity_Name
(Expr
) then
11517 Ent
: constant Entity_Id
:= Entity
(Expr
);
11518 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
11520 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
11523 return Present
(Sub
) and then Sub
= Current_Subprogram
;
11527 end Is_Local_Variable_Reference
;
11529 -------------------------
11530 -- Is_Object_Reference --
11531 -------------------------
11533 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
11535 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
11536 -- Determine whether N is the name of an internally-generated renaming
11538 --------------------------------------
11539 -- Is_Internally_Generated_Renaming --
11540 --------------------------------------
11542 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
11547 while Present
(P
) loop
11548 if Nkind
(P
) = N_Object_Renaming_Declaration
then
11549 return not Comes_From_Source
(P
);
11550 elsif Is_List_Member
(P
) then
11558 end Is_Internally_Generated_Renaming
;
11560 -- Start of processing for Is_Object_Reference
11563 if Is_Entity_Name
(N
) then
11564 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
11568 when N_Indexed_Component | N_Slice
=>
11570 Is_Object_Reference
(Prefix
(N
))
11571 or else Is_Access_Type
(Etype
(Prefix
(N
)));
11573 -- In Ada 95, a function call is a constant object; a procedure
11576 when N_Function_Call
=>
11577 return Etype
(N
) /= Standard_Void_Type
;
11579 -- Attributes 'Input, 'Old and 'Result produce objects
11581 when N_Attribute_Reference
=>
11584 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
11586 when N_Selected_Component
=>
11588 Is_Object_Reference
(Selector_Name
(N
))
11590 (Is_Object_Reference
(Prefix
(N
))
11591 or else Is_Access_Type
(Etype
(Prefix
(N
))));
11593 when N_Explicit_Dereference
=>
11596 -- A view conversion of a tagged object is an object reference
11598 when N_Type_Conversion
=>
11599 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
11600 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
11601 and then Is_Object_Reference
(Expression
(N
));
11603 -- An unchecked type conversion is considered to be an object if
11604 -- the operand is an object (this construction arises only as a
11605 -- result of expansion activities).
11607 when N_Unchecked_Type_Conversion
=>
11610 -- Allow string literals to act as objects as long as they appear
11611 -- in internally-generated renamings. The expansion of iterators
11612 -- may generate such renamings when the range involves a string
11615 when N_String_Literal
=>
11616 return Is_Internally_Generated_Renaming
(Parent
(N
));
11618 -- AI05-0003: In Ada 2012 a qualified expression is a name.
11619 -- This allows disambiguation of function calls and the use
11620 -- of aggregates in more contexts.
11622 when N_Qualified_Expression
=>
11623 if Ada_Version
< Ada_2012
then
11626 return Is_Object_Reference
(Expression
(N
))
11627 or else Nkind
(Expression
(N
)) = N_Aggregate
;
11634 end Is_Object_Reference
;
11636 -----------------------------------
11637 -- Is_OK_Variable_For_Out_Formal --
11638 -----------------------------------
11640 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
11642 Note_Possible_Modification
(AV
, Sure
=> True);
11644 -- We must reject parenthesized variable names. Comes_From_Source is
11645 -- checked because there are currently cases where the compiler violates
11646 -- this rule (e.g. passing a task object to its controlled Initialize
11647 -- routine). This should be properly documented in sinfo???
11649 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
11652 -- A variable is always allowed
11654 elsif Is_Variable
(AV
) then
11657 -- Generalized indexing operations are rewritten as explicit
11658 -- dereferences, and it is only during resolution that we can
11659 -- check whether the context requires an access_to_variable type.
11661 elsif Nkind
(AV
) = N_Explicit_Dereference
11662 and then Ada_Version
>= Ada_2012
11663 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
11664 and then Present
(Etype
(Original_Node
(AV
)))
11665 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
11667 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
11669 -- Unchecked conversions are allowed only if they come from the
11670 -- generated code, which sometimes uses unchecked conversions for out
11671 -- parameters in cases where code generation is unaffected. We tell
11672 -- source unchecked conversions by seeing if they are rewrites of
11673 -- an original Unchecked_Conversion function call, or of an explicit
11674 -- conversion of a function call or an aggregate (as may happen in the
11675 -- expansion of a packed array aggregate).
11677 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
11678 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
11681 elsif Comes_From_Source
(AV
)
11682 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
11686 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
11687 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
11693 -- Normal type conversions are allowed if argument is a variable
11695 elsif Nkind
(AV
) = N_Type_Conversion
then
11696 if Is_Variable
(Expression
(AV
))
11697 and then Paren_Count
(Expression
(AV
)) = 0
11699 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
11702 -- We also allow a non-parenthesized expression that raises
11703 -- constraint error if it rewrites what used to be a variable
11705 elsif Raises_Constraint_Error
(Expression
(AV
))
11706 and then Paren_Count
(Expression
(AV
)) = 0
11707 and then Is_Variable
(Original_Node
(Expression
(AV
)))
11711 -- Type conversion of something other than a variable
11717 -- If this node is rewritten, then test the original form, if that is
11718 -- OK, then we consider the rewritten node OK (for example, if the
11719 -- original node is a conversion, then Is_Variable will not be true
11720 -- but we still want to allow the conversion if it converts a variable).
11722 elsif Original_Node
(AV
) /= AV
then
11724 -- In Ada 2012, the explicit dereference may be a rewritten call to a
11725 -- Reference function.
11727 if Ada_Version
>= Ada_2012
11728 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
11730 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
11735 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
11738 -- All other non-variables are rejected
11743 end Is_OK_Variable_For_Out_Formal
;
11745 -----------------------------------
11746 -- Is_Partially_Initialized_Type --
11747 -----------------------------------
11749 function Is_Partially_Initialized_Type
11751 Include_Implicit
: Boolean := True) return Boolean
11754 if Is_Scalar_Type
(Typ
) then
11757 elsif Is_Access_Type
(Typ
) then
11758 return Include_Implicit
;
11760 elsif Is_Array_Type
(Typ
) then
11762 -- If component type is partially initialized, so is array type
11764 if Is_Partially_Initialized_Type
11765 (Component_Type
(Typ
), Include_Implicit
)
11769 -- Otherwise we are only partially initialized if we are fully
11770 -- initialized (this is the empty array case, no point in us
11771 -- duplicating that code here).
11774 return Is_Fully_Initialized_Type
(Typ
);
11777 elsif Is_Record_Type
(Typ
) then
11779 -- A discriminated type is always partially initialized if in
11782 if Has_Discriminants
(Typ
) and then Include_Implicit
then
11785 -- A tagged type is always partially initialized
11787 elsif Is_Tagged_Type
(Typ
) then
11790 -- Case of non-discriminated record
11796 Component_Present
: Boolean := False;
11797 -- Set True if at least one component is present. If no
11798 -- components are present, then record type is fully
11799 -- initialized (another odd case, like the null array).
11802 -- Loop through components
11804 Ent
:= First_Entity
(Typ
);
11805 while Present
(Ent
) loop
11806 if Ekind
(Ent
) = E_Component
then
11807 Component_Present
:= True;
11809 -- If a component has an initialization expression then
11810 -- the enclosing record type is partially initialized
11812 if Present
(Parent
(Ent
))
11813 and then Present
(Expression
(Parent
(Ent
)))
11817 -- If a component is of a type which is itself partially
11818 -- initialized, then the enclosing record type is also.
11820 elsif Is_Partially_Initialized_Type
11821 (Etype
(Ent
), Include_Implicit
)
11830 -- No initialized components found. If we found any components
11831 -- they were all uninitialized so the result is false.
11833 if Component_Present
then
11836 -- But if we found no components, then all the components are
11837 -- initialized so we consider the type to be initialized.
11845 -- Concurrent types are always fully initialized
11847 elsif Is_Concurrent_Type
(Typ
) then
11850 -- For a private type, go to underlying type. If there is no underlying
11851 -- type then just assume this partially initialized. Not clear if this
11852 -- can happen in a non-error case, but no harm in testing for this.
11854 elsif Is_Private_Type
(Typ
) then
11856 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11861 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
11865 -- For any other type (are there any?) assume partially initialized
11870 end Is_Partially_Initialized_Type
;
11872 ------------------------------------
11873 -- Is_Potentially_Persistent_Type --
11874 ------------------------------------
11876 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
11881 -- For private type, test corresponding full type
11883 if Is_Private_Type
(T
) then
11884 return Is_Potentially_Persistent_Type
(Full_View
(T
));
11886 -- Scalar types are potentially persistent
11888 elsif Is_Scalar_Type
(T
) then
11891 -- Record type is potentially persistent if not tagged and the types of
11892 -- all it components are potentially persistent, and no component has
11893 -- an initialization expression.
11895 elsif Is_Record_Type
(T
)
11896 and then not Is_Tagged_Type
(T
)
11897 and then not Is_Partially_Initialized_Type
(T
)
11899 Comp
:= First_Component
(T
);
11900 while Present
(Comp
) loop
11901 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
11904 Next_Entity
(Comp
);
11910 -- Array type is potentially persistent if its component type is
11911 -- potentially persistent and if all its constraints are static.
11913 elsif Is_Array_Type
(T
) then
11914 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
11918 Indx
:= First_Index
(T
);
11919 while Present
(Indx
) loop
11920 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
11929 -- All other types are not potentially persistent
11934 end Is_Potentially_Persistent_Type
;
11936 --------------------------------
11937 -- Is_Potentially_Unevaluated --
11938 --------------------------------
11940 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
11948 -- A postcondition whose expression is a short-circuit is broken down
11949 -- into individual aspects for better exception reporting. The original
11950 -- short-circuit expression is rewritten as the second operand, and an
11951 -- occurrence of 'Old in that operand is potentially unevaluated.
11952 -- See Sem_ch13.adb for details of this transformation.
11954 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
11958 while not Nkind_In
(Par
, N_If_Expression
,
11966 Par
:= Parent
(Par
);
11968 -- If the context is not an expression, or if is the result of
11969 -- expansion of an enclosing construct (such as another attribute)
11970 -- the predicate does not apply.
11972 if Nkind
(Par
) not in N_Subexpr
11973 or else not Comes_From_Source
(Par
)
11979 if Nkind
(Par
) = N_If_Expression
then
11980 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
11982 elsif Nkind
(Par
) = N_Case_Expression
then
11983 return Expr
/= Expression
(Par
);
11985 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
11986 return Expr
= Right_Opnd
(Par
);
11988 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
11989 return Expr
/= Left_Opnd
(Par
);
11994 end Is_Potentially_Unevaluated
;
11996 ---------------------------------
11997 -- Is_Protected_Self_Reference --
11998 ---------------------------------
12000 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
12002 function In_Access_Definition
(N
: Node_Id
) return Boolean;
12003 -- Returns true if N belongs to an access definition
12005 --------------------------
12006 -- In_Access_Definition --
12007 --------------------------
12009 function In_Access_Definition
(N
: Node_Id
) return Boolean is
12014 while Present
(P
) loop
12015 if Nkind
(P
) = N_Access_Definition
then
12023 end In_Access_Definition
;
12025 -- Start of processing for Is_Protected_Self_Reference
12028 -- Verify that prefix is analyzed and has the proper form. Note that
12029 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
12030 -- which also produce the address of an entity, do not analyze their
12031 -- prefix because they denote entities that are not necessarily visible.
12032 -- Neither of them can apply to a protected type.
12034 return Ada_Version
>= Ada_2005
12035 and then Is_Entity_Name
(N
)
12036 and then Present
(Entity
(N
))
12037 and then Is_Protected_Type
(Entity
(N
))
12038 and then In_Open_Scopes
(Entity
(N
))
12039 and then not In_Access_Definition
(N
);
12040 end Is_Protected_Self_Reference
;
12042 -----------------------------
12043 -- Is_RCI_Pkg_Spec_Or_Body --
12044 -----------------------------
12046 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
12048 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
12049 -- Return True if the unit of Cunit is an RCI package declaration
12051 ---------------------------
12052 -- Is_RCI_Pkg_Decl_Cunit --
12053 ---------------------------
12055 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
12056 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
12059 if Nkind
(The_Unit
) /= N_Package_Declaration
then
12063 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
12064 end Is_RCI_Pkg_Decl_Cunit
;
12066 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12069 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
12071 (Nkind
(Unit
(Cunit
)) = N_Package_Body
12072 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
12073 end Is_RCI_Pkg_Spec_Or_Body
;
12075 -----------------------------------------
12076 -- Is_Remote_Access_To_Class_Wide_Type --
12077 -----------------------------------------
12079 function Is_Remote_Access_To_Class_Wide_Type
12080 (E
: Entity_Id
) return Boolean
12083 -- A remote access to class-wide type is a general access to object type
12084 -- declared in the visible part of a Remote_Types or Remote_Call_
12087 return Ekind
(E
) = E_General_Access_Type
12088 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
12089 end Is_Remote_Access_To_Class_Wide_Type
;
12091 -----------------------------------------
12092 -- Is_Remote_Access_To_Subprogram_Type --
12093 -----------------------------------------
12095 function Is_Remote_Access_To_Subprogram_Type
12096 (E
: Entity_Id
) return Boolean
12099 return (Ekind
(E
) = E_Access_Subprogram_Type
12100 or else (Ekind
(E
) = E_Record_Type
12101 and then Present
(Corresponding_Remote_Type
(E
))))
12102 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
12103 end Is_Remote_Access_To_Subprogram_Type
;
12105 --------------------
12106 -- Is_Remote_Call --
12107 --------------------
12109 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
12111 if Nkind
(N
) not in N_Subprogram_Call
then
12113 -- An entry call cannot be remote
12117 elsif Nkind
(Name
(N
)) in N_Has_Entity
12118 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
12120 -- A subprogram declared in the spec of a RCI package is remote
12124 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
12125 and then Is_Remote_Access_To_Subprogram_Type
12126 (Etype
(Prefix
(Name
(N
))))
12128 -- The dereference of a RAS is a remote call
12132 elsif Present
(Controlling_Argument
(N
))
12133 and then Is_Remote_Access_To_Class_Wide_Type
12134 (Etype
(Controlling_Argument
(N
)))
12136 -- Any primitive operation call with a controlling argument of
12137 -- a RACW type is a remote call.
12142 -- All other calls are local calls
12145 end Is_Remote_Call
;
12147 ----------------------
12148 -- Is_Renamed_Entry --
12149 ----------------------
12151 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
12152 Orig_Node
: Node_Id
:= Empty
;
12153 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
12155 function Is_Entry
(Nam
: Node_Id
) return Boolean;
12156 -- Determine whether Nam is an entry. Traverse selectors if there are
12157 -- nested selected components.
12163 function Is_Entry
(Nam
: Node_Id
) return Boolean is
12165 if Nkind
(Nam
) = N_Selected_Component
then
12166 return Is_Entry
(Selector_Name
(Nam
));
12169 return Ekind
(Entity
(Nam
)) = E_Entry
;
12172 -- Start of processing for Is_Renamed_Entry
12175 if Present
(Alias
(Proc_Nam
)) then
12176 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
12179 -- Look for a rewritten subprogram renaming declaration
12181 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
12182 and then Present
(Original_Node
(Subp_Decl
))
12184 Orig_Node
:= Original_Node
(Subp_Decl
);
12187 -- The rewritten subprogram is actually an entry
12189 if Present
(Orig_Node
)
12190 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
12191 and then Is_Entry
(Name
(Orig_Node
))
12197 end Is_Renamed_Entry
;
12199 ----------------------------
12200 -- Is_Reversible_Iterator --
12201 ----------------------------
12203 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
12204 Ifaces_List
: Elist_Id
;
12205 Iface_Elmt
: Elmt_Id
;
12209 if Is_Class_Wide_Type
(Typ
)
12210 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
12211 and then Is_Predefined_File_Name
12212 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
12216 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
12220 Collect_Interfaces
(Typ
, Ifaces_List
);
12222 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
12223 while Present
(Iface_Elmt
) loop
12224 Iface
:= Node
(Iface_Elmt
);
12225 if Chars
(Iface
) = Name_Reversible_Iterator
12227 Is_Predefined_File_Name
12228 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
12233 Next_Elmt
(Iface_Elmt
);
12238 end Is_Reversible_Iterator
;
12240 ----------------------
12241 -- Is_Selector_Name --
12242 ----------------------
12244 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
12246 if not Is_List_Member
(N
) then
12248 P
: constant Node_Id
:= Parent
(N
);
12250 return Nkind_In
(P
, N_Expanded_Name
,
12251 N_Generic_Association
,
12252 N_Parameter_Association
,
12253 N_Selected_Component
)
12254 and then Selector_Name
(P
) = N
;
12259 L
: constant List_Id
:= List_Containing
(N
);
12260 P
: constant Node_Id
:= Parent
(L
);
12262 return (Nkind
(P
) = N_Discriminant_Association
12263 and then Selector_Names
(P
) = L
)
12265 (Nkind
(P
) = N_Component_Association
12266 and then Choices
(P
) = L
);
12269 end Is_Selector_Name
;
12271 -------------------------------------
12272 -- Is_SPARK_05_Initialization_Expr --
12273 -------------------------------------
12275 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
12278 Comp_Assn
: Node_Id
;
12279 Orig_N
: constant Node_Id
:= Original_Node
(N
);
12284 if not Comes_From_Source
(Orig_N
) then
12288 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
12290 case Nkind
(Orig_N
) is
12291 when N_Character_Literal |
12292 N_Integer_Literal |
12294 N_String_Literal
=>
12297 when N_Identifier |
12299 if Is_Entity_Name
(Orig_N
)
12300 and then Present
(Entity
(Orig_N
)) -- needed in some cases
12302 case Ekind
(Entity
(Orig_N
)) is
12304 E_Enumeration_Literal |
12309 if Is_Type
(Entity
(Orig_N
)) then
12317 when N_Qualified_Expression |
12318 N_Type_Conversion
=>
12319 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
12322 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12326 N_Membership_Test
=>
12327 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
12329 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12332 N_Extension_Aggregate
=>
12333 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
12335 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
12338 Expr
:= First
(Expressions
(Orig_N
));
12339 while Present
(Expr
) loop
12340 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
12348 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
12349 while Present
(Comp_Assn
) loop
12350 Expr
:= Expression
(Comp_Assn
);
12352 -- Note: test for Present here needed for box assocation
12355 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
12364 when N_Attribute_Reference
=>
12365 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
12366 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
12369 Expr
:= First
(Expressions
(Orig_N
));
12370 while Present
(Expr
) loop
12371 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
12379 -- Selected components might be expanded named not yet resolved, so
12380 -- default on the safe side. (Eg on sparklex.ads)
12382 when N_Selected_Component
=>
12391 end Is_SPARK_05_Initialization_Expr
;
12393 ----------------------------------
12394 -- Is_SPARK_05_Object_Reference --
12395 ----------------------------------
12397 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
12399 if Is_Entity_Name
(N
) then
12400 return Present
(Entity
(N
))
12402 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
12403 or else Ekind
(Entity
(N
)) in Formal_Kind
);
12407 when N_Selected_Component
=>
12408 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
12414 end Is_SPARK_05_Object_Reference
;
12416 -----------------------------
12417 -- Is_Specific_Tagged_Type --
12418 -----------------------------
12420 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
12421 Full_Typ
: Entity_Id
;
12424 -- Handle private types
12426 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
12427 Full_Typ
:= Full_View
(Typ
);
12432 -- A specific tagged type is a non-class-wide tagged type
12434 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
12435 end Is_Specific_Tagged_Type
;
12441 function Is_Statement
(N
: Node_Id
) return Boolean is
12444 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
12445 or else Nkind
(N
) = N_Procedure_Call_Statement
;
12448 --------------------------------------------------
12449 -- Is_Subprogram_Stub_Without_Prior_Declaration --
12450 --------------------------------------------------
12452 function Is_Subprogram_Stub_Without_Prior_Declaration
12453 (N
: Node_Id
) return Boolean
12456 -- A subprogram stub without prior declaration serves as declaration for
12457 -- the actual subprogram body. As such, it has an attached defining
12458 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
12460 return Nkind
(N
) = N_Subprogram_Body_Stub
12461 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
12462 end Is_Subprogram_Stub_Without_Prior_Declaration
;
12464 ---------------------------------
12465 -- Is_Synchronized_Tagged_Type --
12466 ---------------------------------
12468 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
12469 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
12472 -- A task or protected type derived from an interface is a tagged type.
12473 -- Such a tagged type is called a synchronized tagged type, as are
12474 -- synchronized interfaces and private extensions whose declaration
12475 -- includes the reserved word synchronized.
12477 return (Is_Tagged_Type
(E
)
12478 and then (Kind
= E_Task_Type
12480 Kind
= E_Protected_Type
))
12483 and then Is_Synchronized_Interface
(E
))
12485 (Ekind
(E
) = E_Record_Type_With_Private
12486 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
12487 and then (Synchronized_Present
(Parent
(E
))
12488 or else Is_Synchronized_Interface
(Etype
(E
))));
12489 end Is_Synchronized_Tagged_Type
;
12495 function Is_Transfer
(N
: Node_Id
) return Boolean is
12496 Kind
: constant Node_Kind
:= Nkind
(N
);
12499 if Kind
= N_Simple_Return_Statement
12501 Kind
= N_Extended_Return_Statement
12503 Kind
= N_Goto_Statement
12505 Kind
= N_Raise_Statement
12507 Kind
= N_Requeue_Statement
12511 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
12512 and then No
(Condition
(N
))
12516 elsif Kind
= N_Procedure_Call_Statement
12517 and then Is_Entity_Name
(Name
(N
))
12518 and then Present
(Entity
(Name
(N
)))
12519 and then No_Return
(Entity
(Name
(N
)))
12523 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
12535 function Is_True
(U
: Uint
) return Boolean is
12540 --------------------------------------
12541 -- Is_Unchecked_Conversion_Instance --
12542 --------------------------------------
12544 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
12545 Gen_Par
: Entity_Id
;
12548 -- Look for a function whose generic parent is the predefined intrinsic
12549 -- function Unchecked_Conversion.
12551 if Ekind
(Id
) = E_Function
then
12552 Gen_Par
:= Generic_Parent
(Parent
(Id
));
12556 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
12557 and then Is_Intrinsic_Subprogram
(Gen_Par
)
12558 and then Is_Predefined_File_Name
12559 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
12563 end Is_Unchecked_Conversion_Instance
;
12565 -------------------------------
12566 -- Is_Universal_Numeric_Type --
12567 -------------------------------
12569 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
12571 return T
= Universal_Integer
or else T
= Universal_Real
;
12572 end Is_Universal_Numeric_Type
;
12574 -------------------
12575 -- Is_Value_Type --
12576 -------------------
12578 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
12580 return VM_Target
= CLI_Target
12581 and then Nkind
(T
) in N_Has_Chars
12582 and then Chars
(T
) /= No_Name
12583 and then Get_Name_String
(Chars
(T
)) = "valuetype";
12586 ----------------------------
12587 -- Is_Variable_Size_Array --
12588 ----------------------------
12590 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
12594 pragma Assert
(Is_Array_Type
(E
));
12596 -- Check if some index is initialized with a non-constant value
12598 Idx
:= First_Index
(E
);
12599 while Present
(Idx
) loop
12600 if Nkind
(Idx
) = N_Range
then
12601 if not Is_Constant_Bound
(Low_Bound
(Idx
))
12602 or else not Is_Constant_Bound
(High_Bound
(Idx
))
12608 Idx
:= Next_Index
(Idx
);
12612 end Is_Variable_Size_Array
;
12614 -----------------------------
12615 -- Is_Variable_Size_Record --
12616 -----------------------------
12618 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
12620 Comp_Typ
: Entity_Id
;
12623 pragma Assert
(Is_Record_Type
(E
));
12625 Comp
:= First_Entity
(E
);
12626 while Present
(Comp
) loop
12627 Comp_Typ
:= Etype
(Comp
);
12629 -- Recursive call if the record type has discriminants
12631 if Is_Record_Type
(Comp_Typ
)
12632 and then Has_Discriminants
(Comp_Typ
)
12633 and then Is_Variable_Size_Record
(Comp_Typ
)
12637 elsif Is_Array_Type
(Comp_Typ
)
12638 and then Is_Variable_Size_Array
(Comp_Typ
)
12643 Next_Entity
(Comp
);
12647 end Is_Variable_Size_Record
;
12653 function Is_Variable
12655 Use_Original_Node
: Boolean := True) return Boolean
12657 Orig_Node
: Node_Id
;
12659 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
12660 -- Within a protected function, the private components of the enclosing
12661 -- protected type are constants. A function nested within a (protected)
12662 -- procedure is not itself protected. Within the body of a protected
12663 -- function the current instance of the protected type is a constant.
12665 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
12666 -- Prefixes can involve implicit dereferences, in which case we must
12667 -- test for the case of a reference of a constant access type, which can
12668 -- can never be a variable.
12670 ---------------------------
12671 -- In_Protected_Function --
12672 ---------------------------
12674 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
12679 -- E is the current instance of a type
12681 if Is_Type
(E
) then
12690 if not Is_Protected_Type
(Prot
) then
12694 S
:= Current_Scope
;
12695 while Present
(S
) and then S
/= Prot
loop
12696 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
12705 end In_Protected_Function
;
12707 ------------------------
12708 -- Is_Variable_Prefix --
12709 ------------------------
12711 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
12713 if Is_Access_Type
(Etype
(P
)) then
12714 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
12716 -- For the case of an indexed component whose prefix has a packed
12717 -- array type, the prefix has been rewritten into a type conversion.
12718 -- Determine variable-ness from the converted expression.
12720 elsif Nkind
(P
) = N_Type_Conversion
12721 and then not Comes_From_Source
(P
)
12722 and then Is_Array_Type
(Etype
(P
))
12723 and then Is_Packed
(Etype
(P
))
12725 return Is_Variable
(Expression
(P
));
12728 return Is_Variable
(P
);
12730 end Is_Variable_Prefix
;
12732 -- Start of processing for Is_Variable
12735 -- Check if we perform the test on the original node since this may be a
12736 -- test of syntactic categories which must not be disturbed by whatever
12737 -- rewriting might have occurred. For example, an aggregate, which is
12738 -- certainly NOT a variable, could be turned into a variable by
12741 if Use_Original_Node
then
12742 Orig_Node
:= Original_Node
(N
);
12747 -- Definitely OK if Assignment_OK is set. Since this is something that
12748 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
12750 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
12753 -- Normally we go to the original node, but there is one exception where
12754 -- we use the rewritten node, namely when it is an explicit dereference.
12755 -- The generated code may rewrite a prefix which is an access type with
12756 -- an explicit dereference. The dereference is a variable, even though
12757 -- the original node may not be (since it could be a constant of the
12760 -- In Ada 2005 we have a further case to consider: the prefix may be a
12761 -- function call given in prefix notation. The original node appears to
12762 -- be a selected component, but we need to examine the call.
12764 elsif Nkind
(N
) = N_Explicit_Dereference
12765 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
12766 and then Present
(Etype
(Orig_Node
))
12767 and then Is_Access_Type
(Etype
(Orig_Node
))
12769 -- Note that if the prefix is an explicit dereference that does not
12770 -- come from source, we must check for a rewritten function call in
12771 -- prefixed notation before other forms of rewriting, to prevent a
12775 (Nkind
(Orig_Node
) = N_Function_Call
12776 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
12778 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
12780 -- in Ada 2012, the dereference may have been added for a type with
12781 -- a declared implicit dereference aspect. Check that it is not an
12782 -- access to constant.
12784 elsif Nkind
(N
) = N_Explicit_Dereference
12785 and then Present
(Etype
(Orig_Node
))
12786 and then Ada_Version
>= Ada_2012
12787 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
12789 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
12791 -- A function call is never a variable
12793 elsif Nkind
(N
) = N_Function_Call
then
12796 -- All remaining checks use the original node
12798 elsif Is_Entity_Name
(Orig_Node
)
12799 and then Present
(Entity
(Orig_Node
))
12802 E
: constant Entity_Id
:= Entity
(Orig_Node
);
12803 K
: constant Entity_Kind
:= Ekind
(E
);
12806 return (K
= E_Variable
12807 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
12808 or else (K
= E_Component
12809 and then not In_Protected_Function
(E
))
12810 or else K
= E_Out_Parameter
12811 or else K
= E_In_Out_Parameter
12812 or else K
= E_Generic_In_Out_Parameter
12814 -- Current instance of type. If this is a protected type, check
12815 -- we are not within the body of one of its protected functions.
12817 or else (Is_Type
(E
)
12818 and then In_Open_Scopes
(E
)
12819 and then not In_Protected_Function
(E
))
12821 or else (Is_Incomplete_Or_Private_Type
(E
)
12822 and then In_Open_Scopes
(Full_View
(E
)));
12826 case Nkind
(Orig_Node
) is
12827 when N_Indexed_Component | N_Slice
=>
12828 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
12830 when N_Selected_Component
=>
12831 return (Is_Variable
(Selector_Name
(Orig_Node
))
12832 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
12834 (Nkind
(N
) = N_Expanded_Name
12835 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
12837 -- For an explicit dereference, the type of the prefix cannot
12838 -- be an access to constant or an access to subprogram.
12840 when N_Explicit_Dereference
=>
12842 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
12844 return Is_Access_Type
(Typ
)
12845 and then not Is_Access_Constant
(Root_Type
(Typ
))
12846 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
12849 -- The type conversion is the case where we do not deal with the
12850 -- context dependent special case of an actual parameter. Thus
12851 -- the type conversion is only considered a variable for the
12852 -- purposes of this routine if the target type is tagged. However,
12853 -- a type conversion is considered to be a variable if it does not
12854 -- come from source (this deals for example with the conversions
12855 -- of expressions to their actual subtypes).
12857 when N_Type_Conversion
=>
12858 return Is_Variable
(Expression
(Orig_Node
))
12860 (not Comes_From_Source
(Orig_Node
)
12862 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
12864 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
12866 -- GNAT allows an unchecked type conversion as a variable. This
12867 -- only affects the generation of internal expanded code, since
12868 -- calls to instantiations of Unchecked_Conversion are never
12869 -- considered variables (since they are function calls).
12871 when N_Unchecked_Type_Conversion
=>
12872 return Is_Variable
(Expression
(Orig_Node
));
12880 ---------------------------
12881 -- Is_Visibly_Controlled --
12882 ---------------------------
12884 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
12885 Root
: constant Entity_Id
:= Root_Type
(T
);
12887 return Chars
(Scope
(Root
)) = Name_Finalization
12888 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
12889 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
12890 end Is_Visibly_Controlled
;
12892 ------------------------
12893 -- Is_Volatile_Object --
12894 ------------------------
12896 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
12898 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
12899 -- If prefix is an implicit dereference, examine designated type
12901 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
12902 -- Determines if given object has volatile components
12904 ------------------------
12905 -- Is_Volatile_Prefix --
12906 ------------------------
12908 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
12909 Typ
: constant Entity_Id
:= Etype
(N
);
12912 if Is_Access_Type
(Typ
) then
12914 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
12917 return Is_Volatile
(Dtyp
)
12918 or else Has_Volatile_Components
(Dtyp
);
12922 return Object_Has_Volatile_Components
(N
);
12924 end Is_Volatile_Prefix
;
12926 ------------------------------------
12927 -- Object_Has_Volatile_Components --
12928 ------------------------------------
12930 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
12931 Typ
: constant Entity_Id
:= Etype
(N
);
12934 if Is_Volatile
(Typ
)
12935 or else Has_Volatile_Components
(Typ
)
12939 elsif Is_Entity_Name
(N
)
12940 and then (Has_Volatile_Components
(Entity
(N
))
12941 or else Is_Volatile
(Entity
(N
)))
12945 elsif Nkind
(N
) = N_Indexed_Component
12946 or else Nkind
(N
) = N_Selected_Component
12948 return Is_Volatile_Prefix
(Prefix
(N
));
12953 end Object_Has_Volatile_Components
;
12955 -- Start of processing for Is_Volatile_Object
12958 if Nkind
(N
) = N_Defining_Identifier
then
12959 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
12961 elsif Nkind
(N
) = N_Expanded_Name
then
12962 return Is_Volatile_Object
(Entity
(N
));
12964 elsif Is_Volatile
(Etype
(N
))
12965 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
12969 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
12970 and then Is_Volatile_Prefix
(Prefix
(N
))
12974 elsif Nkind
(N
) = N_Selected_Component
12975 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
12982 end Is_Volatile_Object
;
12984 ---------------------------
12985 -- Itype_Has_Declaration --
12986 ---------------------------
12988 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
12990 pragma Assert
(Is_Itype
(Id
));
12991 return Present
(Parent
(Id
))
12992 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
12993 N_Subtype_Declaration
)
12994 and then Defining_Entity
(Parent
(Id
)) = Id
;
12995 end Itype_Has_Declaration
;
12997 -------------------------
12998 -- Kill_Current_Values --
12999 -------------------------
13001 procedure Kill_Current_Values
13003 Last_Assignment_Only
: Boolean := False)
13006 if Is_Assignable
(Ent
) then
13007 Set_Last_Assignment
(Ent
, Empty
);
13010 if Is_Object
(Ent
) then
13011 if not Last_Assignment_Only
then
13013 Set_Current_Value
(Ent
, Empty
);
13015 if not Can_Never_Be_Null
(Ent
) then
13016 Set_Is_Known_Non_Null
(Ent
, False);
13019 Set_Is_Known_Null
(Ent
, False);
13021 -- Reset Is_Known_Valid unless type is always valid, or if we have
13022 -- a loop parameter (loop parameters are always valid, since their
13023 -- bounds are defined by the bounds given in the loop header).
13025 if not Is_Known_Valid
(Etype
(Ent
))
13026 and then Ekind
(Ent
) /= E_Loop_Parameter
13028 Set_Is_Known_Valid
(Ent
, False);
13032 end Kill_Current_Values
;
13034 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
13037 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
13038 -- Clear current value for entity E and all entities chained to E
13040 ------------------------------------------
13041 -- Kill_Current_Values_For_Entity_Chain --
13042 ------------------------------------------
13044 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
13048 while Present
(Ent
) loop
13049 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
13052 end Kill_Current_Values_For_Entity_Chain
;
13054 -- Start of processing for Kill_Current_Values
13057 -- Kill all saved checks, a special case of killing saved values
13059 if not Last_Assignment_Only
then
13063 -- Loop through relevant scopes, which includes the current scope and
13064 -- any parent scopes if the current scope is a block or a package.
13066 S
:= Current_Scope
;
13069 -- Clear current values of all entities in current scope
13071 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
13073 -- If scope is a package, also clear current values of all private
13074 -- entities in the scope.
13076 if Is_Package_Or_Generic_Package
(S
)
13077 or else Is_Concurrent_Type
(S
)
13079 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
13082 -- If this is a not a subprogram, deal with parents
13084 if not Is_Subprogram
(S
) then
13086 exit Scope_Loop
when S
= Standard_Standard
;
13090 end loop Scope_Loop
;
13091 end Kill_Current_Values
;
13093 --------------------------
13094 -- Kill_Size_Check_Code --
13095 --------------------------
13097 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
13099 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
13100 and then Present
(Size_Check_Code
(E
))
13102 Remove
(Size_Check_Code
(E
));
13103 Set_Size_Check_Code
(E
, Empty
);
13105 end Kill_Size_Check_Code
;
13107 --------------------------
13108 -- Known_To_Be_Assigned --
13109 --------------------------
13111 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
13112 P
: constant Node_Id
:= Parent
(N
);
13117 -- Test left side of assignment
13119 when N_Assignment_Statement
=>
13120 return N
= Name
(P
);
13122 -- Function call arguments are never lvalues
13124 when N_Function_Call
=>
13127 -- Positional parameter for procedure or accept call
13129 when N_Procedure_Call_Statement |
13138 Proc
:= Get_Subprogram_Entity
(P
);
13144 -- If we are not a list member, something is strange, so
13145 -- be conservative and return False.
13147 if not Is_List_Member
(N
) then
13151 -- We are going to find the right formal by stepping forward
13152 -- through the formals, as we step backwards in the actuals.
13154 Form
:= First_Formal
(Proc
);
13157 -- If no formal, something is weird, so be conservative
13158 -- and return False.
13165 exit when No
(Act
);
13166 Next_Formal
(Form
);
13169 return Ekind
(Form
) /= E_In_Parameter
;
13172 -- Named parameter for procedure or accept call
13174 when N_Parameter_Association
=>
13180 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
13186 -- Loop through formals to find the one that matches
13188 Form
:= First_Formal
(Proc
);
13190 -- If no matching formal, that's peculiar, some kind of
13191 -- previous error, so return False to be conservative.
13192 -- Actually this also happens in legal code in the case
13193 -- where P is a parameter association for an Extra_Formal???
13199 -- Else test for match
13201 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
13202 return Ekind
(Form
) /= E_In_Parameter
;
13205 Next_Formal
(Form
);
13209 -- Test for appearing in a conversion that itself appears
13210 -- in an lvalue context, since this should be an lvalue.
13212 when N_Type_Conversion
=>
13213 return Known_To_Be_Assigned
(P
);
13215 -- All other references are definitely not known to be modifications
13221 end Known_To_Be_Assigned
;
13223 ---------------------------
13224 -- Last_Source_Statement --
13225 ---------------------------
13227 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
13231 N
:= Last
(Statements
(HSS
));
13232 while Present
(N
) loop
13233 exit when Comes_From_Source
(N
);
13238 end Last_Source_Statement
;
13240 ----------------------------------
13241 -- Matching_Static_Array_Bounds --
13242 ----------------------------------
13244 function Matching_Static_Array_Bounds
13246 R_Typ
: Node_Id
) return Boolean
13248 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
13249 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
13261 if L_Ndims
/= R_Ndims
then
13265 -- Unconstrained types do not have static bounds
13267 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
13271 -- First treat specially the first dimension, as the lower bound and
13272 -- length of string literals are not stored like those of arrays.
13274 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
13275 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
13276 L_Len
:= String_Literal_Length
(L_Typ
);
13278 L_Index
:= First_Index
(L_Typ
);
13279 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
13281 if Is_OK_Static_Expression
(L_Low
)
13283 Is_OK_Static_Expression
(L_High
)
13285 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
13288 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
13295 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
13296 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
13297 R_Len
:= String_Literal_Length
(R_Typ
);
13299 R_Index
:= First_Index
(R_Typ
);
13300 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
13302 if Is_OK_Static_Expression
(R_Low
)
13304 Is_OK_Static_Expression
(R_High
)
13306 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
13309 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
13316 if (Is_OK_Static_Expression
(L_Low
)
13318 Is_OK_Static_Expression
(R_Low
))
13319 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
13320 and then L_Len
= R_Len
13327 -- Then treat all other dimensions
13329 for Indx
in 2 .. L_Ndims
loop
13333 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
13334 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
13336 if (Is_OK_Static_Expression
(L_Low
) and then
13337 Is_OK_Static_Expression
(L_High
) and then
13338 Is_OK_Static_Expression
(R_Low
) and then
13339 Is_OK_Static_Expression
(R_High
))
13340 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
13342 Expr_Value
(L_High
) = Expr_Value
(R_High
))
13350 -- If we fall through the loop, all indexes matched
13353 end Matching_Static_Array_Bounds
;
13355 -------------------
13356 -- May_Be_Lvalue --
13357 -------------------
13359 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
13360 P
: constant Node_Id
:= Parent
(N
);
13365 -- Test left side of assignment
13367 when N_Assignment_Statement
=>
13368 return N
= Name
(P
);
13370 -- Test prefix of component or attribute. Note that the prefix of an
13371 -- explicit or implicit dereference cannot be an l-value.
13373 when N_Attribute_Reference
=>
13374 return N
= Prefix
(P
)
13375 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
13377 -- For an expanded name, the name is an lvalue if the expanded name
13378 -- is an lvalue, but the prefix is never an lvalue, since it is just
13379 -- the scope where the name is found.
13381 when N_Expanded_Name
=>
13382 if N
= Prefix
(P
) then
13383 return May_Be_Lvalue
(P
);
13388 -- For a selected component A.B, A is certainly an lvalue if A.B is.
13389 -- B is a little interesting, if we have A.B := 3, there is some
13390 -- discussion as to whether B is an lvalue or not, we choose to say
13391 -- it is. Note however that A is not an lvalue if it is of an access
13392 -- type since this is an implicit dereference.
13394 when N_Selected_Component
=>
13396 and then Present
(Etype
(N
))
13397 and then Is_Access_Type
(Etype
(N
))
13401 return May_Be_Lvalue
(P
);
13404 -- For an indexed component or slice, the index or slice bounds is
13405 -- never an lvalue. The prefix is an lvalue if the indexed component
13406 -- or slice is an lvalue, except if it is an access type, where we
13407 -- have an implicit dereference.
13409 when N_Indexed_Component | N_Slice
=>
13411 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
13415 return May_Be_Lvalue
(P
);
13418 -- Prefix of a reference is an lvalue if the reference is an lvalue
13420 when N_Reference
=>
13421 return May_Be_Lvalue
(P
);
13423 -- Prefix of explicit dereference is never an lvalue
13425 when N_Explicit_Dereference
=>
13428 -- Positional parameter for subprogram, entry, or accept call.
13429 -- In older versions of Ada function call arguments are never
13430 -- lvalues. In Ada 2012 functions can have in-out parameters.
13432 when N_Subprogram_Call |
13433 N_Entry_Call_Statement |
13436 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
13440 -- The following mechanism is clumsy and fragile. A single flag
13441 -- set in Resolve_Actuals would be preferable ???
13449 Proc
:= Get_Subprogram_Entity
(P
);
13455 -- If we are not a list member, something is strange, so be
13456 -- conservative and return True.
13458 if not Is_List_Member
(N
) then
13462 -- We are going to find the right formal by stepping forward
13463 -- through the formals, as we step backwards in the actuals.
13465 Form
:= First_Formal
(Proc
);
13468 -- If no formal, something is weird, so be conservative and
13476 exit when No
(Act
);
13477 Next_Formal
(Form
);
13480 return Ekind
(Form
) /= E_In_Parameter
;
13483 -- Named parameter for procedure or accept call
13485 when N_Parameter_Association
=>
13491 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
13497 -- Loop through formals to find the one that matches
13499 Form
:= First_Formal
(Proc
);
13501 -- If no matching formal, that's peculiar, some kind of
13502 -- previous error, so return True to be conservative.
13503 -- Actually happens with legal code for an unresolved call
13504 -- where we may get the wrong homonym???
13510 -- Else test for match
13512 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
13513 return Ekind
(Form
) /= E_In_Parameter
;
13516 Next_Formal
(Form
);
13520 -- Test for appearing in a conversion that itself appears in an
13521 -- lvalue context, since this should be an lvalue.
13523 when N_Type_Conversion
=>
13524 return May_Be_Lvalue
(P
);
13526 -- Test for appearance in object renaming declaration
13528 when N_Object_Renaming_Declaration
=>
13531 -- All other references are definitely not lvalues
13539 -----------------------
13540 -- Mark_Coextensions --
13541 -----------------------
13543 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
13544 Is_Dynamic
: Boolean;
13545 -- Indicates whether the context causes nested coextensions to be
13546 -- dynamic or static
13548 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
13549 -- Recognize an allocator node and label it as a dynamic coextension
13551 --------------------
13552 -- Mark_Allocator --
13553 --------------------
13555 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
13557 if Nkind
(N
) = N_Allocator
then
13559 Set_Is_Dynamic_Coextension
(N
);
13561 -- If the allocator expression is potentially dynamic, it may
13562 -- be expanded out of order and require dynamic allocation
13563 -- anyway, so we treat the coextension itself as dynamic.
13564 -- Potential optimization ???
13566 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
13567 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
13569 Set_Is_Dynamic_Coextension
(N
);
13571 Set_Is_Static_Coextension
(N
);
13576 end Mark_Allocator
;
13578 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
13580 -- Start of processing Mark_Coextensions
13583 case Nkind
(Context_Nod
) is
13585 -- Comment here ???
13587 when N_Assignment_Statement
=>
13588 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
13590 -- An allocator that is a component of a returned aggregate
13591 -- must be dynamic.
13593 when N_Simple_Return_Statement
=>
13595 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
13598 Nkind
(Expr
) = N_Allocator
13600 (Nkind
(Expr
) = N_Qualified_Expression
13601 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
13604 -- An alloctor within an object declaration in an extended return
13605 -- statement is of necessity dynamic.
13607 when N_Object_Declaration
=>
13608 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
13610 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
13612 -- This routine should not be called for constructs which may not
13613 -- contain coextensions.
13616 raise Program_Error
;
13619 Mark_Allocators
(Root_Nod
);
13620 end Mark_Coextensions
;
13622 ----------------------
13623 -- Needs_One_Actual --
13624 ----------------------
13626 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
13627 Formal
: Entity_Id
;
13630 -- Ada 2005 or later, and formals present
13632 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
13633 Formal
:= Next_Formal
(First_Formal
(E
));
13634 while Present
(Formal
) loop
13635 if No
(Default_Value
(Formal
)) then
13639 Next_Formal
(Formal
);
13644 -- Ada 83/95 or no formals
13649 end Needs_One_Actual
;
13651 ------------------------
13652 -- New_Copy_List_Tree --
13653 ------------------------
13655 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
13660 if List
= No_List
then
13667 while Present
(E
) loop
13668 Append
(New_Copy_Tree
(E
), NL
);
13674 end New_Copy_List_Tree
;
13676 --------------------------------------------------
13677 -- New_Copy_Tree Auxiliary Data and Subprograms --
13678 --------------------------------------------------
13680 use Atree
.Unchecked_Access
;
13681 use Atree_Private_Part
;
13683 -- Our approach here requires a two pass traversal of the tree. The
13684 -- first pass visits all nodes that eventually will be copied looking
13685 -- for defining Itypes. If any defining Itypes are found, then they are
13686 -- copied, and an entry is added to the replacement map. In the second
13687 -- phase, the tree is copied, using the replacement map to replace any
13688 -- Itype references within the copied tree.
13690 -- The following hash tables are used if the Map supplied has more
13691 -- than hash threshold entries to speed up access to the map. If
13692 -- there are fewer entries, then the map is searched sequentially
13693 -- (because setting up a hash table for only a few entries takes
13694 -- more time than it saves.
13696 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
13697 -- Hash function used for hash operations
13699 -------------------
13700 -- New_Copy_Hash --
13701 -------------------
13703 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
13705 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
13712 -- The hash table NCT_Assoc associates old entities in the table
13713 -- with their corresponding new entities (i.e. the pairs of entries
13714 -- presented in the original Map argument are Key-Element pairs).
13716 package NCT_Assoc
is new Simple_HTable
(
13717 Header_Num
=> NCT_Header_Num
,
13718 Element
=> Entity_Id
,
13719 No_Element
=> Empty
,
13721 Hash
=> New_Copy_Hash
,
13722 Equal
=> Types
."=");
13724 ---------------------
13725 -- NCT_Itype_Assoc --
13726 ---------------------
13728 -- The hash table NCT_Itype_Assoc contains entries only for those
13729 -- old nodes which have a non-empty Associated_Node_For_Itype set.
13730 -- The key is the associated node, and the element is the new node
13731 -- itself (NOT the associated node for the new node).
13733 package NCT_Itype_Assoc
is new Simple_HTable
(
13734 Header_Num
=> NCT_Header_Num
,
13735 Element
=> Entity_Id
,
13736 No_Element
=> Empty
,
13738 Hash
=> New_Copy_Hash
,
13739 Equal
=> Types
."=");
13741 -------------------
13742 -- New_Copy_Tree --
13743 -------------------
13745 function New_Copy_Tree
13747 Map
: Elist_Id
:= No_Elist
;
13748 New_Sloc
: Source_Ptr
:= No_Location
;
13749 New_Scope
: Entity_Id
:= Empty
) return Node_Id
13751 Actual_Map
: Elist_Id
:= Map
;
13752 -- This is the actual map for the copy. It is initialized with the
13753 -- given elements, and then enlarged as required for Itypes that are
13754 -- copied during the first phase of the copy operation. The visit
13755 -- procedures add elements to this map as Itypes are encountered.
13756 -- The reason we cannot use Map directly, is that it may well be
13757 -- (and normally is) initialized to No_Elist, and if we have mapped
13758 -- entities, we have to reset it to point to a real Elist.
13760 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
13761 -- Called during second phase to map entities into their corresponding
13762 -- copies using Actual_Map. If the argument is not an entity, or is not
13763 -- in Actual_Map, then it is returned unchanged.
13765 procedure Build_NCT_Hash_Tables
;
13766 -- Builds hash tables (number of elements >= threshold value)
13768 function Copy_Elist_With_Replacement
13769 (Old_Elist
: Elist_Id
) return Elist_Id
;
13770 -- Called during second phase to copy element list doing replacements
13772 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
13773 -- Called during the second phase to process a copied Itype. The actual
13774 -- copy happened during the first phase (so that we could make the entry
13775 -- in the mapping), but we still have to deal with the descendents of
13776 -- the copied Itype and copy them where necessary.
13778 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
13779 -- Called during second phase to copy list doing replacements
13781 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
13782 -- Called during second phase to copy node doing replacements
13784 procedure Visit_Elist
(E
: Elist_Id
);
13785 -- Called during first phase to visit all elements of an Elist
13787 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
13788 -- Visit a single field, recursing to call Visit_Node or Visit_List
13789 -- if the field is a syntactic descendent of the current node (i.e.
13790 -- its parent is Node N).
13792 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
13793 -- Called during first phase to visit subsidiary fields of a defining
13794 -- Itype, and also create a copy and make an entry in the replacement
13795 -- map for the new copy.
13797 procedure Visit_List
(L
: List_Id
);
13798 -- Called during first phase to visit all elements of a List
13800 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
13801 -- Called during first phase to visit a node and all its subtrees
13807 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
13812 if not Has_Extension
(N
) or else No
(Actual_Map
) then
13815 elsif NCT_Hash_Tables_Used
then
13816 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
13818 if Present
(Ent
) then
13824 -- No hash table used, do serial search
13827 E
:= First_Elmt
(Actual_Map
);
13828 while Present
(E
) loop
13829 if Node
(E
) = N
then
13830 return Node
(Next_Elmt
(E
));
13832 E
:= Next_Elmt
(Next_Elmt
(E
));
13840 ---------------------------
13841 -- Build_NCT_Hash_Tables --
13842 ---------------------------
13844 procedure Build_NCT_Hash_Tables
is
13848 if NCT_Hash_Table_Setup
then
13850 NCT_Itype_Assoc
.Reset
;
13853 Elmt
:= First_Elmt
(Actual_Map
);
13854 while Present
(Elmt
) loop
13855 Ent
:= Node
(Elmt
);
13857 -- Get new entity, and associate old and new
13860 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
13862 if Is_Type
(Ent
) then
13864 Anode
: constant Entity_Id
:=
13865 Associated_Node_For_Itype
(Ent
);
13868 if Present
(Anode
) then
13870 -- Enter a link between the associated node of the
13871 -- old Itype and the new Itype, for updating later
13872 -- when node is copied.
13874 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
13882 NCT_Hash_Tables_Used
:= True;
13883 NCT_Hash_Table_Setup
:= True;
13884 end Build_NCT_Hash_Tables
;
13886 ---------------------------------
13887 -- Copy_Elist_With_Replacement --
13888 ---------------------------------
13890 function Copy_Elist_With_Replacement
13891 (Old_Elist
: Elist_Id
) return Elist_Id
13894 New_Elist
: Elist_Id
;
13897 if No
(Old_Elist
) then
13901 New_Elist
:= New_Elmt_List
;
13903 M
:= First_Elmt
(Old_Elist
);
13904 while Present
(M
) loop
13905 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
13911 end Copy_Elist_With_Replacement
;
13913 ---------------------------------
13914 -- Copy_Itype_With_Replacement --
13915 ---------------------------------
13917 -- This routine exactly parallels its phase one analog Visit_Itype,
13919 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
13921 -- Translate Next_Entity, Scope and Etype fields, in case they
13922 -- reference entities that have been mapped into copies.
13924 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
13925 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
13927 if Present
(New_Scope
) then
13928 Set_Scope
(New_Itype
, New_Scope
);
13930 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
13933 -- Copy referenced fields
13935 if Is_Discrete_Type
(New_Itype
) then
13936 Set_Scalar_Range
(New_Itype
,
13937 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
13939 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
13940 Set_Discriminant_Constraint
(New_Itype
,
13941 Copy_Elist_With_Replacement
13942 (Discriminant_Constraint
(New_Itype
)));
13944 elsif Is_Array_Type
(New_Itype
) then
13945 if Present
(First_Index
(New_Itype
)) then
13946 Set_First_Index
(New_Itype
,
13947 First
(Copy_List_With_Replacement
13948 (List_Containing
(First_Index
(New_Itype
)))));
13951 if Is_Packed
(New_Itype
) then
13952 Set_Packed_Array_Impl_Type
(New_Itype
,
13953 Copy_Node_With_Replacement
13954 (Packed_Array_Impl_Type
(New_Itype
)));
13957 end Copy_Itype_With_Replacement
;
13959 --------------------------------
13960 -- Copy_List_With_Replacement --
13961 --------------------------------
13963 function Copy_List_With_Replacement
13964 (Old_List
: List_Id
) return List_Id
13966 New_List
: List_Id
;
13970 if Old_List
= No_List
then
13974 New_List
:= Empty_List
;
13976 E
:= First
(Old_List
);
13977 while Present
(E
) loop
13978 Append
(Copy_Node_With_Replacement
(E
), New_List
);
13984 end Copy_List_With_Replacement
;
13986 --------------------------------
13987 -- Copy_Node_With_Replacement --
13988 --------------------------------
13990 function Copy_Node_With_Replacement
13991 (Old_Node
: Node_Id
) return Node_Id
13993 New_Node
: Node_Id
;
13995 procedure Adjust_Named_Associations
13996 (Old_Node
: Node_Id
;
13997 New_Node
: Node_Id
);
13998 -- If a call node has named associations, these are chained through
13999 -- the First_Named_Actual, Next_Named_Actual links. These must be
14000 -- propagated separately to the new parameter list, because these
14001 -- are not syntactic fields.
14003 function Copy_Field_With_Replacement
14004 (Field
: Union_Id
) return Union_Id
;
14005 -- Given Field, which is a field of Old_Node, return a copy of it
14006 -- if it is a syntactic field (i.e. its parent is Node), setting
14007 -- the parent of the copy to poit to New_Node. Otherwise returns
14008 -- the field (possibly mapped if it is an entity).
14010 -------------------------------
14011 -- Adjust_Named_Associations --
14012 -------------------------------
14014 procedure Adjust_Named_Associations
14015 (Old_Node
: Node_Id
;
14016 New_Node
: Node_Id
)
14021 Old_Next
: Node_Id
;
14022 New_Next
: Node_Id
;
14025 Old_E
:= First
(Parameter_Associations
(Old_Node
));
14026 New_E
:= First
(Parameter_Associations
(New_Node
));
14027 while Present
(Old_E
) loop
14028 if Nkind
(Old_E
) = N_Parameter_Association
14029 and then Present
(Next_Named_Actual
(Old_E
))
14031 if First_Named_Actual
(Old_Node
)
14032 = Explicit_Actual_Parameter
(Old_E
)
14034 Set_First_Named_Actual
14035 (New_Node
, Explicit_Actual_Parameter
(New_E
));
14038 -- Now scan parameter list from the beginning,to locate
14039 -- next named actual, which can be out of order.
14041 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
14042 New_Next
:= First
(Parameter_Associations
(New_Node
));
14044 while Nkind
(Old_Next
) /= N_Parameter_Association
14045 or else Explicit_Actual_Parameter
(Old_Next
)
14046 /= Next_Named_Actual
(Old_E
)
14052 Set_Next_Named_Actual
14053 (New_E
, Explicit_Actual_Parameter
(New_Next
));
14059 end Adjust_Named_Associations
;
14061 ---------------------------------
14062 -- Copy_Field_With_Replacement --
14063 ---------------------------------
14065 function Copy_Field_With_Replacement
14066 (Field
: Union_Id
) return Union_Id
14069 if Field
= Union_Id
(Empty
) then
14072 elsif Field
in Node_Range
then
14074 Old_N
: constant Node_Id
:= Node_Id
(Field
);
14078 -- If syntactic field, as indicated by the parent pointer
14079 -- being set, then copy the referenced node recursively.
14081 if Parent
(Old_N
) = Old_Node
then
14082 New_N
:= Copy_Node_With_Replacement
(Old_N
);
14084 if New_N
/= Old_N
then
14085 Set_Parent
(New_N
, New_Node
);
14088 -- For semantic fields, update possible entity reference
14089 -- from the replacement map.
14092 New_N
:= Assoc
(Old_N
);
14095 return Union_Id
(New_N
);
14098 elsif Field
in List_Range
then
14100 Old_L
: constant List_Id
:= List_Id
(Field
);
14104 -- If syntactic field, as indicated by the parent pointer,
14105 -- then recursively copy the entire referenced list.
14107 if Parent
(Old_L
) = Old_Node
then
14108 New_L
:= Copy_List_With_Replacement
(Old_L
);
14109 Set_Parent
(New_L
, New_Node
);
14111 -- For semantic list, just returned unchanged
14117 return Union_Id
(New_L
);
14120 -- Anything other than a list or a node is returned unchanged
14125 end Copy_Field_With_Replacement
;
14127 -- Start of processing for Copy_Node_With_Replacement
14130 if Old_Node
<= Empty_Or_Error
then
14133 elsif Has_Extension
(Old_Node
) then
14134 return Assoc
(Old_Node
);
14137 New_Node
:= New_Copy
(Old_Node
);
14139 -- If the node we are copying is the associated node of a
14140 -- previously copied Itype, then adjust the associated node
14141 -- of the copy of that Itype accordingly.
14143 if Present
(Actual_Map
) then
14149 -- Case of hash table used
14151 if NCT_Hash_Tables_Used
then
14152 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
14154 if Present
(Ent
) then
14155 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
14158 -- Case of no hash table used
14161 E
:= First_Elmt
(Actual_Map
);
14162 while Present
(E
) loop
14163 if Is_Itype
(Node
(E
))
14165 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
14167 Set_Associated_Node_For_Itype
14168 (Node
(Next_Elmt
(E
)), New_Node
);
14171 E
:= Next_Elmt
(Next_Elmt
(E
));
14177 -- Recursively copy descendents
14180 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
14182 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
14184 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
14186 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
14188 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
14190 -- Adjust Sloc of new node if necessary
14192 if New_Sloc
/= No_Location
then
14193 Set_Sloc
(New_Node
, New_Sloc
);
14195 -- If we adjust the Sloc, then we are essentially making
14196 -- a completely new node, so the Comes_From_Source flag
14197 -- should be reset to the proper default value.
14199 Nodes
.Table
(New_Node
).Comes_From_Source
:=
14200 Default_Node
.Comes_From_Source
;
14203 -- If the node is call and has named associations,
14204 -- set the corresponding links in the copy.
14206 if (Nkind
(Old_Node
) = N_Function_Call
14207 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
14209 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
14210 and then Present
(First_Named_Actual
(Old_Node
))
14212 Adjust_Named_Associations
(Old_Node
, New_Node
);
14215 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14216 -- The replacement mechanism applies to entities, and is not used
14217 -- here. Eventually we may need a more general graph-copying
14218 -- routine. For now, do a sequential search to find desired node.
14220 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
14221 and then Present
(First_Real_Statement
(Old_Node
))
14224 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
14228 N1
:= First
(Statements
(Old_Node
));
14229 N2
:= First
(Statements
(New_Node
));
14231 while N1
/= Old_F
loop
14236 Set_First_Real_Statement
(New_Node
, N2
);
14241 -- All done, return copied node
14244 end Copy_Node_With_Replacement
;
14250 procedure Visit_Elist
(E
: Elist_Id
) is
14253 if Present
(E
) then
14254 Elmt
:= First_Elmt
(E
);
14256 while Elmt
/= No_Elmt
loop
14257 Visit_Node
(Node
(Elmt
));
14267 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
14269 if F
= Union_Id
(Empty
) then
14272 elsif F
in Node_Range
then
14274 -- Copy node if it is syntactic, i.e. its parent pointer is
14275 -- set to point to the field that referenced it (certain
14276 -- Itypes will also meet this criterion, which is fine, since
14277 -- these are clearly Itypes that do need to be copied, since
14278 -- we are copying their parent.)
14280 if Parent
(Node_Id
(F
)) = N
then
14281 Visit_Node
(Node_Id
(F
));
14284 -- Another case, if we are pointing to an Itype, then we want
14285 -- to copy it if its associated node is somewhere in the tree
14288 -- Note: the exclusion of self-referential copies is just an
14289 -- optimization, since the search of the already copied list
14290 -- would catch it, but it is a common case (Etype pointing
14291 -- to itself for an Itype that is a base type).
14293 elsif Has_Extension
(Node_Id
(F
))
14294 and then Is_Itype
(Entity_Id
(F
))
14295 and then Node_Id
(F
) /= N
14301 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
14302 while Present
(P
) loop
14304 Visit_Node
(Node_Id
(F
));
14311 -- An Itype whose parent is not being copied definitely
14312 -- should NOT be copied, since it does not belong in any
14313 -- sense to the copied subtree.
14319 elsif F
in List_Range
and then Parent
(List_Id
(F
)) = N
then
14320 Visit_List
(List_Id
(F
));
14329 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
14330 New_Itype
: Entity_Id
;
14335 -- Itypes that describe the designated type of access to subprograms
14336 -- have the structure of subprogram declarations, with signatures,
14337 -- etc. Either we duplicate the signatures completely, or choose to
14338 -- share such itypes, which is fine because their elaboration will
14339 -- have no side effects.
14341 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
14345 New_Itype
:= New_Copy
(Old_Itype
);
14347 -- The new Itype has all the attributes of the old one, and
14348 -- we just copy the contents of the entity. However, the back-end
14349 -- needs different names for debugging purposes, so we create a
14350 -- new internal name for it in all cases.
14352 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
14354 -- If our associated node is an entity that has already been copied,
14355 -- then set the associated node of the copy to point to the right
14356 -- copy. If we have copied an Itype that is itself the associated
14357 -- node of some previously copied Itype, then we set the right
14358 -- pointer in the other direction.
14360 if Present
(Actual_Map
) then
14362 -- Case of hash tables used
14364 if NCT_Hash_Tables_Used
then
14366 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
14368 if Present
(Ent
) then
14369 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
14372 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
14373 if Present
(Ent
) then
14374 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
14376 -- If the hash table has no association for this Itype and
14377 -- its associated node, enter one now.
14380 NCT_Itype_Assoc
.Set
14381 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
14384 -- Case of hash tables not used
14387 E
:= First_Elmt
(Actual_Map
);
14388 while Present
(E
) loop
14389 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
14390 Set_Associated_Node_For_Itype
14391 (New_Itype
, Node
(Next_Elmt
(E
)));
14394 if Is_Type
(Node
(E
))
14395 and then Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
14397 Set_Associated_Node_For_Itype
14398 (Node
(Next_Elmt
(E
)), New_Itype
);
14401 E
:= Next_Elmt
(Next_Elmt
(E
));
14406 if Present
(Freeze_Node
(New_Itype
)) then
14407 Set_Is_Frozen
(New_Itype
, False);
14408 Set_Freeze_Node
(New_Itype
, Empty
);
14411 -- Add new association to map
14413 if No
(Actual_Map
) then
14414 Actual_Map
:= New_Elmt_List
;
14417 Append_Elmt
(Old_Itype
, Actual_Map
);
14418 Append_Elmt
(New_Itype
, Actual_Map
);
14420 if NCT_Hash_Tables_Used
then
14421 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
14424 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
14426 if NCT_Table_Entries
> NCT_Hash_Threshold
then
14427 Build_NCT_Hash_Tables
;
14431 -- If a record subtype is simply copied, the entity list will be
14432 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
14434 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
14435 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
14438 -- Visit descendents that eventually get copied
14440 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
14442 if Is_Discrete_Type
(Old_Itype
) then
14443 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
14445 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
14446 -- ??? This should involve call to Visit_Field
14447 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
14449 elsif Is_Array_Type
(Old_Itype
) then
14450 if Present
(First_Index
(Old_Itype
)) then
14451 Visit_Field
(Union_Id
(List_Containing
14452 (First_Index
(Old_Itype
))),
14456 if Is_Packed
(Old_Itype
) then
14457 Visit_Field
(Union_Id
(Packed_Array_Impl_Type
(Old_Itype
)),
14467 procedure Visit_List
(L
: List_Id
) is
14470 if L
/= No_List
then
14473 while Present
(N
) loop
14484 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
14486 -- Start of processing for Visit_Node
14489 -- Handle case of an Itype, which must be copied
14491 if Has_Extension
(N
) and then Is_Itype
(N
) then
14493 -- Nothing to do if already in the list. This can happen with an
14494 -- Itype entity that appears more than once in the tree.
14495 -- Note that we do not want to visit descendents in this case.
14497 -- Test for already in list when hash table is used
14499 if NCT_Hash_Tables_Used
then
14500 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
14504 -- Test for already in list when hash table not used
14510 if Present
(Actual_Map
) then
14511 E
:= First_Elmt
(Actual_Map
);
14512 while Present
(E
) loop
14513 if Node
(E
) = N
then
14516 E
:= Next_Elmt
(Next_Elmt
(E
));
14526 -- Visit descendents
14528 Visit_Field
(Field1
(N
), N
);
14529 Visit_Field
(Field2
(N
), N
);
14530 Visit_Field
(Field3
(N
), N
);
14531 Visit_Field
(Field4
(N
), N
);
14532 Visit_Field
(Field5
(N
), N
);
14535 -- Start of processing for New_Copy_Tree
14540 -- See if we should use hash table
14542 if No
(Actual_Map
) then
14543 NCT_Hash_Tables_Used
:= False;
14550 NCT_Table_Entries
:= 0;
14552 Elmt
:= First_Elmt
(Actual_Map
);
14553 while Present
(Elmt
) loop
14554 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
14559 if NCT_Table_Entries
> NCT_Hash_Threshold
then
14560 Build_NCT_Hash_Tables
;
14562 NCT_Hash_Tables_Used
:= False;
14567 -- Hash table set up if required, now start phase one by visiting
14568 -- top node (we will recursively visit the descendents).
14570 Visit_Node
(Source
);
14572 -- Now the second phase of the copy can start. First we process
14573 -- all the mapped entities, copying their descendents.
14575 if Present
(Actual_Map
) then
14578 New_Itype
: Entity_Id
;
14580 Elmt
:= First_Elmt
(Actual_Map
);
14581 while Present
(Elmt
) loop
14583 New_Itype
:= Node
(Elmt
);
14584 Copy_Itype_With_Replacement
(New_Itype
);
14590 -- Now we can copy the actual tree
14592 return Copy_Node_With_Replacement
(Source
);
14595 -------------------------
14596 -- New_External_Entity --
14597 -------------------------
14599 function New_External_Entity
14600 (Kind
: Entity_Kind
;
14601 Scope_Id
: Entity_Id
;
14602 Sloc_Value
: Source_Ptr
;
14603 Related_Id
: Entity_Id
;
14604 Suffix
: Character;
14605 Suffix_Index
: Nat
:= 0;
14606 Prefix
: Character := ' ') return Entity_Id
14608 N
: constant Entity_Id
:=
14609 Make_Defining_Identifier
(Sloc_Value
,
14611 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
14614 Set_Ekind
(N
, Kind
);
14615 Set_Is_Internal
(N
, True);
14616 Append_Entity
(N
, Scope_Id
);
14617 Set_Public_Status
(N
);
14619 if Kind
in Type_Kind
then
14620 Init_Size_Align
(N
);
14624 end New_External_Entity
;
14626 -------------------------
14627 -- New_Internal_Entity --
14628 -------------------------
14630 function New_Internal_Entity
14631 (Kind
: Entity_Kind
;
14632 Scope_Id
: Entity_Id
;
14633 Sloc_Value
: Source_Ptr
;
14634 Id_Char
: Character) return Entity_Id
14636 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
14639 Set_Ekind
(N
, Kind
);
14640 Set_Is_Internal
(N
, True);
14641 Append_Entity
(N
, Scope_Id
);
14643 if Kind
in Type_Kind
then
14644 Init_Size_Align
(N
);
14648 end New_Internal_Entity
;
14654 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
14658 -- If we are pointing at a positional parameter, it is a member of a
14659 -- node list (the list of parameters), and the next parameter is the
14660 -- next node on the list, unless we hit a parameter association, then
14661 -- we shift to using the chain whose head is the First_Named_Actual in
14662 -- the parent, and then is threaded using the Next_Named_Actual of the
14663 -- Parameter_Association. All this fiddling is because the original node
14664 -- list is in the textual call order, and what we need is the
14665 -- declaration order.
14667 if Is_List_Member
(Actual_Id
) then
14668 N
:= Next
(Actual_Id
);
14670 if Nkind
(N
) = N_Parameter_Association
then
14671 return First_Named_Actual
(Parent
(Actual_Id
));
14677 return Next_Named_Actual
(Parent
(Actual_Id
));
14681 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
14683 Actual_Id
:= Next_Actual
(Actual_Id
);
14686 -----------------------
14687 -- Normalize_Actuals --
14688 -----------------------
14690 -- Chain actuals according to formals of subprogram. If there are no named
14691 -- associations, the chain is simply the list of Parameter Associations,
14692 -- since the order is the same as the declaration order. If there are named
14693 -- associations, then the First_Named_Actual field in the N_Function_Call
14694 -- or N_Procedure_Call_Statement node points to the Parameter_Association
14695 -- node for the parameter that comes first in declaration order. The
14696 -- remaining named parameters are then chained in declaration order using
14697 -- Next_Named_Actual.
14699 -- This routine also verifies that the number of actuals is compatible with
14700 -- the number and default values of formals, but performs no type checking
14701 -- (type checking is done by the caller).
14703 -- If the matching succeeds, Success is set to True and the caller proceeds
14704 -- with type-checking. If the match is unsuccessful, then Success is set to
14705 -- False, and the caller attempts a different interpretation, if there is
14708 -- If the flag Report is on, the call is not overloaded, and a failure to
14709 -- match can be reported here, rather than in the caller.
14711 procedure Normalize_Actuals
14715 Success
: out Boolean)
14717 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
14718 Actual
: Node_Id
:= Empty
;
14719 Formal
: Entity_Id
;
14720 Last
: Node_Id
:= Empty
;
14721 First_Named
: Node_Id
:= Empty
;
14724 Formals_To_Match
: Integer := 0;
14725 Actuals_To_Match
: Integer := 0;
14727 procedure Chain
(A
: Node_Id
);
14728 -- Add named actual at the proper place in the list, using the
14729 -- Next_Named_Actual link.
14731 function Reporting
return Boolean;
14732 -- Determines if an error is to be reported. To report an error, we
14733 -- need Report to be True, and also we do not report errors caused
14734 -- by calls to init procs that occur within other init procs. Such
14735 -- errors must always be cascaded errors, since if all the types are
14736 -- declared correctly, the compiler will certainly build decent calls.
14742 procedure Chain
(A
: Node_Id
) is
14746 -- Call node points to first actual in list
14748 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
14751 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
14755 Set_Next_Named_Actual
(Last
, Empty
);
14762 function Reporting
return Boolean is
14767 elsif not Within_Init_Proc
then
14770 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
14778 -- Start of processing for Normalize_Actuals
14781 if Is_Access_Type
(S
) then
14783 -- The name in the call is a function call that returns an access
14784 -- to subprogram. The designated type has the list of formals.
14786 Formal
:= First_Formal
(Designated_Type
(S
));
14788 Formal
:= First_Formal
(S
);
14791 while Present
(Formal
) loop
14792 Formals_To_Match
:= Formals_To_Match
+ 1;
14793 Next_Formal
(Formal
);
14796 -- Find if there is a named association, and verify that no positional
14797 -- associations appear after named ones.
14799 if Present
(Actuals
) then
14800 Actual
:= First
(Actuals
);
14803 while Present
(Actual
)
14804 and then Nkind
(Actual
) /= N_Parameter_Association
14806 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14810 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
14812 -- Most common case: positional notation, no defaults
14817 elsif Actuals_To_Match
> Formals_To_Match
then
14819 -- Too many actuals: will not work
14822 if Is_Entity_Name
(Name
(N
)) then
14823 Error_Msg_N
("too many arguments in call to&", Name
(N
));
14825 Error_Msg_N
("too many arguments in call", N
);
14833 First_Named
:= Actual
;
14835 while Present
(Actual
) loop
14836 if Nkind
(Actual
) /= N_Parameter_Association
then
14838 ("positional parameters not allowed after named ones", Actual
);
14843 Actuals_To_Match
:= Actuals_To_Match
+ 1;
14849 if Present
(Actuals
) then
14850 Actual
:= First
(Actuals
);
14853 Formal
:= First_Formal
(S
);
14854 while Present
(Formal
) loop
14856 -- Match the formals in order. If the corresponding actual is
14857 -- positional, nothing to do. Else scan the list of named actuals
14858 -- to find the one with the right name.
14860 if Present
(Actual
)
14861 and then Nkind
(Actual
) /= N_Parameter_Association
14864 Actuals_To_Match
:= Actuals_To_Match
- 1;
14865 Formals_To_Match
:= Formals_To_Match
- 1;
14868 -- For named parameters, search the list of actuals to find
14869 -- one that matches the next formal name.
14871 Actual
:= First_Named
;
14873 while Present
(Actual
) loop
14874 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
14877 Actuals_To_Match
:= Actuals_To_Match
- 1;
14878 Formals_To_Match
:= Formals_To_Match
- 1;
14886 if Ekind
(Formal
) /= E_In_Parameter
14887 or else No
(Default_Value
(Formal
))
14890 if (Comes_From_Source
(S
)
14891 or else Sloc
(S
) = Standard_Location
)
14892 and then Is_Overloadable
(S
)
14896 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
14898 N_Parameter_Association
)
14899 and then Ekind
(S
) /= E_Function
14901 Set_Etype
(N
, Etype
(S
));
14904 Error_Msg_Name_1
:= Chars
(S
);
14905 Error_Msg_Sloc
:= Sloc
(S
);
14907 ("missing argument for parameter & "
14908 & "in call to % declared #", N
, Formal
);
14911 elsif Is_Overloadable
(S
) then
14912 Error_Msg_Name_1
:= Chars
(S
);
14914 -- Point to type derivation that generated the
14917 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
14920 ("missing argument for parameter & "
14921 & "in call to % (inherited) #", N
, Formal
);
14925 ("missing argument for parameter &", N
, Formal
);
14933 Formals_To_Match
:= Formals_To_Match
- 1;
14938 Next_Formal
(Formal
);
14941 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
14948 -- Find some superfluous named actual that did not get
14949 -- attached to the list of associations.
14951 Actual
:= First
(Actuals
);
14952 while Present
(Actual
) loop
14953 if Nkind
(Actual
) = N_Parameter_Association
14954 and then Actual
/= Last
14955 and then No
(Next_Named_Actual
(Actual
))
14957 Error_Msg_N
("unmatched actual & in call",
14958 Selector_Name
(Actual
));
14969 end Normalize_Actuals
;
14971 --------------------------------
14972 -- Note_Possible_Modification --
14973 --------------------------------
14975 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
14976 Modification_Comes_From_Source
: constant Boolean :=
14977 Comes_From_Source
(Parent
(N
));
14983 -- Loop to find referenced entity, if there is one
14989 if Is_Entity_Name
(Exp
) then
14990 Ent
:= Entity
(Exp
);
14992 -- If the entity is missing, it is an undeclared identifier,
14993 -- and there is nothing to annotate.
14999 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
15001 P
: constant Node_Id
:= Prefix
(Exp
);
15004 -- In formal verification mode, keep track of all reads and
15005 -- writes through explicit dereferences.
15007 if GNATprove_Mode
then
15008 SPARK_Specific
.Generate_Dereference
(N
, 'm');
15011 if Nkind
(P
) = N_Selected_Component
15012 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
15014 -- Case of a reference to an entry formal
15016 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
15018 elsif Nkind
(P
) = N_Identifier
15019 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
15020 and then Present
(Expression
(Parent
(Entity
(P
))))
15021 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
15024 -- Case of a reference to a value on which side effects have
15027 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
15035 elsif Nkind_In
(Exp
, N_Type_Conversion
,
15036 N_Unchecked_Type_Conversion
)
15038 Exp
:= Expression
(Exp
);
15041 elsif Nkind_In
(Exp
, N_Slice
,
15042 N_Indexed_Component
,
15043 N_Selected_Component
)
15045 -- Special check, if the prefix is an access type, then return
15046 -- since we are modifying the thing pointed to, not the prefix.
15047 -- When we are expanding, most usually the prefix is replaced
15048 -- by an explicit dereference, and this test is not needed, but
15049 -- in some cases (notably -gnatc mode and generics) when we do
15050 -- not do full expansion, we need this special test.
15052 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
15055 -- Otherwise go to prefix and keep going
15058 Exp
:= Prefix
(Exp
);
15062 -- All other cases, not a modification
15068 -- Now look for entity being referenced
15070 if Present
(Ent
) then
15071 if Is_Object
(Ent
) then
15072 if Comes_From_Source
(Exp
)
15073 or else Modification_Comes_From_Source
15075 -- Give warning if pragma unmodified given and we are
15076 -- sure this is a modification.
15078 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
15079 Error_Msg_NE
("??pragma Unmodified given for &!", N
, Ent
);
15082 Set_Never_Set_In_Source
(Ent
, False);
15085 Set_Is_True_Constant
(Ent
, False);
15086 Set_Current_Value
(Ent
, Empty
);
15087 Set_Is_Known_Null
(Ent
, False);
15089 if not Can_Never_Be_Null
(Ent
) then
15090 Set_Is_Known_Non_Null
(Ent
, False);
15093 -- Follow renaming chain
15095 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
15096 and then Present
(Renamed_Object
(Ent
))
15098 Exp
:= Renamed_Object
(Ent
);
15100 -- If the entity is the loop variable in an iteration over
15101 -- a container, retrieve container expression to indicate
15102 -- possible modificastion.
15104 if Present
(Related_Expression
(Ent
))
15105 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
15106 N_Iterator_Specification
15108 Exp
:= Original_Node
(Related_Expression
(Ent
));
15113 -- The expression may be the renaming of a subcomponent of an
15114 -- array or container. The assignment to the subcomponent is
15115 -- a modification of the container.
15117 elsif Comes_From_Source
(Original_Node
(Exp
))
15118 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
15119 N_Indexed_Component
)
15121 Exp
:= Prefix
(Original_Node
(Exp
));
15125 -- Generate a reference only if the assignment comes from
15126 -- source. This excludes, for example, calls to a dispatching
15127 -- assignment operation when the left-hand side is tagged. In
15128 -- GNATprove mode, we need those references also on generated
15129 -- code, as these are used to compute the local effects of
15132 if Modification_Comes_From_Source
or GNATprove_Mode
then
15133 Generate_Reference
(Ent
, Exp
, 'm');
15135 -- If the target of the assignment is the bound variable
15136 -- in an iterator, indicate that the corresponding array
15137 -- or container is also modified.
15139 if Ada_Version
>= Ada_2012
15140 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
15143 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
15146 -- TBD : in the full version of the construct, the
15147 -- domain of iteration can be given by an expression.
15149 if Is_Entity_Name
(Domain
) then
15150 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
15151 Set_Is_True_Constant
(Entity
(Domain
), False);
15152 Set_Never_Set_In_Source
(Entity
(Domain
), False);
15158 Check_Nested_Access
(Ent
);
15163 -- If we are sure this is a modification from source, and we know
15164 -- this modifies a constant, then give an appropriate warning.
15166 if Overlays_Constant
(Ent
)
15167 and then (Modification_Comes_From_Source
and Sure
)
15170 A
: constant Node_Id
:= Address_Clause
(Ent
);
15172 if Present
(A
) then
15174 Exp
: constant Node_Id
:= Expression
(A
);
15176 if Nkind
(Exp
) = N_Attribute_Reference
15177 and then Attribute_Name
(Exp
) = Name_Address
15178 and then Is_Entity_Name
(Prefix
(Exp
))
15180 Error_Msg_Sloc
:= Sloc
(A
);
15182 ("constant& may be modified via address "
15183 & "clause#??", N
, Entity
(Prefix
(Exp
)));
15196 end Note_Possible_Modification
;
15198 -------------------------
15199 -- Object_Access_Level --
15200 -------------------------
15202 -- Returns the static accessibility level of the view denoted by Obj. Note
15203 -- that the value returned is the result of a call to Scope_Depth. Only
15204 -- scope depths associated with dynamic scopes can actually be returned.
15205 -- Since only relative levels matter for accessibility checking, the fact
15206 -- that the distance between successive levels of accessibility is not
15207 -- always one is immaterial (invariant: if level(E2) is deeper than
15208 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15210 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
15211 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
15212 -- Determine whether N is a construct of the form
15213 -- Some_Type (Operand._tag'Address)
15214 -- This construct appears in the context of dispatching calls.
15216 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
15217 -- An explicit dereference is created when removing side-effects from
15218 -- expressions for constraint checking purposes. In this case a local
15219 -- access type is created for it. The correct access level is that of
15220 -- the original source node. We detect this case by noting that the
15221 -- prefix of the dereference is created by an object declaration whose
15222 -- initial expression is a reference.
15224 -----------------------------
15225 -- Is_Interface_Conversion --
15226 -----------------------------
15228 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
15230 return Nkind
(N
) = N_Unchecked_Type_Conversion
15231 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
15232 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
15233 end Is_Interface_Conversion
;
15239 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
15240 Pref
: constant Node_Id
:= Prefix
(Obj
);
15242 if Is_Entity_Name
(Pref
)
15243 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
15244 and then Present
(Expression
(Parent
(Entity
(Pref
))))
15245 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
15247 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
15257 -- Start of processing for Object_Access_Level
15260 if Nkind
(Obj
) = N_Defining_Identifier
15261 or else Is_Entity_Name
(Obj
)
15263 if Nkind
(Obj
) = N_Defining_Identifier
then
15269 if Is_Prival
(E
) then
15270 E
:= Prival_Link
(E
);
15273 -- If E is a type then it denotes a current instance. For this case
15274 -- we add one to the normal accessibility level of the type to ensure
15275 -- that current instances are treated as always being deeper than
15276 -- than the level of any visible named access type (see 3.10.2(21)).
15278 if Is_Type
(E
) then
15279 return Type_Access_Level
(E
) + 1;
15281 elsif Present
(Renamed_Object
(E
)) then
15282 return Object_Access_Level
(Renamed_Object
(E
));
15284 -- Similarly, if E is a component of the current instance of a
15285 -- protected type, any instance of it is assumed to be at a deeper
15286 -- level than the type. For a protected object (whose type is an
15287 -- anonymous protected type) its components are at the same level
15288 -- as the type itself.
15290 elsif not Is_Overloadable
(E
)
15291 and then Ekind
(Scope
(E
)) = E_Protected_Type
15292 and then Comes_From_Source
(Scope
(E
))
15294 return Type_Access_Level
(Scope
(E
)) + 1;
15297 -- Aliased formals take their access level from the point of call.
15298 -- This is smaller than the level of the subprogram itself.
15300 if Is_Formal
(E
) and then Is_Aliased
(E
) then
15301 return Type_Access_Level
(Etype
(E
));
15304 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
15308 elsif Nkind
(Obj
) = N_Selected_Component
then
15309 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
15310 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15312 return Object_Access_Level
(Prefix
(Obj
));
15315 elsif Nkind
(Obj
) = N_Indexed_Component
then
15316 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
15317 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15319 return Object_Access_Level
(Prefix
(Obj
));
15322 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
15324 -- If the prefix is a selected access discriminant then we make a
15325 -- recursive call on the prefix, which will in turn check the level
15326 -- of the prefix object of the selected discriminant.
15328 -- In Ada 2012, if the discriminant has implicit dereference and
15329 -- the context is a selected component, treat this as an object of
15330 -- unknown scope (see below). This is necessary in compile-only mode;
15331 -- otherwise expansion will already have transformed the prefix into
15334 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
15335 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
15337 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
15339 (not Has_Implicit_Dereference
15340 (Entity
(Selector_Name
(Prefix
(Obj
))))
15341 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
15343 return Object_Access_Level
(Prefix
(Obj
));
15345 -- Detect an interface conversion in the context of a dispatching
15346 -- call. Use the original form of the conversion to find the access
15347 -- level of the operand.
15349 elsif Is_Interface
(Etype
(Obj
))
15350 and then Is_Interface_Conversion
(Prefix
(Obj
))
15351 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
15353 return Object_Access_Level
(Original_Node
(Obj
));
15355 elsif not Comes_From_Source
(Obj
) then
15357 Ref
: constant Node_Id
:= Reference_To
(Obj
);
15359 if Present
(Ref
) then
15360 return Object_Access_Level
(Ref
);
15362 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15367 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
15370 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
15371 return Object_Access_Level
(Expression
(Obj
));
15373 elsif Nkind
(Obj
) = N_Function_Call
then
15375 -- Function results are objects, so we get either the access level of
15376 -- the function or, in the case of an indirect call, the level of the
15377 -- access-to-subprogram type. (This code is used for Ada 95, but it
15378 -- looks wrong, because it seems that we should be checking the level
15379 -- of the call itself, even for Ada 95. However, using the Ada 2005
15380 -- version of the code causes regressions in several tests that are
15381 -- compiled with -gnat95. ???)
15383 if Ada_Version
< Ada_2005
then
15384 if Is_Entity_Name
(Name
(Obj
)) then
15385 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
15387 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
15390 -- For Ada 2005, the level of the result object of a function call is
15391 -- defined to be the level of the call's innermost enclosing master.
15392 -- We determine that by querying the depth of the innermost enclosing
15396 Return_Master_Scope_Depth_Of_Call
: declare
15398 function Innermost_Master_Scope_Depth
15399 (N
: Node_Id
) return Uint
;
15400 -- Returns the scope depth of the given node's innermost
15401 -- enclosing dynamic scope (effectively the accessibility
15402 -- level of the innermost enclosing master).
15404 ----------------------------------
15405 -- Innermost_Master_Scope_Depth --
15406 ----------------------------------
15408 function Innermost_Master_Scope_Depth
15409 (N
: Node_Id
) return Uint
15411 Node_Par
: Node_Id
:= Parent
(N
);
15414 -- Locate the nearest enclosing node (by traversing Parents)
15415 -- that Defining_Entity can be applied to, and return the
15416 -- depth of that entity's nearest enclosing dynamic scope.
15418 while Present
(Node_Par
) loop
15419 case Nkind
(Node_Par
) is
15420 when N_Component_Declaration |
15421 N_Entry_Declaration |
15422 N_Formal_Object_Declaration |
15423 N_Formal_Type_Declaration |
15424 N_Full_Type_Declaration |
15425 N_Incomplete_Type_Declaration |
15426 N_Loop_Parameter_Specification |
15427 N_Object_Declaration |
15428 N_Protected_Type_Declaration |
15429 N_Private_Extension_Declaration |
15430 N_Private_Type_Declaration |
15431 N_Subtype_Declaration |
15432 N_Function_Specification |
15433 N_Procedure_Specification |
15434 N_Task_Type_Declaration |
15436 N_Generic_Instantiation |
15438 N_Implicit_Label_Declaration |
15439 N_Package_Declaration |
15440 N_Single_Task_Declaration |
15441 N_Subprogram_Declaration |
15442 N_Generic_Declaration |
15443 N_Renaming_Declaration |
15444 N_Block_Statement |
15445 N_Formal_Subprogram_Declaration |
15446 N_Abstract_Subprogram_Declaration |
15448 N_Exception_Declaration |
15449 N_Formal_Package_Declaration |
15450 N_Number_Declaration |
15451 N_Package_Specification |
15452 N_Parameter_Specification |
15453 N_Single_Protected_Declaration |
15457 (Nearest_Dynamic_Scope
15458 (Defining_Entity
(Node_Par
)));
15464 Node_Par
:= Parent
(Node_Par
);
15467 pragma Assert
(False);
15469 -- Should never reach the following return
15471 return Scope_Depth
(Current_Scope
) + 1;
15472 end Innermost_Master_Scope_Depth
;
15474 -- Start of processing for Return_Master_Scope_Depth_Of_Call
15477 return Innermost_Master_Scope_Depth
(Obj
);
15478 end Return_Master_Scope_Depth_Of_Call
;
15481 -- For convenience we handle qualified expressions, even though they
15482 -- aren't technically object names.
15484 elsif Nkind
(Obj
) = N_Qualified_Expression
then
15485 return Object_Access_Level
(Expression
(Obj
));
15487 -- Ditto for aggregates. They have the level of the temporary that
15488 -- will hold their value.
15490 elsif Nkind
(Obj
) = N_Aggregate
then
15491 return Object_Access_Level
(Current_Scope
);
15493 -- Otherwise return the scope level of Standard. (If there are cases
15494 -- that fall through to this point they will be treated as having
15495 -- global accessibility for now. ???)
15498 return Scope_Depth
(Standard_Standard
);
15500 end Object_Access_Level
;
15502 ---------------------------------
15503 -- Original_Aspect_Pragma_Name --
15504 ---------------------------------
15506 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
15508 Item_Nam
: Name_Id
;
15511 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
15515 -- The pragma was generated to emulate an aspect, use the original
15516 -- aspect specification.
15518 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
15519 Item
:= Corresponding_Aspect
(Item
);
15522 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
15523 -- Post and Post_Class rewrite their pragma identifier to preserve the
15525 -- ??? this is kludgey
15527 if Nkind
(Item
) = N_Pragma
then
15528 Item_Nam
:= Chars
(Original_Node
(Pragma_Identifier
(Item
)));
15531 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
15532 Item_Nam
:= Chars
(Identifier
(Item
));
15535 -- Deal with 'Class by converting the name to its _XXX form
15537 if Class_Present
(Item
) then
15538 if Item_Nam
= Name_Invariant
then
15539 Item_Nam
:= Name_uInvariant
;
15541 elsif Item_Nam
= Name_Post
then
15542 Item_Nam
:= Name_uPost
;
15544 elsif Item_Nam
= Name_Pre
then
15545 Item_Nam
:= Name_uPre
;
15547 elsif Nam_In
(Item_Nam
, Name_Type_Invariant
,
15548 Name_Type_Invariant_Class
)
15550 Item_Nam
:= Name_uType_Invariant
;
15552 -- Nothing to do for other cases (e.g. a Check that derived from
15553 -- Pre_Class and has the flag set). Also we do nothing if the name
15554 -- is already in special _xxx form.
15560 end Original_Aspect_Pragma_Name
;
15562 --------------------------------------
15563 -- Original_Corresponding_Operation --
15564 --------------------------------------
15566 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
15568 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
15571 -- If S is an inherited primitive S2 the original corresponding
15572 -- operation of S is the original corresponding operation of S2
15574 if Present
(Alias
(S
))
15575 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
15577 return Original_Corresponding_Operation
(Alias
(S
));
15579 -- If S overrides an inherited subprogram S2 the original corresponding
15580 -- operation of S is the original corresponding operation of S2
15582 elsif Present
(Overridden_Operation
(S
)) then
15583 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
15585 -- otherwise it is S itself
15590 end Original_Corresponding_Operation
;
15592 ----------------------
15593 -- Policy_In_Effect --
15594 ----------------------
15596 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
15597 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
15598 -- Determine the the mode of a policy in a N_Pragma list
15600 --------------------
15601 -- Policy_In_List --
15602 --------------------
15604 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
15611 while Present
(Prag
) loop
15612 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
15613 Expr
:= Get_Pragma_Arg
(Arg
);
15615 -- The current Check_Policy pragma matches the requested policy,
15616 -- return the second argument which denotes the policy identifier.
15618 if Chars
(Expr
) = Policy
then
15619 return Chars
(Get_Pragma_Arg
(Next
(Arg
)));
15622 Prag
:= Next_Pragma
(Prag
);
15626 end Policy_In_List
;
15632 -- Start of processing for Policy_In_Effect
15635 if not Is_Valid_Assertion_Kind
(Policy
) then
15636 raise Program_Error
;
15639 -- Inspect all policy pragmas that appear within scopes (if any)
15641 Kind
:= Policy_In_List
(Check_Policy_List
);
15643 -- Inspect all configuration policy pragmas (if any)
15645 if Kind
= No_Name
then
15646 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
15649 -- The context lacks policy pragmas, determine the mode based on whether
15650 -- assertions are enabled at the configuration level. This ensures that
15651 -- the policy is preserved when analyzing generics.
15653 if Kind
= No_Name
then
15654 if Assertions_Enabled_Config
then
15655 Kind
:= Name_Check
;
15657 Kind
:= Name_Ignore
;
15662 end Policy_In_Effect
;
15664 ----------------------------------
15665 -- Predicate_Tests_On_Arguments --
15666 ----------------------------------
15668 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
15670 -- Always test predicates on indirect call
15672 if Ekind
(Subp
) = E_Subprogram_Type
then
15675 -- Do not test predicates on call to generated default Finalize, since
15676 -- we are not interested in whether something we are finalizing (and
15677 -- typically destroying) satisfies its predicates.
15679 elsif Chars
(Subp
) = Name_Finalize
15680 and then not Comes_From_Source
(Subp
)
15684 -- Do not test predicates on any internally generated routines
15686 elsif Is_Internal_Name
(Chars
(Subp
)) then
15689 -- Do not test predicates on call to Init_Proc, since if needed the
15690 -- predicate test will occur at some other point.
15692 elsif Is_Init_Proc
(Subp
) then
15695 -- Do not test predicates on call to predicate function, since this
15696 -- would cause infinite recursion.
15698 elsif Ekind
(Subp
) = E_Function
15699 and then (Is_Predicate_Function
(Subp
)
15701 Is_Predicate_Function_M
(Subp
))
15705 -- For now, no other exceptions
15710 end Predicate_Tests_On_Arguments
;
15712 -----------------------
15713 -- Private_Component --
15714 -----------------------
15716 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
15717 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
15719 function Trace_Components
15721 Check
: Boolean) return Entity_Id
;
15722 -- Recursive function that does the work, and checks against circular
15723 -- definition for each subcomponent type.
15725 ----------------------
15726 -- Trace_Components --
15727 ----------------------
15729 function Trace_Components
15731 Check
: Boolean) return Entity_Id
15733 Btype
: constant Entity_Id
:= Base_Type
(T
);
15734 Component
: Entity_Id
;
15736 Candidate
: Entity_Id
:= Empty
;
15739 if Check
and then Btype
= Ancestor
then
15740 Error_Msg_N
("circular type definition", Type_Id
);
15744 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
15745 if Present
(Full_View
(Btype
))
15746 and then Is_Record_Type
(Full_View
(Btype
))
15747 and then not Is_Frozen
(Btype
)
15749 -- To indicate that the ancestor depends on a private type, the
15750 -- current Btype is sufficient. However, to check for circular
15751 -- definition we must recurse on the full view.
15753 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
15755 if Candidate
= Any_Type
then
15765 elsif Is_Array_Type
(Btype
) then
15766 return Trace_Components
(Component_Type
(Btype
), True);
15768 elsif Is_Record_Type
(Btype
) then
15769 Component
:= First_Entity
(Btype
);
15770 while Present
(Component
)
15771 and then Comes_From_Source
(Component
)
15773 -- Skip anonymous types generated by constrained components
15775 if not Is_Type
(Component
) then
15776 P
:= Trace_Components
(Etype
(Component
), True);
15778 if Present
(P
) then
15779 if P
= Any_Type
then
15787 Next_Entity
(Component
);
15795 end Trace_Components
;
15797 -- Start of processing for Private_Component
15800 return Trace_Components
(Type_Id
, False);
15801 end Private_Component
;
15803 ---------------------------
15804 -- Primitive_Names_Match --
15805 ---------------------------
15807 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
15809 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
15810 -- Given an internal name, returns the corresponding non-internal name
15812 ------------------------
15813 -- Non_Internal_Name --
15814 ------------------------
15816 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
15818 Get_Name_String
(Chars
(E
));
15819 Name_Len
:= Name_Len
- 1;
15821 end Non_Internal_Name
;
15823 -- Start of processing for Primitive_Names_Match
15826 pragma Assert
(Present
(E1
) and then Present
(E2
));
15828 return Chars
(E1
) = Chars
(E2
)
15830 (not Is_Internal_Name
(Chars
(E1
))
15831 and then Is_Internal_Name
(Chars
(E2
))
15832 and then Non_Internal_Name
(E2
) = Chars
(E1
))
15834 (not Is_Internal_Name
(Chars
(E2
))
15835 and then Is_Internal_Name
(Chars
(E1
))
15836 and then Non_Internal_Name
(E1
) = Chars
(E2
))
15838 (Is_Predefined_Dispatching_Operation
(E1
)
15839 and then Is_Predefined_Dispatching_Operation
(E2
)
15840 and then Same_TSS
(E1
, E2
))
15842 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
15843 end Primitive_Names_Match
;
15845 -----------------------
15846 -- Process_End_Label --
15847 -----------------------
15849 procedure Process_End_Label
15858 Label_Ref
: Boolean;
15859 -- Set True if reference to end label itself is required
15862 -- Gets set to the operator symbol or identifier that references the
15863 -- entity Ent. For the child unit case, this is the identifier from the
15864 -- designator. For other cases, this is simply Endl.
15866 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
15867 -- N is an identifier node that appears as a parent unit reference in
15868 -- the case where Ent is a child unit. This procedure generates an
15869 -- appropriate cross-reference entry. E is the corresponding entity.
15871 -------------------------
15872 -- Generate_Parent_Ref --
15873 -------------------------
15875 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
15877 -- If names do not match, something weird, skip reference
15879 if Chars
(E
) = Chars
(N
) then
15881 -- Generate the reference. We do NOT consider this as a reference
15882 -- for unreferenced symbol purposes.
15884 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
15886 if Style_Check
then
15887 Style
.Check_Identifier
(N
, E
);
15890 end Generate_Parent_Ref
;
15892 -- Start of processing for Process_End_Label
15895 -- If no node, ignore. This happens in some error situations, and
15896 -- also for some internally generated structures where no end label
15897 -- references are required in any case.
15903 -- Nothing to do if no End_Label, happens for internally generated
15904 -- constructs where we don't want an end label reference anyway. Also
15905 -- nothing to do if Endl is a string literal, which means there was
15906 -- some prior error (bad operator symbol)
15908 Endl
:= End_Label
(N
);
15910 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
15914 -- Reference node is not in extended main source unit
15916 if not In_Extended_Main_Source_Unit
(N
) then
15918 -- Generally we do not collect references except for the extended
15919 -- main source unit. The one exception is the 'e' entry for a
15920 -- package spec, where it is useful for a client to have the
15921 -- ending information to define scopes.
15927 Label_Ref
:= False;
15929 -- For this case, we can ignore any parent references, but we
15930 -- need the package name itself for the 'e' entry.
15932 if Nkind
(Endl
) = N_Designator
then
15933 Endl
:= Identifier
(Endl
);
15937 -- Reference is in extended main source unit
15942 -- For designator, generate references for the parent entries
15944 if Nkind
(Endl
) = N_Designator
then
15946 -- Generate references for the prefix if the END line comes from
15947 -- source (otherwise we do not need these references) We climb the
15948 -- scope stack to find the expected entities.
15950 if Comes_From_Source
(Endl
) then
15951 Nam
:= Name
(Endl
);
15952 Scop
:= Current_Scope
;
15953 while Nkind
(Nam
) = N_Selected_Component
loop
15954 Scop
:= Scope
(Scop
);
15955 exit when No
(Scop
);
15956 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
15957 Nam
:= Prefix
(Nam
);
15960 if Present
(Scop
) then
15961 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
15965 Endl
:= Identifier
(Endl
);
15969 -- If the end label is not for the given entity, then either we have
15970 -- some previous error, or this is a generic instantiation for which
15971 -- we do not need to make a cross-reference in this case anyway. In
15972 -- either case we simply ignore the call.
15974 if Chars
(Ent
) /= Chars
(Endl
) then
15978 -- If label was really there, then generate a normal reference and then
15979 -- adjust the location in the end label to point past the name (which
15980 -- should almost always be the semicolon).
15982 Loc
:= Sloc
(Endl
);
15984 if Comes_From_Source
(Endl
) then
15986 -- If a label reference is required, then do the style check and
15987 -- generate an l-type cross-reference entry for the label
15990 if Style_Check
then
15991 Style
.Check_Identifier
(Endl
, Ent
);
15994 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
15997 -- Set the location to point past the label (normally this will
15998 -- mean the semicolon immediately following the label). This is
15999 -- done for the sake of the 'e' or 't' entry generated below.
16001 Get_Decoded_Name_String
(Chars
(Endl
));
16002 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
16005 -- In SPARK mode, no missing label is allowed for packages and
16006 -- subprogram bodies. Detect those cases by testing whether
16007 -- Process_End_Label was called for a body (Typ = 't') or a package.
16009 if Restriction_Check_Required
(SPARK_05
)
16010 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
16012 Error_Msg_Node_1
:= Endl
;
16013 Check_SPARK_05_Restriction
16014 ("`END &` required", Endl
, Force
=> True);
16018 -- Now generate the e/t reference
16020 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
16022 -- Restore Sloc, in case modified above, since we have an identifier
16023 -- and the normal Sloc should be left set in the tree.
16025 Set_Sloc
(Endl
, Loc
);
16026 end Process_End_Label
;
16032 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
16033 Seen
: Boolean := False;
16035 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
16036 -- Determine whether node N denotes a reference to Id. If this is the
16037 -- case, set global flag Seen to True and stop the traversal.
16043 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
16045 if Is_Entity_Name
(N
)
16046 and then Present
(Entity
(N
))
16047 and then Entity
(N
) = Id
16056 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
16058 -- Start of processing for Referenced
16061 Inspect_Expression
(Expr
);
16065 ------------------------------------
16066 -- References_Generic_Formal_Type --
16067 ------------------------------------
16069 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
16071 function Process
(N
: Node_Id
) return Traverse_Result
;
16072 -- Process one node in search for generic formal type
16078 function Process
(N
: Node_Id
) return Traverse_Result
is
16080 if Nkind
(N
) in N_Has_Entity
then
16082 E
: constant Entity_Id
:= Entity
(N
);
16084 if Present
(E
) then
16085 if Is_Generic_Type
(E
) then
16087 elsif Present
(Etype
(E
))
16088 and then Is_Generic_Type
(Etype
(E
))
16099 function Traverse
is new Traverse_Func
(Process
);
16100 -- Traverse tree to look for generic type
16103 if Inside_A_Generic
then
16104 return Traverse
(N
) = Abandon
;
16108 end References_Generic_Formal_Type
;
16110 --------------------
16111 -- Remove_Homonym --
16112 --------------------
16114 procedure Remove_Homonym
(E
: Entity_Id
) is
16115 Prev
: Entity_Id
:= Empty
;
16119 if E
= Current_Entity
(E
) then
16120 if Present
(Homonym
(E
)) then
16121 Set_Current_Entity
(Homonym
(E
));
16123 Set_Name_Entity_Id
(Chars
(E
), Empty
);
16127 H
:= Current_Entity
(E
);
16128 while Present
(H
) and then H
/= E
loop
16133 -- If E is not on the homonym chain, nothing to do
16135 if Present
(H
) then
16136 Set_Homonym
(Prev
, Homonym
(E
));
16139 end Remove_Homonym
;
16141 ---------------------
16142 -- Rep_To_Pos_Flag --
16143 ---------------------
16145 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
16147 return New_Occurrence_Of
16148 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
16149 end Rep_To_Pos_Flag
;
16151 --------------------
16152 -- Require_Entity --
16153 --------------------
16155 procedure Require_Entity
(N
: Node_Id
) is
16157 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
16158 if Total_Errors_Detected
/= 0 then
16159 Set_Entity
(N
, Any_Id
);
16161 raise Program_Error
;
16164 end Require_Entity
;
16166 -------------------------------
16167 -- Requires_State_Refinement --
16168 -------------------------------
16170 function Requires_State_Refinement
16171 (Spec_Id
: Entity_Id
;
16172 Body_Id
: Entity_Id
) return Boolean
16174 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
16175 -- Given pragma SPARK_Mode, determine whether the mode is Off
16181 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
16185 -- The default SPARK mode is On
16191 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
16193 -- Then the pragma lacks an argument, the default mode is On
16198 return Chars
(Mode
) = Name_Off
;
16202 -- Start of processing for Requires_State_Refinement
16205 -- A package that does not define at least one abstract state cannot
16206 -- possibly require refinement.
16208 if No
(Abstract_States
(Spec_Id
)) then
16211 -- The package instroduces a single null state which does not merit
16214 elsif Has_Null_Abstract_State
(Spec_Id
) then
16217 -- Check whether the package body is subject to pragma SPARK_Mode. If
16218 -- it is and the mode is Off, the package body is considered to be in
16219 -- regular Ada and does not require refinement.
16221 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
16224 -- The body's SPARK_Mode may be inherited from a similar pragma that
16225 -- appears in the private declarations of the spec. The pragma we are
16226 -- interested appears as the second entry in SPARK_Pragma.
16228 elsif Present
(SPARK_Pragma
(Spec_Id
))
16229 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
16233 -- The spec defines at least one abstract state and the body has no way
16234 -- of circumventing the refinement.
16239 end Requires_State_Refinement
;
16241 ------------------------------
16242 -- Requires_Transient_Scope --
16243 ------------------------------
16245 -- A transient scope is required when variable-sized temporaries are
16246 -- allocated in the primary or secondary stack, or when finalization
16247 -- actions must be generated before the next instruction.
16249 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
16250 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
16252 -- Start of processing for Requires_Transient_Scope
16255 -- This is a private type which is not completed yet. This can only
16256 -- happen in a default expression (of a formal parameter or of a
16257 -- record component). Do not expand transient scope in this case
16262 -- Do not expand transient scope for non-existent procedure return
16264 elsif Typ
= Standard_Void_Type
then
16267 -- Elementary types do not require a transient scope
16269 elsif Is_Elementary_Type
(Typ
) then
16272 -- Generally, indefinite subtypes require a transient scope, since the
16273 -- back end cannot generate temporaries, since this is not a valid type
16274 -- for declaring an object. It might be possible to relax this in the
16275 -- future, e.g. by declaring the maximum possible space for the type.
16277 elsif Is_Indefinite_Subtype
(Typ
) then
16280 -- Functions returning tagged types may dispatch on result so their
16281 -- returned value is allocated on the secondary stack. Controlled
16282 -- type temporaries need finalization.
16284 elsif Is_Tagged_Type
(Typ
)
16285 or else Has_Controlled_Component
(Typ
)
16287 return not Is_Value_Type
(Typ
);
16291 elsif Is_Record_Type
(Typ
) then
16295 Comp
:= First_Entity
(Typ
);
16296 while Present
(Comp
) loop
16297 if Ekind
(Comp
) = E_Component
16298 and then Requires_Transient_Scope
(Etype
(Comp
))
16302 Next_Entity
(Comp
);
16309 -- String literal types never require transient scope
16311 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
16314 -- Array type. Note that we already know that this is a constrained
16315 -- array, since unconstrained arrays will fail the indefinite test.
16317 elsif Is_Array_Type
(Typ
) then
16319 -- If component type requires a transient scope, the array does too
16321 if Requires_Transient_Scope
(Component_Type
(Typ
)) then
16324 -- Otherwise, we only need a transient scope if the size depends on
16325 -- the value of one or more discriminants.
16328 return Size_Depends_On_Discriminant
(Typ
);
16331 -- All other cases do not require a transient scope
16336 end Requires_Transient_Scope
;
16338 --------------------------
16339 -- Reset_Analyzed_Flags --
16340 --------------------------
16342 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
16344 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
16345 -- Function used to reset Analyzed flags in tree. Note that we do
16346 -- not reset Analyzed flags in entities, since there is no need to
16347 -- reanalyze entities, and indeed, it is wrong to do so, since it
16348 -- can result in generating auxiliary stuff more than once.
16350 --------------------
16351 -- Clear_Analyzed --
16352 --------------------
16354 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
16356 if not Has_Extension
(N
) then
16357 Set_Analyzed
(N
, False);
16361 end Clear_Analyzed
;
16363 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
16365 -- Start of processing for Reset_Analyzed_Flags
16368 Reset_Analyzed
(N
);
16369 end Reset_Analyzed_Flags
;
16371 ------------------------
16372 -- Restore_SPARK_Mode --
16373 ------------------------
16375 procedure Restore_SPARK_Mode
(Mode
: SPARK_Mode_Type
) is
16377 SPARK_Mode
:= Mode
;
16378 end Restore_SPARK_Mode
;
16380 --------------------------------
16381 -- Returns_Unconstrained_Type --
16382 --------------------------------
16384 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
16386 return Ekind
(Subp
) = E_Function
16387 and then not Is_Scalar_Type
(Etype
(Subp
))
16388 and then not Is_Access_Type
(Etype
(Subp
))
16389 and then not Is_Constrained
(Etype
(Subp
));
16390 end Returns_Unconstrained_Type
;
16392 ----------------------------
16393 -- Root_Type_Of_Full_View --
16394 ----------------------------
16396 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
16397 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
16400 -- The root type of the full view may itself be a private type. Keep
16401 -- looking for the ultimate derivation parent.
16403 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
16404 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
16408 end Root_Type_Of_Full_View
;
16410 ---------------------------
16411 -- Safe_To_Capture_Value --
16412 ---------------------------
16414 function Safe_To_Capture_Value
16417 Cond
: Boolean := False) return Boolean
16420 -- The only entities for which we track constant values are variables
16421 -- which are not renamings, constants, out parameters, and in out
16422 -- parameters, so check if we have this case.
16424 -- Note: it may seem odd to track constant values for constants, but in
16425 -- fact this routine is used for other purposes than simply capturing
16426 -- the value. In particular, the setting of Known[_Non]_Null.
16428 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
16430 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
16434 -- For conditionals, we also allow loop parameters and all formals,
16435 -- including in parameters.
16437 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
16440 -- For all other cases, not just unsafe, but impossible to capture
16441 -- Current_Value, since the above are the only entities which have
16442 -- Current_Value fields.
16448 -- Skip if volatile or aliased, since funny things might be going on in
16449 -- these cases which we cannot necessarily track. Also skip any variable
16450 -- for which an address clause is given, or whose address is taken. Also
16451 -- never capture value of library level variables (an attempt to do so
16452 -- can occur in the case of package elaboration code).
16454 if Treat_As_Volatile
(Ent
)
16455 or else Is_Aliased
(Ent
)
16456 or else Present
(Address_Clause
(Ent
))
16457 or else Address_Taken
(Ent
)
16458 or else (Is_Library_Level_Entity
(Ent
)
16459 and then Ekind
(Ent
) = E_Variable
)
16464 -- OK, all above conditions are met. We also require that the scope of
16465 -- the reference be the same as the scope of the entity, not counting
16466 -- packages and blocks and loops.
16469 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
16470 R_Scope
: Entity_Id
;
16473 R_Scope
:= Current_Scope
;
16474 while R_Scope
/= Standard_Standard
loop
16475 exit when R_Scope
= E_Scope
;
16477 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
16480 R_Scope
:= Scope
(R_Scope
);
16485 -- We also require that the reference does not appear in a context
16486 -- where it is not sure to be executed (i.e. a conditional context
16487 -- or an exception handler). We skip this if Cond is True, since the
16488 -- capturing of values from conditional tests handles this ok.
16501 -- Seems dubious that case expressions are not handled here ???
16504 while Present
(P
) loop
16505 if Nkind
(P
) = N_If_Statement
16506 or else Nkind
(P
) = N_Case_Statement
16507 or else (Nkind
(P
) in N_Short_Circuit
16508 and then Desc
= Right_Opnd
(P
))
16509 or else (Nkind
(P
) = N_If_Expression
16510 and then Desc
/= First
(Expressions
(P
)))
16511 or else Nkind
(P
) = N_Exception_Handler
16512 or else Nkind
(P
) = N_Selective_Accept
16513 or else Nkind
(P
) = N_Conditional_Entry_Call
16514 or else Nkind
(P
) = N_Timed_Entry_Call
16515 or else Nkind
(P
) = N_Asynchronous_Select
16523 -- A special Ada 2012 case: the original node may be part
16524 -- of the else_actions of a conditional expression, in which
16525 -- case it might not have been expanded yet, and appears in
16526 -- a non-syntactic list of actions. In that case it is clearly
16527 -- not safe to save a value.
16530 and then Is_List_Member
(Desc
)
16531 and then No
(Parent
(List_Containing
(Desc
)))
16539 -- OK, looks safe to set value
16542 end Safe_To_Capture_Value
;
16548 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
16549 K1
: constant Node_Kind
:= Nkind
(N1
);
16550 K2
: constant Node_Kind
:= Nkind
(N2
);
16553 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
16554 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
16556 return Chars
(N1
) = Chars
(N2
);
16558 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
16559 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
16561 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
16562 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
16573 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
16574 N1
: constant Node_Id
:= Original_Node
(Node1
);
16575 N2
: constant Node_Id
:= Original_Node
(Node2
);
16576 -- We do the tests on original nodes, since we are most interested
16577 -- in the original source, not any expansion that got in the way.
16579 K1
: constant Node_Kind
:= Nkind
(N1
);
16580 K2
: constant Node_Kind
:= Nkind
(N2
);
16583 -- First case, both are entities with same entity
16585 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
16587 EN1
: constant Entity_Id
:= Entity
(N1
);
16588 EN2
: constant Entity_Id
:= Entity
(N2
);
16590 if Present
(EN1
) and then Present
(EN2
)
16591 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
16592 or else Is_Formal
(EN1
))
16600 -- Second case, selected component with same selector, same record
16602 if K1
= N_Selected_Component
16603 and then K2
= N_Selected_Component
16604 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
16606 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
16608 -- Third case, indexed component with same subscripts, same array
16610 elsif K1
= N_Indexed_Component
16611 and then K2
= N_Indexed_Component
16612 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
16617 E1
:= First
(Expressions
(N1
));
16618 E2
:= First
(Expressions
(N2
));
16619 while Present
(E1
) loop
16620 if not Same_Value
(E1
, E2
) then
16631 -- Fourth case, slice of same array with same bounds
16634 and then K2
= N_Slice
16635 and then Nkind
(Discrete_Range
(N1
)) = N_Range
16636 and then Nkind
(Discrete_Range
(N2
)) = N_Range
16637 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
16638 Low_Bound
(Discrete_Range
(N2
)))
16639 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
16640 High_Bound
(Discrete_Range
(N2
)))
16642 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
16644 -- All other cases, not clearly the same object
16655 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
16660 elsif not Is_Constrained
(T1
)
16661 and then not Is_Constrained
(T2
)
16662 and then Base_Type
(T1
) = Base_Type
(T2
)
16666 -- For now don't bother with case of identical constraints, to be
16667 -- fiddled with later on perhaps (this is only used for optimization
16668 -- purposes, so it is not critical to do a best possible job)
16679 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
16681 if Compile_Time_Known_Value
(Node1
)
16682 and then Compile_Time_Known_Value
(Node2
)
16683 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
16686 elsif Same_Object
(Node1
, Node2
) then
16693 -----------------------------
16694 -- Save_SPARK_Mode_And_Set --
16695 -----------------------------
16697 procedure Save_SPARK_Mode_And_Set
16698 (Context
: Entity_Id
;
16699 Mode
: out SPARK_Mode_Type
)
16702 -- Save the current mode in effect
16704 Mode
:= SPARK_Mode
;
16706 -- Do not consider illegal or partially decorated constructs
16708 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
16711 elsif Present
(SPARK_Pragma
(Context
)) then
16712 SPARK_Mode
:= Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Context
));
16714 end Save_SPARK_Mode_And_Set
;
16716 -------------------------
16717 -- Scalar_Part_Present --
16718 -------------------------
16720 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
16724 if Is_Scalar_Type
(T
) then
16727 elsif Is_Array_Type
(T
) then
16728 return Scalar_Part_Present
(Component_Type
(T
));
16730 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
16731 C
:= First_Component_Or_Discriminant
(T
);
16732 while Present
(C
) loop
16733 if Scalar_Part_Present
(Etype
(C
)) then
16736 Next_Component_Or_Discriminant
(C
);
16742 end Scalar_Part_Present
;
16744 ------------------------
16745 -- Scope_Is_Transient --
16746 ------------------------
16748 function Scope_Is_Transient
return Boolean is
16750 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
16751 end Scope_Is_Transient
;
16757 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16762 while Scop
/= Standard_Standard
loop
16763 Scop
:= Scope
(Scop
);
16765 if Scop
= Scope2
then
16773 --------------------------
16774 -- Scope_Within_Or_Same --
16775 --------------------------
16777 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
16782 while Scop
/= Standard_Standard
loop
16783 if Scop
= Scope2
then
16786 Scop
:= Scope
(Scop
);
16791 end Scope_Within_Or_Same
;
16793 --------------------
16794 -- Set_Convention --
16795 --------------------
16797 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
16799 Basic_Set_Convention
(E
, Val
);
16802 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
16803 and then Has_Foreign_Convention
(E
)
16805 Set_Can_Use_Internal_Rep
(E
, False);
16808 -- If E is an object or component, and the type of E is an anonymous
16809 -- access type with no convention set, then also set the convention of
16810 -- the anonymous access type. We do not do this for anonymous protected
16811 -- types, since protected types always have the default convention.
16813 if Present
(Etype
(E
))
16814 and then (Is_Object
(E
)
16815 or else Ekind
(E
) = E_Component
16817 -- Allow E_Void (happens for pragma Convention appearing
16818 -- in the middle of a record applying to a component)
16820 or else Ekind
(E
) = E_Void
)
16823 Typ
: constant Entity_Id
:= Etype
(E
);
16826 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
16827 E_Anonymous_Access_Subprogram_Type
)
16828 and then not Has_Convention_Pragma
(Typ
)
16830 Basic_Set_Convention
(Typ
, Val
);
16831 Set_Has_Convention_Pragma
(Typ
);
16833 -- And for the access subprogram type, deal similarly with the
16834 -- designated E_Subprogram_Type if it is also internal (which
16837 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
16839 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
16841 if Ekind
(Dtype
) = E_Subprogram_Type
16842 and then Is_Itype
(Dtype
)
16843 and then not Has_Convention_Pragma
(Dtype
)
16845 Basic_Set_Convention
(Dtype
, Val
);
16846 Set_Has_Convention_Pragma
(Dtype
);
16853 end Set_Convention
;
16855 ------------------------
16856 -- Set_Current_Entity --
16857 ------------------------
16859 -- The given entity is to be set as the currently visible definition of its
16860 -- associated name (i.e. the Node_Id associated with its name). All we have
16861 -- to do is to get the name from the identifier, and then set the
16862 -- associated Node_Id to point to the given entity.
16864 procedure Set_Current_Entity
(E
: Entity_Id
) is
16866 Set_Name_Entity_Id
(Chars
(E
), E
);
16867 end Set_Current_Entity
;
16869 ---------------------------
16870 -- Set_Debug_Info_Needed --
16871 ---------------------------
16873 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
16875 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
16876 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
16877 -- Used to set debug info in a related node if not set already
16879 --------------------------------------
16880 -- Set_Debug_Info_Needed_If_Not_Set --
16881 --------------------------------------
16883 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
16885 if Present
(E
) and then not Needs_Debug_Info
(E
) then
16886 Set_Debug_Info_Needed
(E
);
16888 -- For a private type, indicate that the full view also needs
16889 -- debug information.
16892 and then Is_Private_Type
(E
)
16893 and then Present
(Full_View
(E
))
16895 Set_Debug_Info_Needed
(Full_View
(E
));
16898 end Set_Debug_Info_Needed_If_Not_Set
;
16900 -- Start of processing for Set_Debug_Info_Needed
16903 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
16904 -- indicates that Debug_Info_Needed is never required for the entity.
16905 -- Nothing to do if entity comes from a predefined file. Library files
16906 -- are compiled without debug information, but inlined bodies of these
16907 -- routines may appear in user code, and debug information on them ends
16908 -- up complicating debugging the user code.
16911 or else Debug_Info_Off
(T
)
16915 elsif In_Inlined_Body
16916 and then Is_Predefined_File_Name
16917 (Unit_File_Name
(Get_Source_Unit
(Sloc
(T
))))
16919 Set_Needs_Debug_Info
(T
, False);
16922 -- Set flag in entity itself. Note that we will go through the following
16923 -- circuitry even if the flag is already set on T. That's intentional,
16924 -- it makes sure that the flag will be set in subsidiary entities.
16926 Set_Needs_Debug_Info
(T
);
16928 -- Set flag on subsidiary entities if not set already
16930 if Is_Object
(T
) then
16931 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16933 elsif Is_Type
(T
) then
16934 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
16936 if Is_Record_Type
(T
) then
16938 Ent
: Entity_Id
:= First_Entity
(T
);
16940 while Present
(Ent
) loop
16941 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
16946 -- For a class wide subtype, we also need debug information
16947 -- for the equivalent type.
16949 if Ekind
(T
) = E_Class_Wide_Subtype
then
16950 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
16953 elsif Is_Array_Type
(T
) then
16954 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
16957 Indx
: Node_Id
:= First_Index
(T
);
16959 while Present
(Indx
) loop
16960 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
16961 Indx
:= Next_Index
(Indx
);
16965 -- For a packed array type, we also need debug information for
16966 -- the type used to represent the packed array. Conversely, we
16967 -- also need it for the former if we need it for the latter.
16969 if Is_Packed
(T
) then
16970 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
16973 if Is_Packed_Array_Impl_Type
(T
) then
16974 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
16977 elsif Is_Access_Type
(T
) then
16978 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
16980 elsif Is_Private_Type
(T
) then
16981 Set_Debug_Info_Needed_If_Not_Set
(Full_View
(T
));
16983 elsif Is_Protected_Type
(T
) then
16984 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
16986 elsif Is_Scalar_Type
(T
) then
16988 -- If the subrange bounds are materialized by dedicated constant
16989 -- objects, also include them in the debug info to make sure the
16990 -- debugger can properly use them.
16992 if Present
(Scalar_Range
(T
))
16993 and then Nkind
(Scalar_Range
(T
)) = N_Range
16996 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
16997 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
17000 if Is_Entity_Name
(Low_Bnd
) then
17001 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
17004 if Is_Entity_Name
(High_Bnd
) then
17005 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
17011 end Set_Debug_Info_Needed
;
17013 ----------------------------
17014 -- Set_Entity_With_Checks --
17015 ----------------------------
17017 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
17018 Val_Actual
: Entity_Id
;
17020 Post_Node
: Node_Id
;
17023 -- Unconditionally set the entity
17025 Set_Entity
(N
, Val
);
17027 -- The node to post on is the selector in the case of an expanded name,
17028 -- and otherwise the node itself.
17030 if Nkind
(N
) = N_Expanded_Name
then
17031 Post_Node
:= Selector_Name
(N
);
17036 -- Check for violation of No_Fixed_IO
17038 if Restriction_Check_Required
(No_Fixed_IO
)
17040 ((RTU_Loaded
(Ada_Text_IO
)
17041 and then (Is_RTE
(Val
, RE_Decimal_IO
)
17043 Is_RTE
(Val
, RE_Fixed_IO
)))
17046 (RTU_Loaded
(Ada_Wide_Text_IO
)
17047 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
17049 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
17052 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
17053 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
17055 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
17057 -- A special extra check, don't complain about a reference from within
17058 -- the Ada.Interrupts package itself!
17060 and then not In_Same_Extended_Unit
(N
, Val
)
17062 Check_Restriction
(No_Fixed_IO
, Post_Node
);
17065 -- Remaining checks are only done on source nodes. Note that we test
17066 -- for violation of No_Fixed_IO even on non-source nodes, because the
17067 -- cases for checking violations of this restriction are instantiations
17068 -- where the reference in the instance has Comes_From_Source False.
17070 if not Comes_From_Source
(N
) then
17074 -- Check for violation of No_Abort_Statements, which is triggered by
17075 -- call to Ada.Task_Identification.Abort_Task.
17077 if Restriction_Check_Required
(No_Abort_Statements
)
17078 and then (Is_RTE
(Val
, RE_Abort_Task
))
17080 -- A special extra check, don't complain about a reference from within
17081 -- the Ada.Task_Identification package itself!
17083 and then not In_Same_Extended_Unit
(N
, Val
)
17085 Check_Restriction
(No_Abort_Statements
, Post_Node
);
17088 if Val
= Standard_Long_Long_Integer
then
17089 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
17092 -- Check for violation of No_Dynamic_Attachment
17094 if Restriction_Check_Required
(No_Dynamic_Attachment
)
17095 and then RTU_Loaded
(Ada_Interrupts
)
17096 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
17097 Is_RTE
(Val
, RE_Is_Attached
) or else
17098 Is_RTE
(Val
, RE_Current_Handler
) or else
17099 Is_RTE
(Val
, RE_Attach_Handler
) or else
17100 Is_RTE
(Val
, RE_Exchange_Handler
) or else
17101 Is_RTE
(Val
, RE_Detach_Handler
) or else
17102 Is_RTE
(Val
, RE_Reference
))
17104 -- A special extra check, don't complain about a reference from within
17105 -- the Ada.Interrupts package itself!
17107 and then not In_Same_Extended_Unit
(N
, Val
)
17109 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
17112 -- Check for No_Implementation_Identifiers
17114 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
17116 -- We have an implementation defined entity if it is marked as
17117 -- implementation defined, or is defined in a package marked as
17118 -- implementation defined. However, library packages themselves
17119 -- are excluded (we don't want to flag Interfaces itself, just
17120 -- the entities within it).
17122 if (Is_Implementation_Defined
(Val
)
17124 (Present
(Scope
(Val
))
17125 and then Is_Implementation_Defined
(Scope
(Val
))))
17126 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
17127 and then Is_Library_Level_Entity
(Val
))
17129 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
17133 -- Do the style check
17136 and then not Suppress_Style_Checks
(Val
)
17137 and then not In_Instance
17139 if Nkind
(N
) = N_Identifier
then
17141 elsif Nkind
(N
) = N_Expanded_Name
then
17142 Nod
:= Selector_Name
(N
);
17147 -- A special situation arises for derived operations, where we want
17148 -- to do the check against the parent (since the Sloc of the derived
17149 -- operation points to the derived type declaration itself).
17152 while not Comes_From_Source
(Val_Actual
)
17153 and then Nkind
(Val_Actual
) in N_Entity
17154 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
17155 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
17156 and then Present
(Alias
(Val_Actual
))
17158 Val_Actual
:= Alias
(Val_Actual
);
17161 -- Renaming declarations for generic actuals do not come from source,
17162 -- and have a different name from that of the entity they rename, so
17163 -- there is no style check to perform here.
17165 if Chars
(Nod
) = Chars
(Val_Actual
) then
17166 Style
.Check_Identifier
(Nod
, Val_Actual
);
17170 Set_Entity
(N
, Val
);
17171 end Set_Entity_With_Checks
;
17173 ------------------------
17174 -- Set_Name_Entity_Id --
17175 ------------------------
17177 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
17179 Set_Name_Table_Int
(Id
, Int
(Val
));
17180 end Set_Name_Entity_Id
;
17182 ---------------------
17183 -- Set_Next_Actual --
17184 ---------------------
17186 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
17188 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
17189 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
17191 end Set_Next_Actual
;
17193 ----------------------------------
17194 -- Set_Optimize_Alignment_Flags --
17195 ----------------------------------
17197 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
17199 if Optimize_Alignment
= 'S' then
17200 Set_Optimize_Alignment_Space
(E
);
17201 elsif Optimize_Alignment
= 'T' then
17202 Set_Optimize_Alignment_Time
(E
);
17204 end Set_Optimize_Alignment_Flags
;
17206 -----------------------
17207 -- Set_Public_Status --
17208 -----------------------
17210 procedure Set_Public_Status
(Id
: Entity_Id
) is
17211 S
: constant Entity_Id
:= Current_Scope
;
17213 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
17214 -- Determines if E is defined within handled statement sequence or
17215 -- an if statement, returns True if so, False otherwise.
17217 ----------------------
17218 -- Within_HSS_Or_If --
17219 ----------------------
17221 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
17224 N
:= Declaration_Node
(E
);
17231 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
17237 end Within_HSS_Or_If
;
17239 -- Start of processing for Set_Public_Status
17242 -- Everything in the scope of Standard is public
17244 if S
= Standard_Standard
then
17245 Set_Is_Public
(Id
);
17247 -- Entity is definitely not public if enclosing scope is not public
17249 elsif not Is_Public
(S
) then
17252 -- An object or function declaration that occurs in a handled sequence
17253 -- of statements or within an if statement is the declaration for a
17254 -- temporary object or local subprogram generated by the expander. It
17255 -- never needs to be made public and furthermore, making it public can
17256 -- cause back end problems.
17258 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
17259 N_Function_Specification
)
17260 and then Within_HSS_Or_If
(Id
)
17264 -- Entities in public packages or records are public
17266 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
17267 Set_Is_Public
(Id
);
17269 -- The bounds of an entry family declaration can generate object
17270 -- declarations that are visible to the back-end, e.g. in the
17271 -- the declaration of a composite type that contains tasks.
17273 elsif Is_Concurrent_Type
(S
)
17274 and then not Has_Completion
(S
)
17275 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
17277 Set_Is_Public
(Id
);
17279 end Set_Public_Status
;
17281 -----------------------------
17282 -- Set_Referenced_Modified --
17283 -----------------------------
17285 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
17289 -- Deal with indexed or selected component where prefix is modified
17291 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
17292 Pref
:= Prefix
(N
);
17294 -- If prefix is access type, then it is the designated object that is
17295 -- being modified, which means we have no entity to set the flag on.
17297 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
17300 -- Otherwise chase the prefix
17303 Set_Referenced_Modified
(Pref
, Out_Param
);
17306 -- Otherwise see if we have an entity name (only other case to process)
17308 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
17309 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
17310 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
17312 end Set_Referenced_Modified
;
17314 ----------------------------
17315 -- Set_Scope_Is_Transient --
17316 ----------------------------
17318 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
17320 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
17321 end Set_Scope_Is_Transient
;
17323 -------------------
17324 -- Set_Size_Info --
17325 -------------------
17327 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
17329 -- We copy Esize, but not RM_Size, since in general RM_Size is
17330 -- subtype specific and does not get inherited by all subtypes.
17332 Set_Esize
(T1
, Esize
(T2
));
17333 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
17335 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
17337 Is_Discrete_Or_Fixed_Point_Type
(T2
)
17339 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
17342 Set_Alignment
(T1
, Alignment
(T2
));
17345 --------------------
17346 -- Static_Boolean --
17347 --------------------
17349 function Static_Boolean
(N
: Node_Id
) return Uint
is
17351 Analyze_And_Resolve
(N
, Standard_Boolean
);
17354 or else Error_Posted
(N
)
17355 or else Etype
(N
) = Any_Type
17360 if Is_OK_Static_Expression
(N
) then
17361 if not Raises_Constraint_Error
(N
) then
17362 return Expr_Value
(N
);
17367 elsif Etype
(N
) = Any_Type
then
17371 Flag_Non_Static_Expr
17372 ("static boolean expression required here", N
);
17375 end Static_Boolean
;
17377 --------------------
17378 -- Static_Integer --
17379 --------------------
17381 function Static_Integer
(N
: Node_Id
) return Uint
is
17383 Analyze_And_Resolve
(N
, Any_Integer
);
17386 or else Error_Posted
(N
)
17387 or else Etype
(N
) = Any_Type
17392 if Is_OK_Static_Expression
(N
) then
17393 if not Raises_Constraint_Error
(N
) then
17394 return Expr_Value
(N
);
17399 elsif Etype
(N
) = Any_Type
then
17403 Flag_Non_Static_Expr
17404 ("static integer expression required here", N
);
17407 end Static_Integer
;
17409 --------------------------
17410 -- Statically_Different --
17411 --------------------------
17413 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
17414 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
17415 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
17417 return Is_Entity_Name
(R1
)
17418 and then Is_Entity_Name
(R2
)
17419 and then Entity
(R1
) /= Entity
(R2
)
17420 and then not Is_Formal
(Entity
(R1
))
17421 and then not Is_Formal
(Entity
(R2
));
17422 end Statically_Different
;
17424 --------------------------------------
17425 -- Subject_To_Loop_Entry_Attributes --
17426 --------------------------------------
17428 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
17434 -- The expansion mechanism transform a loop subject to at least one
17435 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
17436 -- the conditional part.
17438 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
17439 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
17441 Stmt
:= Original_Node
(N
);
17445 Nkind
(Stmt
) = N_Loop_Statement
17446 and then Present
(Identifier
(Stmt
))
17447 and then Present
(Entity
(Identifier
(Stmt
)))
17448 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
17449 end Subject_To_Loop_Entry_Attributes
;
17451 -----------------------------
17452 -- Subprogram_Access_Level --
17453 -----------------------------
17455 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
17457 if Present
(Alias
(Subp
)) then
17458 return Subprogram_Access_Level
(Alias
(Subp
));
17460 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
17462 end Subprogram_Access_Level
;
17464 -------------------------------
17465 -- Support_Atomic_Primitives --
17466 -------------------------------
17468 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
17472 -- Verify the alignment of Typ is known
17474 if not Known_Alignment
(Typ
) then
17478 if Known_Static_Esize
(Typ
) then
17479 Size
:= UI_To_Int
(Esize
(Typ
));
17481 -- If the Esize (Object_Size) is unknown at compile time, look at the
17482 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
17484 elsif Known_Static_RM_Size
(Typ
) then
17485 Size
:= UI_To_Int
(RM_Size
(Typ
));
17487 -- Otherwise, the size is considered to be unknown.
17493 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
17494 -- Typ is properly aligned.
17497 when 8 |
16 |
32 |
64 =>
17498 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
17502 end Support_Atomic_Primitives
;
17508 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
17510 if Debug_Flag_W
then
17511 for J
in 0 .. Scope_Stack
.Last
loop
17516 Write_Name
(Chars
(E
));
17517 Write_Str
(" from ");
17518 Write_Location
(Sloc
(N
));
17523 -----------------------
17524 -- Transfer_Entities --
17525 -----------------------
17527 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
17528 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
17529 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
17530 -- Set_Public_Status. If successfull and Id denotes a record type, set
17531 -- the Is_Public attribute of its fields.
17533 --------------------------
17534 -- Set_Public_Status_Of --
17535 --------------------------
17537 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
17541 if not Is_Public
(Id
) then
17542 Set_Public_Status
(Id
);
17544 -- When the input entity is a public record type, ensure that all
17545 -- its internal fields are also exposed to the linker. The fields
17546 -- of a class-wide type are never made public.
17549 and then Is_Record_Type
(Id
)
17550 and then not Is_Class_Wide_Type
(Id
)
17552 Field
:= First_Entity
(Id
);
17553 while Present
(Field
) loop
17554 Set_Is_Public
(Field
);
17555 Next_Entity
(Field
);
17559 end Set_Public_Status_Of
;
17563 Full_Id
: Entity_Id
;
17566 -- Start of processing for Transfer_Entities
17569 Id
:= First_Entity
(From
);
17571 if Present
(Id
) then
17573 -- Merge the entity chain of the source scope with that of the
17574 -- destination scope.
17576 if Present
(Last_Entity
(To
)) then
17577 Set_Next_Entity
(Last_Entity
(To
), Id
);
17579 Set_First_Entity
(To
, Id
);
17582 Set_Last_Entity
(To
, Last_Entity
(From
));
17584 -- Inspect the entities of the source scope and update their Scope
17587 while Present
(Id
) loop
17588 Set_Scope
(Id
, To
);
17589 Set_Public_Status_Of
(Id
);
17591 -- Handle an internally generated full view for a private type
17593 if Is_Private_Type
(Id
)
17594 and then Present
(Full_View
(Id
))
17595 and then Is_Itype
(Full_View
(Id
))
17597 Full_Id
:= Full_View
(Id
);
17599 Set_Scope
(Full_Id
, To
);
17600 Set_Public_Status_Of
(Full_Id
);
17606 Set_First_Entity
(From
, Empty
);
17607 Set_Last_Entity
(From
, Empty
);
17609 end Transfer_Entities
;
17611 -----------------------
17612 -- Type_Access_Level --
17613 -----------------------
17615 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
17619 Btyp
:= Base_Type
(Typ
);
17621 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
17622 -- simply use the level where the type is declared. This is true for
17623 -- stand-alone object declarations, and for anonymous access types
17624 -- associated with components the level is the same as that of the
17625 -- enclosing composite type. However, special treatment is needed for
17626 -- the cases of access parameters, return objects of an anonymous access
17627 -- type, and, in Ada 95, access discriminants of limited types.
17629 if Is_Access_Type
(Btyp
) then
17630 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
17632 -- If the type is a nonlocal anonymous access type (such as for
17633 -- an access parameter) we treat it as being declared at the
17634 -- library level to ensure that names such as X.all'access don't
17635 -- fail static accessibility checks.
17637 if not Is_Local_Anonymous_Access
(Typ
) then
17638 return Scope_Depth
(Standard_Standard
);
17640 -- If this is a return object, the accessibility level is that of
17641 -- the result subtype of the enclosing function. The test here is
17642 -- little complicated, because we have to account for extended
17643 -- return statements that have been rewritten as blocks, in which
17644 -- case we have to find and the Is_Return_Object attribute of the
17645 -- itype's associated object. It would be nice to find a way to
17646 -- simplify this test, but it doesn't seem worthwhile to add a new
17647 -- flag just for purposes of this test. ???
17649 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
17652 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
17653 N_Object_Declaration
17654 and then Is_Return_Object
17655 (Defining_Identifier
17656 (Associated_Node_For_Itype
(Btyp
))))
17662 Scop
:= Scope
(Scope
(Btyp
));
17663 while Present
(Scop
) loop
17664 exit when Ekind
(Scop
) = E_Function
;
17665 Scop
:= Scope
(Scop
);
17668 -- Treat the return object's type as having the level of the
17669 -- function's result subtype (as per RM05-6.5(5.3/2)).
17671 return Type_Access_Level
(Etype
(Scop
));
17676 Btyp
:= Root_Type
(Btyp
);
17678 -- The accessibility level of anonymous access types associated with
17679 -- discriminants is that of the current instance of the type, and
17680 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
17682 -- AI-402: access discriminants have accessibility based on the
17683 -- object rather than the type in Ada 2005, so the above paragraph
17686 -- ??? Needs completion with rules from AI-416
17688 if Ada_Version
<= Ada_95
17689 and then Ekind
(Typ
) = E_Anonymous_Access_Type
17690 and then Present
(Associated_Node_For_Itype
(Typ
))
17691 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
17692 N_Discriminant_Specification
17694 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
17698 -- Return library level for a generic formal type. This is done because
17699 -- RM(10.3.2) says that "The statically deeper relationship does not
17700 -- apply to ... a descendant of a generic formal type". Rather than
17701 -- checking at each point where a static accessibility check is
17702 -- performed to see if we are dealing with a formal type, this rule is
17703 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
17704 -- return extreme values for a formal type; Deepest_Type_Access_Level
17705 -- returns Int'Last. By calling the appropriate function from among the
17706 -- two, we ensure that the static accessibility check will pass if we
17707 -- happen to run into a formal type. More specifically, we should call
17708 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
17709 -- call occurs as part of a static accessibility check and the error
17710 -- case is the case where the type's level is too shallow (as opposed
17713 if Is_Generic_Type
(Root_Type
(Btyp
)) then
17714 return Scope_Depth
(Standard_Standard
);
17717 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
17718 end Type_Access_Level
;
17720 ------------------------------------
17721 -- Type_Without_Stream_Operation --
17722 ------------------------------------
17724 function Type_Without_Stream_Operation
17726 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
17728 BT
: constant Entity_Id
:= Base_Type
(T
);
17729 Op_Missing
: Boolean;
17732 if not Restriction_Active
(No_Default_Stream_Attributes
) then
17736 if Is_Elementary_Type
(T
) then
17737 if Op
= TSS_Null
then
17739 No
(TSS
(BT
, TSS_Stream_Read
))
17740 or else No
(TSS
(BT
, TSS_Stream_Write
));
17743 Op_Missing
:= No
(TSS
(BT
, Op
));
17752 elsif Is_Array_Type
(T
) then
17753 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
17755 elsif Is_Record_Type
(T
) then
17761 Comp
:= First_Component
(T
);
17762 while Present
(Comp
) loop
17763 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
17765 if Present
(C_Typ
) then
17769 Next_Component
(Comp
);
17775 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
17776 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
17780 end Type_Without_Stream_Operation
;
17782 ----------------------------
17783 -- Unique_Defining_Entity --
17784 ----------------------------
17786 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
17788 return Unique_Entity
(Defining_Entity
(N
));
17789 end Unique_Defining_Entity
;
17791 -------------------
17792 -- Unique_Entity --
17793 -------------------
17795 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
17796 U
: Entity_Id
:= E
;
17802 if Present
(Full_View
(E
)) then
17803 U
:= Full_View
(E
);
17807 if Present
(Full_View
(E
)) then
17808 U
:= Full_View
(E
);
17811 when E_Package_Body
=>
17814 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17818 U
:= Corresponding_Spec
(P
);
17820 when E_Subprogram_Body
=>
17823 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
17829 if Nkind
(P
) = N_Subprogram_Body_Stub
then
17830 if Present
(Library_Unit
(P
)) then
17832 -- Get to the function or procedure (generic) entity through
17833 -- the body entity.
17836 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
17839 U
:= Corresponding_Spec
(P
);
17842 when Formal_Kind
=>
17843 if Present
(Spec_Entity
(E
)) then
17844 U
:= Spec_Entity
(E
);
17858 function Unique_Name
(E
: Entity_Id
) return String is
17860 -- Names of E_Subprogram_Body or E_Package_Body entities are not
17861 -- reliable, as they may not include the overloading suffix. Instead,
17862 -- when looking for the name of E or one of its enclosing scope, we get
17863 -- the name of the corresponding Unique_Entity.
17865 function Get_Scoped_Name
(E
: Entity_Id
) return String;
17866 -- Return the name of E prefixed by all the names of the scopes to which
17867 -- E belongs, except for Standard.
17869 ---------------------
17870 -- Get_Scoped_Name --
17871 ---------------------
17873 function Get_Scoped_Name
(E
: Entity_Id
) return String is
17874 Name
: constant String := Get_Name_String
(Chars
(E
));
17876 if Has_Fully_Qualified_Name
(E
)
17877 or else Scope
(E
) = Standard_Standard
17881 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
17883 end Get_Scoped_Name
;
17885 -- Start of processing for Unique_Name
17888 if E
= Standard_Standard
then
17889 return Get_Name_String
(Name_Standard
);
17891 elsif Scope
(E
) = Standard_Standard
17892 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
17894 return Get_Name_String
(Name_Standard
) & "__" &
17895 Get_Name_String
(Chars
(E
));
17897 elsif Ekind
(E
) = E_Enumeration_Literal
then
17898 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
17901 return Get_Scoped_Name
(Unique_Entity
(E
));
17905 ---------------------
17906 -- Unit_Is_Visible --
17907 ---------------------
17909 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
17910 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
17911 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
17913 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
17914 -- For a child unit, check whether unit appears in a with_clause
17917 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
17918 -- Scan the context clause of one compilation unit looking for a
17919 -- with_clause for the unit in question.
17921 ----------------------------
17922 -- Unit_In_Parent_Context --
17923 ----------------------------
17925 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
17927 if Unit_In_Context
(Par_Unit
) then
17930 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
17931 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
17936 end Unit_In_Parent_Context
;
17938 ---------------------
17939 -- Unit_In_Context --
17940 ---------------------
17942 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
17946 Clause
:= First
(Context_Items
(Comp_Unit
));
17947 while Present
(Clause
) loop
17948 if Nkind
(Clause
) = N_With_Clause
then
17949 if Library_Unit
(Clause
) = U
then
17952 -- The with_clause may denote a renaming of the unit we are
17953 -- looking for, eg. Text_IO which renames Ada.Text_IO.
17956 Renamed_Entity
(Entity
(Name
(Clause
))) =
17957 Defining_Entity
(Unit
(U
))
17967 end Unit_In_Context
;
17969 -- Start of processing for Unit_Is_Visible
17972 -- The currrent unit is directly visible
17977 elsif Unit_In_Context
(Curr
) then
17980 -- If the current unit is a body, check the context of the spec
17982 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
17984 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
17985 and then not Acts_As_Spec
(Unit
(Curr
)))
17987 if Unit_In_Context
(Library_Unit
(Curr
)) then
17992 -- If the spec is a child unit, examine the parents
17994 if Is_Child_Unit
(Curr_Entity
) then
17995 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
17997 Unit_In_Parent_Context
17998 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
18000 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
18006 end Unit_Is_Visible
;
18008 ------------------------------
18009 -- Universal_Interpretation --
18010 ------------------------------
18012 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
18013 Index
: Interp_Index
;
18017 -- The argument may be a formal parameter of an operator or subprogram
18018 -- with multiple interpretations, or else an expression for an actual.
18020 if Nkind
(Opnd
) = N_Defining_Identifier
18021 or else not Is_Overloaded
(Opnd
)
18023 if Etype
(Opnd
) = Universal_Integer
18024 or else Etype
(Opnd
) = Universal_Real
18026 return Etype
(Opnd
);
18032 Get_First_Interp
(Opnd
, Index
, It
);
18033 while Present
(It
.Typ
) loop
18034 if It
.Typ
= Universal_Integer
18035 or else It
.Typ
= Universal_Real
18040 Get_Next_Interp
(Index
, It
);
18045 end Universal_Interpretation
;
18051 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
18053 -- Recurse to handle unlikely case of multiple levels of qualification
18055 if Nkind
(Expr
) = N_Qualified_Expression
then
18056 return Unqualify
(Expression
(Expr
));
18058 -- Normal case, not a qualified expression
18065 -----------------------
18066 -- Visible_Ancestors --
18067 -----------------------
18069 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
18075 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
18077 -- Collect all the parents and progenitors of Typ. If the full-view of
18078 -- private parents and progenitors is available then it is used to
18079 -- generate the list of visible ancestors; otherwise their partial
18080 -- view is added to the resulting list.
18085 Use_Full_View
=> True);
18089 Ifaces_List
=> List_2
,
18090 Exclude_Parents
=> True,
18091 Use_Full_View
=> True);
18093 -- Join the two lists. Avoid duplications because an interface may
18094 -- simultaneously be parent and progenitor of a type.
18096 Elmt
:= First_Elmt
(List_2
);
18097 while Present
(Elmt
) loop
18098 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
18103 end Visible_Ancestors
;
18105 ----------------------
18106 -- Within_Init_Proc --
18107 ----------------------
18109 function Within_Init_Proc
return Boolean is
18113 S
:= Current_Scope
;
18114 while not Is_Overloadable
(S
) loop
18115 if S
= Standard_Standard
then
18122 return Is_Init_Proc
(S
);
18123 end Within_Init_Proc
;
18129 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
18136 elsif SE
= Standard_Standard
then
18148 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
18149 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
18150 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
18152 Matching_Field
: Entity_Id
;
18153 -- Entity to give a more precise suggestion on how to write a one-
18154 -- element positional aggregate.
18156 function Has_One_Matching_Field
return Boolean;
18157 -- Determines if Expec_Type is a record type with a single component or
18158 -- discriminant whose type matches the found type or is one dimensional
18159 -- array whose component type matches the found type. In the case of
18160 -- one discriminant, we ignore the variant parts. That's not accurate,
18161 -- but good enough for the warning.
18163 ----------------------------
18164 -- Has_One_Matching_Field --
18165 ----------------------------
18167 function Has_One_Matching_Field
return Boolean is
18171 Matching_Field
:= Empty
;
18173 if Is_Array_Type
(Expec_Type
)
18174 and then Number_Dimensions
(Expec_Type
) = 1
18175 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
18177 -- Use type name if available. This excludes multidimensional
18178 -- arrays and anonymous arrays.
18180 if Comes_From_Source
(Expec_Type
) then
18181 Matching_Field
:= Expec_Type
;
18183 -- For an assignment, use name of target
18185 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
18186 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
18188 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
18193 elsif not Is_Record_Type
(Expec_Type
) then
18197 E
:= First_Entity
(Expec_Type
);
18202 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
18203 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
18212 if not Covers
(Etype
(E
), Found_Type
) then
18215 elsif Present
(Next_Entity
(E
))
18216 and then (Ekind
(E
) = E_Component
18217 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
18222 Matching_Field
:= E
;
18226 end Has_One_Matching_Field
;
18228 -- Start of processing for Wrong_Type
18231 -- Don't output message if either type is Any_Type, or if a message
18232 -- has already been posted for this node. We need to do the latter
18233 -- check explicitly (it is ordinarily done in Errout), because we
18234 -- are using ! to force the output of the error messages.
18236 if Expec_Type
= Any_Type
18237 or else Found_Type
= Any_Type
18238 or else Error_Posted
(Expr
)
18242 -- If one of the types is a Taft-Amendment type and the other it its
18243 -- completion, it must be an illegal use of a TAT in the spec, for
18244 -- which an error was already emitted. Avoid cascaded errors.
18246 elsif Is_Incomplete_Type
(Expec_Type
)
18247 and then Has_Completion_In_Body
(Expec_Type
)
18248 and then Full_View
(Expec_Type
) = Etype
(Expr
)
18252 elsif Is_Incomplete_Type
(Etype
(Expr
))
18253 and then Has_Completion_In_Body
(Etype
(Expr
))
18254 and then Full_View
(Etype
(Expr
)) = Expec_Type
18258 -- In an instance, there is an ongoing problem with completion of
18259 -- type derived from private types. Their structure is what Gigi
18260 -- expects, but the Etype is the parent type rather than the
18261 -- derived private type itself. Do not flag error in this case. The
18262 -- private completion is an entity without a parent, like an Itype.
18263 -- Similarly, full and partial views may be incorrect in the instance.
18264 -- There is no simple way to insure that it is consistent ???
18266 -- A similar view discrepancy can happen in an inlined body, for the
18267 -- same reason: inserted body may be outside of the original package
18268 -- and only partial views are visible at the point of insertion.
18270 elsif In_Instance
or else In_Inlined_Body
then
18271 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
18273 (Has_Private_Declaration
(Expected_Type
)
18274 or else Has_Private_Declaration
(Etype
(Expr
)))
18275 and then No
(Parent
(Expected_Type
))
18279 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
18280 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
18284 elsif Is_Private_Type
(Expected_Type
)
18285 and then Present
(Full_View
(Expected_Type
))
18286 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
18292 -- An interesting special check. If the expression is parenthesized
18293 -- and its type corresponds to the type of the sole component of the
18294 -- expected record type, or to the component type of the expected one
18295 -- dimensional array type, then assume we have a bad aggregate attempt.
18297 if Nkind
(Expr
) in N_Subexpr
18298 and then Paren_Count
(Expr
) /= 0
18299 and then Has_One_Matching_Field
18301 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
18302 if Present
(Matching_Field
) then
18303 if Is_Array_Type
(Expec_Type
) then
18305 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
18309 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
18313 -- Another special check, if we are looking for a pool-specific access
18314 -- type and we found an E_Access_Attribute_Type, then we have the case
18315 -- of an Access attribute being used in a context which needs a pool-
18316 -- specific type, which is never allowed. The one extra check we make
18317 -- is that the expected designated type covers the Found_Type.
18319 elsif Is_Access_Type
(Expec_Type
)
18320 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
18321 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
18322 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
18324 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
18326 Error_Msg_N
-- CODEFIX
18327 ("result must be general access type!", Expr
);
18328 Error_Msg_NE
-- CODEFIX
18329 ("add ALL to }!", Expr
, Expec_Type
);
18331 -- Another special check, if the expected type is an integer type,
18332 -- but the expression is of type System.Address, and the parent is
18333 -- an addition or subtraction operation whose left operand is the
18334 -- expression in question and whose right operand is of an integral
18335 -- type, then this is an attempt at address arithmetic, so give
18336 -- appropriate message.
18338 elsif Is_Integer_Type
(Expec_Type
)
18339 and then Is_RTE
(Found_Type
, RE_Address
)
18340 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
18341 and then Expr
= Left_Opnd
(Parent
(Expr
))
18342 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
18345 ("address arithmetic not predefined in package System",
18348 ("\possible missing with/use of System.Storage_Elements",
18352 -- If the expected type is an anonymous access type, as for access
18353 -- parameters and discriminants, the error is on the designated types.
18355 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
18356 if Comes_From_Source
(Expec_Type
) then
18357 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
18360 ("expected an access type with designated}",
18361 Expr
, Designated_Type
(Expec_Type
));
18364 if Is_Access_Type
(Found_Type
)
18365 and then not Comes_From_Source
(Found_Type
)
18368 ("\\found an access type with designated}!",
18369 Expr
, Designated_Type
(Found_Type
));
18371 if From_Limited_With
(Found_Type
) then
18372 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
18373 Error_Msg_Qual_Level
:= 99;
18374 Error_Msg_NE
-- CODEFIX
18375 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
18376 Error_Msg_Qual_Level
:= 0;
18378 Error_Msg_NE
("found}!", Expr
, Found_Type
);
18382 -- Normal case of one type found, some other type expected
18385 -- If the names of the two types are the same, see if some number
18386 -- of levels of qualification will help. Don't try more than three
18387 -- levels, and if we get to standard, it's no use (and probably
18388 -- represents an error in the compiler) Also do not bother with
18389 -- internal scope names.
18392 Expec_Scope
: Entity_Id
;
18393 Found_Scope
: Entity_Id
;
18396 Expec_Scope
:= Expec_Type
;
18397 Found_Scope
:= Found_Type
;
18399 for Levels
in Int
range 0 .. 3 loop
18400 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
18401 Error_Msg_Qual_Level
:= Levels
;
18405 Expec_Scope
:= Scope
(Expec_Scope
);
18406 Found_Scope
:= Scope
(Found_Scope
);
18408 exit when Expec_Scope
= Standard_Standard
18409 or else Found_Scope
= Standard_Standard
18410 or else not Comes_From_Source
(Expec_Scope
)
18411 or else not Comes_From_Source
(Found_Scope
);
18415 if Is_Record_Type
(Expec_Type
)
18416 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
18418 Error_Msg_NE
("expected}!", Expr
,
18419 Corresponding_Remote_Type
(Expec_Type
));
18421 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
18424 if Is_Entity_Name
(Expr
)
18425 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
18427 Error_Msg_N
("\\found package name!", Expr
);
18429 elsif Is_Entity_Name
(Expr
)
18430 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
18432 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
18434 ("found procedure name, possibly missing Access attribute!",
18438 ("\\found procedure name instead of function!", Expr
);
18441 elsif Nkind
(Expr
) = N_Function_Call
18442 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
18443 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
18444 and then No
(Parameter_Associations
(Expr
))
18447 ("found function name, possibly missing Access attribute!",
18450 -- Catch common error: a prefix or infix operator which is not
18451 -- directly visible because the type isn't.
18453 elsif Nkind
(Expr
) in N_Op
18454 and then Is_Overloaded
(Expr
)
18455 and then not Is_Immediately_Visible
(Expec_Type
)
18456 and then not Is_Potentially_Use_Visible
(Expec_Type
)
18457 and then not In_Use
(Expec_Type
)
18458 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
18461 ("operator of the type is not directly visible!", Expr
);
18463 elsif Ekind
(Found_Type
) = E_Void
18464 and then Present
(Parent
(Found_Type
))
18465 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
18467 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
18470 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
18473 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
18474 -- of the same modular type, and (M1 and M2) = 0 was intended.
18476 if Expec_Type
= Standard_Boolean
18477 and then Is_Modular_Integer_Type
(Found_Type
)
18478 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
18479 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
18482 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
18483 L
: constant Node_Id
:= Left_Opnd
(Op
);
18484 R
: constant Node_Id
:= Right_Opnd
(Op
);
18487 -- The case for the message is when the left operand of the
18488 -- comparison is the same modular type, or when it is an
18489 -- integer literal (or other universal integer expression),
18490 -- which would have been typed as the modular type if the
18491 -- parens had been there.
18493 if (Etype
(L
) = Found_Type
18495 Etype
(L
) = Universal_Integer
)
18496 and then Is_Integer_Type
(Etype
(R
))
18499 ("\\possible missing parens for modular operation", Expr
);
18504 -- Reset error message qualification indication
18506 Error_Msg_Qual_Level
:= 0;