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
;
38 with Ghost
; use Ghost
;
40 with Lib
.Xref
; use Lib
.Xref
;
41 with Namet
.Sp
; use Namet
.Sp
;
42 with Nlists
; use Nlists
;
43 with Nmake
; use Nmake
;
44 with Output
; use Output
;
45 with Restrict
; use Restrict
;
46 with Rident
; use Rident
;
47 with Rtsfind
; use Rtsfind
;
49 with Sem_Aux
; use Sem_Aux
;
50 with Sem_Attr
; use Sem_Attr
;
51 with Sem_Ch6
; use Sem_Ch6
;
52 with Sem_Ch8
; use Sem_Ch8
;
53 with Sem_Ch12
; use Sem_Ch12
;
54 with Sem_Ch13
; use Sem_Ch13
;
55 with Sem_Disp
; use Sem_Disp
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Prag
; use Sem_Prag
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Sem_Type
; use Sem_Type
;
61 with Sinfo
; use Sinfo
;
62 with Sinput
; use Sinput
;
63 with Stand
; use Stand
;
65 with Stringt
; use Stringt
;
66 with Targparm
; use Targparm
;
67 with Tbuild
; use Tbuild
;
68 with Ttypes
; use Ttypes
;
69 with Uname
; use Uname
;
71 with GNAT
.HTable
; use GNAT
.HTable
;
73 package body Sem_Util
is
75 ----------------------------------------
76 -- Global Variables for New_Copy_Tree --
77 ----------------------------------------
79 -- These global variables are used by New_Copy_Tree. See description of the
80 -- body of this subprogram for details. Global variables can be safely used
81 -- by New_Copy_Tree, since there is no case of a recursive call from the
82 -- processing inside New_Copy_Tree.
84 NCT_Hash_Threshold
: constant := 20;
85 -- If there are more than this number of pairs of entries in the map, then
86 -- Hash_Tables_Used will be set, and the hash tables will be initialized
87 -- and used for the searches.
89 NCT_Hash_Tables_Used
: Boolean := False;
90 -- Set to True if hash tables are in use
92 NCT_Table_Entries
: Nat
:= 0;
93 -- Count entries in table to see if threshold is reached
95 NCT_Hash_Table_Setup
: Boolean := False;
96 -- Set to True if hash table contains data. We set this True if we setup
97 -- the hash table with data, and leave it set permanently from then on,
98 -- this is a signal that second and subsequent users of the hash table
99 -- must clear the old entries before reuse.
101 subtype NCT_Header_Num
is Int
range 0 .. 511;
102 -- Defines range of headers in hash tables (512 headers)
104 -----------------------
105 -- Local Subprograms --
106 -----------------------
108 function Build_Component_Subtype
111 T
: Entity_Id
) return Node_Id
;
112 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
113 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
114 -- Loc is the source location, T is the original subtype.
116 function Has_Enabled_Property
117 (Item_Id
: Entity_Id
;
118 Property
: Name_Id
) return Boolean;
119 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
120 -- Determine whether an abstract state or a variable denoted by entity
121 -- Item_Id has enabled property Property.
123 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
124 -- T is a derived tagged type. Check whether the type extension is null.
125 -- If the parent type is fully initialized, T can be treated as such.
127 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
128 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
129 -- with discriminants whose default values are static, examine only the
130 -- components in the selected variant to determine whether all of them
133 ------------------------------
134 -- Abstract_Interface_List --
135 ------------------------------
137 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
141 if Is_Concurrent_Type
(Typ
) then
143 -- If we are dealing with a synchronized subtype, go to the base
144 -- type, whose declaration has the interface list.
146 -- Shouldn't this be Declaration_Node???
148 Nod
:= Parent
(Base_Type
(Typ
));
150 if Nkind
(Nod
) = N_Full_Type_Declaration
then
154 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
155 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
156 Nod
:= Type_Definition
(Parent
(Typ
));
158 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
159 if Present
(Full_View
(Typ
))
161 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
163 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
165 -- If the full-view is not available we cannot do anything else
166 -- here (the source has errors).
172 -- Support for generic formals with interfaces is still missing ???
174 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
179 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
183 elsif Ekind
(Typ
) = E_Record_Subtype
then
184 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
186 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
188 -- Recurse, because parent may still be a private extension. Also
189 -- note that the full view of the subtype or the full view of its
190 -- base type may (both) be unavailable.
192 return Abstract_Interface_List
(Etype
(Typ
));
194 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
195 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
196 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
198 Nod
:= Type_Definition
(Parent
(Typ
));
202 return Interface_List
(Nod
);
203 end Abstract_Interface_List
;
205 --------------------------------
206 -- Add_Access_Type_To_Process --
207 --------------------------------
209 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
213 Ensure_Freeze_Node
(E
);
214 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
218 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
222 end Add_Access_Type_To_Process
;
224 --------------------------
225 -- Add_Block_Identifier --
226 --------------------------
228 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
229 Loc
: constant Source_Ptr
:= Sloc
(N
);
232 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
234 -- The block already has a label, return its entity
236 if Present
(Identifier
(N
)) then
237 Id
:= Entity
(Identifier
(N
));
239 -- Create a new block label and set its attributes
242 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
243 Set_Etype
(Id
, Standard_Void_Type
);
246 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
247 Set_Block_Node
(Id
, Identifier
(N
));
249 end Add_Block_Identifier
;
251 -----------------------
252 -- Add_Contract_Item --
253 -----------------------
255 procedure Add_Contract_Item
(Prag
: Node_Id
; Id
: Entity_Id
) is
256 Items
: Node_Id
:= Contract
(Id
);
258 procedure Add_Classification
;
259 -- Prepend Prag to the list of classifications
261 procedure Add_Contract_Test_Case
;
262 -- Prepend Prag to the list of contract and test cases
264 procedure Add_Pre_Post_Condition
;
265 -- Prepend Prag to the list of pre- and postconditions
267 ------------------------
268 -- Add_Classification --
269 ------------------------
271 procedure Add_Classification
is
273 Set_Next_Pragma
(Prag
, Classifications
(Items
));
274 Set_Classifications
(Items
, Prag
);
275 end Add_Classification
;
277 ----------------------------
278 -- Add_Contract_Test_Case --
279 ----------------------------
281 procedure Add_Contract_Test_Case
is
283 Set_Next_Pragma
(Prag
, Contract_Test_Cases
(Items
));
284 Set_Contract_Test_Cases
(Items
, Prag
);
285 end Add_Contract_Test_Case
;
287 ----------------------------
288 -- Add_Pre_Post_Condition --
289 ----------------------------
291 procedure Add_Pre_Post_Condition
is
293 Set_Next_Pragma
(Prag
, Pre_Post_Conditions
(Items
));
294 Set_Pre_Post_Conditions
(Items
, Prag
);
295 end Add_Pre_Post_Condition
;
301 -- Start of processing for Add_Contract_Item
304 -- A contract must contain only pragmas
306 pragma Assert
(Nkind
(Prag
) = N_Pragma
);
307 Prag_Nam
:= Pragma_Name
(Prag
);
309 -- Create a new contract when adding the first item
312 Items
:= Make_Contract
(Sloc
(Id
));
313 Set_Contract
(Id
, Items
);
316 -- Contract items related to constants. Applicable pragmas are:
319 if Ekind
(Id
) = E_Constant
then
320 if Prag_Nam
= Name_Part_Of
then
323 -- The pragma is not a proper contract item
329 -- Contract items related to [generic] packages or instantiations. The
330 -- applicable pragmas are:
334 -- Part_Of (instantiation only)
336 elsif Ekind_In
(Id
, E_Generic_Package
, E_Package
) then
337 if Nam_In
(Prag_Nam
, Name_Abstract_State
,
338 Name_Initial_Condition
,
343 -- Indicator Part_Of must be associated with a package instantiation
345 elsif Prag_Nam
= Name_Part_Of
and then Is_Generic_Instance
(Id
) then
348 -- The pragma is not a proper contract item
354 -- Contract items related to package bodies. The applicable pragmas are:
357 elsif Ekind
(Id
) = E_Package_Body
then
358 if Prag_Nam
= Name_Refined_State
then
361 -- The pragma is not a proper contract item
367 -- Contract items related to subprogram or entry declarations. The
368 -- applicable pragmas are:
371 -- Extensions_Visible
377 elsif Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
378 or else Is_Generic_Subprogram
(Id
)
379 or else Is_Subprogram
(Id
)
381 if Nam_In
(Prag_Nam
, Name_Postcondition
, Name_Precondition
) then
382 Add_Pre_Post_Condition
;
384 elsif Nam_In
(Prag_Nam
, Name_Contract_Cases
, Name_Test_Case
) then
385 Add_Contract_Test_Case
;
387 elsif Nam_In
(Prag_Nam
, Name_Depends
,
388 Name_Extensions_Visible
,
393 -- The pragma is not a proper contract item
399 -- Contract items related to subprogram bodies. Applicable pragmas are:
406 elsif Ekind
(Id
) = E_Subprogram_Body
then
407 if Nam_In
(Prag_Nam
, Name_Refined_Depends
, Name_Refined_Global
) then
410 elsif Nam_In
(Prag_Nam
, Name_Postcondition
,
414 Add_Pre_Post_Condition
;
416 -- The pragma is not a proper contract item
422 -- Contract items related to variables. Applicable pragmas are:
429 elsif Ekind
(Id
) = E_Variable
then
430 if Nam_In
(Prag_Nam
, Name_Async_Readers
,
432 Name_Effective_Reads
,
433 Name_Effective_Writes
,
438 -- The pragma is not a proper contract item
444 end Add_Contract_Item
;
446 ----------------------------
447 -- Add_Global_Declaration --
448 ----------------------------
450 procedure Add_Global_Declaration
(N
: Node_Id
) is
451 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
454 if No
(Declarations
(Aux_Node
)) then
455 Set_Declarations
(Aux_Node
, New_List
);
458 Append_To
(Declarations
(Aux_Node
), N
);
460 end Add_Global_Declaration
;
462 --------------------------------
463 -- Address_Integer_Convert_OK --
464 --------------------------------
466 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
468 if Allow_Integer_Address
469 and then ((Is_Descendent_Of_Address
(T1
)
470 and then Is_Private_Type
(T1
)
471 and then Is_Integer_Type
(T2
))
473 (Is_Descendent_Of_Address
(T2
)
474 and then Is_Private_Type
(T2
)
475 and then Is_Integer_Type
(T1
)))
481 end Address_Integer_Convert_OK
;
487 -- For now, just 8/16/32/64. but analyze later if AAMP is special???
489 function Addressable
(V
: Uint
) return Boolean is
491 return V
= Uint_8
or else
497 function Addressable
(V
: Int
) return Boolean is
505 ---------------------------------
506 -- Aggregate_Constraint_Checks --
507 ---------------------------------
509 procedure Aggregate_Constraint_Checks
511 Check_Typ
: Entity_Id
)
513 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
516 if Raises_Constraint_Error
(Exp
) then
520 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
521 -- component's type to force the appropriate accessibility checks.
523 -- Ada 2005 (AI-231): Generate conversion to the null-excluding
524 -- type to force the corresponding run-time check
526 if Is_Access_Type
(Check_Typ
)
527 and then ((Is_Local_Anonymous_Access
(Check_Typ
))
528 or else (Can_Never_Be_Null
(Check_Typ
)
529 and then not Can_Never_Be_Null
(Exp_Typ
)))
531 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
532 Analyze_And_Resolve
(Exp
, Check_Typ
);
533 Check_Unset_Reference
(Exp
);
536 -- This is really expansion activity, so make sure that expansion is
537 -- on and is allowed. In GNATprove mode, we also want check flags to
538 -- be added in the tree, so that the formal verification can rely on
539 -- those to be present. In GNATprove mode for formal verification, some
540 -- treatment typically only done during expansion needs to be performed
541 -- on the tree, but it should not be applied inside generics. Otherwise,
542 -- this breaks the name resolution mechanism for generic instances.
544 if not Expander_Active
545 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
550 -- First check if we have to insert discriminant checks
552 if Has_Discriminants
(Exp_Typ
) then
553 Apply_Discriminant_Check
(Exp
, Check_Typ
);
555 -- Next emit length checks for array aggregates
557 elsif Is_Array_Type
(Exp_Typ
) then
558 Apply_Length_Check
(Exp
, Check_Typ
);
560 -- Finally emit scalar and string checks. If we are dealing with a
561 -- scalar literal we need to check by hand because the Etype of
562 -- literals is not necessarily correct.
564 elsif Is_Scalar_Type
(Exp_Typ
)
565 and then Compile_Time_Known_Value
(Exp
)
567 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
568 Apply_Compile_Time_Constraint_Error
569 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
570 Ent
=> Base_Type
(Check_Typ
),
571 Typ
=> Base_Type
(Check_Typ
));
573 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
574 Apply_Compile_Time_Constraint_Error
575 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
579 elsif not Range_Checks_Suppressed
(Check_Typ
) then
580 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
583 -- Verify that target type is also scalar, to prevent view anomalies
584 -- in instantiations.
586 elsif (Is_Scalar_Type
(Exp_Typ
)
587 or else Nkind
(Exp
) = N_String_Literal
)
588 and then Is_Scalar_Type
(Check_Typ
)
589 and then Exp_Typ
/= Check_Typ
591 if Is_Entity_Name
(Exp
)
592 and then Ekind
(Entity
(Exp
)) = E_Constant
594 -- If expression is a constant, it is worthwhile checking whether
595 -- it is a bound of the type.
597 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
598 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
600 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
601 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
606 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
607 Analyze_And_Resolve
(Exp
, Check_Typ
);
608 Check_Unset_Reference
(Exp
);
611 -- Could use a comment on this case ???
614 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
615 Analyze_And_Resolve
(Exp
, Check_Typ
);
616 Check_Unset_Reference
(Exp
);
620 end Aggregate_Constraint_Checks
;
622 -----------------------
623 -- Alignment_In_Bits --
624 -----------------------
626 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
628 return Alignment
(E
) * System_Storage_Unit
;
629 end Alignment_In_Bits
;
631 ---------------------------------
632 -- Append_Inherited_Subprogram --
633 ---------------------------------
635 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
636 Par
: constant Entity_Id
:= Alias
(S
);
637 -- The parent subprogram
639 Scop
: constant Entity_Id
:= Scope
(Par
);
640 -- The scope of definition of the parent subprogram
642 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
643 -- The derived type of which S is a primitive operation
649 if Ekind
(Current_Scope
) = E_Package
650 and then In_Private_Part
(Current_Scope
)
651 and then Has_Private_Declaration
(Typ
)
652 and then Is_Tagged_Type
(Typ
)
653 and then Scop
= Current_Scope
655 -- The inherited operation is available at the earliest place after
656 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
657 -- relevant for type extensions. If the parent operation appears
658 -- after the type extension, the operation is not visible.
661 (Visible_Declarations
662 (Package_Specification
(Current_Scope
)));
663 while Present
(Decl
) loop
664 if Nkind
(Decl
) = N_Private_Extension_Declaration
665 and then Defining_Entity
(Decl
) = Typ
667 if Sloc
(Decl
) > Sloc
(Par
) then
668 Next_E
:= Next_Entity
(Par
);
669 Set_Next_Entity
(Par
, S
);
670 Set_Next_Entity
(S
, Next_E
);
682 -- If partial view is not a type extension, or it appears before the
683 -- subprogram declaration, insert normally at end of entity list.
685 Append_Entity
(S
, Current_Scope
);
686 end Append_Inherited_Subprogram
;
688 -----------------------------------------
689 -- Apply_Compile_Time_Constraint_Error --
690 -----------------------------------------
692 procedure Apply_Compile_Time_Constraint_Error
695 Reason
: RT_Exception_Code
;
696 Ent
: Entity_Id
:= Empty
;
697 Typ
: Entity_Id
:= Empty
;
698 Loc
: Source_Ptr
:= No_Location
;
699 Rep
: Boolean := True;
700 Warn
: Boolean := False)
702 Stat
: constant Boolean := Is_Static_Expression
(N
);
703 R_Stat
: constant Node_Id
:=
704 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
715 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
721 -- Now we replace the node by an N_Raise_Constraint_Error node
722 -- This does not need reanalyzing, so set it as analyzed now.
725 Set_Analyzed
(N
, True);
728 Set_Raises_Constraint_Error
(N
);
730 -- Now deal with possible local raise handling
732 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
734 -- If the original expression was marked as static, the result is
735 -- still marked as static, but the Raises_Constraint_Error flag is
736 -- always set so that further static evaluation is not attempted.
739 Set_Is_Static_Expression
(N
);
741 end Apply_Compile_Time_Constraint_Error
;
743 ---------------------------
744 -- Async_Readers_Enabled --
745 ---------------------------
747 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
749 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
750 end Async_Readers_Enabled
;
752 ---------------------------
753 -- Async_Writers_Enabled --
754 ---------------------------
756 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
758 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
759 end Async_Writers_Enabled
;
761 --------------------------------------
762 -- Available_Full_View_Of_Component --
763 --------------------------------------
765 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
766 ST
: constant Entity_Id
:= Scope
(T
);
767 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
769 return In_Open_Scopes
(ST
)
770 and then In_Open_Scopes
(SCT
)
771 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
772 end Available_Full_View_Of_Component
;
778 procedure Bad_Attribute
781 Warn
: Boolean := False)
784 Error_Msg_Warn
:= Warn
;
785 Error_Msg_N
("unrecognized attribute&<<", N
);
787 -- Check for possible misspelling
789 Error_Msg_Name_1
:= First_Attribute_Name
;
790 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
791 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
792 Error_Msg_N
-- CODEFIX
793 ("\possible misspelling of %<<", N
);
797 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
801 --------------------------------
802 -- Bad_Predicated_Subtype_Use --
803 --------------------------------
805 procedure Bad_Predicated_Subtype_Use
809 Suggest_Static
: Boolean := False)
814 -- Avoid cascaded errors
816 if Error_Posted
(N
) then
820 if Inside_A_Generic
then
821 Gen
:= Current_Scope
;
822 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
830 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
831 Set_No_Predicate_On_Actual
(Typ
);
834 elsif Has_Predicates
(Typ
) then
835 if Is_Generic_Actual_Type
(Typ
) then
837 -- The restriction on loop parameters is only that the type
838 -- should have no dynamic predicates.
840 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
841 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
842 and then Is_OK_Static_Subtype
(Typ
)
847 Gen
:= Current_Scope
;
848 while not Is_Generic_Instance
(Gen
) loop
852 pragma Assert
(Present
(Gen
));
854 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
855 Error_Msg_Warn
:= SPARK_Mode
/= On
;
856 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
857 Error_Msg_F
("\Program_Error [<<", N
);
860 Make_Raise_Program_Error
(Sloc
(N
),
861 Reason
=> PE_Bad_Predicated_Generic_Type
));
864 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
868 Error_Msg_FE
(Msg
, N
, Typ
);
871 -- Emit an optional suggestion on how to remedy the error if the
872 -- context warrants it.
874 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
875 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
878 end Bad_Predicated_Subtype_Use
;
880 -----------------------------------------
881 -- Bad_Unordered_Enumeration_Reference --
882 -----------------------------------------
884 function Bad_Unordered_Enumeration_Reference
886 T
: Entity_Id
) return Boolean
889 return Is_Enumeration_Type
(T
)
890 and then Warn_On_Unordered_Enumeration_Type
891 and then not Is_Generic_Type
(T
)
892 and then Comes_From_Source
(N
)
893 and then not Has_Pragma_Ordered
(T
)
894 and then not In_Same_Extended_Unit
(N
, T
);
895 end Bad_Unordered_Enumeration_Reference
;
897 --------------------------
898 -- Build_Actual_Subtype --
899 --------------------------
901 function Build_Actual_Subtype
903 N
: Node_Or_Entity_Id
) return Node_Id
906 -- Normally Sloc (N), but may point to corresponding body in some cases
908 Constraints
: List_Id
;
914 Disc_Type
: Entity_Id
;
920 if Nkind
(N
) = N_Defining_Identifier
then
921 Obj
:= New_Occurrence_Of
(N
, Loc
);
923 -- If this is a formal parameter of a subprogram declaration, and
924 -- we are compiling the body, we want the declaration for the
925 -- actual subtype to carry the source position of the body, to
926 -- prevent anomalies in gdb when stepping through the code.
928 if Is_Formal
(N
) then
930 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
932 if Nkind
(Decl
) = N_Subprogram_Declaration
933 and then Present
(Corresponding_Body
(Decl
))
935 Loc
:= Sloc
(Corresponding_Body
(Decl
));
944 if Is_Array_Type
(T
) then
945 Constraints
:= New_List
;
946 for J
in 1 .. Number_Dimensions
(T
) loop
948 -- Build an array subtype declaration with the nominal subtype and
949 -- the bounds of the actual. Add the declaration in front of the
950 -- local declarations for the subprogram, for analysis before any
951 -- reference to the formal in the body.
954 Make_Attribute_Reference
(Loc
,
956 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
957 Attribute_Name
=> Name_First
,
958 Expressions
=> New_List
(
959 Make_Integer_Literal
(Loc
, J
)));
962 Make_Attribute_Reference
(Loc
,
964 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
965 Attribute_Name
=> Name_Last
,
966 Expressions
=> New_List
(
967 Make_Integer_Literal
(Loc
, J
)));
969 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
972 -- If the type has unknown discriminants there is no constrained
973 -- subtype to build. This is never called for a formal or for a
974 -- lhs, so returning the type is ok ???
976 elsif Has_Unknown_Discriminants
(T
) then
980 Constraints
:= New_List
;
982 -- Type T is a generic derived type, inherit the discriminants from
985 if Is_Private_Type
(T
)
986 and then No
(Full_View
(T
))
988 -- T was flagged as an error if it was declared as a formal
989 -- derived type with known discriminants. In this case there
990 -- is no need to look at the parent type since T already carries
991 -- its own discriminants.
993 and then not Error_Posted
(T
)
995 Disc_Type
:= Etype
(Base_Type
(T
));
1000 Discr
:= First_Discriminant
(Disc_Type
);
1001 while Present
(Discr
) loop
1002 Append_To
(Constraints
,
1003 Make_Selected_Component
(Loc
,
1005 Duplicate_Subexpr_No_Checks
(Obj
),
1006 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
1007 Next_Discriminant
(Discr
);
1011 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
1012 Set_Is_Internal
(Subt
);
1015 Make_Subtype_Declaration
(Loc
,
1016 Defining_Identifier
=> Subt
,
1017 Subtype_Indication
=>
1018 Make_Subtype_Indication
(Loc
,
1019 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1021 Make_Index_Or_Discriminant_Constraint
(Loc
,
1022 Constraints
=> Constraints
)));
1024 Mark_Rewrite_Insertion
(Decl
);
1026 end Build_Actual_Subtype
;
1028 ---------------------------------------
1029 -- Build_Actual_Subtype_Of_Component --
1030 ---------------------------------------
1032 function Build_Actual_Subtype_Of_Component
1034 N
: Node_Id
) return Node_Id
1036 Loc
: constant Source_Ptr
:= Sloc
(N
);
1037 P
: constant Node_Id
:= Prefix
(N
);
1040 Index_Typ
: Entity_Id
;
1042 Desig_Typ
: Entity_Id
;
1043 -- This is either a copy of T, or if T is an access type, then it is
1044 -- the directly designated type of this access type.
1046 function Build_Actual_Array_Constraint
return List_Id
;
1047 -- If one or more of the bounds of the component depends on
1048 -- discriminants, build actual constraint using the discriminants
1051 function Build_Actual_Record_Constraint
return List_Id
;
1052 -- Similar to previous one, for discriminated components constrained
1053 -- by the discriminant of the enclosing object.
1055 -----------------------------------
1056 -- Build_Actual_Array_Constraint --
1057 -----------------------------------
1059 function Build_Actual_Array_Constraint
return List_Id
is
1060 Constraints
: constant List_Id
:= New_List
;
1068 Indx
:= First_Index
(Desig_Typ
);
1069 while Present
(Indx
) loop
1070 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1071 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1073 if Denotes_Discriminant
(Old_Lo
) then
1075 Make_Selected_Component
(Loc
,
1076 Prefix
=> New_Copy_Tree
(P
),
1077 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1080 Lo
:= New_Copy_Tree
(Old_Lo
);
1082 -- The new bound will be reanalyzed in the enclosing
1083 -- declaration. For literal bounds that come from a type
1084 -- declaration, the type of the context must be imposed, so
1085 -- insure that analysis will take place. For non-universal
1086 -- types this is not strictly necessary.
1088 Set_Analyzed
(Lo
, False);
1091 if Denotes_Discriminant
(Old_Hi
) then
1093 Make_Selected_Component
(Loc
,
1094 Prefix
=> New_Copy_Tree
(P
),
1095 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1098 Hi
:= New_Copy_Tree
(Old_Hi
);
1099 Set_Analyzed
(Hi
, False);
1102 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1107 end Build_Actual_Array_Constraint
;
1109 ------------------------------------
1110 -- Build_Actual_Record_Constraint --
1111 ------------------------------------
1113 function Build_Actual_Record_Constraint
return List_Id
is
1114 Constraints
: constant List_Id
:= New_List
;
1119 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1120 while Present
(D
) loop
1121 if Denotes_Discriminant
(Node
(D
)) then
1122 D_Val
:= Make_Selected_Component
(Loc
,
1123 Prefix
=> New_Copy_Tree
(P
),
1124 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1127 D_Val
:= New_Copy_Tree
(Node
(D
));
1130 Append
(D_Val
, Constraints
);
1135 end Build_Actual_Record_Constraint
;
1137 -- Start of processing for Build_Actual_Subtype_Of_Component
1140 -- Why the test for Spec_Expression mode here???
1142 if In_Spec_Expression
then
1145 -- More comments for the rest of this body would be good ???
1147 elsif Nkind
(N
) = N_Explicit_Dereference
then
1148 if Is_Composite_Type
(T
)
1149 and then not Is_Constrained
(T
)
1150 and then not (Is_Class_Wide_Type
(T
)
1151 and then Is_Constrained
(Root_Type
(T
)))
1152 and then not Has_Unknown_Discriminants
(T
)
1154 -- If the type of the dereference is already constrained, it is an
1157 if Is_Array_Type
(Etype
(N
))
1158 and then Is_Constrained
(Etype
(N
))
1162 Remove_Side_Effects
(P
);
1163 return Build_Actual_Subtype
(T
, N
);
1170 if Ekind
(T
) = E_Access_Subtype
then
1171 Desig_Typ
:= Designated_Type
(T
);
1176 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1177 Id
:= First_Index
(Desig_Typ
);
1178 while Present
(Id
) loop
1179 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1181 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1183 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1185 Remove_Side_Effects
(P
);
1187 Build_Component_Subtype
1188 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1194 elsif Is_Composite_Type
(Desig_Typ
)
1195 and then Has_Discriminants
(Desig_Typ
)
1196 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1198 if Is_Private_Type
(Desig_Typ
)
1199 and then No
(Discriminant_Constraint
(Desig_Typ
))
1201 Desig_Typ
:= Full_View
(Desig_Typ
);
1204 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1205 while Present
(D
) loop
1206 if Denotes_Discriminant
(Node
(D
)) then
1207 Remove_Side_Effects
(P
);
1209 Build_Component_Subtype
(
1210 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1217 -- If none of the above, the actual and nominal subtypes are the same
1220 end Build_Actual_Subtype_Of_Component
;
1222 -----------------------------
1223 -- Build_Component_Subtype --
1224 -----------------------------
1226 function Build_Component_Subtype
1229 T
: Entity_Id
) return Node_Id
1235 -- Unchecked_Union components do not require component subtypes
1237 if Is_Unchecked_Union
(T
) then
1241 Subt
:= Make_Temporary
(Loc
, 'S');
1242 Set_Is_Internal
(Subt
);
1245 Make_Subtype_Declaration
(Loc
,
1246 Defining_Identifier
=> Subt
,
1247 Subtype_Indication
=>
1248 Make_Subtype_Indication
(Loc
,
1249 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1251 Make_Index_Or_Discriminant_Constraint
(Loc
,
1252 Constraints
=> C
)));
1254 Mark_Rewrite_Insertion
(Decl
);
1256 end Build_Component_Subtype
;
1258 ----------------------------------
1259 -- Build_Default_Init_Cond_Call --
1260 ----------------------------------
1262 function Build_Default_Init_Cond_Call
1265 Typ
: Entity_Id
) return Node_Id
1267 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1268 Formal_Typ
: constant Entity_Id
:= Etype
(First_Formal
(Proc_Id
));
1272 Make_Procedure_Call_Statement
(Loc
,
1273 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
1274 Parameter_Associations
=> New_List
(
1275 Make_Unchecked_Type_Conversion
(Loc
,
1276 Subtype_Mark
=> New_Occurrence_Of
(Formal_Typ
, Loc
),
1277 Expression
=> New_Occurrence_Of
(Obj_Id
, Loc
))));
1278 end Build_Default_Init_Cond_Call
;
1280 ----------------------------------------------
1281 -- Build_Default_Init_Cond_Procedure_Bodies --
1282 ----------------------------------------------
1284 procedure Build_Default_Init_Cond_Procedure_Bodies
(Priv_Decls
: List_Id
) is
1285 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
);
1286 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1287 -- body of the procedure which verifies the assumption of the pragma at
1288 -- run time. The generated body is added after the type declaration.
1290 --------------------------------------------
1291 -- Build_Default_Init_Cond_Procedure_Body --
1292 --------------------------------------------
1294 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
) is
1295 Param_Id
: Entity_Id
;
1296 -- The entity of the sole formal parameter of the default initial
1297 -- condition procedure.
1299 procedure Replace_Type_Reference
(N
: Node_Id
);
1300 -- Replace a single reference to type Typ with a reference to formal
1301 -- parameter Param_Id.
1303 ----------------------------
1304 -- Replace_Type_Reference --
1305 ----------------------------
1307 procedure Replace_Type_Reference
(N
: Node_Id
) is
1309 Rewrite
(N
, New_Occurrence_Of
(Param_Id
, Sloc
(N
)));
1310 end Replace_Type_Reference
;
1312 procedure Replace_Type_References
is
1313 new Replace_Type_References_Generic
(Replace_Type_Reference
);
1317 GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1318 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1319 Prag
: constant Node_Id
:=
1320 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1321 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1322 Spec_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Proc_Id
);
1323 Body_Decl
: Node_Id
;
1327 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1330 -- The procedure should be generated only for [sub]types subject to
1331 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1332 -- not get this specialized procedure.
1334 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1335 pragma Assert
(Present
(Prag
));
1336 pragma Assert
(Present
(Proc_Id
));
1338 -- Nothing to do if the body was already built
1340 if Present
(Corresponding_Body
(Spec_Decl
)) then
1344 -- Ensure that the analysis and expansion produce Ghost nodes if the
1345 -- type itself is Ghost.
1347 Set_Ghost_Mode_From_Entity
(Typ
);
1349 Param_Id
:= First_Formal
(Proc_Id
);
1351 -- The pragma has an argument. Note that the argument is analyzed
1352 -- after all references to the current instance of the type are
1355 if Present
(Pragma_Argument_Associations
(Prag
)) then
1357 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
1359 if Nkind
(Expr
) = N_Null
then
1360 Stmt
:= Make_Null_Statement
(Loc
);
1362 -- Preserve the original argument of the pragma by replicating it.
1363 -- Replace all references to the current instance of the type with
1364 -- references to the formal parameter.
1367 Expr
:= New_Copy_Tree
(Expr
);
1368 Replace_Type_References
(Expr
, Typ
);
1371 -- pragma Check (Default_Initial_Condition, <Expr>);
1375 Pragma_Identifier
=>
1376 Make_Identifier
(Loc
, Name_Check
),
1378 Pragma_Argument_Associations
=> New_List
(
1379 Make_Pragma_Argument_Association
(Loc
,
1381 Make_Identifier
(Loc
,
1382 Chars
=> Name_Default_Initial_Condition
)),
1383 Make_Pragma_Argument_Association
(Loc
,
1384 Expression
=> Expr
)));
1387 -- Otherwise the pragma appears without an argument
1390 Stmt
:= Make_Null_Statement
(Loc
);
1394 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1397 -- end <Typ>Default_Init_Cond;
1400 Make_Subprogram_Body
(Loc
,
1402 Copy_Separate_Tree
(Specification
(Spec_Decl
)),
1403 Declarations
=> Empty_List
,
1404 Handled_Statement_Sequence
=>
1405 Make_Handled_Sequence_Of_Statements
(Loc
,
1406 Statements
=> New_List
(Stmt
)));
1408 -- Link the spec and body of the default initial condition procedure
1409 -- to prevent the generation of a duplicate body.
1411 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
1412 Set_Corresponding_Spec
(Body_Decl
, Proc_Id
);
1414 Insert_After_And_Analyze
(Declaration_Node
(Typ
), Body_Decl
);
1416 -- Restore the original Ghost mode once analysis and expansion have
1420 end Build_Default_Init_Cond_Procedure_Body
;
1427 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1430 -- Inspect the private declarations looking for [sub]type declarations
1432 Decl
:= First
(Priv_Decls
);
1433 while Present
(Decl
) loop
1434 if Nkind_In
(Decl
, N_Full_Type_Declaration
,
1435 N_Subtype_Declaration
)
1437 Typ
:= Defining_Entity
(Decl
);
1439 -- Guard against partially decorate types due to previous errors
1441 if Is_Type
(Typ
) then
1443 -- If the type is subject to pragma Default_Initial_Condition,
1444 -- generate the body of the internal procedure which verifies
1445 -- the assertion of the pragma at run time.
1447 if Has_Default_Init_Cond
(Typ
) then
1448 Build_Default_Init_Cond_Procedure_Body
(Typ
);
1450 -- A derived type inherits the default initial condition
1451 -- procedure from its parent type.
1453 elsif Has_Inherited_Default_Init_Cond
(Typ
) then
1454 Inherit_Default_Init_Cond_Procedure
(Typ
);
1461 end Build_Default_Init_Cond_Procedure_Bodies
;
1463 ---------------------------------------------------
1464 -- Build_Default_Init_Cond_Procedure_Declaration --
1465 ---------------------------------------------------
1467 procedure Build_Default_Init_Cond_Procedure_Declaration
(Typ
: Entity_Id
) is
1468 GM
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1469 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1470 Prag
: constant Node_Id
:=
1471 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1472 Proc_Id
: Entity_Id
;
1475 -- The procedure should be generated only for types subject to pragma
1476 -- Default_Initial_Condition. Types that inherit the pragma do not get
1477 -- this specialized procedure.
1479 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1480 pragma Assert
(Present
(Prag
));
1482 -- Nothing to do if default initial condition procedure already built
1484 if Present
(Default_Init_Cond_Procedure
(Typ
)) then
1488 -- Ensure that the analysis and expansion produce Ghost nodes if the
1489 -- type itself is Ghost.
1491 Set_Ghost_Mode_From_Entity
(Typ
);
1494 Make_Defining_Identifier
(Loc
,
1495 Chars
=> New_External_Name
(Chars
(Typ
), "Default_Init_Cond"));
1497 -- Associate default initial condition procedure with the private type
1499 Set_Ekind
(Proc_Id
, E_Procedure
);
1500 Set_Is_Default_Init_Cond_Procedure
(Proc_Id
);
1501 Set_Default_Init_Cond_Procedure
(Typ
, Proc_Id
);
1503 -- Mark the default initial condition procedure explicitly as Ghost
1504 -- because it does not come from source.
1506 if Ghost_Mode
> None
then
1507 Set_Is_Ghost_Entity
(Proc_Id
);
1511 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1513 Insert_After_And_Analyze
(Prag
,
1514 Make_Subprogram_Declaration
(Loc
,
1516 Make_Procedure_Specification
(Loc
,
1517 Defining_Unit_Name
=> Proc_Id
,
1518 Parameter_Specifications
=> New_List
(
1519 Make_Parameter_Specification
(Loc
,
1520 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
1521 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))))));
1523 -- Restore the original Ghost mode once analysis and expansion have
1527 end Build_Default_Init_Cond_Procedure_Declaration
;
1529 ---------------------------
1530 -- Build_Default_Subtype --
1531 ---------------------------
1533 function Build_Default_Subtype
1535 N
: Node_Id
) return Entity_Id
1537 Loc
: constant Source_Ptr
:= Sloc
(N
);
1541 -- The base type that is to be constrained by the defaults
1544 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1548 Bas
:= Base_Type
(T
);
1550 -- If T is non-private but its base type is private, this is the
1551 -- completion of a subtype declaration whose parent type is private
1552 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1553 -- are to be found in the full view of the base. Check that the private
1554 -- status of T and its base differ.
1556 if Is_Private_Type
(Bas
)
1557 and then not Is_Private_Type
(T
)
1558 and then Present
(Full_View
(Bas
))
1560 Bas
:= Full_View
(Bas
);
1563 Disc
:= First_Discriminant
(T
);
1565 if No
(Discriminant_Default_Value
(Disc
)) then
1570 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1571 Constraints
: constant List_Id
:= New_List
;
1575 while Present
(Disc
) loop
1576 Append_To
(Constraints
,
1577 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1578 Next_Discriminant
(Disc
);
1582 Make_Subtype_Declaration
(Loc
,
1583 Defining_Identifier
=> Act
,
1584 Subtype_Indication
=>
1585 Make_Subtype_Indication
(Loc
,
1586 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1588 Make_Index_Or_Discriminant_Constraint
(Loc
,
1589 Constraints
=> Constraints
)));
1591 Insert_Action
(N
, Decl
);
1593 -- If the context is a component declaration the subtype declaration
1594 -- will be analyzed when the enclosing type is frozen, otherwise do
1597 if Ekind
(Current_Scope
) /= E_Record_Type
then
1603 end Build_Default_Subtype
;
1605 --------------------------------------------
1606 -- Build_Discriminal_Subtype_Of_Component --
1607 --------------------------------------------
1609 function Build_Discriminal_Subtype_Of_Component
1610 (T
: Entity_Id
) return Node_Id
1612 Loc
: constant Source_Ptr
:= Sloc
(T
);
1616 function Build_Discriminal_Array_Constraint
return List_Id
;
1617 -- If one or more of the bounds of the component depends on
1618 -- discriminants, build actual constraint using the discriminants
1621 function Build_Discriminal_Record_Constraint
return List_Id
;
1622 -- Similar to previous one, for discriminated components constrained by
1623 -- the discriminant of the enclosing object.
1625 ----------------------------------------
1626 -- Build_Discriminal_Array_Constraint --
1627 ----------------------------------------
1629 function Build_Discriminal_Array_Constraint
return List_Id
is
1630 Constraints
: constant List_Id
:= New_List
;
1638 Indx
:= First_Index
(T
);
1639 while Present
(Indx
) loop
1640 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1641 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1643 if Denotes_Discriminant
(Old_Lo
) then
1644 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1647 Lo
:= New_Copy_Tree
(Old_Lo
);
1650 if Denotes_Discriminant
(Old_Hi
) then
1651 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1654 Hi
:= New_Copy_Tree
(Old_Hi
);
1657 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1662 end Build_Discriminal_Array_Constraint
;
1664 -----------------------------------------
1665 -- Build_Discriminal_Record_Constraint --
1666 -----------------------------------------
1668 function Build_Discriminal_Record_Constraint
return List_Id
is
1669 Constraints
: constant List_Id
:= New_List
;
1674 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1675 while Present
(D
) loop
1676 if Denotes_Discriminant
(Node
(D
)) then
1678 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1680 D_Val
:= New_Copy_Tree
(Node
(D
));
1683 Append
(D_Val
, Constraints
);
1688 end Build_Discriminal_Record_Constraint
;
1690 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1693 if Ekind
(T
) = E_Array_Subtype
then
1694 Id
:= First_Index
(T
);
1695 while Present
(Id
) loop
1696 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1698 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1700 return Build_Component_Subtype
1701 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1707 elsif Ekind
(T
) = E_Record_Subtype
1708 and then Has_Discriminants
(T
)
1709 and then not Has_Unknown_Discriminants
(T
)
1711 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1712 while Present
(D
) loop
1713 if Denotes_Discriminant
(Node
(D
)) then
1714 return Build_Component_Subtype
1715 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1722 -- If none of the above, the actual and nominal subtypes are the same
1725 end Build_Discriminal_Subtype_Of_Component
;
1727 ------------------------------
1728 -- Build_Elaboration_Entity --
1729 ------------------------------
1731 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1732 Loc
: constant Source_Ptr
:= Sloc
(N
);
1734 Elab_Ent
: Entity_Id
;
1736 procedure Set_Package_Name
(Ent
: Entity_Id
);
1737 -- Given an entity, sets the fully qualified name of the entity in
1738 -- Name_Buffer, with components separated by double underscores. This
1739 -- is a recursive routine that climbs the scope chain to Standard.
1741 ----------------------
1742 -- Set_Package_Name --
1743 ----------------------
1745 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1747 if Scope
(Ent
) /= Standard_Standard
then
1748 Set_Package_Name
(Scope
(Ent
));
1751 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1753 Name_Buffer
(Name_Len
+ 1) := '_';
1754 Name_Buffer
(Name_Len
+ 2) := '_';
1755 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1756 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1760 Get_Name_String
(Chars
(Ent
));
1762 end Set_Package_Name
;
1764 -- Start of processing for Build_Elaboration_Entity
1767 -- Ignore call if already constructed
1769 if Present
(Elaboration_Entity
(Spec_Id
)) then
1772 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1773 -- no role in analysis.
1775 elsif ASIS_Mode
then
1778 -- See if we need elaboration entity. We always need it for the dynamic
1779 -- elaboration model, since it is needed to properly generate the PE
1780 -- exception for access before elaboration.
1782 elsif Dynamic_Elaboration_Checks
then
1785 -- For the static model, we don't need the elaboration counter if this
1786 -- unit is sure to have no elaboration code, since that means there
1787 -- is no elaboration unit to be called. Note that we can't just decide
1788 -- after the fact by looking to see whether there was elaboration code,
1789 -- because that's too late to make this decision.
1791 elsif Restriction_Active
(No_Elaboration_Code
) then
1794 -- Similarly, for the static model, we can skip the elaboration counter
1795 -- if we have the No_Multiple_Elaboration restriction, since for the
1796 -- static model, that's the only purpose of the counter (to avoid
1797 -- multiple elaboration).
1799 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1803 -- Here we need the elaboration entity
1805 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1806 -- name with dots replaced by double underscore. We have to manually
1807 -- construct this name, since it will be elaborated in the outer scope,
1808 -- and thus will not have the unit name automatically prepended.
1810 Set_Package_Name
(Spec_Id
);
1811 Add_Str_To_Name_Buffer
("_E");
1813 -- Create elaboration counter
1815 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1816 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1819 Make_Object_Declaration
(Loc
,
1820 Defining_Identifier
=> Elab_Ent
,
1821 Object_Definition
=>
1822 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1823 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1825 Push_Scope
(Standard_Standard
);
1826 Add_Global_Declaration
(Decl
);
1829 -- Reset True_Constant indication, since we will indeed assign a value
1830 -- to the variable in the binder main. We also kill the Current_Value
1831 -- and Last_Assignment fields for the same reason.
1833 Set_Is_True_Constant
(Elab_Ent
, False);
1834 Set_Current_Value
(Elab_Ent
, Empty
);
1835 Set_Last_Assignment
(Elab_Ent
, Empty
);
1837 -- We do not want any further qualification of the name (if we did not
1838 -- do this, we would pick up the name of the generic package in the case
1839 -- of a library level generic instantiation).
1841 Set_Has_Qualified_Name
(Elab_Ent
);
1842 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1843 end Build_Elaboration_Entity
;
1845 --------------------------------
1846 -- Build_Explicit_Dereference --
1847 --------------------------------
1849 procedure Build_Explicit_Dereference
1853 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1856 -- An entity of a type with a reference aspect is overloaded with
1857 -- both interpretations: with and without the dereference. Now that
1858 -- the dereference is made explicit, set the type of the node properly,
1859 -- to prevent anomalies in the backend. Same if the expression is an
1860 -- overloaded function call whose return type has a reference aspect.
1862 if Is_Entity_Name
(Expr
) then
1863 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1865 elsif Nkind
(Expr
) = N_Function_Call
then
1866 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1869 Set_Is_Overloaded
(Expr
, False);
1871 -- The expression will often be a generalized indexing that yields a
1872 -- container element that is then dereferenced, in which case the
1873 -- generalized indexing call is also non-overloaded.
1875 if Nkind
(Expr
) = N_Indexed_Component
1876 and then Present
(Generalized_Indexing
(Expr
))
1878 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1882 Make_Explicit_Dereference
(Loc
,
1884 Make_Selected_Component
(Loc
,
1885 Prefix
=> Relocate_Node
(Expr
),
1886 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1887 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1888 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1889 end Build_Explicit_Dereference
;
1891 -----------------------------------
1892 -- Cannot_Raise_Constraint_Error --
1893 -----------------------------------
1895 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1897 if Compile_Time_Known_Value
(Expr
) then
1900 elsif Do_Range_Check
(Expr
) then
1903 elsif Raises_Constraint_Error
(Expr
) then
1907 case Nkind
(Expr
) is
1908 when N_Identifier
=>
1911 when N_Expanded_Name
=>
1914 when N_Selected_Component
=>
1915 return not Do_Discriminant_Check
(Expr
);
1917 when N_Attribute_Reference
=>
1918 if Do_Overflow_Check
(Expr
) then
1921 elsif No
(Expressions
(Expr
)) then
1929 N
:= First
(Expressions
(Expr
));
1930 while Present
(N
) loop
1931 if Cannot_Raise_Constraint_Error
(N
) then
1942 when N_Type_Conversion
=>
1943 if Do_Overflow_Check
(Expr
)
1944 or else Do_Length_Check
(Expr
)
1945 or else Do_Tag_Check
(Expr
)
1949 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1952 when N_Unchecked_Type_Conversion
=>
1953 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1956 if Do_Overflow_Check
(Expr
) then
1959 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1966 if Do_Division_Check
(Expr
)
1968 Do_Overflow_Check
(Expr
)
1973 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1975 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1994 N_Op_Shift_Right_Arithmetic |
1998 if Do_Overflow_Check
(Expr
) then
2002 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
2004 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2011 end Cannot_Raise_Constraint_Error
;
2013 -----------------------------------------
2014 -- Check_Dynamically_Tagged_Expression --
2015 -----------------------------------------
2017 procedure Check_Dynamically_Tagged_Expression
2020 Related_Nod
: Node_Id
)
2023 pragma Assert
(Is_Tagged_Type
(Typ
));
2025 -- In order to avoid spurious errors when analyzing the expanded code,
2026 -- this check is done only for nodes that come from source and for
2027 -- actuals of generic instantiations.
2029 if (Comes_From_Source
(Related_Nod
)
2030 or else In_Generic_Actual
(Expr
))
2031 and then (Is_Class_Wide_Type
(Etype
(Expr
))
2032 or else Is_Dynamically_Tagged
(Expr
))
2033 and then Is_Tagged_Type
(Typ
)
2034 and then not Is_Class_Wide_Type
(Typ
)
2036 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
2038 end Check_Dynamically_Tagged_Expression
;
2040 --------------------------
2041 -- Check_Fully_Declared --
2042 --------------------------
2044 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
2046 if Ekind
(T
) = E_Incomplete_Type
then
2048 -- Ada 2005 (AI-50217): If the type is available through a limited
2049 -- with_clause, verify that its full view has been analyzed.
2051 if From_Limited_With
(T
)
2052 and then Present
(Non_Limited_View
(T
))
2053 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2055 -- The non-limited view is fully declared
2061 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2064 -- Need comments for these tests ???
2066 elsif Has_Private_Component
(T
)
2067 and then not Is_Generic_Type
(Root_Type
(T
))
2068 and then not In_Spec_Expression
2070 -- Special case: if T is the anonymous type created for a single
2071 -- task or protected object, use the name of the source object.
2073 if Is_Concurrent_Type
(T
)
2074 and then not Comes_From_Source
(T
)
2075 and then Nkind
(N
) = N_Object_Declaration
2078 ("type of& has incomplete component",
2079 N
, Defining_Identifier
(N
));
2082 ("premature usage of incomplete}",
2083 N
, First_Subtype
(T
));
2086 end Check_Fully_Declared
;
2088 -------------------------------------
2089 -- Check_Function_Writable_Actuals --
2090 -------------------------------------
2092 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2093 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2094 Identifiers_List
: Elist_Id
:= No_Elist
;
2095 Aggr_Error_Node
: Node_Id
:= Empty
;
2096 Error_Node
: Node_Id
:= Empty
;
2098 procedure Collect_Identifiers
(N
: Node_Id
);
2099 -- In a single traversal of subtree N collect in Writable_Actuals_List
2100 -- all the actuals of functions with writable actuals, and in the list
2101 -- Identifiers_List collect all the identifiers that are not actuals of
2102 -- functions with writable actuals. If a writable actual is referenced
2103 -- twice as writable actual then Error_Node is set to reference its
2104 -- second occurrence, the error is reported, and the tree traversal
2107 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
2108 -- Return the entity associated with the function call
2110 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2111 -- Preanalyze N without reporting errors. Very dubious, you can't just
2112 -- go analyzing things more than once???
2114 -------------------------
2115 -- Collect_Identifiers --
2116 -------------------------
2118 procedure Collect_Identifiers
(N
: Node_Id
) is
2120 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2121 -- Process a single node during the tree traversal to collect the
2122 -- writable actuals of functions and all the identifiers which are
2123 -- not writable actuals of functions.
2125 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2126 -- Returns True if List has a node whose Entity is Entity (N)
2128 -------------------------
2129 -- Check_Function_Call --
2130 -------------------------
2132 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2133 Is_Writable_Actual
: Boolean := False;
2137 if Nkind
(N
) = N_Identifier
then
2139 -- No analysis possible if the entity is not decorated
2141 if No
(Entity
(N
)) then
2144 -- Don't collect identifiers of packages, called functions, etc
2146 elsif Ekind_In
(Entity
(N
), E_Package
,
2153 -- For rewritten nodes, continue the traversal in the original
2154 -- subtree. Needed to handle aggregates in original expressions
2155 -- extracted from the tree by Remove_Side_Effects.
2157 elsif Is_Rewrite_Substitution
(N
) then
2158 Collect_Identifiers
(Original_Node
(N
));
2161 -- For now we skip aggregate discriminants, since they require
2162 -- performing the analysis in two phases to identify conflicts:
2163 -- first one analyzing discriminants and second one analyzing
2164 -- the rest of components (since at run time, discriminants are
2165 -- evaluated prior to components): too much computation cost
2166 -- to identify a corner case???
2168 elsif Nkind
(Parent
(N
)) = N_Component_Association
2169 and then Nkind_In
(Parent
(Parent
(N
)),
2171 N_Extension_Aggregate
)
2174 Choice
: constant Node_Id
:= First
(Choices
(Parent
(N
)));
2177 if Ekind
(Entity
(N
)) = E_Discriminant
then
2180 elsif Expression
(Parent
(N
)) = N
2181 and then Nkind
(Choice
) = N_Identifier
2182 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2188 -- Analyze if N is a writable actual of a function
2190 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2192 Call
: constant Node_Id
:= Parent
(N
);
2197 Id
:= Get_Function_Id
(Call
);
2199 -- In case of previous error, no check is possible
2205 if Ekind_In
(Id
, E_Function
, E_Generic_Function
)
2206 and then Has_Out_Or_In_Out_Parameter
(Id
)
2208 Formal
:= First_Formal
(Id
);
2209 Actual
:= First_Actual
(Call
);
2210 while Present
(Actual
) and then Present
(Formal
) loop
2212 if Ekind_In
(Formal
, E_Out_Parameter
,
2215 Is_Writable_Actual
:= True;
2221 Next_Formal
(Formal
);
2222 Next_Actual
(Actual
);
2228 if Is_Writable_Actual
then
2229 if Contains
(Writable_Actuals_List
, N
) then
2231 -- Report the error on the second occurrence of the
2232 -- identifier. We cannot assume that N is the second
2233 -- occurrence, since Traverse_Func walks through Field2
2234 -- last (see comment in the body of Traverse_Func).
2240 Elmt
:= First_Elmt
(Writable_Actuals_List
);
2241 while Present
(Elmt
)
2242 and then Entity
(Node
(Elmt
)) /= Entity
(N
)
2247 if Sloc
(N
) > Sloc
(Node
(Elmt
)) then
2250 Error_Node
:= Node
(Elmt
);
2254 ("value may be affected by call to & "
2255 & "because order of evaluation is arbitrary",
2261 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2264 if Identifiers_List
= No_Elist
then
2265 Identifiers_List
:= New_Elmt_List
;
2268 Append_Unique_Elmt
(N
, Identifiers_List
);
2281 N
: Node_Id
) return Boolean
2283 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2288 if List
= No_Elist
then
2292 Elmt
:= First_Elmt
(List
);
2293 while Present
(Elmt
) loop
2294 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2308 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2309 -- The traversal procedure
2311 -- Start of processing for Collect_Identifiers
2314 if Present
(Error_Node
) then
2318 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2323 end Collect_Identifiers
;
2325 ---------------------
2326 -- Get_Function_Id --
2327 ---------------------
2329 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
2330 Nam
: constant Node_Id
:= Name
(Call
);
2334 if Nkind
(Nam
) = N_Explicit_Dereference
then
2336 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
2338 elsif Nkind
(Nam
) = N_Selected_Component
then
2339 Id
:= Entity
(Selector_Name
(Nam
));
2341 elsif Nkind
(Nam
) = N_Indexed_Component
then
2342 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
2349 end Get_Function_Id
;
2351 ---------------------------
2352 -- Preanalyze_Expression --
2353 ---------------------------
2355 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2356 Status
: constant Boolean := Get_Ignore_Errors
;
2358 Set_Ignore_Errors
(True);
2360 Set_Ignore_Errors
(Status
);
2361 end Preanalyze_Without_Errors
;
2363 -- Start of processing for Check_Function_Writable_Actuals
2366 -- The check only applies to Ada 2012 code on which Check_Actuals has
2367 -- been set, and only to constructs that have multiple constituents
2368 -- whose order of evaluation is not specified by the language.
2370 if Ada_Version
< Ada_2012
2371 or else not Check_Actuals
(N
)
2372 or else (not (Nkind
(N
) in N_Op
)
2373 and then not (Nkind
(N
) in N_Membership_Test
)
2374 and then not Nkind_In
(N
, N_Range
,
2376 N_Extension_Aggregate
,
2377 N_Full_Type_Declaration
,
2379 N_Procedure_Call_Statement
,
2380 N_Entry_Call_Statement
))
2381 or else (Nkind
(N
) = N_Full_Type_Declaration
2382 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2384 -- In addition, this check only applies to source code, not to code
2385 -- generated by constraint checks.
2387 or else not Comes_From_Source
(N
)
2392 -- If a construct C has two or more direct constituents that are names
2393 -- or expressions whose evaluation may occur in an arbitrary order, at
2394 -- least one of which contains a function call with an in out or out
2395 -- parameter, then the construct is legal only if: for each name N that
2396 -- is passed as a parameter of mode in out or out to some inner function
2397 -- call C2 (not including the construct C itself), there is no other
2398 -- name anywhere within a direct constituent of the construct C other
2399 -- than the one containing C2, that is known to refer to the same
2400 -- object (RM 6.4.1(6.17/3)).
2404 Collect_Identifiers
(Low_Bound
(N
));
2405 Collect_Identifiers
(High_Bound
(N
));
2407 when N_Op | N_Membership_Test
=>
2412 Collect_Identifiers
(Left_Opnd
(N
));
2414 if Present
(Right_Opnd
(N
)) then
2415 Collect_Identifiers
(Right_Opnd
(N
));
2418 if Nkind_In
(N
, N_In
, N_Not_In
)
2419 and then Present
(Alternatives
(N
))
2421 Expr
:= First
(Alternatives
(N
));
2422 while Present
(Expr
) loop
2423 Collect_Identifiers
(Expr
);
2430 when N_Full_Type_Declaration
=>
2432 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2433 -- Return the record part of this record type definition
2435 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2436 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2438 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2439 return Record_Extension_Part
(Type_Def
);
2443 end Get_Record_Part
;
2446 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2447 Rec
: Node_Id
:= Get_Record_Part
(N
);
2450 -- No need to perform any analysis if the record has no
2453 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2457 -- Collect the identifiers starting from the deepest
2458 -- derivation. Done to report the error in the deepest
2462 if Present
(Component_List
(Rec
)) then
2463 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2464 while Present
(Comp
) loop
2465 if Nkind
(Comp
) = N_Component_Declaration
2466 and then Present
(Expression
(Comp
))
2468 Collect_Identifiers
(Expression
(Comp
));
2475 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2476 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2479 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2480 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2484 when N_Subprogram_Call |
2485 N_Entry_Call_Statement
=>
2487 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
2492 Formal
:= First_Formal
(Id
);
2493 Actual
:= First_Actual
(N
);
2494 while Present
(Actual
) and then Present
(Formal
) loop
2495 if Ekind_In
(Formal
, E_Out_Parameter
,
2498 Collect_Identifiers
(Actual
);
2501 Next_Formal
(Formal
);
2502 Next_Actual
(Actual
);
2507 N_Extension_Aggregate
=>
2511 Comp_Expr
: Node_Id
;
2514 -- Handle the N_Others_Choice of array aggregates with static
2515 -- bounds. There is no need to perform this analysis in
2516 -- aggregates without static bounds since we cannot evaluate
2517 -- if the N_Others_Choice covers several elements. There is
2518 -- no need to handle the N_Others choice of record aggregates
2519 -- since at this stage it has been already expanded by
2520 -- Resolve_Record_Aggregate.
2522 if Is_Array_Type
(Etype
(N
))
2523 and then Nkind
(N
) = N_Aggregate
2524 and then Present
(Aggregate_Bounds
(N
))
2525 and then Compile_Time_Known_Bounds
(Etype
(N
))
2526 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2528 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2531 Count_Components
: Uint
:= Uint_0
;
2532 Num_Components
: Uint
;
2533 Others_Assoc
: Node_Id
;
2534 Others_Choice
: Node_Id
:= Empty
;
2535 Others_Box_Present
: Boolean := False;
2538 -- Count positional associations
2540 if Present
(Expressions
(N
)) then
2541 Comp_Expr
:= First
(Expressions
(N
));
2542 while Present
(Comp_Expr
) loop
2543 Count_Components
:= Count_Components
+ 1;
2548 -- Count the rest of elements and locate the N_Others
2551 Assoc
:= First
(Component_Associations
(N
));
2552 while Present
(Assoc
) loop
2553 Choice
:= First
(Choices
(Assoc
));
2554 while Present
(Choice
) loop
2555 if Nkind
(Choice
) = N_Others_Choice
then
2556 Others_Assoc
:= Assoc
;
2557 Others_Choice
:= Choice
;
2558 Others_Box_Present
:= Box_Present
(Assoc
);
2560 -- Count several components
2562 elsif Nkind_In
(Choice
, N_Range
,
2563 N_Subtype_Indication
)
2564 or else (Is_Entity_Name
(Choice
)
2565 and then Is_Type
(Entity
(Choice
)))
2570 Get_Index_Bounds
(Choice
, L
, H
);
2572 (Compile_Time_Known_Value
(L
)
2573 and then Compile_Time_Known_Value
(H
));
2576 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2579 -- Count single component. No other case available
2580 -- since we are handling an aggregate with static
2584 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2585 or else Nkind
(Choice
) = N_Identifier
2586 or else Nkind
(Choice
) = N_Integer_Literal
);
2588 Count_Components
:= Count_Components
+ 1;
2598 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2599 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2601 pragma Assert
(Count_Components
<= Num_Components
);
2603 -- Handle the N_Others choice if it covers several
2606 if Present
(Others_Choice
)
2607 and then (Num_Components
- Count_Components
) > 1
2609 if not Others_Box_Present
then
2611 -- At this stage, if expansion is active, the
2612 -- expression of the others choice has not been
2613 -- analyzed. Hence we generate a duplicate and
2614 -- we analyze it silently to have available the
2615 -- minimum decoration required to collect the
2618 if not Expander_Active
then
2619 Comp_Expr
:= Expression
(Others_Assoc
);
2622 New_Copy_Tree
(Expression
(Others_Assoc
));
2623 Preanalyze_Without_Errors
(Comp_Expr
);
2626 Collect_Identifiers
(Comp_Expr
);
2628 if Writable_Actuals_List
/= No_Elist
then
2630 -- As suggested by Robert, at current stage we
2631 -- report occurrences of this case as warnings.
2634 ("writable function parameter may affect "
2635 & "value in other component because order "
2636 & "of evaluation is unspecified??",
2637 Node
(First_Elmt
(Writable_Actuals_List
)));
2643 -- For an array aggregate, a discrete_choice_list that has
2644 -- a nonstatic range is considered as two or more separate
2645 -- occurrences of the expression (RM 6.4.1(20/3)).
2647 elsif Is_Array_Type
(Etype
(N
))
2648 and then Nkind
(N
) = N_Aggregate
2649 and then Present
(Aggregate_Bounds
(N
))
2650 and then not Compile_Time_Known_Bounds
(Etype
(N
))
2652 -- Collect identifiers found in the dynamic bounds
2655 Count_Components
: Natural := 0;
2656 Low
, High
: Node_Id
;
2659 Assoc
:= First
(Component_Associations
(N
));
2660 while Present
(Assoc
) loop
2661 Choice
:= First
(Choices
(Assoc
));
2662 while Present
(Choice
) loop
2663 if Nkind_In
(Choice
, N_Range
,
2664 N_Subtype_Indication
)
2665 or else (Is_Entity_Name
(Choice
)
2666 and then Is_Type
(Entity
(Choice
)))
2668 Get_Index_Bounds
(Choice
, Low
, High
);
2670 if not Compile_Time_Known_Value
(Low
) then
2671 Collect_Identifiers
(Low
);
2673 if No
(Aggr_Error_Node
) then
2674 Aggr_Error_Node
:= Low
;
2678 if not Compile_Time_Known_Value
(High
) then
2679 Collect_Identifiers
(High
);
2681 if No
(Aggr_Error_Node
) then
2682 Aggr_Error_Node
:= High
;
2686 -- The RM rule is violated if there is more than
2687 -- a single choice in a component association.
2690 Count_Components
:= Count_Components
+ 1;
2692 if No
(Aggr_Error_Node
)
2693 and then Count_Components
> 1
2695 Aggr_Error_Node
:= Choice
;
2698 if not Compile_Time_Known_Value
(Choice
) then
2699 Collect_Identifiers
(Choice
);
2711 -- Handle ancestor part of extension aggregates
2713 if Nkind
(N
) = N_Extension_Aggregate
then
2714 Collect_Identifiers
(Ancestor_Part
(N
));
2717 -- Handle positional associations
2719 if Present
(Expressions
(N
)) then
2720 Comp_Expr
:= First
(Expressions
(N
));
2721 while Present
(Comp_Expr
) loop
2722 if not Is_OK_Static_Expression
(Comp_Expr
) then
2723 Collect_Identifiers
(Comp_Expr
);
2730 -- Handle discrete associations
2732 if Present
(Component_Associations
(N
)) then
2733 Assoc
:= First
(Component_Associations
(N
));
2734 while Present
(Assoc
) loop
2736 if not Box_Present
(Assoc
) then
2737 Choice
:= First
(Choices
(Assoc
));
2738 while Present
(Choice
) loop
2740 -- For now we skip discriminants since it requires
2741 -- performing the analysis in two phases: first one
2742 -- analyzing discriminants and second one analyzing
2743 -- the rest of components since discriminants are
2744 -- evaluated prior to components: too much extra
2745 -- work to detect a corner case???
2747 if Nkind
(Choice
) in N_Has_Entity
2748 and then Present
(Entity
(Choice
))
2749 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2753 elsif Box_Present
(Assoc
) then
2757 if not Analyzed
(Expression
(Assoc
)) then
2759 New_Copy_Tree
(Expression
(Assoc
));
2760 Set_Parent
(Comp_Expr
, Parent
(N
));
2761 Preanalyze_Without_Errors
(Comp_Expr
);
2763 Comp_Expr
:= Expression
(Assoc
);
2766 Collect_Identifiers
(Comp_Expr
);
2782 -- No further action needed if we already reported an error
2784 if Present
(Error_Node
) then
2788 -- Check violation of RM 6.20/3 in aggregates
2790 if Present
(Aggr_Error_Node
)
2791 and then Writable_Actuals_List
/= No_Elist
2794 ("value may be affected by call in other component because they "
2795 & "are evaluated in unspecified order",
2796 Node
(First_Elmt
(Writable_Actuals_List
)));
2800 -- Check if some writable argument of a function is referenced
2802 if Writable_Actuals_List
/= No_Elist
2803 and then Identifiers_List
/= No_Elist
2810 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2811 while Present
(Elmt_1
) loop
2812 Elmt_2
:= First_Elmt
(Identifiers_List
);
2813 while Present
(Elmt_2
) loop
2814 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2815 case Nkind
(Parent
(Node
(Elmt_2
))) is
2817 N_Component_Association |
2818 N_Component_Declaration
=>
2820 ("value may be affected by call in other "
2821 & "component because they are evaluated "
2822 & "in unspecified order",
2825 when N_In | N_Not_In
=>
2827 ("value may be affected by call in other "
2828 & "alternative because they are evaluated "
2829 & "in unspecified order",
2834 ("value of actual may be affected by call in "
2835 & "other actual because they are evaluated "
2836 & "in unspecified order",
2848 end Check_Function_Writable_Actuals
;
2850 --------------------------------
2851 -- Check_Implicit_Dereference --
2852 --------------------------------
2854 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
2860 if Nkind
(N
) = N_Indexed_Component
2861 and then Present
(Generalized_Indexing
(N
))
2863 Nam
:= Generalized_Indexing
(N
);
2868 if Ada_Version
< Ada_2012
2869 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2873 elsif not Comes_From_Source
(N
)
2874 and then Nkind
(N
) /= N_Indexed_Component
2878 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2882 Disc
:= First_Discriminant
(Typ
);
2883 while Present
(Disc
) loop
2884 if Has_Implicit_Dereference
(Disc
) then
2885 Desig
:= Designated_Type
(Etype
(Disc
));
2886 Add_One_Interp
(Nam
, Disc
, Desig
);
2888 -- If the node is a generalized indexing, add interpretation
2889 -- to that node as well, for subsequent resolution.
2891 if Nkind
(N
) = N_Indexed_Component
then
2892 Add_One_Interp
(N
, Disc
, Desig
);
2895 -- If the operation comes from a generic unit and the context
2896 -- is a selected component, the selector name may be global
2897 -- and set in the instance already. Remove the entity to
2898 -- force resolution of the selected component, and the
2899 -- generation of an explicit dereference if needed.
2902 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
2904 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
2910 Next_Discriminant
(Disc
);
2913 end Check_Implicit_Dereference
;
2915 ----------------------------------
2916 -- Check_Internal_Protected_Use --
2917 ----------------------------------
2919 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2925 while Present
(S
) loop
2926 if S
= Standard_Standard
then
2929 elsif Ekind
(S
) = E_Function
2930 and then Ekind
(Scope
(S
)) = E_Protected_Type
2939 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
2941 -- An indirect function call (e.g. a callback within a protected
2942 -- function body) is not statically illegal. If the access type is
2943 -- anonymous and is the type of an access parameter, the scope of Nam
2944 -- will be the protected type, but it is not a protected operation.
2946 if Ekind
(Nam
) = E_Subprogram_Type
2948 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
2952 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2954 ("within protected function cannot use protected "
2955 & "procedure in renaming or as generic actual", N
);
2957 elsif Nkind
(N
) = N_Attribute_Reference
then
2959 ("within protected function cannot take access of "
2960 & " protected procedure", N
);
2964 ("within protected function, protected object is constant", N
);
2966 ("\cannot call operation that may modify it", N
);
2969 end Check_Internal_Protected_Use
;
2971 ---------------------------------------
2972 -- Check_Later_Vs_Basic_Declarations --
2973 ---------------------------------------
2975 procedure Check_Later_Vs_Basic_Declarations
2977 During_Parsing
: Boolean)
2979 Body_Sloc
: Source_Ptr
;
2982 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
2983 -- Return whether Decl is considered as a declarative item.
2984 -- When During_Parsing is True, the semantics of Ada 83 is followed.
2985 -- When During_Parsing is False, the semantics of SPARK is followed.
2987 -------------------------------
2988 -- Is_Later_Declarative_Item --
2989 -------------------------------
2991 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
2993 if Nkind
(Decl
) in N_Later_Decl_Item
then
2996 elsif Nkind
(Decl
) = N_Pragma
then
2999 elsif During_Parsing
then
3002 -- In SPARK, a package declaration is not considered as a later
3003 -- declarative item.
3005 elsif Nkind
(Decl
) = N_Package_Declaration
then
3008 -- In SPARK, a renaming is considered as a later declarative item
3010 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
3016 end Is_Later_Declarative_Item
;
3018 -- Start of Check_Later_Vs_Basic_Declarations
3021 Decl
:= First
(Decls
);
3023 -- Loop through sequence of basic declarative items
3025 Outer
: while Present
(Decl
) loop
3026 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
3027 and then Nkind
(Decl
) not in N_Body_Stub
3031 -- Once a body is encountered, we only allow later declarative
3032 -- items. The inner loop checks the rest of the list.
3035 Body_Sloc
:= Sloc
(Decl
);
3037 Inner
: while Present
(Decl
) loop
3038 if not Is_Later_Declarative_Item
(Decl
) then
3039 if During_Parsing
then
3040 if Ada_Version
= Ada_83
then
3041 Error_Msg_Sloc
:= Body_Sloc
;
3043 ("(Ada 83) decl cannot appear after body#", Decl
);
3046 Error_Msg_Sloc
:= Body_Sloc
;
3047 Check_SPARK_05_Restriction
3048 ("decl cannot appear after body#", Decl
);
3056 end Check_Later_Vs_Basic_Declarations
;
3058 -------------------------
3059 -- Check_Nested_Access --
3060 -------------------------
3062 procedure Check_Nested_Access
(Ent
: Entity_Id
) is
3063 Scop
: constant Entity_Id
:= Current_Scope
;
3064 Current_Subp
: Entity_Id
;
3065 Enclosing
: Entity_Id
;
3068 -- Currently only enabled for VM back-ends for efficiency
3070 if VM_Target
/= No_VM
3071 and then Ekind_In
(Ent
, E_Variable
, E_Constant
, E_Loop_Parameter
)
3072 and then Scope
(Ent
) /= Empty
3073 and then not Is_Library_Level_Entity
(Ent
)
3075 -- Comment the exclusion of imported entities ???
3077 and then not Is_Imported
(Ent
)
3079 -- Get current subprogram that is relevant
3081 if Is_Subprogram
(Scop
)
3082 or else Is_Generic_Subprogram
(Scop
)
3083 or else Is_Entry
(Scop
)
3085 Current_Subp
:= Scop
;
3087 Current_Subp
:= Current_Subprogram
;
3090 Enclosing
:= Enclosing_Subprogram
(Ent
);
3092 -- Set flag if uplevel reference
3094 if Enclosing
/= Empty
and then Enclosing
/= Current_Subp
then
3095 Set_Has_Uplevel_Reference
(Ent
, True);
3098 end Check_Nested_Access
;
3100 ---------------------------
3101 -- Check_No_Hidden_State --
3102 ---------------------------
3104 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
3105 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
3106 -- Determine whether the entity of a package denoted by Pkg has a null
3109 -----------------------------
3110 -- Has_Null_Abstract_State --
3111 -----------------------------
3113 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
3114 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
3117 -- Check first available state of related package. A null abstract
3118 -- state always appears as the sole element of the state list.
3122 and then Is_Null_State
(Node
(First_Elmt
(States
)));
3123 end Has_Null_Abstract_State
;
3127 Context
: Entity_Id
:= Empty
;
3128 Not_Visible
: Boolean := False;
3131 -- Start of processing for Check_No_Hidden_State
3134 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
3136 -- Find the proper context where the object or state appears
3139 while Present
(Scop
) loop
3142 -- Keep track of the context's visibility
3144 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
3146 -- Prevent the search from going too far
3148 if Context
= Standard_Standard
then
3151 -- Objects and states that appear immediately within a subprogram or
3152 -- inside a construct nested within a subprogram do not introduce a
3153 -- hidden state. They behave as local variable declarations.
3155 elsif Is_Subprogram
(Context
) then
3158 -- When examining a package body, use the entity of the spec as it
3159 -- carries the abstract state declarations.
3161 elsif Ekind
(Context
) = E_Package_Body
then
3162 Context
:= Spec_Entity
(Context
);
3165 -- Stop the traversal when a package subject to a null abstract state
3168 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
3169 and then Has_Null_Abstract_State
(Context
)
3174 Scop
:= Scope
(Scop
);
3177 -- At this point we know that there is at least one package with a null
3178 -- abstract state in visibility. Emit an error message unconditionally
3179 -- if the entity being processed is a state because the placement of the
3180 -- related package is irrelevant. This is not the case for objects as
3181 -- the intermediate context matters.
3183 if Present
(Context
)
3184 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
3186 Error_Msg_N
("cannot introduce hidden state &", Id
);
3187 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
3189 end Check_No_Hidden_State
;
3191 ------------------------------------------
3192 -- Check_Potentially_Blocking_Operation --
3193 ------------------------------------------
3195 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
3199 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3200 -- When pragma Detect_Blocking is active, the run time will raise
3201 -- Program_Error. Here we only issue a warning, since we generally
3202 -- support the use of potentially blocking operations in the absence
3205 -- Indirect blocking through a subprogram call cannot be diagnosed
3206 -- statically without interprocedural analysis, so we do not attempt
3209 S
:= Scope
(Current_Scope
);
3210 while Present
(S
) and then S
/= Standard_Standard
loop
3211 if Is_Protected_Type
(S
) then
3213 ("potentially blocking operation in protected operation??", N
);
3219 end Check_Potentially_Blocking_Operation
;
3221 ---------------------------------
3222 -- Check_Result_And_Post_State --
3223 ---------------------------------
3225 procedure Check_Result_And_Post_State
(Subp_Id
: Entity_Id
) is
3226 procedure Check_Result_And_Post_State_In_Pragma
3228 Result_Seen
: in out Boolean);
3229 -- Determine whether pragma Prag mentions attribute 'Result and whether
3230 -- the pragma contains an expression that evaluates differently in pre-
3231 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3232 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3234 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean;
3235 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3236 -- formal parameter.
3238 -------------------------------------------
3239 -- Check_Result_And_Post_State_In_Pragma --
3240 -------------------------------------------
3242 procedure Check_Result_And_Post_State_In_Pragma
3244 Result_Seen
: in out Boolean)
3246 procedure Check_Expression
(Expr
: Node_Id
);
3247 -- Perform the 'Result and post-state checks on a given expression
3249 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
3250 -- Attempt to find attribute 'Result in a subtree denoted by N
3252 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
3253 -- Determine whether source node N denotes "True" or "False"
3255 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
3256 -- Determine whether a subtree denoted by N mentions any construct
3257 -- that denotes a post-state.
3259 procedure Check_Function_Result
is
3260 new Traverse_Proc
(Is_Function_Result
);
3262 ----------------------
3263 -- Check_Expression --
3264 ----------------------
3266 procedure Check_Expression
(Expr
: Node_Id
) is
3268 if not Is_Trivial_Boolean
(Expr
) then
3269 Check_Function_Result
(Expr
);
3271 if not Mentions_Post_State
(Expr
) then
3272 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3274 ("contract case does not check the outcome of calling "
3275 & "&?T?", Expr
, Subp_Id
);
3277 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3279 ("refined postcondition does not check the outcome of "
3280 & "calling &?T?", Prag
, Subp_Id
);
3284 ("postcondition does not check the outcome of calling "
3285 & "&?T?", Prag
, Subp_Id
);
3289 end Check_Expression
;
3291 ------------------------
3292 -- Is_Function_Result --
3293 ------------------------
3295 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3297 if Is_Attribute_Result
(N
) then
3298 Result_Seen
:= True;
3301 -- Continue the traversal
3306 end Is_Function_Result
;
3308 ------------------------
3309 -- Is_Trivial_Boolean --
3310 ------------------------
3312 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3315 Comes_From_Source
(N
)
3316 and then Is_Entity_Name
(N
)
3317 and then (Entity
(N
) = Standard_True
3319 Entity
(N
) = Standard_False
);
3320 end Is_Trivial_Boolean
;
3322 -------------------------
3323 -- Mentions_Post_State --
3324 -------------------------
3326 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3327 Post_State_Seen
: Boolean := False;
3329 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3330 -- Attempt to find a construct that denotes a post-state. If this
3331 -- is the case, set flag Post_State_Seen.
3337 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3341 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3342 Post_State_Seen
:= True;
3345 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3348 -- The entity may be modifiable through an implicit
3352 or else Ekind
(Ent
) in Assignable_Kind
3353 or else (Is_Access_Type
(Etype
(Ent
))
3354 and then Nkind
(Parent
(N
)) =
3355 N_Selected_Component
)
3357 Post_State_Seen
:= True;
3361 elsif Nkind
(N
) = N_Attribute_Reference
then
3362 if Attribute_Name
(N
) = Name_Old
then
3365 elsif Attribute_Name
(N
) = Name_Result
then
3366 Post_State_Seen
:= True;
3374 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3376 -- Start of processing for Mentions_Post_State
3379 Find_Post_State
(N
);
3381 return Post_State_Seen
;
3382 end Mentions_Post_State
;
3386 Expr
: constant Node_Id
:=
3388 (First
(Pragma_Argument_Associations
(Prag
)));
3389 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3392 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3395 -- Examine all consequences
3397 if Nam
= Name_Contract_Cases
then
3398 CCase
:= First
(Component_Associations
(Expr
));
3399 while Present
(CCase
) loop
3400 Check_Expression
(Expression
(CCase
));
3405 -- Examine the expression of a postcondition
3407 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
,
3408 Name_Refined_Post
));
3409 Check_Expression
(Expr
);
3411 end Check_Result_And_Post_State_In_Pragma
;
3413 --------------------------
3414 -- Has_In_Out_Parameter --
3415 --------------------------
3417 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean is
3421 -- Traverse the formals looking for an IN OUT parameter
3423 Formal
:= First_Formal
(Subp_Id
);
3424 while Present
(Formal
) loop
3425 if Ekind
(Formal
) = E_In_Out_Parameter
then
3429 Next_Formal
(Formal
);
3433 end Has_In_Out_Parameter
;
3437 Items
: constant Node_Id
:= Contract
(Subp_Id
);
3438 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
3439 Case_Prag
: Node_Id
:= Empty
;
3440 Post_Prag
: Node_Id
:= Empty
;
3442 Seen_In_Case
: Boolean := False;
3443 Seen_In_Post
: Boolean := False;
3444 Spec_Id
: Entity_Id
;
3446 -- Start of processing for Check_Result_And_Post_State
3449 -- The lack of attribute 'Result or a post-state is classified as a
3450 -- suspicious contract. Do not perform the check if the corresponding
3451 -- swich is not set.
3453 if not Warn_On_Suspicious_Contract
then
3456 -- Nothing to do if there is no contract
3458 elsif No
(Items
) then
3462 -- Retrieve the entity of the subprogram spec (if any)
3464 if Nkind
(Subp_Decl
) = N_Subprogram_Body
3465 and then Present
(Corresponding_Spec
(Subp_Decl
))
3467 Spec_Id
:= Corresponding_Spec
(Subp_Decl
);
3469 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
3470 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
3472 Spec_Id
:= Corresponding_Spec_Of_Stub
(Subp_Decl
);
3478 -- Examine all postconditions for attribute 'Result and a post-state
3480 Prag
:= Pre_Post_Conditions
(Items
);
3481 while Present
(Prag
) loop
3482 if Nam_In
(Pragma_Name
(Prag
), Name_Postcondition
,
3484 and then not Error_Posted
(Prag
)
3487 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Post
);
3490 Prag
:= Next_Pragma
(Prag
);
3493 -- Examine the contract cases of the subprogram for attribute 'Result
3494 -- and a post-state.
3496 Prag
:= Contract_Test_Cases
(Items
);
3497 while Present
(Prag
) loop
3498 if Pragma_Name
(Prag
) = Name_Contract_Cases
3499 and then not Error_Posted
(Prag
)
3502 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Case
);
3505 Prag
:= Next_Pragma
(Prag
);
3508 -- Do not emit any errors if the subprogram is not a function
3510 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
3513 -- Regardless of whether the function has postconditions or contract
3514 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3515 -- parameter is always treated as a result.
3517 elsif Has_In_Out_Parameter
(Spec_Id
) then
3520 -- The function has both a postcondition and contract cases and they do
3521 -- not mention attribute 'Result.
3523 elsif Present
(Case_Prag
)
3524 and then not Seen_In_Case
3525 and then Present
(Post_Prag
)
3526 and then not Seen_In_Post
3529 ("neither postcondition nor contract cases mention function "
3530 & "result?T?", Post_Prag
);
3532 -- The function has contract cases only and they do not mention
3533 -- attribute 'Result.
3535 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
3536 Error_Msg_N
("contract cases do not mention result?T?", Case_Prag
);
3538 -- The function has postconditions only and they do not mention
3539 -- attribute 'Result.
3541 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
3543 ("postcondition does not mention function result?T?", Post_Prag
);
3545 end Check_Result_And_Post_State
;
3547 ------------------------------
3548 -- Check_Unprotected_Access --
3549 ------------------------------
3551 procedure Check_Unprotected_Access
3555 Cont_Encl_Typ
: Entity_Id
;
3556 Pref_Encl_Typ
: Entity_Id
;
3558 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
3559 -- Check whether Obj is a private component of a protected object.
3560 -- Return the protected type where the component resides, Empty
3563 function Is_Public_Operation
return Boolean;
3564 -- Verify that the enclosing operation is callable from outside the
3565 -- protected object, to minimize false positives.
3567 ------------------------------
3568 -- Enclosing_Protected_Type --
3569 ------------------------------
3571 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
3573 if Is_Entity_Name
(Obj
) then
3575 Ent
: Entity_Id
:= Entity
(Obj
);
3578 -- The object can be a renaming of a private component, use
3579 -- the original record component.
3581 if Is_Prival
(Ent
) then
3582 Ent
:= Prival_Link
(Ent
);
3585 if Is_Protected_Type
(Scope
(Ent
)) then
3591 -- For indexed and selected components, recursively check the prefix
3593 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
3594 return Enclosing_Protected_Type
(Prefix
(Obj
));
3596 -- The object does not denote a protected component
3601 end Enclosing_Protected_Type
;
3603 -------------------------
3604 -- Is_Public_Operation --
3605 -------------------------
3607 function Is_Public_Operation
return Boolean is
3613 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
3614 if Scope
(S
) = Pref_Encl_Typ
then
3615 E
:= First_Entity
(Pref_Encl_Typ
);
3617 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
3631 end Is_Public_Operation
;
3633 -- Start of processing for Check_Unprotected_Access
3636 if Nkind
(Expr
) = N_Attribute_Reference
3637 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
3639 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
3640 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
3642 -- Check whether we are trying to export a protected component to a
3643 -- context with an equal or lower access level.
3645 if Present
(Pref_Encl_Typ
)
3646 and then No
(Cont_Encl_Typ
)
3647 and then Is_Public_Operation
3648 and then Scope_Depth
(Pref_Encl_Typ
) >=
3649 Object_Access_Level
(Context
)
3652 ("??possible unprotected access to protected data", Expr
);
3655 end Check_Unprotected_Access
;
3657 ------------------------
3658 -- Collect_Interfaces --
3659 ------------------------
3661 procedure Collect_Interfaces
3663 Ifaces_List
: out Elist_Id
;
3664 Exclude_Parents
: Boolean := False;
3665 Use_Full_View
: Boolean := True)
3667 procedure Collect
(Typ
: Entity_Id
);
3668 -- Subsidiary subprogram used to traverse the whole list
3669 -- of directly and indirectly implemented interfaces
3675 procedure Collect
(Typ
: Entity_Id
) is
3676 Ancestor
: Entity_Id
;
3684 -- Handle private types and subtypes
3687 and then Is_Private_Type
(Typ
)
3688 and then Present
(Full_View
(Typ
))
3690 Full_T
:= Full_View
(Typ
);
3692 if Ekind
(Full_T
) = E_Record_Subtype
then
3693 Full_T
:= Full_View
(Etype
(Typ
));
3697 -- Include the ancestor if we are generating the whole list of
3698 -- abstract interfaces.
3700 if Etype
(Full_T
) /= Typ
3702 -- Protect the frontend against wrong sources. For example:
3705 -- type A is tagged null record;
3706 -- type B is new A with private;
3707 -- type C is new A with private;
3709 -- type B is new C with null record;
3710 -- type C is new B with null record;
3713 and then Etype
(Full_T
) /= T
3715 Ancestor
:= Etype
(Full_T
);
3718 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
3719 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
3723 -- Traverse the graph of ancestor interfaces
3725 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
3726 Id
:= First
(Abstract_Interface_List
(Full_T
));
3727 while Present
(Id
) loop
3728 Iface
:= Etype
(Id
);
3730 -- Protect against wrong uses. For example:
3731 -- type I is interface;
3732 -- type O is tagged null record;
3733 -- type Wrong is new I and O with null record; -- ERROR
3735 if Is_Interface
(Iface
) then
3737 and then Etype
(T
) /= T
3738 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
3743 Append_Unique_Elmt
(Iface
, Ifaces_List
);
3752 -- Start of processing for Collect_Interfaces
3755 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
3756 Ifaces_List
:= New_Elmt_List
;
3758 end Collect_Interfaces
;
3760 ----------------------------------
3761 -- Collect_Interface_Components --
3762 ----------------------------------
3764 procedure Collect_Interface_Components
3765 (Tagged_Type
: Entity_Id
;
3766 Components_List
: out Elist_Id
)
3768 procedure Collect
(Typ
: Entity_Id
);
3769 -- Subsidiary subprogram used to climb to the parents
3775 procedure Collect
(Typ
: Entity_Id
) is
3776 Tag_Comp
: Entity_Id
;
3777 Parent_Typ
: Entity_Id
;
3780 -- Handle private types
3782 if Present
(Full_View
(Etype
(Typ
))) then
3783 Parent_Typ
:= Full_View
(Etype
(Typ
));
3785 Parent_Typ
:= Etype
(Typ
);
3788 if Parent_Typ
/= Typ
3790 -- Protect the frontend against wrong sources. For example:
3793 -- type A is tagged null record;
3794 -- type B is new A with private;
3795 -- type C is new A with private;
3797 -- type B is new C with null record;
3798 -- type C is new B with null record;
3801 and then Parent_Typ
/= Tagged_Type
3803 Collect
(Parent_Typ
);
3806 -- Collect the components containing tags of secondary dispatch
3809 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
3810 while Present
(Tag_Comp
) loop
3811 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
3812 Append_Elmt
(Tag_Comp
, Components_List
);
3814 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
3818 -- Start of processing for Collect_Interface_Components
3821 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
3822 and then Is_Tagged_Type
(Tagged_Type
));
3824 Components_List
:= New_Elmt_List
;
3825 Collect
(Tagged_Type
);
3826 end Collect_Interface_Components
;
3828 -----------------------------
3829 -- Collect_Interfaces_Info --
3830 -----------------------------
3832 procedure Collect_Interfaces_Info
3834 Ifaces_List
: out Elist_Id
;
3835 Components_List
: out Elist_Id
;
3836 Tags_List
: out Elist_Id
)
3838 Comps_List
: Elist_Id
;
3839 Comp_Elmt
: Elmt_Id
;
3840 Comp_Iface
: Entity_Id
;
3841 Iface_Elmt
: Elmt_Id
;
3844 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
3845 -- Search for the secondary tag associated with the interface type
3846 -- Iface that is implemented by T.
3852 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
3855 if not Is_CPP_Class
(T
) then
3856 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
3858 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
3862 and then Is_Tag
(Node
(ADT
))
3863 and then Related_Type
(Node
(ADT
)) /= Iface
3865 -- Skip secondary dispatch table referencing thunks to user
3866 -- defined primitives covered by this interface.
3868 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
3871 -- Skip secondary dispatch tables of Ada types
3873 if not Is_CPP_Class
(T
) then
3875 -- Skip secondary dispatch table referencing thunks to
3876 -- predefined primitives.
3878 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
3881 -- Skip secondary dispatch table referencing user-defined
3882 -- primitives covered by this interface.
3884 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
3887 -- Skip secondary dispatch table referencing predefined
3890 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
3895 pragma Assert
(Is_Tag
(Node
(ADT
)));
3899 -- Start of processing for Collect_Interfaces_Info
3902 Collect_Interfaces
(T
, Ifaces_List
);
3903 Collect_Interface_Components
(T
, Comps_List
);
3905 -- Search for the record component and tag associated with each
3906 -- interface type of T.
3908 Components_List
:= New_Elmt_List
;
3909 Tags_List
:= New_Elmt_List
;
3911 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
3912 while Present
(Iface_Elmt
) loop
3913 Iface
:= Node
(Iface_Elmt
);
3915 -- Associate the primary tag component and the primary dispatch table
3916 -- with all the interfaces that are parents of T
3918 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
3919 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
3920 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
3922 -- Otherwise search for the tag component and secondary dispatch
3926 Comp_Elmt
:= First_Elmt
(Comps_List
);
3927 while Present
(Comp_Elmt
) loop
3928 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
3930 if Comp_Iface
= Iface
3931 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
3933 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
3934 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
3938 Next_Elmt
(Comp_Elmt
);
3940 pragma Assert
(Present
(Comp_Elmt
));
3943 Next_Elmt
(Iface_Elmt
);
3945 end Collect_Interfaces_Info
;
3947 ---------------------
3948 -- Collect_Parents --
3949 ---------------------
3951 procedure Collect_Parents
3953 List
: out Elist_Id
;
3954 Use_Full_View
: Boolean := True)
3956 Current_Typ
: Entity_Id
:= T
;
3957 Parent_Typ
: Entity_Id
;
3960 List
:= New_Elmt_List
;
3962 -- No action if the if the type has no parents
3964 if T
= Etype
(T
) then
3969 Parent_Typ
:= Etype
(Current_Typ
);
3971 if Is_Private_Type
(Parent_Typ
)
3972 and then Present
(Full_View
(Parent_Typ
))
3973 and then Use_Full_View
3975 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
3978 Append_Elmt
(Parent_Typ
, List
);
3980 exit when Parent_Typ
= Current_Typ
;
3981 Current_Typ
:= Parent_Typ
;
3983 end Collect_Parents
;
3985 ----------------------------------
3986 -- Collect_Primitive_Operations --
3987 ----------------------------------
3989 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
3990 B_Type
: constant Entity_Id
:= Base_Type
(T
);
3991 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
3992 B_Scope
: Entity_Id
:= Scope
(B_Type
);
3996 Is_Type_In_Pkg
: Boolean;
3997 Formal_Derived
: Boolean := False;
4000 function Match
(E
: Entity_Id
) return Boolean;
4001 -- True if E's base type is B_Type, or E is of an anonymous access type
4002 -- and the base type of its designated type is B_Type.
4008 function Match
(E
: Entity_Id
) return Boolean is
4009 Etyp
: Entity_Id
:= Etype
(E
);
4012 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
4013 Etyp
:= Designated_Type
(Etyp
);
4016 -- In Ada 2012 a primitive operation may have a formal of an
4017 -- incomplete view of the parent type.
4019 return Base_Type
(Etyp
) = B_Type
4021 (Ada_Version
>= Ada_2012
4022 and then Ekind
(Etyp
) = E_Incomplete_Type
4023 and then Full_View
(Etyp
) = B_Type
);
4026 -- Start of processing for Collect_Primitive_Operations
4029 -- For tagged types, the primitive operations are collected as they
4030 -- are declared, and held in an explicit list which is simply returned.
4032 if Is_Tagged_Type
(B_Type
) then
4033 return Primitive_Operations
(B_Type
);
4035 -- An untagged generic type that is a derived type inherits the
4036 -- primitive operations of its parent type. Other formal types only
4037 -- have predefined operators, which are not explicitly represented.
4039 elsif Is_Generic_Type
(B_Type
) then
4040 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
4041 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
4042 N_Formal_Derived_Type_Definition
4044 Formal_Derived
:= True;
4046 return New_Elmt_List
;
4050 Op_List
:= New_Elmt_List
;
4052 if B_Scope
= Standard_Standard
then
4053 if B_Type
= Standard_String
then
4054 Append_Elmt
(Standard_Op_Concat
, Op_List
);
4056 elsif B_Type
= Standard_Wide_String
then
4057 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
4063 -- Locate the primitive subprograms of the type
4066 -- The primitive operations appear after the base type, except
4067 -- if the derivation happens within the private part of B_Scope
4068 -- and the type is a private type, in which case both the type
4069 -- and some primitive operations may appear before the base
4070 -- type, and the list of candidates starts after the type.
4072 if In_Open_Scopes
(B_Scope
)
4073 and then Scope
(T
) = B_Scope
4074 and then In_Private_Part
(B_Scope
)
4076 Id
:= Next_Entity
(T
);
4078 -- In Ada 2012, If the type has an incomplete partial view, there
4079 -- may be primitive operations declared before the full view, so
4080 -- we need to start scanning from the incomplete view, which is
4081 -- earlier on the entity chain.
4083 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
4084 and then Present
(Incomplete_View
(Parent
(B_Type
)))
4086 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
4089 Id
:= Next_Entity
(B_Type
);
4092 -- Set flag if this is a type in a package spec
4095 Is_Package_Or_Generic_Package
(B_Scope
)
4097 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
4100 while Present
(Id
) loop
4102 -- Test whether the result type or any of the parameter types of
4103 -- each subprogram following the type match that type when the
4104 -- type is declared in a package spec, is a derived type, or the
4105 -- subprogram is marked as primitive. (The Is_Primitive test is
4106 -- needed to find primitives of nonderived types in declarative
4107 -- parts that happen to override the predefined "=" operator.)
4109 -- Note that generic formal subprograms are not considered to be
4110 -- primitive operations and thus are never inherited.
4112 if Is_Overloadable
(Id
)
4113 and then (Is_Type_In_Pkg
4114 or else Is_Derived_Type
(B_Type
)
4115 or else Is_Primitive
(Id
))
4116 and then Nkind
(Parent
(Parent
(Id
)))
4117 not in N_Formal_Subprogram_Declaration
4125 Formal
:= First_Formal
(Id
);
4126 while Present
(Formal
) loop
4127 if Match
(Formal
) then
4132 Next_Formal
(Formal
);
4136 -- For a formal derived type, the only primitives are the ones
4137 -- inherited from the parent type. Operations appearing in the
4138 -- package declaration are not primitive for it.
4141 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
4143 -- In the special case of an equality operator aliased to
4144 -- an overriding dispatching equality belonging to the same
4145 -- type, we don't include it in the list of primitives.
4146 -- This avoids inheriting multiple equality operators when
4147 -- deriving from untagged private types whose full type is
4148 -- tagged, which can otherwise cause ambiguities. Note that
4149 -- this should only happen for this kind of untagged parent
4150 -- type, since normally dispatching operations are inherited
4151 -- using the type's Primitive_Operations list.
4153 if Chars
(Id
) = Name_Op_Eq
4154 and then Is_Dispatching_Operation
(Id
)
4155 and then Present
(Alias
(Id
))
4156 and then Present
(Overridden_Operation
(Alias
(Id
)))
4157 and then Base_Type
(Etype
(First_Entity
(Id
))) =
4158 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
4162 -- Include the subprogram in the list of primitives
4165 Append_Elmt
(Id
, Op_List
);
4172 -- For a type declared in System, some of its operations may
4173 -- appear in the target-specific extension to System.
4176 and then B_Scope
= RTU_Entity
(System
)
4177 and then Present_System_Aux
4179 B_Scope
:= System_Aux_Id
;
4180 Id
:= First_Entity
(System_Aux_Id
);
4186 end Collect_Primitive_Operations
;
4188 -----------------------------------
4189 -- Compile_Time_Constraint_Error --
4190 -----------------------------------
4192 function Compile_Time_Constraint_Error
4195 Ent
: Entity_Id
:= Empty
;
4196 Loc
: Source_Ptr
:= No_Location
;
4197 Warn
: Boolean := False) return Node_Id
4199 Msgc
: String (1 .. Msg
'Length + 3);
4200 -- Copy of message, with room for possible ?? or << and ! at end
4206 -- Start of processing for Compile_Time_Constraint_Error
4209 -- If this is a warning, convert it into an error if we are in code
4210 -- subject to SPARK_Mode being set ON.
4212 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4214 -- A static constraint error in an instance body is not a fatal error.
4215 -- we choose to inhibit the message altogether, because there is no
4216 -- obvious node (for now) on which to post it. On the other hand the
4217 -- offending node must be replaced with a constraint_error in any case.
4219 -- No messages are generated if we already posted an error on this node
4221 if not Error_Posted
(N
) then
4222 if Loc
/= No_Location
then
4228 -- Copy message to Msgc, converting any ? in the message into
4229 -- < instead, so that we have an error in GNATprove mode.
4233 for J
in 1 .. Msgl
loop
4234 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
) /= ''') then
4237 Msgc
(J
) := Msg
(J
);
4241 -- Message is a warning, even in Ada 95 case
4243 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
4246 -- In Ada 83, all messages are warnings. In the private part and
4247 -- the body of an instance, constraint_checks are only warnings.
4248 -- We also make this a warning if the Warn parameter is set.
4251 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
4259 elsif In_Instance_Not_Visible
then
4266 -- Otherwise we have a real error message (Ada 95 static case)
4267 -- and we make this an unconditional message. Note that in the
4268 -- warning case we do not make the message unconditional, it seems
4269 -- quite reasonable to delete messages like this (about exceptions
4270 -- that will be raised) in dead code.
4278 -- One more test, skip the warning if the related expression is
4279 -- statically unevaluated, since we don't want to warn about what
4280 -- will happen when something is evaluated if it never will be
4283 if not Is_Statically_Unevaluated
(N
) then
4284 Error_Msg_Warn
:= SPARK_Mode
/= On
;
4286 if Present
(Ent
) then
4287 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
4289 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
4294 -- Check whether the context is an Init_Proc
4296 if Inside_Init_Proc
then
4298 Conc_Typ
: constant Entity_Id
:=
4299 Corresponding_Concurrent_Type
4300 (Entity
(Parameter_Type
(First
4301 (Parameter_Specifications
4302 (Parent
(Current_Scope
))))));
4305 -- Don't complain if the corresponding concurrent type
4306 -- doesn't come from source (i.e. a single task/protected
4309 if Present
(Conc_Typ
)
4310 and then not Comes_From_Source
(Conc_Typ
)
4313 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4316 if GNATprove_Mode
then
4318 ("\& would have been raised for objects of this "
4319 & "type", N
, Standard_Constraint_Error
, Eloc
);
4322 ("\& will be raised for objects of this type??",
4323 N
, Standard_Constraint_Error
, Eloc
);
4329 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4333 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
4334 Set_Error_Posted
(N
);
4340 end Compile_Time_Constraint_Error
;
4342 -----------------------
4343 -- Conditional_Delay --
4344 -----------------------
4346 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
4348 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
4349 Set_Has_Delayed_Freeze
(New_Ent
);
4351 end Conditional_Delay
;
4353 ----------------------------
4354 -- Contains_Refined_State --
4355 ----------------------------
4357 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
4358 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
4359 -- Determine whether a dependency list mentions a state with a visible
4362 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
4363 -- Determine whether a global list mentions a state with a visible
4366 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
4367 -- Determine whether Item is a reference to an abstract state with a
4368 -- visible refinement.
4370 -----------------------------
4371 -- Has_State_In_Dependency --
4372 -----------------------------
4374 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
4379 -- A null dependency list does not mention any states
4381 if Nkind
(List
) = N_Null
then
4384 -- Dependency clauses appear as component associations of an
4387 elsif Nkind
(List
) = N_Aggregate
4388 and then Present
(Component_Associations
(List
))
4390 Clause
:= First
(Component_Associations
(List
));
4391 while Present
(Clause
) loop
4393 -- Inspect the outputs of a dependency clause
4395 Output
:= First
(Choices
(Clause
));
4396 while Present
(Output
) loop
4397 if Is_Refined_State
(Output
) then
4404 -- Inspect the outputs of a dependency clause
4406 if Is_Refined_State
(Expression
(Clause
)) then
4413 -- If we get here, then none of the dependency clauses mention a
4414 -- state with visible refinement.
4418 -- An illegal pragma managed to sneak in
4421 raise Program_Error
;
4423 end Has_State_In_Dependency
;
4425 -------------------------
4426 -- Has_State_In_Global --
4427 -------------------------
4429 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
4433 -- A null global list does not mention any states
4435 if Nkind
(List
) = N_Null
then
4438 -- Simple global list or moded global list declaration
4440 elsif Nkind
(List
) = N_Aggregate
then
4442 -- The declaration of a simple global list appear as a collection
4445 if Present
(Expressions
(List
)) then
4446 Item
:= First
(Expressions
(List
));
4447 while Present
(Item
) loop
4448 if Is_Refined_State
(Item
) then
4455 -- The declaration of a moded global list appears as a collection
4456 -- of component associations where individual choices denote
4460 Item
:= First
(Component_Associations
(List
));
4461 while Present
(Item
) loop
4462 if Has_State_In_Global
(Expression
(Item
)) then
4470 -- If we get here, then the simple/moded global list did not
4471 -- mention any states with a visible refinement.
4475 -- Single global item declaration
4477 elsif Is_Entity_Name
(List
) then
4478 return Is_Refined_State
(List
);
4480 -- An illegal pragma managed to sneak in
4483 raise Program_Error
;
4485 end Has_State_In_Global
;
4487 ----------------------
4488 -- Is_Refined_State --
4489 ----------------------
4491 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
4493 Item_Id
: Entity_Id
;
4496 if Nkind
(Item
) = N_Null
then
4499 -- States cannot be subject to attribute 'Result. This case arises
4500 -- in dependency relations.
4502 elsif Nkind
(Item
) = N_Attribute_Reference
4503 and then Attribute_Name
(Item
) = Name_Result
4507 -- Multiple items appear as an aggregate. This case arises in
4508 -- dependency relations.
4510 elsif Nkind
(Item
) = N_Aggregate
4511 and then Present
(Expressions
(Item
))
4513 Elmt
:= First
(Expressions
(Item
));
4514 while Present
(Elmt
) loop
4515 if Is_Refined_State
(Elmt
) then
4522 -- If we get here, then none of the inputs or outputs reference a
4523 -- state with visible refinement.
4530 Item_Id
:= Entity_Of
(Item
);
4534 and then Ekind
(Item_Id
) = E_Abstract_State
4535 and then Has_Visible_Refinement
(Item_Id
);
4537 end Is_Refined_State
;
4541 Arg
: constant Node_Id
:=
4542 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
4543 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
4545 -- Start of processing for Contains_Refined_State
4548 if Nam
= Name_Depends
then
4549 return Has_State_In_Dependency
(Arg
);
4551 else pragma Assert
(Nam
= Name_Global
);
4552 return Has_State_In_Global
(Arg
);
4554 end Contains_Refined_State
;
4556 -------------------------
4557 -- Copy_Component_List --
4558 -------------------------
4560 function Copy_Component_List
4562 Loc
: Source_Ptr
) return List_Id
4565 Comps
: constant List_Id
:= New_List
;
4568 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
4569 while Present
(Comp
) loop
4570 if Comes_From_Source
(Comp
) then
4572 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
4575 Make_Component_Declaration
(Loc
,
4576 Defining_Identifier
=>
4577 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
4578 Component_Definition
=>
4580 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
4584 Next_Component
(Comp
);
4588 end Copy_Component_List
;
4590 -------------------------
4591 -- Copy_Parameter_List --
4592 -------------------------
4594 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
4595 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
4600 if No
(First_Formal
(Subp_Id
)) then
4604 Formal
:= First_Formal
(Subp_Id
);
4605 while Present
(Formal
) loop
4607 Make_Parameter_Specification
(Loc
,
4608 Defining_Identifier
=>
4609 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
4610 In_Present
=> In_Present
(Parent
(Formal
)),
4611 Out_Present
=> Out_Present
(Parent
(Formal
)),
4613 New_Occurrence_Of
(Etype
(Formal
), Loc
),
4615 New_Copy_Tree
(Expression
(Parent
(Formal
)))));
4617 Next_Formal
(Formal
);
4622 end Copy_Parameter_List
;
4624 --------------------------
4625 -- Copy_Subprogram_Spec --
4626 --------------------------
4628 function Copy_Subprogram_Spec
(Spec
: Node_Id
) return Node_Id
is
4630 Formal_Spec
: Node_Id
;
4634 -- The structure of the original tree must be replicated without any
4635 -- alterations. Use New_Copy_Tree for this purpose.
4637 Result
:= New_Copy_Tree
(Spec
);
4639 -- Create a new entity for the defining unit name
4641 Def_Id
:= Defining_Unit_Name
(Result
);
4642 Set_Defining_Unit_Name
(Result
,
4643 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
4645 -- Create new entities for the formal parameters
4647 if Present
(Parameter_Specifications
(Result
)) then
4648 Formal_Spec
:= First
(Parameter_Specifications
(Result
));
4649 while Present
(Formal_Spec
) loop
4650 Def_Id
:= Defining_Identifier
(Formal_Spec
);
4651 Set_Defining_Identifier
(Formal_Spec
,
4652 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
4659 end Copy_Subprogram_Spec
;
4661 --------------------------------
4662 -- Corresponding_Generic_Type --
4663 --------------------------------
4665 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
4671 if not Is_Generic_Actual_Type
(T
) then
4674 -- If the actual is the actual of an enclosing instance, resolution
4675 -- was correct in the generic.
4677 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
4678 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
4680 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
4687 if Is_Wrapper_Package
(Inst
) then
4688 Inst
:= Related_Instance
(Inst
);
4693 (Specification
(Unit_Declaration_Node
(Inst
)));
4695 -- Generic actual has the same name as the corresponding formal
4697 Typ
:= First_Entity
(Gen
);
4698 while Present
(Typ
) loop
4699 if Chars
(Typ
) = Chars
(T
) then
4708 end Corresponding_Generic_Type
;
4710 ---------------------------
4711 -- Corresponding_Spec_Of --
4712 ---------------------------
4714 function Corresponding_Spec_Of
(Decl
: Node_Id
) return Entity_Id
is
4716 if Nkind_In
(Decl
, N_Package_Body
, N_Subprogram_Body
)
4717 and then Present
(Corresponding_Spec
(Decl
))
4719 return Corresponding_Spec
(Decl
);
4721 elsif Nkind_In
(Decl
, N_Package_Body_Stub
, N_Subprogram_Body_Stub
)
4722 and then Present
(Corresponding_Spec_Of_Stub
(Decl
))
4724 return Corresponding_Spec_Of_Stub
(Decl
);
4727 return Defining_Entity
(Decl
);
4729 end Corresponding_Spec_Of
;
4731 -----------------------------
4732 -- Create_Generic_Contract --
4733 -----------------------------
4735 procedure Create_Generic_Contract
(Unit
: Node_Id
) is
4736 Templ
: constant Node_Id
:= Original_Node
(Unit
);
4737 Templ_Id
: constant Entity_Id
:= Defining_Entity
(Templ
);
4739 procedure Add_Generic_Contract_Pragma
(Prag
: Node_Id
);
4740 -- Add a single contract-related source pragma Prag to the contract of
4741 -- generic template Templ_Id.
4743 ---------------------------------
4744 -- Add_Generic_Contract_Pragma --
4745 ---------------------------------
4747 procedure Add_Generic_Contract_Pragma
(Prag
: Node_Id
) is
4748 Prag_Templ
: Node_Id
;
4751 -- Mark the pragma to prevent the premature capture of global
4752 -- references when capturing global references of the context
4753 -- (see Save_References_In_Pragma).
4755 Set_Is_Generic_Contract_Pragma
(Prag
);
4757 -- Pragmas that apply to a generic subprogram declaration are not
4758 -- part of the semantic structure of the generic template:
4761 -- procedure Example (Formal : Integer);
4762 -- pragma Precondition (Formal > 0);
4764 -- Create a generic template for such pragmas and link the template
4765 -- of the pragma with the generic template.
4767 if Nkind
(Templ
) = N_Generic_Subprogram_Declaration
then
4769 (Prag
, Copy_Generic_Node
(Prag
, Empty
, Instantiating
=> False));
4770 Prag_Templ
:= Original_Node
(Prag
);
4772 Set_Is_Generic_Contract_Pragma
(Prag_Templ
);
4773 Add_Contract_Item
(Prag_Templ
, Templ_Id
);
4775 -- Otherwise link the pragma with the generic template
4778 Add_Contract_Item
(Prag
, Templ_Id
);
4780 end Add_Generic_Contract_Pragma
;
4784 Context
: constant Node_Id
:= Parent
(Unit
);
4785 Decl
: Node_Id
:= Empty
;
4787 -- Start of processing for Create_Generic_Contract
4790 -- A generic package declaration carries contract-related source pragmas
4791 -- in its visible declarations.
4793 if Nkind
(Templ
) = N_Generic_Package_Declaration
then
4794 Set_Ekind
(Templ_Id
, E_Generic_Package
);
4796 if Present
(Visible_Declarations
(Specification
(Templ
))) then
4797 Decl
:= First
(Visible_Declarations
(Specification
(Templ
)));
4800 -- A generic package body carries contract-related source pragmas in its
4803 elsif Nkind
(Templ
) = N_Package_Body
then
4804 Set_Ekind
(Templ_Id
, E_Package_Body
);
4806 if Present
(Declarations
(Templ
)) then
4807 Decl
:= First
(Declarations
(Templ
));
4810 -- Generic subprogram declaration
4812 elsif Nkind
(Templ
) = N_Generic_Subprogram_Declaration
then
4813 if Nkind
(Specification
(Templ
)) = N_Function_Specification
then
4814 Set_Ekind
(Templ_Id
, E_Generic_Function
);
4816 Set_Ekind
(Templ_Id
, E_Generic_Procedure
);
4819 -- When the generic subprogram acts as a compilation unit, inspect
4820 -- the Pragmas_After list for contract-related source pragmas.
4822 if Nkind
(Context
) = N_Compilation_Unit
then
4823 if Present
(Aux_Decls_Node
(Context
))
4824 and then Present
(Pragmas_After
(Aux_Decls_Node
(Context
)))
4826 Decl
:= First
(Pragmas_After
(Aux_Decls_Node
(Context
)));
4829 -- Otherwise inspect the successive declarations for contract-related
4833 Decl
:= Next
(Unit
);
4836 -- A generic subprogram body carries contract-related source pragmas in
4837 -- its declarations.
4839 elsif Nkind
(Templ
) = N_Subprogram_Body
then
4840 Set_Ekind
(Templ_Id
, E_Subprogram_Body
);
4842 if Present
(Declarations
(Templ
)) then
4843 Decl
:= First
(Declarations
(Templ
));
4847 -- Inspect the relevant declarations looking for contract-related source
4848 -- pragmas and add them to the contract of the generic unit.
4850 while Present
(Decl
) loop
4851 if Comes_From_Source
(Decl
) then
4852 if Nkind
(Decl
) = N_Pragma
then
4854 -- The source pragma is a contract annotation
4856 if Is_Contract_Annotation
(Decl
) then
4857 Add_Generic_Contract_Pragma
(Decl
);
4860 -- The region where a contract-related source pragma may appear
4861 -- ends with the first source non-pragma declaration or statement.
4870 end Create_Generic_Contract
;
4872 --------------------
4873 -- Current_Entity --
4874 --------------------
4876 -- The currently visible definition for a given identifier is the
4877 -- one most chained at the start of the visibility chain, i.e. the
4878 -- one that is referenced by the Node_Id value of the name of the
4879 -- given identifier.
4881 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
4883 return Get_Name_Entity_Id
(Chars
(N
));
4886 -----------------------------
4887 -- Current_Entity_In_Scope --
4888 -----------------------------
4890 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
4892 CS
: constant Entity_Id
:= Current_Scope
;
4894 Transient_Case
: constant Boolean := Scope_Is_Transient
;
4897 E
:= Get_Name_Entity_Id
(Chars
(N
));
4899 and then Scope
(E
) /= CS
4900 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
4906 end Current_Entity_In_Scope
;
4912 function Current_Scope
return Entity_Id
is
4914 if Scope_Stack
.Last
= -1 then
4915 return Standard_Standard
;
4918 C
: constant Entity_Id
:=
4919 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
4924 return Standard_Standard
;
4930 ------------------------
4931 -- Current_Subprogram --
4932 ------------------------
4934 function Current_Subprogram
return Entity_Id
is
4935 Scop
: constant Entity_Id
:= Current_Scope
;
4937 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
4940 return Enclosing_Subprogram
(Scop
);
4942 end Current_Subprogram
;
4944 ----------------------------------
4945 -- Deepest_Type_Access_Level --
4946 ----------------------------------
4948 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
4950 if Ekind
(Typ
) = E_Anonymous_Access_Type
4951 and then not Is_Local_Anonymous_Access
(Typ
)
4952 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
4954 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
4958 Scope_Depth
(Enclosing_Dynamic_Scope
4959 (Defining_Identifier
4960 (Associated_Node_For_Itype
(Typ
))));
4962 -- For generic formal type, return Int'Last (infinite).
4963 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
4965 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
4966 return UI_From_Int
(Int
'Last);
4969 return Type_Access_Level
(Typ
);
4971 end Deepest_Type_Access_Level
;
4973 ---------------------
4974 -- Defining_Entity --
4975 ---------------------
4977 function Defining_Entity
(N
: Node_Id
) return Entity_Id
is
4978 K
: constant Node_Kind
:= Nkind
(N
);
4979 Err
: Entity_Id
:= Empty
;
4984 N_Subprogram_Declaration |
4985 N_Abstract_Subprogram_Declaration |
4987 N_Package_Declaration |
4988 N_Subprogram_Renaming_Declaration |
4989 N_Subprogram_Body_Stub |
4990 N_Generic_Subprogram_Declaration |
4991 N_Generic_Package_Declaration |
4992 N_Formal_Subprogram_Declaration |
4993 N_Expression_Function
4995 return Defining_Entity
(Specification
(N
));
4998 N_Component_Declaration |
4999 N_Defining_Program_Unit_Name |
5000 N_Discriminant_Specification |
5002 N_Entry_Declaration |
5003 N_Entry_Index_Specification |
5004 N_Exception_Declaration |
5005 N_Exception_Renaming_Declaration |
5006 N_Formal_Object_Declaration |
5007 N_Formal_Package_Declaration |
5008 N_Formal_Type_Declaration |
5009 N_Full_Type_Declaration |
5010 N_Implicit_Label_Declaration |
5011 N_Incomplete_Type_Declaration |
5012 N_Loop_Parameter_Specification |
5013 N_Number_Declaration |
5014 N_Object_Declaration |
5015 N_Object_Renaming_Declaration |
5016 N_Package_Body_Stub |
5017 N_Parameter_Specification |
5018 N_Private_Extension_Declaration |
5019 N_Private_Type_Declaration |
5021 N_Protected_Body_Stub |
5022 N_Protected_Type_Declaration |
5023 N_Single_Protected_Declaration |
5024 N_Single_Task_Declaration |
5025 N_Subtype_Declaration |
5028 N_Task_Type_Declaration
5030 return Defining_Identifier
(N
);
5033 return Defining_Entity
(Proper_Body
(N
));
5036 N_Function_Instantiation |
5037 N_Function_Specification |
5038 N_Generic_Function_Renaming_Declaration |
5039 N_Generic_Package_Renaming_Declaration |
5040 N_Generic_Procedure_Renaming_Declaration |
5042 N_Package_Instantiation |
5043 N_Package_Renaming_Declaration |
5044 N_Package_Specification |
5045 N_Procedure_Instantiation |
5046 N_Procedure_Specification
5049 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
5052 if Nkind
(Nam
) in N_Entity
then
5055 -- For Error, make up a name and attach to declaration
5056 -- so we can continue semantic analysis
5058 elsif Nam
= Error
then
5059 Err
:= Make_Temporary
(Sloc
(N
), 'T');
5060 Set_Defining_Unit_Name
(N
, Err
);
5064 -- If not an entity, get defining identifier
5067 return Defining_Identifier
(Nam
);
5075 return Entity
(Identifier
(N
));
5078 raise Program_Error
;
5081 end Defining_Entity
;
5083 --------------------------
5084 -- Denotes_Discriminant --
5085 --------------------------
5087 function Denotes_Discriminant
5089 Check_Concurrent
: Boolean := False) return Boolean
5094 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
5100 -- If we are checking for a protected type, the discriminant may have
5101 -- been rewritten as the corresponding discriminal of the original type
5102 -- or of the corresponding concurrent record, depending on whether we
5103 -- are in the spec or body of the protected type.
5105 return Ekind
(E
) = E_Discriminant
5108 and then Ekind
(E
) = E_In_Parameter
5109 and then Present
(Discriminal_Link
(E
))
5111 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
5113 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
5115 end Denotes_Discriminant
;
5117 -------------------------
5118 -- Denotes_Same_Object --
5119 -------------------------
5121 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
5122 Obj1
: Node_Id
:= A1
;
5123 Obj2
: Node_Id
:= A2
;
5125 function Has_Prefix
(N
: Node_Id
) return Boolean;
5126 -- Return True if N has attribute Prefix
5128 function Is_Renaming
(N
: Node_Id
) return Boolean;
5129 -- Return true if N names a renaming entity
5131 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
5132 -- For renamings, return False if the prefix of any dereference within
5133 -- the renamed object_name is a variable, or any expression within the
5134 -- renamed object_name contains references to variables or calls on
5135 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5141 function Has_Prefix
(N
: Node_Id
) return Boolean is
5145 N_Attribute_Reference
,
5147 N_Explicit_Dereference
,
5148 N_Indexed_Component
,
5150 N_Selected_Component
,
5158 function Is_Renaming
(N
: Node_Id
) return Boolean is
5160 return Is_Entity_Name
(N
)
5161 and then Present
(Renamed_Entity
(Entity
(N
)));
5164 -----------------------
5165 -- Is_Valid_Renaming --
5166 -----------------------
5168 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
5170 function Check_Renaming
(N
: Node_Id
) return Boolean;
5171 -- Recursive function used to traverse all the prefixes of N
5173 function Check_Renaming
(N
: Node_Id
) return Boolean is
5176 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
5181 if Nkind
(N
) = N_Indexed_Component
then
5186 Indx
:= First
(Expressions
(N
));
5187 while Present
(Indx
) loop
5188 if not Is_OK_Static_Expression
(Indx
) then
5197 if Has_Prefix
(N
) then
5199 P
: constant Node_Id
:= Prefix
(N
);
5202 if Nkind
(N
) = N_Explicit_Dereference
5203 and then Is_Variable
(P
)
5207 elsif Is_Entity_Name
(P
)
5208 and then Ekind
(Entity
(P
)) = E_Function
5212 elsif Nkind
(P
) = N_Function_Call
then
5216 -- Recursion to continue traversing the prefix of the
5217 -- renaming expression
5219 return Check_Renaming
(P
);
5226 -- Start of processing for Is_Valid_Renaming
5229 return Check_Renaming
(N
);
5230 end Is_Valid_Renaming
;
5232 -- Start of processing for Denotes_Same_Object
5235 -- Both names statically denote the same stand-alone object or parameter
5236 -- (RM 6.4.1(6.5/3))
5238 if Is_Entity_Name
(Obj1
)
5239 and then Is_Entity_Name
(Obj2
)
5240 and then Entity
(Obj1
) = Entity
(Obj2
)
5245 -- For renamings, the prefix of any dereference within the renamed
5246 -- object_name is not a variable, and any expression within the
5247 -- renamed object_name contains no references to variables nor
5248 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5250 if Is_Renaming
(Obj1
) then
5251 if Is_Valid_Renaming
(Obj1
) then
5252 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
5258 if Is_Renaming
(Obj2
) then
5259 if Is_Valid_Renaming
(Obj2
) then
5260 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
5266 -- No match if not same node kind (such cases are handled by
5267 -- Denotes_Same_Prefix)
5269 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
5272 -- After handling valid renamings, one of the two names statically
5273 -- denoted a renaming declaration whose renamed object_name is known
5274 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5276 elsif Is_Entity_Name
(Obj1
) then
5277 if Is_Entity_Name
(Obj2
) then
5278 return Entity
(Obj1
) = Entity
(Obj2
);
5283 -- Both names are selected_components, their prefixes are known to
5284 -- denote the same object, and their selector_names denote the same
5285 -- component (RM 6.4.1(6.6/3)).
5287 elsif Nkind
(Obj1
) = N_Selected_Component
then
5288 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
5290 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
5292 -- Both names are dereferences and the dereferenced names are known to
5293 -- denote the same object (RM 6.4.1(6.7/3))
5295 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
5296 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
5298 -- Both names are indexed_components, their prefixes are known to denote
5299 -- the same object, and each of the pairs of corresponding index values
5300 -- are either both static expressions with the same static value or both
5301 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5303 elsif Nkind
(Obj1
) = N_Indexed_Component
then
5304 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
5312 Indx1
:= First
(Expressions
(Obj1
));
5313 Indx2
:= First
(Expressions
(Obj2
));
5314 while Present
(Indx1
) loop
5316 -- Indexes must denote the same static value or same object
5318 if Is_OK_Static_Expression
(Indx1
) then
5319 if not Is_OK_Static_Expression
(Indx2
) then
5322 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
5326 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
5338 -- Both names are slices, their prefixes are known to denote the same
5339 -- object, and the two slices have statically matching index constraints
5340 -- (RM 6.4.1(6.9/3))
5342 elsif Nkind
(Obj1
) = N_Slice
5343 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
5346 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
5349 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
5350 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
5352 -- Check whether bounds are statically identical. There is no
5353 -- attempt to detect partial overlap of slices.
5355 return Denotes_Same_Object
(Lo1
, Lo2
)
5357 Denotes_Same_Object
(Hi1
, Hi2
);
5360 -- In the recursion, literals appear as indexes
5362 elsif Nkind
(Obj1
) = N_Integer_Literal
5364 Nkind
(Obj2
) = N_Integer_Literal
5366 return Intval
(Obj1
) = Intval
(Obj2
);
5371 end Denotes_Same_Object
;
5373 -------------------------
5374 -- Denotes_Same_Prefix --
5375 -------------------------
5377 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
5380 if Is_Entity_Name
(A1
) then
5381 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
5382 and then not Is_Access_Type
(Etype
(A1
))
5384 return Denotes_Same_Object
(A1
, Prefix
(A2
))
5385 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
5390 elsif Is_Entity_Name
(A2
) then
5391 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
5393 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5395 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5398 Root1
, Root2
: Node_Id
;
5399 Depth1
, Depth2
: Int
:= 0;
5402 Root1
:= Prefix
(A1
);
5403 while not Is_Entity_Name
(Root1
) loop
5405 (Root1
, N_Selected_Component
, N_Indexed_Component
)
5409 Root1
:= Prefix
(Root1
);
5412 Depth1
:= Depth1
+ 1;
5415 Root2
:= Prefix
(A2
);
5416 while not Is_Entity_Name
(Root2
) loop
5417 if not Nkind_In
(Root2
, N_Selected_Component
,
5418 N_Indexed_Component
)
5422 Root2
:= Prefix
(Root2
);
5425 Depth2
:= Depth2
+ 1;
5428 -- If both have the same depth and they do not denote the same
5429 -- object, they are disjoint and no warning is needed.
5431 if Depth1
= Depth2
then
5434 elsif Depth1
> Depth2
then
5435 Root1
:= Prefix
(A1
);
5436 for J
in 1 .. Depth1
- Depth2
- 1 loop
5437 Root1
:= Prefix
(Root1
);
5440 return Denotes_Same_Object
(Root1
, A2
);
5443 Root2
:= Prefix
(A2
);
5444 for J
in 1 .. Depth2
- Depth1
- 1 loop
5445 Root2
:= Prefix
(Root2
);
5448 return Denotes_Same_Object
(A1
, Root2
);
5455 end Denotes_Same_Prefix
;
5457 ----------------------
5458 -- Denotes_Variable --
5459 ----------------------
5461 function Denotes_Variable
(N
: Node_Id
) return Boolean is
5463 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
5464 end Denotes_Variable
;
5466 -----------------------------
5467 -- Depends_On_Discriminant --
5468 -----------------------------
5470 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
5475 Get_Index_Bounds
(N
, L
, H
);
5476 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
5477 end Depends_On_Discriminant
;
5479 -------------------------
5480 -- Designate_Same_Unit --
5481 -------------------------
5483 function Designate_Same_Unit
5485 Name2
: Node_Id
) return Boolean
5487 K1
: constant Node_Kind
:= Nkind
(Name1
);
5488 K2
: constant Node_Kind
:= Nkind
(Name2
);
5490 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
5491 -- Returns the parent unit name node of a defining program unit name
5492 -- or the prefix if N is a selected component or an expanded name.
5494 function Select_Node
(N
: Node_Id
) return Node_Id
;
5495 -- Returns the defining identifier node of a defining program unit
5496 -- name or the selector node if N is a selected component or an
5503 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
5505 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
5516 function Select_Node
(N
: Node_Id
) return Node_Id
is
5518 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
5519 return Defining_Identifier
(N
);
5521 return Selector_Name
(N
);
5525 -- Start of processing for Designate_Same_Unit
5528 if Nkind_In
(K1
, N_Identifier
, N_Defining_Identifier
)
5530 Nkind_In
(K2
, N_Identifier
, N_Defining_Identifier
)
5532 return Chars
(Name1
) = Chars
(Name2
);
5534 elsif Nkind_In
(K1
, N_Expanded_Name
,
5535 N_Selected_Component
,
5536 N_Defining_Program_Unit_Name
)
5538 Nkind_In
(K2
, N_Expanded_Name
,
5539 N_Selected_Component
,
5540 N_Defining_Program_Unit_Name
)
5543 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
5545 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
5550 end Designate_Same_Unit
;
5552 ------------------------------------------
5553 -- function Dynamic_Accessibility_Level --
5554 ------------------------------------------
5556 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
5558 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
5560 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
5561 -- Construct an integer literal representing an accessibility level
5562 -- with its type set to Natural.
5564 ------------------------
5565 -- Make_Level_Literal --
5566 ------------------------
5568 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
5569 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
5571 Set_Etype
(Result
, Standard_Natural
);
5573 end Make_Level_Literal
;
5575 -- Start of processing for Dynamic_Accessibility_Level
5578 if Is_Entity_Name
(Expr
) then
5581 if Present
(Renamed_Object
(E
)) then
5582 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
5585 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
5586 if Present
(Extra_Accessibility
(E
)) then
5587 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
5592 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
5594 case Nkind
(Expr
) is
5596 -- For access discriminant, the level of the enclosing object
5598 when N_Selected_Component
=>
5599 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
5600 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
5601 E_Anonymous_Access_Type
5603 return Make_Level_Literal
(Object_Access_Level
(Expr
));
5606 when N_Attribute_Reference
=>
5607 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
5609 -- For X'Access, the level of the prefix X
5611 when Attribute_Access
=>
5612 return Make_Level_Literal
5613 (Object_Access_Level
(Prefix
(Expr
)));
5615 -- Treat the unchecked attributes as library-level
5617 when Attribute_Unchecked_Access |
5618 Attribute_Unrestricted_Access
=>
5619 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
5621 -- No other access-valued attributes
5624 raise Program_Error
;
5629 -- Unimplemented: depends on context. As an actual parameter where
5630 -- formal type is anonymous, use
5631 -- Scope_Depth (Current_Scope) + 1.
5632 -- For other cases, see 3.10.2(14/3) and following. ???
5636 when N_Type_Conversion
=>
5637 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
5639 -- Handle type conversions introduced for a rename of an
5640 -- Ada 2012 stand-alone object of an anonymous access type.
5642 return Dynamic_Accessibility_Level
(Expression
(Expr
));
5649 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
5650 end Dynamic_Accessibility_Level
;
5652 -----------------------------------
5653 -- Effective_Extra_Accessibility --
5654 -----------------------------------
5656 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
5658 if Present
(Renamed_Object
(Id
))
5659 and then Is_Entity_Name
(Renamed_Object
(Id
))
5661 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
5663 return Extra_Accessibility
(Id
);
5665 end Effective_Extra_Accessibility
;
5667 -----------------------------
5668 -- Effective_Reads_Enabled --
5669 -----------------------------
5671 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
5673 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
5674 end Effective_Reads_Enabled
;
5676 ------------------------------
5677 -- Effective_Writes_Enabled --
5678 ------------------------------
5680 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
5682 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
5683 end Effective_Writes_Enabled
;
5685 ------------------------------
5686 -- Enclosing_Comp_Unit_Node --
5687 ------------------------------
5689 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
5690 Current_Node
: Node_Id
;
5694 while Present
(Current_Node
)
5695 and then Nkind
(Current_Node
) /= N_Compilation_Unit
5697 Current_Node
:= Parent
(Current_Node
);
5700 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
5703 return Current_Node
;
5705 end Enclosing_Comp_Unit_Node
;
5707 --------------------------
5708 -- Enclosing_CPP_Parent --
5709 --------------------------
5711 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
5712 Parent_Typ
: Entity_Id
:= Typ
;
5715 while not Is_CPP_Class
(Parent_Typ
)
5716 and then Etype
(Parent_Typ
) /= Parent_Typ
5718 Parent_Typ
:= Etype
(Parent_Typ
);
5720 if Is_Private_Type
(Parent_Typ
) then
5721 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
5725 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
5727 end Enclosing_CPP_Parent
;
5729 ---------------------------
5730 -- Enclosing_Declaration --
5731 ---------------------------
5733 function Enclosing_Declaration
(N
: Node_Id
) return Node_Id
is
5734 Decl
: Node_Id
:= N
;
5737 while Present
(Decl
)
5738 and then not (Nkind
(Decl
) in N_Declaration
5740 Nkind
(Decl
) in N_Later_Decl_Item
)
5742 Decl
:= Parent
(Decl
);
5746 end Enclosing_Declaration
;
5748 ----------------------------
5749 -- Enclosing_Generic_Body --
5750 ----------------------------
5752 function Enclosing_Generic_Body
5753 (N
: Node_Id
) return Node_Id
5761 while Present
(P
) loop
5762 if Nkind
(P
) = N_Package_Body
5763 or else Nkind
(P
) = N_Subprogram_Body
5765 Spec
:= Corresponding_Spec
(P
);
5767 if Present
(Spec
) then
5768 Decl
:= Unit_Declaration_Node
(Spec
);
5770 if Nkind
(Decl
) = N_Generic_Package_Declaration
5771 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5782 end Enclosing_Generic_Body
;
5784 ----------------------------
5785 -- Enclosing_Generic_Unit --
5786 ----------------------------
5788 function Enclosing_Generic_Unit
5789 (N
: Node_Id
) return Node_Id
5797 while Present
(P
) loop
5798 if Nkind
(P
) = N_Generic_Package_Declaration
5799 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
5803 elsif Nkind
(P
) = N_Package_Body
5804 or else Nkind
(P
) = N_Subprogram_Body
5806 Spec
:= Corresponding_Spec
(P
);
5808 if Present
(Spec
) then
5809 Decl
:= Unit_Declaration_Node
(Spec
);
5811 if Nkind
(Decl
) = N_Generic_Package_Declaration
5812 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
5823 end Enclosing_Generic_Unit
;
5825 -------------------------------
5826 -- Enclosing_Lib_Unit_Entity --
5827 -------------------------------
5829 function Enclosing_Lib_Unit_Entity
5830 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
5832 Unit_Entity
: Entity_Id
;
5835 -- Look for enclosing library unit entity by following scope links.
5836 -- Equivalent to, but faster than indexing through the scope stack.
5839 while (Present
(Scope
(Unit_Entity
))
5840 and then Scope
(Unit_Entity
) /= Standard_Standard
)
5841 and not Is_Child_Unit
(Unit_Entity
)
5843 Unit_Entity
:= Scope
(Unit_Entity
);
5847 end Enclosing_Lib_Unit_Entity
;
5849 -----------------------------
5850 -- Enclosing_Lib_Unit_Node --
5851 -----------------------------
5853 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
5854 Encl_Unit
: Node_Id
;
5857 Encl_Unit
:= Enclosing_Comp_Unit_Node
(N
);
5858 while Present
(Encl_Unit
)
5859 and then Nkind
(Unit
(Encl_Unit
)) = N_Subunit
5861 Encl_Unit
:= Library_Unit
(Encl_Unit
);
5865 end Enclosing_Lib_Unit_Node
;
5867 -----------------------
5868 -- Enclosing_Package --
5869 -----------------------
5871 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
5872 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5875 if Dynamic_Scope
= Standard_Standard
then
5876 return Standard_Standard
;
5878 elsif Dynamic_Scope
= Empty
then
5881 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
5884 return Dynamic_Scope
;
5887 return Enclosing_Package
(Dynamic_Scope
);
5889 end Enclosing_Package
;
5891 -------------------------------------
5892 -- Enclosing_Package_Or_Subprogram --
5893 -------------------------------------
5895 function Enclosing_Package_Or_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5900 while Present
(S
) loop
5901 if Is_Package_Or_Generic_Package
(S
)
5902 or else Ekind
(S
) = E_Package_Body
5906 elsif Is_Subprogram_Or_Generic_Subprogram
(S
)
5907 or else Ekind
(S
) = E_Subprogram_Body
5917 end Enclosing_Package_Or_Subprogram
;
5919 --------------------------
5920 -- Enclosing_Subprogram --
5921 --------------------------
5923 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
5924 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
5927 if Dynamic_Scope
= Standard_Standard
then
5930 elsif Dynamic_Scope
= Empty
then
5933 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
5934 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
5936 elsif Ekind
(Dynamic_Scope
) = E_Block
5937 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
5939 return Enclosing_Subprogram
(Dynamic_Scope
);
5941 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
5942 return Get_Task_Body_Procedure
(Dynamic_Scope
);
5944 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
5945 and then Present
(Full_View
(Dynamic_Scope
))
5946 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
5948 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
5950 -- No body is generated if the protected operation is eliminated
5952 elsif Convention
(Dynamic_Scope
) = Convention_Protected
5953 and then not Is_Eliminated
(Dynamic_Scope
)
5954 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
5956 return Protected_Body_Subprogram
(Dynamic_Scope
);
5959 return Dynamic_Scope
;
5961 end Enclosing_Subprogram
;
5963 ------------------------
5964 -- Ensure_Freeze_Node --
5965 ------------------------
5967 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
5970 if No
(Freeze_Node
(E
)) then
5971 FN
:= Make_Freeze_Entity
(Sloc
(E
));
5972 Set_Has_Delayed_Freeze
(E
);
5973 Set_Freeze_Node
(E
, FN
);
5974 Set_Access_Types_To_Process
(FN
, No_Elist
);
5975 Set_TSS_Elist
(FN
, No_Elist
);
5978 end Ensure_Freeze_Node
;
5984 procedure Enter_Name
(Def_Id
: Entity_Id
) is
5985 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
5986 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
5987 S
: constant Entity_Id
:= Current_Scope
;
5990 Generate_Definition
(Def_Id
);
5992 -- Add new name to current scope declarations. Check for duplicate
5993 -- declaration, which may or may not be a genuine error.
5997 -- Case of previous entity entered because of a missing declaration
5998 -- or else a bad subtype indication. Best is to use the new entity,
5999 -- and make the previous one invisible.
6001 if Etype
(E
) = Any_Type
then
6002 Set_Is_Immediately_Visible
(E
, False);
6004 -- Case of renaming declaration constructed for package instances.
6005 -- if there is an explicit declaration with the same identifier,
6006 -- the renaming is not immediately visible any longer, but remains
6007 -- visible through selected component notation.
6009 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
6010 and then not Comes_From_Source
(E
)
6012 Set_Is_Immediately_Visible
(E
, False);
6014 -- The new entity may be the package renaming, which has the same
6015 -- same name as a generic formal which has been seen already.
6017 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
6018 and then not Comes_From_Source
(Def_Id
)
6020 Set_Is_Immediately_Visible
(E
, False);
6022 -- For a fat pointer corresponding to a remote access to subprogram,
6023 -- we use the same identifier as the RAS type, so that the proper
6024 -- name appears in the stub. This type is only retrieved through
6025 -- the RAS type and never by visibility, and is not added to the
6026 -- visibility list (see below).
6028 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
6029 and then Ekind
(Def_Id
) = E_Record_Type
6030 and then Present
(Corresponding_Remote_Type
(Def_Id
))
6034 -- Case of an implicit operation or derived literal. The new entity
6035 -- hides the implicit one, which is removed from all visibility,
6036 -- i.e. the entity list of its scope, and homonym chain of its name.
6038 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
6039 or else Is_Internal
(E
)
6043 Prev_Vis
: Entity_Id
;
6044 Decl
: constant Node_Id
:= Parent
(E
);
6047 -- If E is an implicit declaration, it cannot be the first
6048 -- entity in the scope.
6050 Prev
:= First_Entity
(Current_Scope
);
6051 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
6057 -- If E is not on the entity chain of the current scope,
6058 -- it is an implicit declaration in the generic formal
6059 -- part of a generic subprogram. When analyzing the body,
6060 -- the generic formals are visible but not on the entity
6061 -- chain of the subprogram. The new entity will become
6062 -- the visible one in the body.
6065 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
6069 Set_Next_Entity
(Prev
, Next_Entity
(E
));
6071 if No
(Next_Entity
(Prev
)) then
6072 Set_Last_Entity
(Current_Scope
, Prev
);
6075 if E
= Current_Entity
(E
) then
6079 Prev_Vis
:= Current_Entity
(E
);
6080 while Homonym
(Prev_Vis
) /= E
loop
6081 Prev_Vis
:= Homonym
(Prev_Vis
);
6085 if Present
(Prev_Vis
) then
6087 -- Skip E in the visibility chain
6089 Set_Homonym
(Prev_Vis
, Homonym
(E
));
6092 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6097 -- This section of code could use a comment ???
6099 elsif Present
(Etype
(E
))
6100 and then Is_Concurrent_Type
(Etype
(E
))
6105 -- If the homograph is a protected component renaming, it should not
6106 -- be hiding the current entity. Such renamings are treated as weak
6109 elsif Is_Prival
(E
) then
6110 Set_Is_Immediately_Visible
(E
, False);
6112 -- In this case the current entity is a protected component renaming.
6113 -- Perform minimal decoration by setting the scope and return since
6114 -- the prival should not be hiding other visible entities.
6116 elsif Is_Prival
(Def_Id
) then
6117 Set_Scope
(Def_Id
, Current_Scope
);
6120 -- Analogous to privals, the discriminal generated for an entry index
6121 -- parameter acts as a weak declaration. Perform minimal decoration
6122 -- to avoid bogus errors.
6124 elsif Is_Discriminal
(Def_Id
)
6125 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
6127 Set_Scope
(Def_Id
, Current_Scope
);
6130 -- In the body or private part of an instance, a type extension may
6131 -- introduce a component with the same name as that of an actual. The
6132 -- legality rule is not enforced, but the semantics of the full type
6133 -- with two components of same name are not clear at this point???
6135 elsif In_Instance_Not_Visible
then
6138 -- When compiling a package body, some child units may have become
6139 -- visible. They cannot conflict with local entities that hide them.
6141 elsif Is_Child_Unit
(E
)
6142 and then In_Open_Scopes
(Scope
(E
))
6143 and then not Is_Immediately_Visible
(E
)
6147 -- Conversely, with front-end inlining we may compile the parent body
6148 -- first, and a child unit subsequently. The context is now the
6149 -- parent spec, and body entities are not visible.
6151 elsif Is_Child_Unit
(Def_Id
)
6152 and then Is_Package_Body_Entity
(E
)
6153 and then not In_Package_Body
(Current_Scope
)
6157 -- Case of genuine duplicate declaration
6160 Error_Msg_Sloc
:= Sloc
(E
);
6162 -- If the previous declaration is an incomplete type declaration
6163 -- this may be an attempt to complete it with a private type. The
6164 -- following avoids confusing cascaded errors.
6166 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
6167 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
6170 ("incomplete type cannot be completed with a private " &
6171 "declaration", Parent
(Def_Id
));
6172 Set_Is_Immediately_Visible
(E
, False);
6173 Set_Full_View
(E
, Def_Id
);
6175 -- An inherited component of a record conflicts with a new
6176 -- discriminant. The discriminant is inserted first in the scope,
6177 -- but the error should be posted on it, not on the component.
6179 elsif Ekind
(E
) = E_Discriminant
6180 and then Present
(Scope
(Def_Id
))
6181 and then Scope
(Def_Id
) /= Current_Scope
6183 Error_Msg_Sloc
:= Sloc
(Def_Id
);
6184 Error_Msg_N
("& conflicts with declaration#", E
);
6187 -- If the name of the unit appears in its own context clause, a
6188 -- dummy package with the name has already been created, and the
6189 -- error emitted. Try to continue quietly.
6191 elsif Error_Posted
(E
)
6192 and then Sloc
(E
) = No_Location
6193 and then Nkind
(Parent
(E
)) = N_Package_Specification
6194 and then Current_Scope
= Standard_Standard
6196 Set_Scope
(Def_Id
, Current_Scope
);
6200 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
6202 -- Avoid cascaded messages with duplicate components in
6205 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
6210 if Nkind
(Parent
(Parent
(Def_Id
))) =
6211 N_Generic_Subprogram_Declaration
6213 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
6215 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
6218 -- If entity is in standard, then we are in trouble, because it
6219 -- means that we have a library package with a duplicated name.
6220 -- That's hard to recover from, so abort.
6222 if S
= Standard_Standard
then
6223 raise Unrecoverable_Error
;
6225 -- Otherwise we continue with the declaration. Having two
6226 -- identical declarations should not cause us too much trouble.
6234 -- If we fall through, declaration is OK, at least OK enough to continue
6236 -- If Def_Id is a discriminant or a record component we are in the midst
6237 -- of inheriting components in a derived record definition. Preserve
6238 -- their Ekind and Etype.
6240 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
6243 -- If a type is already set, leave it alone (happens when a type
6244 -- declaration is reanalyzed following a call to the optimizer).
6246 elsif Present
(Etype
(Def_Id
)) then
6249 -- Otherwise, the kind E_Void insures that premature uses of the entity
6250 -- will be detected. Any_Type insures that no cascaded errors will occur
6253 Set_Ekind
(Def_Id
, E_Void
);
6254 Set_Etype
(Def_Id
, Any_Type
);
6257 -- Inherited discriminants and components in derived record types are
6258 -- immediately visible. Itypes are not.
6260 -- Unless the Itype is for a record type with a corresponding remote
6261 -- type (what is that about, it was not commented ???)
6263 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
6265 ((not Is_Record_Type
(Def_Id
)
6266 or else No
(Corresponding_Remote_Type
(Def_Id
)))
6267 and then not Is_Itype
(Def_Id
))
6269 Set_Is_Immediately_Visible
(Def_Id
);
6270 Set_Current_Entity
(Def_Id
);
6273 Set_Homonym
(Def_Id
, C
);
6274 Append_Entity
(Def_Id
, S
);
6275 Set_Public_Status
(Def_Id
);
6277 -- Declaring a homonym is not allowed in SPARK ...
6279 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
6281 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
6282 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
6283 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
6286 -- ... unless the new declaration is in a subprogram, and the
6287 -- visible declaration is a variable declaration or a parameter
6288 -- specification outside that subprogram.
6290 if Present
(Enclosing_Subp
)
6291 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
6292 N_Parameter_Specification
)
6293 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
6297 -- ... or the new declaration is in a package, and the visible
6298 -- declaration occurs outside that package.
6300 elsif Present
(Enclosing_Pack
)
6301 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
6305 -- ... or the new declaration is a component declaration in a
6306 -- record type definition.
6308 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
6311 -- Don't issue error for non-source entities
6313 elsif Comes_From_Source
(Def_Id
)
6314 and then Comes_From_Source
(C
)
6316 Error_Msg_Sloc
:= Sloc
(C
);
6317 Check_SPARK_05_Restriction
6318 ("redeclaration of identifier &#", Def_Id
);
6323 -- Warn if new entity hides an old one
6325 if Warn_On_Hiding
and then Present
(C
)
6327 -- Don't warn for record components since they always have a well
6328 -- defined scope which does not confuse other uses. Note that in
6329 -- some cases, Ekind has not been set yet.
6331 and then Ekind
(C
) /= E_Component
6332 and then Ekind
(C
) /= E_Discriminant
6333 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
6334 and then Ekind
(Def_Id
) /= E_Component
6335 and then Ekind
(Def_Id
) /= E_Discriminant
6336 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
6338 -- Don't warn for one character variables. It is too common to use
6339 -- such variables as locals and will just cause too many false hits.
6341 and then Length_Of_Name
(Chars
(C
)) /= 1
6343 -- Don't warn for non-source entities
6345 and then Comes_From_Source
(C
)
6346 and then Comes_From_Source
(Def_Id
)
6348 -- Don't warn unless entity in question is in extended main source
6350 and then In_Extended_Main_Source_Unit
(Def_Id
)
6352 -- Finally, the hidden entity must be either immediately visible or
6353 -- use visible (i.e. from a used package).
6356 (Is_Immediately_Visible
(C
)
6358 Is_Potentially_Use_Visible
(C
))
6360 Error_Msg_Sloc
:= Sloc
(C
);
6361 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
6369 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
6375 if Is_Entity_Name
(N
) then
6378 -- Follow a possible chain of renamings to reach the root renamed
6381 while Present
(Id
) and then Present
(Renamed_Object
(Id
)) loop
6382 if Is_Entity_Name
(Renamed_Object
(Id
)) then
6383 Id
:= Entity
(Renamed_Object
(Id
));
6394 --------------------------
6395 -- Explain_Limited_Type --
6396 --------------------------
6398 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
6402 -- For array, component type must be limited
6404 if Is_Array_Type
(T
) then
6405 Error_Msg_Node_2
:= T
;
6407 ("\component type& of type& is limited", N
, Component_Type
(T
));
6408 Explain_Limited_Type
(Component_Type
(T
), N
);
6410 elsif Is_Record_Type
(T
) then
6412 -- No need for extra messages if explicit limited record
6414 if Is_Limited_Record
(Base_Type
(T
)) then
6418 -- Otherwise find a limited component. Check only components that
6419 -- come from source, or inherited components that appear in the
6420 -- source of the ancestor.
6422 C
:= First_Component
(T
);
6423 while Present
(C
) loop
6424 if Is_Limited_Type
(Etype
(C
))
6426 (Comes_From_Source
(C
)
6428 (Present
(Original_Record_Component
(C
))
6430 Comes_From_Source
(Original_Record_Component
(C
))))
6432 Error_Msg_Node_2
:= T
;
6433 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
6434 Explain_Limited_Type
(Etype
(C
), N
);
6441 -- The type may be declared explicitly limited, even if no component
6442 -- of it is limited, in which case we fall out of the loop.
6445 end Explain_Limited_Type
;
6447 -------------------------------
6448 -- Extensions_Visible_Status --
6449 -------------------------------
6451 function Extensions_Visible_Status
6452 (Id
: Entity_Id
) return Extensions_Visible_Mode
6461 -- When a formal parameter is subject to Extensions_Visible, the pragma
6462 -- is stored in the contract of related subprogram.
6464 if Is_Formal
(Id
) then
6467 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
6470 -- No other construct carries this pragma
6473 return Extensions_Visible_None
;
6476 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
6478 -- In certain cases analysis may request the Extensions_Visible status
6479 -- of an expression function before the pragma has been analyzed yet.
6480 -- Inspect the declarative items after the expression function looking
6481 -- for the pragma (if any).
6483 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
6484 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
6485 while Present
(Decl
) loop
6486 if Nkind
(Decl
) = N_Pragma
6487 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
6492 -- A source construct ends the region where Extensions_Visible may
6493 -- appear, stop the traversal. An expanded expression function is
6494 -- no longer a source construct, but it must still be recognized.
6496 elsif Comes_From_Source
(Decl
)
6498 (Nkind_In
(Decl
, N_Subprogram_Body
,
6499 N_Subprogram_Declaration
)
6500 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
6509 -- Extract the value from the Boolean expression (if any)
6511 if Present
(Prag
) then
6512 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
6514 if Present
(Arg
) then
6515 Expr
:= Get_Pragma_Arg
(Arg
);
6517 -- When the associated subprogram is an expression function, the
6518 -- argument of the pragma may not have been analyzed.
6520 if not Analyzed
(Expr
) then
6521 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
6524 -- Guard against cascading errors when the argument of pragma
6525 -- Extensions_Visible is not a valid static Boolean expression.
6527 if Error_Posted
(Expr
) then
6528 return Extensions_Visible_None
;
6530 elsif Is_True
(Expr_Value
(Expr
)) then
6531 return Extensions_Visible_True
;
6534 return Extensions_Visible_False
;
6537 -- Otherwise the aspect or pragma defaults to True
6540 return Extensions_Visible_True
;
6543 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
6544 -- directly specified. In SPARK code, its value defaults to "False".
6546 elsif SPARK_Mode
= On
then
6547 return Extensions_Visible_False
;
6549 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
6553 return Extensions_Visible_True
;
6555 end Extensions_Visible_Status
;
6561 procedure Find_Actual
6563 Formal
: out Entity_Id
;
6566 Parnt
: constant Node_Id
:= Parent
(N
);
6570 if Nkind_In
(Parnt
, N_Indexed_Component
, N_Selected_Component
)
6571 and then N
= Prefix
(Parnt
)
6573 Find_Actual
(Parnt
, Formal
, Call
);
6576 elsif Nkind
(Parnt
) = N_Parameter_Association
6577 and then N
= Explicit_Actual_Parameter
(Parnt
)
6579 Call
:= Parent
(Parnt
);
6581 elsif Nkind
(Parnt
) in N_Subprogram_Call
then
6590 -- If we have a call to a subprogram look for the parameter. Note that
6591 -- we exclude overloaded calls, since we don't know enough to be sure
6592 -- of giving the right answer in this case.
6594 if Nkind_In
(Call
, N_Function_Call
, N_Procedure_Call_Statement
)
6595 and then Is_Entity_Name
(Name
(Call
))
6596 and then Present
(Entity
(Name
(Call
)))
6597 and then Is_Overloadable
(Entity
(Name
(Call
)))
6598 and then not Is_Overloaded
(Name
(Call
))
6600 -- If node is name in call it is not an actual
6602 if N
= Name
(Call
) then
6608 -- Fall here if we are definitely a parameter
6610 Actual
:= First_Actual
(Call
);
6611 Formal
:= First_Formal
(Entity
(Name
(Call
)));
6612 while Present
(Formal
) and then Present
(Actual
) loop
6616 -- An actual that is the prefix in a prefixed call may have
6617 -- been rewritten in the call, after the deferred reference
6618 -- was collected. Check if sloc and kinds and names match.
6620 elsif Sloc
(Actual
) = Sloc
(N
)
6621 and then Nkind
(Actual
) = N_Identifier
6622 and then Nkind
(Actual
) = Nkind
(N
)
6623 and then Chars
(Actual
) = Chars
(N
)
6628 Actual
:= Next_Actual
(Actual
);
6629 Formal
:= Next_Formal
(Formal
);
6634 -- Fall through here if we did not find matching actual
6640 ---------------------------
6641 -- Find_Body_Discriminal --
6642 ---------------------------
6644 function Find_Body_Discriminal
6645 (Spec_Discriminant
: Entity_Id
) return Entity_Id
6651 -- If expansion is suppressed, then the scope can be the concurrent type
6652 -- itself rather than a corresponding concurrent record type.
6654 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
6655 Tsk
:= Scope
(Spec_Discriminant
);
6658 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
6660 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
6663 -- Find discriminant of original concurrent type, and use its current
6664 -- discriminal, which is the renaming within the task/protected body.
6666 Disc
:= First_Discriminant
(Tsk
);
6667 while Present
(Disc
) loop
6668 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
6669 return Discriminal
(Disc
);
6672 Next_Discriminant
(Disc
);
6675 -- That loop should always succeed in finding a matching entry and
6676 -- returning. Fatal error if not.
6678 raise Program_Error
;
6679 end Find_Body_Discriminal
;
6681 -------------------------------------
6682 -- Find_Corresponding_Discriminant --
6683 -------------------------------------
6685 function Find_Corresponding_Discriminant
6687 Typ
: Entity_Id
) return Entity_Id
6689 Par_Disc
: Entity_Id
;
6690 Old_Disc
: Entity_Id
;
6691 New_Disc
: Entity_Id
;
6694 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
6696 -- The original type may currently be private, and the discriminant
6697 -- only appear on its full view.
6699 if Is_Private_Type
(Scope
(Par_Disc
))
6700 and then not Has_Discriminants
(Scope
(Par_Disc
))
6701 and then Present
(Full_View
(Scope
(Par_Disc
)))
6703 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
6705 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
6708 if Is_Class_Wide_Type
(Typ
) then
6709 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
6711 New_Disc
:= First_Discriminant
(Typ
);
6714 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
6715 if Old_Disc
= Par_Disc
then
6719 Next_Discriminant
(Old_Disc
);
6720 Next_Discriminant
(New_Disc
);
6723 -- Should always find it
6725 raise Program_Error
;
6726 end Find_Corresponding_Discriminant
;
6728 ----------------------------------
6729 -- Find_Enclosing_Iterator_Loop --
6730 ----------------------------------
6732 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
6737 -- Traverse the scope chain looking for an iterator loop. Such loops are
6738 -- usually transformed into blocks, hence the use of Original_Node.
6741 while Present
(S
) and then S
/= Standard_Standard
loop
6742 if Ekind
(S
) = E_Loop
6743 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
6745 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
6747 if Nkind
(Constr
) = N_Loop_Statement
6748 and then Present
(Iteration_Scheme
(Constr
))
6749 and then Nkind
(Iterator_Specification
6750 (Iteration_Scheme
(Constr
))) =
6751 N_Iterator_Specification
6761 end Find_Enclosing_Iterator_Loop
;
6763 ------------------------------------
6764 -- Find_Loop_In_Conditional_Block --
6765 ------------------------------------
6767 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
6773 if Nkind
(Stmt
) = N_If_Statement
then
6774 Stmt
:= First
(Then_Statements
(Stmt
));
6777 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
6779 -- Inspect the statements of the conditional block. In general the loop
6780 -- should be the first statement in the statement sequence of the block,
6781 -- but the finalization machinery may have introduced extra object
6784 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
6785 while Present
(Stmt
) loop
6786 if Nkind
(Stmt
) = N_Loop_Statement
then
6793 -- The expansion of attribute 'Loop_Entry produced a malformed block
6795 raise Program_Error
;
6796 end Find_Loop_In_Conditional_Block
;
6798 --------------------------
6799 -- Find_Overlaid_Entity --
6800 --------------------------
6802 procedure Find_Overlaid_Entity
6804 Ent
: out Entity_Id
;
6810 -- We are looking for one of the two following forms:
6812 -- for X'Address use Y'Address
6816 -- Const : constant Address := expr;
6818 -- for X'Address use Const;
6820 -- In the second case, the expr is either Y'Address, or recursively a
6821 -- constant that eventually references Y'Address.
6826 if Nkind
(N
) = N_Attribute_Definition_Clause
6827 and then Chars
(N
) = Name_Address
6829 Expr
:= Expression
(N
);
6831 -- This loop checks the form of the expression for Y'Address,
6832 -- using recursion to deal with intermediate constants.
6835 -- Check for Y'Address
6837 if Nkind
(Expr
) = N_Attribute_Reference
6838 and then Attribute_Name
(Expr
) = Name_Address
6840 Expr
:= Prefix
(Expr
);
6843 -- Check for Const where Const is a constant entity
6845 elsif Is_Entity_Name
(Expr
)
6846 and then Ekind
(Entity
(Expr
)) = E_Constant
6848 Expr
:= Constant_Value
(Entity
(Expr
));
6850 -- Anything else does not need checking
6857 -- This loop checks the form of the prefix for an entity, using
6858 -- recursion to deal with intermediate components.
6861 -- Check for Y where Y is an entity
6863 if Is_Entity_Name
(Expr
) then
6864 Ent
:= Entity
(Expr
);
6867 -- Check for components
6870 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
6872 Expr
:= Prefix
(Expr
);
6875 -- Anything else does not need checking
6882 end Find_Overlaid_Entity
;
6884 -------------------------
6885 -- Find_Parameter_Type --
6886 -------------------------
6888 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
6890 if Nkind
(Param
) /= N_Parameter_Specification
then
6893 -- For an access parameter, obtain the type from the formal entity
6894 -- itself, because access to subprogram nodes do not carry a type.
6895 -- Shouldn't we always use the formal entity ???
6897 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
6898 return Etype
(Defining_Identifier
(Param
));
6901 return Etype
(Parameter_Type
(Param
));
6903 end Find_Parameter_Type
;
6905 -----------------------------------
6906 -- Find_Placement_In_State_Space --
6907 -----------------------------------
6909 procedure Find_Placement_In_State_Space
6910 (Item_Id
: Entity_Id
;
6911 Placement
: out State_Space_Kind
;
6912 Pack_Id
: out Entity_Id
)
6914 Context
: Entity_Id
;
6917 -- Assume that the item does not appear in the state space of a package
6919 Placement
:= Not_In_Package
;
6922 -- Climb the scope stack and examine the enclosing context
6924 Context
:= Scope
(Item_Id
);
6925 while Present
(Context
) and then Context
/= Standard_Standard
loop
6926 if Ekind
(Context
) = E_Package
then
6929 -- A package body is a cut off point for the traversal as the item
6930 -- cannot be visible to the outside from this point on. Note that
6931 -- this test must be done first as a body is also classified as a
6934 if In_Package_Body
(Context
) then
6935 Placement
:= Body_State_Space
;
6938 -- The private part of a package is a cut off point for the
6939 -- traversal as the item cannot be visible to the outside from
6942 elsif In_Private_Part
(Context
) then
6943 Placement
:= Private_State_Space
;
6946 -- When the item appears in the visible state space of a package,
6947 -- continue to climb the scope stack as this may not be the final
6951 Placement
:= Visible_State_Space
;
6953 -- The visible state space of a child unit acts as the proper
6954 -- placement of an item.
6956 if Is_Child_Unit
(Context
) then
6961 -- The item or its enclosing package appear in a construct that has
6965 Placement
:= Not_In_Package
;
6969 Context
:= Scope
(Context
);
6971 end Find_Placement_In_State_Space
;
6973 ------------------------
6974 -- Find_Specific_Type --
6975 ------------------------
6977 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
6978 Typ
: Entity_Id
:= Root_Type
(CW
);
6981 if Ekind
(Typ
) = E_Incomplete_Type
then
6982 if From_Limited_With
(Typ
) then
6983 Typ
:= Non_Limited_View
(Typ
);
6985 Typ
:= Full_View
(Typ
);
6989 if Is_Private_Type
(Typ
)
6990 and then not Is_Tagged_Type
(Typ
)
6991 and then Present
(Full_View
(Typ
))
6993 return Full_View
(Typ
);
6997 end Find_Specific_Type
;
6999 -----------------------------
7000 -- Find_Static_Alternative --
7001 -----------------------------
7003 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
7004 Expr
: constant Node_Id
:= Expression
(N
);
7005 Val
: constant Uint
:= Expr_Value
(Expr
);
7010 Alt
:= First
(Alternatives
(N
));
7013 if Nkind
(Alt
) /= N_Pragma
then
7014 Choice
:= First
(Discrete_Choices
(Alt
));
7015 while Present
(Choice
) loop
7017 -- Others choice, always matches
7019 if Nkind
(Choice
) = N_Others_Choice
then
7022 -- Range, check if value is in the range
7024 elsif Nkind
(Choice
) = N_Range
then
7026 Val
>= Expr_Value
(Low_Bound
(Choice
))
7028 Val
<= Expr_Value
(High_Bound
(Choice
));
7030 -- Choice is a subtype name. Note that we know it must
7031 -- be a static subtype, since otherwise it would have
7032 -- been diagnosed as illegal.
7034 elsif Is_Entity_Name
(Choice
)
7035 and then Is_Type
(Entity
(Choice
))
7037 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
7038 Assume_Valid
=> False);
7040 -- Choice is a subtype indication
7042 elsif Nkind
(Choice
) = N_Subtype_Indication
then
7044 C
: constant Node_Id
:= Constraint
(Choice
);
7045 R
: constant Node_Id
:= Range_Expression
(C
);
7049 Val
>= Expr_Value
(Low_Bound
(R
))
7051 Val
<= Expr_Value
(High_Bound
(R
));
7054 -- Choice is a simple expression
7057 exit Search
when Val
= Expr_Value
(Choice
);
7065 pragma Assert
(Present
(Alt
));
7068 -- The above loop *must* terminate by finding a match, since
7069 -- we know the case statement is valid, and the value of the
7070 -- expression is known at compile time. When we fall out of
7071 -- the loop, Alt points to the alternative that we know will
7072 -- be selected at run time.
7075 end Find_Static_Alternative
;
7081 function First_Actual
(Node
: Node_Id
) return Node_Id
is
7085 if No
(Parameter_Associations
(Node
)) then
7089 N
:= First
(Parameter_Associations
(Node
));
7091 if Nkind
(N
) = N_Parameter_Association
then
7092 return First_Named_Actual
(Node
);
7098 -----------------------
7099 -- Gather_Components --
7100 -----------------------
7102 procedure Gather_Components
7104 Comp_List
: Node_Id
;
7105 Governed_By
: List_Id
;
7107 Report_Errors
: out Boolean)
7111 Discrete_Choice
: Node_Id
;
7112 Comp_Item
: Node_Id
;
7114 Discrim
: Entity_Id
;
7115 Discrim_Name
: Node_Id
;
7116 Discrim_Value
: Node_Id
;
7119 Report_Errors
:= False;
7121 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
7124 elsif Present
(Component_Items
(Comp_List
)) then
7125 Comp_Item
:= First
(Component_Items
(Comp_List
));
7131 while Present
(Comp_Item
) loop
7133 -- Skip the tag of a tagged record, the interface tags, as well
7134 -- as all items that are not user components (anonymous types,
7135 -- rep clauses, Parent field, controller field).
7137 if Nkind
(Comp_Item
) = N_Component_Declaration
then
7139 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
7141 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
7142 Append_Elmt
(Comp
, Into
);
7150 if No
(Variant_Part
(Comp_List
)) then
7153 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
7154 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
7157 -- Look for the discriminant that governs this variant part.
7158 -- The discriminant *must* be in the Governed_By List
7160 Assoc
:= First
(Governed_By
);
7161 Find_Constraint
: loop
7162 Discrim
:= First
(Choices
(Assoc
));
7163 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
7164 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
7166 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
7167 Chars
(Discrim_Name
))
7168 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
7169 = Chars
(Discrim_Name
);
7171 if No
(Next
(Assoc
)) then
7172 if not Is_Constrained
(Typ
)
7173 and then Is_Derived_Type
(Typ
)
7174 and then Present
(Stored_Constraint
(Typ
))
7176 -- If the type is a tagged type with inherited discriminants,
7177 -- use the stored constraint on the parent in order to find
7178 -- the values of discriminants that are otherwise hidden by an
7179 -- explicit constraint. Renamed discriminants are handled in
7182 -- If several parent discriminants are renamed by a single
7183 -- discriminant of the derived type, the call to obtain the
7184 -- Corresponding_Discriminant field only retrieves the last
7185 -- of them. We recover the constraint on the others from the
7186 -- Stored_Constraint as well.
7193 D
:= First_Discriminant
(Etype
(Typ
));
7194 C
:= First_Elmt
(Stored_Constraint
(Typ
));
7195 while Present
(D
) and then Present
(C
) loop
7196 if Chars
(Discrim_Name
) = Chars
(D
) then
7197 if Is_Entity_Name
(Node
(C
))
7198 and then Entity
(Node
(C
)) = Entity
(Discrim
)
7200 -- D is renamed by Discrim, whose value is given in
7207 Make_Component_Association
(Sloc
(Typ
),
7209 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
7210 Duplicate_Subexpr_No_Checks
(Node
(C
)));
7212 exit Find_Constraint
;
7215 Next_Discriminant
(D
);
7222 if No
(Next
(Assoc
)) then
7223 Error_Msg_NE
(" missing value for discriminant&",
7224 First
(Governed_By
), Discrim_Name
);
7225 Report_Errors
:= True;
7230 end loop Find_Constraint
;
7232 Discrim_Value
:= Expression
(Assoc
);
7234 if not Is_OK_Static_Expression
(Discrim_Value
) then
7236 -- If the variant part is governed by a discriminant of the type
7237 -- this is an error. If the variant part and the discriminant are
7238 -- inherited from an ancestor this is legal (AI05-120) unless the
7239 -- components are being gathered for an aggregate, in which case
7240 -- the caller must check Report_Errors.
7242 if Scope
(Original_Record_Component
7243 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
7246 ("value for discriminant & must be static!",
7247 Discrim_Value
, Discrim
);
7248 Why_Not_Static
(Discrim_Value
);
7251 Report_Errors
:= True;
7255 Search_For_Discriminant_Value
: declare
7261 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
7264 Find_Discrete_Value
: while Present
(Variant
) loop
7265 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
7266 while Present
(Discrete_Choice
) loop
7267 exit Find_Discrete_Value
when
7268 Nkind
(Discrete_Choice
) = N_Others_Choice
;
7270 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
7272 UI_Low
:= Expr_Value
(Low
);
7273 UI_High
:= Expr_Value
(High
);
7275 exit Find_Discrete_Value
when
7276 UI_Low
<= UI_Discrim_Value
7278 UI_High
>= UI_Discrim_Value
;
7280 Next
(Discrete_Choice
);
7283 Next_Non_Pragma
(Variant
);
7284 end loop Find_Discrete_Value
;
7285 end Search_For_Discriminant_Value
;
7287 if No
(Variant
) then
7289 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
7290 Report_Errors
:= True;
7294 -- If we have found the corresponding choice, recursively add its
7295 -- components to the Into list.
7298 (Empty
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
7299 end Gather_Components
;
7301 ------------------------
7302 -- Get_Actual_Subtype --
7303 ------------------------
7305 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
7306 Typ
: constant Entity_Id
:= Etype
(N
);
7307 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
7316 -- If what we have is an identifier that references a subprogram
7317 -- formal, or a variable or constant object, then we get the actual
7318 -- subtype from the referenced entity if one has been built.
7320 if Nkind
(N
) = N_Identifier
7322 (Is_Formal
(Entity
(N
))
7323 or else Ekind
(Entity
(N
)) = E_Constant
7324 or else Ekind
(Entity
(N
)) = E_Variable
)
7325 and then Present
(Actual_Subtype
(Entity
(N
)))
7327 return Actual_Subtype
(Entity
(N
));
7329 -- Actual subtype of unchecked union is always itself. We never need
7330 -- the "real" actual subtype. If we did, we couldn't get it anyway
7331 -- because the discriminant is not available. The restrictions on
7332 -- Unchecked_Union are designed to make sure that this is OK.
7334 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
7337 -- Here for the unconstrained case, we must find actual subtype
7338 -- No actual subtype is available, so we must build it on the fly.
7340 -- Checking the type, not the underlying type, for constrainedness
7341 -- seems to be necessary. Maybe all the tests should be on the type???
7343 elsif (not Is_Constrained
(Typ
))
7344 and then (Is_Array_Type
(Utyp
)
7345 or else (Is_Record_Type
(Utyp
)
7346 and then Has_Discriminants
(Utyp
)))
7347 and then not Has_Unknown_Discriminants
(Utyp
)
7348 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
7350 -- Nothing to do if in spec expression (why not???)
7352 if In_Spec_Expression
then
7355 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
7357 -- If the type has no discriminants, there is no subtype to
7358 -- build, even if the underlying type is discriminated.
7362 -- Else build the actual subtype
7365 Decl
:= Build_Actual_Subtype
(Typ
, N
);
7366 Atyp
:= Defining_Identifier
(Decl
);
7368 -- If Build_Actual_Subtype generated a new declaration then use it
7372 -- The actual subtype is an Itype, so analyze the declaration,
7373 -- but do not attach it to the tree, to get the type defined.
7375 Set_Parent
(Decl
, N
);
7376 Set_Is_Itype
(Atyp
);
7377 Analyze
(Decl
, Suppress
=> All_Checks
);
7378 Set_Associated_Node_For_Itype
(Atyp
, N
);
7379 Set_Has_Delayed_Freeze
(Atyp
, False);
7381 -- We need to freeze the actual subtype immediately. This is
7382 -- needed, because otherwise this Itype will not get frozen
7383 -- at all, and it is always safe to freeze on creation because
7384 -- any associated types must be frozen at this point.
7386 Freeze_Itype
(Atyp
, N
);
7389 -- Otherwise we did not build a declaration, so return original
7396 -- For all remaining cases, the actual subtype is the same as
7397 -- the nominal type.
7402 end Get_Actual_Subtype
;
7404 -------------------------------------
7405 -- Get_Actual_Subtype_If_Available --
7406 -------------------------------------
7408 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
7409 Typ
: constant Entity_Id
:= Etype
(N
);
7412 -- If what we have is an identifier that references a subprogram
7413 -- formal, or a variable or constant object, then we get the actual
7414 -- subtype from the referenced entity if one has been built.
7416 if Nkind
(N
) = N_Identifier
7418 (Is_Formal
(Entity
(N
))
7419 or else Ekind
(Entity
(N
)) = E_Constant
7420 or else Ekind
(Entity
(N
)) = E_Variable
)
7421 and then Present
(Actual_Subtype
(Entity
(N
)))
7423 return Actual_Subtype
(Entity
(N
));
7425 -- Otherwise the Etype of N is returned unchanged
7430 end Get_Actual_Subtype_If_Available
;
7432 ------------------------
7433 -- Get_Body_From_Stub --
7434 ------------------------
7436 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
7438 return Proper_Body
(Unit
(Library_Unit
(N
)));
7439 end Get_Body_From_Stub
;
7441 ---------------------
7442 -- Get_Cursor_Type --
7443 ---------------------
7445 function Get_Cursor_Type
7447 Typ
: Entity_Id
) return Entity_Id
7451 First_Op
: Entity_Id
;
7455 -- If error already detected, return
7457 if Error_Posted
(Aspect
) then
7461 -- The cursor type for an Iterable aspect is the return type of a
7462 -- non-overloaded First primitive operation. Locate association for
7465 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
7467 while Present
(Assoc
) loop
7468 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
7469 First_Op
:= Expression
(Assoc
);
7476 if First_Op
= Any_Id
then
7477 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
7483 -- Locate function with desired name and profile in scope of type
7485 Func
:= First_Entity
(Scope
(Typ
));
7486 while Present
(Func
) loop
7487 if Chars
(Func
) = Chars
(First_Op
)
7488 and then Ekind
(Func
) = E_Function
7489 and then Present
(First_Formal
(Func
))
7490 and then Etype
(First_Formal
(Func
)) = Typ
7491 and then No
(Next_Formal
(First_Formal
(Func
)))
7493 if Cursor
/= Any_Type
then
7495 ("Operation First for iterable type must be unique", Aspect
);
7498 Cursor
:= Etype
(Func
);
7505 -- If not found, no way to resolve remaining primitives.
7507 if Cursor
= Any_Type
then
7509 ("No legal primitive operation First for Iterable type", Aspect
);
7513 end Get_Cursor_Type
;
7515 function Get_Cursor_Type
(Typ
: Entity_Id
) return Entity_Id
is
7517 return Etype
(Get_Iterable_Type_Primitive
(Typ
, Name_First
));
7518 end Get_Cursor_Type
;
7520 -------------------------------
7521 -- Get_Default_External_Name --
7522 -------------------------------
7524 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
7526 Get_Decoded_Name_String
(Chars
(E
));
7528 if Opt
.External_Name_Imp_Casing
= Uppercase
then
7529 Set_Casing
(All_Upper_Case
);
7531 Set_Casing
(All_Lower_Case
);
7535 Make_String_Literal
(Sloc
(E
),
7536 Strval
=> String_From_Name_Buffer
);
7537 end Get_Default_External_Name
;
7539 --------------------------
7540 -- Get_Enclosing_Object --
7541 --------------------------
7543 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
7545 if Is_Entity_Name
(N
) then
7549 when N_Indexed_Component |
7551 N_Selected_Component
=>
7553 -- If not generating code, a dereference may be left implicit.
7554 -- In thoses cases, return Empty.
7556 if Is_Access_Type
(Etype
(Prefix
(N
))) then
7559 return Get_Enclosing_Object
(Prefix
(N
));
7562 when N_Type_Conversion
=>
7563 return Get_Enclosing_Object
(Expression
(N
));
7569 end Get_Enclosing_Object
;
7571 ---------------------------
7572 -- Get_Enum_Lit_From_Pos --
7573 ---------------------------
7575 function Get_Enum_Lit_From_Pos
7578 Loc
: Source_Ptr
) return Node_Id
7580 Btyp
: Entity_Id
:= Base_Type
(T
);
7584 -- In the case where the literal is of type Character, Wide_Character
7585 -- or Wide_Wide_Character or of a type derived from them, there needs
7586 -- to be some special handling since there is no explicit chain of
7587 -- literals to search. Instead, an N_Character_Literal node is created
7588 -- with the appropriate Char_Code and Chars fields.
7590 if Is_Standard_Character_Type
(T
) then
7591 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
7593 Make_Character_Literal
(Loc
,
7595 Char_Literal_Value
=> Pos
);
7597 -- For all other cases, we have a complete table of literals, and
7598 -- we simply iterate through the chain of literal until the one
7599 -- with the desired position value is found.
7602 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
7603 Btyp
:= Full_View
(Btyp
);
7606 Lit
:= First_Literal
(Btyp
);
7607 for J
in 1 .. UI_To_Int
(Pos
) loop
7611 return New_Occurrence_Of
(Lit
, Loc
);
7613 end Get_Enum_Lit_From_Pos
;
7615 ------------------------
7616 -- Get_Generic_Entity --
7617 ------------------------
7619 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
7620 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
7622 if Present
(Renamed_Object
(Ent
)) then
7623 return Renamed_Object
(Ent
);
7627 end Get_Generic_Entity
;
7629 -------------------------------------
7630 -- Get_Incomplete_View_Of_Ancestor --
7631 -------------------------------------
7633 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
7634 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
7635 Par_Scope
: Entity_Id
;
7636 Par_Type
: Entity_Id
;
7639 -- The incomplete view of an ancestor is only relevant for private
7640 -- derived types in child units.
7642 if not Is_Derived_Type
(E
)
7643 or else not Is_Child_Unit
(Cur_Unit
)
7648 Par_Scope
:= Scope
(Cur_Unit
);
7649 if No
(Par_Scope
) then
7653 Par_Type
:= Etype
(Base_Type
(E
));
7655 -- Traverse list of ancestor types until we find one declared in
7656 -- a parent or grandparent unit (two levels seem sufficient).
7658 while Present
(Par_Type
) loop
7659 if Scope
(Par_Type
) = Par_Scope
7660 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
7664 elsif not Is_Derived_Type
(Par_Type
) then
7668 Par_Type
:= Etype
(Base_Type
(Par_Type
));
7672 -- If none found, there is no relevant ancestor type.
7676 end Get_Incomplete_View_Of_Ancestor
;
7678 ----------------------
7679 -- Get_Index_Bounds --
7680 ----------------------
7682 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
7683 Kind
: constant Node_Kind
:= Nkind
(N
);
7687 if Kind
= N_Range
then
7689 H
:= High_Bound
(N
);
7691 elsif Kind
= N_Subtype_Indication
then
7692 R
:= Range_Expression
(Constraint
(N
));
7700 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
7701 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
7704 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
7705 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
7709 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
7710 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
7713 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
7714 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
7718 -- N is an expression, indicating a range with one value
7723 end Get_Index_Bounds
;
7725 ---------------------------------
7726 -- Get_Iterable_Type_Primitive --
7727 ---------------------------------
7729 function Get_Iterable_Type_Primitive
7731 Nam
: Name_Id
) return Entity_Id
7733 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
7741 Assoc
:= First
(Component_Associations
(Funcs
));
7742 while Present
(Assoc
) loop
7743 if Chars
(First
(Choices
(Assoc
))) = Nam
then
7744 return Entity
(Expression
(Assoc
));
7747 Assoc
:= Next
(Assoc
);
7752 end Get_Iterable_Type_Primitive
;
7754 ----------------------------------
7755 -- Get_Library_Unit_Name_string --
7756 ----------------------------------
7758 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
7759 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
7762 Get_Unit_Name_String
(Unit_Name_Id
);
7764 -- Remove seven last character (" (spec)" or " (body)")
7766 Name_Len
:= Name_Len
- 7;
7767 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
7768 end Get_Library_Unit_Name_String
;
7770 ------------------------
7771 -- Get_Name_Entity_Id --
7772 ------------------------
7774 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
7776 return Entity_Id
(Get_Name_Table_Int
(Id
));
7777 end Get_Name_Entity_Id
;
7779 ------------------------------
7780 -- Get_Name_From_CTC_Pragma --
7781 ------------------------------
7783 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
7784 Arg
: constant Node_Id
:=
7785 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
7787 return Strval
(Expr_Value_S
(Arg
));
7788 end Get_Name_From_CTC_Pragma
;
7790 -----------------------
7791 -- Get_Parent_Entity --
7792 -----------------------
7794 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
7796 if Nkind
(Unit
) = N_Package_Body
7797 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
7799 return Defining_Entity
7800 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
7801 elsif Nkind
(Unit
) = N_Package_Instantiation
then
7802 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
7804 return Defining_Entity
(Unit
);
7806 end Get_Parent_Entity
;
7811 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
7813 return Get_Pragma_Id
(Pragma_Name
(N
));
7816 -----------------------
7817 -- Get_Reason_String --
7818 -----------------------
7820 procedure Get_Reason_String
(N
: Node_Id
) is
7822 if Nkind
(N
) = N_String_Literal
then
7823 Store_String_Chars
(Strval
(N
));
7825 elsif Nkind
(N
) = N_Op_Concat
then
7826 Get_Reason_String
(Left_Opnd
(N
));
7827 Get_Reason_String
(Right_Opnd
(N
));
7829 -- If not of required form, error
7833 ("Reason for pragma Warnings has wrong form", N
);
7835 ("\must be string literal or concatenation of string literals", N
);
7838 end Get_Reason_String
;
7840 ---------------------------
7841 -- Get_Referenced_Object --
7842 ---------------------------
7844 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
7849 while Is_Entity_Name
(R
)
7850 and then Present
(Renamed_Object
(Entity
(R
)))
7852 R
:= Renamed_Object
(Entity
(R
));
7856 end Get_Referenced_Object
;
7858 ------------------------
7859 -- Get_Renamed_Entity --
7860 ------------------------
7862 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
7867 while Present
(Renamed_Entity
(R
)) loop
7868 R
:= Renamed_Entity
(R
);
7872 end Get_Renamed_Entity
;
7874 -----------------------
7875 -- Get_Return_Object --
7876 -----------------------
7878 function Get_Return_Object
(N
: Node_Id
) return Entity_Id
is
7882 Decl
:= First
(Return_Object_Declarations
(N
));
7883 while Present
(Decl
) loop
7884 exit when Nkind
(Decl
) = N_Object_Declaration
7885 and then Is_Return_Object
(Defining_Identifier
(Decl
));
7889 pragma Assert
(Present
(Decl
));
7890 return Defining_Identifier
(Decl
);
7891 end Get_Return_Object
;
7893 ---------------------------
7894 -- Get_Subprogram_Entity --
7895 ---------------------------
7897 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
7899 Subp_Id
: Entity_Id
;
7902 if Nkind
(Nod
) = N_Accept_Statement
then
7903 Subp
:= Entry_Direct_Name
(Nod
);
7905 elsif Nkind
(Nod
) = N_Slice
then
7906 Subp
:= Prefix
(Nod
);
7912 -- Strip the subprogram call
7915 if Nkind_In
(Subp
, N_Explicit_Dereference
,
7916 N_Indexed_Component
,
7917 N_Selected_Component
)
7919 Subp
:= Prefix
(Subp
);
7921 elsif Nkind_In
(Subp
, N_Type_Conversion
,
7922 N_Unchecked_Type_Conversion
)
7924 Subp
:= Expression
(Subp
);
7931 -- Extract the entity of the subprogram call
7933 if Is_Entity_Name
(Subp
) then
7934 Subp_Id
:= Entity
(Subp
);
7936 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
7937 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
7940 if Is_Subprogram
(Subp_Id
) then
7946 -- The search did not find a construct that denotes a subprogram
7951 end Get_Subprogram_Entity
;
7953 -----------------------------
7954 -- Get_Task_Body_Procedure --
7955 -----------------------------
7957 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
7959 -- Note: A task type may be the completion of a private type with
7960 -- discriminants. When performing elaboration checks on a task
7961 -- declaration, the current view of the type may be the private one,
7962 -- and the procedure that holds the body of the task is held in its
7965 -- This is an odd function, why not have Task_Body_Procedure do
7966 -- the following digging???
7968 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
7969 end Get_Task_Body_Procedure
;
7971 -------------------------
7972 -- Get_User_Defined_Eq --
7973 -------------------------
7975 function Get_User_Defined_Eq
(E
: Entity_Id
) return Entity_Id
is
7980 Prim
:= First_Elmt
(Collect_Primitive_Operations
(E
));
7981 while Present
(Prim
) loop
7984 if Chars
(Op
) = Name_Op_Eq
7985 and then Etype
(Op
) = Standard_Boolean
7986 and then Etype
(First_Formal
(Op
)) = E
7987 and then Etype
(Next_Formal
(First_Formal
(Op
))) = E
7996 end Get_User_Defined_Eq
;
7998 -----------------------
7999 -- Has_Access_Values --
8000 -----------------------
8002 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
8003 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
8006 -- Case of a private type which is not completed yet. This can only
8007 -- happen in the case of a generic format type appearing directly, or
8008 -- as a component of the type to which this function is being applied
8009 -- at the top level. Return False in this case, since we certainly do
8010 -- not know that the type contains access types.
8015 elsif Is_Access_Type
(Typ
) then
8018 elsif Is_Array_Type
(Typ
) then
8019 return Has_Access_Values
(Component_Type
(Typ
));
8021 elsif Is_Record_Type
(Typ
) then
8026 -- Loop to Check components
8028 Comp
:= First_Component_Or_Discriminant
(Typ
);
8029 while Present
(Comp
) loop
8031 -- Check for access component, tag field does not count, even
8032 -- though it is implemented internally using an access type.
8034 if Has_Access_Values
(Etype
(Comp
))
8035 and then Chars
(Comp
) /= Name_uTag
8040 Next_Component_Or_Discriminant
(Comp
);
8049 end Has_Access_Values
;
8051 ------------------------------
8052 -- Has_Compatible_Alignment --
8053 ------------------------------
8055 function Has_Compatible_Alignment
8057 Expr
: Node_Id
) return Alignment_Result
8059 function Has_Compatible_Alignment_Internal
8062 Default
: Alignment_Result
) return Alignment_Result
;
8063 -- This is the internal recursive function that actually does the work.
8064 -- There is one additional parameter, which says what the result should
8065 -- be if no alignment information is found, and there is no definite
8066 -- indication of compatible alignments. At the outer level, this is set
8067 -- to Unknown, but for internal recursive calls in the case where types
8068 -- are known to be correct, it is set to Known_Compatible.
8070 ---------------------------------------
8071 -- Has_Compatible_Alignment_Internal --
8072 ---------------------------------------
8074 function Has_Compatible_Alignment_Internal
8077 Default
: Alignment_Result
) return Alignment_Result
8079 Result
: Alignment_Result
:= Known_Compatible
;
8080 -- Holds the current status of the result. Note that once a value of
8081 -- Known_Incompatible is set, it is sticky and does not get changed
8082 -- to Unknown (the value in Result only gets worse as we go along,
8085 Offs
: Uint
:= No_Uint
;
8086 -- Set to a factor of the offset from the base object when Expr is a
8087 -- selected or indexed component, based on Component_Bit_Offset and
8088 -- Component_Size respectively. A negative value is used to represent
8089 -- a value which is not known at compile time.
8091 procedure Check_Prefix
;
8092 -- Checks the prefix recursively in the case where the expression
8093 -- is an indexed or selected component.
8095 procedure Set_Result
(R
: Alignment_Result
);
8096 -- If R represents a worse outcome (unknown instead of known
8097 -- compatible, or known incompatible), then set Result to R.
8103 procedure Check_Prefix
is
8105 -- The subtlety here is that in doing a recursive call to check
8106 -- the prefix, we have to decide what to do in the case where we
8107 -- don't find any specific indication of an alignment problem.
8109 -- At the outer level, we normally set Unknown as the result in
8110 -- this case, since we can only set Known_Compatible if we really
8111 -- know that the alignment value is OK, but for the recursive
8112 -- call, in the case where the types match, and we have not
8113 -- specified a peculiar alignment for the object, we are only
8114 -- concerned about suspicious rep clauses, the default case does
8115 -- not affect us, since the compiler will, in the absence of such
8116 -- rep clauses, ensure that the alignment is correct.
8118 if Default
= Known_Compatible
8120 (Etype
(Obj
) = Etype
(Expr
)
8121 and then (Unknown_Alignment
(Obj
)
8123 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
8126 (Has_Compatible_Alignment_Internal
8127 (Obj
, Prefix
(Expr
), Known_Compatible
));
8129 -- In all other cases, we need a full check on the prefix
8133 (Has_Compatible_Alignment_Internal
8134 (Obj
, Prefix
(Expr
), Unknown
));
8142 procedure Set_Result
(R
: Alignment_Result
) is
8149 -- Start of processing for Has_Compatible_Alignment_Internal
8152 -- If Expr is a selected component, we must make sure there is no
8153 -- potentially troublesome component clause, and that the record is
8156 if Nkind
(Expr
) = N_Selected_Component
then
8158 -- Packed record always generate unknown alignment
8160 if Is_Packed
(Etype
(Prefix
(Expr
))) then
8161 Set_Result
(Unknown
);
8164 -- Check prefix and component offset
8167 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
8169 -- If Expr is an indexed component, we must make sure there is no
8170 -- potentially troublesome Component_Size clause and that the array
8171 -- is not bit-packed.
8173 elsif Nkind
(Expr
) = N_Indexed_Component
then
8175 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
8176 Ind
: constant Node_Id
:= First_Index
(Typ
);
8179 -- Bit packed array always generates unknown alignment
8181 if Is_Bit_Packed_Array
(Typ
) then
8182 Set_Result
(Unknown
);
8185 -- Check prefix and component offset
8188 Offs
:= Component_Size
(Typ
);
8190 -- Small optimization: compute the full offset when possible
8193 and then Offs
> Uint_0
8194 and then Present
(Ind
)
8195 and then Nkind
(Ind
) = N_Range
8196 and then Compile_Time_Known_Value
(Low_Bound
(Ind
))
8197 and then Compile_Time_Known_Value
(First
(Expressions
(Expr
)))
8199 Offs
:= Offs
* (Expr_Value
(First
(Expressions
(Expr
)))
8200 - Expr_Value
(Low_Bound
((Ind
))));
8205 -- If we have a null offset, the result is entirely determined by
8206 -- the base object and has already been computed recursively.
8208 if Offs
= Uint_0
then
8211 -- Case where we know the alignment of the object
8213 elsif Known_Alignment
(Obj
) then
8215 ObjA
: constant Uint
:= Alignment
(Obj
);
8216 ExpA
: Uint
:= No_Uint
;
8217 SizA
: Uint
:= No_Uint
;
8220 -- If alignment of Obj is 1, then we are always OK
8223 Set_Result
(Known_Compatible
);
8225 -- Alignment of Obj is greater than 1, so we need to check
8228 -- If we have an offset, see if it is compatible
8230 if Offs
/= No_Uint
and Offs
> Uint_0
then
8231 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
8232 Set_Result
(Known_Incompatible
);
8235 -- See if Expr is an object with known alignment
8237 elsif Is_Entity_Name
(Expr
)
8238 and then Known_Alignment
(Entity
(Expr
))
8240 ExpA
:= Alignment
(Entity
(Expr
));
8242 -- Otherwise, we can use the alignment of the type of
8243 -- Expr given that we already checked for
8244 -- discombobulating rep clauses for the cases of indexed
8245 -- and selected components above.
8247 elsif Known_Alignment
(Etype
(Expr
)) then
8248 ExpA
:= Alignment
(Etype
(Expr
));
8250 -- Otherwise the alignment is unknown
8253 Set_Result
(Default
);
8256 -- If we got an alignment, see if it is acceptable
8258 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
8259 Set_Result
(Known_Incompatible
);
8262 -- If Expr is not a piece of a larger object, see if size
8263 -- is given. If so, check that it is not too small for the
8264 -- required alignment.
8266 if Offs
/= No_Uint
then
8269 -- See if Expr is an object with known size
8271 elsif Is_Entity_Name
(Expr
)
8272 and then Known_Static_Esize
(Entity
(Expr
))
8274 SizA
:= Esize
(Entity
(Expr
));
8276 -- Otherwise, we check the object size of the Expr type
8278 elsif Known_Static_Esize
(Etype
(Expr
)) then
8279 SizA
:= Esize
(Etype
(Expr
));
8282 -- If we got a size, see if it is a multiple of the Obj
8283 -- alignment, if not, then the alignment cannot be
8284 -- acceptable, since the size is always a multiple of the
8287 if SizA
/= No_Uint
then
8288 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
8289 Set_Result
(Known_Incompatible
);
8295 -- If we do not know required alignment, any non-zero offset is a
8296 -- potential problem (but certainly may be OK, so result is unknown).
8298 elsif Offs
/= No_Uint
then
8299 Set_Result
(Unknown
);
8301 -- If we can't find the result by direct comparison of alignment
8302 -- values, then there is still one case that we can determine known
8303 -- result, and that is when we can determine that the types are the
8304 -- same, and no alignments are specified. Then we known that the
8305 -- alignments are compatible, even if we don't know the alignment
8306 -- value in the front end.
8308 elsif Etype
(Obj
) = Etype
(Expr
) then
8310 -- Types are the same, but we have to check for possible size
8311 -- and alignments on the Expr object that may make the alignment
8312 -- different, even though the types are the same.
8314 if Is_Entity_Name
(Expr
) then
8316 -- First check alignment of the Expr object. Any alignment less
8317 -- than Maximum_Alignment is worrisome since this is the case
8318 -- where we do not know the alignment of Obj.
8320 if Known_Alignment
(Entity
(Expr
))
8321 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
8322 Ttypes
.Maximum_Alignment
8324 Set_Result
(Unknown
);
8326 -- Now check size of Expr object. Any size that is not an
8327 -- even multiple of Maximum_Alignment is also worrisome
8328 -- since it may cause the alignment of the object to be less
8329 -- than the alignment of the type.
8331 elsif Known_Static_Esize
(Entity
(Expr
))
8333 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
8334 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
8337 Set_Result
(Unknown
);
8339 -- Otherwise same type is decisive
8342 Set_Result
(Known_Compatible
);
8346 -- Another case to deal with is when there is an explicit size or
8347 -- alignment clause when the types are not the same. If so, then the
8348 -- result is Unknown. We don't need to do this test if the Default is
8349 -- Unknown, since that result will be set in any case.
8351 elsif Default
/= Unknown
8352 and then (Has_Size_Clause
(Etype
(Expr
))
8354 Has_Alignment_Clause
(Etype
(Expr
)))
8356 Set_Result
(Unknown
);
8358 -- If no indication found, set default
8361 Set_Result
(Default
);
8364 -- Return worst result found
8367 end Has_Compatible_Alignment_Internal
;
8369 -- Start of processing for Has_Compatible_Alignment
8372 -- If Obj has no specified alignment, then set alignment from the type
8373 -- alignment. Perhaps we should always do this, but for sure we should
8374 -- do it when there is an address clause since we can do more if the
8375 -- alignment is known.
8377 if Unknown_Alignment
(Obj
) then
8378 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
8381 -- Now do the internal call that does all the work
8383 return Has_Compatible_Alignment_Internal
(Obj
, Expr
, Unknown
);
8384 end Has_Compatible_Alignment
;
8386 ----------------------
8387 -- Has_Declarations --
8388 ----------------------
8390 function Has_Declarations
(N
: Node_Id
) return Boolean is
8392 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
8394 N_Compilation_Unit_Aux
,
8400 N_Package_Specification
);
8401 end Has_Declarations
;
8403 ---------------------------------
8404 -- Has_Defaulted_Discriminants --
8405 ---------------------------------
8407 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
8409 return Has_Discriminants
(Typ
)
8410 and then Present
(First_Discriminant
(Typ
))
8411 and then Present
(Discriminant_Default_Value
8412 (First_Discriminant
(Typ
)));
8413 end Has_Defaulted_Discriminants
;
8419 function Has_Denormals
(E
: Entity_Id
) return Boolean is
8421 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
8424 -------------------------------------------
8425 -- Has_Discriminant_Dependent_Constraint --
8426 -------------------------------------------
8428 function Has_Discriminant_Dependent_Constraint
8429 (Comp
: Entity_Id
) return Boolean
8431 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
8432 Subt_Indic
: Node_Id
;
8437 -- Discriminants can't depend on discriminants
8439 if Ekind
(Comp
) = E_Discriminant
then
8443 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
8445 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
8446 Constr
:= Constraint
(Subt_Indic
);
8448 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
8449 Assn
:= First
(Constraints
(Constr
));
8450 while Present
(Assn
) loop
8451 case Nkind
(Assn
) is
8452 when N_Subtype_Indication |
8456 if Depends_On_Discriminant
(Assn
) then
8460 when N_Discriminant_Association
=>
8461 if Depends_On_Discriminant
(Expression
(Assn
)) then
8476 end Has_Discriminant_Dependent_Constraint
;
8478 --------------------------
8479 -- Has_Enabled_Property --
8480 --------------------------
8482 function Has_Enabled_Property
8483 (Item_Id
: Entity_Id
;
8484 Property
: Name_Id
) return Boolean
8486 function State_Has_Enabled_Property
return Boolean;
8487 -- Determine whether a state denoted by Item_Id has the property enabled
8489 function Variable_Has_Enabled_Property
return Boolean;
8490 -- Determine whether a variable denoted by Item_Id has the property
8493 --------------------------------
8494 -- State_Has_Enabled_Property --
8495 --------------------------------
8497 function State_Has_Enabled_Property
return Boolean is
8498 Decl
: constant Node_Id
:= Parent
(Item_Id
);
8506 -- The declaration of an external abstract state appears as an
8507 -- extension aggregate. If this is not the case, properties can never
8510 if Nkind
(Decl
) /= N_Extension_Aggregate
then
8514 -- When External appears as a simple option, it automatically enables
8517 Opt
:= First
(Expressions
(Decl
));
8518 while Present
(Opt
) loop
8519 if Nkind
(Opt
) = N_Identifier
8520 and then Chars
(Opt
) = Name_External
8528 -- When External specifies particular properties, inspect those and
8529 -- find the desired one (if any).
8531 Opt
:= First
(Component_Associations
(Decl
));
8532 while Present
(Opt
) loop
8533 Opt_Nam
:= First
(Choices
(Opt
));
8535 if Nkind
(Opt_Nam
) = N_Identifier
8536 and then Chars
(Opt_Nam
) = Name_External
8538 Props
:= Expression
(Opt
);
8540 -- Multiple properties appear as an aggregate
8542 if Nkind
(Props
) = N_Aggregate
then
8544 -- Simple property form
8546 Prop
:= First
(Expressions
(Props
));
8547 while Present
(Prop
) loop
8548 if Chars
(Prop
) = Property
then
8555 -- Property with expression form
8557 Prop
:= First
(Component_Associations
(Props
));
8558 while Present
(Prop
) loop
8559 Prop_Nam
:= First
(Choices
(Prop
));
8561 -- The property can be represented in two ways:
8562 -- others => <value>
8563 -- <property> => <value>
8565 if Nkind
(Prop_Nam
) = N_Others_Choice
8566 or else (Nkind
(Prop_Nam
) = N_Identifier
8567 and then Chars
(Prop_Nam
) = Property
)
8569 return Is_True
(Expr_Value
(Expression
(Prop
)));
8578 return Chars
(Props
) = Property
;
8586 end State_Has_Enabled_Property
;
8588 -----------------------------------
8589 -- Variable_Has_Enabled_Property --
8590 -----------------------------------
8592 function Variable_Has_Enabled_Property
return Boolean is
8593 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
8594 -- Determine whether property pragma Prag (if present) denotes an
8595 -- enabled property.
8601 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
8605 if Present
(Prag
) then
8606 Arg2
:= Next
(First
(Pragma_Argument_Associations
(Prag
)));
8608 -- The pragma has an optional Boolean expression, the related
8609 -- property is enabled only when the expression evaluates to
8612 if Present
(Arg2
) then
8613 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg2
)));
8615 -- Otherwise the lack of expression enables the property by
8622 -- The property was never set in the first place
8631 AR
: constant Node_Id
:=
8632 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
8633 AW
: constant Node_Id
:=
8634 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
8635 ER
: constant Node_Id
:=
8636 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
8637 EW
: constant Node_Id
:=
8638 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
8640 -- Start of processing for Variable_Has_Enabled_Property
8643 -- A non-effectively volatile object can never possess external
8646 if not Is_Effectively_Volatile
(Item_Id
) then
8649 -- External properties related to variables come in two flavors -
8650 -- explicit and implicit. The explicit case is characterized by the
8651 -- presence of a property pragma with an optional Boolean flag. The
8652 -- property is enabled when the flag evaluates to True or the flag is
8653 -- missing altogether.
8655 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
8658 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
8661 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
8664 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
8667 -- The implicit case lacks all property pragmas
8669 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
8675 end Variable_Has_Enabled_Property
;
8677 -- Start of processing for Has_Enabled_Property
8680 -- Abstract states and variables have a flexible scheme of specifying
8681 -- external properties.
8683 if Ekind
(Item_Id
) = E_Abstract_State
then
8684 return State_Has_Enabled_Property
;
8686 elsif Ekind
(Item_Id
) = E_Variable
then
8687 return Variable_Has_Enabled_Property
;
8689 -- Otherwise a property is enabled when the related item is effectively
8693 return Is_Effectively_Volatile
(Item_Id
);
8695 end Has_Enabled_Property
;
8697 --------------------
8698 -- Has_Infinities --
8699 --------------------
8701 function Has_Infinities
(E
: Entity_Id
) return Boolean is
8704 Is_Floating_Point_Type
(E
)
8705 and then Nkind
(Scalar_Range
(E
)) = N_Range
8706 and then Includes_Infinities
(Scalar_Range
(E
));
8709 --------------------
8710 -- Has_Interfaces --
8711 --------------------
8713 function Has_Interfaces
8715 Use_Full_View
: Boolean := True) return Boolean
8717 Typ
: Entity_Id
:= Base_Type
(T
);
8720 -- Handle concurrent types
8722 if Is_Concurrent_Type
(Typ
) then
8723 Typ
:= Corresponding_Record_Type
(Typ
);
8726 if not Present
(Typ
)
8727 or else not Is_Record_Type
(Typ
)
8728 or else not Is_Tagged_Type
(Typ
)
8733 -- Handle private types
8735 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
8736 Typ
:= Full_View
(Typ
);
8739 -- Handle concurrent record types
8741 if Is_Concurrent_Record_Type
(Typ
)
8742 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
8748 if Is_Interface
(Typ
)
8750 (Is_Record_Type
(Typ
)
8751 and then Present
(Interfaces
(Typ
))
8752 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
8757 exit when Etype
(Typ
) = Typ
8759 -- Handle private types
8761 or else (Present
(Full_View
(Etype
(Typ
)))
8762 and then Full_View
(Etype
(Typ
)) = Typ
)
8764 -- Protect frontend against wrong sources with cyclic derivations
8766 or else Etype
(Typ
) = T
;
8768 -- Climb to the ancestor type handling private types
8770 if Present
(Full_View
(Etype
(Typ
))) then
8771 Typ
:= Full_View
(Etype
(Typ
));
8780 ---------------------------------
8781 -- Has_No_Obvious_Side_Effects --
8782 ---------------------------------
8784 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
8786 -- For now, just handle literals, constants, and non-volatile
8787 -- variables and expressions combining these with operators or
8788 -- short circuit forms.
8790 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
8793 elsif Nkind
(N
) = N_Character_Literal
then
8796 elsif Nkind
(N
) in N_Unary_Op
then
8797 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8799 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
8800 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
8802 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
8804 elsif Nkind
(N
) = N_Expression_With_Actions
8805 and then Is_Empty_List
(Actions
(N
))
8807 return Has_No_Obvious_Side_Effects
(Expression
(N
));
8809 elsif Nkind
(N
) in N_Has_Entity
then
8810 return Present
(Entity
(N
))
8811 and then Ekind_In
(Entity
(N
), E_Variable
,
8813 E_Enumeration_Literal
,
8817 and then not Is_Volatile
(Entity
(N
));
8822 end Has_No_Obvious_Side_Effects
;
8824 ------------------------
8825 -- Has_Null_Exclusion --
8826 ------------------------
8828 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
8831 when N_Access_Definition |
8832 N_Access_Function_Definition |
8833 N_Access_Procedure_Definition |
8834 N_Access_To_Object_Definition |
8836 N_Derived_Type_Definition |
8837 N_Function_Specification |
8838 N_Subtype_Declaration
=>
8839 return Null_Exclusion_Present
(N
);
8841 when N_Component_Definition |
8842 N_Formal_Object_Declaration |
8843 N_Object_Renaming_Declaration
=>
8844 if Present
(Subtype_Mark
(N
)) then
8845 return Null_Exclusion_Present
(N
);
8846 else pragma Assert
(Present
(Access_Definition
(N
)));
8847 return Null_Exclusion_Present
(Access_Definition
(N
));
8850 when N_Discriminant_Specification
=>
8851 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
8852 return Null_Exclusion_Present
(Discriminant_Type
(N
));
8854 return Null_Exclusion_Present
(N
);
8857 when N_Object_Declaration
=>
8858 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
8859 return Null_Exclusion_Present
(Object_Definition
(N
));
8861 return Null_Exclusion_Present
(N
);
8864 when N_Parameter_Specification
=>
8865 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
8866 return Null_Exclusion_Present
(Parameter_Type
(N
));
8868 return Null_Exclusion_Present
(N
);
8875 end Has_Null_Exclusion
;
8877 ------------------------
8878 -- Has_Null_Extension --
8879 ------------------------
8881 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
8882 B
: constant Entity_Id
:= Base_Type
(T
);
8887 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
8888 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
8890 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
8892 if Present
(Ext
) then
8893 if Null_Present
(Ext
) then
8896 Comps
:= Component_List
(Ext
);
8898 -- The null component list is rewritten during analysis to
8899 -- include the parent component. Any other component indicates
8900 -- that the extension was not originally null.
8902 return Null_Present
(Comps
)
8903 or else No
(Next
(First
(Component_Items
(Comps
))));
8912 end Has_Null_Extension
;
8914 -------------------------------
8915 -- Has_Overriding_Initialize --
8916 -------------------------------
8918 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
8919 BT
: constant Entity_Id
:= Base_Type
(T
);
8923 if Is_Controlled
(BT
) then
8924 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
8927 elsif Present
(Primitive_Operations
(BT
)) then
8928 P
:= First_Elmt
(Primitive_Operations
(BT
));
8929 while Present
(P
) loop
8931 Init
: constant Entity_Id
:= Node
(P
);
8932 Formal
: constant Entity_Id
:= First_Formal
(Init
);
8934 if Ekind
(Init
) = E_Procedure
8935 and then Chars
(Init
) = Name_Initialize
8936 and then Comes_From_Source
(Init
)
8937 and then Present
(Formal
)
8938 and then Etype
(Formal
) = BT
8939 and then No
(Next_Formal
(Formal
))
8940 and then (Ada_Version
< Ada_2012
8941 or else not Null_Present
(Parent
(Init
)))
8951 -- Here if type itself does not have a non-null Initialize operation:
8952 -- check immediate ancestor.
8954 if Is_Derived_Type
(BT
)
8955 and then Has_Overriding_Initialize
(Etype
(BT
))
8962 end Has_Overriding_Initialize
;
8964 --------------------------------------
8965 -- Has_Preelaborable_Initialization --
8966 --------------------------------------
8968 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
8971 procedure Check_Components
(E
: Entity_Id
);
8972 -- Check component/discriminant chain, sets Has_PE False if a component
8973 -- or discriminant does not meet the preelaborable initialization rules.
8975 ----------------------
8976 -- Check_Components --
8977 ----------------------
8979 procedure Check_Components
(E
: Entity_Id
) is
8983 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
8984 -- Returns True if and only if the expression denoted by N does not
8985 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
8987 ---------------------------------
8988 -- Is_Preelaborable_Expression --
8989 ---------------------------------
8991 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
8995 Comp_Type
: Entity_Id
;
8996 Is_Array_Aggr
: Boolean;
8999 if Is_OK_Static_Expression
(N
) then
9002 elsif Nkind
(N
) = N_Null
then
9005 -- Attributes are allowed in general, even if their prefix is a
9006 -- formal type. (It seems that certain attributes known not to be
9007 -- static might not be allowed, but there are no rules to prevent
9010 elsif Nkind
(N
) = N_Attribute_Reference
then
9013 -- The name of a discriminant evaluated within its parent type is
9014 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9015 -- names that denote discriminals as well as discriminants to
9016 -- catch references occurring within init procs.
9018 elsif Is_Entity_Name
(N
)
9020 (Ekind
(Entity
(N
)) = E_Discriminant
9021 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
9022 and then Present
(Discriminal_Link
(Entity
(N
)))))
9026 elsif Nkind
(N
) = N_Qualified_Expression
then
9027 return Is_Preelaborable_Expression
(Expression
(N
));
9029 -- For aggregates we have to check that each of the associations
9030 -- is preelaborable.
9032 elsif Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
9033 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
9035 if Is_Array_Aggr
then
9036 Comp_Type
:= Component_Type
(Etype
(N
));
9039 -- Check the ancestor part of extension aggregates, which must
9040 -- be either the name of a type that has preelaborable init or
9041 -- an expression that is preelaborable.
9043 if Nkind
(N
) = N_Extension_Aggregate
then
9045 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
9048 if Is_Entity_Name
(Anc_Part
)
9049 and then Is_Type
(Entity
(Anc_Part
))
9051 if not Has_Preelaborable_Initialization
9057 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
9063 -- Check positional associations
9065 Exp
:= First
(Expressions
(N
));
9066 while Present
(Exp
) loop
9067 if not Is_Preelaborable_Expression
(Exp
) then
9074 -- Check named associations
9076 Assn
:= First
(Component_Associations
(N
));
9077 while Present
(Assn
) loop
9078 Choice
:= First
(Choices
(Assn
));
9079 while Present
(Choice
) loop
9080 if Is_Array_Aggr
then
9081 if Nkind
(Choice
) = N_Others_Choice
then
9084 elsif Nkind
(Choice
) = N_Range
then
9085 if not Is_OK_Static_Range
(Choice
) then
9089 elsif not Is_OK_Static_Expression
(Choice
) then
9094 Comp_Type
:= Etype
(Choice
);
9100 -- If the association has a <> at this point, then we have
9101 -- to check whether the component's type has preelaborable
9102 -- initialization. Note that this only occurs when the
9103 -- association's corresponding component does not have a
9104 -- default expression, the latter case having already been
9105 -- expanded as an expression for the association.
9107 if Box_Present
(Assn
) then
9108 if not Has_Preelaborable_Initialization
(Comp_Type
) then
9112 -- In the expression case we check whether the expression
9113 -- is preelaborable.
9116 not Is_Preelaborable_Expression
(Expression
(Assn
))
9124 -- If we get here then aggregate as a whole is preelaborable
9128 -- All other cases are not preelaborable
9133 end Is_Preelaborable_Expression
;
9135 -- Start of processing for Check_Components
9138 -- Loop through entities of record or protected type
9141 while Present
(Ent
) loop
9143 -- We are interested only in components and discriminants
9150 -- Get default expression if any. If there is no declaration
9151 -- node, it means we have an internal entity. The parent and
9152 -- tag fields are examples of such entities. For such cases,
9153 -- we just test the type of the entity.
9155 if Present
(Declaration_Node
(Ent
)) then
9156 Exp
:= Expression
(Declaration_Node
(Ent
));
9159 when E_Discriminant
=>
9161 -- Note: for a renamed discriminant, the Declaration_Node
9162 -- may point to the one from the ancestor, and have a
9163 -- different expression, so use the proper attribute to
9164 -- retrieve the expression from the derived constraint.
9166 Exp
:= Discriminant_Default_Value
(Ent
);
9169 goto Check_Next_Entity
;
9172 -- A component has PI if it has no default expression and the
9173 -- component type has PI.
9176 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
9181 -- Require the default expression to be preelaborable
9183 elsif not Is_Preelaborable_Expression
(Exp
) then
9188 <<Check_Next_Entity
>>
9191 end Check_Components
;
9193 -- Start of processing for Has_Preelaborable_Initialization
9196 -- Immediate return if already marked as known preelaborable init. This
9197 -- covers types for which this function has already been called once
9198 -- and returned True (in which case the result is cached), and also
9199 -- types to which a pragma Preelaborable_Initialization applies.
9201 if Known_To_Have_Preelab_Init
(E
) then
9205 -- If the type is a subtype representing a generic actual type, then
9206 -- test whether its base type has preelaborable initialization since
9207 -- the subtype representing the actual does not inherit this attribute
9208 -- from the actual or formal. (but maybe it should???)
9210 if Is_Generic_Actual_Type
(E
) then
9211 return Has_Preelaborable_Initialization
(Base_Type
(E
));
9214 -- All elementary types have preelaborable initialization
9216 if Is_Elementary_Type
(E
) then
9219 -- Array types have PI if the component type has PI
9221 elsif Is_Array_Type
(E
) then
9222 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
9224 -- A derived type has preelaborable initialization if its parent type
9225 -- has preelaborable initialization and (in the case of a derived record
9226 -- extension) if the non-inherited components all have preelaborable
9227 -- initialization. However, a user-defined controlled type with an
9228 -- overriding Initialize procedure does not have preelaborable
9231 elsif Is_Derived_Type
(E
) then
9233 -- If the derived type is a private extension then it doesn't have
9234 -- preelaborable initialization.
9236 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
9240 -- First check whether ancestor type has preelaborable initialization
9242 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
9244 -- If OK, check extension components (if any)
9246 if Has_PE
and then Is_Record_Type
(E
) then
9247 Check_Components
(First_Entity
(E
));
9250 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
9251 -- with a user defined Initialize procedure does not have PI. If
9252 -- the type is untagged, the control primitives come from a component
9253 -- that has already been checked.
9256 and then Is_Controlled
(E
)
9257 and then Is_Tagged_Type
(E
)
9258 and then Has_Overriding_Initialize
(E
)
9263 -- Private types not derived from a type having preelaborable init and
9264 -- that are not marked with pragma Preelaborable_Initialization do not
9265 -- have preelaborable initialization.
9267 elsif Is_Private_Type
(E
) then
9270 -- Record type has PI if it is non private and all components have PI
9272 elsif Is_Record_Type
(E
) then
9274 Check_Components
(First_Entity
(E
));
9276 -- Protected types must not have entries, and components must meet
9277 -- same set of rules as for record components.
9279 elsif Is_Protected_Type
(E
) then
9280 if Has_Entries
(E
) then
9284 Check_Components
(First_Entity
(E
));
9285 Check_Components
(First_Private_Entity
(E
));
9288 -- Type System.Address always has preelaborable initialization
9290 elsif Is_RTE
(E
, RE_Address
) then
9293 -- In all other cases, type does not have preelaborable initialization
9299 -- If type has preelaborable initialization, cache result
9302 Set_Known_To_Have_Preelab_Init
(E
);
9306 end Has_Preelaborable_Initialization
;
9308 ---------------------------
9309 -- Has_Private_Component --
9310 ---------------------------
9312 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
9313 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
9314 Component
: Entity_Id
;
9317 if Error_Posted
(Type_Id
)
9318 or else Error_Posted
(Btype
)
9323 if Is_Class_Wide_Type
(Btype
) then
9324 Btype
:= Root_Type
(Btype
);
9327 if Is_Private_Type
(Btype
) then
9329 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
9332 if No
(Full_View
(Btype
)) then
9333 return not Is_Generic_Type
(Btype
)
9335 not Is_Generic_Type
(Root_Type
(Btype
));
9337 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
9340 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
9344 elsif Is_Array_Type
(Btype
) then
9345 return Has_Private_Component
(Component_Type
(Btype
));
9347 elsif Is_Record_Type
(Btype
) then
9348 Component
:= First_Component
(Btype
);
9349 while Present
(Component
) loop
9350 if Has_Private_Component
(Etype
(Component
)) then
9354 Next_Component
(Component
);
9359 elsif Is_Protected_Type
(Btype
)
9360 and then Present
(Corresponding_Record_Type
(Btype
))
9362 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
9367 end Has_Private_Component
;
9369 ----------------------
9370 -- Has_Signed_Zeros --
9371 ----------------------
9373 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
9375 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
9376 end Has_Signed_Zeros
;
9378 ------------------------------
9379 -- Has_Significant_Contract --
9380 ------------------------------
9382 function Has_Significant_Contract
(Subp_Id
: Entity_Id
) return Boolean is
9383 Subp_Nam
: constant Name_Id
:= Chars
(Subp_Id
);
9386 -- _Finalizer procedure
9388 if Subp_Nam
= Name_uFinalizer
then
9391 -- _Postconditions procedure
9393 elsif Subp_Nam
= Name_uPostconditions
then
9396 -- Predicate function
9398 elsif Ekind
(Subp_Id
) = E_Function
9399 and then Is_Predicate_Function
(Subp_Id
)
9405 elsif Get_TSS_Name
(Subp_Id
) /= TSS_Null
then
9411 end Has_Significant_Contract
;
9413 -----------------------------
9414 -- Has_Static_Array_Bounds --
9415 -----------------------------
9417 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
9418 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
9425 -- Unconstrained types do not have static bounds
9427 if not Is_Constrained
(Typ
) then
9431 -- First treat string literals specially, as the lower bound and length
9432 -- of string literals are not stored like those of arrays.
9434 -- A string literal always has static bounds
9436 if Ekind
(Typ
) = E_String_Literal_Subtype
then
9440 -- Treat all dimensions in turn
9442 Index
:= First_Index
(Typ
);
9443 for Indx
in 1 .. Ndims
loop
9445 -- In case of an illegal index which is not a discrete type, return
9446 -- that the type is not static.
9448 if not Is_Discrete_Type
(Etype
(Index
))
9449 or else Etype
(Index
) = Any_Type
9454 Get_Index_Bounds
(Index
, Low
, High
);
9456 if Error_Posted
(Low
) or else Error_Posted
(High
) then
9460 if Is_OK_Static_Expression
(Low
)
9462 Is_OK_Static_Expression
(High
)
9472 -- If we fall through the loop, all indexes matched
9475 end Has_Static_Array_Bounds
;
9481 function Has_Stream
(T
: Entity_Id
) return Boolean is
9488 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
9491 elsif Is_Array_Type
(T
) then
9492 return Has_Stream
(Component_Type
(T
));
9494 elsif Is_Record_Type
(T
) then
9495 E
:= First_Component
(T
);
9496 while Present
(E
) loop
9497 if Has_Stream
(Etype
(E
)) then
9506 elsif Is_Private_Type
(T
) then
9507 return Has_Stream
(Underlying_Type
(T
));
9518 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
9520 Get_Name_String
(Chars
(E
));
9521 return Name_Buffer
(Name_Len
) = Suffix
;
9528 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
9530 Get_Name_String
(Chars
(E
));
9531 Add_Char_To_Name_Buffer
(Suffix
);
9539 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
9541 pragma Assert
(Has_Suffix
(E
, Suffix
));
9542 Get_Name_String
(Chars
(E
));
9543 Name_Len
:= Name_Len
- 1;
9547 --------------------------
9548 -- Has_Tagged_Component --
9549 --------------------------
9551 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
9555 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
9556 return Has_Tagged_Component
(Underlying_Type
(Typ
));
9558 elsif Is_Array_Type
(Typ
) then
9559 return Has_Tagged_Component
(Component_Type
(Typ
));
9561 elsif Is_Tagged_Type
(Typ
) then
9564 elsif Is_Record_Type
(Typ
) then
9565 Comp
:= First_Component
(Typ
);
9566 while Present
(Comp
) loop
9567 if Has_Tagged_Component
(Etype
(Comp
)) then
9571 Next_Component
(Comp
);
9579 end Has_Tagged_Component
;
9581 ----------------------------
9582 -- Has_Volatile_Component --
9583 ----------------------------
9585 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
9589 if Has_Volatile_Components
(Typ
) then
9592 elsif Is_Array_Type
(Typ
) then
9593 return Is_Volatile
(Component_Type
(Typ
));
9595 elsif Is_Record_Type
(Typ
) then
9596 Comp
:= First_Component
(Typ
);
9597 while Present
(Comp
) loop
9598 if Is_Volatile_Object
(Comp
) then
9602 Comp
:= Next_Component
(Comp
);
9607 end Has_Volatile_Component
;
9609 -------------------------
9610 -- Implementation_Kind --
9611 -------------------------
9613 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
9614 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
9617 pragma Assert
(Present
(Impl_Prag
));
9618 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
9619 return Chars
(Get_Pragma_Arg
(Arg
));
9620 end Implementation_Kind
;
9622 --------------------------
9623 -- Implements_Interface --
9624 --------------------------
9626 function Implements_Interface
9627 (Typ_Ent
: Entity_Id
;
9628 Iface_Ent
: Entity_Id
;
9629 Exclude_Parents
: Boolean := False) return Boolean
9631 Ifaces_List
: Elist_Id
;
9633 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
9634 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
9637 if Is_Class_Wide_Type
(Typ
) then
9638 Typ
:= Root_Type
(Typ
);
9641 if not Has_Interfaces
(Typ
) then
9645 if Is_Class_Wide_Type
(Iface
) then
9646 Iface
:= Root_Type
(Iface
);
9649 Collect_Interfaces
(Typ
, Ifaces_List
);
9651 Elmt
:= First_Elmt
(Ifaces_List
);
9652 while Present
(Elmt
) loop
9653 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
9654 and then Exclude_Parents
9658 elsif Node
(Elmt
) = Iface
then
9666 end Implements_Interface
;
9668 ------------------------------------
9669 -- In_Assertion_Expression_Pragma --
9670 ------------------------------------
9672 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
9674 Prag
: Node_Id
:= Empty
;
9677 -- Climb the parent chain looking for an enclosing pragma
9680 while Present
(Par
) loop
9681 if Nkind
(Par
) = N_Pragma
then
9685 -- Precondition-like pragmas are expanded into if statements, check
9686 -- the original node instead.
9688 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
9689 Prag
:= Original_Node
(Par
);
9692 -- The expansion of attribute 'Old generates a constant to capture
9693 -- the result of the prefix. If the parent traversal reaches
9694 -- one of these constants, then the node technically came from a
9695 -- postcondition-like pragma. Note that the Ekind is not tested here
9696 -- because N may be the expression of an object declaration which is
9697 -- currently being analyzed. Such objects carry Ekind of E_Void.
9699 elsif Nkind
(Par
) = N_Object_Declaration
9700 and then Constant_Present
(Par
)
9701 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
9705 -- Prevent the search from going too far
9707 elsif Is_Body_Or_Package_Declaration
(Par
) then
9711 Par
:= Parent
(Par
);
9716 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
9717 end In_Assertion_Expression_Pragma
;
9723 function In_Instance
return Boolean is
9724 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
9729 while Present
(S
) and then S
/= Standard_Standard
loop
9730 if Ekind_In
(S
, E_Function
, E_Package
, E_Procedure
)
9731 and then Is_Generic_Instance
(S
)
9733 -- A child instance is always compiled in the context of a parent
9734 -- instance. Nevertheless, the actuals are not analyzed in an
9735 -- instance context. We detect this case by examining the current
9736 -- compilation unit, which must be a child instance, and checking
9737 -- that it is not currently on the scope stack.
9739 if Is_Child_Unit
(Curr_Unit
)
9740 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
9741 N_Package_Instantiation
9742 and then not In_Open_Scopes
(Curr_Unit
)
9756 ----------------------
9757 -- In_Instance_Body --
9758 ----------------------
9760 function In_Instance_Body
return Boolean is
9765 while Present
(S
) and then S
/= Standard_Standard
loop
9766 if Ekind_In
(S
, E_Function
, E_Procedure
)
9767 and then Is_Generic_Instance
(S
)
9771 elsif Ekind
(S
) = E_Package
9772 and then In_Package_Body
(S
)
9773 and then Is_Generic_Instance
(S
)
9782 end In_Instance_Body
;
9784 -----------------------------
9785 -- In_Instance_Not_Visible --
9786 -----------------------------
9788 function In_Instance_Not_Visible
return Boolean is
9793 while Present
(S
) and then S
/= Standard_Standard
loop
9794 if Ekind_In
(S
, E_Function
, E_Procedure
)
9795 and then Is_Generic_Instance
(S
)
9799 elsif Ekind
(S
) = E_Package
9800 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
9801 and then Is_Generic_Instance
(S
)
9810 end In_Instance_Not_Visible
;
9812 ------------------------------
9813 -- In_Instance_Visible_Part --
9814 ------------------------------
9816 function In_Instance_Visible_Part
return Boolean is
9821 while Present
(S
) and then S
/= Standard_Standard
loop
9822 if Ekind
(S
) = E_Package
9823 and then Is_Generic_Instance
(S
)
9824 and then not In_Package_Body
(S
)
9825 and then not In_Private_Part
(S
)
9834 end In_Instance_Visible_Part
;
9836 ---------------------
9837 -- In_Package_Body --
9838 ---------------------
9840 function In_Package_Body
return Boolean is
9845 while Present
(S
) and then S
/= Standard_Standard
loop
9846 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
9854 end In_Package_Body
;
9856 --------------------------------
9857 -- In_Parameter_Specification --
9858 --------------------------------
9860 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
9865 while Present
(PN
) loop
9866 if Nkind
(PN
) = N_Parameter_Specification
then
9874 end In_Parameter_Specification
;
9876 --------------------------
9877 -- In_Pragma_Expression --
9878 --------------------------
9880 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
9887 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
9893 end In_Pragma_Expression
;
9895 -------------------------------------
9896 -- In_Reverse_Storage_Order_Object --
9897 -------------------------------------
9899 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
9901 Btyp
: Entity_Id
:= Empty
;
9904 -- Climb up indexed components
9908 case Nkind
(Pref
) is
9909 when N_Selected_Component
=>
9910 Pref
:= Prefix
(Pref
);
9913 when N_Indexed_Component
=>
9914 Pref
:= Prefix
(Pref
);
9922 if Present
(Pref
) then
9923 Btyp
:= Base_Type
(Etype
(Pref
));
9926 return Present
(Btyp
)
9927 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
9928 and then Reverse_Storage_Order
(Btyp
);
9929 end In_Reverse_Storage_Order_Object
;
9931 --------------------------------------
9932 -- In_Subprogram_Or_Concurrent_Unit --
9933 --------------------------------------
9935 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
9940 -- Use scope chain to check successively outer scopes
9946 if K
in Subprogram_Kind
9947 or else K
in Concurrent_Kind
9948 or else K
in Generic_Subprogram_Kind
9952 elsif E
= Standard_Standard
then
9958 end In_Subprogram_Or_Concurrent_Unit
;
9960 ---------------------
9961 -- In_Visible_Part --
9962 ---------------------
9964 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
9966 return Is_Package_Or_Generic_Package
(Scope_Id
)
9967 and then In_Open_Scopes
(Scope_Id
)
9968 and then not In_Package_Body
(Scope_Id
)
9969 and then not In_Private_Part
(Scope_Id
);
9970 end In_Visible_Part
;
9972 --------------------------------
9973 -- Incomplete_Or_Partial_View --
9974 --------------------------------
9976 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
9977 function Inspect_Decls
9979 Taft
: Boolean := False) return Entity_Id
;
9980 -- Check whether a declarative region contains the incomplete or partial
9987 function Inspect_Decls
9989 Taft
: Boolean := False) return Entity_Id
9995 Decl
:= First
(Decls
);
9996 while Present
(Decl
) loop
10000 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
10001 Match
:= Defining_Identifier
(Decl
);
10005 if Nkind_In
(Decl
, N_Private_Extension_Declaration
,
10006 N_Private_Type_Declaration
)
10008 Match
:= Defining_Identifier
(Decl
);
10013 and then Present
(Full_View
(Match
))
10014 and then Full_View
(Match
) = Id
10029 -- Start of processing for Incomplete_Or_Partial_View
10032 -- Deferred constant or incomplete type case
10034 Prev
:= Current_Entity_In_Scope
(Id
);
10037 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
10038 and then Present
(Full_View
(Prev
))
10039 and then Full_View
(Prev
) = Id
10044 -- Private or Taft amendment type case
10047 Pkg
: constant Entity_Id
:= Scope
(Id
);
10048 Pkg_Decl
: Node_Id
:= Pkg
;
10051 if Present
(Pkg
) and then Ekind
(Pkg
) = E_Package
then
10052 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
10053 Pkg_Decl
:= Parent
(Pkg_Decl
);
10056 -- It is knows that Typ has a private view, look for it in the
10057 -- visible declarations of the enclosing scope. A special case
10058 -- of this is when the two views have been exchanged - the full
10059 -- appears earlier than the private.
10061 if Has_Private_Declaration
(Id
) then
10062 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
10064 -- Exchanged view case, look in the private declarations
10067 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
10072 -- Otherwise if this is the package body, then Typ is a potential
10073 -- Taft amendment type. The incomplete view should be located in
10074 -- the private declarations of the enclosing scope.
10076 elsif In_Package_Body
(Pkg
) then
10077 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
10082 -- The type has no incomplete or private view
10085 end Incomplete_Or_Partial_View
;
10087 -----------------------------------------
10088 -- Inherit_Default_Init_Cond_Procedure --
10089 -----------------------------------------
10091 procedure Inherit_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
10092 Par_Typ
: constant Entity_Id
:= Etype
(Typ
);
10095 -- A derived type inherits the default initial condition procedure of
10096 -- its parent type.
10098 if No
(Default_Init_Cond_Procedure
(Typ
)) then
10099 Set_Default_Init_Cond_Procedure
10100 (Typ
, Default_Init_Cond_Procedure
(Par_Typ
));
10102 end Inherit_Default_Init_Cond_Procedure
;
10104 ----------------------------
10105 -- Inherit_Rep_Item_Chain --
10106 ----------------------------
10108 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
10109 From_Item
: constant Node_Id
:= First_Rep_Item
(From_Typ
);
10110 Item
: Node_Id
:= Empty
;
10111 Last_Item
: Node_Id
:= Empty
;
10114 -- Reach the end of the destination type's chain (if any) and capture
10117 Item
:= First_Rep_Item
(Typ
);
10118 while Present
(Item
) loop
10120 -- Do not inherit a chain that has been inherited already
10122 if Item
= From_Item
then
10127 Item
:= Next_Rep_Item
(Item
);
10130 -- When the destination type has a rep item chain, the chain of the
10131 -- source type is appended to it.
10133 if Present
(Last_Item
) then
10134 Set_Next_Rep_Item
(Last_Item
, From_Item
);
10136 -- Otherwise the destination type directly inherits the rep item chain
10137 -- of the source type (if any).
10140 Set_First_Rep_Item
(Typ
, From_Item
);
10142 end Inherit_Rep_Item_Chain
;
10144 ---------------------------------
10145 -- Inherit_Subprogram_Contract --
10146 ---------------------------------
10148 procedure Inherit_Subprogram_Contract
10150 From_Subp
: Entity_Id
)
10152 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
);
10153 -- Propagate a pragma denoted by Prag_Id from From_Subp's contract to
10154 -- Subp's contract.
10156 --------------------
10157 -- Inherit_Pragma --
10158 --------------------
10160 procedure Inherit_Pragma
(Prag_Id
: Pragma_Id
) is
10161 Prag
: constant Node_Id
:= Get_Pragma
(From_Subp
, Prag_Id
);
10162 New_Prag
: Node_Id
;
10165 -- A pragma cannot be part of more than one First_Pragma/Next_Pragma
10166 -- chains, therefore the node must be replicated. The new pragma is
10167 -- flagged is inherited for distrinction purposes.
10169 if Present
(Prag
) then
10170 New_Prag
:= New_Copy_Tree
(Prag
);
10171 Set_Is_Inherited
(New_Prag
);
10173 Add_Contract_Item
(New_Prag
, Subp
);
10175 end Inherit_Pragma
;
10177 -- Start of processing for Inherit_Subprogram_Contract
10180 -- Inheritance is carried out only when both entities are subprograms
10183 if Is_Subprogram_Or_Generic_Subprogram
(Subp
)
10184 and then Is_Subprogram_Or_Generic_Subprogram
(From_Subp
)
10185 and then Present
(Contract
(From_Subp
))
10187 Inherit_Pragma
(Pragma_Extensions_Visible
);
10189 end Inherit_Subprogram_Contract
;
10191 ---------------------------------
10192 -- Insert_Explicit_Dereference --
10193 ---------------------------------
10195 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
10196 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
10197 Ent
: Entity_Id
:= Empty
;
10204 Save_Interps
(N
, New_Prefix
);
10207 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
10208 Prefix
=> New_Prefix
));
10210 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
10212 if Is_Overloaded
(New_Prefix
) then
10214 -- The dereference is also overloaded, and its interpretations are
10215 -- the designated types of the interpretations of the original node.
10217 Set_Etype
(N
, Any_Type
);
10219 Get_First_Interp
(New_Prefix
, I
, It
);
10220 while Present
(It
.Nam
) loop
10223 if Is_Access_Type
(T
) then
10224 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
10227 Get_Next_Interp
(I
, It
);
10233 -- Prefix is unambiguous: mark the original prefix (which might
10234 -- Come_From_Source) as a reference, since the new (relocated) one
10235 -- won't be taken into account.
10237 if Is_Entity_Name
(New_Prefix
) then
10238 Ent
:= Entity
(New_Prefix
);
10239 Pref
:= New_Prefix
;
10241 -- For a retrieval of a subcomponent of some composite object,
10242 -- retrieve the ultimate entity if there is one.
10244 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
10245 N_Indexed_Component
)
10247 Pref
:= Prefix
(New_Prefix
);
10248 while Present
(Pref
)
10249 and then Nkind_In
(Pref
, N_Selected_Component
,
10250 N_Indexed_Component
)
10252 Pref
:= Prefix
(Pref
);
10255 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
10256 Ent
:= Entity
(Pref
);
10260 -- Place the reference on the entity node
10262 if Present
(Ent
) then
10263 Generate_Reference
(Ent
, Pref
);
10266 end Insert_Explicit_Dereference
;
10268 ------------------------------------------
10269 -- Inspect_Deferred_Constant_Completion --
10270 ------------------------------------------
10272 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
10276 Decl
:= First
(Decls
);
10277 while Present
(Decl
) loop
10279 -- Deferred constant signature
10281 if Nkind
(Decl
) = N_Object_Declaration
10282 and then Constant_Present
(Decl
)
10283 and then No
(Expression
(Decl
))
10285 -- No need to check internally generated constants
10287 and then Comes_From_Source
(Decl
)
10289 -- The constant is not completed. A full object declaration or a
10290 -- pragma Import complete a deferred constant.
10292 and then not Has_Completion
(Defining_Identifier
(Decl
))
10295 ("constant declaration requires initialization expression",
10296 Defining_Identifier
(Decl
));
10299 Decl
:= Next
(Decl
);
10301 end Inspect_Deferred_Constant_Completion
;
10303 -----------------------------
10304 -- Install_Generic_Formals --
10305 -----------------------------
10307 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
10311 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
10313 E
:= First_Entity
(Subp_Id
);
10314 while Present
(E
) loop
10315 Install_Entity
(E
);
10318 end Install_Generic_Formals
;
10320 -----------------------------
10321 -- Is_Actual_Out_Parameter --
10322 -----------------------------
10324 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
10325 Formal
: Entity_Id
;
10328 Find_Actual
(N
, Formal
, Call
);
10329 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
10330 end Is_Actual_Out_Parameter
;
10332 -------------------------
10333 -- Is_Actual_Parameter --
10334 -------------------------
10336 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
10337 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
10341 when N_Parameter_Association
=>
10342 return N
= Explicit_Actual_Parameter
(Parent
(N
));
10344 when N_Subprogram_Call
=>
10345 return Is_List_Member
(N
)
10347 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
10352 end Is_Actual_Parameter
;
10354 --------------------------------
10355 -- Is_Actual_Tagged_Parameter --
10356 --------------------------------
10358 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
10359 Formal
: Entity_Id
;
10362 Find_Actual
(N
, Formal
, Call
);
10363 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
10364 end Is_Actual_Tagged_Parameter
;
10366 ---------------------
10367 -- Is_Aliased_View --
10368 ---------------------
10370 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
10374 if Is_Entity_Name
(Obj
) then
10381 or else (Present
(Renamed_Object
(E
))
10382 and then Is_Aliased_View
(Renamed_Object
(E
)))))
10384 or else ((Is_Formal
(E
)
10385 or else Ekind_In
(E
, E_Generic_In_Out_Parameter
,
10386 E_Generic_In_Parameter
))
10387 and then Is_Tagged_Type
(Etype
(E
)))
10389 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
10391 -- Current instance of type, either directly or as rewritten
10392 -- reference to the current object.
10394 or else (Is_Entity_Name
(Original_Node
(Obj
))
10395 and then Present
(Entity
(Original_Node
(Obj
)))
10396 and then Is_Type
(Entity
(Original_Node
(Obj
))))
10398 or else (Is_Type
(E
) and then E
= Current_Scope
)
10400 or else (Is_Incomplete_Or_Private_Type
(E
)
10401 and then Full_View
(E
) = Current_Scope
)
10403 -- Ada 2012 AI05-0053: the return object of an extended return
10404 -- statement is aliased if its type is immutably limited.
10406 or else (Is_Return_Object
(E
)
10407 and then Is_Limited_View
(Etype
(E
)));
10409 elsif Nkind
(Obj
) = N_Selected_Component
then
10410 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
10412 elsif Nkind
(Obj
) = N_Indexed_Component
then
10413 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
10415 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
10416 and then Has_Aliased_Components
10417 (Designated_Type
(Etype
(Prefix
(Obj
)))));
10419 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
10420 return Is_Tagged_Type
(Etype
(Obj
))
10421 and then Is_Aliased_View
(Expression
(Obj
));
10423 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
10424 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
10429 end Is_Aliased_View
;
10431 -------------------------
10432 -- Is_Ancestor_Package --
10433 -------------------------
10435 function Is_Ancestor_Package
10437 E2
: Entity_Id
) return Boolean
10443 while Present
(Par
) and then Par
/= Standard_Standard
loop
10448 Par
:= Scope
(Par
);
10452 end Is_Ancestor_Package
;
10454 ----------------------
10455 -- Is_Atomic_Object --
10456 ----------------------
10458 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
10460 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
10461 -- Determines if given object has atomic components
10463 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
10464 -- If prefix is an implicit dereference, examine designated type
10466 ----------------------
10467 -- Is_Atomic_Prefix --
10468 ----------------------
10470 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
10472 if Is_Access_Type
(Etype
(N
)) then
10474 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
10476 return Object_Has_Atomic_Components
(N
);
10478 end Is_Atomic_Prefix
;
10480 ----------------------------------
10481 -- Object_Has_Atomic_Components --
10482 ----------------------------------
10484 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
10486 if Has_Atomic_Components
(Etype
(N
))
10487 or else Is_Atomic
(Etype
(N
))
10491 elsif Is_Entity_Name
(N
)
10492 and then (Has_Atomic_Components
(Entity
(N
))
10493 or else Is_Atomic
(Entity
(N
)))
10497 elsif Nkind
(N
) = N_Selected_Component
10498 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
10502 elsif Nkind
(N
) = N_Indexed_Component
10503 or else Nkind
(N
) = N_Selected_Component
10505 return Is_Atomic_Prefix
(Prefix
(N
));
10510 end Object_Has_Atomic_Components
;
10512 -- Start of processing for Is_Atomic_Object
10515 -- Predicate is not relevant to subprograms
10517 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
10520 elsif Is_Atomic
(Etype
(N
))
10521 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
10525 elsif Nkind
(N
) = N_Selected_Component
10526 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
10530 elsif Nkind
(N
) = N_Indexed_Component
10531 or else Nkind
(N
) = N_Selected_Component
10533 return Is_Atomic_Prefix
(Prefix
(N
));
10538 end Is_Atomic_Object
;
10540 -----------------------------
10541 -- Is_Atomic_Or_VFA_Object --
10542 -----------------------------
10544 function Is_Atomic_Or_VFA_Object
(N
: Node_Id
) return Boolean is
10546 return Is_Atomic_Object
(N
)
10547 or else (Is_Object_Reference
(N
)
10548 and then Is_Entity_Name
(N
)
10549 and then (Is_Volatile_Full_Access
(Entity
(N
))
10551 Is_Volatile_Full_Access
(Etype
(Entity
(N
)))));
10552 end Is_Atomic_Or_VFA_Object
;
10554 -------------------------
10555 -- Is_Attribute_Result --
10556 -------------------------
10558 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
10560 return Nkind
(N
) = N_Attribute_Reference
10561 and then Attribute_Name
(N
) = Name_Result
;
10562 end Is_Attribute_Result
;
10564 -------------------------
10565 -- Is_Attribute_Update --
10566 -------------------------
10568 function Is_Attribute_Update
(N
: Node_Id
) return Boolean is
10570 return Nkind
(N
) = N_Attribute_Reference
10571 and then Attribute_Name
(N
) = Name_Update
;
10572 end Is_Attribute_Update
;
10574 ------------------------------------
10575 -- Is_Body_Or_Package_Declaration --
10576 ------------------------------------
10578 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
10580 return Nkind_In
(N
, N_Entry_Body
,
10582 N_Package_Declaration
,
10586 end Is_Body_Or_Package_Declaration
;
10588 -----------------------
10589 -- Is_Bounded_String --
10590 -----------------------
10592 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
10593 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
10596 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
10597 -- Super_String, or one of the [Wide_]Wide_ versions. This will
10598 -- be True for all the Bounded_String types in instances of the
10599 -- Generic_Bounded_Length generics, and for types derived from those.
10601 return Present
(Under
)
10602 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
10603 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
10604 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
10605 end Is_Bounded_String
;
10607 -------------------------
10608 -- Is_Child_Or_Sibling --
10609 -------------------------
10611 function Is_Child_Or_Sibling
10612 (Pack_1
: Entity_Id
;
10613 Pack_2
: Entity_Id
) return Boolean
10615 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
10616 -- Given an arbitrary package, return the number of "climbs" necessary
10617 -- to reach scope Standard_Standard.
10619 procedure Equalize_Depths
10620 (Pack
: in out Entity_Id
;
10621 Depth
: in out Nat
;
10622 Depth_To_Reach
: Nat
);
10623 -- Given an arbitrary package, its depth and a target depth to reach,
10624 -- climb the scope chain until the said depth is reached. The pointer
10625 -- to the package and its depth a modified during the climb.
10627 ----------------------------
10628 -- Distance_From_Standard --
10629 ----------------------------
10631 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
10638 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
10640 Scop
:= Scope
(Scop
);
10644 end Distance_From_Standard
;
10646 ---------------------
10647 -- Equalize_Depths --
10648 ---------------------
10650 procedure Equalize_Depths
10651 (Pack
: in out Entity_Id
;
10652 Depth
: in out Nat
;
10653 Depth_To_Reach
: Nat
)
10656 -- The package must be at a greater or equal depth
10658 if Depth
< Depth_To_Reach
then
10659 raise Program_Error
;
10662 -- Climb the scope chain until the desired depth is reached
10664 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
10665 Pack
:= Scope
(Pack
);
10666 Depth
:= Depth
- 1;
10668 end Equalize_Depths
;
10672 P_1
: Entity_Id
:= Pack_1
;
10673 P_1_Child
: Boolean := False;
10674 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
10675 P_2
: Entity_Id
:= Pack_2
;
10676 P_2_Child
: Boolean := False;
10677 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
10679 -- Start of processing for Is_Child_Or_Sibling
10683 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
10685 -- Both packages denote the same entity, therefore they cannot be
10686 -- children or siblings.
10691 -- One of the packages is at a deeper level than the other. Note that
10692 -- both may still come from differen hierarchies.
10700 elsif P_1_Depth
> P_2_Depth
then
10703 Depth
=> P_1_Depth
,
10704 Depth_To_Reach
=> P_2_Depth
);
10713 elsif P_2_Depth
> P_1_Depth
then
10716 Depth
=> P_2_Depth
,
10717 Depth_To_Reach
=> P_1_Depth
);
10721 -- At this stage the package pointers have been elevated to the same
10722 -- depth. If the related entities are the same, then one package is a
10723 -- potential child of the other:
10727 -- X became P_1 P_2 or vica versa
10733 return Is_Child_Unit
(Pack_1
);
10735 else pragma Assert
(P_2_Child
);
10736 return Is_Child_Unit
(Pack_2
);
10739 -- The packages may come from the same package chain or from entirely
10740 -- different hierarcies. To determine this, climb the scope stack until
10741 -- a common root is found.
10743 -- (root) (root 1) (root 2)
10748 while Present
(P_1
) and then Present
(P_2
) loop
10750 -- The two packages may be siblings
10753 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
10756 P_1
:= Scope
(P_1
);
10757 P_2
:= Scope
(P_2
);
10762 end Is_Child_Or_Sibling
;
10764 -----------------------------
10765 -- Is_Concurrent_Interface --
10766 -----------------------------
10768 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
10770 return Is_Interface
(T
)
10772 (Is_Protected_Interface
(T
)
10773 or else Is_Synchronized_Interface
(T
)
10774 or else Is_Task_Interface
(T
));
10775 end Is_Concurrent_Interface
;
10777 -----------------------
10778 -- Is_Constant_Bound --
10779 -----------------------
10781 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
10783 if Compile_Time_Known_Value
(Exp
) then
10786 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
10787 return Is_Constant_Object
(Entity
(Exp
))
10788 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
10790 elsif Nkind
(Exp
) in N_Binary_Op
then
10791 return Is_Constant_Bound
(Left_Opnd
(Exp
))
10792 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
10793 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
10798 end Is_Constant_Bound
;
10800 ---------------------------
10801 -- Is_Container_Element --
10802 ---------------------------
10804 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
10805 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
10806 Pref
: constant Node_Id
:= Prefix
(Exp
);
10809 -- Call to an indexing aspect
10811 Cont_Typ
: Entity_Id
;
10812 -- The type of the container being accessed
10814 Elem_Typ
: Entity_Id
;
10815 -- Its element type
10817 Indexing
: Entity_Id
;
10818 Is_Const
: Boolean;
10819 -- Indicates that constant indexing is used, and the element is thus
10822 Ref_Typ
: Entity_Id
;
10823 -- The reference type returned by the indexing operation
10826 -- If C is a container, in a context that imposes the element type of
10827 -- that container, the indexing notation C (X) is rewritten as:
10829 -- Indexing (C, X).Discr.all
10831 -- where Indexing is one of the indexing aspects of the container.
10832 -- If the context does not require a reference, the construct can be
10837 -- First, verify that the construct has the proper form
10839 if not Expander_Active
then
10842 elsif Nkind
(Pref
) /= N_Selected_Component
then
10845 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
10849 Call
:= Prefix
(Pref
);
10850 Ref_Typ
:= Etype
(Call
);
10853 if not Has_Implicit_Dereference
(Ref_Typ
)
10854 or else No
(First
(Parameter_Associations
(Call
)))
10855 or else not Is_Entity_Name
(Name
(Call
))
10860 -- Retrieve type of container object, and its iterator aspects
10862 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
10863 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
10866 if No
(Indexing
) then
10868 -- Container should have at least one indexing operation
10872 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
10874 -- This may be a variable indexing operation
10876 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
10879 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
10888 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
10890 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
10894 -- Check that the expression is not the target of an assignment, in
10895 -- which case the rewriting is not possible.
10897 if not Is_Const
then
10903 while Present
(Par
)
10905 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
10906 and then Par
= Name
(Parent
(Par
))
10910 -- A renaming produces a reference, and the transformation
10913 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
10917 (Nkind
(Parent
(Par
)), N_Function_Call
,
10918 N_Procedure_Call_Statement
,
10919 N_Entry_Call_Statement
)
10921 -- Check that the element is not part of an actual for an
10922 -- in-out parameter.
10929 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
10930 A
:= First
(Parameter_Associations
(Parent
(Par
)));
10931 while Present
(F
) loop
10932 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
10941 -- E_In_Parameter in a call: element is not modified.
10946 Par
:= Parent
(Par
);
10951 -- The expression has the proper form and the context requires the
10952 -- element type. Retrieve the Element function of the container and
10953 -- rewrite the construct as a call to it.
10959 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
10960 while Present
(Op
) loop
10961 exit when Chars
(Node
(Op
)) = Name_Element
;
10970 Make_Function_Call
(Loc
,
10971 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
10972 Parameter_Associations
=> Parameter_Associations
(Call
)));
10973 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
10977 end Is_Container_Element
;
10979 ----------------------------
10980 -- Is_Contract_Annotation --
10981 ----------------------------
10983 function Is_Contract_Annotation
(Item
: Node_Id
) return Boolean is
10985 return Is_Package_Contract_Annotation
(Item
)
10987 Is_Subprogram_Contract_Annotation
(Item
);
10988 end Is_Contract_Annotation
;
10990 --------------------------------------
10991 -- Is_Controlling_Limited_Procedure --
10992 --------------------------------------
10994 function Is_Controlling_Limited_Procedure
10995 (Proc_Nam
: Entity_Id
) return Boolean
10997 Param_Typ
: Entity_Id
:= Empty
;
11000 if Ekind
(Proc_Nam
) = E_Procedure
11001 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
11003 Param_Typ
:= Etype
(Parameter_Type
(First
(
11004 Parameter_Specifications
(Parent
(Proc_Nam
)))));
11006 -- In this case where an Itype was created, the procedure call has been
11009 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
11010 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
11012 Present
(Parameter_Associations
11013 (Associated_Node_For_Itype
(Proc_Nam
)))
11016 Etype
(First
(Parameter_Associations
11017 (Associated_Node_For_Itype
(Proc_Nam
))));
11020 if Present
(Param_Typ
) then
11022 Is_Interface
(Param_Typ
)
11023 and then Is_Limited_Record
(Param_Typ
);
11027 end Is_Controlling_Limited_Procedure
;
11029 -----------------------------
11030 -- Is_CPP_Constructor_Call --
11031 -----------------------------
11033 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
11035 return Nkind
(N
) = N_Function_Call
11036 and then Is_CPP_Class
(Etype
(Etype
(N
)))
11037 and then Is_Constructor
(Entity
(Name
(N
)))
11038 and then Is_Imported
(Entity
(Name
(N
)));
11039 end Is_CPP_Constructor_Call
;
11041 -------------------------
11042 -- Is_Current_Instance --
11043 -------------------------
11045 function Is_Current_Instance
(N
: Node_Id
) return Boolean is
11046 Typ
: constant Entity_Id
:= Entity
(N
);
11050 -- Simplest case: entity is a concurrent type and we are currently
11051 -- inside the body. This will eventually be expanded into a
11052 -- call to Self (for tasks) or _object (for protected objects).
11054 if Is_Concurrent_Type
(Typ
) and then In_Open_Scopes
(Typ
) then
11058 -- Check whether the context is a (sub)type declaration for the
11062 while Present
(P
) loop
11063 if Nkind_In
(P
, N_Full_Type_Declaration
,
11064 N_Private_Type_Declaration
,
11065 N_Subtype_Declaration
)
11066 and then Comes_From_Source
(P
)
11067 and then Defining_Entity
(P
) = Typ
11076 -- In any other context this is not a current occurrence
11079 end Is_Current_Instance
;
11081 --------------------
11082 -- Is_Declaration --
11083 --------------------
11085 function Is_Declaration
(N
: Node_Id
) return Boolean is
11088 when N_Abstract_Subprogram_Declaration |
11089 N_Exception_Declaration |
11090 N_Exception_Renaming_Declaration |
11091 N_Full_Type_Declaration |
11092 N_Generic_Function_Renaming_Declaration |
11093 N_Generic_Package_Declaration |
11094 N_Generic_Package_Renaming_Declaration |
11095 N_Generic_Procedure_Renaming_Declaration |
11096 N_Generic_Subprogram_Declaration |
11097 N_Number_Declaration |
11098 N_Object_Declaration |
11099 N_Object_Renaming_Declaration |
11100 N_Package_Declaration |
11101 N_Package_Renaming_Declaration |
11102 N_Private_Extension_Declaration |
11103 N_Private_Type_Declaration |
11104 N_Subprogram_Declaration |
11105 N_Subprogram_Renaming_Declaration |
11106 N_Subtype_Declaration
=>
11112 end Is_Declaration
;
11118 function Is_Delegate
(T
: Entity_Id
) return Boolean is
11119 Desig_Type
: Entity_Id
;
11122 if VM_Target
/= CLI_Target
then
11126 -- Access-to-subprograms are delegates in CIL
11128 if Ekind
(T
) = E_Access_Subprogram_Type
then
11132 if not Is_Access_Type
(T
) then
11134 -- A delegate is a managed pointer. If no designated type is defined
11135 -- it means that it's not a delegate.
11140 Desig_Type
:= Etype
(Directly_Designated_Type
(T
));
11142 if not Is_Tagged_Type
(Desig_Type
) then
11146 -- Test if the type is inherited from [mscorlib]System.Delegate
11148 while Etype
(Desig_Type
) /= Desig_Type
loop
11149 if Chars
(Scope
(Desig_Type
)) /= No_Name
11150 and then Is_Imported
(Scope
(Desig_Type
))
11151 and then Get_Name_String
(Chars
(Scope
(Desig_Type
))) = "delegate"
11156 Desig_Type
:= Etype
(Desig_Type
);
11162 ----------------------------------------------
11163 -- Is_Dependent_Component_Of_Mutable_Object --
11164 ----------------------------------------------
11166 function Is_Dependent_Component_Of_Mutable_Object
11167 (Object
: Node_Id
) return Boolean
11169 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean;
11170 -- Returns True if and only if Comp is declared within a variant part
11172 --------------------------------
11173 -- Is_Declared_Within_Variant --
11174 --------------------------------
11176 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
11177 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
11178 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
11180 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
11181 end Is_Declared_Within_Variant
;
11184 Prefix_Type
: Entity_Id
;
11185 P_Aliased
: Boolean := False;
11188 Deref
: Node_Id
:= Object
;
11189 -- Dereference node, in something like X.all.Y(2)
11191 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
11194 -- Find the dereference node if any
11196 while Nkind_In
(Deref
, N_Indexed_Component
,
11197 N_Selected_Component
,
11200 Deref
:= Prefix
(Deref
);
11203 -- Ada 2005: If we have a component or slice of a dereference,
11204 -- something like X.all.Y (2), and the type of X is access-to-constant,
11205 -- Is_Variable will return False, because it is indeed a constant
11206 -- view. But it might be a view of a variable object, so we want the
11207 -- following condition to be True in that case.
11209 if Is_Variable
(Object
)
11210 or else (Ada_Version
>= Ada_2005
11211 and then Nkind
(Deref
) = N_Explicit_Dereference
)
11213 if Nkind
(Object
) = N_Selected_Component
then
11214 P
:= Prefix
(Object
);
11215 Prefix_Type
:= Etype
(P
);
11217 if Is_Entity_Name
(P
) then
11218 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
11219 Prefix_Type
:= Base_Type
(Prefix_Type
);
11222 if Is_Aliased
(Entity
(P
)) then
11226 -- A discriminant check on a selected component may be expanded
11227 -- into a dereference when removing side-effects. Recover the
11228 -- original node and its type, which may be unconstrained.
11230 elsif Nkind
(P
) = N_Explicit_Dereference
11231 and then not (Comes_From_Source
(P
))
11233 P
:= Original_Node
(P
);
11234 Prefix_Type
:= Etype
(P
);
11237 -- Check for prefix being an aliased component???
11243 -- A heap object is constrained by its initial value
11245 -- Ada 2005 (AI-363): Always assume the object could be mutable in
11246 -- the dereferenced case, since the access value might denote an
11247 -- unconstrained aliased object, whereas in Ada 95 the designated
11248 -- object is guaranteed to be constrained. A worst-case assumption
11249 -- has to apply in Ada 2005 because we can't tell at compile
11250 -- time whether the object is "constrained by its initial value"
11251 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
11252 -- rules (these rules are acknowledged to need fixing).
11254 if Ada_Version
< Ada_2005
then
11255 if Is_Access_Type
(Prefix_Type
)
11256 or else Nkind
(P
) = N_Explicit_Dereference
11261 else pragma Assert
(Ada_Version
>= Ada_2005
);
11262 if Is_Access_Type
(Prefix_Type
) then
11264 -- If the access type is pool-specific, and there is no
11265 -- constrained partial view of the designated type, then the
11266 -- designated object is known to be constrained.
11268 if Ekind
(Prefix_Type
) = E_Access_Type
11269 and then not Object_Type_Has_Constrained_Partial_View
11270 (Typ
=> Designated_Type
(Prefix_Type
),
11271 Scop
=> Current_Scope
)
11275 -- Otherwise (general access type, or there is a constrained
11276 -- partial view of the designated type), we need to check
11277 -- based on the designated type.
11280 Prefix_Type
:= Designated_Type
(Prefix_Type
);
11286 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
11288 -- As per AI-0017, the renaming is illegal in a generic body, even
11289 -- if the subtype is indefinite.
11291 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
11293 if not Is_Constrained
(Prefix_Type
)
11294 and then (Is_Definite_Subtype
(Prefix_Type
)
11296 (Is_Generic_Type
(Prefix_Type
)
11297 and then Ekind
(Current_Scope
) = E_Generic_Package
11298 and then In_Package_Body
(Current_Scope
)))
11300 and then (Is_Declared_Within_Variant
(Comp
)
11301 or else Has_Discriminant_Dependent_Constraint
(Comp
))
11302 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
11306 -- If the prefix is of an access type at this point, then we want
11307 -- to return False, rather than calling this function recursively
11308 -- on the access object (which itself might be a discriminant-
11309 -- dependent component of some other object, but that isn't
11310 -- relevant to checking the object passed to us). This avoids
11311 -- issuing wrong errors when compiling with -gnatc, where there
11312 -- can be implicit dereferences that have not been expanded.
11314 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
11319 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
11322 elsif Nkind
(Object
) = N_Indexed_Component
11323 or else Nkind
(Object
) = N_Slice
11325 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
11327 -- A type conversion that Is_Variable is a view conversion:
11328 -- go back to the denoted object.
11330 elsif Nkind
(Object
) = N_Type_Conversion
then
11332 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
11337 end Is_Dependent_Component_Of_Mutable_Object
;
11339 ---------------------
11340 -- Is_Dereferenced --
11341 ---------------------
11343 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
11344 P
: constant Node_Id
:= Parent
(N
);
11346 return Nkind_In
(P
, N_Selected_Component
,
11347 N_Explicit_Dereference
,
11348 N_Indexed_Component
,
11350 and then Prefix
(P
) = N
;
11351 end Is_Dereferenced
;
11353 ----------------------
11354 -- Is_Descendent_Of --
11355 ----------------------
11357 function Is_Descendent_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
11362 pragma Assert
(Nkind
(T1
) in N_Entity
);
11363 pragma Assert
(Nkind
(T2
) in N_Entity
);
11365 T
:= Base_Type
(T1
);
11367 -- Immediate return if the types match
11372 -- Comment needed here ???
11374 elsif Ekind
(T
) = E_Class_Wide_Type
then
11375 return Etype
(T
) = T2
;
11383 -- Done if we found the type we are looking for
11388 -- Done if no more derivations to check
11395 -- Following test catches error cases resulting from prev errors
11397 elsif No
(Etyp
) then
11400 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
11403 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
11407 T
:= Base_Type
(Etyp
);
11410 end Is_Descendent_Of
;
11412 ---------------------------------------------
11413 -- Is_Double_Precision_Floating_Point_Type --
11414 ---------------------------------------------
11416 function Is_Double_Precision_Floating_Point_Type
11417 (E
: Entity_Id
) return Boolean is
11419 return Is_Floating_Point_Type
(E
)
11420 and then Machine_Radix_Value
(E
) = Uint_2
11421 and then Machine_Mantissa_Value
(E
) = UI_From_Int
(53)
11422 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_10
11423 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_10
);
11424 end Is_Double_Precision_Floating_Point_Type
;
11426 -----------------------------
11427 -- Is_Effectively_Volatile --
11428 -----------------------------
11430 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
11432 if Is_Type
(Id
) then
11434 -- An arbitrary type is effectively volatile when it is subject to
11435 -- pragma Atomic or Volatile.
11437 if Is_Volatile
(Id
) then
11440 -- An array type is effectively volatile when it is subject to pragma
11441 -- Atomic_Components or Volatile_Components or its compolent type is
11442 -- effectively volatile.
11444 elsif Is_Array_Type
(Id
) then
11446 Has_Volatile_Components
(Id
)
11448 Is_Effectively_Volatile
(Component_Type
(Base_Type
(Id
)));
11454 -- Otherwise Id denotes an object
11459 or else Has_Volatile_Components
(Id
)
11460 or else Is_Effectively_Volatile
(Etype
(Id
));
11462 end Is_Effectively_Volatile
;
11464 ------------------------------------
11465 -- Is_Effectively_Volatile_Object --
11466 ------------------------------------
11468 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
11470 if Is_Entity_Name
(N
) then
11471 return Is_Effectively_Volatile
(Entity
(N
));
11473 elsif Nkind
(N
) = N_Expanded_Name
then
11474 return Is_Effectively_Volatile
(Entity
(N
));
11476 elsif Nkind
(N
) = N_Indexed_Component
then
11477 return Is_Effectively_Volatile_Object
(Prefix
(N
));
11479 elsif Nkind
(N
) = N_Selected_Component
then
11481 Is_Effectively_Volatile_Object
(Prefix
(N
))
11483 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
11488 end Is_Effectively_Volatile_Object
;
11490 ----------------------------
11491 -- Is_Expression_Function --
11492 ----------------------------
11494 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
11498 if Ekind
(Subp
) /= E_Function
then
11502 Decl
:= Unit_Declaration_Node
(Subp
);
11503 return Nkind
(Decl
) = N_Subprogram_Declaration
11505 (Nkind
(Original_Node
(Decl
)) = N_Expression_Function
11507 (Present
(Corresponding_Body
(Decl
))
11509 Nkind
(Original_Node
11510 (Unit_Declaration_Node
11511 (Corresponding_Body
(Decl
)))) =
11512 N_Expression_Function
));
11514 end Is_Expression_Function
;
11516 -----------------------
11517 -- Is_EVF_Expression --
11518 -----------------------
11520 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
11521 Orig_N
: constant Node_Id
:= Original_Node
(N
);
11527 -- Detect a reference to a formal parameter of a specific tagged type
11528 -- whose related subprogram is subject to pragma Expresions_Visible with
11531 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
11536 and then Is_Specific_Tagged_Type
(Etype
(Id
))
11537 and then Extensions_Visible_Status
(Id
) =
11538 Extensions_Visible_False
;
11540 -- A case expression is an EVF expression when it contains at least one
11541 -- EVF dependent_expression. Note that a case expression may have been
11542 -- expanded, hence the use of Original_Node.
11544 elsif Nkind
(Orig_N
) = N_Case_Expression
then
11545 Alt
:= First
(Alternatives
(Orig_N
));
11546 while Present
(Alt
) loop
11547 if Is_EVF_Expression
(Expression
(Alt
)) then
11554 -- An if expression is an EVF expression when it contains at least one
11555 -- EVF dependent_expression. Note that an if expression may have been
11556 -- expanded, hence the use of Original_Node.
11558 elsif Nkind
(Orig_N
) = N_If_Expression
then
11559 Expr
:= Next
(First
(Expressions
(Orig_N
)));
11560 while Present
(Expr
) loop
11561 if Is_EVF_Expression
(Expr
) then
11568 -- A qualified expression or a type conversion is an EVF expression when
11569 -- its operand is an EVF expression.
11571 elsif Nkind_In
(N
, N_Qualified_Expression
,
11572 N_Unchecked_Type_Conversion
,
11575 return Is_EVF_Expression
(Expression
(N
));
11577 -- Attributes 'Loop_Entry, 'Old and 'Update are an EVF expression when
11578 -- their prefix denotes an EVF expression.
11580 elsif Nkind
(N
) = N_Attribute_Reference
11581 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
11585 return Is_EVF_Expression
(Prefix
(N
));
11589 end Is_EVF_Expression
;
11595 function Is_False
(U
: Uint
) return Boolean is
11600 ---------------------------
11601 -- Is_Fixed_Model_Number --
11602 ---------------------------
11604 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
11605 S
: constant Ureal
:= Small_Value
(T
);
11606 M
: Urealp
.Save_Mark
;
11610 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
11611 Urealp
.Release
(M
);
11613 end Is_Fixed_Model_Number
;
11615 -------------------------------
11616 -- Is_Fully_Initialized_Type --
11617 -------------------------------
11619 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
11623 if Is_Scalar_Type
(Typ
) then
11625 -- A scalar type with an aspect Default_Value is fully initialized
11627 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
11628 -- of a scalar type, but we don't take that into account here, since
11629 -- we don't want these to affect warnings.
11631 return Has_Default_Aspect
(Typ
);
11633 elsif Is_Access_Type
(Typ
) then
11636 elsif Is_Array_Type
(Typ
) then
11637 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
11638 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
11643 -- An interesting case, if we have a constrained type one of whose
11644 -- bounds is known to be null, then there are no elements to be
11645 -- initialized, so all the elements are initialized.
11647 if Is_Constrained
(Typ
) then
11650 Indx_Typ
: Entity_Id
;
11651 Lbd
, Hbd
: Node_Id
;
11654 Indx
:= First_Index
(Typ
);
11655 while Present
(Indx
) loop
11656 if Etype
(Indx
) = Any_Type
then
11659 -- If index is a range, use directly
11661 elsif Nkind
(Indx
) = N_Range
then
11662 Lbd
:= Low_Bound
(Indx
);
11663 Hbd
:= High_Bound
(Indx
);
11666 Indx_Typ
:= Etype
(Indx
);
11668 if Is_Private_Type
(Indx_Typ
) then
11669 Indx_Typ
:= Full_View
(Indx_Typ
);
11672 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
11675 Lbd
:= Type_Low_Bound
(Indx_Typ
);
11676 Hbd
:= Type_High_Bound
(Indx_Typ
);
11680 if Compile_Time_Known_Value
(Lbd
)
11682 Compile_Time_Known_Value
(Hbd
)
11684 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
11694 -- If no null indexes, then type is not fully initialized
11700 elsif Is_Record_Type
(Typ
) then
11701 if Has_Discriminants
(Typ
)
11703 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
11704 and then Is_Fully_Initialized_Variant
(Typ
)
11709 -- We consider bounded string types to be fully initialized, because
11710 -- otherwise we get false alarms when the Data component is not
11711 -- default-initialized.
11713 if Is_Bounded_String
(Typ
) then
11717 -- Controlled records are considered to be fully initialized if
11718 -- there is a user defined Initialize routine. This may not be
11719 -- entirely correct, but as the spec notes, we are guessing here
11720 -- what is best from the point of view of issuing warnings.
11722 if Is_Controlled
(Typ
) then
11724 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
11727 if Present
(Utyp
) then
11729 Init
: constant Entity_Id
:=
11730 (Find_Optional_Prim_Op
11731 (Underlying_Type
(Typ
), Name_Initialize
));
11735 and then Comes_From_Source
(Init
)
11737 Is_Predefined_File_Name
11738 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
11742 elsif Has_Null_Extension
(Typ
)
11744 Is_Fully_Initialized_Type
11745 (Etype
(Base_Type
(Typ
)))
11754 -- Otherwise see if all record components are initialized
11760 Ent
:= First_Entity
(Typ
);
11761 while Present
(Ent
) loop
11762 if Ekind
(Ent
) = E_Component
11763 and then (No
(Parent
(Ent
))
11764 or else No
(Expression
(Parent
(Ent
))))
11765 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
11767 -- Special VM case for tag components, which need to be
11768 -- defined in this case, but are never initialized as VMs
11769 -- are using other dispatching mechanisms. Ignore this
11770 -- uninitialized case. Note that this applies both to the
11771 -- uTag entry and the main vtable pointer (CPP_Class case).
11773 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
11782 -- No uninitialized components, so type is fully initialized.
11783 -- Note that this catches the case of no components as well.
11787 elsif Is_Concurrent_Type
(Typ
) then
11790 elsif Is_Private_Type
(Typ
) then
11792 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11798 return Is_Fully_Initialized_Type
(U
);
11805 end Is_Fully_Initialized_Type
;
11807 ----------------------------------
11808 -- Is_Fully_Initialized_Variant --
11809 ----------------------------------
11811 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
11812 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
11813 Constraints
: constant List_Id
:= New_List
;
11814 Components
: constant Elist_Id
:= New_Elmt_List
;
11815 Comp_Elmt
: Elmt_Id
;
11817 Comp_List
: Node_Id
;
11819 Discr_Val
: Node_Id
;
11821 Report_Errors
: Boolean;
11822 pragma Warnings
(Off
, Report_Errors
);
11825 if Serious_Errors_Detected
> 0 then
11829 if Is_Record_Type
(Typ
)
11830 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
11831 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
11833 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
11835 Discr
:= First_Discriminant
(Typ
);
11836 while Present
(Discr
) loop
11837 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
11838 Discr_Val
:= Expression
(Parent
(Discr
));
11840 if Present
(Discr_Val
)
11841 and then Is_OK_Static_Expression
(Discr_Val
)
11843 Append_To
(Constraints
,
11844 Make_Component_Association
(Loc
,
11845 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
11846 Expression
=> New_Copy
(Discr_Val
)));
11854 Next_Discriminant
(Discr
);
11859 Comp_List
=> Comp_List
,
11860 Governed_By
=> Constraints
,
11861 Into
=> Components
,
11862 Report_Errors
=> Report_Errors
);
11864 -- Check that each component present is fully initialized
11866 Comp_Elmt
:= First_Elmt
(Components
);
11867 while Present
(Comp_Elmt
) loop
11868 Comp_Id
:= Node
(Comp_Elmt
);
11870 if Ekind
(Comp_Id
) = E_Component
11871 and then (No
(Parent
(Comp_Id
))
11872 or else No
(Expression
(Parent
(Comp_Id
))))
11873 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
11878 Next_Elmt
(Comp_Elmt
);
11883 elsif Is_Private_Type
(Typ
) then
11885 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
11891 return Is_Fully_Initialized_Variant
(U
);
11898 end Is_Fully_Initialized_Variant
;
11900 ------------------------------------
11901 -- Is_Generic_Declaration_Or_Body --
11902 ------------------------------------
11904 function Is_Generic_Declaration_Or_Body
(Decl
: Node_Id
) return Boolean is
11905 Spec_Decl
: Node_Id
;
11908 -- Package/subprogram body
11910 if Nkind_In
(Decl
, N_Package_Body
, N_Subprogram_Body
)
11911 and then Present
(Corresponding_Spec
(Decl
))
11913 Spec_Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(Decl
));
11915 -- Package/subprogram body stub
11917 elsif Nkind_In
(Decl
, N_Package_Body_Stub
, N_Subprogram_Body_Stub
)
11918 and then Present
(Corresponding_Spec_Of_Stub
(Decl
))
11921 Unit_Declaration_Node
(Corresponding_Spec_Of_Stub
(Decl
));
11929 -- Rather than inspecting the defining entity of the spec declaration,
11930 -- look at its Nkind. This takes care of the case where the analysis of
11931 -- a generic body modifies the Ekind of its spec to allow for recursive
11935 Nkind_In
(Spec_Decl
, N_Generic_Package_Declaration
,
11936 N_Generic_Subprogram_Declaration
);
11937 end Is_Generic_Declaration_Or_Body
;
11939 ----------------------------
11940 -- Is_Inherited_Operation --
11941 ----------------------------
11943 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
11944 pragma Assert
(Is_Overloadable
(E
));
11945 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
11947 return Kind
= N_Full_Type_Declaration
11948 or else Kind
= N_Private_Extension_Declaration
11949 or else Kind
= N_Subtype_Declaration
11950 or else (Ekind
(E
) = E_Enumeration_Literal
11951 and then Is_Derived_Type
(Etype
(E
)));
11952 end Is_Inherited_Operation
;
11954 -------------------------------------
11955 -- Is_Inherited_Operation_For_Type --
11956 -------------------------------------
11958 function Is_Inherited_Operation_For_Type
11960 Typ
: Entity_Id
) return Boolean
11963 -- Check that the operation has been created by the type declaration
11965 return Is_Inherited_Operation
(E
)
11966 and then Defining_Identifier
(Parent
(E
)) = Typ
;
11967 end Is_Inherited_Operation_For_Type
;
11973 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
11974 Ifaces_List
: Elist_Id
;
11975 Iface_Elmt
: Elmt_Id
;
11979 if Is_Class_Wide_Type
(Typ
)
11980 and then Nam_In
(Chars
(Etype
(Typ
)), Name_Forward_Iterator
,
11981 Name_Reversible_Iterator
)
11983 Is_Predefined_File_Name
11984 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
11988 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
11991 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
11995 Collect_Interfaces
(Typ
, Ifaces_List
);
11997 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
11998 while Present
(Iface_Elmt
) loop
11999 Iface
:= Node
(Iface_Elmt
);
12000 if Chars
(Iface
) = Name_Forward_Iterator
12002 Is_Predefined_File_Name
12003 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
12008 Next_Elmt
(Iface_Elmt
);
12019 -- We seem to have a lot of overlapping functions that do similar things
12020 -- (testing for left hand sides or lvalues???).
12022 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
12023 P
: constant Node_Id
:= Parent
(N
);
12026 -- Return True if we are the left hand side of an assignment statement
12028 if Nkind
(P
) = N_Assignment_Statement
then
12029 if Name
(P
) = N
then
12035 -- Case of prefix of indexed or selected component or slice
12037 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
12038 and then N
= Prefix
(P
)
12040 -- Here we have the case where the parent P is N.Q or N(Q .. R).
12041 -- If P is an LHS, then N is also effectively an LHS, but there
12042 -- is an important exception. If N is of an access type, then
12043 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
12044 -- case this makes N.all a left hand side but not N itself.
12046 -- If we don't know the type yet, this is the case where we return
12047 -- Unknown, since the answer depends on the type which is unknown.
12049 if No
(Etype
(N
)) then
12052 -- We have an Etype set, so we can check it
12054 elsif Is_Access_Type
(Etype
(N
)) then
12057 -- OK, not access type case, so just test whole expression
12063 -- All other cases are not left hand sides
12070 -----------------------------
12071 -- Is_Library_Level_Entity --
12072 -----------------------------
12074 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
12076 -- The following is a small optimization, and it also properly handles
12077 -- discriminals, which in task bodies might appear in expressions before
12078 -- the corresponding procedure has been created, and which therefore do
12079 -- not have an assigned scope.
12081 if Is_Formal
(E
) then
12085 -- Normal test is simply that the enclosing dynamic scope is Standard
12087 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
12088 end Is_Library_Level_Entity
;
12090 --------------------------------
12091 -- Is_Limited_Class_Wide_Type --
12092 --------------------------------
12094 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
12097 Is_Class_Wide_Type
(Typ
)
12098 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
12099 end Is_Limited_Class_Wide_Type
;
12101 ---------------------------------
12102 -- Is_Local_Variable_Reference --
12103 ---------------------------------
12105 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
12107 if not Is_Entity_Name
(Expr
) then
12112 Ent
: constant Entity_Id
:= Entity
(Expr
);
12113 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
12115 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
12118 return Present
(Sub
) and then Sub
= Current_Subprogram
;
12122 end Is_Local_Variable_Reference
;
12124 -------------------------
12125 -- Is_Object_Reference --
12126 -------------------------
12128 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
12130 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
12131 -- Determine whether N is the name of an internally-generated renaming
12133 --------------------------------------
12134 -- Is_Internally_Generated_Renaming --
12135 --------------------------------------
12137 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
12142 while Present
(P
) loop
12143 if Nkind
(P
) = N_Object_Renaming_Declaration
then
12144 return not Comes_From_Source
(P
);
12145 elsif Is_List_Member
(P
) then
12153 end Is_Internally_Generated_Renaming
;
12155 -- Start of processing for Is_Object_Reference
12158 if Is_Entity_Name
(N
) then
12159 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
12163 when N_Indexed_Component | N_Slice
=>
12165 Is_Object_Reference
(Prefix
(N
))
12166 or else Is_Access_Type
(Etype
(Prefix
(N
)));
12168 -- In Ada 95, a function call is a constant object; a procedure
12171 when N_Function_Call
=>
12172 return Etype
(N
) /= Standard_Void_Type
;
12174 -- Attributes 'Input, 'Old and 'Result produce objects
12176 when N_Attribute_Reference
=>
12179 (Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
12181 when N_Selected_Component
=>
12183 Is_Object_Reference
(Selector_Name
(N
))
12185 (Is_Object_Reference
(Prefix
(N
))
12186 or else Is_Access_Type
(Etype
(Prefix
(N
))));
12188 when N_Explicit_Dereference
=>
12191 -- A view conversion of a tagged object is an object reference
12193 when N_Type_Conversion
=>
12194 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
12195 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
12196 and then Is_Object_Reference
(Expression
(N
));
12198 -- An unchecked type conversion is considered to be an object if
12199 -- the operand is an object (this construction arises only as a
12200 -- result of expansion activities).
12202 when N_Unchecked_Type_Conversion
=>
12205 -- Allow string literals to act as objects as long as they appear
12206 -- in internally-generated renamings. The expansion of iterators
12207 -- may generate such renamings when the range involves a string
12210 when N_String_Literal
=>
12211 return Is_Internally_Generated_Renaming
(Parent
(N
));
12213 -- AI05-0003: In Ada 2012 a qualified expression is a name.
12214 -- This allows disambiguation of function calls and the use
12215 -- of aggregates in more contexts.
12217 when N_Qualified_Expression
=>
12218 if Ada_Version
< Ada_2012
then
12221 return Is_Object_Reference
(Expression
(N
))
12222 or else Nkind
(Expression
(N
)) = N_Aggregate
;
12229 end Is_Object_Reference
;
12231 -----------------------------------
12232 -- Is_OK_Variable_For_Out_Formal --
12233 -----------------------------------
12235 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
12237 Note_Possible_Modification
(AV
, Sure
=> True);
12239 -- We must reject parenthesized variable names. Comes_From_Source is
12240 -- checked because there are currently cases where the compiler violates
12241 -- this rule (e.g. passing a task object to its controlled Initialize
12242 -- routine). This should be properly documented in sinfo???
12244 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
12247 -- A variable is always allowed
12249 elsif Is_Variable
(AV
) then
12252 -- Generalized indexing operations are rewritten as explicit
12253 -- dereferences, and it is only during resolution that we can
12254 -- check whether the context requires an access_to_variable type.
12256 elsif Nkind
(AV
) = N_Explicit_Dereference
12257 and then Ada_Version
>= Ada_2012
12258 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
12259 and then Present
(Etype
(Original_Node
(AV
)))
12260 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
12262 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
12264 -- Unchecked conversions are allowed only if they come from the
12265 -- generated code, which sometimes uses unchecked conversions for out
12266 -- parameters in cases where code generation is unaffected. We tell
12267 -- source unchecked conversions by seeing if they are rewrites of
12268 -- an original Unchecked_Conversion function call, or of an explicit
12269 -- conversion of a function call or an aggregate (as may happen in the
12270 -- expansion of a packed array aggregate).
12272 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
12273 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
12276 elsif Comes_From_Source
(AV
)
12277 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
12281 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
12282 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
12288 -- Normal type conversions are allowed if argument is a variable
12290 elsif Nkind
(AV
) = N_Type_Conversion
then
12291 if Is_Variable
(Expression
(AV
))
12292 and then Paren_Count
(Expression
(AV
)) = 0
12294 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
12297 -- We also allow a non-parenthesized expression that raises
12298 -- constraint error if it rewrites what used to be a variable
12300 elsif Raises_Constraint_Error
(Expression
(AV
))
12301 and then Paren_Count
(Expression
(AV
)) = 0
12302 and then Is_Variable
(Original_Node
(Expression
(AV
)))
12306 -- Type conversion of something other than a variable
12312 -- If this node is rewritten, then test the original form, if that is
12313 -- OK, then we consider the rewritten node OK (for example, if the
12314 -- original node is a conversion, then Is_Variable will not be true
12315 -- but we still want to allow the conversion if it converts a variable).
12317 elsif Original_Node
(AV
) /= AV
then
12319 -- In Ada 2012, the explicit dereference may be a rewritten call to a
12320 -- Reference function.
12322 if Ada_Version
>= Ada_2012
12323 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
12325 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
12330 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
12333 -- All other non-variables are rejected
12338 end Is_OK_Variable_For_Out_Formal
;
12340 ------------------------------------
12341 -- Is_Package_Contract_Annotation --
12342 ------------------------------------
12344 function Is_Package_Contract_Annotation
(Item
: Node_Id
) return Boolean is
12348 if Nkind
(Item
) = N_Aspect_Specification
then
12349 Nam
:= Chars
(Identifier
(Item
));
12351 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
12352 Nam
:= Pragma_Name
(Item
);
12355 return Nam
= Name_Abstract_State
12356 or else Nam
= Name_Initial_Condition
12357 or else Nam
= Name_Initializes
12358 or else Nam
= Name_Refined_State
;
12359 end Is_Package_Contract_Annotation
;
12361 -----------------------------------
12362 -- Is_Partially_Initialized_Type --
12363 -----------------------------------
12365 function Is_Partially_Initialized_Type
12367 Include_Implicit
: Boolean := True) return Boolean
12370 if Is_Scalar_Type
(Typ
) then
12373 elsif Is_Access_Type
(Typ
) then
12374 return Include_Implicit
;
12376 elsif Is_Array_Type
(Typ
) then
12378 -- If component type is partially initialized, so is array type
12380 if Is_Partially_Initialized_Type
12381 (Component_Type
(Typ
), Include_Implicit
)
12385 -- Otherwise we are only partially initialized if we are fully
12386 -- initialized (this is the empty array case, no point in us
12387 -- duplicating that code here).
12390 return Is_Fully_Initialized_Type
(Typ
);
12393 elsif Is_Record_Type
(Typ
) then
12395 -- A discriminated type is always partially initialized if in
12398 if Has_Discriminants
(Typ
) and then Include_Implicit
then
12401 -- A tagged type is always partially initialized
12403 elsif Is_Tagged_Type
(Typ
) then
12406 -- Case of non-discriminated record
12412 Component_Present
: Boolean := False;
12413 -- Set True if at least one component is present. If no
12414 -- components are present, then record type is fully
12415 -- initialized (another odd case, like the null array).
12418 -- Loop through components
12420 Ent
:= First_Entity
(Typ
);
12421 while Present
(Ent
) loop
12422 if Ekind
(Ent
) = E_Component
then
12423 Component_Present
:= True;
12425 -- If a component has an initialization expression then
12426 -- the enclosing record type is partially initialized
12428 if Present
(Parent
(Ent
))
12429 and then Present
(Expression
(Parent
(Ent
)))
12433 -- If a component is of a type which is itself partially
12434 -- initialized, then the enclosing record type is also.
12436 elsif Is_Partially_Initialized_Type
12437 (Etype
(Ent
), Include_Implicit
)
12446 -- No initialized components found. If we found any components
12447 -- they were all uninitialized so the result is false.
12449 if Component_Present
then
12452 -- But if we found no components, then all the components are
12453 -- initialized so we consider the type to be initialized.
12461 -- Concurrent types are always fully initialized
12463 elsif Is_Concurrent_Type
(Typ
) then
12466 -- For a private type, go to underlying type. If there is no underlying
12467 -- type then just assume this partially initialized. Not clear if this
12468 -- can happen in a non-error case, but no harm in testing for this.
12470 elsif Is_Private_Type
(Typ
) then
12472 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
12477 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
12481 -- For any other type (are there any?) assume partially initialized
12486 end Is_Partially_Initialized_Type
;
12488 ------------------------------------
12489 -- Is_Potentially_Persistent_Type --
12490 ------------------------------------
12492 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
12497 -- For private type, test corresponding full type
12499 if Is_Private_Type
(T
) then
12500 return Is_Potentially_Persistent_Type
(Full_View
(T
));
12502 -- Scalar types are potentially persistent
12504 elsif Is_Scalar_Type
(T
) then
12507 -- Record type is potentially persistent if not tagged and the types of
12508 -- all it components are potentially persistent, and no component has
12509 -- an initialization expression.
12511 elsif Is_Record_Type
(T
)
12512 and then not Is_Tagged_Type
(T
)
12513 and then not Is_Partially_Initialized_Type
(T
)
12515 Comp
:= First_Component
(T
);
12516 while Present
(Comp
) loop
12517 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
12520 Next_Entity
(Comp
);
12526 -- Array type is potentially persistent if its component type is
12527 -- potentially persistent and if all its constraints are static.
12529 elsif Is_Array_Type
(T
) then
12530 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
12534 Indx
:= First_Index
(T
);
12535 while Present
(Indx
) loop
12536 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
12545 -- All other types are not potentially persistent
12550 end Is_Potentially_Persistent_Type
;
12552 --------------------------------
12553 -- Is_Potentially_Unevaluated --
12554 --------------------------------
12556 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
12564 -- A postcondition whose expression is a short-circuit is broken down
12565 -- into individual aspects for better exception reporting. The original
12566 -- short-circuit expression is rewritten as the second operand, and an
12567 -- occurrence of 'Old in that operand is potentially unevaluated.
12568 -- See Sem_ch13.adb for details of this transformation.
12570 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
12574 while not Nkind_In
(Par
, N_If_Expression
,
12582 Par
:= Parent
(Par
);
12584 -- If the context is not an expression, or if is the result of
12585 -- expansion of an enclosing construct (such as another attribute)
12586 -- the predicate does not apply.
12588 if Nkind
(Par
) not in N_Subexpr
12589 or else not Comes_From_Source
(Par
)
12595 if Nkind
(Par
) = N_If_Expression
then
12596 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
12598 elsif Nkind
(Par
) = N_Case_Expression
then
12599 return Expr
/= Expression
(Par
);
12601 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
12602 return Expr
= Right_Opnd
(Par
);
12604 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
12605 return Expr
/= Left_Opnd
(Par
);
12610 end Is_Potentially_Unevaluated
;
12612 ---------------------------------
12613 -- Is_Protected_Self_Reference --
12614 ---------------------------------
12616 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
12618 function In_Access_Definition
(N
: Node_Id
) return Boolean;
12619 -- Returns true if N belongs to an access definition
12621 --------------------------
12622 -- In_Access_Definition --
12623 --------------------------
12625 function In_Access_Definition
(N
: Node_Id
) return Boolean is
12630 while Present
(P
) loop
12631 if Nkind
(P
) = N_Access_Definition
then
12639 end In_Access_Definition
;
12641 -- Start of processing for Is_Protected_Self_Reference
12644 -- Verify that prefix is analyzed and has the proper form. Note that
12645 -- the attributes Elab_Spec, Elab_Body, Elab_Subp_Body and UET_Address,
12646 -- which also produce the address of an entity, do not analyze their
12647 -- prefix because they denote entities that are not necessarily visible.
12648 -- Neither of them can apply to a protected type.
12650 return Ada_Version
>= Ada_2005
12651 and then Is_Entity_Name
(N
)
12652 and then Present
(Entity
(N
))
12653 and then Is_Protected_Type
(Entity
(N
))
12654 and then In_Open_Scopes
(Entity
(N
))
12655 and then not In_Access_Definition
(N
);
12656 end Is_Protected_Self_Reference
;
12658 -----------------------------
12659 -- Is_RCI_Pkg_Spec_Or_Body --
12660 -----------------------------
12662 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
12664 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
12665 -- Return True if the unit of Cunit is an RCI package declaration
12667 ---------------------------
12668 -- Is_RCI_Pkg_Decl_Cunit --
12669 ---------------------------
12671 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
12672 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
12675 if Nkind
(The_Unit
) /= N_Package_Declaration
then
12679 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
12680 end Is_RCI_Pkg_Decl_Cunit
;
12682 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
12685 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
12687 (Nkind
(Unit
(Cunit
)) = N_Package_Body
12688 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
12689 end Is_RCI_Pkg_Spec_Or_Body
;
12691 -----------------------------------------
12692 -- Is_Remote_Access_To_Class_Wide_Type --
12693 -----------------------------------------
12695 function Is_Remote_Access_To_Class_Wide_Type
12696 (E
: Entity_Id
) return Boolean
12699 -- A remote access to class-wide type is a general access to object type
12700 -- declared in the visible part of a Remote_Types or Remote_Call_
12703 return Ekind
(E
) = E_General_Access_Type
12704 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
12705 end Is_Remote_Access_To_Class_Wide_Type
;
12707 -----------------------------------------
12708 -- Is_Remote_Access_To_Subprogram_Type --
12709 -----------------------------------------
12711 function Is_Remote_Access_To_Subprogram_Type
12712 (E
: Entity_Id
) return Boolean
12715 return (Ekind
(E
) = E_Access_Subprogram_Type
12716 or else (Ekind
(E
) = E_Record_Type
12717 and then Present
(Corresponding_Remote_Type
(E
))))
12718 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
12719 end Is_Remote_Access_To_Subprogram_Type
;
12721 --------------------
12722 -- Is_Remote_Call --
12723 --------------------
12725 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
12727 if Nkind
(N
) not in N_Subprogram_Call
then
12729 -- An entry call cannot be remote
12733 elsif Nkind
(Name
(N
)) in N_Has_Entity
12734 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
12736 -- A subprogram declared in the spec of a RCI package is remote
12740 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
12741 and then Is_Remote_Access_To_Subprogram_Type
12742 (Etype
(Prefix
(Name
(N
))))
12744 -- The dereference of a RAS is a remote call
12748 elsif Present
(Controlling_Argument
(N
))
12749 and then Is_Remote_Access_To_Class_Wide_Type
12750 (Etype
(Controlling_Argument
(N
)))
12752 -- Any primitive operation call with a controlling argument of
12753 -- a RACW type is a remote call.
12758 -- All other calls are local calls
12761 end Is_Remote_Call
;
12763 ----------------------
12764 -- Is_Renamed_Entry --
12765 ----------------------
12767 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
12768 Orig_Node
: Node_Id
:= Empty
;
12769 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
12771 function Is_Entry
(Nam
: Node_Id
) return Boolean;
12772 -- Determine whether Nam is an entry. Traverse selectors if there are
12773 -- nested selected components.
12779 function Is_Entry
(Nam
: Node_Id
) return Boolean is
12781 if Nkind
(Nam
) = N_Selected_Component
then
12782 return Is_Entry
(Selector_Name
(Nam
));
12785 return Ekind
(Entity
(Nam
)) = E_Entry
;
12788 -- Start of processing for Is_Renamed_Entry
12791 if Present
(Alias
(Proc_Nam
)) then
12792 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
12795 -- Look for a rewritten subprogram renaming declaration
12797 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
12798 and then Present
(Original_Node
(Subp_Decl
))
12800 Orig_Node
:= Original_Node
(Subp_Decl
);
12803 -- The rewritten subprogram is actually an entry
12805 if Present
(Orig_Node
)
12806 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
12807 and then Is_Entry
(Name
(Orig_Node
))
12813 end Is_Renamed_Entry
;
12815 -----------------------------
12816 -- Is_Renaming_Declaration --
12817 -----------------------------
12819 function Is_Renaming_Declaration
(N
: Node_Id
) return Boolean is
12822 when N_Exception_Renaming_Declaration |
12823 N_Generic_Function_Renaming_Declaration |
12824 N_Generic_Package_Renaming_Declaration |
12825 N_Generic_Procedure_Renaming_Declaration |
12826 N_Object_Renaming_Declaration |
12827 N_Package_Renaming_Declaration |
12828 N_Subprogram_Renaming_Declaration
=>
12834 end Is_Renaming_Declaration
;
12836 ----------------------------
12837 -- Is_Reversible_Iterator --
12838 ----------------------------
12840 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
12841 Ifaces_List
: Elist_Id
;
12842 Iface_Elmt
: Elmt_Id
;
12846 if Is_Class_Wide_Type
(Typ
)
12847 and then Chars
(Etype
(Typ
)) = Name_Reversible_Iterator
12848 and then Is_Predefined_File_Name
12849 (Unit_File_Name
(Get_Source_Unit
(Etype
(Typ
))))
12853 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
12857 Collect_Interfaces
(Typ
, Ifaces_List
);
12859 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
12860 while Present
(Iface_Elmt
) loop
12861 Iface
:= Node
(Iface_Elmt
);
12862 if Chars
(Iface
) = Name_Reversible_Iterator
12864 Is_Predefined_File_Name
12865 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
12870 Next_Elmt
(Iface_Elmt
);
12875 end Is_Reversible_Iterator
;
12877 ----------------------
12878 -- Is_Selector_Name --
12879 ----------------------
12881 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
12883 if not Is_List_Member
(N
) then
12885 P
: constant Node_Id
:= Parent
(N
);
12887 return Nkind_In
(P
, N_Expanded_Name
,
12888 N_Generic_Association
,
12889 N_Parameter_Association
,
12890 N_Selected_Component
)
12891 and then Selector_Name
(P
) = N
;
12896 L
: constant List_Id
:= List_Containing
(N
);
12897 P
: constant Node_Id
:= Parent
(L
);
12899 return (Nkind
(P
) = N_Discriminant_Association
12900 and then Selector_Names
(P
) = L
)
12902 (Nkind
(P
) = N_Component_Association
12903 and then Choices
(P
) = L
);
12906 end Is_Selector_Name
;
12908 ---------------------------------------------
12909 -- Is_Single_Precision_Floating_Point_Type --
12910 ---------------------------------------------
12912 function Is_Single_Precision_Floating_Point_Type
12913 (E
: Entity_Id
) return Boolean is
12915 return Is_Floating_Point_Type
(E
)
12916 and then Machine_Radix_Value
(E
) = Uint_2
12917 and then Machine_Mantissa_Value
(E
) = Uint_24
12918 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_7
12919 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_7
);
12920 end Is_Single_Precision_Floating_Point_Type
;
12922 -------------------------------------
12923 -- Is_SPARK_05_Initialization_Expr --
12924 -------------------------------------
12926 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
12929 Comp_Assn
: Node_Id
;
12930 Orig_N
: constant Node_Id
:= Original_Node
(N
);
12935 if not Comes_From_Source
(Orig_N
) then
12939 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
12941 case Nkind
(Orig_N
) is
12942 when N_Character_Literal |
12943 N_Integer_Literal |
12945 N_String_Literal
=>
12948 when N_Identifier |
12950 if Is_Entity_Name
(Orig_N
)
12951 and then Present
(Entity
(Orig_N
)) -- needed in some cases
12953 case Ekind
(Entity
(Orig_N
)) is
12955 E_Enumeration_Literal |
12960 if Is_Type
(Entity
(Orig_N
)) then
12968 when N_Qualified_Expression |
12969 N_Type_Conversion
=>
12970 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
12973 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12977 N_Membership_Test
=>
12978 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
12980 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
12983 N_Extension_Aggregate
=>
12984 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
12986 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
12989 Expr
:= First
(Expressions
(Orig_N
));
12990 while Present
(Expr
) loop
12991 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
12999 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
13000 while Present
(Comp_Assn
) loop
13001 Expr
:= Expression
(Comp_Assn
);
13003 -- Note: test for Present here needed for box assocation
13006 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
13015 when N_Attribute_Reference
=>
13016 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
13017 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
13020 Expr
:= First
(Expressions
(Orig_N
));
13021 while Present
(Expr
) loop
13022 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
13030 -- Selected components might be expanded named not yet resolved, so
13031 -- default on the safe side. (Eg on sparklex.ads)
13033 when N_Selected_Component
=>
13042 end Is_SPARK_05_Initialization_Expr
;
13044 ----------------------------------
13045 -- Is_SPARK_05_Object_Reference --
13046 ----------------------------------
13048 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
13050 if Is_Entity_Name
(N
) then
13051 return Present
(Entity
(N
))
13053 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
13054 or else Ekind
(Entity
(N
)) in Formal_Kind
);
13058 when N_Selected_Component
=>
13059 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
13065 end Is_SPARK_05_Object_Reference
;
13067 -----------------------------
13068 -- Is_Specific_Tagged_Type --
13069 -----------------------------
13071 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
13072 Full_Typ
: Entity_Id
;
13075 -- Handle private types
13077 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
13078 Full_Typ
:= Full_View
(Typ
);
13083 -- A specific tagged type is a non-class-wide tagged type
13085 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
13086 end Is_Specific_Tagged_Type
;
13092 function Is_Statement
(N
: Node_Id
) return Boolean is
13095 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
13096 or else Nkind
(N
) = N_Procedure_Call_Statement
;
13099 ---------------------------------------
13100 -- Is_Subprogram_Contract_Annotation --
13101 ---------------------------------------
13103 function Is_Subprogram_Contract_Annotation
13104 (Item
: Node_Id
) return Boolean
13109 if Nkind
(Item
) = N_Aspect_Specification
then
13110 Nam
:= Chars
(Identifier
(Item
));
13112 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
13113 Nam
:= Pragma_Name
(Item
);
13116 return Nam
= Name_Contract_Cases
13117 or else Nam
= Name_Depends
13118 or else Nam
= Name_Extensions_Visible
13119 or else Nam
= Name_Global
13120 or else Nam
= Name_Post
13121 or else Nam
= Name_Post_Class
13122 or else Nam
= Name_Postcondition
13123 or else Nam
= Name_Pre
13124 or else Nam
= Name_Pre_Class
13125 or else Nam
= Name_Precondition
13126 or else Nam
= Name_Refined_Depends
13127 or else Nam
= Name_Refined_Global
13128 or else Nam
= Name_Refined_Post
13129 or else Nam
= Name_Test_Case
;
13130 end Is_Subprogram_Contract_Annotation
;
13132 --------------------------------------------------
13133 -- Is_Subprogram_Stub_Without_Prior_Declaration --
13134 --------------------------------------------------
13136 function Is_Subprogram_Stub_Without_Prior_Declaration
13137 (N
: Node_Id
) return Boolean
13140 -- A subprogram stub without prior declaration serves as declaration for
13141 -- the actual subprogram body. As such, it has an attached defining
13142 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
13144 return Nkind
(N
) = N_Subprogram_Body_Stub
13145 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
13146 end Is_Subprogram_Stub_Without_Prior_Declaration
;
13148 ---------------------------------
13149 -- Is_Synchronized_Tagged_Type --
13150 ---------------------------------
13152 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
13153 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
13156 -- A task or protected type derived from an interface is a tagged type.
13157 -- Such a tagged type is called a synchronized tagged type, as are
13158 -- synchronized interfaces and private extensions whose declaration
13159 -- includes the reserved word synchronized.
13161 return (Is_Tagged_Type
(E
)
13162 and then (Kind
= E_Task_Type
13164 Kind
= E_Protected_Type
))
13167 and then Is_Synchronized_Interface
(E
))
13169 (Ekind
(E
) = E_Record_Type_With_Private
13170 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
13171 and then (Synchronized_Present
(Parent
(E
))
13172 or else Is_Synchronized_Interface
(Etype
(E
))));
13173 end Is_Synchronized_Tagged_Type
;
13179 function Is_Transfer
(N
: Node_Id
) return Boolean is
13180 Kind
: constant Node_Kind
:= Nkind
(N
);
13183 if Kind
= N_Simple_Return_Statement
13185 Kind
= N_Extended_Return_Statement
13187 Kind
= N_Goto_Statement
13189 Kind
= N_Raise_Statement
13191 Kind
= N_Requeue_Statement
13195 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
13196 and then No
(Condition
(N
))
13200 elsif Kind
= N_Procedure_Call_Statement
13201 and then Is_Entity_Name
(Name
(N
))
13202 and then Present
(Entity
(Name
(N
)))
13203 and then No_Return
(Entity
(Name
(N
)))
13207 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
13219 function Is_True
(U
: Uint
) return Boolean is
13224 --------------------------------------
13225 -- Is_Unchecked_Conversion_Instance --
13226 --------------------------------------
13228 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
13229 Gen_Par
: Entity_Id
;
13232 -- Look for a function whose generic parent is the predefined intrinsic
13233 -- function Unchecked_Conversion.
13235 if Ekind
(Id
) = E_Function
then
13236 Gen_Par
:= Generic_Parent
(Parent
(Id
));
13240 and then Chars
(Gen_Par
) = Name_Unchecked_Conversion
13241 and then Is_Intrinsic_Subprogram
(Gen_Par
)
13242 and then Is_Predefined_File_Name
13243 (Unit_File_Name
(Get_Source_Unit
(Gen_Par
)));
13247 end Is_Unchecked_Conversion_Instance
;
13249 -------------------------------
13250 -- Is_Universal_Numeric_Type --
13251 -------------------------------
13253 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
13255 return T
= Universal_Integer
or else T
= Universal_Real
;
13256 end Is_Universal_Numeric_Type
;
13258 -------------------
13259 -- Is_Value_Type --
13260 -------------------
13262 function Is_Value_Type
(T
: Entity_Id
) return Boolean is
13264 return VM_Target
= CLI_Target
13265 and then Nkind
(T
) in N_Has_Chars
13266 and then Chars
(T
) /= No_Name
13267 and then Get_Name_String
(Chars
(T
)) = "valuetype";
13270 ----------------------------
13271 -- Is_Variable_Size_Array --
13272 ----------------------------
13274 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
13278 pragma Assert
(Is_Array_Type
(E
));
13280 -- Check if some index is initialized with a non-constant value
13282 Idx
:= First_Index
(E
);
13283 while Present
(Idx
) loop
13284 if Nkind
(Idx
) = N_Range
then
13285 if not Is_Constant_Bound
(Low_Bound
(Idx
))
13286 or else not Is_Constant_Bound
(High_Bound
(Idx
))
13292 Idx
:= Next_Index
(Idx
);
13296 end Is_Variable_Size_Array
;
13298 -----------------------------
13299 -- Is_Variable_Size_Record --
13300 -----------------------------
13302 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
13304 Comp_Typ
: Entity_Id
;
13307 pragma Assert
(Is_Record_Type
(E
));
13309 Comp
:= First_Entity
(E
);
13310 while Present
(Comp
) loop
13311 Comp_Typ
:= Etype
(Comp
);
13313 -- Recursive call if the record type has discriminants
13315 if Is_Record_Type
(Comp_Typ
)
13316 and then Has_Discriminants
(Comp_Typ
)
13317 and then Is_Variable_Size_Record
(Comp_Typ
)
13321 elsif Is_Array_Type
(Comp_Typ
)
13322 and then Is_Variable_Size_Array
(Comp_Typ
)
13327 Next_Entity
(Comp
);
13331 end Is_Variable_Size_Record
;
13337 function Is_Variable
13339 Use_Original_Node
: Boolean := True) return Boolean
13341 Orig_Node
: Node_Id
;
13343 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
13344 -- Within a protected function, the private components of the enclosing
13345 -- protected type are constants. A function nested within a (protected)
13346 -- procedure is not itself protected. Within the body of a protected
13347 -- function the current instance of the protected type is a constant.
13349 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
13350 -- Prefixes can involve implicit dereferences, in which case we must
13351 -- test for the case of a reference of a constant access type, which can
13352 -- can never be a variable.
13354 ---------------------------
13355 -- In_Protected_Function --
13356 ---------------------------
13358 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
13363 -- E is the current instance of a type
13365 if Is_Type
(E
) then
13374 if not Is_Protected_Type
(Prot
) then
13378 S
:= Current_Scope
;
13379 while Present
(S
) and then S
/= Prot
loop
13380 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
13389 end In_Protected_Function
;
13391 ------------------------
13392 -- Is_Variable_Prefix --
13393 ------------------------
13395 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
13397 if Is_Access_Type
(Etype
(P
)) then
13398 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
13400 -- For the case of an indexed component whose prefix has a packed
13401 -- array type, the prefix has been rewritten into a type conversion.
13402 -- Determine variable-ness from the converted expression.
13404 elsif Nkind
(P
) = N_Type_Conversion
13405 and then not Comes_From_Source
(P
)
13406 and then Is_Array_Type
(Etype
(P
))
13407 and then Is_Packed
(Etype
(P
))
13409 return Is_Variable
(Expression
(P
));
13412 return Is_Variable
(P
);
13414 end Is_Variable_Prefix
;
13416 -- Start of processing for Is_Variable
13419 -- Special check, allow x'Deref(expr) as a variable
13421 if Nkind
(N
) = N_Attribute_Reference
13422 and then Attribute_Name
(N
) = Name_Deref
13427 -- Check if we perform the test on the original node since this may be a
13428 -- test of syntactic categories which must not be disturbed by whatever
13429 -- rewriting might have occurred. For example, an aggregate, which is
13430 -- certainly NOT a variable, could be turned into a variable by
13433 if Use_Original_Node
then
13434 Orig_Node
:= Original_Node
(N
);
13439 -- Definitely OK if Assignment_OK is set. Since this is something that
13440 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
13442 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
13445 -- Normally we go to the original node, but there is one exception where
13446 -- we use the rewritten node, namely when it is an explicit dereference.
13447 -- The generated code may rewrite a prefix which is an access type with
13448 -- an explicit dereference. The dereference is a variable, even though
13449 -- the original node may not be (since it could be a constant of the
13452 -- In Ada 2005 we have a further case to consider: the prefix may be a
13453 -- function call given in prefix notation. The original node appears to
13454 -- be a selected component, but we need to examine the call.
13456 elsif Nkind
(N
) = N_Explicit_Dereference
13457 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
13458 and then Present
(Etype
(Orig_Node
))
13459 and then Is_Access_Type
(Etype
(Orig_Node
))
13461 -- Note that if the prefix is an explicit dereference that does not
13462 -- come from source, we must check for a rewritten function call in
13463 -- prefixed notation before other forms of rewriting, to prevent a
13467 (Nkind
(Orig_Node
) = N_Function_Call
13468 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
13470 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
13472 -- in Ada 2012, the dereference may have been added for a type with
13473 -- a declared implicit dereference aspect. Check that it is not an
13474 -- access to constant.
13476 elsif Nkind
(N
) = N_Explicit_Dereference
13477 and then Present
(Etype
(Orig_Node
))
13478 and then Ada_Version
>= Ada_2012
13479 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
13481 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
13483 -- A function call is never a variable
13485 elsif Nkind
(N
) = N_Function_Call
then
13488 -- All remaining checks use the original node
13490 elsif Is_Entity_Name
(Orig_Node
)
13491 and then Present
(Entity
(Orig_Node
))
13494 E
: constant Entity_Id
:= Entity
(Orig_Node
);
13495 K
: constant Entity_Kind
:= Ekind
(E
);
13498 return (K
= E_Variable
13499 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
13500 or else (K
= E_Component
13501 and then not In_Protected_Function
(E
))
13502 or else K
= E_Out_Parameter
13503 or else K
= E_In_Out_Parameter
13504 or else K
= E_Generic_In_Out_Parameter
13506 -- Current instance of type. If this is a protected type, check
13507 -- we are not within the body of one of its protected functions.
13509 or else (Is_Type
(E
)
13510 and then In_Open_Scopes
(E
)
13511 and then not In_Protected_Function
(E
))
13513 or else (Is_Incomplete_Or_Private_Type
(E
)
13514 and then In_Open_Scopes
(Full_View
(E
)));
13518 case Nkind
(Orig_Node
) is
13519 when N_Indexed_Component | N_Slice
=>
13520 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
13522 when N_Selected_Component
=>
13523 return (Is_Variable
(Selector_Name
(Orig_Node
))
13524 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
13526 (Nkind
(N
) = N_Expanded_Name
13527 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
13529 -- For an explicit dereference, the type of the prefix cannot
13530 -- be an access to constant or an access to subprogram.
13532 when N_Explicit_Dereference
=>
13534 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
13536 return Is_Access_Type
(Typ
)
13537 and then not Is_Access_Constant
(Root_Type
(Typ
))
13538 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
13541 -- The type conversion is the case where we do not deal with the
13542 -- context dependent special case of an actual parameter. Thus
13543 -- the type conversion is only considered a variable for the
13544 -- purposes of this routine if the target type is tagged. However,
13545 -- a type conversion is considered to be a variable if it does not
13546 -- come from source (this deals for example with the conversions
13547 -- of expressions to their actual subtypes).
13549 when N_Type_Conversion
=>
13550 return Is_Variable
(Expression
(Orig_Node
))
13552 (not Comes_From_Source
(Orig_Node
)
13554 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
13556 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
13558 -- GNAT allows an unchecked type conversion as a variable. This
13559 -- only affects the generation of internal expanded code, since
13560 -- calls to instantiations of Unchecked_Conversion are never
13561 -- considered variables (since they are function calls).
13563 when N_Unchecked_Type_Conversion
=>
13564 return Is_Variable
(Expression
(Orig_Node
));
13572 ---------------------------
13573 -- Is_Visibly_Controlled --
13574 ---------------------------
13576 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
13577 Root
: constant Entity_Id
:= Root_Type
(T
);
13579 return Chars
(Scope
(Root
)) = Name_Finalization
13580 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
13581 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
13582 end Is_Visibly_Controlled
;
13584 ------------------------
13585 -- Is_Volatile_Object --
13586 ------------------------
13588 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
13590 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
13591 -- If prefix is an implicit dereference, examine designated type
13593 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
13594 -- Determines if given object has volatile components
13596 ------------------------
13597 -- Is_Volatile_Prefix --
13598 ------------------------
13600 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
13601 Typ
: constant Entity_Id
:= Etype
(N
);
13604 if Is_Access_Type
(Typ
) then
13606 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
13609 return Is_Volatile
(Dtyp
)
13610 or else Has_Volatile_Components
(Dtyp
);
13614 return Object_Has_Volatile_Components
(N
);
13616 end Is_Volatile_Prefix
;
13618 ------------------------------------
13619 -- Object_Has_Volatile_Components --
13620 ------------------------------------
13622 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
13623 Typ
: constant Entity_Id
:= Etype
(N
);
13626 if Is_Volatile
(Typ
)
13627 or else Has_Volatile_Components
(Typ
)
13631 elsif Is_Entity_Name
(N
)
13632 and then (Has_Volatile_Components
(Entity
(N
))
13633 or else Is_Volatile
(Entity
(N
)))
13637 elsif Nkind
(N
) = N_Indexed_Component
13638 or else Nkind
(N
) = N_Selected_Component
13640 return Is_Volatile_Prefix
(Prefix
(N
));
13645 end Object_Has_Volatile_Components
;
13647 -- Start of processing for Is_Volatile_Object
13650 if Nkind
(N
) = N_Defining_Identifier
then
13651 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
13653 elsif Nkind
(N
) = N_Expanded_Name
then
13654 return Is_Volatile_Object
(Entity
(N
));
13656 elsif Is_Volatile
(Etype
(N
))
13657 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
13661 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
13662 and then Is_Volatile_Prefix
(Prefix
(N
))
13666 elsif Nkind
(N
) = N_Selected_Component
13667 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
13674 end Is_Volatile_Object
;
13676 ---------------------------
13677 -- Itype_Has_Declaration --
13678 ---------------------------
13680 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
13682 pragma Assert
(Is_Itype
(Id
));
13683 return Present
(Parent
(Id
))
13684 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
13685 N_Subtype_Declaration
)
13686 and then Defining_Entity
(Parent
(Id
)) = Id
;
13687 end Itype_Has_Declaration
;
13689 -------------------------
13690 -- Kill_Current_Values --
13691 -------------------------
13693 procedure Kill_Current_Values
13695 Last_Assignment_Only
: Boolean := False)
13698 if Is_Assignable
(Ent
) then
13699 Set_Last_Assignment
(Ent
, Empty
);
13702 if Is_Object
(Ent
) then
13703 if not Last_Assignment_Only
then
13705 Set_Current_Value
(Ent
, Empty
);
13707 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
13708 -- for a constant. Once the constant is elaborated, its value is
13709 -- not changed, therefore the associated flags that describe the
13710 -- value should not be modified either.
13712 if Ekind
(Ent
) = E_Constant
then
13715 -- Non-constant entities
13718 if not Can_Never_Be_Null
(Ent
) then
13719 Set_Is_Known_Non_Null
(Ent
, False);
13722 Set_Is_Known_Null
(Ent
, False);
13724 -- Reset the Is_Known_Valid flag unless the type is always
13725 -- valid. This does not apply to a loop parameter because its
13726 -- bounds are defined by the loop header and therefore always
13729 if not Is_Known_Valid
(Etype
(Ent
))
13730 and then Ekind
(Ent
) /= E_Loop_Parameter
13732 Set_Is_Known_Valid
(Ent
, False);
13737 end Kill_Current_Values
;
13739 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
13742 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
13743 -- Clear current value for entity E and all entities chained to E
13745 ------------------------------------------
13746 -- Kill_Current_Values_For_Entity_Chain --
13747 ------------------------------------------
13749 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
13753 while Present
(Ent
) loop
13754 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
13757 end Kill_Current_Values_For_Entity_Chain
;
13759 -- Start of processing for Kill_Current_Values
13762 -- Kill all saved checks, a special case of killing saved values
13764 if not Last_Assignment_Only
then
13768 -- Loop through relevant scopes, which includes the current scope and
13769 -- any parent scopes if the current scope is a block or a package.
13771 S
:= Current_Scope
;
13774 -- Clear current values of all entities in current scope
13776 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
13778 -- If scope is a package, also clear current values of all private
13779 -- entities in the scope.
13781 if Is_Package_Or_Generic_Package
(S
)
13782 or else Is_Concurrent_Type
(S
)
13784 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
13787 -- If this is a not a subprogram, deal with parents
13789 if not Is_Subprogram
(S
) then
13791 exit Scope_Loop
when S
= Standard_Standard
;
13795 end loop Scope_Loop
;
13796 end Kill_Current_Values
;
13798 --------------------------
13799 -- Kill_Size_Check_Code --
13800 --------------------------
13802 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
13804 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
13805 and then Present
(Size_Check_Code
(E
))
13807 Remove
(Size_Check_Code
(E
));
13808 Set_Size_Check_Code
(E
, Empty
);
13810 end Kill_Size_Check_Code
;
13812 --------------------------
13813 -- Known_To_Be_Assigned --
13814 --------------------------
13816 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
13817 P
: constant Node_Id
:= Parent
(N
);
13822 -- Test left side of assignment
13824 when N_Assignment_Statement
=>
13825 return N
= Name
(P
);
13827 -- Function call arguments are never lvalues
13829 when N_Function_Call
=>
13832 -- Positional parameter for procedure or accept call
13834 when N_Procedure_Call_Statement |
13843 Proc
:= Get_Subprogram_Entity
(P
);
13849 -- If we are not a list member, something is strange, so
13850 -- be conservative and return False.
13852 if not Is_List_Member
(N
) then
13856 -- We are going to find the right formal by stepping forward
13857 -- through the formals, as we step backwards in the actuals.
13859 Form
:= First_Formal
(Proc
);
13862 -- If no formal, something is weird, so be conservative
13863 -- and return False.
13870 exit when No
(Act
);
13871 Next_Formal
(Form
);
13874 return Ekind
(Form
) /= E_In_Parameter
;
13877 -- Named parameter for procedure or accept call
13879 when N_Parameter_Association
=>
13885 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
13891 -- Loop through formals to find the one that matches
13893 Form
:= First_Formal
(Proc
);
13895 -- If no matching formal, that's peculiar, some kind of
13896 -- previous error, so return False to be conservative.
13897 -- Actually this also happens in legal code in the case
13898 -- where P is a parameter association for an Extra_Formal???
13904 -- Else test for match
13906 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
13907 return Ekind
(Form
) /= E_In_Parameter
;
13910 Next_Formal
(Form
);
13914 -- Test for appearing in a conversion that itself appears
13915 -- in an lvalue context, since this should be an lvalue.
13917 when N_Type_Conversion
=>
13918 return Known_To_Be_Assigned
(P
);
13920 -- All other references are definitely not known to be modifications
13926 end Known_To_Be_Assigned
;
13928 ---------------------------
13929 -- Last_Source_Statement --
13930 ---------------------------
13932 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
13936 N
:= Last
(Statements
(HSS
));
13937 while Present
(N
) loop
13938 exit when Comes_From_Source
(N
);
13943 end Last_Source_Statement
;
13945 ----------------------------------
13946 -- Matching_Static_Array_Bounds --
13947 ----------------------------------
13949 function Matching_Static_Array_Bounds
13951 R_Typ
: Node_Id
) return Boolean
13953 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
13954 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
13966 if L_Ndims
/= R_Ndims
then
13970 -- Unconstrained types do not have static bounds
13972 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
13976 -- First treat specially the first dimension, as the lower bound and
13977 -- length of string literals are not stored like those of arrays.
13979 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
13980 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
13981 L_Len
:= String_Literal_Length
(L_Typ
);
13983 L_Index
:= First_Index
(L_Typ
);
13984 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
13986 if Is_OK_Static_Expression
(L_Low
)
13988 Is_OK_Static_Expression
(L_High
)
13990 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
13993 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
14000 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
14001 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
14002 R_Len
:= String_Literal_Length
(R_Typ
);
14004 R_Index
:= First_Index
(R_Typ
);
14005 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
14007 if Is_OK_Static_Expression
(R_Low
)
14009 Is_OK_Static_Expression
(R_High
)
14011 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
14014 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
14021 if (Is_OK_Static_Expression
(L_Low
)
14023 Is_OK_Static_Expression
(R_Low
))
14024 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
14025 and then L_Len
= R_Len
14032 -- Then treat all other dimensions
14034 for Indx
in 2 .. L_Ndims
loop
14038 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
14039 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
14041 if (Is_OK_Static_Expression
(L_Low
) and then
14042 Is_OK_Static_Expression
(L_High
) and then
14043 Is_OK_Static_Expression
(R_Low
) and then
14044 Is_OK_Static_Expression
(R_High
))
14045 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
14047 Expr_Value
(L_High
) = Expr_Value
(R_High
))
14055 -- If we fall through the loop, all indexes matched
14058 end Matching_Static_Array_Bounds
;
14060 -------------------
14061 -- May_Be_Lvalue --
14062 -------------------
14064 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
14065 P
: constant Node_Id
:= Parent
(N
);
14070 -- Test left side of assignment
14072 when N_Assignment_Statement
=>
14073 return N
= Name
(P
);
14075 -- Test prefix of component or attribute. Note that the prefix of an
14076 -- explicit or implicit dereference cannot be an l-value.
14078 when N_Attribute_Reference
=>
14079 return N
= Prefix
(P
)
14080 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
));
14082 -- For an expanded name, the name is an lvalue if the expanded name
14083 -- is an lvalue, but the prefix is never an lvalue, since it is just
14084 -- the scope where the name is found.
14086 when N_Expanded_Name
=>
14087 if N
= Prefix
(P
) then
14088 return May_Be_Lvalue
(P
);
14093 -- For a selected component A.B, A is certainly an lvalue if A.B is.
14094 -- B is a little interesting, if we have A.B := 3, there is some
14095 -- discussion as to whether B is an lvalue or not, we choose to say
14096 -- it is. Note however that A is not an lvalue if it is of an access
14097 -- type since this is an implicit dereference.
14099 when N_Selected_Component
=>
14101 and then Present
(Etype
(N
))
14102 and then Is_Access_Type
(Etype
(N
))
14106 return May_Be_Lvalue
(P
);
14109 -- For an indexed component or slice, the index or slice bounds is
14110 -- never an lvalue. The prefix is an lvalue if the indexed component
14111 -- or slice is an lvalue, except if it is an access type, where we
14112 -- have an implicit dereference.
14114 when N_Indexed_Component | N_Slice
=>
14116 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
14120 return May_Be_Lvalue
(P
);
14123 -- Prefix of a reference is an lvalue if the reference is an lvalue
14125 when N_Reference
=>
14126 return May_Be_Lvalue
(P
);
14128 -- Prefix of explicit dereference is never an lvalue
14130 when N_Explicit_Dereference
=>
14133 -- Positional parameter for subprogram, entry, or accept call.
14134 -- In older versions of Ada function call arguments are never
14135 -- lvalues. In Ada 2012 functions can have in-out parameters.
14137 when N_Subprogram_Call |
14138 N_Entry_Call_Statement |
14141 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
14145 -- The following mechanism is clumsy and fragile. A single flag
14146 -- set in Resolve_Actuals would be preferable ???
14154 Proc
:= Get_Subprogram_Entity
(P
);
14160 -- If we are not a list member, something is strange, so be
14161 -- conservative and return True.
14163 if not Is_List_Member
(N
) then
14167 -- We are going to find the right formal by stepping forward
14168 -- through the formals, as we step backwards in the actuals.
14170 Form
:= First_Formal
(Proc
);
14173 -- If no formal, something is weird, so be conservative and
14181 exit when No
(Act
);
14182 Next_Formal
(Form
);
14185 return Ekind
(Form
) /= E_In_Parameter
;
14188 -- Named parameter for procedure or accept call
14190 when N_Parameter_Association
=>
14196 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
14202 -- Loop through formals to find the one that matches
14204 Form
:= First_Formal
(Proc
);
14206 -- If no matching formal, that's peculiar, some kind of
14207 -- previous error, so return True to be conservative.
14208 -- Actually happens with legal code for an unresolved call
14209 -- where we may get the wrong homonym???
14215 -- Else test for match
14217 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
14218 return Ekind
(Form
) /= E_In_Parameter
;
14221 Next_Formal
(Form
);
14225 -- Test for appearing in a conversion that itself appears in an
14226 -- lvalue context, since this should be an lvalue.
14228 when N_Type_Conversion
=>
14229 return May_Be_Lvalue
(P
);
14231 -- Test for appearance in object renaming declaration
14233 when N_Object_Renaming_Declaration
=>
14236 -- All other references are definitely not lvalues
14244 -----------------------
14245 -- Mark_Coextensions --
14246 -----------------------
14248 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
14249 Is_Dynamic
: Boolean;
14250 -- Indicates whether the context causes nested coextensions to be
14251 -- dynamic or static
14253 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
14254 -- Recognize an allocator node and label it as a dynamic coextension
14256 --------------------
14257 -- Mark_Allocator --
14258 --------------------
14260 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
14262 if Nkind
(N
) = N_Allocator
then
14264 Set_Is_Dynamic_Coextension
(N
);
14266 -- If the allocator expression is potentially dynamic, it may
14267 -- be expanded out of order and require dynamic allocation
14268 -- anyway, so we treat the coextension itself as dynamic.
14269 -- Potential optimization ???
14271 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
14272 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
14274 Set_Is_Dynamic_Coextension
(N
);
14276 Set_Is_Static_Coextension
(N
);
14281 end Mark_Allocator
;
14283 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
14285 -- Start of processing Mark_Coextensions
14288 case Nkind
(Context_Nod
) is
14290 -- Comment here ???
14292 when N_Assignment_Statement
=>
14293 Is_Dynamic
:= Nkind
(Expression
(Context_Nod
)) = N_Allocator
;
14295 -- An allocator that is a component of a returned aggregate
14296 -- must be dynamic.
14298 when N_Simple_Return_Statement
=>
14300 Expr
: constant Node_Id
:= Expression
(Context_Nod
);
14303 Nkind
(Expr
) = N_Allocator
14305 (Nkind
(Expr
) = N_Qualified_Expression
14306 and then Nkind
(Expression
(Expr
)) = N_Aggregate
);
14309 -- An alloctor within an object declaration in an extended return
14310 -- statement is of necessity dynamic.
14312 when N_Object_Declaration
=>
14313 Is_Dynamic
:= Nkind
(Root_Nod
) = N_Allocator
14315 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
14317 -- This routine should not be called for constructs which may not
14318 -- contain coextensions.
14321 raise Program_Error
;
14324 Mark_Allocators
(Root_Nod
);
14325 end Mark_Coextensions
;
14327 ----------------------
14328 -- Needs_One_Actual --
14329 ----------------------
14331 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
14332 Formal
: Entity_Id
;
14335 -- Ada 2005 or later, and formals present
14337 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
14338 Formal
:= Next_Formal
(First_Formal
(E
));
14339 while Present
(Formal
) loop
14340 if No
(Default_Value
(Formal
)) then
14344 Next_Formal
(Formal
);
14349 -- Ada 83/95 or no formals
14354 end Needs_One_Actual
;
14356 ------------------------
14357 -- New_Copy_List_Tree --
14358 ------------------------
14360 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
14365 if List
= No_List
then
14372 while Present
(E
) loop
14373 Append
(New_Copy_Tree
(E
), NL
);
14379 end New_Copy_List_Tree
;
14381 --------------------------------------------------
14382 -- New_Copy_Tree Auxiliary Data and Subprograms --
14383 --------------------------------------------------
14385 use Atree
.Unchecked_Access
;
14386 use Atree_Private_Part
;
14388 -- Our approach here requires a two pass traversal of the tree. The
14389 -- first pass visits all nodes that eventually will be copied looking
14390 -- for defining Itypes. If any defining Itypes are found, then they are
14391 -- copied, and an entry is added to the replacement map. In the second
14392 -- phase, the tree is copied, using the replacement map to replace any
14393 -- Itype references within the copied tree.
14395 -- The following hash tables are used if the Map supplied has more
14396 -- than hash threshold entries to speed up access to the map. If
14397 -- there are fewer entries, then the map is searched sequentially
14398 -- (because setting up a hash table for only a few entries takes
14399 -- more time than it saves.
14401 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
14402 -- Hash function used for hash operations
14404 -------------------
14405 -- New_Copy_Hash --
14406 -------------------
14408 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
14410 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
14417 -- The hash table NCT_Assoc associates old entities in the table
14418 -- with their corresponding new entities (i.e. the pairs of entries
14419 -- presented in the original Map argument are Key-Element pairs).
14421 package NCT_Assoc
is new Simple_HTable
(
14422 Header_Num
=> NCT_Header_Num
,
14423 Element
=> Entity_Id
,
14424 No_Element
=> Empty
,
14426 Hash
=> New_Copy_Hash
,
14427 Equal
=> Types
."=");
14429 ---------------------
14430 -- NCT_Itype_Assoc --
14431 ---------------------
14433 -- The hash table NCT_Itype_Assoc contains entries only for those
14434 -- old nodes which have a non-empty Associated_Node_For_Itype set.
14435 -- The key is the associated node, and the element is the new node
14436 -- itself (NOT the associated node for the new node).
14438 package NCT_Itype_Assoc
is new Simple_HTable
(
14439 Header_Num
=> NCT_Header_Num
,
14440 Element
=> Entity_Id
,
14441 No_Element
=> Empty
,
14443 Hash
=> New_Copy_Hash
,
14444 Equal
=> Types
."=");
14446 -------------------
14447 -- New_Copy_Tree --
14448 -------------------
14450 function New_Copy_Tree
14452 Map
: Elist_Id
:= No_Elist
;
14453 New_Sloc
: Source_Ptr
:= No_Location
;
14454 New_Scope
: Entity_Id
:= Empty
) return Node_Id
14456 Actual_Map
: Elist_Id
:= Map
;
14457 -- This is the actual map for the copy. It is initialized with the
14458 -- given elements, and then enlarged as required for Itypes that are
14459 -- copied during the first phase of the copy operation. The visit
14460 -- procedures add elements to this map as Itypes are encountered.
14461 -- The reason we cannot use Map directly, is that it may well be
14462 -- (and normally is) initialized to No_Elist, and if we have mapped
14463 -- entities, we have to reset it to point to a real Elist.
14465 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
14466 -- Called during second phase to map entities into their corresponding
14467 -- copies using Actual_Map. If the argument is not an entity, or is not
14468 -- in Actual_Map, then it is returned unchanged.
14470 procedure Build_NCT_Hash_Tables
;
14471 -- Builds hash tables (number of elements >= threshold value)
14473 function Copy_Elist_With_Replacement
14474 (Old_Elist
: Elist_Id
) return Elist_Id
;
14475 -- Called during second phase to copy element list doing replacements
14477 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
14478 -- Called during the second phase to process a copied Itype. The actual
14479 -- copy happened during the first phase (so that we could make the entry
14480 -- in the mapping), but we still have to deal with the descendents of
14481 -- the copied Itype and copy them where necessary.
14483 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
14484 -- Called during second phase to copy list doing replacements
14486 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
14487 -- Called during second phase to copy node doing replacements
14489 procedure Visit_Elist
(E
: Elist_Id
);
14490 -- Called during first phase to visit all elements of an Elist
14492 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
14493 -- Visit a single field, recursing to call Visit_Node or Visit_List
14494 -- if the field is a syntactic descendent of the current node (i.e.
14495 -- its parent is Node N).
14497 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
14498 -- Called during first phase to visit subsidiary fields of a defining
14499 -- Itype, and also create a copy and make an entry in the replacement
14500 -- map for the new copy.
14502 procedure Visit_List
(L
: List_Id
);
14503 -- Called during first phase to visit all elements of a List
14505 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
14506 -- Called during first phase to visit a node and all its subtrees
14512 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
14517 if not Has_Extension
(N
) or else No
(Actual_Map
) then
14520 elsif NCT_Hash_Tables_Used
then
14521 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
14523 if Present
(Ent
) then
14529 -- No hash table used, do serial search
14532 E
:= First_Elmt
(Actual_Map
);
14533 while Present
(E
) loop
14534 if Node
(E
) = N
then
14535 return Node
(Next_Elmt
(E
));
14537 E
:= Next_Elmt
(Next_Elmt
(E
));
14545 ---------------------------
14546 -- Build_NCT_Hash_Tables --
14547 ---------------------------
14549 procedure Build_NCT_Hash_Tables
is
14553 if NCT_Hash_Table_Setup
then
14555 NCT_Itype_Assoc
.Reset
;
14558 Elmt
:= First_Elmt
(Actual_Map
);
14559 while Present
(Elmt
) loop
14560 Ent
:= Node
(Elmt
);
14562 -- Get new entity, and associate old and new
14565 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
14567 if Is_Type
(Ent
) then
14569 Anode
: constant Entity_Id
:=
14570 Associated_Node_For_Itype
(Ent
);
14573 if Present
(Anode
) then
14575 -- Enter a link between the associated node of the
14576 -- old Itype and the new Itype, for updating later
14577 -- when node is copied.
14579 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
14587 NCT_Hash_Tables_Used
:= True;
14588 NCT_Hash_Table_Setup
:= True;
14589 end Build_NCT_Hash_Tables
;
14591 ---------------------------------
14592 -- Copy_Elist_With_Replacement --
14593 ---------------------------------
14595 function Copy_Elist_With_Replacement
14596 (Old_Elist
: Elist_Id
) return Elist_Id
14599 New_Elist
: Elist_Id
;
14602 if No
(Old_Elist
) then
14606 New_Elist
:= New_Elmt_List
;
14608 M
:= First_Elmt
(Old_Elist
);
14609 while Present
(M
) loop
14610 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
14616 end Copy_Elist_With_Replacement
;
14618 ---------------------------------
14619 -- Copy_Itype_With_Replacement --
14620 ---------------------------------
14622 -- This routine exactly parallels its phase one analog Visit_Itype,
14624 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
14626 -- Translate Next_Entity, Scope and Etype fields, in case they
14627 -- reference entities that have been mapped into copies.
14629 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
14630 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
14632 if Present
(New_Scope
) then
14633 Set_Scope
(New_Itype
, New_Scope
);
14635 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
14638 -- Copy referenced fields
14640 if Is_Discrete_Type
(New_Itype
) then
14641 Set_Scalar_Range
(New_Itype
,
14642 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
14644 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
14645 Set_Discriminant_Constraint
(New_Itype
,
14646 Copy_Elist_With_Replacement
14647 (Discriminant_Constraint
(New_Itype
)));
14649 elsif Is_Array_Type
(New_Itype
) then
14650 if Present
(First_Index
(New_Itype
)) then
14651 Set_First_Index
(New_Itype
,
14652 First
(Copy_List_With_Replacement
14653 (List_Containing
(First_Index
(New_Itype
)))));
14656 if Is_Packed
(New_Itype
) then
14657 Set_Packed_Array_Impl_Type
(New_Itype
,
14658 Copy_Node_With_Replacement
14659 (Packed_Array_Impl_Type
(New_Itype
)));
14662 end Copy_Itype_With_Replacement
;
14664 --------------------------------
14665 -- Copy_List_With_Replacement --
14666 --------------------------------
14668 function Copy_List_With_Replacement
14669 (Old_List
: List_Id
) return List_Id
14671 New_List
: List_Id
;
14675 if Old_List
= No_List
then
14679 New_List
:= Empty_List
;
14681 E
:= First
(Old_List
);
14682 while Present
(E
) loop
14683 Append
(Copy_Node_With_Replacement
(E
), New_List
);
14689 end Copy_List_With_Replacement
;
14691 --------------------------------
14692 -- Copy_Node_With_Replacement --
14693 --------------------------------
14695 function Copy_Node_With_Replacement
14696 (Old_Node
: Node_Id
) return Node_Id
14698 New_Node
: Node_Id
;
14700 procedure Adjust_Named_Associations
14701 (Old_Node
: Node_Id
;
14702 New_Node
: Node_Id
);
14703 -- If a call node has named associations, these are chained through
14704 -- the First_Named_Actual, Next_Named_Actual links. These must be
14705 -- propagated separately to the new parameter list, because these
14706 -- are not syntactic fields.
14708 function Copy_Field_With_Replacement
14709 (Field
: Union_Id
) return Union_Id
;
14710 -- Given Field, which is a field of Old_Node, return a copy of it
14711 -- if it is a syntactic field (i.e. its parent is Node), setting
14712 -- the parent of the copy to poit to New_Node. Otherwise returns
14713 -- the field (possibly mapped if it is an entity).
14715 -------------------------------
14716 -- Adjust_Named_Associations --
14717 -------------------------------
14719 procedure Adjust_Named_Associations
14720 (Old_Node
: Node_Id
;
14721 New_Node
: Node_Id
)
14726 Old_Next
: Node_Id
;
14727 New_Next
: Node_Id
;
14730 Old_E
:= First
(Parameter_Associations
(Old_Node
));
14731 New_E
:= First
(Parameter_Associations
(New_Node
));
14732 while Present
(Old_E
) loop
14733 if Nkind
(Old_E
) = N_Parameter_Association
14734 and then Present
(Next_Named_Actual
(Old_E
))
14736 if First_Named_Actual
(Old_Node
)
14737 = Explicit_Actual_Parameter
(Old_E
)
14739 Set_First_Named_Actual
14740 (New_Node
, Explicit_Actual_Parameter
(New_E
));
14743 -- Now scan parameter list from the beginning,to locate
14744 -- next named actual, which can be out of order.
14746 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
14747 New_Next
:= First
(Parameter_Associations
(New_Node
));
14749 while Nkind
(Old_Next
) /= N_Parameter_Association
14750 or else Explicit_Actual_Parameter
(Old_Next
) /=
14751 Next_Named_Actual
(Old_E
)
14757 Set_Next_Named_Actual
14758 (New_E
, Explicit_Actual_Parameter
(New_Next
));
14764 end Adjust_Named_Associations
;
14766 ---------------------------------
14767 -- Copy_Field_With_Replacement --
14768 ---------------------------------
14770 function Copy_Field_With_Replacement
14771 (Field
: Union_Id
) return Union_Id
14774 if Field
= Union_Id
(Empty
) then
14777 elsif Field
in Node_Range
then
14779 Old_N
: constant Node_Id
:= Node_Id
(Field
);
14783 -- If syntactic field, as indicated by the parent pointer
14784 -- being set, then copy the referenced node recursively.
14786 if Parent
(Old_N
) = Old_Node
then
14787 New_N
:= Copy_Node_With_Replacement
(Old_N
);
14789 if New_N
/= Old_N
then
14790 Set_Parent
(New_N
, New_Node
);
14793 -- For semantic fields, update possible entity reference
14794 -- from the replacement map.
14797 New_N
:= Assoc
(Old_N
);
14800 return Union_Id
(New_N
);
14803 elsif Field
in List_Range
then
14805 Old_L
: constant List_Id
:= List_Id
(Field
);
14809 -- If syntactic field, as indicated by the parent pointer,
14810 -- then recursively copy the entire referenced list.
14812 if Parent
(Old_L
) = Old_Node
then
14813 New_L
:= Copy_List_With_Replacement
(Old_L
);
14814 Set_Parent
(New_L
, New_Node
);
14816 -- For semantic list, just returned unchanged
14822 return Union_Id
(New_L
);
14825 -- Anything other than a list or a node is returned unchanged
14830 end Copy_Field_With_Replacement
;
14832 -- Start of processing for Copy_Node_With_Replacement
14835 if Old_Node
<= Empty_Or_Error
then
14838 elsif Has_Extension
(Old_Node
) then
14839 return Assoc
(Old_Node
);
14842 New_Node
:= New_Copy
(Old_Node
);
14844 -- If the node we are copying is the associated node of a
14845 -- previously copied Itype, then adjust the associated node
14846 -- of the copy of that Itype accordingly.
14848 if Present
(Actual_Map
) then
14854 -- Case of hash table used
14856 if NCT_Hash_Tables_Used
then
14857 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
14859 if Present
(Ent
) then
14860 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
14863 -- Case of no hash table used
14866 E
:= First_Elmt
(Actual_Map
);
14867 while Present
(E
) loop
14868 if Is_Itype
(Node
(E
))
14870 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
14872 Set_Associated_Node_For_Itype
14873 (Node
(Next_Elmt
(E
)), New_Node
);
14876 E
:= Next_Elmt
(Next_Elmt
(E
));
14882 -- Recursively copy descendents
14885 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
14887 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
14889 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
14891 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
14893 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
14895 -- Adjust Sloc of new node if necessary
14897 if New_Sloc
/= No_Location
then
14898 Set_Sloc
(New_Node
, New_Sloc
);
14900 -- If we adjust the Sloc, then we are essentially making
14901 -- a completely new node, so the Comes_From_Source flag
14902 -- should be reset to the proper default value.
14904 Nodes
.Table
(New_Node
).Comes_From_Source
:=
14905 Default_Node
.Comes_From_Source
;
14908 -- If the node is call and has named associations,
14909 -- set the corresponding links in the copy.
14911 if (Nkind
(Old_Node
) = N_Function_Call
14912 or else Nkind
(Old_Node
) = N_Entry_Call_Statement
14914 Nkind
(Old_Node
) = N_Procedure_Call_Statement
)
14915 and then Present
(First_Named_Actual
(Old_Node
))
14917 Adjust_Named_Associations
(Old_Node
, New_Node
);
14920 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
14921 -- The replacement mechanism applies to entities, and is not used
14922 -- here. Eventually we may need a more general graph-copying
14923 -- routine. For now, do a sequential search to find desired node.
14925 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
14926 and then Present
(First_Real_Statement
(Old_Node
))
14929 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
14933 N1
:= First
(Statements
(Old_Node
));
14934 N2
:= First
(Statements
(New_Node
));
14936 while N1
/= Old_F
loop
14941 Set_First_Real_Statement
(New_Node
, N2
);
14946 -- All done, return copied node
14949 end Copy_Node_With_Replacement
;
14955 procedure Visit_Elist
(E
: Elist_Id
) is
14958 if Present
(E
) then
14959 Elmt
:= First_Elmt
(E
);
14961 while Elmt
/= No_Elmt
loop
14962 Visit_Node
(Node
(Elmt
));
14972 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
14974 if F
= Union_Id
(Empty
) then
14977 elsif F
in Node_Range
then
14979 -- Copy node if it is syntactic, i.e. its parent pointer is
14980 -- set to point to the field that referenced it (certain
14981 -- Itypes will also meet this criterion, which is fine, since
14982 -- these are clearly Itypes that do need to be copied, since
14983 -- we are copying their parent.)
14985 if Parent
(Node_Id
(F
)) = N
then
14986 Visit_Node
(Node_Id
(F
));
14989 -- Another case, if we are pointing to an Itype, then we want
14990 -- to copy it if its associated node is somewhere in the tree
14993 -- Note: the exclusion of self-referential copies is just an
14994 -- optimization, since the search of the already copied list
14995 -- would catch it, but it is a common case (Etype pointing
14996 -- to itself for an Itype that is a base type).
14998 elsif Has_Extension
(Node_Id
(F
))
14999 and then Is_Itype
(Entity_Id
(F
))
15000 and then Node_Id
(F
) /= N
15006 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
15007 while Present
(P
) loop
15009 Visit_Node
(Node_Id
(F
));
15016 -- An Itype whose parent is not being copied definitely
15017 -- should NOT be copied, since it does not belong in any
15018 -- sense to the copied subtree.
15024 elsif F
in List_Range
and then Parent
(List_Id
(F
)) = N
then
15025 Visit_List
(List_Id
(F
));
15034 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
15035 New_Itype
: Entity_Id
;
15040 -- Itypes that describe the designated type of access to subprograms
15041 -- have the structure of subprogram declarations, with signatures,
15042 -- etc. Either we duplicate the signatures completely, or choose to
15043 -- share such itypes, which is fine because their elaboration will
15044 -- have no side effects.
15046 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
15050 New_Itype
:= New_Copy
(Old_Itype
);
15052 -- The new Itype has all the attributes of the old one, and
15053 -- we just copy the contents of the entity. However, the back-end
15054 -- needs different names for debugging purposes, so we create a
15055 -- new internal name for it in all cases.
15057 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
15059 -- If our associated node is an entity that has already been copied,
15060 -- then set the associated node of the copy to point to the right
15061 -- copy. If we have copied an Itype that is itself the associated
15062 -- node of some previously copied Itype, then we set the right
15063 -- pointer in the other direction.
15065 if Present
(Actual_Map
) then
15067 -- Case of hash tables used
15069 if NCT_Hash_Tables_Used
then
15071 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
15073 if Present
(Ent
) then
15074 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
15077 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
15078 if Present
(Ent
) then
15079 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
15081 -- If the hash table has no association for this Itype and
15082 -- its associated node, enter one now.
15085 NCT_Itype_Assoc
.Set
15086 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
15089 -- Case of hash tables not used
15092 E
:= First_Elmt
(Actual_Map
);
15093 while Present
(E
) loop
15094 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
15095 Set_Associated_Node_For_Itype
15096 (New_Itype
, Node
(Next_Elmt
(E
)));
15099 if Is_Type
(Node
(E
))
15100 and then Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
15102 Set_Associated_Node_For_Itype
15103 (Node
(Next_Elmt
(E
)), New_Itype
);
15106 E
:= Next_Elmt
(Next_Elmt
(E
));
15111 if Present
(Freeze_Node
(New_Itype
)) then
15112 Set_Is_Frozen
(New_Itype
, False);
15113 Set_Freeze_Node
(New_Itype
, Empty
);
15116 -- Add new association to map
15118 if No
(Actual_Map
) then
15119 Actual_Map
:= New_Elmt_List
;
15122 Append_Elmt
(Old_Itype
, Actual_Map
);
15123 Append_Elmt
(New_Itype
, Actual_Map
);
15125 if NCT_Hash_Tables_Used
then
15126 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
15129 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
15131 if NCT_Table_Entries
> NCT_Hash_Threshold
then
15132 Build_NCT_Hash_Tables
;
15136 -- If a record subtype is simply copied, the entity list will be
15137 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
15139 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
15140 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
15143 -- Visit descendents that eventually get copied
15145 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
15147 if Is_Discrete_Type
(Old_Itype
) then
15148 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
15150 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
15151 -- ??? This should involve call to Visit_Field
15152 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
15154 elsif Is_Array_Type
(Old_Itype
) then
15155 if Present
(First_Index
(Old_Itype
)) then
15156 Visit_Field
(Union_Id
(List_Containing
15157 (First_Index
(Old_Itype
))),
15161 if Is_Packed
(Old_Itype
) then
15162 Visit_Field
(Union_Id
(Packed_Array_Impl_Type
(Old_Itype
)),
15172 procedure Visit_List
(L
: List_Id
) is
15175 if L
/= No_List
then
15178 while Present
(N
) loop
15189 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
15191 -- Start of processing for Visit_Node
15194 -- Handle case of an Itype, which must be copied
15196 if Has_Extension
(N
) and then Is_Itype
(N
) then
15198 -- Nothing to do if already in the list. This can happen with an
15199 -- Itype entity that appears more than once in the tree.
15200 -- Note that we do not want to visit descendents in this case.
15202 -- Test for already in list when hash table is used
15204 if NCT_Hash_Tables_Used
then
15205 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
15209 -- Test for already in list when hash table not used
15215 if Present
(Actual_Map
) then
15216 E
:= First_Elmt
(Actual_Map
);
15217 while Present
(E
) loop
15218 if Node
(E
) = N
then
15221 E
:= Next_Elmt
(Next_Elmt
(E
));
15231 -- Visit descendents
15233 Visit_Field
(Field1
(N
), N
);
15234 Visit_Field
(Field2
(N
), N
);
15235 Visit_Field
(Field3
(N
), N
);
15236 Visit_Field
(Field4
(N
), N
);
15237 Visit_Field
(Field5
(N
), N
);
15240 -- Start of processing for New_Copy_Tree
15245 -- See if we should use hash table
15247 if No
(Actual_Map
) then
15248 NCT_Hash_Tables_Used
:= False;
15255 NCT_Table_Entries
:= 0;
15257 Elmt
:= First_Elmt
(Actual_Map
);
15258 while Present
(Elmt
) loop
15259 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
15264 if NCT_Table_Entries
> NCT_Hash_Threshold
then
15265 Build_NCT_Hash_Tables
;
15267 NCT_Hash_Tables_Used
:= False;
15272 -- Hash table set up if required, now start phase one by visiting
15273 -- top node (we will recursively visit the descendents).
15275 Visit_Node
(Source
);
15277 -- Now the second phase of the copy can start. First we process
15278 -- all the mapped entities, copying their descendents.
15280 if Present
(Actual_Map
) then
15283 New_Itype
: Entity_Id
;
15285 Elmt
:= First_Elmt
(Actual_Map
);
15286 while Present
(Elmt
) loop
15288 New_Itype
:= Node
(Elmt
);
15289 Copy_Itype_With_Replacement
(New_Itype
);
15295 -- Now we can copy the actual tree
15297 return Copy_Node_With_Replacement
(Source
);
15300 -------------------------
15301 -- New_External_Entity --
15302 -------------------------
15304 function New_External_Entity
15305 (Kind
: Entity_Kind
;
15306 Scope_Id
: Entity_Id
;
15307 Sloc_Value
: Source_Ptr
;
15308 Related_Id
: Entity_Id
;
15309 Suffix
: Character;
15310 Suffix_Index
: Nat
:= 0;
15311 Prefix
: Character := ' ') return Entity_Id
15313 N
: constant Entity_Id
:=
15314 Make_Defining_Identifier
(Sloc_Value
,
15316 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
15319 Set_Ekind
(N
, Kind
);
15320 Set_Is_Internal
(N
, True);
15321 Append_Entity
(N
, Scope_Id
);
15322 Set_Public_Status
(N
);
15324 if Kind
in Type_Kind
then
15325 Init_Size_Align
(N
);
15329 end New_External_Entity
;
15331 -------------------------
15332 -- New_Internal_Entity --
15333 -------------------------
15335 function New_Internal_Entity
15336 (Kind
: Entity_Kind
;
15337 Scope_Id
: Entity_Id
;
15338 Sloc_Value
: Source_Ptr
;
15339 Id_Char
: Character) return Entity_Id
15341 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
15344 Set_Ekind
(N
, Kind
);
15345 Set_Is_Internal
(N
, True);
15346 Append_Entity
(N
, Scope_Id
);
15348 if Kind
in Type_Kind
then
15349 Init_Size_Align
(N
);
15353 end New_Internal_Entity
;
15359 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
15363 -- If we are pointing at a positional parameter, it is a member of a
15364 -- node list (the list of parameters), and the next parameter is the
15365 -- next node on the list, unless we hit a parameter association, then
15366 -- we shift to using the chain whose head is the First_Named_Actual in
15367 -- the parent, and then is threaded using the Next_Named_Actual of the
15368 -- Parameter_Association. All this fiddling is because the original node
15369 -- list is in the textual call order, and what we need is the
15370 -- declaration order.
15372 if Is_List_Member
(Actual_Id
) then
15373 N
:= Next
(Actual_Id
);
15375 if Nkind
(N
) = N_Parameter_Association
then
15376 return First_Named_Actual
(Parent
(Actual_Id
));
15382 return Next_Named_Actual
(Parent
(Actual_Id
));
15386 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
15388 Actual_Id
:= Next_Actual
(Actual_Id
);
15391 -----------------------
15392 -- Normalize_Actuals --
15393 -----------------------
15395 -- Chain actuals according to formals of subprogram. If there are no named
15396 -- associations, the chain is simply the list of Parameter Associations,
15397 -- since the order is the same as the declaration order. If there are named
15398 -- associations, then the First_Named_Actual field in the N_Function_Call
15399 -- or N_Procedure_Call_Statement node points to the Parameter_Association
15400 -- node for the parameter that comes first in declaration order. The
15401 -- remaining named parameters are then chained in declaration order using
15402 -- Next_Named_Actual.
15404 -- This routine also verifies that the number of actuals is compatible with
15405 -- the number and default values of formals, but performs no type checking
15406 -- (type checking is done by the caller).
15408 -- If the matching succeeds, Success is set to True and the caller proceeds
15409 -- with type-checking. If the match is unsuccessful, then Success is set to
15410 -- False, and the caller attempts a different interpretation, if there is
15413 -- If the flag Report is on, the call is not overloaded, and a failure to
15414 -- match can be reported here, rather than in the caller.
15416 procedure Normalize_Actuals
15420 Success
: out Boolean)
15422 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
15423 Actual
: Node_Id
:= Empty
;
15424 Formal
: Entity_Id
;
15425 Last
: Node_Id
:= Empty
;
15426 First_Named
: Node_Id
:= Empty
;
15429 Formals_To_Match
: Integer := 0;
15430 Actuals_To_Match
: Integer := 0;
15432 procedure Chain
(A
: Node_Id
);
15433 -- Add named actual at the proper place in the list, using the
15434 -- Next_Named_Actual link.
15436 function Reporting
return Boolean;
15437 -- Determines if an error is to be reported. To report an error, we
15438 -- need Report to be True, and also we do not report errors caused
15439 -- by calls to init procs that occur within other init procs. Such
15440 -- errors must always be cascaded errors, since if all the types are
15441 -- declared correctly, the compiler will certainly build decent calls.
15447 procedure Chain
(A
: Node_Id
) is
15451 -- Call node points to first actual in list
15453 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
15456 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
15460 Set_Next_Named_Actual
(Last
, Empty
);
15467 function Reporting
return Boolean is
15472 elsif not Within_Init_Proc
then
15475 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
15483 -- Start of processing for Normalize_Actuals
15486 if Is_Access_Type
(S
) then
15488 -- The name in the call is a function call that returns an access
15489 -- to subprogram. The designated type has the list of formals.
15491 Formal
:= First_Formal
(Designated_Type
(S
));
15493 Formal
:= First_Formal
(S
);
15496 while Present
(Formal
) loop
15497 Formals_To_Match
:= Formals_To_Match
+ 1;
15498 Next_Formal
(Formal
);
15501 -- Find if there is a named association, and verify that no positional
15502 -- associations appear after named ones.
15504 if Present
(Actuals
) then
15505 Actual
:= First
(Actuals
);
15508 while Present
(Actual
)
15509 and then Nkind
(Actual
) /= N_Parameter_Association
15511 Actuals_To_Match
:= Actuals_To_Match
+ 1;
15515 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
15517 -- Most common case: positional notation, no defaults
15522 elsif Actuals_To_Match
> Formals_To_Match
then
15524 -- Too many actuals: will not work
15527 if Is_Entity_Name
(Name
(N
)) then
15528 Error_Msg_N
("too many arguments in call to&", Name
(N
));
15530 Error_Msg_N
("too many arguments in call", N
);
15538 First_Named
:= Actual
;
15540 while Present
(Actual
) loop
15541 if Nkind
(Actual
) /= N_Parameter_Association
then
15543 ("positional parameters not allowed after named ones", Actual
);
15548 Actuals_To_Match
:= Actuals_To_Match
+ 1;
15554 if Present
(Actuals
) then
15555 Actual
:= First
(Actuals
);
15558 Formal
:= First_Formal
(S
);
15559 while Present
(Formal
) loop
15561 -- Match the formals in order. If the corresponding actual is
15562 -- positional, nothing to do. Else scan the list of named actuals
15563 -- to find the one with the right name.
15565 if Present
(Actual
)
15566 and then Nkind
(Actual
) /= N_Parameter_Association
15569 Actuals_To_Match
:= Actuals_To_Match
- 1;
15570 Formals_To_Match
:= Formals_To_Match
- 1;
15573 -- For named parameters, search the list of actuals to find
15574 -- one that matches the next formal name.
15576 Actual
:= First_Named
;
15578 while Present
(Actual
) loop
15579 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
15582 Actuals_To_Match
:= Actuals_To_Match
- 1;
15583 Formals_To_Match
:= Formals_To_Match
- 1;
15591 if Ekind
(Formal
) /= E_In_Parameter
15592 or else No
(Default_Value
(Formal
))
15595 if (Comes_From_Source
(S
)
15596 or else Sloc
(S
) = Standard_Location
)
15597 and then Is_Overloadable
(S
)
15601 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
15603 N_Parameter_Association
)
15604 and then Ekind
(S
) /= E_Function
15606 Set_Etype
(N
, Etype
(S
));
15609 Error_Msg_Name_1
:= Chars
(S
);
15610 Error_Msg_Sloc
:= Sloc
(S
);
15612 ("missing argument for parameter & "
15613 & "in call to % declared #", N
, Formal
);
15616 elsif Is_Overloadable
(S
) then
15617 Error_Msg_Name_1
:= Chars
(S
);
15619 -- Point to type derivation that generated the
15622 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
15625 ("missing argument for parameter & "
15626 & "in call to % (inherited) #", N
, Formal
);
15630 ("missing argument for parameter &", N
, Formal
);
15638 Formals_To_Match
:= Formals_To_Match
- 1;
15643 Next_Formal
(Formal
);
15646 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
15653 -- Find some superfluous named actual that did not get
15654 -- attached to the list of associations.
15656 Actual
:= First
(Actuals
);
15657 while Present
(Actual
) loop
15658 if Nkind
(Actual
) = N_Parameter_Association
15659 and then Actual
/= Last
15660 and then No
(Next_Named_Actual
(Actual
))
15662 Error_Msg_N
("unmatched actual & in call",
15663 Selector_Name
(Actual
));
15674 end Normalize_Actuals
;
15676 --------------------------------
15677 -- Note_Possible_Modification --
15678 --------------------------------
15680 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
15681 Modification_Comes_From_Source
: constant Boolean :=
15682 Comes_From_Source
(Parent
(N
));
15688 -- Loop to find referenced entity, if there is one
15694 if Is_Entity_Name
(Exp
) then
15695 Ent
:= Entity
(Exp
);
15697 -- If the entity is missing, it is an undeclared identifier,
15698 -- and there is nothing to annotate.
15704 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
15706 P
: constant Node_Id
:= Prefix
(Exp
);
15709 -- In formal verification mode, keep track of all reads and
15710 -- writes through explicit dereferences.
15712 if GNATprove_Mode
then
15713 SPARK_Specific
.Generate_Dereference
(N
, 'm');
15716 if Nkind
(P
) = N_Selected_Component
15717 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
15719 -- Case of a reference to an entry formal
15721 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
15723 elsif Nkind
(P
) = N_Identifier
15724 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
15725 and then Present
(Expression
(Parent
(Entity
(P
))))
15726 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
15729 -- Case of a reference to a value on which side effects have
15732 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
15740 elsif Nkind_In
(Exp
, N_Type_Conversion
,
15741 N_Unchecked_Type_Conversion
)
15743 Exp
:= Expression
(Exp
);
15746 elsif Nkind_In
(Exp
, N_Slice
,
15747 N_Indexed_Component
,
15748 N_Selected_Component
)
15750 -- Special check, if the prefix is an access type, then return
15751 -- since we are modifying the thing pointed to, not the prefix.
15752 -- When we are expanding, most usually the prefix is replaced
15753 -- by an explicit dereference, and this test is not needed, but
15754 -- in some cases (notably -gnatc mode and generics) when we do
15755 -- not do full expansion, we need this special test.
15757 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
15760 -- Otherwise go to prefix and keep going
15763 Exp
:= Prefix
(Exp
);
15767 -- All other cases, not a modification
15773 -- Now look for entity being referenced
15775 if Present
(Ent
) then
15776 if Is_Object
(Ent
) then
15777 if Comes_From_Source
(Exp
)
15778 or else Modification_Comes_From_Source
15780 -- Give warning if pragma unmodified given and we are
15781 -- sure this is a modification.
15783 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
15784 Error_Msg_NE
("??pragma Unmodified given for &!", N
, Ent
);
15787 Set_Never_Set_In_Source
(Ent
, False);
15790 Set_Is_True_Constant
(Ent
, False);
15791 Set_Current_Value
(Ent
, Empty
);
15792 Set_Is_Known_Null
(Ent
, False);
15794 if not Can_Never_Be_Null
(Ent
) then
15795 Set_Is_Known_Non_Null
(Ent
, False);
15798 -- Follow renaming chain
15800 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
15801 and then Present
(Renamed_Object
(Ent
))
15803 Exp
:= Renamed_Object
(Ent
);
15805 -- If the entity is the loop variable in an iteration over
15806 -- a container, retrieve container expression to indicate
15807 -- possible modification.
15809 if Present
(Related_Expression
(Ent
))
15810 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
15811 N_Iterator_Specification
15813 Exp
:= Original_Node
(Related_Expression
(Ent
));
15818 -- The expression may be the renaming of a subcomponent of an
15819 -- array or container. The assignment to the subcomponent is
15820 -- a modification of the container.
15822 elsif Comes_From_Source
(Original_Node
(Exp
))
15823 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
15824 N_Indexed_Component
)
15826 Exp
:= Prefix
(Original_Node
(Exp
));
15830 -- Generate a reference only if the assignment comes from
15831 -- source. This excludes, for example, calls to a dispatching
15832 -- assignment operation when the left-hand side is tagged. In
15833 -- GNATprove mode, we need those references also on generated
15834 -- code, as these are used to compute the local effects of
15837 if Modification_Comes_From_Source
or GNATprove_Mode
then
15838 Generate_Reference
(Ent
, Exp
, 'm');
15840 -- If the target of the assignment is the bound variable
15841 -- in an iterator, indicate that the corresponding array
15842 -- or container is also modified.
15844 if Ada_Version
>= Ada_2012
15845 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
15848 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
15851 -- TBD : in the full version of the construct, the
15852 -- domain of iteration can be given by an expression.
15854 if Is_Entity_Name
(Domain
) then
15855 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
15856 Set_Is_True_Constant
(Entity
(Domain
), False);
15857 Set_Never_Set_In_Source
(Entity
(Domain
), False);
15863 Check_Nested_Access
(Ent
);
15868 -- If we are sure this is a modification from source, and we know
15869 -- this modifies a constant, then give an appropriate warning.
15871 if Overlays_Constant
(Ent
)
15872 and then (Modification_Comes_From_Source
and Sure
)
15875 A
: constant Node_Id
:= Address_Clause
(Ent
);
15877 if Present
(A
) then
15879 Exp
: constant Node_Id
:= Expression
(A
);
15881 if Nkind
(Exp
) = N_Attribute_Reference
15882 and then Attribute_Name
(Exp
) = Name_Address
15883 and then Is_Entity_Name
(Prefix
(Exp
))
15885 Error_Msg_Sloc
:= Sloc
(A
);
15887 ("constant& may be modified via address "
15888 & "clause#??", N
, Entity
(Prefix
(Exp
)));
15901 end Note_Possible_Modification
;
15903 -------------------------
15904 -- Object_Access_Level --
15905 -------------------------
15907 -- Returns the static accessibility level of the view denoted by Obj. Note
15908 -- that the value returned is the result of a call to Scope_Depth. Only
15909 -- scope depths associated with dynamic scopes can actually be returned.
15910 -- Since only relative levels matter for accessibility checking, the fact
15911 -- that the distance between successive levels of accessibility is not
15912 -- always one is immaterial (invariant: if level(E2) is deeper than
15913 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
15915 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
15916 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
15917 -- Determine whether N is a construct of the form
15918 -- Some_Type (Operand._tag'Address)
15919 -- This construct appears in the context of dispatching calls.
15921 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
15922 -- An explicit dereference is created when removing side-effects from
15923 -- expressions for constraint checking purposes. In this case a local
15924 -- access type is created for it. The correct access level is that of
15925 -- the original source node. We detect this case by noting that the
15926 -- prefix of the dereference is created by an object declaration whose
15927 -- initial expression is a reference.
15929 -----------------------------
15930 -- Is_Interface_Conversion --
15931 -----------------------------
15933 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
15935 return Nkind
(N
) = N_Unchecked_Type_Conversion
15936 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
15937 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
15938 end Is_Interface_Conversion
;
15944 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
15945 Pref
: constant Node_Id
:= Prefix
(Obj
);
15947 if Is_Entity_Name
(Pref
)
15948 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
15949 and then Present
(Expression
(Parent
(Entity
(Pref
))))
15950 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
15952 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
15962 -- Start of processing for Object_Access_Level
15965 if Nkind
(Obj
) = N_Defining_Identifier
15966 or else Is_Entity_Name
(Obj
)
15968 if Nkind
(Obj
) = N_Defining_Identifier
then
15974 if Is_Prival
(E
) then
15975 E
:= Prival_Link
(E
);
15978 -- If E is a type then it denotes a current instance. For this case
15979 -- we add one to the normal accessibility level of the type to ensure
15980 -- that current instances are treated as always being deeper than
15981 -- than the level of any visible named access type (see 3.10.2(21)).
15983 if Is_Type
(E
) then
15984 return Type_Access_Level
(E
) + 1;
15986 elsif Present
(Renamed_Object
(E
)) then
15987 return Object_Access_Level
(Renamed_Object
(E
));
15989 -- Similarly, if E is a component of the current instance of a
15990 -- protected type, any instance of it is assumed to be at a deeper
15991 -- level than the type. For a protected object (whose type is an
15992 -- anonymous protected type) its components are at the same level
15993 -- as the type itself.
15995 elsif not Is_Overloadable
(E
)
15996 and then Ekind
(Scope
(E
)) = E_Protected_Type
15997 and then Comes_From_Source
(Scope
(E
))
15999 return Type_Access_Level
(Scope
(E
)) + 1;
16002 -- Aliased formals take their access level from the point of call.
16003 -- This is smaller than the level of the subprogram itself.
16005 if Is_Formal
(E
) and then Is_Aliased
(E
) then
16006 return Type_Access_Level
(Etype
(E
));
16009 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
16013 elsif Nkind
(Obj
) = N_Selected_Component
then
16014 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
16015 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
16017 return Object_Access_Level
(Prefix
(Obj
));
16020 elsif Nkind
(Obj
) = N_Indexed_Component
then
16021 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
16022 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
16024 return Object_Access_Level
(Prefix
(Obj
));
16027 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
16029 -- If the prefix is a selected access discriminant then we make a
16030 -- recursive call on the prefix, which will in turn check the level
16031 -- of the prefix object of the selected discriminant.
16033 -- In Ada 2012, if the discriminant has implicit dereference and
16034 -- the context is a selected component, treat this as an object of
16035 -- unknown scope (see below). This is necessary in compile-only mode;
16036 -- otherwise expansion will already have transformed the prefix into
16039 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
16040 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
16042 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
16044 (not Has_Implicit_Dereference
16045 (Entity
(Selector_Name
(Prefix
(Obj
))))
16046 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
16048 return Object_Access_Level
(Prefix
(Obj
));
16050 -- Detect an interface conversion in the context of a dispatching
16051 -- call. Use the original form of the conversion to find the access
16052 -- level of the operand.
16054 elsif Is_Interface
(Etype
(Obj
))
16055 and then Is_Interface_Conversion
(Prefix
(Obj
))
16056 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
16058 return Object_Access_Level
(Original_Node
(Obj
));
16060 elsif not Comes_From_Source
(Obj
) then
16062 Ref
: constant Node_Id
:= Reference_To
(Obj
);
16064 if Present
(Ref
) then
16065 return Object_Access_Level
(Ref
);
16067 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
16072 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
16075 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
16076 return Object_Access_Level
(Expression
(Obj
));
16078 elsif Nkind
(Obj
) = N_Function_Call
then
16080 -- Function results are objects, so we get either the access level of
16081 -- the function or, in the case of an indirect call, the level of the
16082 -- access-to-subprogram type. (This code is used for Ada 95, but it
16083 -- looks wrong, because it seems that we should be checking the level
16084 -- of the call itself, even for Ada 95. However, using the Ada 2005
16085 -- version of the code causes regressions in several tests that are
16086 -- compiled with -gnat95. ???)
16088 if Ada_Version
< Ada_2005
then
16089 if Is_Entity_Name
(Name
(Obj
)) then
16090 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
16092 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
16095 -- For Ada 2005, the level of the result object of a function call is
16096 -- defined to be the level of the call's innermost enclosing master.
16097 -- We determine that by querying the depth of the innermost enclosing
16101 Return_Master_Scope_Depth_Of_Call
: declare
16103 function Innermost_Master_Scope_Depth
16104 (N
: Node_Id
) return Uint
;
16105 -- Returns the scope depth of the given node's innermost
16106 -- enclosing dynamic scope (effectively the accessibility
16107 -- level of the innermost enclosing master).
16109 ----------------------------------
16110 -- Innermost_Master_Scope_Depth --
16111 ----------------------------------
16113 function Innermost_Master_Scope_Depth
16114 (N
: Node_Id
) return Uint
16116 Node_Par
: Node_Id
:= Parent
(N
);
16119 -- Locate the nearest enclosing node (by traversing Parents)
16120 -- that Defining_Entity can be applied to, and return the
16121 -- depth of that entity's nearest enclosing dynamic scope.
16123 while Present
(Node_Par
) loop
16124 case Nkind
(Node_Par
) is
16125 when N_Component_Declaration |
16126 N_Entry_Declaration |
16127 N_Formal_Object_Declaration |
16128 N_Formal_Type_Declaration |
16129 N_Full_Type_Declaration |
16130 N_Incomplete_Type_Declaration |
16131 N_Loop_Parameter_Specification |
16132 N_Object_Declaration |
16133 N_Protected_Type_Declaration |
16134 N_Private_Extension_Declaration |
16135 N_Private_Type_Declaration |
16136 N_Subtype_Declaration |
16137 N_Function_Specification |
16138 N_Procedure_Specification |
16139 N_Task_Type_Declaration |
16141 N_Generic_Instantiation |
16143 N_Implicit_Label_Declaration |
16144 N_Package_Declaration |
16145 N_Single_Task_Declaration |
16146 N_Subprogram_Declaration |
16147 N_Generic_Declaration |
16148 N_Renaming_Declaration |
16149 N_Block_Statement |
16150 N_Formal_Subprogram_Declaration |
16151 N_Abstract_Subprogram_Declaration |
16153 N_Exception_Declaration |
16154 N_Formal_Package_Declaration |
16155 N_Number_Declaration |
16156 N_Package_Specification |
16157 N_Parameter_Specification |
16158 N_Single_Protected_Declaration |
16162 (Nearest_Dynamic_Scope
16163 (Defining_Entity
(Node_Par
)));
16169 Node_Par
:= Parent
(Node_Par
);
16172 pragma Assert
(False);
16174 -- Should never reach the following return
16176 return Scope_Depth
(Current_Scope
) + 1;
16177 end Innermost_Master_Scope_Depth
;
16179 -- Start of processing for Return_Master_Scope_Depth_Of_Call
16182 return Innermost_Master_Scope_Depth
(Obj
);
16183 end Return_Master_Scope_Depth_Of_Call
;
16186 -- For convenience we handle qualified expressions, even though they
16187 -- aren't technically object names.
16189 elsif Nkind
(Obj
) = N_Qualified_Expression
then
16190 return Object_Access_Level
(Expression
(Obj
));
16192 -- Ditto for aggregates. They have the level of the temporary that
16193 -- will hold their value.
16195 elsif Nkind
(Obj
) = N_Aggregate
then
16196 return Object_Access_Level
(Current_Scope
);
16198 -- Otherwise return the scope level of Standard. (If there are cases
16199 -- that fall through to this point they will be treated as having
16200 -- global accessibility for now. ???)
16203 return Scope_Depth
(Standard_Standard
);
16205 end Object_Access_Level
;
16207 ---------------------------------
16208 -- Original_Aspect_Pragma_Name --
16209 ---------------------------------
16211 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
16213 Item_Nam
: Name_Id
;
16216 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
16220 -- The pragma was generated to emulate an aspect, use the original
16221 -- aspect specification.
16223 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
16224 Item
:= Corresponding_Aspect
(Item
);
16227 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
16228 -- Post and Post_Class rewrite their pragma identifier to preserve the
16230 -- ??? this is kludgey
16232 if Nkind
(Item
) = N_Pragma
then
16233 Item_Nam
:= Chars
(Original_Node
(Pragma_Identifier
(Item
)));
16236 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
16237 Item_Nam
:= Chars
(Identifier
(Item
));
16240 -- Deal with 'Class by converting the name to its _XXX form
16242 if Class_Present
(Item
) then
16243 if Item_Nam
= Name_Invariant
then
16244 Item_Nam
:= Name_uInvariant
;
16246 elsif Item_Nam
= Name_Post
then
16247 Item_Nam
:= Name_uPost
;
16249 elsif Item_Nam
= Name_Pre
then
16250 Item_Nam
:= Name_uPre
;
16252 elsif Nam_In
(Item_Nam
, Name_Type_Invariant
,
16253 Name_Type_Invariant_Class
)
16255 Item_Nam
:= Name_uType_Invariant
;
16257 -- Nothing to do for other cases (e.g. a Check that derived from
16258 -- Pre_Class and has the flag set). Also we do nothing if the name
16259 -- is already in special _xxx form.
16265 end Original_Aspect_Pragma_Name
;
16267 --------------------------------------
16268 -- Original_Corresponding_Operation --
16269 --------------------------------------
16271 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
16273 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
16276 -- If S is an inherited primitive S2 the original corresponding
16277 -- operation of S is the original corresponding operation of S2
16279 if Present
(Alias
(S
))
16280 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
16282 return Original_Corresponding_Operation
(Alias
(S
));
16284 -- If S overrides an inherited subprogram S2 the original corresponding
16285 -- operation of S is the original corresponding operation of S2
16287 elsif Present
(Overridden_Operation
(S
)) then
16288 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
16290 -- otherwise it is S itself
16295 end Original_Corresponding_Operation
;
16297 ----------------------
16298 -- Policy_In_Effect --
16299 ----------------------
16301 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
16302 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
16303 -- Determine the mode of a policy in a N_Pragma list
16305 --------------------
16306 -- Policy_In_List --
16307 --------------------
16309 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
16316 while Present
(Prag
) loop
16317 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
16318 Arg2
:= Next
(Arg1
);
16320 Arg1
:= Get_Pragma_Arg
(Arg1
);
16321 Arg2
:= Get_Pragma_Arg
(Arg2
);
16323 -- The current Check_Policy pragma matches the requested policy or
16324 -- appears in the single argument form (Assertion, policy_id).
16326 if Nam_In
(Chars
(Arg1
), Name_Assertion
, Policy
) then
16327 return Chars
(Arg2
);
16330 Prag
:= Next_Pragma
(Prag
);
16334 end Policy_In_List
;
16340 -- Start of processing for Policy_In_Effect
16343 if not Is_Valid_Assertion_Kind
(Policy
) then
16344 raise Program_Error
;
16347 -- Inspect all policy pragmas that appear within scopes (if any)
16349 Kind
:= Policy_In_List
(Check_Policy_List
);
16351 -- Inspect all configuration policy pragmas (if any)
16353 if Kind
= No_Name
then
16354 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
16357 -- The context lacks policy pragmas, determine the mode based on whether
16358 -- assertions are enabled at the configuration level. This ensures that
16359 -- the policy is preserved when analyzing generics.
16361 if Kind
= No_Name
then
16362 if Assertions_Enabled_Config
then
16363 Kind
:= Name_Check
;
16365 Kind
:= Name_Ignore
;
16370 end Policy_In_Effect
;
16372 ----------------------------------
16373 -- Predicate_Tests_On_Arguments --
16374 ----------------------------------
16376 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
16378 -- Always test predicates on indirect call
16380 if Ekind
(Subp
) = E_Subprogram_Type
then
16383 -- Do not test predicates on call to generated default Finalize, since
16384 -- we are not interested in whether something we are finalizing (and
16385 -- typically destroying) satisfies its predicates.
16387 elsif Chars
(Subp
) = Name_Finalize
16388 and then not Comes_From_Source
(Subp
)
16392 -- Do not test predicates on any internally generated routines
16394 elsif Is_Internal_Name
(Chars
(Subp
)) then
16397 -- Do not test predicates on call to Init_Proc, since if needed the
16398 -- predicate test will occur at some other point.
16400 elsif Is_Init_Proc
(Subp
) then
16403 -- Do not test predicates on call to predicate function, since this
16404 -- would cause infinite recursion.
16406 elsif Ekind
(Subp
) = E_Function
16407 and then (Is_Predicate_Function
(Subp
)
16409 Is_Predicate_Function_M
(Subp
))
16413 -- For now, no other exceptions
16418 end Predicate_Tests_On_Arguments
;
16420 -----------------------
16421 -- Private_Component --
16422 -----------------------
16424 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
16425 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
16427 function Trace_Components
16429 Check
: Boolean) return Entity_Id
;
16430 -- Recursive function that does the work, and checks against circular
16431 -- definition for each subcomponent type.
16433 ----------------------
16434 -- Trace_Components --
16435 ----------------------
16437 function Trace_Components
16439 Check
: Boolean) return Entity_Id
16441 Btype
: constant Entity_Id
:= Base_Type
(T
);
16442 Component
: Entity_Id
;
16444 Candidate
: Entity_Id
:= Empty
;
16447 if Check
and then Btype
= Ancestor
then
16448 Error_Msg_N
("circular type definition", Type_Id
);
16452 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
16453 if Present
(Full_View
(Btype
))
16454 and then Is_Record_Type
(Full_View
(Btype
))
16455 and then not Is_Frozen
(Btype
)
16457 -- To indicate that the ancestor depends on a private type, the
16458 -- current Btype is sufficient. However, to check for circular
16459 -- definition we must recurse on the full view.
16461 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
16463 if Candidate
= Any_Type
then
16473 elsif Is_Array_Type
(Btype
) then
16474 return Trace_Components
(Component_Type
(Btype
), True);
16476 elsif Is_Record_Type
(Btype
) then
16477 Component
:= First_Entity
(Btype
);
16478 while Present
(Component
)
16479 and then Comes_From_Source
(Component
)
16481 -- Skip anonymous types generated by constrained components
16483 if not Is_Type
(Component
) then
16484 P
:= Trace_Components
(Etype
(Component
), True);
16486 if Present
(P
) then
16487 if P
= Any_Type
then
16495 Next_Entity
(Component
);
16503 end Trace_Components
;
16505 -- Start of processing for Private_Component
16508 return Trace_Components
(Type_Id
, False);
16509 end Private_Component
;
16511 ---------------------------
16512 -- Primitive_Names_Match --
16513 ---------------------------
16515 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
16517 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
16518 -- Given an internal name, returns the corresponding non-internal name
16520 ------------------------
16521 -- Non_Internal_Name --
16522 ------------------------
16524 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
16526 Get_Name_String
(Chars
(E
));
16527 Name_Len
:= Name_Len
- 1;
16529 end Non_Internal_Name
;
16531 -- Start of processing for Primitive_Names_Match
16534 pragma Assert
(Present
(E1
) and then Present
(E2
));
16536 return Chars
(E1
) = Chars
(E2
)
16538 (not Is_Internal_Name
(Chars
(E1
))
16539 and then Is_Internal_Name
(Chars
(E2
))
16540 and then Non_Internal_Name
(E2
) = Chars
(E1
))
16542 (not Is_Internal_Name
(Chars
(E2
))
16543 and then Is_Internal_Name
(Chars
(E1
))
16544 and then Non_Internal_Name
(E1
) = Chars
(E2
))
16546 (Is_Predefined_Dispatching_Operation
(E1
)
16547 and then Is_Predefined_Dispatching_Operation
(E2
)
16548 and then Same_TSS
(E1
, E2
))
16550 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
16551 end Primitive_Names_Match
;
16553 -----------------------
16554 -- Process_End_Label --
16555 -----------------------
16557 procedure Process_End_Label
16566 Label_Ref
: Boolean;
16567 -- Set True if reference to end label itself is required
16570 -- Gets set to the operator symbol or identifier that references the
16571 -- entity Ent. For the child unit case, this is the identifier from the
16572 -- designator. For other cases, this is simply Endl.
16574 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
16575 -- N is an identifier node that appears as a parent unit reference in
16576 -- the case where Ent is a child unit. This procedure generates an
16577 -- appropriate cross-reference entry. E is the corresponding entity.
16579 -------------------------
16580 -- Generate_Parent_Ref --
16581 -------------------------
16583 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
16585 -- If names do not match, something weird, skip reference
16587 if Chars
(E
) = Chars
(N
) then
16589 -- Generate the reference. We do NOT consider this as a reference
16590 -- for unreferenced symbol purposes.
16592 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
16594 if Style_Check
then
16595 Style
.Check_Identifier
(N
, E
);
16598 end Generate_Parent_Ref
;
16600 -- Start of processing for Process_End_Label
16603 -- If no node, ignore. This happens in some error situations, and
16604 -- also for some internally generated structures where no end label
16605 -- references are required in any case.
16611 -- Nothing to do if no End_Label, happens for internally generated
16612 -- constructs where we don't want an end label reference anyway. Also
16613 -- nothing to do if Endl is a string literal, which means there was
16614 -- some prior error (bad operator symbol)
16616 Endl
:= End_Label
(N
);
16618 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
16622 -- Reference node is not in extended main source unit
16624 if not In_Extended_Main_Source_Unit
(N
) then
16626 -- Generally we do not collect references except for the extended
16627 -- main source unit. The one exception is the 'e' entry for a
16628 -- package spec, where it is useful for a client to have the
16629 -- ending information to define scopes.
16635 Label_Ref
:= False;
16637 -- For this case, we can ignore any parent references, but we
16638 -- need the package name itself for the 'e' entry.
16640 if Nkind
(Endl
) = N_Designator
then
16641 Endl
:= Identifier
(Endl
);
16645 -- Reference is in extended main source unit
16650 -- For designator, generate references for the parent entries
16652 if Nkind
(Endl
) = N_Designator
then
16654 -- Generate references for the prefix if the END line comes from
16655 -- source (otherwise we do not need these references) We climb the
16656 -- scope stack to find the expected entities.
16658 if Comes_From_Source
(Endl
) then
16659 Nam
:= Name
(Endl
);
16660 Scop
:= Current_Scope
;
16661 while Nkind
(Nam
) = N_Selected_Component
loop
16662 Scop
:= Scope
(Scop
);
16663 exit when No
(Scop
);
16664 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
16665 Nam
:= Prefix
(Nam
);
16668 if Present
(Scop
) then
16669 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
16673 Endl
:= Identifier
(Endl
);
16677 -- If the end label is not for the given entity, then either we have
16678 -- some previous error, or this is a generic instantiation for which
16679 -- we do not need to make a cross-reference in this case anyway. In
16680 -- either case we simply ignore the call.
16682 if Chars
(Ent
) /= Chars
(Endl
) then
16686 -- If label was really there, then generate a normal reference and then
16687 -- adjust the location in the end label to point past the name (which
16688 -- should almost always be the semicolon).
16690 Loc
:= Sloc
(Endl
);
16692 if Comes_From_Source
(Endl
) then
16694 -- If a label reference is required, then do the style check and
16695 -- generate an l-type cross-reference entry for the label
16698 if Style_Check
then
16699 Style
.Check_Identifier
(Endl
, Ent
);
16702 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
16705 -- Set the location to point past the label (normally this will
16706 -- mean the semicolon immediately following the label). This is
16707 -- done for the sake of the 'e' or 't' entry generated below.
16709 Get_Decoded_Name_String
(Chars
(Endl
));
16710 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
16713 -- In SPARK mode, no missing label is allowed for packages and
16714 -- subprogram bodies. Detect those cases by testing whether
16715 -- Process_End_Label was called for a body (Typ = 't') or a package.
16717 if Restriction_Check_Required
(SPARK_05
)
16718 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
16720 Error_Msg_Node_1
:= Endl
;
16721 Check_SPARK_05_Restriction
16722 ("`END &` required", Endl
, Force
=> True);
16726 -- Now generate the e/t reference
16728 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
16730 -- Restore Sloc, in case modified above, since we have an identifier
16731 -- and the normal Sloc should be left set in the tree.
16733 Set_Sloc
(Endl
, Loc
);
16734 end Process_End_Label
;
16740 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
16741 Seen
: Boolean := False;
16743 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
16744 -- Determine whether node N denotes a reference to Id. If this is the
16745 -- case, set global flag Seen to True and stop the traversal.
16751 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
16753 if Is_Entity_Name
(N
)
16754 and then Present
(Entity
(N
))
16755 and then Entity
(N
) = Id
16764 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
16766 -- Start of processing for Referenced
16769 Inspect_Expression
(Expr
);
16773 ------------------------------------
16774 -- References_Generic_Formal_Type --
16775 ------------------------------------
16777 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
16779 function Process
(N
: Node_Id
) return Traverse_Result
;
16780 -- Process one node in search for generic formal type
16786 function Process
(N
: Node_Id
) return Traverse_Result
is
16788 if Nkind
(N
) in N_Has_Entity
then
16790 E
: constant Entity_Id
:= Entity
(N
);
16792 if Present
(E
) then
16793 if Is_Generic_Type
(E
) then
16795 elsif Present
(Etype
(E
))
16796 and then Is_Generic_Type
(Etype
(E
))
16807 function Traverse
is new Traverse_Func
(Process
);
16808 -- Traverse tree to look for generic type
16811 if Inside_A_Generic
then
16812 return Traverse
(N
) = Abandon
;
16816 end References_Generic_Formal_Type
;
16818 --------------------
16819 -- Remove_Homonym --
16820 --------------------
16822 procedure Remove_Homonym
(E
: Entity_Id
) is
16823 Prev
: Entity_Id
:= Empty
;
16827 if E
= Current_Entity
(E
) then
16828 if Present
(Homonym
(E
)) then
16829 Set_Current_Entity
(Homonym
(E
));
16831 Set_Name_Entity_Id
(Chars
(E
), Empty
);
16835 H
:= Current_Entity
(E
);
16836 while Present
(H
) and then H
/= E
loop
16841 -- If E is not on the homonym chain, nothing to do
16843 if Present
(H
) then
16844 Set_Homonym
(Prev
, Homonym
(E
));
16847 end Remove_Homonym
;
16849 ---------------------
16850 -- Rep_To_Pos_Flag --
16851 ---------------------
16853 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
16855 return New_Occurrence_Of
16856 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
16857 end Rep_To_Pos_Flag
;
16859 --------------------
16860 -- Require_Entity --
16861 --------------------
16863 procedure Require_Entity
(N
: Node_Id
) is
16865 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
16866 if Total_Errors_Detected
/= 0 then
16867 Set_Entity
(N
, Any_Id
);
16869 raise Program_Error
;
16872 end Require_Entity
;
16874 -------------------------------
16875 -- Requires_State_Refinement --
16876 -------------------------------
16878 function Requires_State_Refinement
16879 (Spec_Id
: Entity_Id
;
16880 Body_Id
: Entity_Id
) return Boolean
16882 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean;
16883 -- Given pragma SPARK_Mode, determine whether the mode is Off
16889 function Mode_Is_Off
(Prag
: Node_Id
) return Boolean is
16893 -- The default SPARK mode is On
16899 Mode
:= Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
16901 -- Then the pragma lacks an argument, the default mode is On
16906 return Chars
(Mode
) = Name_Off
;
16910 -- Start of processing for Requires_State_Refinement
16913 -- A package that does not define at least one abstract state cannot
16914 -- possibly require refinement.
16916 if No
(Abstract_States
(Spec_Id
)) then
16919 -- The package instroduces a single null state which does not merit
16922 elsif Has_Null_Abstract_State
(Spec_Id
) then
16925 -- Check whether the package body is subject to pragma SPARK_Mode. If
16926 -- it is and the mode is Off, the package body is considered to be in
16927 -- regular Ada and does not require refinement.
16929 elsif Mode_Is_Off
(SPARK_Pragma
(Body_Id
)) then
16932 -- The body's SPARK_Mode may be inherited from a similar pragma that
16933 -- appears in the private declarations of the spec. The pragma we are
16934 -- interested appears as the second entry in SPARK_Pragma.
16936 elsif Present
(SPARK_Pragma
(Spec_Id
))
16937 and then Mode_Is_Off
(Next_Pragma
(SPARK_Pragma
(Spec_Id
)))
16941 -- The spec defines at least one abstract state and the body has no way
16942 -- of circumventing the refinement.
16947 end Requires_State_Refinement
;
16949 ------------------------------
16950 -- Requires_Transient_Scope --
16951 ------------------------------
16953 -- A transient scope is required when variable-sized temporaries are
16954 -- allocated on the secondary stack, or when finalization actions must be
16955 -- generated before the next instruction.
16957 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
16958 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
16959 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
16960 -- the time being. New_Requires_Transient_Scope is used by default; the
16961 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
16962 -- instead. The intent is to use this temporarily to measure before/after
16963 -- efficiency. Note: when this temporary code is removed, the documentation
16964 -- of dQ in debug.adb should be removed.
16966 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
16967 Old_Result
: constant Boolean := Old_Requires_Transient_Scope
(Id
);
16970 if Debug_Flag_QQ
then
16975 New_Result
: constant Boolean := New_Requires_Transient_Scope
(Id
);
16978 -- Assert that we're not putting things on the secondary stack if we
16979 -- didn't before; we are trying to AVOID secondary stack when
16982 if not Old_Result
then
16983 pragma Assert
(not New_Result
);
16989 end Requires_Transient_Scope
;
16991 ----------------------------------
16992 -- Old_Requires_Transient_Scope --
16993 ----------------------------------
16995 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
16996 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
16999 -- This is a private type which is not completed yet. This can only
17000 -- happen in a default expression (of a formal parameter or of a
17001 -- record component). Do not expand transient scope in this case
17006 -- Do not expand transient scope for non-existent procedure return
17008 elsif Typ
= Standard_Void_Type
then
17011 -- Elementary types do not require a transient scope
17013 elsif Is_Elementary_Type
(Typ
) then
17016 -- Generally, indefinite subtypes require a transient scope, since the
17017 -- back end cannot generate temporaries, since this is not a valid type
17018 -- for declaring an object. It might be possible to relax this in the
17019 -- future, e.g. by declaring the maximum possible space for the type.
17021 elsif not Is_Definite_Subtype
(Typ
) then
17024 -- Functions returning tagged types may dispatch on result so their
17025 -- returned value is allocated on the secondary stack. Controlled
17026 -- type temporaries need finalization.
17028 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
17029 return not Is_Value_Type
(Typ
);
17033 elsif Is_Record_Type
(Typ
) then
17038 Comp
:= First_Entity
(Typ
);
17039 while Present
(Comp
) loop
17040 if Ekind
(Comp
) = E_Component
then
17042 -- ???It's not clear we need a full recursive call to
17043 -- Old_Requires_Transient_Scope here. Note that the
17044 -- following can't happen.
17046 pragma Assert
(Is_Definite_Subtype
(Etype
(Comp
)));
17047 pragma Assert
(not Has_Controlled_Component
(Etype
(Comp
)));
17049 if Old_Requires_Transient_Scope
(Etype
(Comp
)) then
17054 Next_Entity
(Comp
);
17060 -- String literal types never require transient scope
17062 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
17065 -- Array type. Note that we already know that this is a constrained
17066 -- array, since unconstrained arrays will fail the indefinite test.
17068 elsif Is_Array_Type
(Typ
) then
17070 -- If component type requires a transient scope, the array does too
17072 if Old_Requires_Transient_Scope
(Component_Type
(Typ
)) then
17075 -- Otherwise, we only need a transient scope if the size depends on
17076 -- the value of one or more discriminants.
17079 return Size_Depends_On_Discriminant
(Typ
);
17082 -- All other cases do not require a transient scope
17085 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
17088 end Old_Requires_Transient_Scope
;
17090 ----------------------------------
17091 -- New_Requires_Transient_Scope --
17092 ----------------------------------
17094 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
17096 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean;
17097 -- This is called for untagged records and protected types, with
17098 -- nondefaulted discriminants. Returns True if the size of function
17099 -- results is known at the call site, False otherwise. Returns False
17100 -- if there is a variant part that depends on the discriminants of
17101 -- this type, or if there is an array constrained by the discriminants
17102 -- of this type. ???Currently, this is overly conservative (the array
17103 -- could be nested inside some other record that is constrained by
17104 -- nondiscriminants). That is, the recursive calls are too conservative.
17106 function Has_Discrim_Dep_Array
(Typ
: Entity_Id
) return Boolean;
17107 -- True if we find certain discriminant-dependent array
17108 -- subcomponents. This shouldn't be necessary, but without this check,
17109 -- we crash in gimplify. ???
17111 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean is
17112 pragma Assert
(Typ
= Underlying_Type
(Typ
));
17115 if Has_Variant_Part
(Typ
) and then not Is_Definite_Subtype
(Typ
) then
17120 Comp
: Entity_Id
:= First_Entity
(Typ
);
17123 while Present
(Comp
) loop
17125 -- Only look at E_Component entities. No need to look at
17126 -- E_Discriminant entities, and we must ignore internal
17127 -- subtypes generated for constrained components.
17129 if Ekind
(Comp
) = E_Component
then
17131 Comp_Type
: constant Entity_Id
:=
17132 Underlying_Type
(Etype
(Comp
));
17135 if Is_Record_Type
(Comp_Type
)
17137 Is_Protected_Type
(Comp_Type
)
17139 if not Caller_Known_Size_Record
(Comp_Type
) then
17143 elsif Is_Array_Type
(Comp_Type
) then
17144 if Size_Depends_On_Discriminant
(Comp_Type
) then
17151 Next_Entity
(Comp
);
17156 end Caller_Known_Size_Record
;
17158 function Has_Discrim_Dep_Array
(Typ
: Entity_Id
) return Boolean is
17159 pragma Assert
(Typ
= Underlying_Type
(Typ
));
17162 if Is_Array_Type
(Typ
) then
17163 return Size_Depends_On_Discriminant
(Typ
);
17166 if Is_Record_Type
(Typ
)
17168 Is_Protected_Type
(Typ
)
17171 Comp
: Entity_Id
:= First_Entity
(Typ
);
17174 while Present
(Comp
) loop
17176 -- Only look at E_Component entities. No need to look at
17177 -- E_Discriminant entities, and we must ignore internal
17178 -- subtypes generated for constrained components.
17180 if Ekind
(Comp
) = E_Component
then
17182 Comp_Type
: constant Entity_Id
:=
17183 Underlying_Type
(Etype
(Comp
));
17186 if Has_Discrim_Dep_Array
(Comp_Type
) then
17192 Next_Entity
(Comp
);
17198 end Has_Discrim_Dep_Array
;
17200 -- Local declarations
17202 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
17204 -- Start of processing for New_Requires_Transient_Scope
17207 -- This is a private type which is not completed yet. This can only
17208 -- happen in a default expression (of a formal parameter or of a
17209 -- record component). Do not expand transient scope in this case
17214 -- Do not expand transient scope for non-existent procedure return or
17215 -- string literal types.
17217 elsif Typ
= Standard_Void_Type
17218 or else Ekind
(Typ
) = E_String_Literal_Subtype
17222 -- Functions returning tagged types may dispatch on result so their
17223 -- returned value is allocated on the secondary stack, even in the
17224 -- definite case. Is_Tagged_Type includes controlled types and
17225 -- class-wide types. Controlled type temporaries need finalization.
17226 -- ???It's not clear why we need to return noncontrolled types with
17227 -- controlled components on the secondary stack. Also, it's not clear
17228 -- why nonprimitive tagged type functions need the secondary stack,
17229 -- since they can't be called via dispatching.
17231 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
17232 return not Is_Value_Type
(Typ
);
17234 -- Untagged definite subtypes are known size. This includes all
17235 -- elementary [sub]types. Tasks are known size even if they have
17238 elsif Is_Definite_Subtype
(Typ
) or else Is_Task_Type
(Typ
) then
17239 if Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
17240 if not Has_Discriminants
(Typ
) then
17241 if Has_Discrim_Dep_Array
(Typ
) then
17242 return True; -- ???Shouldn't be necessary
17249 -- Indefinite (discriminated) untagged record or protected type
17251 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
17252 return not Caller_Known_Size_Record
(Typ
);
17254 -- Unconstrained array
17257 pragma Assert
(Is_Array_Type
(Typ
) and not Is_Definite_Subtype
(Typ
));
17260 end New_Requires_Transient_Scope
;
17262 --------------------------
17263 -- Reset_Analyzed_Flags --
17264 --------------------------
17266 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
17268 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
17269 -- Function used to reset Analyzed flags in tree. Note that we do
17270 -- not reset Analyzed flags in entities, since there is no need to
17271 -- reanalyze entities, and indeed, it is wrong to do so, since it
17272 -- can result in generating auxiliary stuff more than once.
17274 --------------------
17275 -- Clear_Analyzed --
17276 --------------------
17278 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
17280 if not Has_Extension
(N
) then
17281 Set_Analyzed
(N
, False);
17285 end Clear_Analyzed
;
17287 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
17289 -- Start of processing for Reset_Analyzed_Flags
17292 Reset_Analyzed
(N
);
17293 end Reset_Analyzed_Flags
;
17295 ------------------------
17296 -- Restore_SPARK_Mode --
17297 ------------------------
17299 procedure Restore_SPARK_Mode
(Mode
: SPARK_Mode_Type
) is
17301 SPARK_Mode
:= Mode
;
17302 end Restore_SPARK_Mode
;
17304 --------------------------------
17305 -- Returns_Unconstrained_Type --
17306 --------------------------------
17308 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
17310 return Ekind
(Subp
) = E_Function
17311 and then not Is_Scalar_Type
(Etype
(Subp
))
17312 and then not Is_Access_Type
(Etype
(Subp
))
17313 and then not Is_Constrained
(Etype
(Subp
));
17314 end Returns_Unconstrained_Type
;
17316 ----------------------------
17317 -- Root_Type_Of_Full_View --
17318 ----------------------------
17320 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
17321 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
17324 -- The root type of the full view may itself be a private type. Keep
17325 -- looking for the ultimate derivation parent.
17327 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
17328 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
17332 end Root_Type_Of_Full_View
;
17334 ---------------------------
17335 -- Safe_To_Capture_Value --
17336 ---------------------------
17338 function Safe_To_Capture_Value
17341 Cond
: Boolean := False) return Boolean
17344 -- The only entities for which we track constant values are variables
17345 -- which are not renamings, constants, out parameters, and in out
17346 -- parameters, so check if we have this case.
17348 -- Note: it may seem odd to track constant values for constants, but in
17349 -- fact this routine is used for other purposes than simply capturing
17350 -- the value. In particular, the setting of Known[_Non]_Null.
17352 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
17354 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
17358 -- For conditionals, we also allow loop parameters and all formals,
17359 -- including in parameters.
17361 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
17364 -- For all other cases, not just unsafe, but impossible to capture
17365 -- Current_Value, since the above are the only entities which have
17366 -- Current_Value fields.
17372 -- Skip if volatile or aliased, since funny things might be going on in
17373 -- these cases which we cannot necessarily track. Also skip any variable
17374 -- for which an address clause is given, or whose address is taken. Also
17375 -- never capture value of library level variables (an attempt to do so
17376 -- can occur in the case of package elaboration code).
17378 if Treat_As_Volatile
(Ent
)
17379 or else Is_Aliased
(Ent
)
17380 or else Present
(Address_Clause
(Ent
))
17381 or else Address_Taken
(Ent
)
17382 or else (Is_Library_Level_Entity
(Ent
)
17383 and then Ekind
(Ent
) = E_Variable
)
17388 -- OK, all above conditions are met. We also require that the scope of
17389 -- the reference be the same as the scope of the entity, not counting
17390 -- packages and blocks and loops.
17393 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
17394 R_Scope
: Entity_Id
;
17397 R_Scope
:= Current_Scope
;
17398 while R_Scope
/= Standard_Standard
loop
17399 exit when R_Scope
= E_Scope
;
17401 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
17404 R_Scope
:= Scope
(R_Scope
);
17409 -- We also require that the reference does not appear in a context
17410 -- where it is not sure to be executed (i.e. a conditional context
17411 -- or an exception handler). We skip this if Cond is True, since the
17412 -- capturing of values from conditional tests handles this ok.
17425 -- Seems dubious that case expressions are not handled here ???
17428 while Present
(P
) loop
17429 if Nkind
(P
) = N_If_Statement
17430 or else Nkind
(P
) = N_Case_Statement
17431 or else (Nkind
(P
) in N_Short_Circuit
17432 and then Desc
= Right_Opnd
(P
))
17433 or else (Nkind
(P
) = N_If_Expression
17434 and then Desc
/= First
(Expressions
(P
)))
17435 or else Nkind
(P
) = N_Exception_Handler
17436 or else Nkind
(P
) = N_Selective_Accept
17437 or else Nkind
(P
) = N_Conditional_Entry_Call
17438 or else Nkind
(P
) = N_Timed_Entry_Call
17439 or else Nkind
(P
) = N_Asynchronous_Select
17447 -- A special Ada 2012 case: the original node may be part
17448 -- of the else_actions of a conditional expression, in which
17449 -- case it might not have been expanded yet, and appears in
17450 -- a non-syntactic list of actions. In that case it is clearly
17451 -- not safe to save a value.
17454 and then Is_List_Member
(Desc
)
17455 and then No
(Parent
(List_Containing
(Desc
)))
17463 -- OK, looks safe to set value
17466 end Safe_To_Capture_Value
;
17472 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
17473 K1
: constant Node_Kind
:= Nkind
(N1
);
17474 K2
: constant Node_Kind
:= Nkind
(N2
);
17477 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
17478 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
17480 return Chars
(N1
) = Chars
(N2
);
17482 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
17483 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
17485 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
17486 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
17497 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
17498 N1
: constant Node_Id
:= Original_Node
(Node1
);
17499 N2
: constant Node_Id
:= Original_Node
(Node2
);
17500 -- We do the tests on original nodes, since we are most interested
17501 -- in the original source, not any expansion that got in the way.
17503 K1
: constant Node_Kind
:= Nkind
(N1
);
17504 K2
: constant Node_Kind
:= Nkind
(N2
);
17507 -- First case, both are entities with same entity
17509 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
17511 EN1
: constant Entity_Id
:= Entity
(N1
);
17512 EN2
: constant Entity_Id
:= Entity
(N2
);
17514 if Present
(EN1
) and then Present
(EN2
)
17515 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
17516 or else Is_Formal
(EN1
))
17524 -- Second case, selected component with same selector, same record
17526 if K1
= N_Selected_Component
17527 and then K2
= N_Selected_Component
17528 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
17530 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
17532 -- Third case, indexed component with same subscripts, same array
17534 elsif K1
= N_Indexed_Component
17535 and then K2
= N_Indexed_Component
17536 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
17541 E1
:= First
(Expressions
(N1
));
17542 E2
:= First
(Expressions
(N2
));
17543 while Present
(E1
) loop
17544 if not Same_Value
(E1
, E2
) then
17555 -- Fourth case, slice of same array with same bounds
17558 and then K2
= N_Slice
17559 and then Nkind
(Discrete_Range
(N1
)) = N_Range
17560 and then Nkind
(Discrete_Range
(N2
)) = N_Range
17561 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
17562 Low_Bound
(Discrete_Range
(N2
)))
17563 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
17564 High_Bound
(Discrete_Range
(N2
)))
17566 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
17568 -- All other cases, not clearly the same object
17579 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
17584 elsif not Is_Constrained
(T1
)
17585 and then not Is_Constrained
(T2
)
17586 and then Base_Type
(T1
) = Base_Type
(T2
)
17590 -- For now don't bother with case of identical constraints, to be
17591 -- fiddled with later on perhaps (this is only used for optimization
17592 -- purposes, so it is not critical to do a best possible job)
17603 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
17605 if Compile_Time_Known_Value
(Node1
)
17606 and then Compile_Time_Known_Value
(Node2
)
17607 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
17610 elsif Same_Object
(Node1
, Node2
) then
17617 -----------------------------
17618 -- Save_SPARK_Mode_And_Set --
17619 -----------------------------
17621 procedure Save_SPARK_Mode_And_Set
17622 (Context
: Entity_Id
;
17623 Mode
: out SPARK_Mode_Type
)
17626 -- Save the current mode in effect
17628 Mode
:= SPARK_Mode
;
17630 -- Do not consider illegal or partially decorated constructs
17632 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
17635 elsif Present
(SPARK_Pragma
(Context
)) then
17636 SPARK_Mode
:= Get_SPARK_Mode_From_Pragma
(SPARK_Pragma
(Context
));
17638 end Save_SPARK_Mode_And_Set
;
17640 -------------------------
17641 -- Scalar_Part_Present --
17642 -------------------------
17644 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
17648 if Is_Scalar_Type
(T
) then
17651 elsif Is_Array_Type
(T
) then
17652 return Scalar_Part_Present
(Component_Type
(T
));
17654 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
17655 C
:= First_Component_Or_Discriminant
(T
);
17656 while Present
(C
) loop
17657 if Scalar_Part_Present
(Etype
(C
)) then
17660 Next_Component_Or_Discriminant
(C
);
17666 end Scalar_Part_Present
;
17668 ------------------------
17669 -- Scope_Is_Transient --
17670 ------------------------
17672 function Scope_Is_Transient
return Boolean is
17674 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
17675 end Scope_Is_Transient
;
17681 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
17686 while Scop
/= Standard_Standard
loop
17687 Scop
:= Scope
(Scop
);
17689 if Scop
= Scope2
then
17697 --------------------------
17698 -- Scope_Within_Or_Same --
17699 --------------------------
17701 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
17706 while Scop
/= Standard_Standard
loop
17707 if Scop
= Scope2
then
17710 Scop
:= Scope
(Scop
);
17715 end Scope_Within_Or_Same
;
17717 --------------------
17718 -- Set_Convention --
17719 --------------------
17721 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
17723 Basic_Set_Convention
(E
, Val
);
17726 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
17727 and then Has_Foreign_Convention
(E
)
17730 -- A pragma Convention in an instance may apply to the subtype
17731 -- created for a formal, in which case we have already verified
17732 -- that conventions of actual and formal match and there is nothing
17733 -- to flag on the subtype.
17735 if In_Instance
then
17738 Set_Can_Use_Internal_Rep
(E
, False);
17742 -- If E is an object or component, and the type of E is an anonymous
17743 -- access type with no convention set, then also set the convention of
17744 -- the anonymous access type. We do not do this for anonymous protected
17745 -- types, since protected types always have the default convention.
17747 if Present
(Etype
(E
))
17748 and then (Is_Object
(E
)
17749 or else Ekind
(E
) = E_Component
17751 -- Allow E_Void (happens for pragma Convention appearing
17752 -- in the middle of a record applying to a component)
17754 or else Ekind
(E
) = E_Void
)
17757 Typ
: constant Entity_Id
:= Etype
(E
);
17760 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
17761 E_Anonymous_Access_Subprogram_Type
)
17762 and then not Has_Convention_Pragma
(Typ
)
17764 Basic_Set_Convention
(Typ
, Val
);
17765 Set_Has_Convention_Pragma
(Typ
);
17767 -- And for the access subprogram type, deal similarly with the
17768 -- designated E_Subprogram_Type if it is also internal (which
17771 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
17773 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
17775 if Ekind
(Dtype
) = E_Subprogram_Type
17776 and then Is_Itype
(Dtype
)
17777 and then not Has_Convention_Pragma
(Dtype
)
17779 Basic_Set_Convention
(Dtype
, Val
);
17780 Set_Has_Convention_Pragma
(Dtype
);
17787 end Set_Convention
;
17789 ------------------------
17790 -- Set_Current_Entity --
17791 ------------------------
17793 -- The given entity is to be set as the currently visible definition of its
17794 -- associated name (i.e. the Node_Id associated with its name). All we have
17795 -- to do is to get the name from the identifier, and then set the
17796 -- associated Node_Id to point to the given entity.
17798 procedure Set_Current_Entity
(E
: Entity_Id
) is
17800 Set_Name_Entity_Id
(Chars
(E
), E
);
17801 end Set_Current_Entity
;
17803 ---------------------------
17804 -- Set_Debug_Info_Needed --
17805 ---------------------------
17807 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
17809 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
17810 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
17811 -- Used to set debug info in a related node if not set already
17813 --------------------------------------
17814 -- Set_Debug_Info_Needed_If_Not_Set --
17815 --------------------------------------
17817 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
17819 if Present
(E
) and then not Needs_Debug_Info
(E
) then
17820 Set_Debug_Info_Needed
(E
);
17822 -- For a private type, indicate that the full view also needs
17823 -- debug information.
17826 and then Is_Private_Type
(E
)
17827 and then Present
(Full_View
(E
))
17829 Set_Debug_Info_Needed
(Full_View
(E
));
17832 end Set_Debug_Info_Needed_If_Not_Set
;
17834 -- Start of processing for Set_Debug_Info_Needed
17837 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
17838 -- indicates that Debug_Info_Needed is never required for the entity.
17839 -- Nothing to do if entity comes from a predefined file. Library files
17840 -- are compiled without debug information, but inlined bodies of these
17841 -- routines may appear in user code, and debug information on them ends
17842 -- up complicating debugging the user code.
17845 or else Debug_Info_Off
(T
)
17849 elsif In_Inlined_Body
17850 and then Is_Predefined_File_Name
17851 (Unit_File_Name
(Get_Source_Unit
(Sloc
(T
))))
17853 Set_Needs_Debug_Info
(T
, False);
17856 -- Set flag in entity itself. Note that we will go through the following
17857 -- circuitry even if the flag is already set on T. That's intentional,
17858 -- it makes sure that the flag will be set in subsidiary entities.
17860 Set_Needs_Debug_Info
(T
);
17862 -- Set flag on subsidiary entities if not set already
17864 if Is_Object
(T
) then
17865 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
17867 elsif Is_Type
(T
) then
17868 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
17870 if Is_Record_Type
(T
) then
17872 Ent
: Entity_Id
:= First_Entity
(T
);
17874 while Present
(Ent
) loop
17875 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
17880 -- For a class wide subtype, we also need debug information
17881 -- for the equivalent type.
17883 if Ekind
(T
) = E_Class_Wide_Subtype
then
17884 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
17887 elsif Is_Array_Type
(T
) then
17888 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
17891 Indx
: Node_Id
:= First_Index
(T
);
17893 while Present
(Indx
) loop
17894 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
17895 Indx
:= Next_Index
(Indx
);
17899 -- For a packed array type, we also need debug information for
17900 -- the type used to represent the packed array. Conversely, we
17901 -- also need it for the former if we need it for the latter.
17903 if Is_Packed
(T
) then
17904 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
17907 if Is_Packed_Array_Impl_Type
(T
) then
17908 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
17911 elsif Is_Access_Type
(T
) then
17912 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
17914 elsif Is_Private_Type
(T
) then
17916 FV
: constant Entity_Id
:= Full_View
(T
);
17919 Set_Debug_Info_Needed_If_Not_Set
(FV
);
17921 -- If the full view is itself a derived private type, we need
17922 -- debug information on its underlying type.
17925 and then Is_Private_Type
(FV
)
17926 and then Present
(Underlying_Full_View
(FV
))
17928 Set_Needs_Debug_Info
(Underlying_Full_View
(FV
));
17932 elsif Is_Protected_Type
(T
) then
17933 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
17935 elsif Is_Scalar_Type
(T
) then
17937 -- If the subrange bounds are materialized by dedicated constant
17938 -- objects, also include them in the debug info to make sure the
17939 -- debugger can properly use them.
17941 if Present
(Scalar_Range
(T
))
17942 and then Nkind
(Scalar_Range
(T
)) = N_Range
17945 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
17946 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
17949 if Is_Entity_Name
(Low_Bnd
) then
17950 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
17953 if Is_Entity_Name
(High_Bnd
) then
17954 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
17960 end Set_Debug_Info_Needed
;
17962 ----------------------------
17963 -- Set_Entity_With_Checks --
17964 ----------------------------
17966 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
17967 Val_Actual
: Entity_Id
;
17969 Post_Node
: Node_Id
;
17972 -- Unconditionally set the entity
17974 Set_Entity
(N
, Val
);
17976 -- The node to post on is the selector in the case of an expanded name,
17977 -- and otherwise the node itself.
17979 if Nkind
(N
) = N_Expanded_Name
then
17980 Post_Node
:= Selector_Name
(N
);
17985 -- Check for violation of No_Fixed_IO
17987 if Restriction_Check_Required
(No_Fixed_IO
)
17989 ((RTU_Loaded
(Ada_Text_IO
)
17990 and then (Is_RTE
(Val
, RE_Decimal_IO
)
17992 Is_RTE
(Val
, RE_Fixed_IO
)))
17995 (RTU_Loaded
(Ada_Wide_Text_IO
)
17996 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
17998 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
18001 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
18002 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
18004 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
18006 -- A special extra check, don't complain about a reference from within
18007 -- the Ada.Interrupts package itself!
18009 and then not In_Same_Extended_Unit
(N
, Val
)
18011 Check_Restriction
(No_Fixed_IO
, Post_Node
);
18014 -- Remaining checks are only done on source nodes. Note that we test
18015 -- for violation of No_Fixed_IO even on non-source nodes, because the
18016 -- cases for checking violations of this restriction are instantiations
18017 -- where the reference in the instance has Comes_From_Source False.
18019 if not Comes_From_Source
(N
) then
18023 -- Check for violation of No_Abort_Statements, which is triggered by
18024 -- call to Ada.Task_Identification.Abort_Task.
18026 if Restriction_Check_Required
(No_Abort_Statements
)
18027 and then (Is_RTE
(Val
, RE_Abort_Task
))
18029 -- A special extra check, don't complain about a reference from within
18030 -- the Ada.Task_Identification package itself!
18032 and then not In_Same_Extended_Unit
(N
, Val
)
18034 Check_Restriction
(No_Abort_Statements
, Post_Node
);
18037 if Val
= Standard_Long_Long_Integer
then
18038 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
18041 -- Check for violation of No_Dynamic_Attachment
18043 if Restriction_Check_Required
(No_Dynamic_Attachment
)
18044 and then RTU_Loaded
(Ada_Interrupts
)
18045 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
18046 Is_RTE
(Val
, RE_Is_Attached
) or else
18047 Is_RTE
(Val
, RE_Current_Handler
) or else
18048 Is_RTE
(Val
, RE_Attach_Handler
) or else
18049 Is_RTE
(Val
, RE_Exchange_Handler
) or else
18050 Is_RTE
(Val
, RE_Detach_Handler
) or else
18051 Is_RTE
(Val
, RE_Reference
))
18053 -- A special extra check, don't complain about a reference from within
18054 -- the Ada.Interrupts package itself!
18056 and then not In_Same_Extended_Unit
(N
, Val
)
18058 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
18061 -- Check for No_Implementation_Identifiers
18063 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
18065 -- We have an implementation defined entity if it is marked as
18066 -- implementation defined, or is defined in a package marked as
18067 -- implementation defined. However, library packages themselves
18068 -- are excluded (we don't want to flag Interfaces itself, just
18069 -- the entities within it).
18071 if (Is_Implementation_Defined
(Val
)
18073 (Present
(Scope
(Val
))
18074 and then Is_Implementation_Defined
(Scope
(Val
))))
18075 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
18076 and then Is_Library_Level_Entity
(Val
))
18078 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
18082 -- Do the style check
18085 and then not Suppress_Style_Checks
(Val
)
18086 and then not In_Instance
18088 if Nkind
(N
) = N_Identifier
then
18090 elsif Nkind
(N
) = N_Expanded_Name
then
18091 Nod
:= Selector_Name
(N
);
18096 -- A special situation arises for derived operations, where we want
18097 -- to do the check against the parent (since the Sloc of the derived
18098 -- operation points to the derived type declaration itself).
18101 while not Comes_From_Source
(Val_Actual
)
18102 and then Nkind
(Val_Actual
) in N_Entity
18103 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
18104 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
18105 and then Present
(Alias
(Val_Actual
))
18107 Val_Actual
:= Alias
(Val_Actual
);
18110 -- Renaming declarations for generic actuals do not come from source,
18111 -- and have a different name from that of the entity they rename, so
18112 -- there is no style check to perform here.
18114 if Chars
(Nod
) = Chars
(Val_Actual
) then
18115 Style
.Check_Identifier
(Nod
, Val_Actual
);
18119 Set_Entity
(N
, Val
);
18120 end Set_Entity_With_Checks
;
18122 ------------------------
18123 -- Set_Name_Entity_Id --
18124 ------------------------
18126 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
18128 Set_Name_Table_Int
(Id
, Int
(Val
));
18129 end Set_Name_Entity_Id
;
18131 ---------------------
18132 -- Set_Next_Actual --
18133 ---------------------
18135 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
18137 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
18138 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
18140 end Set_Next_Actual
;
18142 ----------------------------------
18143 -- Set_Optimize_Alignment_Flags --
18144 ----------------------------------
18146 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
18148 if Optimize_Alignment
= 'S' then
18149 Set_Optimize_Alignment_Space
(E
);
18150 elsif Optimize_Alignment
= 'T' then
18151 Set_Optimize_Alignment_Time
(E
);
18153 end Set_Optimize_Alignment_Flags
;
18155 -----------------------
18156 -- Set_Public_Status --
18157 -----------------------
18159 procedure Set_Public_Status
(Id
: Entity_Id
) is
18160 S
: constant Entity_Id
:= Current_Scope
;
18162 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
18163 -- Determines if E is defined within handled statement sequence or
18164 -- an if statement, returns True if so, False otherwise.
18166 ----------------------
18167 -- Within_HSS_Or_If --
18168 ----------------------
18170 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
18173 N
:= Declaration_Node
(E
);
18180 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
18186 end Within_HSS_Or_If
;
18188 -- Start of processing for Set_Public_Status
18191 -- Everything in the scope of Standard is public
18193 if S
= Standard_Standard
then
18194 Set_Is_Public
(Id
);
18196 -- Entity is definitely not public if enclosing scope is not public
18198 elsif not Is_Public
(S
) then
18201 -- An object or function declaration that occurs in a handled sequence
18202 -- of statements or within an if statement is the declaration for a
18203 -- temporary object or local subprogram generated by the expander. It
18204 -- never needs to be made public and furthermore, making it public can
18205 -- cause back end problems.
18207 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
18208 N_Function_Specification
)
18209 and then Within_HSS_Or_If
(Id
)
18213 -- Entities in public packages or records are public
18215 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
18216 Set_Is_Public
(Id
);
18218 -- The bounds of an entry family declaration can generate object
18219 -- declarations that are visible to the back-end, e.g. in the
18220 -- the declaration of a composite type that contains tasks.
18222 elsif Is_Concurrent_Type
(S
)
18223 and then not Has_Completion
(S
)
18224 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
18226 Set_Is_Public
(Id
);
18228 end Set_Public_Status
;
18230 -----------------------------
18231 -- Set_Referenced_Modified --
18232 -----------------------------
18234 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
18238 -- Deal with indexed or selected component where prefix is modified
18240 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
18241 Pref
:= Prefix
(N
);
18243 -- If prefix is access type, then it is the designated object that is
18244 -- being modified, which means we have no entity to set the flag on.
18246 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
18249 -- Otherwise chase the prefix
18252 Set_Referenced_Modified
(Pref
, Out_Param
);
18255 -- Otherwise see if we have an entity name (only other case to process)
18257 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
18258 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
18259 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
18261 end Set_Referenced_Modified
;
18263 ----------------------------
18264 -- Set_Scope_Is_Transient --
18265 ----------------------------
18267 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
18269 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
18270 end Set_Scope_Is_Transient
;
18272 -------------------
18273 -- Set_Size_Info --
18274 -------------------
18276 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
18278 -- We copy Esize, but not RM_Size, since in general RM_Size is
18279 -- subtype specific and does not get inherited by all subtypes.
18281 Set_Esize
(T1
, Esize
(T2
));
18282 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
18284 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
18286 Is_Discrete_Or_Fixed_Point_Type
(T2
)
18288 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
18291 Set_Alignment
(T1
, Alignment
(T2
));
18294 --------------------
18295 -- Static_Boolean --
18296 --------------------
18298 function Static_Boolean
(N
: Node_Id
) return Uint
is
18300 Analyze_And_Resolve
(N
, Standard_Boolean
);
18303 or else Error_Posted
(N
)
18304 or else Etype
(N
) = Any_Type
18309 if Is_OK_Static_Expression
(N
) then
18310 if not Raises_Constraint_Error
(N
) then
18311 return Expr_Value
(N
);
18316 elsif Etype
(N
) = Any_Type
then
18320 Flag_Non_Static_Expr
18321 ("static boolean expression required here", N
);
18324 end Static_Boolean
;
18326 --------------------
18327 -- Static_Integer --
18328 --------------------
18330 function Static_Integer
(N
: Node_Id
) return Uint
is
18332 Analyze_And_Resolve
(N
, Any_Integer
);
18335 or else Error_Posted
(N
)
18336 or else Etype
(N
) = Any_Type
18341 if Is_OK_Static_Expression
(N
) then
18342 if not Raises_Constraint_Error
(N
) then
18343 return Expr_Value
(N
);
18348 elsif Etype
(N
) = Any_Type
then
18352 Flag_Non_Static_Expr
18353 ("static integer expression required here", N
);
18356 end Static_Integer
;
18358 --------------------------
18359 -- Statically_Different --
18360 --------------------------
18362 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
18363 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
18364 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
18366 return Is_Entity_Name
(R1
)
18367 and then Is_Entity_Name
(R2
)
18368 and then Entity
(R1
) /= Entity
(R2
)
18369 and then not Is_Formal
(Entity
(R1
))
18370 and then not Is_Formal
(Entity
(R2
));
18371 end Statically_Different
;
18373 --------------------------------------
18374 -- Subject_To_Loop_Entry_Attributes --
18375 --------------------------------------
18377 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
18383 -- The expansion mechanism transform a loop subject to at least one
18384 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
18385 -- the conditional part.
18387 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
18388 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
18390 Stmt
:= Original_Node
(N
);
18394 Nkind
(Stmt
) = N_Loop_Statement
18395 and then Present
(Identifier
(Stmt
))
18396 and then Present
(Entity
(Identifier
(Stmt
)))
18397 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
18398 end Subject_To_Loop_Entry_Attributes
;
18400 -----------------------------
18401 -- Subprogram_Access_Level --
18402 -----------------------------
18404 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
18406 if Present
(Alias
(Subp
)) then
18407 return Subprogram_Access_Level
(Alias
(Subp
));
18409 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
18411 end Subprogram_Access_Level
;
18413 -------------------------------
18414 -- Support_Atomic_Primitives --
18415 -------------------------------
18417 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
18421 -- Verify the alignment of Typ is known
18423 if not Known_Alignment
(Typ
) then
18427 if Known_Static_Esize
(Typ
) then
18428 Size
:= UI_To_Int
(Esize
(Typ
));
18430 -- If the Esize (Object_Size) is unknown at compile time, look at the
18431 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
18433 elsif Known_Static_RM_Size
(Typ
) then
18434 Size
:= UI_To_Int
(RM_Size
(Typ
));
18436 -- Otherwise, the size is considered to be unknown.
18442 -- Check that the size of the component is 8, 16, 32 or 64 bits and that
18443 -- Typ is properly aligned.
18446 when 8 |
16 |
32 |
64 =>
18447 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
18451 end Support_Atomic_Primitives
;
18457 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
18459 if Debug_Flag_W
then
18460 for J
in 0 .. Scope_Stack
.Last
loop
18465 Write_Name
(Chars
(E
));
18466 Write_Str
(" from ");
18467 Write_Location
(Sloc
(N
));
18472 -----------------------
18473 -- Transfer_Entities --
18474 -----------------------
18476 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
18477 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
18478 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
18479 -- Set_Public_Status. If successfull and Id denotes a record type, set
18480 -- the Is_Public attribute of its fields.
18482 --------------------------
18483 -- Set_Public_Status_Of --
18484 --------------------------
18486 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
18490 if not Is_Public
(Id
) then
18491 Set_Public_Status
(Id
);
18493 -- When the input entity is a public record type, ensure that all
18494 -- its internal fields are also exposed to the linker. The fields
18495 -- of a class-wide type are never made public.
18498 and then Is_Record_Type
(Id
)
18499 and then not Is_Class_Wide_Type
(Id
)
18501 Field
:= First_Entity
(Id
);
18502 while Present
(Field
) loop
18503 Set_Is_Public
(Field
);
18504 Next_Entity
(Field
);
18508 end Set_Public_Status_Of
;
18512 Full_Id
: Entity_Id
;
18515 -- Start of processing for Transfer_Entities
18518 Id
:= First_Entity
(From
);
18520 if Present
(Id
) then
18522 -- Merge the entity chain of the source scope with that of the
18523 -- destination scope.
18525 if Present
(Last_Entity
(To
)) then
18526 Set_Next_Entity
(Last_Entity
(To
), Id
);
18528 Set_First_Entity
(To
, Id
);
18531 Set_Last_Entity
(To
, Last_Entity
(From
));
18533 -- Inspect the entities of the source scope and update their Scope
18536 while Present
(Id
) loop
18537 Set_Scope
(Id
, To
);
18538 Set_Public_Status_Of
(Id
);
18540 -- Handle an internally generated full view for a private type
18542 if Is_Private_Type
(Id
)
18543 and then Present
(Full_View
(Id
))
18544 and then Is_Itype
(Full_View
(Id
))
18546 Full_Id
:= Full_View
(Id
);
18548 Set_Scope
(Full_Id
, To
);
18549 Set_Public_Status_Of
(Full_Id
);
18555 Set_First_Entity
(From
, Empty
);
18556 Set_Last_Entity
(From
, Empty
);
18558 end Transfer_Entities
;
18560 -----------------------
18561 -- Type_Access_Level --
18562 -----------------------
18564 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
18568 Btyp
:= Base_Type
(Typ
);
18570 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
18571 -- simply use the level where the type is declared. This is true for
18572 -- stand-alone object declarations, and for anonymous access types
18573 -- associated with components the level is the same as that of the
18574 -- enclosing composite type. However, special treatment is needed for
18575 -- the cases of access parameters, return objects of an anonymous access
18576 -- type, and, in Ada 95, access discriminants of limited types.
18578 if Is_Access_Type
(Btyp
) then
18579 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
18581 -- If the type is a nonlocal anonymous access type (such as for
18582 -- an access parameter) we treat it as being declared at the
18583 -- library level to ensure that names such as X.all'access don't
18584 -- fail static accessibility checks.
18586 if not Is_Local_Anonymous_Access
(Typ
) then
18587 return Scope_Depth
(Standard_Standard
);
18589 -- If this is a return object, the accessibility level is that of
18590 -- the result subtype of the enclosing function. The test here is
18591 -- little complicated, because we have to account for extended
18592 -- return statements that have been rewritten as blocks, in which
18593 -- case we have to find and the Is_Return_Object attribute of the
18594 -- itype's associated object. It would be nice to find a way to
18595 -- simplify this test, but it doesn't seem worthwhile to add a new
18596 -- flag just for purposes of this test. ???
18598 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
18601 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
18602 N_Object_Declaration
18603 and then Is_Return_Object
18604 (Defining_Identifier
18605 (Associated_Node_For_Itype
(Btyp
))))
18611 Scop
:= Scope
(Scope
(Btyp
));
18612 while Present
(Scop
) loop
18613 exit when Ekind
(Scop
) = E_Function
;
18614 Scop
:= Scope
(Scop
);
18617 -- Treat the return object's type as having the level of the
18618 -- function's result subtype (as per RM05-6.5(5.3/2)).
18620 return Type_Access_Level
(Etype
(Scop
));
18625 Btyp
:= Root_Type
(Btyp
);
18627 -- The accessibility level of anonymous access types associated with
18628 -- discriminants is that of the current instance of the type, and
18629 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
18631 -- AI-402: access discriminants have accessibility based on the
18632 -- object rather than the type in Ada 2005, so the above paragraph
18635 -- ??? Needs completion with rules from AI-416
18637 if Ada_Version
<= Ada_95
18638 and then Ekind
(Typ
) = E_Anonymous_Access_Type
18639 and then Present
(Associated_Node_For_Itype
(Typ
))
18640 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
18641 N_Discriminant_Specification
18643 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
18647 -- Return library level for a generic formal type. This is done because
18648 -- RM(10.3.2) says that "The statically deeper relationship does not
18649 -- apply to ... a descendant of a generic formal type". Rather than
18650 -- checking at each point where a static accessibility check is
18651 -- performed to see if we are dealing with a formal type, this rule is
18652 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
18653 -- return extreme values for a formal type; Deepest_Type_Access_Level
18654 -- returns Int'Last. By calling the appropriate function from among the
18655 -- two, we ensure that the static accessibility check will pass if we
18656 -- happen to run into a formal type. More specifically, we should call
18657 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
18658 -- call occurs as part of a static accessibility check and the error
18659 -- case is the case where the type's level is too shallow (as opposed
18662 if Is_Generic_Type
(Root_Type
(Btyp
)) then
18663 return Scope_Depth
(Standard_Standard
);
18666 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
18667 end Type_Access_Level
;
18669 ------------------------------------
18670 -- Type_Without_Stream_Operation --
18671 ------------------------------------
18673 function Type_Without_Stream_Operation
18675 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
18677 BT
: constant Entity_Id
:= Base_Type
(T
);
18678 Op_Missing
: Boolean;
18681 if not Restriction_Active
(No_Default_Stream_Attributes
) then
18685 if Is_Elementary_Type
(T
) then
18686 if Op
= TSS_Null
then
18688 No
(TSS
(BT
, TSS_Stream_Read
))
18689 or else No
(TSS
(BT
, TSS_Stream_Write
));
18692 Op_Missing
:= No
(TSS
(BT
, Op
));
18701 elsif Is_Array_Type
(T
) then
18702 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
18704 elsif Is_Record_Type
(T
) then
18710 Comp
:= First_Component
(T
);
18711 while Present
(Comp
) loop
18712 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
18714 if Present
(C_Typ
) then
18718 Next_Component
(Comp
);
18724 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
18725 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
18729 end Type_Without_Stream_Operation
;
18731 ----------------------------
18732 -- Unique_Defining_Entity --
18733 ----------------------------
18735 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
18737 return Unique_Entity
(Defining_Entity
(N
));
18738 end Unique_Defining_Entity
;
18740 -------------------
18741 -- Unique_Entity --
18742 -------------------
18744 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
18745 U
: Entity_Id
:= E
;
18751 if Present
(Full_View
(E
)) then
18752 U
:= Full_View
(E
);
18756 if Present
(Full_View
(E
)) then
18757 U
:= Full_View
(E
);
18760 when E_Package_Body
=>
18763 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
18767 U
:= Corresponding_Spec
(P
);
18769 when E_Subprogram_Body
=>
18772 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
18778 if Nkind
(P
) = N_Subprogram_Body_Stub
then
18779 if Present
(Library_Unit
(P
)) then
18781 -- Get to the function or procedure (generic) entity through
18782 -- the body entity.
18785 Unique_Entity
(Defining_Entity
(Get_Body_From_Stub
(P
)));
18788 U
:= Corresponding_Spec
(P
);
18791 when Formal_Kind
=>
18792 if Present
(Spec_Entity
(E
)) then
18793 U
:= Spec_Entity
(E
);
18807 function Unique_Name
(E
: Entity_Id
) return String is
18809 -- Names of E_Subprogram_Body or E_Package_Body entities are not
18810 -- reliable, as they may not include the overloading suffix. Instead,
18811 -- when looking for the name of E or one of its enclosing scope, we get
18812 -- the name of the corresponding Unique_Entity.
18814 function Get_Scoped_Name
(E
: Entity_Id
) return String;
18815 -- Return the name of E prefixed by all the names of the scopes to which
18816 -- E belongs, except for Standard.
18818 ---------------------
18819 -- Get_Scoped_Name --
18820 ---------------------
18822 function Get_Scoped_Name
(E
: Entity_Id
) return String is
18823 Name
: constant String := Get_Name_String
(Chars
(E
));
18825 if Has_Fully_Qualified_Name
(E
)
18826 or else Scope
(E
) = Standard_Standard
18830 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
18832 end Get_Scoped_Name
;
18834 -- Start of processing for Unique_Name
18837 if E
= Standard_Standard
then
18838 return Get_Name_String
(Name_Standard
);
18840 elsif Scope
(E
) = Standard_Standard
18841 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
18843 return Get_Name_String
(Name_Standard
) & "__" &
18844 Get_Name_String
(Chars
(E
));
18846 elsif Ekind
(E
) = E_Enumeration_Literal
then
18847 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
18850 return Get_Scoped_Name
(Unique_Entity
(E
));
18854 ---------------------
18855 -- Unit_Is_Visible --
18856 ---------------------
18858 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
18859 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
18860 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
18862 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
18863 -- For a child unit, check whether unit appears in a with_clause
18866 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
18867 -- Scan the context clause of one compilation unit looking for a
18868 -- with_clause for the unit in question.
18870 ----------------------------
18871 -- Unit_In_Parent_Context --
18872 ----------------------------
18874 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
18876 if Unit_In_Context
(Par_Unit
) then
18879 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
18880 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
18885 end Unit_In_Parent_Context
;
18887 ---------------------
18888 -- Unit_In_Context --
18889 ---------------------
18891 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
18895 Clause
:= First
(Context_Items
(Comp_Unit
));
18896 while Present
(Clause
) loop
18897 if Nkind
(Clause
) = N_With_Clause
then
18898 if Library_Unit
(Clause
) = U
then
18901 -- The with_clause may denote a renaming of the unit we are
18902 -- looking for, eg. Text_IO which renames Ada.Text_IO.
18905 Renamed_Entity
(Entity
(Name
(Clause
))) =
18906 Defining_Entity
(Unit
(U
))
18916 end Unit_In_Context
;
18918 -- Start of processing for Unit_Is_Visible
18921 -- The currrent unit is directly visible
18926 elsif Unit_In_Context
(Curr
) then
18929 -- If the current unit is a body, check the context of the spec
18931 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
18933 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
18934 and then not Acts_As_Spec
(Unit
(Curr
)))
18936 if Unit_In_Context
(Library_Unit
(Curr
)) then
18941 -- If the spec is a child unit, examine the parents
18943 if Is_Child_Unit
(Curr_Entity
) then
18944 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
18946 Unit_In_Parent_Context
18947 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
18949 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
18955 end Unit_Is_Visible
;
18957 ------------------------------
18958 -- Universal_Interpretation --
18959 ------------------------------
18961 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
18962 Index
: Interp_Index
;
18966 -- The argument may be a formal parameter of an operator or subprogram
18967 -- with multiple interpretations, or else an expression for an actual.
18969 if Nkind
(Opnd
) = N_Defining_Identifier
18970 or else not Is_Overloaded
(Opnd
)
18972 if Etype
(Opnd
) = Universal_Integer
18973 or else Etype
(Opnd
) = Universal_Real
18975 return Etype
(Opnd
);
18981 Get_First_Interp
(Opnd
, Index
, It
);
18982 while Present
(It
.Typ
) loop
18983 if It
.Typ
= Universal_Integer
18984 or else It
.Typ
= Universal_Real
18989 Get_Next_Interp
(Index
, It
);
18994 end Universal_Interpretation
;
19000 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
19002 -- Recurse to handle unlikely case of multiple levels of qualification
19004 if Nkind
(Expr
) = N_Qualified_Expression
then
19005 return Unqualify
(Expression
(Expr
));
19007 -- Normal case, not a qualified expression
19014 -----------------------
19015 -- Visible_Ancestors --
19016 -----------------------
19018 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
19024 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
19026 -- Collect all the parents and progenitors of Typ. If the full-view of
19027 -- private parents and progenitors is available then it is used to
19028 -- generate the list of visible ancestors; otherwise their partial
19029 -- view is added to the resulting list.
19034 Use_Full_View
=> True);
19038 Ifaces_List
=> List_2
,
19039 Exclude_Parents
=> True,
19040 Use_Full_View
=> True);
19042 -- Join the two lists. Avoid duplications because an interface may
19043 -- simultaneously be parent and progenitor of a type.
19045 Elmt
:= First_Elmt
(List_2
);
19046 while Present
(Elmt
) loop
19047 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
19052 end Visible_Ancestors
;
19054 ----------------------
19055 -- Within_Init_Proc --
19056 ----------------------
19058 function Within_Init_Proc
return Boolean is
19062 S
:= Current_Scope
;
19063 while not Is_Overloadable
(S
) loop
19064 if S
= Standard_Standard
then
19071 return Is_Init_Proc
(S
);
19072 end Within_Init_Proc
;
19078 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
19085 elsif SE
= Standard_Standard
then
19097 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
19098 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
19099 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
19101 Matching_Field
: Entity_Id
;
19102 -- Entity to give a more precise suggestion on how to write a one-
19103 -- element positional aggregate.
19105 function Has_One_Matching_Field
return Boolean;
19106 -- Determines if Expec_Type is a record type with a single component or
19107 -- discriminant whose type matches the found type or is one dimensional
19108 -- array whose component type matches the found type. In the case of
19109 -- one discriminant, we ignore the variant parts. That's not accurate,
19110 -- but good enough for the warning.
19112 ----------------------------
19113 -- Has_One_Matching_Field --
19114 ----------------------------
19116 function Has_One_Matching_Field
return Boolean is
19120 Matching_Field
:= Empty
;
19122 if Is_Array_Type
(Expec_Type
)
19123 and then Number_Dimensions
(Expec_Type
) = 1
19124 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
19126 -- Use type name if available. This excludes multidimensional
19127 -- arrays and anonymous arrays.
19129 if Comes_From_Source
(Expec_Type
) then
19130 Matching_Field
:= Expec_Type
;
19132 -- For an assignment, use name of target
19134 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
19135 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
19137 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
19142 elsif not Is_Record_Type
(Expec_Type
) then
19146 E
:= First_Entity
(Expec_Type
);
19151 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
19152 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
19161 if not Covers
(Etype
(E
), Found_Type
) then
19164 elsif Present
(Next_Entity
(E
))
19165 and then (Ekind
(E
) = E_Component
19166 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
19171 Matching_Field
:= E
;
19175 end Has_One_Matching_Field
;
19177 -- Start of processing for Wrong_Type
19180 -- Don't output message if either type is Any_Type, or if a message
19181 -- has already been posted for this node. We need to do the latter
19182 -- check explicitly (it is ordinarily done in Errout), because we
19183 -- are using ! to force the output of the error messages.
19185 if Expec_Type
= Any_Type
19186 or else Found_Type
= Any_Type
19187 or else Error_Posted
(Expr
)
19191 -- If one of the types is a Taft-Amendment type and the other it its
19192 -- completion, it must be an illegal use of a TAT in the spec, for
19193 -- which an error was already emitted. Avoid cascaded errors.
19195 elsif Is_Incomplete_Type
(Expec_Type
)
19196 and then Has_Completion_In_Body
(Expec_Type
)
19197 and then Full_View
(Expec_Type
) = Etype
(Expr
)
19201 elsif Is_Incomplete_Type
(Etype
(Expr
))
19202 and then Has_Completion_In_Body
(Etype
(Expr
))
19203 and then Full_View
(Etype
(Expr
)) = Expec_Type
19207 -- In an instance, there is an ongoing problem with completion of
19208 -- type derived from private types. Their structure is what Gigi
19209 -- expects, but the Etype is the parent type rather than the
19210 -- derived private type itself. Do not flag error in this case. The
19211 -- private completion is an entity without a parent, like an Itype.
19212 -- Similarly, full and partial views may be incorrect in the instance.
19213 -- There is no simple way to insure that it is consistent ???
19215 -- A similar view discrepancy can happen in an inlined body, for the
19216 -- same reason: inserted body may be outside of the original package
19217 -- and only partial views are visible at the point of insertion.
19219 elsif In_Instance
or else In_Inlined_Body
then
19220 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
19222 (Has_Private_Declaration
(Expected_Type
)
19223 or else Has_Private_Declaration
(Etype
(Expr
)))
19224 and then No
(Parent
(Expected_Type
))
19228 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
19229 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
19233 elsif Is_Private_Type
(Expected_Type
)
19234 and then Present
(Full_View
(Expected_Type
))
19235 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
19239 -- Conversely, type of expression may be the private one
19241 elsif Is_Private_Type
(Base_Type
(Etype
(Expr
)))
19242 and then Full_View
(Base_Type
(Etype
(Expr
))) = Expected_Type
19248 -- An interesting special check. If the expression is parenthesized
19249 -- and its type corresponds to the type of the sole component of the
19250 -- expected record type, or to the component type of the expected one
19251 -- dimensional array type, then assume we have a bad aggregate attempt.
19253 if Nkind
(Expr
) in N_Subexpr
19254 and then Paren_Count
(Expr
) /= 0
19255 and then Has_One_Matching_Field
19257 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
19259 if Present
(Matching_Field
) then
19260 if Is_Array_Type
(Expec_Type
) then
19262 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
19265 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
19269 -- Another special check, if we are looking for a pool-specific access
19270 -- type and we found an E_Access_Attribute_Type, then we have the case
19271 -- of an Access attribute being used in a context which needs a pool-
19272 -- specific type, which is never allowed. The one extra check we make
19273 -- is that the expected designated type covers the Found_Type.
19275 elsif Is_Access_Type
(Expec_Type
)
19276 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
19277 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
19278 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
19280 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
19282 Error_Msg_N
-- CODEFIX
19283 ("result must be general access type!", Expr
);
19284 Error_Msg_NE
-- CODEFIX
19285 ("add ALL to }!", Expr
, Expec_Type
);
19287 -- Another special check, if the expected type is an integer type,
19288 -- but the expression is of type System.Address, and the parent is
19289 -- an addition or subtraction operation whose left operand is the
19290 -- expression in question and whose right operand is of an integral
19291 -- type, then this is an attempt at address arithmetic, so give
19292 -- appropriate message.
19294 elsif Is_Integer_Type
(Expec_Type
)
19295 and then Is_RTE
(Found_Type
, RE_Address
)
19296 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
19297 and then Expr
= Left_Opnd
(Parent
(Expr
))
19298 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
19301 ("address arithmetic not predefined in package System",
19304 ("\possible missing with/use of System.Storage_Elements",
19308 -- If the expected type is an anonymous access type, as for access
19309 -- parameters and discriminants, the error is on the designated types.
19311 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
19312 if Comes_From_Source
(Expec_Type
) then
19313 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
19316 ("expected an access type with designated}",
19317 Expr
, Designated_Type
(Expec_Type
));
19320 if Is_Access_Type
(Found_Type
)
19321 and then not Comes_From_Source
(Found_Type
)
19324 ("\\found an access type with designated}!",
19325 Expr
, Designated_Type
(Found_Type
));
19327 if From_Limited_With
(Found_Type
) then
19328 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
19329 Error_Msg_Qual_Level
:= 99;
19330 Error_Msg_NE
-- CODEFIX
19331 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
19332 Error_Msg_Qual_Level
:= 0;
19334 Error_Msg_NE
("found}!", Expr
, Found_Type
);
19338 -- Normal case of one type found, some other type expected
19341 -- If the names of the two types are the same, see if some number
19342 -- of levels of qualification will help. Don't try more than three
19343 -- levels, and if we get to standard, it's no use (and probably
19344 -- represents an error in the compiler) Also do not bother with
19345 -- internal scope names.
19348 Expec_Scope
: Entity_Id
;
19349 Found_Scope
: Entity_Id
;
19352 Expec_Scope
:= Expec_Type
;
19353 Found_Scope
:= Found_Type
;
19355 for Levels
in Int
range 0 .. 3 loop
19356 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
19357 Error_Msg_Qual_Level
:= Levels
;
19361 Expec_Scope
:= Scope
(Expec_Scope
);
19362 Found_Scope
:= Scope
(Found_Scope
);
19364 exit when Expec_Scope
= Standard_Standard
19365 or else Found_Scope
= Standard_Standard
19366 or else not Comes_From_Source
(Expec_Scope
)
19367 or else not Comes_From_Source
(Found_Scope
);
19371 if Is_Record_Type
(Expec_Type
)
19372 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
19374 Error_Msg_NE
("expected}!", Expr
,
19375 Corresponding_Remote_Type
(Expec_Type
));
19377 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
19380 if Is_Entity_Name
(Expr
)
19381 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
19383 Error_Msg_N
("\\found package name!", Expr
);
19385 elsif Is_Entity_Name
(Expr
)
19386 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
19388 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
19390 ("found procedure name, possibly missing Access attribute!",
19394 ("\\found procedure name instead of function!", Expr
);
19397 elsif Nkind
(Expr
) = N_Function_Call
19398 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
19399 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
19400 and then No
(Parameter_Associations
(Expr
))
19403 ("found function name, possibly missing Access attribute!",
19406 -- Catch common error: a prefix or infix operator which is not
19407 -- directly visible because the type isn't.
19409 elsif Nkind
(Expr
) in N_Op
19410 and then Is_Overloaded
(Expr
)
19411 and then not Is_Immediately_Visible
(Expec_Type
)
19412 and then not Is_Potentially_Use_Visible
(Expec_Type
)
19413 and then not In_Use
(Expec_Type
)
19414 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
19417 ("operator of the type is not directly visible!", Expr
);
19419 elsif Ekind
(Found_Type
) = E_Void
19420 and then Present
(Parent
(Found_Type
))
19421 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
19423 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
19426 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
19429 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
19430 -- of the same modular type, and (M1 and M2) = 0 was intended.
19432 if Expec_Type
= Standard_Boolean
19433 and then Is_Modular_Integer_Type
(Found_Type
)
19434 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
19435 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
19438 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
19439 L
: constant Node_Id
:= Left_Opnd
(Op
);
19440 R
: constant Node_Id
:= Right_Opnd
(Op
);
19443 -- The case for the message is when the left operand of the
19444 -- comparison is the same modular type, or when it is an
19445 -- integer literal (or other universal integer expression),
19446 -- which would have been typed as the modular type if the
19447 -- parens had been there.
19449 if (Etype
(L
) = Found_Type
19451 Etype
(L
) = Universal_Integer
)
19452 and then Is_Integer_Type
(Etype
(R
))
19455 ("\\possible missing parens for modular operation", Expr
);
19460 -- Reset error message qualification indication
19462 Error_Msg_Qual_Level
:= 0;