1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2016, 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 Treepr
; -- ???For debugging code below
28 with Aspects
; use Aspects
;
29 with Atree
; use Atree
;
30 with Casing
; use Casing
;
31 with Checks
; use Checks
;
32 with Debug
; use Debug
;
33 with Elists
; use Elists
;
34 with Errout
; use Errout
;
35 with Exp_Ch11
; use Exp_Ch11
;
36 with Exp_Disp
; use Exp_Disp
;
37 with Exp_Util
; use Exp_Util
;
38 with Fname
; use Fname
;
39 with Freeze
; use Freeze
;
40 with Ghost
; use Ghost
;
42 with Lib
.Xref
; use Lib
.Xref
;
43 with Namet
.Sp
; use Namet
.Sp
;
44 with Nlists
; use Nlists
;
45 with Nmake
; use Nmake
;
46 with Output
; use Output
;
47 with Restrict
; use Restrict
;
48 with Rident
; use Rident
;
49 with Rtsfind
; use Rtsfind
;
51 with Sem_Aux
; use Sem_Aux
;
52 with Sem_Attr
; use Sem_Attr
;
53 with Sem_Ch6
; use Sem_Ch6
;
54 with Sem_Ch8
; use Sem_Ch8
;
55 with Sem_Ch13
; use Sem_Ch13
;
56 with Sem_Disp
; use Sem_Disp
;
57 with Sem_Eval
; use Sem_Eval
;
58 with Sem_Prag
; use Sem_Prag
;
59 with Sem_Res
; use Sem_Res
;
60 with Sem_Warn
; use Sem_Warn
;
61 with Sem_Type
; use Sem_Type
;
62 with Sinfo
; use Sinfo
;
63 with Sinput
; use Sinput
;
64 with Stand
; use Stand
;
66 with Stringt
; use Stringt
;
67 with Targparm
; use Targparm
;
68 with Tbuild
; use Tbuild
;
69 with Ttypes
; use Ttypes
;
70 with Uname
; use Uname
;
72 with GNAT
.HTable
; use GNAT
.HTable
;
74 package body Sem_Util
is
76 ----------------------------------------
77 -- Global Variables for New_Copy_Tree --
78 ----------------------------------------
80 -- These global variables are used by New_Copy_Tree. See description of the
81 -- body of this subprogram for details. Global variables can be safely used
82 -- by New_Copy_Tree, since there is no case of a recursive call from the
83 -- processing inside New_Copy_Tree.
85 NCT_Hash_Threshold
: constant := 20;
86 -- If there are more than this number of pairs of entries in the map, then
87 -- Hash_Tables_Used will be set, and the hash tables will be initialized
88 -- and used for the searches.
90 NCT_Hash_Tables_Used
: Boolean := False;
91 -- Set to True if hash tables are in use
93 NCT_Table_Entries
: Nat
:= 0;
94 -- Count entries in table to see if threshold is reached
96 NCT_Hash_Table_Setup
: Boolean := False;
97 -- Set to True if hash table contains data. We set this True if we setup
98 -- the hash table with data, and leave it set permanently from then on,
99 -- this is a signal that second and subsequent users of the hash table
100 -- must clear the old entries before reuse.
102 subtype NCT_Header_Num
is Int
range 0 .. 511;
103 -- Defines range of headers in hash tables (512 headers)
105 -----------------------
106 -- Local Subprograms --
107 -----------------------
109 function Build_Component_Subtype
112 T
: Entity_Id
) return Node_Id
;
113 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
114 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
115 -- Loc is the source location, T is the original subtype.
117 function Has_Enabled_Property
118 (Item_Id
: Entity_Id
;
119 Property
: Name_Id
) return Boolean;
120 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
121 -- Determine whether an abstract state or a variable denoted by entity
122 -- Item_Id has enabled property Property.
124 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
125 -- T is a derived tagged type. Check whether the type extension is null.
126 -- If the parent type is fully initialized, T can be treated as such.
128 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
129 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
130 -- with discriminants whose default values are static, examine only the
131 -- components in the selected variant to determine whether all of them
134 ------------------------------
135 -- Abstract_Interface_List --
136 ------------------------------
138 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
142 if Is_Concurrent_Type
(Typ
) then
144 -- If we are dealing with a synchronized subtype, go to the base
145 -- type, whose declaration has the interface list.
147 -- Shouldn't this be Declaration_Node???
149 Nod
:= Parent
(Base_Type
(Typ
));
151 if Nkind
(Nod
) = N_Full_Type_Declaration
then
155 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
156 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
157 Nod
:= Type_Definition
(Parent
(Typ
));
159 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
160 if Present
(Full_View
(Typ
))
162 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
164 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
166 -- If the full-view is not available we cannot do anything else
167 -- here (the source has errors).
173 -- Support for generic formals with interfaces is still missing ???
175 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
180 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
184 elsif Ekind
(Typ
) = E_Record_Subtype
then
185 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
187 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
189 -- Recurse, because parent may still be a private extension. Also
190 -- note that the full view of the subtype or the full view of its
191 -- base type may (both) be unavailable.
193 return Abstract_Interface_List
(Etype
(Typ
));
195 else pragma Assert
((Ekind
(Typ
)) = E_Record_Type
);
196 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
197 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
199 Nod
:= Type_Definition
(Parent
(Typ
));
203 return Interface_List
(Nod
);
204 end Abstract_Interface_List
;
206 --------------------------------
207 -- Add_Access_Type_To_Process --
208 --------------------------------
210 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
214 Ensure_Freeze_Node
(E
);
215 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
219 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
223 end Add_Access_Type_To_Process
;
225 --------------------------
226 -- Add_Block_Identifier --
227 --------------------------
229 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
230 Loc
: constant Source_Ptr
:= Sloc
(N
);
233 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
235 -- The block already has a label, return its entity
237 if Present
(Identifier
(N
)) then
238 Id
:= Entity
(Identifier
(N
));
240 -- Create a new block label and set its attributes
243 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
244 Set_Etype
(Id
, Standard_Void_Type
);
247 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
248 Set_Block_Node
(Id
, Identifier
(N
));
250 end Add_Block_Identifier
;
252 ----------------------------
253 -- Add_Global_Declaration --
254 ----------------------------
256 procedure Add_Global_Declaration
(N
: Node_Id
) is
257 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
260 if No
(Declarations
(Aux_Node
)) then
261 Set_Declarations
(Aux_Node
, New_List
);
264 Append_To
(Declarations
(Aux_Node
), N
);
266 end Add_Global_Declaration
;
268 --------------------------------
269 -- Address_Integer_Convert_OK --
270 --------------------------------
272 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
274 if Allow_Integer_Address
275 and then ((Is_Descendant_Of_Address
(T1
)
276 and then Is_Private_Type
(T1
)
277 and then Is_Integer_Type
(T2
))
279 (Is_Descendant_Of_Address
(T2
)
280 and then Is_Private_Type
(T2
)
281 and then Is_Integer_Type
(T1
)))
287 end Address_Integer_Convert_OK
;
293 function Address_Value
(N
: Node_Id
) return Node_Id
is
298 -- For constant, get constant expression
300 if Is_Entity_Name
(Expr
)
301 and then Ekind
(Entity
(Expr
)) = E_Constant
303 Expr
:= Constant_Value
(Entity
(Expr
));
305 -- For unchecked conversion, get result to convert
307 elsif Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
308 Expr
:= Expression
(Expr
);
310 -- For (common case) of To_Address call, get argument
312 elsif Nkind
(Expr
) = N_Function_Call
313 and then Is_Entity_Name
(Name
(Expr
))
314 and then Is_RTE
(Entity
(Name
(Expr
)), RE_To_Address
)
316 Expr
:= First
(Parameter_Associations
(Expr
));
318 if Nkind
(Expr
) = N_Parameter_Association
then
319 Expr
:= Explicit_Actual_Parameter
(Expr
);
322 -- We finally have the real expression
336 -- For now, just 8/16/32/64
338 function Addressable
(V
: Uint
) return Boolean is
340 return V
= Uint_8
or else
346 function Addressable
(V
: Int
) return Boolean is
354 ---------------------------------
355 -- Aggregate_Constraint_Checks --
356 ---------------------------------
358 procedure Aggregate_Constraint_Checks
360 Check_Typ
: Entity_Id
)
362 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
365 if Raises_Constraint_Error
(Exp
) then
369 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
370 -- component's type to force the appropriate accessibility checks.
372 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
373 -- force the corresponding run-time check
375 if Is_Access_Type
(Check_Typ
)
376 and then Is_Local_Anonymous_Access
(Check_Typ
)
378 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
379 Analyze_And_Resolve
(Exp
, Check_Typ
);
380 Check_Unset_Reference
(Exp
);
383 -- What follows is really expansion activity, so check that expansion
384 -- is on and is allowed. In GNATprove mode, we also want check flags to
385 -- be added in the tree, so that the formal verification can rely on
386 -- those to be present. In GNATprove mode for formal verification, some
387 -- treatment typically only done during expansion needs to be performed
388 -- on the tree, but it should not be applied inside generics. Otherwise,
389 -- this breaks the name resolution mechanism for generic instances.
391 if not Expander_Active
392 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
397 if Is_Access_Type
(Check_Typ
)
398 and then Can_Never_Be_Null
(Check_Typ
)
399 and then not Can_Never_Be_Null
(Exp_Typ
)
401 Install_Null_Excluding_Check
(Exp
);
404 -- First check if we have to insert discriminant checks
406 if Has_Discriminants
(Exp_Typ
) then
407 Apply_Discriminant_Check
(Exp
, Check_Typ
);
409 -- Next emit length checks for array aggregates
411 elsif Is_Array_Type
(Exp_Typ
) then
412 Apply_Length_Check
(Exp
, Check_Typ
);
414 -- Finally emit scalar and string checks. If we are dealing with a
415 -- scalar literal we need to check by hand because the Etype of
416 -- literals is not necessarily correct.
418 elsif Is_Scalar_Type
(Exp_Typ
)
419 and then Compile_Time_Known_Value
(Exp
)
421 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
422 Apply_Compile_Time_Constraint_Error
423 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
424 Ent
=> Base_Type
(Check_Typ
),
425 Typ
=> Base_Type
(Check_Typ
));
427 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
428 Apply_Compile_Time_Constraint_Error
429 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
433 elsif not Range_Checks_Suppressed
(Check_Typ
) then
434 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
437 -- Verify that target type is also scalar, to prevent view anomalies
438 -- in instantiations.
440 elsif (Is_Scalar_Type
(Exp_Typ
)
441 or else Nkind
(Exp
) = N_String_Literal
)
442 and then Is_Scalar_Type
(Check_Typ
)
443 and then Exp_Typ
/= Check_Typ
445 if Is_Entity_Name
(Exp
)
446 and then Ekind
(Entity
(Exp
)) = E_Constant
448 -- If expression is a constant, it is worthwhile checking whether
449 -- it is a bound of the type.
451 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
452 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
454 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
455 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
460 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
461 Analyze_And_Resolve
(Exp
, Check_Typ
);
462 Check_Unset_Reference
(Exp
);
465 -- Could use a comment on this case ???
468 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
469 Analyze_And_Resolve
(Exp
, Check_Typ
);
470 Check_Unset_Reference
(Exp
);
474 end Aggregate_Constraint_Checks
;
476 -----------------------
477 -- Alignment_In_Bits --
478 -----------------------
480 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
482 return Alignment
(E
) * System_Storage_Unit
;
483 end Alignment_In_Bits
;
485 --------------------------------------
486 -- All_Composite_Constraints_Static --
487 --------------------------------------
489 function All_Composite_Constraints_Static
490 (Constr
: Node_Id
) return Boolean
493 if No
(Constr
) or else Error_Posted
(Constr
) then
497 case Nkind
(Constr
) is
499 if Nkind
(Constr
) in N_Has_Entity
500 and then Present
(Entity
(Constr
))
502 if Is_Type
(Entity
(Constr
)) then
504 not Is_Discrete_Type
(Entity
(Constr
))
505 or else Is_OK_Static_Subtype
(Entity
(Constr
));
508 elsif Nkind
(Constr
) = N_Range
then
510 Is_OK_Static_Expression
(Low_Bound
(Constr
))
512 Is_OK_Static_Expression
(High_Bound
(Constr
));
514 elsif Nkind
(Constr
) = N_Attribute_Reference
515 and then Attribute_Name
(Constr
) = Name_Range
518 Is_OK_Static_Expression
519 (Type_Low_Bound
(Etype
(Prefix
(Constr
))))
521 Is_OK_Static_Expression
522 (Type_High_Bound
(Etype
(Prefix
(Constr
))));
526 not Present
(Etype
(Constr
)) -- previous error
527 or else not Is_Discrete_Type
(Etype
(Constr
))
528 or else Is_OK_Static_Expression
(Constr
);
530 when N_Discriminant_Association
=>
531 return All_Composite_Constraints_Static
(Expression
(Constr
));
533 when N_Range_Constraint
=>
535 All_Composite_Constraints_Static
(Range_Expression
(Constr
));
537 when N_Index_Or_Discriminant_Constraint
=>
539 One_Cstr
: Entity_Id
;
541 One_Cstr
:= First
(Constraints
(Constr
));
542 while Present
(One_Cstr
) loop
543 if not All_Composite_Constraints_Static
(One_Cstr
) then
553 when N_Subtype_Indication
=>
555 All_Composite_Constraints_Static
(Subtype_Mark
(Constr
))
557 All_Composite_Constraints_Static
(Constraint
(Constr
));
562 end All_Composite_Constraints_Static
;
564 ---------------------------------
565 -- Append_Inherited_Subprogram --
566 ---------------------------------
568 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
569 Par
: constant Entity_Id
:= Alias
(S
);
570 -- The parent subprogram
572 Scop
: constant Entity_Id
:= Scope
(Par
);
573 -- The scope of definition of the parent subprogram
575 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
576 -- The derived type of which S is a primitive operation
582 if Ekind
(Current_Scope
) = E_Package
583 and then In_Private_Part
(Current_Scope
)
584 and then Has_Private_Declaration
(Typ
)
585 and then Is_Tagged_Type
(Typ
)
586 and then Scop
= Current_Scope
588 -- The inherited operation is available at the earliest place after
589 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
590 -- relevant for type extensions. If the parent operation appears
591 -- after the type extension, the operation is not visible.
594 (Visible_Declarations
595 (Package_Specification
(Current_Scope
)));
596 while Present
(Decl
) loop
597 if Nkind
(Decl
) = N_Private_Extension_Declaration
598 and then Defining_Entity
(Decl
) = Typ
600 if Sloc
(Decl
) > Sloc
(Par
) then
601 Next_E
:= Next_Entity
(Par
);
602 Set_Next_Entity
(Par
, S
);
603 Set_Next_Entity
(S
, Next_E
);
615 -- If partial view is not a type extension, or it appears before the
616 -- subprogram declaration, insert normally at end of entity list.
618 Append_Entity
(S
, Current_Scope
);
619 end Append_Inherited_Subprogram
;
621 -----------------------------------------
622 -- Apply_Compile_Time_Constraint_Error --
623 -----------------------------------------
625 procedure Apply_Compile_Time_Constraint_Error
628 Reason
: RT_Exception_Code
;
629 Ent
: Entity_Id
:= Empty
;
630 Typ
: Entity_Id
:= Empty
;
631 Loc
: Source_Ptr
:= No_Location
;
632 Rep
: Boolean := True;
633 Warn
: Boolean := False)
635 Stat
: constant Boolean := Is_Static_Expression
(N
);
636 R_Stat
: constant Node_Id
:=
637 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
648 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
650 -- In GNATprove mode, do not replace the node with an exception raised.
651 -- In such a case, either the call to Compile_Time_Constraint_Error
652 -- issues an error which stops analysis, or it issues a warning in
653 -- a few cases where a suitable check flag is set for GNATprove to
654 -- generate a check message.
656 if not Rep
or GNATprove_Mode
then
660 -- Now we replace the node by an N_Raise_Constraint_Error node
661 -- This does not need reanalyzing, so set it as analyzed now.
664 Set_Analyzed
(N
, True);
667 Set_Raises_Constraint_Error
(N
);
669 -- Now deal with possible local raise handling
671 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
673 -- If the original expression was marked as static, the result is
674 -- still marked as static, but the Raises_Constraint_Error flag is
675 -- always set so that further static evaluation is not attempted.
678 Set_Is_Static_Expression
(N
);
680 end Apply_Compile_Time_Constraint_Error
;
682 ---------------------------
683 -- Async_Readers_Enabled --
684 ---------------------------
686 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
688 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
689 end Async_Readers_Enabled
;
691 ---------------------------
692 -- Async_Writers_Enabled --
693 ---------------------------
695 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
697 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
698 end Async_Writers_Enabled
;
700 --------------------------------------
701 -- Available_Full_View_Of_Component --
702 --------------------------------------
704 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
705 ST
: constant Entity_Id
:= Scope
(T
);
706 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
708 return In_Open_Scopes
(ST
)
709 and then In_Open_Scopes
(SCT
)
710 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
711 end Available_Full_View_Of_Component
;
717 procedure Bad_Attribute
720 Warn
: Boolean := False)
723 Error_Msg_Warn
:= Warn
;
724 Error_Msg_N
("unrecognized attribute&<<", N
);
726 -- Check for possible misspelling
728 Error_Msg_Name_1
:= First_Attribute_Name
;
729 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
730 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
731 Error_Msg_N
-- CODEFIX
732 ("\possible misspelling of %<<", N
);
736 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
740 --------------------------------
741 -- Bad_Predicated_Subtype_Use --
742 --------------------------------
744 procedure Bad_Predicated_Subtype_Use
748 Suggest_Static
: Boolean := False)
753 -- Avoid cascaded errors
755 if Error_Posted
(N
) then
759 if Inside_A_Generic
then
760 Gen
:= Current_Scope
;
761 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
769 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
770 Set_No_Predicate_On_Actual
(Typ
);
773 elsif Has_Predicates
(Typ
) then
774 if Is_Generic_Actual_Type
(Typ
) then
776 -- The restriction on loop parameters is only that the type
777 -- should have no dynamic predicates.
779 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
780 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
781 and then Is_OK_Static_Subtype
(Typ
)
786 Gen
:= Current_Scope
;
787 while not Is_Generic_Instance
(Gen
) loop
791 pragma Assert
(Present
(Gen
));
793 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
794 Error_Msg_Warn
:= SPARK_Mode
/= On
;
795 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
796 Error_Msg_F
("\Program_Error [<<", N
);
799 Make_Raise_Program_Error
(Sloc
(N
),
800 Reason
=> PE_Bad_Predicated_Generic_Type
));
803 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
807 Error_Msg_FE
(Msg
, N
, Typ
);
810 -- Emit an optional suggestion on how to remedy the error if the
811 -- context warrants it.
813 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
814 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
817 end Bad_Predicated_Subtype_Use
;
819 -----------------------------------------
820 -- Bad_Unordered_Enumeration_Reference --
821 -----------------------------------------
823 function Bad_Unordered_Enumeration_Reference
825 T
: Entity_Id
) return Boolean
828 return Is_Enumeration_Type
(T
)
829 and then Warn_On_Unordered_Enumeration_Type
830 and then not Is_Generic_Type
(T
)
831 and then Comes_From_Source
(N
)
832 and then not Has_Pragma_Ordered
(T
)
833 and then not In_Same_Extended_Unit
(N
, T
);
834 end Bad_Unordered_Enumeration_Reference
;
836 --------------------------
837 -- Build_Actual_Subtype --
838 --------------------------
840 function Build_Actual_Subtype
842 N
: Node_Or_Entity_Id
) return Node_Id
845 -- Normally Sloc (N), but may point to corresponding body in some cases
847 Constraints
: List_Id
;
853 Disc_Type
: Entity_Id
;
859 if Nkind
(N
) = N_Defining_Identifier
then
860 Obj
:= New_Occurrence_Of
(N
, Loc
);
862 -- If this is a formal parameter of a subprogram declaration, and
863 -- we are compiling the body, we want the declaration for the
864 -- actual subtype to carry the source position of the body, to
865 -- prevent anomalies in gdb when stepping through the code.
867 if Is_Formal
(N
) then
869 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
871 if Nkind
(Decl
) = N_Subprogram_Declaration
872 and then Present
(Corresponding_Body
(Decl
))
874 Loc
:= Sloc
(Corresponding_Body
(Decl
));
883 if Is_Array_Type
(T
) then
884 Constraints
:= New_List
;
885 for J
in 1 .. Number_Dimensions
(T
) loop
887 -- Build an array subtype declaration with the nominal subtype and
888 -- the bounds of the actual. Add the declaration in front of the
889 -- local declarations for the subprogram, for analysis before any
890 -- reference to the formal in the body.
893 Make_Attribute_Reference
(Loc
,
895 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
896 Attribute_Name
=> Name_First
,
897 Expressions
=> New_List
(
898 Make_Integer_Literal
(Loc
, J
)));
901 Make_Attribute_Reference
(Loc
,
903 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
904 Attribute_Name
=> Name_Last
,
905 Expressions
=> New_List
(
906 Make_Integer_Literal
(Loc
, J
)));
908 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
911 -- If the type has unknown discriminants there is no constrained
912 -- subtype to build. This is never called for a formal or for a
913 -- lhs, so returning the type is ok ???
915 elsif Has_Unknown_Discriminants
(T
) then
919 Constraints
:= New_List
;
921 -- Type T is a generic derived type, inherit the discriminants from
924 if Is_Private_Type
(T
)
925 and then No
(Full_View
(T
))
927 -- T was flagged as an error if it was declared as a formal
928 -- derived type with known discriminants. In this case there
929 -- is no need to look at the parent type since T already carries
930 -- its own discriminants.
932 and then not Error_Posted
(T
)
934 Disc_Type
:= Etype
(Base_Type
(T
));
939 Discr
:= First_Discriminant
(Disc_Type
);
940 while Present
(Discr
) loop
941 Append_To
(Constraints
,
942 Make_Selected_Component
(Loc
,
944 Duplicate_Subexpr_No_Checks
(Obj
),
945 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
946 Next_Discriminant
(Discr
);
950 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
951 Set_Is_Internal
(Subt
);
954 Make_Subtype_Declaration
(Loc
,
955 Defining_Identifier
=> Subt
,
956 Subtype_Indication
=>
957 Make_Subtype_Indication
(Loc
,
958 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
960 Make_Index_Or_Discriminant_Constraint
(Loc
,
961 Constraints
=> Constraints
)));
963 Mark_Rewrite_Insertion
(Decl
);
965 end Build_Actual_Subtype
;
967 ---------------------------------------
968 -- Build_Actual_Subtype_Of_Component --
969 ---------------------------------------
971 function Build_Actual_Subtype_Of_Component
973 N
: Node_Id
) return Node_Id
975 Loc
: constant Source_Ptr
:= Sloc
(N
);
976 P
: constant Node_Id
:= Prefix
(N
);
979 Index_Typ
: Entity_Id
;
981 Desig_Typ
: Entity_Id
;
982 -- This is either a copy of T, or if T is an access type, then it is
983 -- the directly designated type of this access type.
985 function Build_Actual_Array_Constraint
return List_Id
;
986 -- If one or more of the bounds of the component depends on
987 -- discriminants, build actual constraint using the discriminants
990 function Build_Actual_Record_Constraint
return List_Id
;
991 -- Similar to previous one, for discriminated components constrained
992 -- by the discriminant of the enclosing object.
994 -----------------------------------
995 -- Build_Actual_Array_Constraint --
996 -----------------------------------
998 function Build_Actual_Array_Constraint
return List_Id
is
999 Constraints
: constant List_Id
:= New_List
;
1007 Indx
:= First_Index
(Desig_Typ
);
1008 while Present
(Indx
) loop
1009 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1010 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1012 if Denotes_Discriminant
(Old_Lo
) then
1014 Make_Selected_Component
(Loc
,
1015 Prefix
=> New_Copy_Tree
(P
),
1016 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1019 Lo
:= New_Copy_Tree
(Old_Lo
);
1021 -- The new bound will be reanalyzed in the enclosing
1022 -- declaration. For literal bounds that come from a type
1023 -- declaration, the type of the context must be imposed, so
1024 -- insure that analysis will take place. For non-universal
1025 -- types this is not strictly necessary.
1027 Set_Analyzed
(Lo
, False);
1030 if Denotes_Discriminant
(Old_Hi
) then
1032 Make_Selected_Component
(Loc
,
1033 Prefix
=> New_Copy_Tree
(P
),
1034 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1037 Hi
:= New_Copy_Tree
(Old_Hi
);
1038 Set_Analyzed
(Hi
, False);
1041 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1046 end Build_Actual_Array_Constraint
;
1048 ------------------------------------
1049 -- Build_Actual_Record_Constraint --
1050 ------------------------------------
1052 function Build_Actual_Record_Constraint
return List_Id
is
1053 Constraints
: constant List_Id
:= New_List
;
1058 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1059 while Present
(D
) loop
1060 if Denotes_Discriminant
(Node
(D
)) then
1061 D_Val
:= Make_Selected_Component
(Loc
,
1062 Prefix
=> New_Copy_Tree
(P
),
1063 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1066 D_Val
:= New_Copy_Tree
(Node
(D
));
1069 Append
(D_Val
, Constraints
);
1074 end Build_Actual_Record_Constraint
;
1076 -- Start of processing for Build_Actual_Subtype_Of_Component
1079 -- Why the test for Spec_Expression mode here???
1081 if In_Spec_Expression
then
1084 -- More comments for the rest of this body would be good ???
1086 elsif Nkind
(N
) = N_Explicit_Dereference
then
1087 if Is_Composite_Type
(T
)
1088 and then not Is_Constrained
(T
)
1089 and then not (Is_Class_Wide_Type
(T
)
1090 and then Is_Constrained
(Root_Type
(T
)))
1091 and then not Has_Unknown_Discriminants
(T
)
1093 -- If the type of the dereference is already constrained, it is an
1096 if Is_Array_Type
(Etype
(N
))
1097 and then Is_Constrained
(Etype
(N
))
1101 Remove_Side_Effects
(P
);
1102 return Build_Actual_Subtype
(T
, N
);
1109 if Ekind
(T
) = E_Access_Subtype
then
1110 Desig_Typ
:= Designated_Type
(T
);
1115 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1116 Id
:= First_Index
(Desig_Typ
);
1117 while Present
(Id
) loop
1118 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1120 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1122 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1124 Remove_Side_Effects
(P
);
1126 Build_Component_Subtype
1127 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1133 elsif Is_Composite_Type
(Desig_Typ
)
1134 and then Has_Discriminants
(Desig_Typ
)
1135 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1137 if Is_Private_Type
(Desig_Typ
)
1138 and then No
(Discriminant_Constraint
(Desig_Typ
))
1140 Desig_Typ
:= Full_View
(Desig_Typ
);
1143 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1144 while Present
(D
) loop
1145 if Denotes_Discriminant
(Node
(D
)) then
1146 Remove_Side_Effects
(P
);
1148 Build_Component_Subtype
(
1149 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1156 -- If none of the above, the actual and nominal subtypes are the same
1159 end Build_Actual_Subtype_Of_Component
;
1161 -----------------------------
1162 -- Build_Component_Subtype --
1163 -----------------------------
1165 function Build_Component_Subtype
1168 T
: Entity_Id
) return Node_Id
1174 -- Unchecked_Union components do not require component subtypes
1176 if Is_Unchecked_Union
(T
) then
1180 Subt
:= Make_Temporary
(Loc
, 'S');
1181 Set_Is_Internal
(Subt
);
1184 Make_Subtype_Declaration
(Loc
,
1185 Defining_Identifier
=> Subt
,
1186 Subtype_Indication
=>
1187 Make_Subtype_Indication
(Loc
,
1188 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1190 Make_Index_Or_Discriminant_Constraint
(Loc
,
1191 Constraints
=> C
)));
1193 Mark_Rewrite_Insertion
(Decl
);
1195 end Build_Component_Subtype
;
1197 ----------------------------------
1198 -- Build_Default_Init_Cond_Call --
1199 ----------------------------------
1201 function Build_Default_Init_Cond_Call
1204 Typ
: Entity_Id
) return Node_Id
1206 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1207 Formal_Typ
: constant Entity_Id
:= Etype
(First_Formal
(Proc_Id
));
1211 Make_Procedure_Call_Statement
(Loc
,
1212 Name
=> New_Occurrence_Of
(Proc_Id
, Loc
),
1213 Parameter_Associations
=> New_List
(
1214 Make_Unchecked_Type_Conversion
(Loc
,
1215 Subtype_Mark
=> New_Occurrence_Of
(Formal_Typ
, Loc
),
1216 Expression
=> New_Occurrence_Of
(Obj_Id
, Loc
))));
1217 end Build_Default_Init_Cond_Call
;
1219 ----------------------------------------------
1220 -- Build_Default_Init_Cond_Procedure_Bodies --
1221 ----------------------------------------------
1223 procedure Build_Default_Init_Cond_Procedure_Bodies
(Priv_Decls
: List_Id
) is
1224 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
);
1225 -- If type Typ is subject to pragma Default_Initial_Condition, build the
1226 -- body of the procedure which verifies the assumption of the pragma at
1227 -- run time. The generated body is added after the type declaration.
1229 --------------------------------------------
1230 -- Build_Default_Init_Cond_Procedure_Body --
1231 --------------------------------------------
1233 procedure Build_Default_Init_Cond_Procedure_Body
(Typ
: Entity_Id
) is
1234 Param_Id
: Entity_Id
;
1235 -- The entity of the sole formal parameter of the default initial
1236 -- condition procedure.
1238 procedure Replace_Type_Reference
(N
: Node_Id
);
1239 -- Replace a single reference to type Typ with a reference to formal
1240 -- parameter Param_Id.
1242 ----------------------------
1243 -- Replace_Type_Reference --
1244 ----------------------------
1246 procedure Replace_Type_Reference
(N
: Node_Id
) is
1248 Rewrite
(N
, New_Occurrence_Of
(Param_Id
, Sloc
(N
)));
1249 end Replace_Type_Reference
;
1251 procedure Replace_Type_References
is
1252 new Replace_Type_References_Generic
(Replace_Type_Reference
);
1256 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1257 Prag
: constant Node_Id
:=
1258 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1259 Proc_Id
: constant Entity_Id
:= Default_Init_Cond_Procedure
(Typ
);
1260 Body_Decl
: Node_Id
;
1262 Spec_Decl
: Node_Id
;
1265 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1267 -- Start of processing for Build_Default_Init_Cond_Procedure_Body
1270 -- The procedure should be generated only for [sub]types subject to
1271 -- pragma Default_Initial_Condition. Types that inherit the pragma do
1272 -- not get this specialized procedure.
1274 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1275 pragma Assert
(Present
(Prag
));
1277 -- Nothing to do if the spec was not built. This occurs when the
1278 -- expression of the Default_Initial_Condition is missing or is
1281 if No
(Proc_Id
) then
1284 -- Nothing to do if the body was already built
1286 elsif Present
(Corresponding_Body
(Unit_Declaration_Node
(Proc_Id
)))
1291 -- The related type may be subject to pragma Ghost. Set the mode now
1292 -- to ensure that the analysis and expansion produce Ghost nodes.
1294 Set_Ghost_Mode_From_Entity
(Typ
);
1296 Param_Id
:= First_Formal
(Proc_Id
);
1298 -- The pragma has an argument. Note that the argument is analyzed
1299 -- after all references to the current instance of the type are
1302 if Present
(Pragma_Argument_Associations
(Prag
)) then
1304 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
1306 if Nkind
(Expr
) = N_Null
then
1307 Stmt
:= Make_Null_Statement
(Loc
);
1309 -- Preserve the original argument of the pragma by replicating it.
1310 -- Replace all references to the current instance of the type with
1311 -- references to the formal parameter.
1314 Expr
:= New_Copy_Tree
(Expr
);
1315 Replace_Type_References
(Expr
, Typ
);
1318 -- pragma Check (Default_Initial_Condition, <Expr>);
1322 Pragma_Identifier
=>
1323 Make_Identifier
(Loc
, Name_Check
),
1325 Pragma_Argument_Associations
=> New_List
(
1326 Make_Pragma_Argument_Association
(Loc
,
1328 Make_Identifier
(Loc
,
1329 Chars
=> Name_Default_Initial_Condition
)),
1330 Make_Pragma_Argument_Association
(Loc
,
1331 Expression
=> Expr
)));
1334 -- Otherwise the pragma appears without an argument
1337 Stmt
:= Make_Null_Statement
(Loc
);
1341 -- procedure <Typ>Default_Init_Cond (I : <Typ>) is
1344 -- end <Typ>Default_Init_Cond;
1346 Spec_Decl
:= Unit_Declaration_Node
(Proc_Id
);
1348 Make_Subprogram_Body
(Loc
,
1350 Copy_Separate_Tree
(Specification
(Spec_Decl
)),
1351 Declarations
=> Empty_List
,
1352 Handled_Statement_Sequence
=>
1353 Make_Handled_Sequence_Of_Statements
(Loc
,
1354 Statements
=> New_List
(Stmt
)));
1356 -- Link the spec and body of the default initial condition procedure
1357 -- to prevent the generation of a duplicate body.
1359 Set_Corresponding_Body
(Spec_Decl
, Defining_Entity
(Body_Decl
));
1360 Set_Corresponding_Spec
(Body_Decl
, Proc_Id
);
1362 Insert_After_And_Analyze
(Declaration_Node
(Typ
), Body_Decl
);
1363 Ghost_Mode
:= Save_Ghost_Mode
;
1364 end Build_Default_Init_Cond_Procedure_Body
;
1371 -- Start of processing for Build_Default_Init_Cond_Procedure_Bodies
1374 -- Inspect the private declarations looking for [sub]type declarations
1376 Decl
:= First
(Priv_Decls
);
1377 while Present
(Decl
) loop
1378 if Nkind_In
(Decl
, N_Full_Type_Declaration
,
1379 N_Subtype_Declaration
)
1381 Typ
:= Defining_Entity
(Decl
);
1383 -- Guard against partially decorate types due to previous errors
1385 if Is_Type
(Typ
) then
1387 -- If the type is subject to pragma Default_Initial_Condition,
1388 -- generate the body of the internal procedure which verifies
1389 -- the assertion of the pragma at run time.
1391 if Has_Default_Init_Cond
(Typ
) then
1392 Build_Default_Init_Cond_Procedure_Body
(Typ
);
1394 -- A derived type inherits the default initial condition
1395 -- procedure from its parent type.
1397 elsif Has_Inherited_Default_Init_Cond
(Typ
) then
1398 Inherit_Default_Init_Cond_Procedure
(Typ
);
1405 end Build_Default_Init_Cond_Procedure_Bodies
;
1407 ---------------------------------------------------
1408 -- Build_Default_Init_Cond_Procedure_Declaration --
1409 ---------------------------------------------------
1411 procedure Build_Default_Init_Cond_Procedure_Declaration
(Typ
: Entity_Id
) is
1412 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1413 Prag
: constant Node_Id
:=
1414 Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
1416 Save_Ghost_Mode
: constant Ghost_Mode_Type
:= Ghost_Mode
;
1419 Proc_Id
: Entity_Id
;
1422 -- The procedure should be generated only for types subject to pragma
1423 -- Default_Initial_Condition. Types that inherit the pragma do not get
1424 -- this specialized procedure.
1426 pragma Assert
(Has_Default_Init_Cond
(Typ
));
1427 pragma Assert
(Present
(Prag
));
1429 Args
:= Pragma_Argument_Associations
(Prag
);
1431 -- Nothing to do if default initial condition procedure already built
1433 if Present
(Default_Init_Cond_Procedure
(Typ
)) then
1436 -- Nothing to do if the default initial condition appears without an
1439 elsif No
(Args
) then
1442 -- Nothing to do if the expression of the default initial condition is
1445 elsif Nkind
(Get_Pragma_Arg
(First
(Args
))) = N_Null
then
1449 -- The related type may be subject to pragma Ghost. Set the mode now to
1450 -- ensure that the analysis and expansion produce Ghost nodes.
1452 Set_Ghost_Mode_From_Entity
(Typ
);
1455 Make_Defining_Identifier
(Loc
,
1456 Chars
=> New_External_Name
(Chars
(Typ
), "Default_Init_Cond"));
1458 -- Associate default initial condition procedure with the private type
1460 Set_Ekind
(Proc_Id
, E_Procedure
);
1461 Set_Is_Default_Init_Cond_Procedure
(Proc_Id
);
1462 Set_Default_Init_Cond_Procedure
(Typ
, Proc_Id
);
1464 -- Mark the default initial condition procedure explicitly as Ghost
1465 -- because it does not come from source.
1467 if Ghost_Mode
> None
then
1468 Set_Is_Ghost_Entity
(Proc_Id
);
1472 -- procedure <Typ>Default_Init_Cond (Inn : <Typ>);
1474 Insert_After_And_Analyze
(Prag
,
1475 Make_Subprogram_Declaration
(Loc
,
1477 Make_Procedure_Specification
(Loc
,
1478 Defining_Unit_Name
=> Proc_Id
,
1479 Parameter_Specifications
=> New_List
(
1480 Make_Parameter_Specification
(Loc
,
1481 Defining_Identifier
=> Make_Temporary
(Loc
, 'I'),
1482 Parameter_Type
=> New_Occurrence_Of
(Typ
, Loc
))))));
1484 Ghost_Mode
:= Save_Ghost_Mode
;
1485 end Build_Default_Init_Cond_Procedure_Declaration
;
1487 ---------------------------
1488 -- Build_Default_Subtype --
1489 ---------------------------
1491 function Build_Default_Subtype
1493 N
: Node_Id
) return Entity_Id
1495 Loc
: constant Source_Ptr
:= Sloc
(N
);
1499 -- The base type that is to be constrained by the defaults
1502 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1506 Bas
:= Base_Type
(T
);
1508 -- If T is non-private but its base type is private, this is the
1509 -- completion of a subtype declaration whose parent type is private
1510 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1511 -- are to be found in the full view of the base. Check that the private
1512 -- status of T and its base differ.
1514 if Is_Private_Type
(Bas
)
1515 and then not Is_Private_Type
(T
)
1516 and then Present
(Full_View
(Bas
))
1518 Bas
:= Full_View
(Bas
);
1521 Disc
:= First_Discriminant
(T
);
1523 if No
(Discriminant_Default_Value
(Disc
)) then
1528 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1529 Constraints
: constant List_Id
:= New_List
;
1533 while Present
(Disc
) loop
1534 Append_To
(Constraints
,
1535 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1536 Next_Discriminant
(Disc
);
1540 Make_Subtype_Declaration
(Loc
,
1541 Defining_Identifier
=> Act
,
1542 Subtype_Indication
=>
1543 Make_Subtype_Indication
(Loc
,
1544 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1546 Make_Index_Or_Discriminant_Constraint
(Loc
,
1547 Constraints
=> Constraints
)));
1549 Insert_Action
(N
, Decl
);
1551 -- If the context is a component declaration the subtype declaration
1552 -- will be analyzed when the enclosing type is frozen, otherwise do
1555 if Ekind
(Current_Scope
) /= E_Record_Type
then
1561 end Build_Default_Subtype
;
1563 --------------------------------------------
1564 -- Build_Discriminal_Subtype_Of_Component --
1565 --------------------------------------------
1567 function Build_Discriminal_Subtype_Of_Component
1568 (T
: Entity_Id
) return Node_Id
1570 Loc
: constant Source_Ptr
:= Sloc
(T
);
1574 function Build_Discriminal_Array_Constraint
return List_Id
;
1575 -- If one or more of the bounds of the component depends on
1576 -- discriminants, build actual constraint using the discriminants
1579 function Build_Discriminal_Record_Constraint
return List_Id
;
1580 -- Similar to previous one, for discriminated components constrained by
1581 -- the discriminant of the enclosing object.
1583 ----------------------------------------
1584 -- Build_Discriminal_Array_Constraint --
1585 ----------------------------------------
1587 function Build_Discriminal_Array_Constraint
return List_Id
is
1588 Constraints
: constant List_Id
:= New_List
;
1596 Indx
:= First_Index
(T
);
1597 while Present
(Indx
) loop
1598 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1599 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1601 if Denotes_Discriminant
(Old_Lo
) then
1602 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1605 Lo
:= New_Copy_Tree
(Old_Lo
);
1608 if Denotes_Discriminant
(Old_Hi
) then
1609 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1612 Hi
:= New_Copy_Tree
(Old_Hi
);
1615 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1620 end Build_Discriminal_Array_Constraint
;
1622 -----------------------------------------
1623 -- Build_Discriminal_Record_Constraint --
1624 -----------------------------------------
1626 function Build_Discriminal_Record_Constraint
return List_Id
is
1627 Constraints
: constant List_Id
:= New_List
;
1632 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1633 while Present
(D
) loop
1634 if Denotes_Discriminant
(Node
(D
)) then
1636 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1638 D_Val
:= New_Copy_Tree
(Node
(D
));
1641 Append
(D_Val
, Constraints
);
1646 end Build_Discriminal_Record_Constraint
;
1648 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1651 if Ekind
(T
) = E_Array_Subtype
then
1652 Id
:= First_Index
(T
);
1653 while Present
(Id
) loop
1654 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1656 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1658 return Build_Component_Subtype
1659 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1665 elsif Ekind
(T
) = E_Record_Subtype
1666 and then Has_Discriminants
(T
)
1667 and then not Has_Unknown_Discriminants
(T
)
1669 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1670 while Present
(D
) loop
1671 if Denotes_Discriminant
(Node
(D
)) then
1672 return Build_Component_Subtype
1673 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1680 -- If none of the above, the actual and nominal subtypes are the same
1683 end Build_Discriminal_Subtype_Of_Component
;
1685 ------------------------------
1686 -- Build_Elaboration_Entity --
1687 ------------------------------
1689 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1690 Loc
: constant Source_Ptr
:= Sloc
(N
);
1692 Elab_Ent
: Entity_Id
;
1694 procedure Set_Package_Name
(Ent
: Entity_Id
);
1695 -- Given an entity, sets the fully qualified name of the entity in
1696 -- Name_Buffer, with components separated by double underscores. This
1697 -- is a recursive routine that climbs the scope chain to Standard.
1699 ----------------------
1700 -- Set_Package_Name --
1701 ----------------------
1703 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1705 if Scope
(Ent
) /= Standard_Standard
then
1706 Set_Package_Name
(Scope
(Ent
));
1709 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1711 Name_Buffer
(Name_Len
+ 1) := '_';
1712 Name_Buffer
(Name_Len
+ 2) := '_';
1713 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1714 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1718 Get_Name_String
(Chars
(Ent
));
1720 end Set_Package_Name
;
1722 -- Start of processing for Build_Elaboration_Entity
1725 -- Ignore call if already constructed
1727 if Present
(Elaboration_Entity
(Spec_Id
)) then
1730 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1731 -- no role in analysis.
1733 elsif ASIS_Mode
then
1736 -- See if we need elaboration entity.
1738 -- We always need an elaboration entity when preserving control flow, as
1739 -- we want to remain explicit about the unit's elaboration order.
1741 elsif Opt
.Suppress_Control_Flow_Optimizations
then
1744 -- We always need an elaboration entity for the dynamic elaboration
1745 -- model, since it is needed to properly generate the PE exception for
1746 -- access before elaboration.
1748 elsif Dynamic_Elaboration_Checks
then
1751 -- For the static model, we don't need the elaboration counter if this
1752 -- unit is sure to have no elaboration code, since that means there
1753 -- is no elaboration unit to be called. Note that we can't just decide
1754 -- after the fact by looking to see whether there was elaboration code,
1755 -- because that's too late to make this decision.
1757 elsif Restriction_Active
(No_Elaboration_Code
) then
1760 -- Similarly, for the static model, we can skip the elaboration counter
1761 -- if we have the No_Multiple_Elaboration restriction, since for the
1762 -- static model, that's the only purpose of the counter (to avoid
1763 -- multiple elaboration).
1765 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1769 -- Here we need the elaboration entity
1771 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1772 -- name with dots replaced by double underscore. We have to manually
1773 -- construct this name, since it will be elaborated in the outer scope,
1774 -- and thus will not have the unit name automatically prepended.
1776 Set_Package_Name
(Spec_Id
);
1777 Add_Str_To_Name_Buffer
("_E");
1779 -- Create elaboration counter
1781 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1782 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1785 Make_Object_Declaration
(Loc
,
1786 Defining_Identifier
=> Elab_Ent
,
1787 Object_Definition
=>
1788 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1789 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1791 Push_Scope
(Standard_Standard
);
1792 Add_Global_Declaration
(Decl
);
1795 -- Reset True_Constant indication, since we will indeed assign a value
1796 -- to the variable in the binder main. We also kill the Current_Value
1797 -- and Last_Assignment fields for the same reason.
1799 Set_Is_True_Constant
(Elab_Ent
, False);
1800 Set_Current_Value
(Elab_Ent
, Empty
);
1801 Set_Last_Assignment
(Elab_Ent
, Empty
);
1803 -- We do not want any further qualification of the name (if we did not
1804 -- do this, we would pick up the name of the generic package in the case
1805 -- of a library level generic instantiation).
1807 Set_Has_Qualified_Name
(Elab_Ent
);
1808 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1809 end Build_Elaboration_Entity
;
1811 --------------------------------
1812 -- Build_Explicit_Dereference --
1813 --------------------------------
1815 procedure Build_Explicit_Dereference
1819 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1824 -- An entity of a type with a reference aspect is overloaded with
1825 -- both interpretations: with and without the dereference. Now that
1826 -- the dereference is made explicit, set the type of the node properly,
1827 -- to prevent anomalies in the backend. Same if the expression is an
1828 -- overloaded function call whose return type has a reference aspect.
1830 if Is_Entity_Name
(Expr
) then
1831 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1833 -- The designated entity will not be examined again when resolving
1834 -- the dereference, so generate a reference to it now.
1836 Generate_Reference
(Entity
(Expr
), Expr
);
1838 elsif Nkind
(Expr
) = N_Function_Call
then
1840 -- If the name of the indexing function is overloaded, locate the one
1841 -- whose return type has an implicit dereference on the desired
1842 -- discriminant, and set entity and type of function call.
1844 if Is_Overloaded
(Name
(Expr
)) then
1845 Get_First_Interp
(Name
(Expr
), I
, It
);
1847 while Present
(It
.Nam
) loop
1848 if Ekind
((It
.Typ
)) = E_Record_Type
1849 and then First_Entity
((It
.Typ
)) = Disc
1851 Set_Entity
(Name
(Expr
), It
.Nam
);
1852 Set_Etype
(Name
(Expr
), Etype
(It
.Nam
));
1856 Get_Next_Interp
(I
, It
);
1860 -- Set type of call from resolved function name.
1862 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1865 Set_Is_Overloaded
(Expr
, False);
1867 -- The expression will often be a generalized indexing that yields a
1868 -- container element that is then dereferenced, in which case the
1869 -- generalized indexing call is also non-overloaded.
1871 if Nkind
(Expr
) = N_Indexed_Component
1872 and then Present
(Generalized_Indexing
(Expr
))
1874 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1878 Make_Explicit_Dereference
(Loc
,
1880 Make_Selected_Component
(Loc
,
1881 Prefix
=> Relocate_Node
(Expr
),
1882 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1883 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1884 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1885 end Build_Explicit_Dereference
;
1887 -----------------------------------
1888 -- Cannot_Raise_Constraint_Error --
1889 -----------------------------------
1891 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1893 if Compile_Time_Known_Value
(Expr
) then
1896 elsif Do_Range_Check
(Expr
) then
1899 elsif Raises_Constraint_Error
(Expr
) then
1903 case Nkind
(Expr
) is
1904 when N_Identifier
=>
1907 when N_Expanded_Name
=>
1910 when N_Selected_Component
=>
1911 return not Do_Discriminant_Check
(Expr
);
1913 when N_Attribute_Reference
=>
1914 if Do_Overflow_Check
(Expr
) then
1917 elsif No
(Expressions
(Expr
)) then
1925 N
:= First
(Expressions
(Expr
));
1926 while Present
(N
) loop
1927 if Cannot_Raise_Constraint_Error
(N
) then
1938 when N_Type_Conversion
=>
1939 if Do_Overflow_Check
(Expr
)
1940 or else Do_Length_Check
(Expr
)
1941 or else Do_Tag_Check
(Expr
)
1945 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1948 when N_Unchecked_Type_Conversion
=>
1949 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1952 if Do_Overflow_Check
(Expr
) then
1955 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1962 if Do_Division_Check
(Expr
)
1964 Do_Overflow_Check
(Expr
)
1969 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1971 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1990 N_Op_Shift_Right_Arithmetic |
1994 if Do_Overflow_Check
(Expr
) then
1998 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
2000 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2007 end Cannot_Raise_Constraint_Error
;
2009 -----------------------------
2010 -- Check_Part_Of_Reference --
2011 -----------------------------
2013 procedure Check_Part_Of_Reference
(Var_Id
: Entity_Id
; Ref
: Node_Id
) is
2014 Conc_Typ
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
2016 OK_Use
: Boolean := False;
2019 Spec_Id
: Entity_Id
;
2022 -- Traverse the parent chain looking for a suitable context for the
2023 -- reference to the concurrent constituent.
2025 Par
:= Parent
(Ref
);
2026 while Present
(Par
) loop
2027 if Nkind
(Par
) = N_Pragma
then
2028 Prag_Nam
:= Pragma_Name
(Par
);
2030 -- A concurrent constituent is allowed to appear in pragmas
2031 -- Initial_Condition and Initializes as this is part of the
2032 -- elaboration checks for the constituent (SPARK RM 9.3).
2034 if Nam_In
(Prag_Nam
, Name_Initial_Condition
, Name_Initializes
) then
2038 -- When the reference appears within pragma Depends or Global,
2039 -- check whether the pragma applies to a single task type. Note
2040 -- that the pragma is not encapsulated by the type definition,
2041 -- but this is still a valid context.
2043 elsif Nam_In
(Prag_Nam
, Name_Depends
, Name_Global
) then
2044 Decl
:= Find_Related_Declaration_Or_Body
(Par
);
2046 if Nkind
(Decl
) = N_Object_Declaration
2047 and then Defining_Entity
(Decl
) = Conc_Typ
2054 -- The reference appears somewhere in the definition of the single
2055 -- protected/task type (SPARK RM 9.3).
2057 elsif Nkind_In
(Par
, N_Single_Protected_Declaration
,
2058 N_Single_Task_Declaration
)
2059 and then Defining_Entity
(Par
) = Conc_Typ
2064 -- The reference appears within the expanded declaration or the body
2065 -- of the single protected/task type (SPARK RM 9.3).
2067 elsif Nkind_In
(Par
, N_Protected_Body
,
2068 N_Protected_Type_Declaration
,
2070 N_Task_Type_Declaration
)
2072 Spec_Id
:= Unique_Defining_Entity
(Par
);
2074 if Present
(Anonymous_Object
(Spec_Id
))
2075 and then Anonymous_Object
(Spec_Id
) = Conc_Typ
2081 -- The reference has been relocated within an internally generated
2082 -- package or subprogram. Assume that the reference is legal as the
2083 -- real check was already performed in the original context of the
2086 elsif Nkind_In
(Par
, N_Package_Body
,
2087 N_Package_Declaration
,
2089 N_Subprogram_Declaration
)
2090 and then not Comes_From_Source
(Par
)
2095 -- The reference has been relocated to an inlined body for GNATprove.
2096 -- Assume that the reference is legal as the real check was already
2097 -- performed in the original context of the reference.
2099 elsif GNATprove_Mode
2100 and then Nkind
(Par
) = N_Subprogram_Body
2101 and then Chars
(Defining_Entity
(Par
)) = Name_uParent
2107 Par
:= Parent
(Par
);
2110 -- The reference is illegal as it appears outside the definition or
2111 -- body of the single protected/task type.
2115 ("reference to variable & cannot appear in this context",
2117 Error_Msg_Name_1
:= Chars
(Var_Id
);
2119 if Ekind
(Conc_Typ
) = E_Protected_Type
then
2121 ("\% is constituent of single protected type &", Ref
, Conc_Typ
);
2124 ("\% is constituent of single task type &", Ref
, Conc_Typ
);
2127 end Check_Part_Of_Reference
;
2129 -----------------------------------------
2130 -- Check_Dynamically_Tagged_Expression --
2131 -----------------------------------------
2133 procedure Check_Dynamically_Tagged_Expression
2136 Related_Nod
: Node_Id
)
2139 pragma Assert
(Is_Tagged_Type
(Typ
));
2141 -- In order to avoid spurious errors when analyzing the expanded code,
2142 -- this check is done only for nodes that come from source and for
2143 -- actuals of generic instantiations.
2145 if (Comes_From_Source
(Related_Nod
)
2146 or else In_Generic_Actual
(Expr
))
2147 and then (Is_Class_Wide_Type
(Etype
(Expr
))
2148 or else Is_Dynamically_Tagged
(Expr
))
2149 and then Is_Tagged_Type
(Typ
)
2150 and then not Is_Class_Wide_Type
(Typ
)
2152 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
2154 end Check_Dynamically_Tagged_Expression
;
2156 --------------------------
2157 -- Check_Fully_Declared --
2158 --------------------------
2160 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
2162 if Ekind
(T
) = E_Incomplete_Type
then
2164 -- Ada 2005 (AI-50217): If the type is available through a limited
2165 -- with_clause, verify that its full view has been analyzed.
2167 if From_Limited_With
(T
)
2168 and then Present
(Non_Limited_View
(T
))
2169 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2171 -- The non-limited view is fully declared
2177 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2180 -- Need comments for these tests ???
2182 elsif Has_Private_Component
(T
)
2183 and then not Is_Generic_Type
(Root_Type
(T
))
2184 and then not In_Spec_Expression
2186 -- Special case: if T is the anonymous type created for a single
2187 -- task or protected object, use the name of the source object.
2189 if Is_Concurrent_Type
(T
)
2190 and then not Comes_From_Source
(T
)
2191 and then Nkind
(N
) = N_Object_Declaration
2194 ("type of& has incomplete component",
2195 N
, Defining_Identifier
(N
));
2198 ("premature usage of incomplete}",
2199 N
, First_Subtype
(T
));
2202 end Check_Fully_Declared
;
2204 -------------------------------------------
2205 -- Check_Function_With_Address_Parameter --
2206 -------------------------------------------
2208 procedure Check_Function_With_Address_Parameter
(Subp_Id
: Entity_Id
) is
2213 F
:= First_Formal
(Subp_Id
);
2214 while Present
(F
) loop
2217 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
2221 if Is_Descendant_Of_Address
(T
) or else Is_Limited_Type
(T
) then
2222 Set_Is_Pure
(Subp_Id
, False);
2228 end Check_Function_With_Address_Parameter
;
2230 -------------------------------------
2231 -- Check_Function_Writable_Actuals --
2232 -------------------------------------
2234 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2235 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2236 Identifiers_List
: Elist_Id
:= No_Elist
;
2237 Aggr_Error_Node
: Node_Id
:= Empty
;
2238 Error_Node
: Node_Id
:= Empty
;
2240 procedure Collect_Identifiers
(N
: Node_Id
);
2241 -- In a single traversal of subtree N collect in Writable_Actuals_List
2242 -- all the actuals of functions with writable actuals, and in the list
2243 -- Identifiers_List collect all the identifiers that are not actuals of
2244 -- functions with writable actuals. If a writable actual is referenced
2245 -- twice as writable actual then Error_Node is set to reference its
2246 -- second occurrence, the error is reported, and the tree traversal
2249 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
;
2250 -- Return the entity associated with the function call
2252 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2253 -- Preanalyze N without reporting errors. Very dubious, you can't just
2254 -- go analyzing things more than once???
2256 -------------------------
2257 -- Collect_Identifiers --
2258 -------------------------
2260 procedure Collect_Identifiers
(N
: Node_Id
) is
2262 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2263 -- Process a single node during the tree traversal to collect the
2264 -- writable actuals of functions and all the identifiers which are
2265 -- not writable actuals of functions.
2267 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2268 -- Returns True if List has a node whose Entity is Entity (N)
2270 -------------------------
2271 -- Check_Function_Call --
2272 -------------------------
2274 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2275 Is_Writable_Actual
: Boolean := False;
2279 if Nkind
(N
) = N_Identifier
then
2281 -- No analysis possible if the entity is not decorated
2283 if No
(Entity
(N
)) then
2286 -- Don't collect identifiers of packages, called functions, etc
2288 elsif Ekind_In
(Entity
(N
), E_Package
,
2295 -- For rewritten nodes, continue the traversal in the original
2296 -- subtree. Needed to handle aggregates in original expressions
2297 -- extracted from the tree by Remove_Side_Effects.
2299 elsif Is_Rewrite_Substitution
(N
) then
2300 Collect_Identifiers
(Original_Node
(N
));
2303 -- For now we skip aggregate discriminants, since they require
2304 -- performing the analysis in two phases to identify conflicts:
2305 -- first one analyzing discriminants and second one analyzing
2306 -- the rest of components (since at run time, discriminants are
2307 -- evaluated prior to components): too much computation cost
2308 -- to identify a corner case???
2310 elsif Nkind
(Parent
(N
)) = N_Component_Association
2311 and then Nkind_In
(Parent
(Parent
(N
)),
2313 N_Extension_Aggregate
)
2316 Choice
: constant Node_Id
:= First
(Choices
(Parent
(N
)));
2319 if Ekind
(Entity
(N
)) = E_Discriminant
then
2322 elsif Expression
(Parent
(N
)) = N
2323 and then Nkind
(Choice
) = N_Identifier
2324 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2330 -- Analyze if N is a writable actual of a function
2332 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2334 Call
: constant Node_Id
:= Parent
(N
);
2339 Id
:= Get_Function_Id
(Call
);
2341 -- In case of previous error, no check is possible
2347 if Ekind_In
(Id
, E_Function
, E_Generic_Function
)
2348 and then Has_Out_Or_In_Out_Parameter
(Id
)
2350 Formal
:= First_Formal
(Id
);
2351 Actual
:= First_Actual
(Call
);
2352 while Present
(Actual
) and then Present
(Formal
) loop
2354 if Ekind_In
(Formal
, E_Out_Parameter
,
2357 Is_Writable_Actual
:= True;
2363 Next_Formal
(Formal
);
2364 Next_Actual
(Actual
);
2370 if Is_Writable_Actual
then
2372 -- Skip checking the error in non-elementary types since
2373 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2374 -- store this actual in Writable_Actuals_List since it is
2375 -- needed to perform checks on other constructs that have
2376 -- arbitrary order of evaluation (for example, aggregates).
2378 if not Is_Elementary_Type
(Etype
(N
)) then
2379 if not Contains
(Writable_Actuals_List
, N
) then
2380 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2383 -- Second occurrence of an elementary type writable actual
2385 elsif Contains
(Writable_Actuals_List
, N
) then
2387 -- Report the error on the second occurrence of the
2388 -- identifier. We cannot assume that N is the second
2389 -- occurrence (according to their location in the
2390 -- sources), since Traverse_Func walks through Field2
2391 -- last (see comment in the body of Traverse_Func).
2397 Elmt
:= First_Elmt
(Writable_Actuals_List
);
2398 while Present
(Elmt
)
2399 and then Entity
(Node
(Elmt
)) /= Entity
(N
)
2404 if Sloc
(N
) > Sloc
(Node
(Elmt
)) then
2407 Error_Node
:= Node
(Elmt
);
2411 ("value may be affected by call to & "
2412 & "because order of evaluation is arbitrary",
2417 -- First occurrence of a elementary type writable actual
2420 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2424 if Identifiers_List
= No_Elist
then
2425 Identifiers_List
:= New_Elmt_List
;
2428 Append_Unique_Elmt
(N
, Identifiers_List
);
2441 N
: Node_Id
) return Boolean
2443 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2448 if List
= No_Elist
then
2452 Elmt
:= First_Elmt
(List
);
2453 while Present
(Elmt
) loop
2454 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2468 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2469 -- The traversal procedure
2471 -- Start of processing for Collect_Identifiers
2474 if Present
(Error_Node
) then
2478 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2483 end Collect_Identifiers
;
2485 ---------------------
2486 -- Get_Function_Id --
2487 ---------------------
2489 function Get_Function_Id
(Call
: Node_Id
) return Entity_Id
is
2490 Nam
: constant Node_Id
:= Name
(Call
);
2494 if Nkind
(Nam
) = N_Explicit_Dereference
then
2496 pragma Assert
(Ekind
(Id
) = E_Subprogram_Type
);
2498 elsif Nkind
(Nam
) = N_Selected_Component
then
2499 Id
:= Entity
(Selector_Name
(Nam
));
2501 elsif Nkind
(Nam
) = N_Indexed_Component
then
2502 Id
:= Entity
(Selector_Name
(Prefix
(Nam
)));
2509 end Get_Function_Id
;
2511 -------------------------------
2512 -- Preanalyze_Without_Errors --
2513 -------------------------------
2515 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2516 Status
: constant Boolean := Get_Ignore_Errors
;
2518 Set_Ignore_Errors
(True);
2520 Set_Ignore_Errors
(Status
);
2521 end Preanalyze_Without_Errors
;
2523 -- Start of processing for Check_Function_Writable_Actuals
2526 -- The check only applies to Ada 2012 code on which Check_Actuals has
2527 -- been set, and only to constructs that have multiple constituents
2528 -- whose order of evaluation is not specified by the language.
2530 if Ada_Version
< Ada_2012
2531 or else not Check_Actuals
(N
)
2532 or else (not (Nkind
(N
) in N_Op
)
2533 and then not (Nkind
(N
) in N_Membership_Test
)
2534 and then not Nkind_In
(N
, N_Range
,
2536 N_Extension_Aggregate
,
2537 N_Full_Type_Declaration
,
2539 N_Procedure_Call_Statement
,
2540 N_Entry_Call_Statement
))
2541 or else (Nkind
(N
) = N_Full_Type_Declaration
2542 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2544 -- In addition, this check only applies to source code, not to code
2545 -- generated by constraint checks.
2547 or else not Comes_From_Source
(N
)
2552 -- If a construct C has two or more direct constituents that are names
2553 -- or expressions whose evaluation may occur in an arbitrary order, at
2554 -- least one of which contains a function call with an in out or out
2555 -- parameter, then the construct is legal only if: for each name N that
2556 -- is passed as a parameter of mode in out or out to some inner function
2557 -- call C2 (not including the construct C itself), there is no other
2558 -- name anywhere within a direct constituent of the construct C other
2559 -- than the one containing C2, that is known to refer to the same
2560 -- object (RM 6.4.1(6.17/3)).
2564 Collect_Identifiers
(Low_Bound
(N
));
2565 Collect_Identifiers
(High_Bound
(N
));
2567 when N_Op | N_Membership_Test
=>
2572 Collect_Identifiers
(Left_Opnd
(N
));
2574 if Present
(Right_Opnd
(N
)) then
2575 Collect_Identifiers
(Right_Opnd
(N
));
2578 if Nkind_In
(N
, N_In
, N_Not_In
)
2579 and then Present
(Alternatives
(N
))
2581 Expr
:= First
(Alternatives
(N
));
2582 while Present
(Expr
) loop
2583 Collect_Identifiers
(Expr
);
2590 when N_Full_Type_Declaration
=>
2592 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2593 -- Return the record part of this record type definition
2595 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2596 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2598 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2599 return Record_Extension_Part
(Type_Def
);
2603 end Get_Record_Part
;
2606 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2607 Rec
: Node_Id
:= Get_Record_Part
(N
);
2610 -- No need to perform any analysis if the record has no
2613 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2617 -- Collect the identifiers starting from the deepest
2618 -- derivation. Done to report the error in the deepest
2622 if Present
(Component_List
(Rec
)) then
2623 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2624 while Present
(Comp
) loop
2625 if Nkind
(Comp
) = N_Component_Declaration
2626 and then Present
(Expression
(Comp
))
2628 Collect_Identifiers
(Expression
(Comp
));
2635 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2636 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2639 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2640 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2644 when N_Subprogram_Call |
2645 N_Entry_Call_Statement
=>
2647 Id
: constant Entity_Id
:= Get_Function_Id
(N
);
2652 Formal
:= First_Formal
(Id
);
2653 Actual
:= First_Actual
(N
);
2654 while Present
(Actual
) and then Present
(Formal
) loop
2655 if Ekind_In
(Formal
, E_Out_Parameter
,
2658 Collect_Identifiers
(Actual
);
2661 Next_Formal
(Formal
);
2662 Next_Actual
(Actual
);
2667 N_Extension_Aggregate
=>
2671 Comp_Expr
: Node_Id
;
2674 -- Handle the N_Others_Choice of array aggregates with static
2675 -- bounds. There is no need to perform this analysis in
2676 -- aggregates without static bounds since we cannot evaluate
2677 -- if the N_Others_Choice covers several elements. There is
2678 -- no need to handle the N_Others choice of record aggregates
2679 -- since at this stage it has been already expanded by
2680 -- Resolve_Record_Aggregate.
2682 if Is_Array_Type
(Etype
(N
))
2683 and then Nkind
(N
) = N_Aggregate
2684 and then Present
(Aggregate_Bounds
(N
))
2685 and then Compile_Time_Known_Bounds
(Etype
(N
))
2686 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2688 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2691 Count_Components
: Uint
:= Uint_0
;
2692 Num_Components
: Uint
;
2693 Others_Assoc
: Node_Id
;
2694 Others_Choice
: Node_Id
:= Empty
;
2695 Others_Box_Present
: Boolean := False;
2698 -- Count positional associations
2700 if Present
(Expressions
(N
)) then
2701 Comp_Expr
:= First
(Expressions
(N
));
2702 while Present
(Comp_Expr
) loop
2703 Count_Components
:= Count_Components
+ 1;
2708 -- Count the rest of elements and locate the N_Others
2711 Assoc
:= First
(Component_Associations
(N
));
2712 while Present
(Assoc
) loop
2713 Choice
:= First
(Choices
(Assoc
));
2714 while Present
(Choice
) loop
2715 if Nkind
(Choice
) = N_Others_Choice
then
2716 Others_Assoc
:= Assoc
;
2717 Others_Choice
:= Choice
;
2718 Others_Box_Present
:= Box_Present
(Assoc
);
2720 -- Count several components
2722 elsif Nkind_In
(Choice
, N_Range
,
2723 N_Subtype_Indication
)
2724 or else (Is_Entity_Name
(Choice
)
2725 and then Is_Type
(Entity
(Choice
)))
2730 Get_Index_Bounds
(Choice
, L
, H
);
2732 (Compile_Time_Known_Value
(L
)
2733 and then Compile_Time_Known_Value
(H
));
2736 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2739 -- Count single component. No other case available
2740 -- since we are handling an aggregate with static
2744 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2745 or else Nkind
(Choice
) = N_Identifier
2746 or else Nkind
(Choice
) = N_Integer_Literal
);
2748 Count_Components
:= Count_Components
+ 1;
2758 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2759 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2761 pragma Assert
(Count_Components
<= Num_Components
);
2763 -- Handle the N_Others choice if it covers several
2766 if Present
(Others_Choice
)
2767 and then (Num_Components
- Count_Components
) > 1
2769 if not Others_Box_Present
then
2771 -- At this stage, if expansion is active, the
2772 -- expression of the others choice has not been
2773 -- analyzed. Hence we generate a duplicate and
2774 -- we analyze it silently to have available the
2775 -- minimum decoration required to collect the
2778 if not Expander_Active
then
2779 Comp_Expr
:= Expression
(Others_Assoc
);
2782 New_Copy_Tree
(Expression
(Others_Assoc
));
2783 Preanalyze_Without_Errors
(Comp_Expr
);
2786 Collect_Identifiers
(Comp_Expr
);
2788 if Writable_Actuals_List
/= No_Elist
then
2790 -- As suggested by Robert, at current stage we
2791 -- report occurrences of this case as warnings.
2794 ("writable function parameter may affect "
2795 & "value in other component because order "
2796 & "of evaluation is unspecified??",
2797 Node
(First_Elmt
(Writable_Actuals_List
)));
2803 -- For an array aggregate, a discrete_choice_list that has
2804 -- a nonstatic range is considered as two or more separate
2805 -- occurrences of the expression (RM 6.4.1(20/3)).
2807 elsif Is_Array_Type
(Etype
(N
))
2808 and then Nkind
(N
) = N_Aggregate
2809 and then Present
(Aggregate_Bounds
(N
))
2810 and then not Compile_Time_Known_Bounds
(Etype
(N
))
2812 -- Collect identifiers found in the dynamic bounds
2815 Count_Components
: Natural := 0;
2816 Low
, High
: Node_Id
;
2819 Assoc
:= First
(Component_Associations
(N
));
2820 while Present
(Assoc
) loop
2821 Choice
:= First
(Choices
(Assoc
));
2822 while Present
(Choice
) loop
2823 if Nkind_In
(Choice
, N_Range
,
2824 N_Subtype_Indication
)
2825 or else (Is_Entity_Name
(Choice
)
2826 and then Is_Type
(Entity
(Choice
)))
2828 Get_Index_Bounds
(Choice
, Low
, High
);
2830 if not Compile_Time_Known_Value
(Low
) then
2831 Collect_Identifiers
(Low
);
2833 if No
(Aggr_Error_Node
) then
2834 Aggr_Error_Node
:= Low
;
2838 if not Compile_Time_Known_Value
(High
) then
2839 Collect_Identifiers
(High
);
2841 if No
(Aggr_Error_Node
) then
2842 Aggr_Error_Node
:= High
;
2846 -- The RM rule is violated if there is more than
2847 -- a single choice in a component association.
2850 Count_Components
:= Count_Components
+ 1;
2852 if No
(Aggr_Error_Node
)
2853 and then Count_Components
> 1
2855 Aggr_Error_Node
:= Choice
;
2858 if not Compile_Time_Known_Value
(Choice
) then
2859 Collect_Identifiers
(Choice
);
2871 -- Handle ancestor part of extension aggregates
2873 if Nkind
(N
) = N_Extension_Aggregate
then
2874 Collect_Identifiers
(Ancestor_Part
(N
));
2877 -- Handle positional associations
2879 if Present
(Expressions
(N
)) then
2880 Comp_Expr
:= First
(Expressions
(N
));
2881 while Present
(Comp_Expr
) loop
2882 if not Is_OK_Static_Expression
(Comp_Expr
) then
2883 Collect_Identifiers
(Comp_Expr
);
2890 -- Handle discrete associations
2892 if Present
(Component_Associations
(N
)) then
2893 Assoc
:= First
(Component_Associations
(N
));
2894 while Present
(Assoc
) loop
2896 if not Box_Present
(Assoc
) then
2897 Choice
:= First
(Choices
(Assoc
));
2898 while Present
(Choice
) loop
2900 -- For now we skip discriminants since it requires
2901 -- performing the analysis in two phases: first one
2902 -- analyzing discriminants and second one analyzing
2903 -- the rest of components since discriminants are
2904 -- evaluated prior to components: too much extra
2905 -- work to detect a corner case???
2907 if Nkind
(Choice
) in N_Has_Entity
2908 and then Present
(Entity
(Choice
))
2909 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2913 elsif Box_Present
(Assoc
) then
2917 if not Analyzed
(Expression
(Assoc
)) then
2919 New_Copy_Tree
(Expression
(Assoc
));
2920 Set_Parent
(Comp_Expr
, Parent
(N
));
2921 Preanalyze_Without_Errors
(Comp_Expr
);
2923 Comp_Expr
:= Expression
(Assoc
);
2926 Collect_Identifiers
(Comp_Expr
);
2942 -- No further action needed if we already reported an error
2944 if Present
(Error_Node
) then
2948 -- Check violation of RM 6.20/3 in aggregates
2950 if Present
(Aggr_Error_Node
)
2951 and then Writable_Actuals_List
/= No_Elist
2954 ("value may be affected by call in other component because they "
2955 & "are evaluated in unspecified order",
2956 Node
(First_Elmt
(Writable_Actuals_List
)));
2960 -- Check if some writable argument of a function is referenced
2962 if Writable_Actuals_List
/= No_Elist
2963 and then Identifiers_List
/= No_Elist
2970 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2971 while Present
(Elmt_1
) loop
2972 Elmt_2
:= First_Elmt
(Identifiers_List
);
2973 while Present
(Elmt_2
) loop
2974 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2975 case Nkind
(Parent
(Node
(Elmt_2
))) is
2977 N_Component_Association |
2978 N_Component_Declaration
=>
2980 ("value may be affected by call in other "
2981 & "component because they are evaluated "
2982 & "in unspecified order",
2985 when N_In | N_Not_In
=>
2987 ("value may be affected by call in other "
2988 & "alternative because they are evaluated "
2989 & "in unspecified order",
2994 ("value of actual may be affected by call in "
2995 & "other actual because they are evaluated "
2996 & "in unspecified order",
3008 end Check_Function_Writable_Actuals
;
3010 --------------------------------
3011 -- Check_Implicit_Dereference --
3012 --------------------------------
3014 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
3020 if Nkind
(N
) = N_Indexed_Component
3021 and then Present
(Generalized_Indexing
(N
))
3023 Nam
:= Generalized_Indexing
(N
);
3028 if Ada_Version
< Ada_2012
3029 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
3033 elsif not Comes_From_Source
(N
)
3034 and then Nkind
(N
) /= N_Indexed_Component
3038 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
3042 Disc
:= First_Discriminant
(Typ
);
3043 while Present
(Disc
) loop
3044 if Has_Implicit_Dereference
(Disc
) then
3045 Desig
:= Designated_Type
(Etype
(Disc
));
3046 Add_One_Interp
(Nam
, Disc
, Desig
);
3048 -- If the node is a generalized indexing, add interpretation
3049 -- to that node as well, for subsequent resolution.
3051 if Nkind
(N
) = N_Indexed_Component
then
3052 Add_One_Interp
(N
, Disc
, Desig
);
3055 -- If the operation comes from a generic unit and the context
3056 -- is a selected component, the selector name may be global
3057 -- and set in the instance already. Remove the entity to
3058 -- force resolution of the selected component, and the
3059 -- generation of an explicit dereference if needed.
3062 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
3064 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
3070 Next_Discriminant
(Disc
);
3073 end Check_Implicit_Dereference
;
3075 ----------------------------------
3076 -- Check_Internal_Protected_Use --
3077 ----------------------------------
3079 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
3085 while Present
(S
) loop
3086 if S
= Standard_Standard
then
3089 elsif Ekind
(S
) = E_Function
3090 and then Ekind
(Scope
(S
)) = E_Protected_Type
3099 if Scope
(Nam
) = Prot
and then Ekind
(Nam
) /= E_Function
then
3101 -- An indirect function call (e.g. a callback within a protected
3102 -- function body) is not statically illegal. If the access type is
3103 -- anonymous and is the type of an access parameter, the scope of Nam
3104 -- will be the protected type, but it is not a protected operation.
3106 if Ekind
(Nam
) = E_Subprogram_Type
3108 Nkind
(Associated_Node_For_Itype
(Nam
)) = N_Function_Specification
3112 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
3114 ("within protected function cannot use protected "
3115 & "procedure in renaming or as generic actual", N
);
3117 elsif Nkind
(N
) = N_Attribute_Reference
then
3119 ("within protected function cannot take access of "
3120 & " protected procedure", N
);
3124 ("within protected function, protected object is constant", N
);
3126 ("\cannot call operation that may modify it", N
);
3129 end Check_Internal_Protected_Use
;
3131 ---------------------------------------
3132 -- Check_Later_Vs_Basic_Declarations --
3133 ---------------------------------------
3135 procedure Check_Later_Vs_Basic_Declarations
3137 During_Parsing
: Boolean)
3139 Body_Sloc
: Source_Ptr
;
3142 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
3143 -- Return whether Decl is considered as a declarative item.
3144 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3145 -- When During_Parsing is False, the semantics of SPARK is followed.
3147 -------------------------------
3148 -- Is_Later_Declarative_Item --
3149 -------------------------------
3151 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
3153 if Nkind
(Decl
) in N_Later_Decl_Item
then
3156 elsif Nkind
(Decl
) = N_Pragma
then
3159 elsif During_Parsing
then
3162 -- In SPARK, a package declaration is not considered as a later
3163 -- declarative item.
3165 elsif Nkind
(Decl
) = N_Package_Declaration
then
3168 -- In SPARK, a renaming is considered as a later declarative item
3170 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
3176 end Is_Later_Declarative_Item
;
3178 -- Start of processing for Check_Later_Vs_Basic_Declarations
3181 Decl
:= First
(Decls
);
3183 -- Loop through sequence of basic declarative items
3185 Outer
: while Present
(Decl
) loop
3186 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
3187 and then Nkind
(Decl
) not in N_Body_Stub
3191 -- Once a body is encountered, we only allow later declarative
3192 -- items. The inner loop checks the rest of the list.
3195 Body_Sloc
:= Sloc
(Decl
);
3197 Inner
: while Present
(Decl
) loop
3198 if not Is_Later_Declarative_Item
(Decl
) then
3199 if During_Parsing
then
3200 if Ada_Version
= Ada_83
then
3201 Error_Msg_Sloc
:= Body_Sloc
;
3203 ("(Ada 83) decl cannot appear after body#", Decl
);
3206 Error_Msg_Sloc
:= Body_Sloc
;
3207 Check_SPARK_05_Restriction
3208 ("decl cannot appear after body#", Decl
);
3216 end Check_Later_Vs_Basic_Declarations
;
3218 ---------------------------
3219 -- Check_No_Hidden_State --
3220 ---------------------------
3222 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
3223 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
3224 -- Determine whether the entity of a package denoted by Pkg has a null
3227 -----------------------------
3228 -- Has_Null_Abstract_State --
3229 -----------------------------
3231 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
3232 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
3235 -- Check first available state of related package. A null abstract
3236 -- state always appears as the sole element of the state list.
3240 and then Is_Null_State
(Node
(First_Elmt
(States
)));
3241 end Has_Null_Abstract_State
;
3245 Context
: Entity_Id
:= Empty
;
3246 Not_Visible
: Boolean := False;
3249 -- Start of processing for Check_No_Hidden_State
3252 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
3254 -- Find the proper context where the object or state appears
3257 while Present
(Scop
) loop
3260 -- Keep track of the context's visibility
3262 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
3264 -- Prevent the search from going too far
3266 if Context
= Standard_Standard
then
3269 -- Objects and states that appear immediately within a subprogram or
3270 -- inside a construct nested within a subprogram do not introduce a
3271 -- hidden state. They behave as local variable declarations.
3273 elsif Is_Subprogram
(Context
) then
3276 -- When examining a package body, use the entity of the spec as it
3277 -- carries the abstract state declarations.
3279 elsif Ekind
(Context
) = E_Package_Body
then
3280 Context
:= Spec_Entity
(Context
);
3283 -- Stop the traversal when a package subject to a null abstract state
3286 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
3287 and then Has_Null_Abstract_State
(Context
)
3292 Scop
:= Scope
(Scop
);
3295 -- At this point we know that there is at least one package with a null
3296 -- abstract state in visibility. Emit an error message unconditionally
3297 -- if the entity being processed is a state because the placement of the
3298 -- related package is irrelevant. This is not the case for objects as
3299 -- the intermediate context matters.
3301 if Present
(Context
)
3302 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
3304 Error_Msg_N
("cannot introduce hidden state &", Id
);
3305 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
3307 end Check_No_Hidden_State
;
3309 ----------------------------------------
3310 -- Check_Nonvolatile_Function_Profile --
3311 ----------------------------------------
3313 procedure Check_Nonvolatile_Function_Profile
(Func_Id
: Entity_Id
) is
3317 -- Inspect all formal parameters
3319 Formal
:= First_Formal
(Func_Id
);
3320 while Present
(Formal
) loop
3321 if Is_Effectively_Volatile
(Etype
(Formal
)) then
3323 ("nonvolatile function & cannot have a volatile parameter",
3327 Next_Formal
(Formal
);
3330 -- Inspect the return type
3332 if Is_Effectively_Volatile
(Etype
(Func_Id
)) then
3334 ("nonvolatile function & cannot have a volatile return type",
3335 Result_Definition
(Parent
(Func_Id
)), Func_Id
);
3337 end Check_Nonvolatile_Function_Profile
;
3339 ------------------------------------------
3340 -- Check_Potentially_Blocking_Operation --
3341 ------------------------------------------
3343 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
3347 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3348 -- When pragma Detect_Blocking is active, the run time will raise
3349 -- Program_Error. Here we only issue a warning, since we generally
3350 -- support the use of potentially blocking operations in the absence
3353 -- Indirect blocking through a subprogram call cannot be diagnosed
3354 -- statically without interprocedural analysis, so we do not attempt
3357 S
:= Scope
(Current_Scope
);
3358 while Present
(S
) and then S
/= Standard_Standard
loop
3359 if Is_Protected_Type
(S
) then
3361 ("potentially blocking operation in protected operation??", N
);
3367 end Check_Potentially_Blocking_Operation
;
3369 ---------------------------------
3370 -- Check_Result_And_Post_State --
3371 ---------------------------------
3373 procedure Check_Result_And_Post_State
(Subp_Id
: Entity_Id
) is
3374 procedure Check_Result_And_Post_State_In_Pragma
3376 Result_Seen
: in out Boolean);
3377 -- Determine whether pragma Prag mentions attribute 'Result and whether
3378 -- the pragma contains an expression that evaluates differently in pre-
3379 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3380 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3382 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean;
3383 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3384 -- formal parameter.
3386 -------------------------------------------
3387 -- Check_Result_And_Post_State_In_Pragma --
3388 -------------------------------------------
3390 procedure Check_Result_And_Post_State_In_Pragma
3392 Result_Seen
: in out Boolean)
3394 procedure Check_Expression
(Expr
: Node_Id
);
3395 -- Perform the 'Result and post-state checks on a given expression
3397 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
3398 -- Attempt to find attribute 'Result in a subtree denoted by N
3400 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
3401 -- Determine whether source node N denotes "True" or "False"
3403 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
3404 -- Determine whether a subtree denoted by N mentions any construct
3405 -- that denotes a post-state.
3407 procedure Check_Function_Result
is
3408 new Traverse_Proc
(Is_Function_Result
);
3410 ----------------------
3411 -- Check_Expression --
3412 ----------------------
3414 procedure Check_Expression
(Expr
: Node_Id
) is
3416 if not Is_Trivial_Boolean
(Expr
) then
3417 Check_Function_Result
(Expr
);
3419 if not Mentions_Post_State
(Expr
) then
3420 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3422 ("contract case does not check the outcome of calling "
3423 & "&?T?", Expr
, Subp_Id
);
3425 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3427 ("refined postcondition does not check the outcome of "
3428 & "calling &?T?", Prag
, Subp_Id
);
3432 ("postcondition does not check the outcome of calling "
3433 & "&?T?", Prag
, Subp_Id
);
3437 end Check_Expression
;
3439 ------------------------
3440 -- Is_Function_Result --
3441 ------------------------
3443 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3445 if Is_Attribute_Result
(N
) then
3446 Result_Seen
:= True;
3449 -- Continue the traversal
3454 end Is_Function_Result
;
3456 ------------------------
3457 -- Is_Trivial_Boolean --
3458 ------------------------
3460 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3463 Comes_From_Source
(N
)
3464 and then Is_Entity_Name
(N
)
3465 and then (Entity
(N
) = Standard_True
3467 Entity
(N
) = Standard_False
);
3468 end Is_Trivial_Boolean
;
3470 -------------------------
3471 -- Mentions_Post_State --
3472 -------------------------
3474 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3475 Post_State_Seen
: Boolean := False;
3477 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3478 -- Attempt to find a construct that denotes a post-state. If this
3479 -- is the case, set flag Post_State_Seen.
3485 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3489 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3490 Post_State_Seen
:= True;
3493 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3496 -- The entity may be modifiable through an implicit
3500 or else Ekind
(Ent
) in Assignable_Kind
3501 or else (Is_Access_Type
(Etype
(Ent
))
3502 and then Nkind
(Parent
(N
)) =
3503 N_Selected_Component
)
3505 Post_State_Seen
:= True;
3509 elsif Nkind
(N
) = N_Attribute_Reference
then
3510 if Attribute_Name
(N
) = Name_Old
then
3513 elsif Attribute_Name
(N
) = Name_Result
then
3514 Post_State_Seen
:= True;
3522 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3524 -- Start of processing for Mentions_Post_State
3527 Find_Post_State
(N
);
3529 return Post_State_Seen
;
3530 end Mentions_Post_State
;
3534 Expr
: constant Node_Id
:=
3536 (First
(Pragma_Argument_Associations
(Prag
)));
3537 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3540 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3543 -- Examine all consequences
3545 if Nam
= Name_Contract_Cases
then
3546 CCase
:= First
(Component_Associations
(Expr
));
3547 while Present
(CCase
) loop
3548 Check_Expression
(Expression
(CCase
));
3553 -- Examine the expression of a postcondition
3555 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
,
3556 Name_Refined_Post
));
3557 Check_Expression
(Expr
);
3559 end Check_Result_And_Post_State_In_Pragma
;
3561 --------------------------
3562 -- Has_In_Out_Parameter --
3563 --------------------------
3565 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean is
3569 -- Traverse the formals looking for an IN OUT parameter
3571 Formal
:= First_Formal
(Subp_Id
);
3572 while Present
(Formal
) loop
3573 if Ekind
(Formal
) = E_In_Out_Parameter
then
3577 Next_Formal
(Formal
);
3581 end Has_In_Out_Parameter
;
3585 Items
: constant Node_Id
:= Contract
(Subp_Id
);
3586 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
3587 Case_Prag
: Node_Id
:= Empty
;
3588 Post_Prag
: Node_Id
:= Empty
;
3590 Seen_In_Case
: Boolean := False;
3591 Seen_In_Post
: Boolean := False;
3592 Spec_Id
: Entity_Id
;
3594 -- Start of processing for Check_Result_And_Post_State
3597 -- The lack of attribute 'Result or a post-state is classified as a
3598 -- suspicious contract. Do not perform the check if the corresponding
3599 -- swich is not set.
3601 if not Warn_On_Suspicious_Contract
then
3604 -- Nothing to do if there is no contract
3606 elsif No
(Items
) then
3610 -- Retrieve the entity of the subprogram spec (if any)
3612 if Nkind
(Subp_Decl
) = N_Subprogram_Body
3613 and then Present
(Corresponding_Spec
(Subp_Decl
))
3615 Spec_Id
:= Corresponding_Spec
(Subp_Decl
);
3617 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
3618 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
3620 Spec_Id
:= Corresponding_Spec_Of_Stub
(Subp_Decl
);
3626 -- Examine all postconditions for attribute 'Result and a post-state
3628 Prag
:= Pre_Post_Conditions
(Items
);
3629 while Present
(Prag
) loop
3630 if Nam_In
(Pragma_Name
(Prag
), Name_Postcondition
,
3632 and then not Error_Posted
(Prag
)
3635 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Post
);
3638 Prag
:= Next_Pragma
(Prag
);
3641 -- Examine the contract cases of the subprogram for attribute 'Result
3642 -- and a post-state.
3644 Prag
:= Contract_Test_Cases
(Items
);
3645 while Present
(Prag
) loop
3646 if Pragma_Name
(Prag
) = Name_Contract_Cases
3647 and then not Error_Posted
(Prag
)
3650 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Case
);
3653 Prag
:= Next_Pragma
(Prag
);
3656 -- Do not emit any errors if the subprogram is not a function
3658 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
3661 -- Regardless of whether the function has postconditions or contract
3662 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3663 -- parameter is always treated as a result.
3665 elsif Has_In_Out_Parameter
(Spec_Id
) then
3668 -- The function has both a postcondition and contract cases and they do
3669 -- not mention attribute 'Result.
3671 elsif Present
(Case_Prag
)
3672 and then not Seen_In_Case
3673 and then Present
(Post_Prag
)
3674 and then not Seen_In_Post
3677 ("neither postcondition nor contract cases mention function "
3678 & "result?T?", Post_Prag
);
3680 -- The function has contract cases only and they do not mention
3681 -- attribute 'Result.
3683 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
3684 Error_Msg_N
("contract cases do not mention result?T?", Case_Prag
);
3686 -- The function has postconditions only and they do not mention
3687 -- attribute 'Result.
3689 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
3691 ("postcondition does not mention function result?T?", Post_Prag
);
3693 end Check_Result_And_Post_State
;
3695 -----------------------------
3696 -- Check_State_Refinements --
3697 -----------------------------
3699 procedure Check_State_Refinements
3701 Is_Main_Unit
: Boolean := False)
3703 procedure Check_Package
(Pack
: Node_Id
);
3704 -- Verify that all abstract states of a [generic] package denoted by its
3705 -- declarative node Pack have proper refinement. Recursively verify the
3706 -- visible and private declarations of the [generic] package for other
3709 procedure Check_Packages_In
(Decls
: List_Id
);
3710 -- Seek out [generic] package declarations within declarative list Decls
3711 -- and verify the status of their abstract state refinement.
3713 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean;
3714 -- Determine whether construct N is subject to pragma SPARK_Mode Off
3720 procedure Check_Package
(Pack
: Node_Id
) is
3721 Body_Id
: constant Entity_Id
:= Corresponding_Body
(Pack
);
3722 Spec
: constant Node_Id
:= Specification
(Pack
);
3723 States
: constant Elist_Id
:=
3724 Abstract_States
(Defining_Entity
(Pack
));
3726 State_Elmt
: Elmt_Id
;
3727 State_Id
: Entity_Id
;
3730 -- Do not verify proper state refinement when the package is subject
3731 -- to pragma SPARK_Mode Off because this disables the requirement for
3732 -- state refinement.
3734 if SPARK_Mode_Is_Off
(Pack
) then
3737 -- State refinement can only occur in a completing packge body. Do
3738 -- not verify proper state refinement when the body is subject to
3739 -- pragma SPARK_Mode Off because this disables the requirement for
3740 -- state refinement.
3742 elsif Present
(Body_Id
)
3743 and then SPARK_Mode_Is_Off
(Unit_Declaration_Node
(Body_Id
))
3747 -- Do not verify proper state refinement when the package is an
3748 -- instance as this check was already performed in the generic.
3750 elsif Present
(Generic_Parent
(Spec
)) then
3753 -- Otherwise examine the contents of the package
3756 if Present
(States
) then
3757 State_Elmt
:= First_Elmt
(States
);
3758 while Present
(State_Elmt
) loop
3759 State_Id
:= Node
(State_Elmt
);
3761 -- Emit an error when a non-null state lacks any form of
3764 if not Is_Null_State
(State_Id
)
3765 and then not Has_Null_Refinement
(State_Id
)
3766 and then not Has_Non_Null_Refinement
(State_Id
)
3768 Error_Msg_N
("state & requires refinement", State_Id
);
3771 Next_Elmt
(State_Elmt
);
3775 Check_Packages_In
(Visible_Declarations
(Spec
));
3776 Check_Packages_In
(Private_Declarations
(Spec
));
3780 -----------------------
3781 -- Check_Packages_In --
3782 -----------------------
3784 procedure Check_Packages_In
(Decls
: List_Id
) is
3788 if Present
(Decls
) then
3789 Decl
:= First
(Decls
);
3790 while Present
(Decl
) loop
3791 if Nkind_In
(Decl
, N_Generic_Package_Declaration
,
3792 N_Package_Declaration
)
3794 Check_Package
(Decl
);
3800 end Check_Packages_In
;
3802 -----------------------
3803 -- SPARK_Mode_Is_Off --
3804 -----------------------
3806 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean is
3807 Prag
: constant Node_Id
:= SPARK_Pragma
(Defining_Entity
(N
));
3811 Present
(Prag
) and then Get_SPARK_Mode_From_Annotation
(Prag
) = Off
;
3812 end SPARK_Mode_Is_Off
;
3814 -- Start of processing for Check_State_Refinements
3817 -- A block may declare a nested package
3819 if Nkind
(Context
) = N_Block_Statement
then
3820 Check_Packages_In
(Declarations
(Context
));
3822 -- An entry, protected, subprogram, or task body may declare a nested
3825 elsif Nkind_In
(Context
, N_Entry_Body
,
3830 -- Do not verify proper state refinement when the body is subject to
3831 -- pragma SPARK_Mode Off because this disables the requirement for
3832 -- state refinement.
3834 if not SPARK_Mode_Is_Off
(Context
) then
3835 Check_Packages_In
(Declarations
(Context
));
3838 -- A package body may declare a nested package
3840 elsif Nkind
(Context
) = N_Package_Body
then
3841 Check_Package
(Unit_Declaration_Node
(Corresponding_Spec
(Context
)));
3843 -- Do not verify proper state refinement when the body is subject to
3844 -- pragma SPARK_Mode Off because this disables the requirement for
3845 -- state refinement.
3847 if not SPARK_Mode_Is_Off
(Context
) then
3848 Check_Packages_In
(Declarations
(Context
));
3851 -- A library level [generic] package may declare a nested package
3853 elsif Nkind_In
(Context
, N_Generic_Package_Declaration
,
3854 N_Package_Declaration
)
3855 and then Is_Main_Unit
3857 Check_Package
(Context
);
3859 end Check_State_Refinements
;
3861 ------------------------------
3862 -- Check_Unprotected_Access --
3863 ------------------------------
3865 procedure Check_Unprotected_Access
3869 Cont_Encl_Typ
: Entity_Id
;
3870 Pref_Encl_Typ
: Entity_Id
;
3872 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
3873 -- Check whether Obj is a private component of a protected object.
3874 -- Return the protected type where the component resides, Empty
3877 function Is_Public_Operation
return Boolean;
3878 -- Verify that the enclosing operation is callable from outside the
3879 -- protected object, to minimize false positives.
3881 ------------------------------
3882 -- Enclosing_Protected_Type --
3883 ------------------------------
3885 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
3887 if Is_Entity_Name
(Obj
) then
3889 Ent
: Entity_Id
:= Entity
(Obj
);
3892 -- The object can be a renaming of a private component, use
3893 -- the original record component.
3895 if Is_Prival
(Ent
) then
3896 Ent
:= Prival_Link
(Ent
);
3899 if Is_Protected_Type
(Scope
(Ent
)) then
3905 -- For indexed and selected components, recursively check the prefix
3907 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
3908 return Enclosing_Protected_Type
(Prefix
(Obj
));
3910 -- The object does not denote a protected component
3915 end Enclosing_Protected_Type
;
3917 -------------------------
3918 -- Is_Public_Operation --
3919 -------------------------
3921 function Is_Public_Operation
return Boolean is
3927 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
3928 if Scope
(S
) = Pref_Encl_Typ
then
3929 E
:= First_Entity
(Pref_Encl_Typ
);
3931 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
3945 end Is_Public_Operation
;
3947 -- Start of processing for Check_Unprotected_Access
3950 if Nkind
(Expr
) = N_Attribute_Reference
3951 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
3953 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
3954 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
3956 -- Check whether we are trying to export a protected component to a
3957 -- context with an equal or lower access level.
3959 if Present
(Pref_Encl_Typ
)
3960 and then No
(Cont_Encl_Typ
)
3961 and then Is_Public_Operation
3962 and then Scope_Depth
(Pref_Encl_Typ
) >=
3963 Object_Access_Level
(Context
)
3966 ("??possible unprotected access to protected data", Expr
);
3969 end Check_Unprotected_Access
;
3971 ------------------------------
3972 -- Check_Unused_Body_States --
3973 ------------------------------
3975 procedure Check_Unused_Body_States
(Body_Id
: Entity_Id
) is
3976 procedure Process_Refinement_Clause
3979 -- Inspect all constituents of refinement clause Clause and remove any
3980 -- matches from body state list States.
3982 procedure Report_Unused_Body_States
(States
: Elist_Id
);
3983 -- Emit errors for each abstract state or object found in list States
3985 -------------------------------
3986 -- Process_Refinement_Clause --
3987 -------------------------------
3989 procedure Process_Refinement_Clause
3993 procedure Process_Constituent
(Constit
: Node_Id
);
3994 -- Remove constituent Constit from body state list States
3996 -------------------------
3997 -- Process_Constituent --
3998 -------------------------
4000 procedure Process_Constituent
(Constit
: Node_Id
) is
4001 Constit_Id
: Entity_Id
;
4004 -- Guard against illegal constituents. Only abstract states and
4005 -- objects can appear on the right hand side of a refinement.
4007 if Is_Entity_Name
(Constit
) then
4008 Constit_Id
:= Entity_Of
(Constit
);
4010 if Present
(Constit_Id
)
4011 and then Ekind_In
(Constit_Id
, E_Abstract_State
,
4015 Remove
(States
, Constit_Id
);
4018 end Process_Constituent
;
4024 -- Start of processing for Process_Refinement_Clause
4027 if Nkind
(Clause
) = N_Component_Association
then
4028 Constit
:= Expression
(Clause
);
4030 -- Multiple constituents appear as an aggregate
4032 if Nkind
(Constit
) = N_Aggregate
then
4033 Constit
:= First
(Expressions
(Constit
));
4034 while Present
(Constit
) loop
4035 Process_Constituent
(Constit
);
4039 -- Various forms of a single constituent
4042 Process_Constituent
(Constit
);
4045 end Process_Refinement_Clause
;
4047 -------------------------------
4048 -- Report_Unused_Body_States --
4049 -------------------------------
4051 procedure Report_Unused_Body_States
(States
: Elist_Id
) is
4052 Posted
: Boolean := False;
4053 State_Elmt
: Elmt_Id
;
4054 State_Id
: Entity_Id
;
4057 if Present
(States
) then
4058 State_Elmt
:= First_Elmt
(States
);
4059 while Present
(State_Elmt
) loop
4060 State_Id
:= Node
(State_Elmt
);
4062 -- Constants are part of the hidden state of a package, but the
4063 -- compiler cannot determine whether they have variable input
4064 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4065 -- hidden state. Do not emit an error when a constant does not
4066 -- participate in a state refinement, even though it acts as a
4069 if Ekind
(State_Id
) = E_Constant
then
4072 -- Generate an error message of the form:
4074 -- body of package ... has unused hidden states
4075 -- abstract state ... defined at ...
4076 -- variable ... defined at ...
4082 ("body of package & has unused hidden states", Body_Id
);
4085 Error_Msg_Sloc
:= Sloc
(State_Id
);
4087 if Ekind
(State_Id
) = E_Abstract_State
then
4089 ("\abstract state & defined #", Body_Id
, State_Id
);
4092 SPARK_Msg_NE
("\variable & defined #", Body_Id
, State_Id
);
4096 Next_Elmt
(State_Elmt
);
4099 end Report_Unused_Body_States
;
4103 Prag
: constant Node_Id
:= Get_Pragma
(Body_Id
, Pragma_Refined_State
);
4104 Spec_Id
: constant Entity_Id
:= Spec_Entity
(Body_Id
);
4108 -- Start of processing for Check_Unused_Body_States
4111 -- Inspect the clauses of pragma Refined_State and determine whether all
4112 -- visible states declared within the package body participate in the
4115 if Present
(Prag
) then
4116 Clause
:= Expression
(Get_Argument
(Prag
, Spec_Id
));
4117 States
:= Collect_Body_States
(Body_Id
);
4119 -- Multiple non-null state refinements appear as an aggregate
4121 if Nkind
(Clause
) = N_Aggregate
then
4122 Clause
:= First
(Component_Associations
(Clause
));
4123 while Present
(Clause
) loop
4124 Process_Refinement_Clause
(Clause
, States
);
4128 -- Various forms of a single state refinement
4131 Process_Refinement_Clause
(Clause
, States
);
4134 -- Ensure that all abstract states and objects declared in the
4135 -- package body state space are utilized as constituents.
4137 Report_Unused_Body_States
(States
);
4139 end Check_Unused_Body_States
;
4141 -------------------------
4142 -- Collect_Body_States --
4143 -------------------------
4145 function Collect_Body_States
(Body_Id
: Entity_Id
) return Elist_Id
is
4146 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean;
4147 -- Determine whether object Obj_Id is a suitable visible state of a
4150 procedure Collect_Visible_States
4151 (Pack_Id
: Entity_Id
;
4152 States
: in out Elist_Id
);
4153 -- Gather the entities of all abstract states and objects declared in
4154 -- the visible state space of package Pack_Id.
4156 ----------------------------
4157 -- Collect_Visible_States --
4158 ----------------------------
4160 procedure Collect_Visible_States
4161 (Pack_Id
: Entity_Id
;
4162 States
: in out Elist_Id
)
4164 Item_Id
: Entity_Id
;
4167 -- Traverse the entity chain of the package and inspect all visible
4170 Item_Id
:= First_Entity
(Pack_Id
);
4171 while Present
(Item_Id
) and then not In_Private_Part
(Item_Id
) loop
4173 -- Do not consider internally generated items as those cannot be
4174 -- named and participate in refinement.
4176 if not Comes_From_Source
(Item_Id
) then
4179 elsif Ekind
(Item_Id
) = E_Abstract_State
then
4180 Append_New_Elmt
(Item_Id
, States
);
4182 elsif Ekind_In
(Item_Id
, E_Constant
, E_Variable
)
4183 and then Is_Visible_Object
(Item_Id
)
4185 Append_New_Elmt
(Item_Id
, States
);
4187 -- Recursively gather the visible states of a nested package
4189 elsif Ekind
(Item_Id
) = E_Package
then
4190 Collect_Visible_States
(Item_Id
, States
);
4193 Next_Entity
(Item_Id
);
4195 end Collect_Visible_States
;
4197 -----------------------
4198 -- Is_Visible_Object --
4199 -----------------------
4201 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean is
4203 -- Objects that map generic formals to their actuals are not visible
4204 -- from outside the generic instantiation.
4206 if Present
(Corresponding_Generic_Association
4207 (Declaration_Node
(Obj_Id
)))
4211 -- Constituents of a single protected/task type act as components of
4212 -- the type and are not visible from outside the type.
4214 elsif Ekind
(Obj_Id
) = E_Variable
4215 and then Present
(Encapsulating_State
(Obj_Id
))
4216 and then Is_Single_Concurrent_Object
(Encapsulating_State
(Obj_Id
))
4223 end Is_Visible_Object
;
4227 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Body_Id
);
4229 Item_Id
: Entity_Id
;
4230 States
: Elist_Id
:= No_Elist
;
4232 -- Start of processing for Collect_Body_States
4235 -- Inspect the declarations of the body looking for source objects,
4236 -- packages and package instantiations. Note that even though this
4237 -- processing is very similar to Collect_Visible_States, a package
4238 -- body does not have a First/Next_Entity list.
4240 Decl
:= First
(Declarations
(Body_Decl
));
4241 while Present
(Decl
) loop
4243 -- Capture source objects as internally generated temporaries cannot
4244 -- be named and participate in refinement.
4246 if Nkind
(Decl
) = N_Object_Declaration
then
4247 Item_Id
:= Defining_Entity
(Decl
);
4249 if Comes_From_Source
(Item_Id
)
4250 and then Is_Visible_Object
(Item_Id
)
4252 Append_New_Elmt
(Item_Id
, States
);
4255 -- Capture the visible abstract states and objects of a source
4256 -- package [instantiation].
4258 elsif Nkind
(Decl
) = N_Package_Declaration
then
4259 Item_Id
:= Defining_Entity
(Decl
);
4261 if Comes_From_Source
(Item_Id
) then
4262 Collect_Visible_States
(Item_Id
, States
);
4270 end Collect_Body_States
;
4272 ------------------------
4273 -- Collect_Interfaces --
4274 ------------------------
4276 procedure Collect_Interfaces
4278 Ifaces_List
: out Elist_Id
;
4279 Exclude_Parents
: Boolean := False;
4280 Use_Full_View
: Boolean := True)
4282 procedure Collect
(Typ
: Entity_Id
);
4283 -- Subsidiary subprogram used to traverse the whole list
4284 -- of directly and indirectly implemented interfaces
4290 procedure Collect
(Typ
: Entity_Id
) is
4291 Ancestor
: Entity_Id
;
4299 -- Handle private types and subtypes
4302 and then Is_Private_Type
(Typ
)
4303 and then Present
(Full_View
(Typ
))
4305 Full_T
:= Full_View
(Typ
);
4307 if Ekind
(Full_T
) = E_Record_Subtype
then
4308 Full_T
:= Etype
(Typ
);
4310 if Present
(Full_View
(Full_T
)) then
4311 Full_T
:= Full_View
(Full_T
);
4316 -- Include the ancestor if we are generating the whole list of
4317 -- abstract interfaces.
4319 if Etype
(Full_T
) /= Typ
4321 -- Protect the frontend against wrong sources. For example:
4324 -- type A is tagged null record;
4325 -- type B is new A with private;
4326 -- type C is new A with private;
4328 -- type B is new C with null record;
4329 -- type C is new B with null record;
4332 and then Etype
(Full_T
) /= T
4334 Ancestor
:= Etype
(Full_T
);
4337 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
4338 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
4342 -- Traverse the graph of ancestor interfaces
4344 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
4345 Id
:= First
(Abstract_Interface_List
(Full_T
));
4346 while Present
(Id
) loop
4347 Iface
:= Etype
(Id
);
4349 -- Protect against wrong uses. For example:
4350 -- type I is interface;
4351 -- type O is tagged null record;
4352 -- type Wrong is new I and O with null record; -- ERROR
4354 if Is_Interface
(Iface
) then
4356 and then Etype
(T
) /= T
4357 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
4362 Append_Unique_Elmt
(Iface
, Ifaces_List
);
4371 -- Start of processing for Collect_Interfaces
4374 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
4375 Ifaces_List
:= New_Elmt_List
;
4377 end Collect_Interfaces
;
4379 ----------------------------------
4380 -- Collect_Interface_Components --
4381 ----------------------------------
4383 procedure Collect_Interface_Components
4384 (Tagged_Type
: Entity_Id
;
4385 Components_List
: out Elist_Id
)
4387 procedure Collect
(Typ
: Entity_Id
);
4388 -- Subsidiary subprogram used to climb to the parents
4394 procedure Collect
(Typ
: Entity_Id
) is
4395 Tag_Comp
: Entity_Id
;
4396 Parent_Typ
: Entity_Id
;
4399 -- Handle private types
4401 if Present
(Full_View
(Etype
(Typ
))) then
4402 Parent_Typ
:= Full_View
(Etype
(Typ
));
4404 Parent_Typ
:= Etype
(Typ
);
4407 if Parent_Typ
/= Typ
4409 -- Protect the frontend against wrong sources. For example:
4412 -- type A is tagged null record;
4413 -- type B is new A with private;
4414 -- type C is new A with private;
4416 -- type B is new C with null record;
4417 -- type C is new B with null record;
4420 and then Parent_Typ
/= Tagged_Type
4422 Collect
(Parent_Typ
);
4425 -- Collect the components containing tags of secondary dispatch
4428 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
4429 while Present
(Tag_Comp
) loop
4430 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
4431 Append_Elmt
(Tag_Comp
, Components_List
);
4433 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
4437 -- Start of processing for Collect_Interface_Components
4440 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
4441 and then Is_Tagged_Type
(Tagged_Type
));
4443 Components_List
:= New_Elmt_List
;
4444 Collect
(Tagged_Type
);
4445 end Collect_Interface_Components
;
4447 -----------------------------
4448 -- Collect_Interfaces_Info --
4449 -----------------------------
4451 procedure Collect_Interfaces_Info
4453 Ifaces_List
: out Elist_Id
;
4454 Components_List
: out Elist_Id
;
4455 Tags_List
: out Elist_Id
)
4457 Comps_List
: Elist_Id
;
4458 Comp_Elmt
: Elmt_Id
;
4459 Comp_Iface
: Entity_Id
;
4460 Iface_Elmt
: Elmt_Id
;
4463 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
4464 -- Search for the secondary tag associated with the interface type
4465 -- Iface that is implemented by T.
4471 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
4474 if not Is_CPP_Class
(T
) then
4475 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
4477 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
4481 and then Is_Tag
(Node
(ADT
))
4482 and then Related_Type
(Node
(ADT
)) /= Iface
4484 -- Skip secondary dispatch table referencing thunks to user
4485 -- defined primitives covered by this interface.
4487 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
4490 -- Skip secondary dispatch tables of Ada types
4492 if not Is_CPP_Class
(T
) then
4494 -- Skip secondary dispatch table referencing thunks to
4495 -- predefined primitives.
4497 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
4500 -- Skip secondary dispatch table referencing user-defined
4501 -- primitives covered by this interface.
4503 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
4506 -- Skip secondary dispatch table referencing predefined
4509 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
4514 pragma Assert
(Is_Tag
(Node
(ADT
)));
4518 -- Start of processing for Collect_Interfaces_Info
4521 Collect_Interfaces
(T
, Ifaces_List
);
4522 Collect_Interface_Components
(T
, Comps_List
);
4524 -- Search for the record component and tag associated with each
4525 -- interface type of T.
4527 Components_List
:= New_Elmt_List
;
4528 Tags_List
:= New_Elmt_List
;
4530 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
4531 while Present
(Iface_Elmt
) loop
4532 Iface
:= Node
(Iface_Elmt
);
4534 -- Associate the primary tag component and the primary dispatch table
4535 -- with all the interfaces that are parents of T
4537 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
4538 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
4539 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
4541 -- Otherwise search for the tag component and secondary dispatch
4545 Comp_Elmt
:= First_Elmt
(Comps_List
);
4546 while Present
(Comp_Elmt
) loop
4547 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
4549 if Comp_Iface
= Iface
4550 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
4552 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
4553 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
4557 Next_Elmt
(Comp_Elmt
);
4559 pragma Assert
(Present
(Comp_Elmt
));
4562 Next_Elmt
(Iface_Elmt
);
4564 end Collect_Interfaces_Info
;
4566 ---------------------
4567 -- Collect_Parents --
4568 ---------------------
4570 procedure Collect_Parents
4572 List
: out Elist_Id
;
4573 Use_Full_View
: Boolean := True)
4575 Current_Typ
: Entity_Id
:= T
;
4576 Parent_Typ
: Entity_Id
;
4579 List
:= New_Elmt_List
;
4581 -- No action if the if the type has no parents
4583 if T
= Etype
(T
) then
4588 Parent_Typ
:= Etype
(Current_Typ
);
4590 if Is_Private_Type
(Parent_Typ
)
4591 and then Present
(Full_View
(Parent_Typ
))
4592 and then Use_Full_View
4594 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4597 Append_Elmt
(Parent_Typ
, List
);
4599 exit when Parent_Typ
= Current_Typ
;
4600 Current_Typ
:= Parent_Typ
;
4602 end Collect_Parents
;
4604 ----------------------------------
4605 -- Collect_Primitive_Operations --
4606 ----------------------------------
4608 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
4609 B_Type
: constant Entity_Id
:= Base_Type
(T
);
4610 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
4611 B_Scope
: Entity_Id
:= Scope
(B_Type
);
4615 Is_Type_In_Pkg
: Boolean;
4616 Formal_Derived
: Boolean := False;
4619 function Match
(E
: Entity_Id
) return Boolean;
4620 -- True if E's base type is B_Type, or E is of an anonymous access type
4621 -- and the base type of its designated type is B_Type.
4627 function Match
(E
: Entity_Id
) return Boolean is
4628 Etyp
: Entity_Id
:= Etype
(E
);
4631 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
4632 Etyp
:= Designated_Type
(Etyp
);
4635 -- In Ada 2012 a primitive operation may have a formal of an
4636 -- incomplete view of the parent type.
4638 return Base_Type
(Etyp
) = B_Type
4640 (Ada_Version
>= Ada_2012
4641 and then Ekind
(Etyp
) = E_Incomplete_Type
4642 and then Full_View
(Etyp
) = B_Type
);
4645 -- Start of processing for Collect_Primitive_Operations
4648 -- For tagged types, the primitive operations are collected as they
4649 -- are declared, and held in an explicit list which is simply returned.
4651 if Is_Tagged_Type
(B_Type
) then
4652 return Primitive_Operations
(B_Type
);
4654 -- An untagged generic type that is a derived type inherits the
4655 -- primitive operations of its parent type. Other formal types only
4656 -- have predefined operators, which are not explicitly represented.
4658 elsif Is_Generic_Type
(B_Type
) then
4659 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
4660 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
4661 N_Formal_Derived_Type_Definition
4663 Formal_Derived
:= True;
4665 return New_Elmt_List
;
4669 Op_List
:= New_Elmt_List
;
4671 if B_Scope
= Standard_Standard
then
4672 if B_Type
= Standard_String
then
4673 Append_Elmt
(Standard_Op_Concat
, Op_List
);
4675 elsif B_Type
= Standard_Wide_String
then
4676 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
4682 -- Locate the primitive subprograms of the type
4685 -- The primitive operations appear after the base type, except
4686 -- if the derivation happens within the private part of B_Scope
4687 -- and the type is a private type, in which case both the type
4688 -- and some primitive operations may appear before the base
4689 -- type, and the list of candidates starts after the type.
4691 if In_Open_Scopes
(B_Scope
)
4692 and then Scope
(T
) = B_Scope
4693 and then In_Private_Part
(B_Scope
)
4695 Id
:= Next_Entity
(T
);
4697 -- In Ada 2012, If the type has an incomplete partial view, there
4698 -- may be primitive operations declared before the full view, so
4699 -- we need to start scanning from the incomplete view, which is
4700 -- earlier on the entity chain.
4702 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
4703 and then Present
(Incomplete_View
(Parent
(B_Type
)))
4705 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
4707 -- If T is a derived from a type with an incomplete view declared
4708 -- elsewhere, that incomplete view is irrelevant, we want the
4709 -- operations in the scope of T.
4711 if Scope
(Id
) /= Scope
(B_Type
) then
4712 Id
:= Next_Entity
(B_Type
);
4716 Id
:= Next_Entity
(B_Type
);
4719 -- Set flag if this is a type in a package spec
4722 Is_Package_Or_Generic_Package
(B_Scope
)
4724 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
4727 while Present
(Id
) loop
4729 -- Test whether the result type or any of the parameter types of
4730 -- each subprogram following the type match that type when the
4731 -- type is declared in a package spec, is a derived type, or the
4732 -- subprogram is marked as primitive. (The Is_Primitive test is
4733 -- needed to find primitives of nonderived types in declarative
4734 -- parts that happen to override the predefined "=" operator.)
4736 -- Note that generic formal subprograms are not considered to be
4737 -- primitive operations and thus are never inherited.
4739 if Is_Overloadable
(Id
)
4740 and then (Is_Type_In_Pkg
4741 or else Is_Derived_Type
(B_Type
)
4742 or else Is_Primitive
(Id
))
4743 and then Nkind
(Parent
(Parent
(Id
)))
4744 not in N_Formal_Subprogram_Declaration
4752 Formal
:= First_Formal
(Id
);
4753 while Present
(Formal
) loop
4754 if Match
(Formal
) then
4759 Next_Formal
(Formal
);
4763 -- For a formal derived type, the only primitives are the ones
4764 -- inherited from the parent type. Operations appearing in the
4765 -- package declaration are not primitive for it.
4768 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
4770 -- In the special case of an equality operator aliased to
4771 -- an overriding dispatching equality belonging to the same
4772 -- type, we don't include it in the list of primitives.
4773 -- This avoids inheriting multiple equality operators when
4774 -- deriving from untagged private types whose full type is
4775 -- tagged, which can otherwise cause ambiguities. Note that
4776 -- this should only happen for this kind of untagged parent
4777 -- type, since normally dispatching operations are inherited
4778 -- using the type's Primitive_Operations list.
4780 if Chars
(Id
) = Name_Op_Eq
4781 and then Is_Dispatching_Operation
(Id
)
4782 and then Present
(Alias
(Id
))
4783 and then Present
(Overridden_Operation
(Alias
(Id
)))
4784 and then Base_Type
(Etype
(First_Entity
(Id
))) =
4785 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
4789 -- Include the subprogram in the list of primitives
4792 Append_Elmt
(Id
, Op_List
);
4799 -- For a type declared in System, some of its operations may
4800 -- appear in the target-specific extension to System.
4803 and then B_Scope
= RTU_Entity
(System
)
4804 and then Present_System_Aux
4806 B_Scope
:= System_Aux_Id
;
4807 Id
:= First_Entity
(System_Aux_Id
);
4813 end Collect_Primitive_Operations
;
4815 -----------------------------------
4816 -- Compile_Time_Constraint_Error --
4817 -----------------------------------
4819 function Compile_Time_Constraint_Error
4822 Ent
: Entity_Id
:= Empty
;
4823 Loc
: Source_Ptr
:= No_Location
;
4824 Warn
: Boolean := False) return Node_Id
4826 Msgc
: String (1 .. Msg
'Length + 3);
4827 -- Copy of message, with room for possible ?? or << and ! at end
4833 -- Start of processing for Compile_Time_Constraint_Error
4836 -- If this is a warning, convert it into an error if we are in code
4837 -- subject to SPARK_Mode being set On, unless Warn is True to force a
4838 -- warning. The rationale is that a compile-time constraint error should
4839 -- lead to an error instead of a warning when SPARK_Mode is On, but in
4840 -- a few cases we prefer to issue a warning and generate both a suitable
4841 -- run-time error in GNAT and a suitable check message in GNATprove.
4842 -- Those cases are those that likely correspond to deactivated SPARK
4843 -- code, so that this kind of code can be compiled and analyzed instead
4844 -- of being rejected.
4846 Error_Msg_Warn
:= Warn
or SPARK_Mode
/= On
;
4848 -- A static constraint error in an instance body is not a fatal error.
4849 -- we choose to inhibit the message altogether, because there is no
4850 -- obvious node (for now) on which to post it. On the other hand the
4851 -- offending node must be replaced with a constraint_error in any case.
4853 -- No messages are generated if we already posted an error on this node
4855 if not Error_Posted
(N
) then
4856 if Loc
/= No_Location
then
4862 -- Copy message to Msgc, converting any ? in the message into
4863 -- < instead, so that we have an error in GNATprove mode.
4867 for J
in 1 .. Msgl
loop
4868 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
- 1) /= ''') then
4871 Msgc
(J
) := Msg
(J
);
4875 -- Message is a warning, even in Ada 95 case
4877 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
4880 -- In Ada 83, all messages are warnings. In the private part and
4881 -- the body of an instance, constraint_checks are only warnings.
4882 -- We also make this a warning if the Warn parameter is set.
4885 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
4893 elsif In_Instance_Not_Visible
then
4900 -- Otherwise we have a real error message (Ada 95 static case)
4901 -- and we make this an unconditional message. Note that in the
4902 -- warning case we do not make the message unconditional, it seems
4903 -- quite reasonable to delete messages like this (about exceptions
4904 -- that will be raised) in dead code.
4912 -- One more test, skip the warning if the related expression is
4913 -- statically unevaluated, since we don't want to warn about what
4914 -- will happen when something is evaluated if it never will be
4917 if not Is_Statically_Unevaluated
(N
) then
4918 if Present
(Ent
) then
4919 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
4921 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
4926 -- Check whether the context is an Init_Proc
4928 if Inside_Init_Proc
then
4930 Conc_Typ
: constant Entity_Id
:=
4931 Corresponding_Concurrent_Type
4932 (Entity
(Parameter_Type
(First
4933 (Parameter_Specifications
4934 (Parent
(Current_Scope
))))));
4937 -- Don't complain if the corresponding concurrent type
4938 -- doesn't come from source (i.e. a single task/protected
4941 if Present
(Conc_Typ
)
4942 and then not Comes_From_Source
(Conc_Typ
)
4945 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4948 if GNATprove_Mode
then
4950 ("\& would have been raised for objects of this "
4951 & "type", N
, Standard_Constraint_Error
, Eloc
);
4954 ("\& will be raised for objects of this type??",
4955 N
, Standard_Constraint_Error
, Eloc
);
4961 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
4965 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
4966 Set_Error_Posted
(N
);
4972 end Compile_Time_Constraint_Error
;
4974 -----------------------
4975 -- Conditional_Delay --
4976 -----------------------
4978 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
4980 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
4981 Set_Has_Delayed_Freeze
(New_Ent
);
4983 end Conditional_Delay
;
4985 ----------------------------
4986 -- Contains_Refined_State --
4987 ----------------------------
4989 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
4990 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
4991 -- Determine whether a dependency list mentions a state with a visible
4994 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
4995 -- Determine whether a global list mentions a state with a visible
4998 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
4999 -- Determine whether Item is a reference to an abstract state with a
5000 -- visible refinement.
5002 -----------------------------
5003 -- Has_State_In_Dependency --
5004 -----------------------------
5006 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
5011 -- A null dependency list does not mention any states
5013 if Nkind
(List
) = N_Null
then
5016 -- Dependency clauses appear as component associations of an
5019 elsif Nkind
(List
) = N_Aggregate
5020 and then Present
(Component_Associations
(List
))
5022 Clause
:= First
(Component_Associations
(List
));
5023 while Present
(Clause
) loop
5025 -- Inspect the outputs of a dependency clause
5027 Output
:= First
(Choices
(Clause
));
5028 while Present
(Output
) loop
5029 if Is_Refined_State
(Output
) then
5036 -- Inspect the outputs of a dependency clause
5038 if Is_Refined_State
(Expression
(Clause
)) then
5045 -- If we get here, then none of the dependency clauses mention a
5046 -- state with visible refinement.
5050 -- An illegal pragma managed to sneak in
5053 raise Program_Error
;
5055 end Has_State_In_Dependency
;
5057 -------------------------
5058 -- Has_State_In_Global --
5059 -------------------------
5061 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
5065 -- A null global list does not mention any states
5067 if Nkind
(List
) = N_Null
then
5070 -- Simple global list or moded global list declaration
5072 elsif Nkind
(List
) = N_Aggregate
then
5074 -- The declaration of a simple global list appear as a collection
5077 if Present
(Expressions
(List
)) then
5078 Item
:= First
(Expressions
(List
));
5079 while Present
(Item
) loop
5080 if Is_Refined_State
(Item
) then
5087 -- The declaration of a moded global list appears as a collection
5088 -- of component associations where individual choices denote
5092 Item
:= First
(Component_Associations
(List
));
5093 while Present
(Item
) loop
5094 if Has_State_In_Global
(Expression
(Item
)) then
5102 -- If we get here, then the simple/moded global list did not
5103 -- mention any states with a visible refinement.
5107 -- Single global item declaration
5109 elsif Is_Entity_Name
(List
) then
5110 return Is_Refined_State
(List
);
5112 -- An illegal pragma managed to sneak in
5115 raise Program_Error
;
5117 end Has_State_In_Global
;
5119 ----------------------
5120 -- Is_Refined_State --
5121 ----------------------
5123 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
5125 Item_Id
: Entity_Id
;
5128 if Nkind
(Item
) = N_Null
then
5131 -- States cannot be subject to attribute 'Result. This case arises
5132 -- in dependency relations.
5134 elsif Nkind
(Item
) = N_Attribute_Reference
5135 and then Attribute_Name
(Item
) = Name_Result
5139 -- Multiple items appear as an aggregate. This case arises in
5140 -- dependency relations.
5142 elsif Nkind
(Item
) = N_Aggregate
5143 and then Present
(Expressions
(Item
))
5145 Elmt
:= First
(Expressions
(Item
));
5146 while Present
(Elmt
) loop
5147 if Is_Refined_State
(Elmt
) then
5154 -- If we get here, then none of the inputs or outputs reference a
5155 -- state with visible refinement.
5162 Item_Id
:= Entity_Of
(Item
);
5166 and then Ekind
(Item_Id
) = E_Abstract_State
5167 and then Has_Visible_Refinement
(Item_Id
);
5169 end Is_Refined_State
;
5173 Arg
: constant Node_Id
:=
5174 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
5175 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
5177 -- Start of processing for Contains_Refined_State
5180 if Nam
= Name_Depends
then
5181 return Has_State_In_Dependency
(Arg
);
5183 else pragma Assert
(Nam
= Name_Global
);
5184 return Has_State_In_Global
(Arg
);
5186 end Contains_Refined_State
;
5188 -------------------------
5189 -- Copy_Component_List --
5190 -------------------------
5192 function Copy_Component_List
5194 Loc
: Source_Ptr
) return List_Id
5197 Comps
: constant List_Id
:= New_List
;
5200 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
5201 while Present
(Comp
) loop
5202 if Comes_From_Source
(Comp
) then
5204 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
5207 Make_Component_Declaration
(Loc
,
5208 Defining_Identifier
=>
5209 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
5210 Component_Definition
=>
5212 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
5216 Next_Component
(Comp
);
5220 end Copy_Component_List
;
5222 -------------------------
5223 -- Copy_Parameter_List --
5224 -------------------------
5226 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
5227 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
5232 if No
(First_Formal
(Subp_Id
)) then
5236 Formal
:= First_Formal
(Subp_Id
);
5237 while Present
(Formal
) loop
5239 Make_Parameter_Specification
(Loc
,
5240 Defining_Identifier
=>
5241 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
5242 In_Present
=> In_Present
(Parent
(Formal
)),
5243 Out_Present
=> Out_Present
(Parent
(Formal
)),
5245 New_Occurrence_Of
(Etype
(Formal
), Loc
),
5247 New_Copy_Tree
(Expression
(Parent
(Formal
)))));
5249 Next_Formal
(Formal
);
5254 end Copy_Parameter_List
;
5256 --------------------------
5257 -- Copy_Subprogram_Spec --
5258 --------------------------
5260 function Copy_Subprogram_Spec
(Spec
: Node_Id
) return Node_Id
is
5262 Formal_Spec
: Node_Id
;
5266 -- The structure of the original tree must be replicated without any
5267 -- alterations. Use New_Copy_Tree for this purpose.
5269 Result
:= New_Copy_Tree
(Spec
);
5271 -- Create a new entity for the defining unit name
5273 Def_Id
:= Defining_Unit_Name
(Result
);
5274 Set_Defining_Unit_Name
(Result
,
5275 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
5277 -- Create new entities for the formal parameters
5279 if Present
(Parameter_Specifications
(Result
)) then
5280 Formal_Spec
:= First
(Parameter_Specifications
(Result
));
5281 while Present
(Formal_Spec
) loop
5282 Def_Id
:= Defining_Identifier
(Formal_Spec
);
5283 Set_Defining_Identifier
(Formal_Spec
,
5284 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
5291 end Copy_Subprogram_Spec
;
5293 --------------------------------
5294 -- Corresponding_Generic_Type --
5295 --------------------------------
5297 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
5303 if not Is_Generic_Actual_Type
(T
) then
5306 -- If the actual is the actual of an enclosing instance, resolution
5307 -- was correct in the generic.
5309 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
5310 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
5312 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
5319 if Is_Wrapper_Package
(Inst
) then
5320 Inst
:= Related_Instance
(Inst
);
5325 (Specification
(Unit_Declaration_Node
(Inst
)));
5327 -- Generic actual has the same name as the corresponding formal
5329 Typ
:= First_Entity
(Gen
);
5330 while Present
(Typ
) loop
5331 if Chars
(Typ
) = Chars
(T
) then
5340 end Corresponding_Generic_Type
;
5342 --------------------
5343 -- Current_Entity --
5344 --------------------
5346 -- The currently visible definition for a given identifier is the
5347 -- one most chained at the start of the visibility chain, i.e. the
5348 -- one that is referenced by the Node_Id value of the name of the
5349 -- given identifier.
5351 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
5353 return Get_Name_Entity_Id
(Chars
(N
));
5356 -----------------------------
5357 -- Current_Entity_In_Scope --
5358 -----------------------------
5360 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
5362 CS
: constant Entity_Id
:= Current_Scope
;
5364 Transient_Case
: constant Boolean := Scope_Is_Transient
;
5367 E
:= Get_Name_Entity_Id
(Chars
(N
));
5369 and then Scope
(E
) /= CS
5370 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
5376 end Current_Entity_In_Scope
;
5382 function Current_Scope
return Entity_Id
is
5384 if Scope_Stack
.Last
= -1 then
5385 return Standard_Standard
;
5388 C
: constant Entity_Id
:=
5389 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
5394 return Standard_Standard
;
5400 ----------------------------
5401 -- Current_Scope_No_Loops --
5402 ----------------------------
5404 function Current_Scope_No_Loops
return Entity_Id
is
5408 -- Examine the scope stack starting from the current scope and skip any
5409 -- internally generated loops.
5412 while Present
(S
) and then S
/= Standard_Standard
loop
5413 if Ekind
(S
) = E_Loop
and then not Comes_From_Source
(S
) then
5421 end Current_Scope_No_Loops
;
5423 ------------------------
5424 -- Current_Subprogram --
5425 ------------------------
5427 function Current_Subprogram
return Entity_Id
is
5428 Scop
: constant Entity_Id
:= Current_Scope
;
5430 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
5433 return Enclosing_Subprogram
(Scop
);
5435 end Current_Subprogram
;
5437 ----------------------------------
5438 -- Deepest_Type_Access_Level --
5439 ----------------------------------
5441 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
5443 if Ekind
(Typ
) = E_Anonymous_Access_Type
5444 and then not Is_Local_Anonymous_Access
(Typ
)
5445 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
5447 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5451 Scope_Depth
(Enclosing_Dynamic_Scope
5452 (Defining_Identifier
5453 (Associated_Node_For_Itype
(Typ
))));
5455 -- For generic formal type, return Int'Last (infinite).
5456 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5458 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
5459 return UI_From_Int
(Int
'Last);
5462 return Type_Access_Level
(Typ
);
5464 end Deepest_Type_Access_Level
;
5466 ---------------------
5467 -- Defining_Entity --
5468 ---------------------
5470 function Defining_Entity
5472 Empty_On_Errors
: Boolean := False) return Entity_Id
5474 Err
: Entity_Id
:= Empty
;
5478 when N_Abstract_Subprogram_Declaration |
5479 N_Expression_Function |
5480 N_Formal_Subprogram_Declaration |
5481 N_Generic_Package_Declaration |
5482 N_Generic_Subprogram_Declaration |
5483 N_Package_Declaration |
5485 N_Subprogram_Body_Stub |
5486 N_Subprogram_Declaration |
5487 N_Subprogram_Renaming_Declaration
5489 return Defining_Entity
(Specification
(N
));
5491 when N_Component_Declaration |
5492 N_Defining_Program_Unit_Name |
5493 N_Discriminant_Specification |
5495 N_Entry_Declaration |
5496 N_Entry_Index_Specification |
5497 N_Exception_Declaration |
5498 N_Exception_Renaming_Declaration |
5499 N_Formal_Object_Declaration |
5500 N_Formal_Package_Declaration |
5501 N_Formal_Type_Declaration |
5502 N_Full_Type_Declaration |
5503 N_Implicit_Label_Declaration |
5504 N_Incomplete_Type_Declaration |
5505 N_Loop_Parameter_Specification |
5506 N_Number_Declaration |
5507 N_Object_Declaration |
5508 N_Object_Renaming_Declaration |
5509 N_Package_Body_Stub |
5510 N_Parameter_Specification |
5511 N_Private_Extension_Declaration |
5512 N_Private_Type_Declaration |
5514 N_Protected_Body_Stub |
5515 N_Protected_Type_Declaration |
5516 N_Single_Protected_Declaration |
5517 N_Single_Task_Declaration |
5518 N_Subtype_Declaration |
5521 N_Task_Type_Declaration
5523 return Defining_Identifier
(N
);
5526 return Defining_Entity
(Proper_Body
(N
));
5528 when N_Function_Instantiation |
5529 N_Function_Specification |
5530 N_Generic_Function_Renaming_Declaration |
5531 N_Generic_Package_Renaming_Declaration |
5532 N_Generic_Procedure_Renaming_Declaration |
5534 N_Package_Instantiation |
5535 N_Package_Renaming_Declaration |
5536 N_Package_Specification |
5537 N_Procedure_Instantiation |
5538 N_Procedure_Specification
5541 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
5544 if Nkind
(Nam
) in N_Entity
then
5547 -- For Error, make up a name and attach to declaration so we
5548 -- can continue semantic analysis.
5550 elsif Nam
= Error
then
5551 if Empty_On_Errors
then
5554 Err
:= Make_Temporary
(Sloc
(N
), 'T');
5555 Set_Defining_Unit_Name
(N
, Err
);
5560 -- If not an entity, get defining identifier
5563 return Defining_Identifier
(Nam
);
5567 when N_Block_Statement |
5569 return Entity
(Identifier
(N
));
5572 if Empty_On_Errors
then
5575 raise Program_Error
;
5579 end Defining_Entity
;
5581 --------------------------
5582 -- Denotes_Discriminant --
5583 --------------------------
5585 function Denotes_Discriminant
5587 Check_Concurrent
: Boolean := False) return Boolean
5592 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
5598 -- If we are checking for a protected type, the discriminant may have
5599 -- been rewritten as the corresponding discriminal of the original type
5600 -- or of the corresponding concurrent record, depending on whether we
5601 -- are in the spec or body of the protected type.
5603 return Ekind
(E
) = E_Discriminant
5606 and then Ekind
(E
) = E_In_Parameter
5607 and then Present
(Discriminal_Link
(E
))
5609 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
5611 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
5612 end Denotes_Discriminant
;
5614 -------------------------
5615 -- Denotes_Same_Object --
5616 -------------------------
5618 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
5619 Obj1
: Node_Id
:= A1
;
5620 Obj2
: Node_Id
:= A2
;
5622 function Has_Prefix
(N
: Node_Id
) return Boolean;
5623 -- Return True if N has attribute Prefix
5625 function Is_Renaming
(N
: Node_Id
) return Boolean;
5626 -- Return true if N names a renaming entity
5628 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
5629 -- For renamings, return False if the prefix of any dereference within
5630 -- the renamed object_name is a variable, or any expression within the
5631 -- renamed object_name contains references to variables or calls on
5632 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5638 function Has_Prefix
(N
: Node_Id
) return Boolean is
5642 N_Attribute_Reference
,
5644 N_Explicit_Dereference
,
5645 N_Indexed_Component
,
5647 N_Selected_Component
,
5655 function Is_Renaming
(N
: Node_Id
) return Boolean is
5657 return Is_Entity_Name
(N
)
5658 and then Present
(Renamed_Entity
(Entity
(N
)));
5661 -----------------------
5662 -- Is_Valid_Renaming --
5663 -----------------------
5665 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
5667 function Check_Renaming
(N
: Node_Id
) return Boolean;
5668 -- Recursive function used to traverse all the prefixes of N
5670 function Check_Renaming
(N
: Node_Id
) return Boolean is
5673 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
5678 if Nkind
(N
) = N_Indexed_Component
then
5683 Indx
:= First
(Expressions
(N
));
5684 while Present
(Indx
) loop
5685 if not Is_OK_Static_Expression
(Indx
) then
5694 if Has_Prefix
(N
) then
5696 P
: constant Node_Id
:= Prefix
(N
);
5699 if Nkind
(N
) = N_Explicit_Dereference
5700 and then Is_Variable
(P
)
5704 elsif Is_Entity_Name
(P
)
5705 and then Ekind
(Entity
(P
)) = E_Function
5709 elsif Nkind
(P
) = N_Function_Call
then
5713 -- Recursion to continue traversing the prefix of the
5714 -- renaming expression
5716 return Check_Renaming
(P
);
5723 -- Start of processing for Is_Valid_Renaming
5726 return Check_Renaming
(N
);
5727 end Is_Valid_Renaming
;
5729 -- Start of processing for Denotes_Same_Object
5732 -- Both names statically denote the same stand-alone object or parameter
5733 -- (RM 6.4.1(6.5/3))
5735 if Is_Entity_Name
(Obj1
)
5736 and then Is_Entity_Name
(Obj2
)
5737 and then Entity
(Obj1
) = Entity
(Obj2
)
5742 -- For renamings, the prefix of any dereference within the renamed
5743 -- object_name is not a variable, and any expression within the
5744 -- renamed object_name contains no references to variables nor
5745 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5747 if Is_Renaming
(Obj1
) then
5748 if Is_Valid_Renaming
(Obj1
) then
5749 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
5755 if Is_Renaming
(Obj2
) then
5756 if Is_Valid_Renaming
(Obj2
) then
5757 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
5763 -- No match if not same node kind (such cases are handled by
5764 -- Denotes_Same_Prefix)
5766 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
5769 -- After handling valid renamings, one of the two names statically
5770 -- denoted a renaming declaration whose renamed object_name is known
5771 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5773 elsif Is_Entity_Name
(Obj1
) then
5774 if Is_Entity_Name
(Obj2
) then
5775 return Entity
(Obj1
) = Entity
(Obj2
);
5780 -- Both names are selected_components, their prefixes are known to
5781 -- denote the same object, and their selector_names denote the same
5782 -- component (RM 6.4.1(6.6/3)).
5784 elsif Nkind
(Obj1
) = N_Selected_Component
then
5785 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
5787 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
5789 -- Both names are dereferences and the dereferenced names are known to
5790 -- denote the same object (RM 6.4.1(6.7/3))
5792 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
5793 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
5795 -- Both names are indexed_components, their prefixes are known to denote
5796 -- the same object, and each of the pairs of corresponding index values
5797 -- are either both static expressions with the same static value or both
5798 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
5800 elsif Nkind
(Obj1
) = N_Indexed_Component
then
5801 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
5809 Indx1
:= First
(Expressions
(Obj1
));
5810 Indx2
:= First
(Expressions
(Obj2
));
5811 while Present
(Indx1
) loop
5813 -- Indexes must denote the same static value or same object
5815 if Is_OK_Static_Expression
(Indx1
) then
5816 if not Is_OK_Static_Expression
(Indx2
) then
5819 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
5823 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
5835 -- Both names are slices, their prefixes are known to denote the same
5836 -- object, and the two slices have statically matching index constraints
5837 -- (RM 6.4.1(6.9/3))
5839 elsif Nkind
(Obj1
) = N_Slice
5840 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
5843 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
5846 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
5847 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
5849 -- Check whether bounds are statically identical. There is no
5850 -- attempt to detect partial overlap of slices.
5852 return Denotes_Same_Object
(Lo1
, Lo2
)
5854 Denotes_Same_Object
(Hi1
, Hi2
);
5857 -- In the recursion, literals appear as indexes
5859 elsif Nkind
(Obj1
) = N_Integer_Literal
5861 Nkind
(Obj2
) = N_Integer_Literal
5863 return Intval
(Obj1
) = Intval
(Obj2
);
5868 end Denotes_Same_Object
;
5870 -------------------------
5871 -- Denotes_Same_Prefix --
5872 -------------------------
5874 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
5876 if Is_Entity_Name
(A1
) then
5877 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
5878 and then not Is_Access_Type
(Etype
(A1
))
5880 return Denotes_Same_Object
(A1
, Prefix
(A2
))
5881 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
5886 elsif Is_Entity_Name
(A2
) then
5887 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
5889 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5891 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
5894 Root1
, Root2
: Node_Id
;
5895 Depth1
, Depth2
: Nat
:= 0;
5898 Root1
:= Prefix
(A1
);
5899 while not Is_Entity_Name
(Root1
) loop
5901 (Root1
, N_Selected_Component
, N_Indexed_Component
)
5905 Root1
:= Prefix
(Root1
);
5908 Depth1
:= Depth1
+ 1;
5911 Root2
:= Prefix
(A2
);
5912 while not Is_Entity_Name
(Root2
) loop
5913 if not Nkind_In
(Root2
, N_Selected_Component
,
5914 N_Indexed_Component
)
5918 Root2
:= Prefix
(Root2
);
5921 Depth2
:= Depth2
+ 1;
5924 -- If both have the same depth and they do not denote the same
5925 -- object, they are disjoint and no warning is needed.
5927 if Depth1
= Depth2
then
5930 elsif Depth1
> Depth2
then
5931 Root1
:= Prefix
(A1
);
5932 for J
in 1 .. Depth1
- Depth2
- 1 loop
5933 Root1
:= Prefix
(Root1
);
5936 return Denotes_Same_Object
(Root1
, A2
);
5939 Root2
:= Prefix
(A2
);
5940 for J
in 1 .. Depth2
- Depth1
- 1 loop
5941 Root2
:= Prefix
(Root2
);
5944 return Denotes_Same_Object
(A1
, Root2
);
5951 end Denotes_Same_Prefix
;
5953 ----------------------
5954 -- Denotes_Variable --
5955 ----------------------
5957 function Denotes_Variable
(N
: Node_Id
) return Boolean is
5959 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
5960 end Denotes_Variable
;
5962 -----------------------------
5963 -- Depends_On_Discriminant --
5964 -----------------------------
5966 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
5971 Get_Index_Bounds
(N
, L
, H
);
5972 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
5973 end Depends_On_Discriminant
;
5975 -------------------------
5976 -- Designate_Same_Unit --
5977 -------------------------
5979 function Designate_Same_Unit
5981 Name2
: Node_Id
) return Boolean
5983 K1
: constant Node_Kind
:= Nkind
(Name1
);
5984 K2
: constant Node_Kind
:= Nkind
(Name2
);
5986 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
5987 -- Returns the parent unit name node of a defining program unit name
5988 -- or the prefix if N is a selected component or an expanded name.
5990 function Select_Node
(N
: Node_Id
) return Node_Id
;
5991 -- Returns the defining identifier node of a defining program unit
5992 -- name or the selector node if N is a selected component or an
5999 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
6001 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
6012 function Select_Node
(N
: Node_Id
) return Node_Id
is
6014 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
6015 return Defining_Identifier
(N
);
6017 return Selector_Name
(N
);
6021 -- Start of processing for Designate_Same_Unit
6024 if Nkind_In
(K1
, N_Identifier
, N_Defining_Identifier
)
6026 Nkind_In
(K2
, N_Identifier
, N_Defining_Identifier
)
6028 return Chars
(Name1
) = Chars
(Name2
);
6030 elsif Nkind_In
(K1
, N_Expanded_Name
,
6031 N_Selected_Component
,
6032 N_Defining_Program_Unit_Name
)
6034 Nkind_In
(K2
, N_Expanded_Name
,
6035 N_Selected_Component
,
6036 N_Defining_Program_Unit_Name
)
6039 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
6041 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
6046 end Designate_Same_Unit
;
6048 ------------------------------------------
6049 -- function Dynamic_Accessibility_Level --
6050 ------------------------------------------
6052 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
6054 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6056 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
6057 -- Construct an integer literal representing an accessibility level
6058 -- with its type set to Natural.
6060 ------------------------
6061 -- Make_Level_Literal --
6062 ------------------------
6064 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
6065 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
6067 Set_Etype
(Result
, Standard_Natural
);
6069 end Make_Level_Literal
;
6071 -- Start of processing for Dynamic_Accessibility_Level
6074 if Is_Entity_Name
(Expr
) then
6077 if Present
(Renamed_Object
(E
)) then
6078 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
6081 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
6082 if Present
(Extra_Accessibility
(E
)) then
6083 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
6088 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6090 case Nkind
(Expr
) is
6092 -- For access discriminant, the level of the enclosing object
6094 when N_Selected_Component
=>
6095 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
6096 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
6097 E_Anonymous_Access_Type
6099 return Make_Level_Literal
(Object_Access_Level
(Expr
));
6102 when N_Attribute_Reference
=>
6103 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
6105 -- For X'Access, the level of the prefix X
6107 when Attribute_Access
=>
6108 return Make_Level_Literal
6109 (Object_Access_Level
(Prefix
(Expr
)));
6111 -- Treat the unchecked attributes as library-level
6113 when Attribute_Unchecked_Access |
6114 Attribute_Unrestricted_Access
=>
6115 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
6117 -- No other access-valued attributes
6120 raise Program_Error
;
6125 -- Unimplemented: depends on context. As an actual parameter where
6126 -- formal type is anonymous, use
6127 -- Scope_Depth (Current_Scope) + 1.
6128 -- For other cases, see 3.10.2(14/3) and following. ???
6132 when N_Type_Conversion
=>
6133 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
6135 -- Handle type conversions introduced for a rename of an
6136 -- Ada 2012 stand-alone object of an anonymous access type.
6138 return Dynamic_Accessibility_Level
(Expression
(Expr
));
6145 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
6146 end Dynamic_Accessibility_Level
;
6148 -----------------------------------
6149 -- Effective_Extra_Accessibility --
6150 -----------------------------------
6152 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
6154 if Present
(Renamed_Object
(Id
))
6155 and then Is_Entity_Name
(Renamed_Object
(Id
))
6157 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
6159 return Extra_Accessibility
(Id
);
6161 end Effective_Extra_Accessibility
;
6163 -----------------------------
6164 -- Effective_Reads_Enabled --
6165 -----------------------------
6167 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
6169 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
6170 end Effective_Reads_Enabled
;
6172 ------------------------------
6173 -- Effective_Writes_Enabled --
6174 ------------------------------
6176 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
6178 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
6179 end Effective_Writes_Enabled
;
6181 ------------------------------
6182 -- Enclosing_Comp_Unit_Node --
6183 ------------------------------
6185 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
6186 Current_Node
: Node_Id
;
6190 while Present
(Current_Node
)
6191 and then Nkind
(Current_Node
) /= N_Compilation_Unit
6193 Current_Node
:= Parent
(Current_Node
);
6196 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
6199 return Current_Node
;
6201 end Enclosing_Comp_Unit_Node
;
6203 --------------------------
6204 -- Enclosing_CPP_Parent --
6205 --------------------------
6207 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
6208 Parent_Typ
: Entity_Id
:= Typ
;
6211 while not Is_CPP_Class
(Parent_Typ
)
6212 and then Etype
(Parent_Typ
) /= Parent_Typ
6214 Parent_Typ
:= Etype
(Parent_Typ
);
6216 if Is_Private_Type
(Parent_Typ
) then
6217 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6221 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
6223 end Enclosing_CPP_Parent
;
6225 ---------------------------
6226 -- Enclosing_Declaration --
6227 ---------------------------
6229 function Enclosing_Declaration
(N
: Node_Id
) return Node_Id
is
6230 Decl
: Node_Id
:= N
;
6233 while Present
(Decl
)
6234 and then not (Nkind
(Decl
) in N_Declaration
6236 Nkind
(Decl
) in N_Later_Decl_Item
)
6238 Decl
:= Parent
(Decl
);
6242 end Enclosing_Declaration
;
6244 ----------------------------
6245 -- Enclosing_Generic_Body --
6246 ----------------------------
6248 function Enclosing_Generic_Body
6249 (N
: Node_Id
) return Node_Id
6257 while Present
(P
) loop
6258 if Nkind
(P
) = N_Package_Body
6259 or else Nkind
(P
) = N_Subprogram_Body
6261 Spec
:= Corresponding_Spec
(P
);
6263 if Present
(Spec
) then
6264 Decl
:= Unit_Declaration_Node
(Spec
);
6266 if Nkind
(Decl
) = N_Generic_Package_Declaration
6267 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
6278 end Enclosing_Generic_Body
;
6280 ----------------------------
6281 -- Enclosing_Generic_Unit --
6282 ----------------------------
6284 function Enclosing_Generic_Unit
6285 (N
: Node_Id
) return Node_Id
6293 while Present
(P
) loop
6294 if Nkind
(P
) = N_Generic_Package_Declaration
6295 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
6299 elsif Nkind
(P
) = N_Package_Body
6300 or else Nkind
(P
) = N_Subprogram_Body
6302 Spec
:= Corresponding_Spec
(P
);
6304 if Present
(Spec
) then
6305 Decl
:= Unit_Declaration_Node
(Spec
);
6307 if Nkind
(Decl
) = N_Generic_Package_Declaration
6308 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
6319 end Enclosing_Generic_Unit
;
6321 -------------------------------
6322 -- Enclosing_Lib_Unit_Entity --
6323 -------------------------------
6325 function Enclosing_Lib_Unit_Entity
6326 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
6328 Unit_Entity
: Entity_Id
;
6331 -- Look for enclosing library unit entity by following scope links.
6332 -- Equivalent to, but faster than indexing through the scope stack.
6335 while (Present
(Scope
(Unit_Entity
))
6336 and then Scope
(Unit_Entity
) /= Standard_Standard
)
6337 and not Is_Child_Unit
(Unit_Entity
)
6339 Unit_Entity
:= Scope
(Unit_Entity
);
6343 end Enclosing_Lib_Unit_Entity
;
6345 -----------------------------
6346 -- Enclosing_Lib_Unit_Node --
6347 -----------------------------
6349 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
6350 Encl_Unit
: Node_Id
;
6353 Encl_Unit
:= Enclosing_Comp_Unit_Node
(N
);
6354 while Present
(Encl_Unit
)
6355 and then Nkind
(Unit
(Encl_Unit
)) = N_Subunit
6357 Encl_Unit
:= Library_Unit
(Encl_Unit
);
6360 pragma Assert
(Nkind
(Encl_Unit
) = N_Compilation_Unit
);
6362 end Enclosing_Lib_Unit_Node
;
6364 -----------------------
6365 -- Enclosing_Package --
6366 -----------------------
6368 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
6369 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
6372 if Dynamic_Scope
= Standard_Standard
then
6373 return Standard_Standard
;
6375 elsif Dynamic_Scope
= Empty
then
6378 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
6381 return Dynamic_Scope
;
6384 return Enclosing_Package
(Dynamic_Scope
);
6386 end Enclosing_Package
;
6388 -------------------------------------
6389 -- Enclosing_Package_Or_Subprogram --
6390 -------------------------------------
6392 function Enclosing_Package_Or_Subprogram
(E
: Entity_Id
) return Entity_Id
is
6397 while Present
(S
) loop
6398 if Is_Package_Or_Generic_Package
(S
)
6399 or else Ekind
(S
) = E_Package_Body
6403 elsif Is_Subprogram_Or_Generic_Subprogram
(S
)
6404 or else Ekind
(S
) = E_Subprogram_Body
6414 end Enclosing_Package_Or_Subprogram
;
6416 --------------------------
6417 -- Enclosing_Subprogram --
6418 --------------------------
6420 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
6421 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
6424 if Dynamic_Scope
= Standard_Standard
then
6427 elsif Dynamic_Scope
= Empty
then
6430 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
6431 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
6433 elsif Ekind
(Dynamic_Scope
) = E_Block
6434 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
6436 return Enclosing_Subprogram
(Dynamic_Scope
);
6438 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
6439 return Get_Task_Body_Procedure
(Dynamic_Scope
);
6441 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
6442 and then Present
(Full_View
(Dynamic_Scope
))
6443 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
6445 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
6447 -- No body is generated if the protected operation is eliminated
6449 elsif Convention
(Dynamic_Scope
) = Convention_Protected
6450 and then not Is_Eliminated
(Dynamic_Scope
)
6451 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
6453 return Protected_Body_Subprogram
(Dynamic_Scope
);
6456 return Dynamic_Scope
;
6458 end Enclosing_Subprogram
;
6460 ------------------------
6461 -- Ensure_Freeze_Node --
6462 ------------------------
6464 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
6467 if No
(Freeze_Node
(E
)) then
6468 FN
:= Make_Freeze_Entity
(Sloc
(E
));
6469 Set_Has_Delayed_Freeze
(E
);
6470 Set_Freeze_Node
(E
, FN
);
6471 Set_Access_Types_To_Process
(FN
, No_Elist
);
6472 Set_TSS_Elist
(FN
, No_Elist
);
6475 end Ensure_Freeze_Node
;
6481 procedure Enter_Name
(Def_Id
: Entity_Id
) is
6482 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
6483 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
6484 S
: constant Entity_Id
:= Current_Scope
;
6487 Generate_Definition
(Def_Id
);
6489 -- Add new name to current scope declarations. Check for duplicate
6490 -- declaration, which may or may not be a genuine error.
6494 -- Case of previous entity entered because of a missing declaration
6495 -- or else a bad subtype indication. Best is to use the new entity,
6496 -- and make the previous one invisible.
6498 if Etype
(E
) = Any_Type
then
6499 Set_Is_Immediately_Visible
(E
, False);
6501 -- Case of renaming declaration constructed for package instances.
6502 -- if there is an explicit declaration with the same identifier,
6503 -- the renaming is not immediately visible any longer, but remains
6504 -- visible through selected component notation.
6506 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
6507 and then not Comes_From_Source
(E
)
6509 Set_Is_Immediately_Visible
(E
, False);
6511 -- The new entity may be the package renaming, which has the same
6512 -- same name as a generic formal which has been seen already.
6514 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
6515 and then not Comes_From_Source
(Def_Id
)
6517 Set_Is_Immediately_Visible
(E
, False);
6519 -- For a fat pointer corresponding to a remote access to subprogram,
6520 -- we use the same identifier as the RAS type, so that the proper
6521 -- name appears in the stub. This type is only retrieved through
6522 -- the RAS type and never by visibility, and is not added to the
6523 -- visibility list (see below).
6525 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
6526 and then Ekind
(Def_Id
) = E_Record_Type
6527 and then Present
(Corresponding_Remote_Type
(Def_Id
))
6531 -- Case of an implicit operation or derived literal. The new entity
6532 -- hides the implicit one, which is removed from all visibility,
6533 -- i.e. the entity list of its scope, and homonym chain of its name.
6535 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
6536 or else Is_Internal
(E
)
6539 Decl
: constant Node_Id
:= Parent
(E
);
6541 Prev_Vis
: Entity_Id
;
6544 -- If E is an implicit declaration, it cannot be the first
6545 -- entity in the scope.
6547 Prev
:= First_Entity
(Current_Scope
);
6548 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
6554 -- If E is not on the entity chain of the current scope,
6555 -- it is an implicit declaration in the generic formal
6556 -- part of a generic subprogram. When analyzing the body,
6557 -- the generic formals are visible but not on the entity
6558 -- chain of the subprogram. The new entity will become
6559 -- the visible one in the body.
6562 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
6566 Set_Next_Entity
(Prev
, Next_Entity
(E
));
6568 if No
(Next_Entity
(Prev
)) then
6569 Set_Last_Entity
(Current_Scope
, Prev
);
6572 if E
= Current_Entity
(E
) then
6576 Prev_Vis
:= Current_Entity
(E
);
6577 while Homonym
(Prev_Vis
) /= E
loop
6578 Prev_Vis
:= Homonym
(Prev_Vis
);
6582 if Present
(Prev_Vis
) then
6584 -- Skip E in the visibility chain
6586 Set_Homonym
(Prev_Vis
, Homonym
(E
));
6589 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6594 -- This section of code could use a comment ???
6596 elsif Present
(Etype
(E
))
6597 and then Is_Concurrent_Type
(Etype
(E
))
6602 -- If the homograph is a protected component renaming, it should not
6603 -- be hiding the current entity. Such renamings are treated as weak
6606 elsif Is_Prival
(E
) then
6607 Set_Is_Immediately_Visible
(E
, False);
6609 -- In this case the current entity is a protected component renaming.
6610 -- Perform minimal decoration by setting the scope and return since
6611 -- the prival should not be hiding other visible entities.
6613 elsif Is_Prival
(Def_Id
) then
6614 Set_Scope
(Def_Id
, Current_Scope
);
6617 -- Analogous to privals, the discriminal generated for an entry index
6618 -- parameter acts as a weak declaration. Perform minimal decoration
6619 -- to avoid bogus errors.
6621 elsif Is_Discriminal
(Def_Id
)
6622 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
6624 Set_Scope
(Def_Id
, Current_Scope
);
6627 -- In the body or private part of an instance, a type extension may
6628 -- introduce a component with the same name as that of an actual. The
6629 -- legality rule is not enforced, but the semantics of the full type
6630 -- with two components of same name are not clear at this point???
6632 elsif In_Instance_Not_Visible
then
6635 -- When compiling a package body, some child units may have become
6636 -- visible. They cannot conflict with local entities that hide them.
6638 elsif Is_Child_Unit
(E
)
6639 and then In_Open_Scopes
(Scope
(E
))
6640 and then not Is_Immediately_Visible
(E
)
6644 -- Conversely, with front-end inlining we may compile the parent body
6645 -- first, and a child unit subsequently. The context is now the
6646 -- parent spec, and body entities are not visible.
6648 elsif Is_Child_Unit
(Def_Id
)
6649 and then Is_Package_Body_Entity
(E
)
6650 and then not In_Package_Body
(Current_Scope
)
6654 -- Case of genuine duplicate declaration
6657 Error_Msg_Sloc
:= Sloc
(E
);
6659 -- If the previous declaration is an incomplete type declaration
6660 -- this may be an attempt to complete it with a private type. The
6661 -- following avoids confusing cascaded errors.
6663 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
6664 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
6667 ("incomplete type cannot be completed with a private " &
6668 "declaration", Parent
(Def_Id
));
6669 Set_Is_Immediately_Visible
(E
, False);
6670 Set_Full_View
(E
, Def_Id
);
6672 -- An inherited component of a record conflicts with a new
6673 -- discriminant. The discriminant is inserted first in the scope,
6674 -- but the error should be posted on it, not on the component.
6676 elsif Ekind
(E
) = E_Discriminant
6677 and then Present
(Scope
(Def_Id
))
6678 and then Scope
(Def_Id
) /= Current_Scope
6680 Error_Msg_Sloc
:= Sloc
(Def_Id
);
6681 Error_Msg_N
("& conflicts with declaration#", E
);
6684 -- If the name of the unit appears in its own context clause, a
6685 -- dummy package with the name has already been created, and the
6686 -- error emitted. Try to continue quietly.
6688 elsif Error_Posted
(E
)
6689 and then Sloc
(E
) = No_Location
6690 and then Nkind
(Parent
(E
)) = N_Package_Specification
6691 and then Current_Scope
= Standard_Standard
6693 Set_Scope
(Def_Id
, Current_Scope
);
6697 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
6699 -- Avoid cascaded messages with duplicate components in
6702 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
6707 if Nkind
(Parent
(Parent
(Def_Id
))) =
6708 N_Generic_Subprogram_Declaration
6710 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
6712 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
6715 -- If entity is in standard, then we are in trouble, because it
6716 -- means that we have a library package with a duplicated name.
6717 -- That's hard to recover from, so abort.
6719 if S
= Standard_Standard
then
6720 raise Unrecoverable_Error
;
6722 -- Otherwise we continue with the declaration. Having two
6723 -- identical declarations should not cause us too much trouble.
6731 -- If we fall through, declaration is OK, at least OK enough to continue
6733 -- If Def_Id is a discriminant or a record component we are in the midst
6734 -- of inheriting components in a derived record definition. Preserve
6735 -- their Ekind and Etype.
6737 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
6740 -- If a type is already set, leave it alone (happens when a type
6741 -- declaration is reanalyzed following a call to the optimizer).
6743 elsif Present
(Etype
(Def_Id
)) then
6746 -- Otherwise, the kind E_Void insures that premature uses of the entity
6747 -- will be detected. Any_Type insures that no cascaded errors will occur
6750 Set_Ekind
(Def_Id
, E_Void
);
6751 Set_Etype
(Def_Id
, Any_Type
);
6754 -- Inherited discriminants and components in derived record types are
6755 -- immediately visible. Itypes are not.
6757 -- Unless the Itype is for a record type with a corresponding remote
6758 -- type (what is that about, it was not commented ???)
6760 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
6762 ((not Is_Record_Type
(Def_Id
)
6763 or else No
(Corresponding_Remote_Type
(Def_Id
)))
6764 and then not Is_Itype
(Def_Id
))
6766 Set_Is_Immediately_Visible
(Def_Id
);
6767 Set_Current_Entity
(Def_Id
);
6770 Set_Homonym
(Def_Id
, C
);
6771 Append_Entity
(Def_Id
, S
);
6772 Set_Public_Status
(Def_Id
);
6774 -- Declaring a homonym is not allowed in SPARK ...
6776 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
6778 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
6779 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
6780 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
6783 -- ... unless the new declaration is in a subprogram, and the
6784 -- visible declaration is a variable declaration or a parameter
6785 -- specification outside that subprogram.
6787 if Present
(Enclosing_Subp
)
6788 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
6789 N_Parameter_Specification
)
6790 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
6794 -- ... or the new declaration is in a package, and the visible
6795 -- declaration occurs outside that package.
6797 elsif Present
(Enclosing_Pack
)
6798 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
6802 -- ... or the new declaration is a component declaration in a
6803 -- record type definition.
6805 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
6808 -- Don't issue error for non-source entities
6810 elsif Comes_From_Source
(Def_Id
)
6811 and then Comes_From_Source
(C
)
6813 Error_Msg_Sloc
:= Sloc
(C
);
6814 Check_SPARK_05_Restriction
6815 ("redeclaration of identifier &#", Def_Id
);
6820 -- Warn if new entity hides an old one
6822 if Warn_On_Hiding
and then Present
(C
)
6824 -- Don't warn for record components since they always have a well
6825 -- defined scope which does not confuse other uses. Note that in
6826 -- some cases, Ekind has not been set yet.
6828 and then Ekind
(C
) /= E_Component
6829 and then Ekind
(C
) /= E_Discriminant
6830 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
6831 and then Ekind
(Def_Id
) /= E_Component
6832 and then Ekind
(Def_Id
) /= E_Discriminant
6833 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
6835 -- Don't warn for one character variables. It is too common to use
6836 -- such variables as locals and will just cause too many false hits.
6838 and then Length_Of_Name
(Chars
(C
)) /= 1
6840 -- Don't warn for non-source entities
6842 and then Comes_From_Source
(C
)
6843 and then Comes_From_Source
(Def_Id
)
6845 -- Don't warn unless entity in question is in extended main source
6847 and then In_Extended_Main_Source_Unit
(Def_Id
)
6849 -- Finally, the hidden entity must be either immediately visible or
6850 -- use visible (i.e. from a used package).
6853 (Is_Immediately_Visible
(C
)
6855 Is_Potentially_Use_Visible
(C
))
6857 Error_Msg_Sloc
:= Sloc
(C
);
6858 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
6866 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
6872 if Is_Entity_Name
(N
) then
6875 -- Follow a possible chain of renamings to reach the root renamed
6879 and then Is_Object
(Id
)
6880 and then Present
(Renamed_Object
(Id
))
6882 if Is_Entity_Name
(Renamed_Object
(Id
)) then
6883 Id
:= Entity
(Renamed_Object
(Id
));
6894 --------------------------
6895 -- Explain_Limited_Type --
6896 --------------------------
6898 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
6902 -- For array, component type must be limited
6904 if Is_Array_Type
(T
) then
6905 Error_Msg_Node_2
:= T
;
6907 ("\component type& of type& is limited", N
, Component_Type
(T
));
6908 Explain_Limited_Type
(Component_Type
(T
), N
);
6910 elsif Is_Record_Type
(T
) then
6912 -- No need for extra messages if explicit limited record
6914 if Is_Limited_Record
(Base_Type
(T
)) then
6918 -- Otherwise find a limited component. Check only components that
6919 -- come from source, or inherited components that appear in the
6920 -- source of the ancestor.
6922 C
:= First_Component
(T
);
6923 while Present
(C
) loop
6924 if Is_Limited_Type
(Etype
(C
))
6926 (Comes_From_Source
(C
)
6928 (Present
(Original_Record_Component
(C
))
6930 Comes_From_Source
(Original_Record_Component
(C
))))
6932 Error_Msg_Node_2
:= T
;
6933 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
6934 Explain_Limited_Type
(Etype
(C
), N
);
6941 -- The type may be declared explicitly limited, even if no component
6942 -- of it is limited, in which case we fall out of the loop.
6945 end Explain_Limited_Type
;
6947 -------------------------------
6948 -- Extensions_Visible_Status --
6949 -------------------------------
6951 function Extensions_Visible_Status
6952 (Id
: Entity_Id
) return Extensions_Visible_Mode
6961 -- When a formal parameter is subject to Extensions_Visible, the pragma
6962 -- is stored in the contract of related subprogram.
6964 if Is_Formal
(Id
) then
6967 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
6970 -- No other construct carries this pragma
6973 return Extensions_Visible_None
;
6976 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
6978 -- In certain cases analysis may request the Extensions_Visible status
6979 -- of an expression function before the pragma has been analyzed yet.
6980 -- Inspect the declarative items after the expression function looking
6981 -- for the pragma (if any).
6983 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
6984 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
6985 while Present
(Decl
) loop
6986 if Nkind
(Decl
) = N_Pragma
6987 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
6992 -- A source construct ends the region where Extensions_Visible may
6993 -- appear, stop the traversal. An expanded expression function is
6994 -- no longer a source construct, but it must still be recognized.
6996 elsif Comes_From_Source
(Decl
)
6998 (Nkind_In
(Decl
, N_Subprogram_Body
,
6999 N_Subprogram_Declaration
)
7000 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
7009 -- Extract the value from the Boolean expression (if any)
7011 if Present
(Prag
) then
7012 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
7014 if Present
(Arg
) then
7015 Expr
:= Get_Pragma_Arg
(Arg
);
7017 -- When the associated subprogram is an expression function, the
7018 -- argument of the pragma may not have been analyzed.
7020 if not Analyzed
(Expr
) then
7021 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
7024 -- Guard against cascading errors when the argument of pragma
7025 -- Extensions_Visible is not a valid static Boolean expression.
7027 if Error_Posted
(Expr
) then
7028 return Extensions_Visible_None
;
7030 elsif Is_True
(Expr_Value
(Expr
)) then
7031 return Extensions_Visible_True
;
7034 return Extensions_Visible_False
;
7037 -- Otherwise the aspect or pragma defaults to True
7040 return Extensions_Visible_True
;
7043 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7044 -- directly specified. In SPARK code, its value defaults to "False".
7046 elsif SPARK_Mode
= On
then
7047 return Extensions_Visible_False
;
7049 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7053 return Extensions_Visible_True
;
7055 end Extensions_Visible_Status
;
7061 procedure Find_Actual
7063 Formal
: out Entity_Id
;
7066 Context
: constant Node_Id
:= Parent
(N
);
7071 if Nkind_In
(Context
, N_Indexed_Component
, N_Selected_Component
)
7072 and then N
= Prefix
(Context
)
7074 Find_Actual
(Context
, Formal
, Call
);
7077 elsif Nkind
(Context
) = N_Parameter_Association
7078 and then N
= Explicit_Actual_Parameter
(Context
)
7080 Call
:= Parent
(Context
);
7082 elsif Nkind_In
(Context
, N_Entry_Call_Statement
,
7084 N_Procedure_Call_Statement
)
7094 -- If we have a call to a subprogram look for the parameter. Note that
7095 -- we exclude overloaded calls, since we don't know enough to be sure
7096 -- of giving the right answer in this case.
7098 if Nkind_In
(Call
, N_Entry_Call_Statement
,
7100 N_Procedure_Call_Statement
)
7102 Call_Nam
:= Name
(Call
);
7104 -- A call to a protected or task entry appears as a selected
7105 -- component rather than an expanded name.
7107 if Nkind
(Call_Nam
) = N_Selected_Component
then
7108 Call_Nam
:= Selector_Name
(Call_Nam
);
7111 if Is_Entity_Name
(Call_Nam
)
7112 and then Present
(Entity
(Call_Nam
))
7113 and then Is_Overloadable
(Entity
(Call_Nam
))
7114 and then not Is_Overloaded
(Call_Nam
)
7116 -- If node is name in call it is not an actual
7118 if N
= Call_Nam
then
7124 -- Fall here if we are definitely a parameter
7126 Actual
:= First_Actual
(Call
);
7127 Formal
:= First_Formal
(Entity
(Call_Nam
));
7128 while Present
(Formal
) and then Present
(Actual
) loop
7132 -- An actual that is the prefix in a prefixed call may have
7133 -- been rewritten in the call, after the deferred reference
7134 -- was collected. Check if sloc and kinds and names match.
7136 elsif Sloc
(Actual
) = Sloc
(N
)
7137 and then Nkind
(Actual
) = N_Identifier
7138 and then Nkind
(Actual
) = Nkind
(N
)
7139 and then Chars
(Actual
) = Chars
(N
)
7144 Actual
:= Next_Actual
(Actual
);
7145 Formal
:= Next_Formal
(Formal
);
7151 -- Fall through here if we did not find matching actual
7157 ---------------------------
7158 -- Find_Body_Discriminal --
7159 ---------------------------
7161 function Find_Body_Discriminal
7162 (Spec_Discriminant
: Entity_Id
) return Entity_Id
7168 -- If expansion is suppressed, then the scope can be the concurrent type
7169 -- itself rather than a corresponding concurrent record type.
7171 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
7172 Tsk
:= Scope
(Spec_Discriminant
);
7175 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
7177 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
7180 -- Find discriminant of original concurrent type, and use its current
7181 -- discriminal, which is the renaming within the task/protected body.
7183 Disc
:= First_Discriminant
(Tsk
);
7184 while Present
(Disc
) loop
7185 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
7186 return Discriminal
(Disc
);
7189 Next_Discriminant
(Disc
);
7192 -- That loop should always succeed in finding a matching entry and
7193 -- returning. Fatal error if not.
7195 raise Program_Error
;
7196 end Find_Body_Discriminal
;
7198 -------------------------------------
7199 -- Find_Corresponding_Discriminant --
7200 -------------------------------------
7202 function Find_Corresponding_Discriminant
7204 Typ
: Entity_Id
) return Entity_Id
7206 Par_Disc
: Entity_Id
;
7207 Old_Disc
: Entity_Id
;
7208 New_Disc
: Entity_Id
;
7211 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
7213 -- The original type may currently be private, and the discriminant
7214 -- only appear on its full view.
7216 if Is_Private_Type
(Scope
(Par_Disc
))
7217 and then not Has_Discriminants
(Scope
(Par_Disc
))
7218 and then Present
(Full_View
(Scope
(Par_Disc
)))
7220 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
7222 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
7225 if Is_Class_Wide_Type
(Typ
) then
7226 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
7228 New_Disc
:= First_Discriminant
(Typ
);
7231 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
7232 if Old_Disc
= Par_Disc
then
7236 Next_Discriminant
(Old_Disc
);
7237 Next_Discriminant
(New_Disc
);
7240 -- Should always find it
7242 raise Program_Error
;
7243 end Find_Corresponding_Discriminant
;
7245 ----------------------------------
7246 -- Find_Enclosing_Iterator_Loop --
7247 ----------------------------------
7249 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
7254 -- Traverse the scope chain looking for an iterator loop. Such loops are
7255 -- usually transformed into blocks, hence the use of Original_Node.
7258 while Present
(S
) and then S
/= Standard_Standard
loop
7259 if Ekind
(S
) = E_Loop
7260 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
7262 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
7264 if Nkind
(Constr
) = N_Loop_Statement
7265 and then Present
(Iteration_Scheme
(Constr
))
7266 and then Nkind
(Iterator_Specification
7267 (Iteration_Scheme
(Constr
))) =
7268 N_Iterator_Specification
7278 end Find_Enclosing_Iterator_Loop
;
7280 ------------------------------------
7281 -- Find_Loop_In_Conditional_Block --
7282 ------------------------------------
7284 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
7290 if Nkind
(Stmt
) = N_If_Statement
then
7291 Stmt
:= First
(Then_Statements
(Stmt
));
7294 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
7296 -- Inspect the statements of the conditional block. In general the loop
7297 -- should be the first statement in the statement sequence of the block,
7298 -- but the finalization machinery may have introduced extra object
7301 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
7302 while Present
(Stmt
) loop
7303 if Nkind
(Stmt
) = N_Loop_Statement
then
7310 -- The expansion of attribute 'Loop_Entry produced a malformed block
7312 raise Program_Error
;
7313 end Find_Loop_In_Conditional_Block
;
7315 --------------------------
7316 -- Find_Overlaid_Entity --
7317 --------------------------
7319 procedure Find_Overlaid_Entity
7321 Ent
: out Entity_Id
;
7327 -- We are looking for one of the two following forms:
7329 -- for X'Address use Y'Address
7333 -- Const : constant Address := expr;
7335 -- for X'Address use Const;
7337 -- In the second case, the expr is either Y'Address, or recursively a
7338 -- constant that eventually references Y'Address.
7343 if Nkind
(N
) = N_Attribute_Definition_Clause
7344 and then Chars
(N
) = Name_Address
7346 Expr
:= Expression
(N
);
7348 -- This loop checks the form of the expression for Y'Address,
7349 -- using recursion to deal with intermediate constants.
7352 -- Check for Y'Address
7354 if Nkind
(Expr
) = N_Attribute_Reference
7355 and then Attribute_Name
(Expr
) = Name_Address
7357 Expr
:= Prefix
(Expr
);
7360 -- Check for Const where Const is a constant entity
7362 elsif Is_Entity_Name
(Expr
)
7363 and then Ekind
(Entity
(Expr
)) = E_Constant
7365 Expr
:= Constant_Value
(Entity
(Expr
));
7367 -- Anything else does not need checking
7374 -- This loop checks the form of the prefix for an entity, using
7375 -- recursion to deal with intermediate components.
7378 -- Check for Y where Y is an entity
7380 if Is_Entity_Name
(Expr
) then
7381 Ent
:= Entity
(Expr
);
7384 -- Check for components
7387 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
7389 Expr
:= Prefix
(Expr
);
7392 -- Anything else does not need checking
7399 end Find_Overlaid_Entity
;
7401 -------------------------
7402 -- Find_Parameter_Type --
7403 -------------------------
7405 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
7407 if Nkind
(Param
) /= N_Parameter_Specification
then
7410 -- For an access parameter, obtain the type from the formal entity
7411 -- itself, because access to subprogram nodes do not carry a type.
7412 -- Shouldn't we always use the formal entity ???
7414 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
7415 return Etype
(Defining_Identifier
(Param
));
7418 return Etype
(Parameter_Type
(Param
));
7420 end Find_Parameter_Type
;
7422 -----------------------------------
7423 -- Find_Placement_In_State_Space --
7424 -----------------------------------
7426 procedure Find_Placement_In_State_Space
7427 (Item_Id
: Entity_Id
;
7428 Placement
: out State_Space_Kind
;
7429 Pack_Id
: out Entity_Id
)
7431 Context
: Entity_Id
;
7434 -- Assume that the item does not appear in the state space of a package
7436 Placement
:= Not_In_Package
;
7439 -- Climb the scope stack and examine the enclosing context
7441 Context
:= Scope
(Item_Id
);
7442 while Present
(Context
) and then Context
/= Standard_Standard
loop
7443 if Ekind
(Context
) = E_Package
then
7446 -- A package body is a cut off point for the traversal as the item
7447 -- cannot be visible to the outside from this point on. Note that
7448 -- this test must be done first as a body is also classified as a
7451 if In_Package_Body
(Context
) then
7452 Placement
:= Body_State_Space
;
7455 -- The private part of a package is a cut off point for the
7456 -- traversal as the item cannot be visible to the outside from
7459 elsif In_Private_Part
(Context
) then
7460 Placement
:= Private_State_Space
;
7463 -- When the item appears in the visible state space of a package,
7464 -- continue to climb the scope stack as this may not be the final
7468 Placement
:= Visible_State_Space
;
7470 -- The visible state space of a child unit acts as the proper
7471 -- placement of an item.
7473 if Is_Child_Unit
(Context
) then
7478 -- The item or its enclosing package appear in a construct that has
7482 Placement
:= Not_In_Package
;
7486 Context
:= Scope
(Context
);
7488 end Find_Placement_In_State_Space
;
7490 ------------------------
7491 -- Find_Specific_Type --
7492 ------------------------
7494 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
7495 Typ
: Entity_Id
:= Root_Type
(CW
);
7498 if Ekind
(Typ
) = E_Incomplete_Type
then
7499 if From_Limited_With
(Typ
) then
7500 Typ
:= Non_Limited_View
(Typ
);
7502 Typ
:= Full_View
(Typ
);
7506 if Is_Private_Type
(Typ
)
7507 and then not Is_Tagged_Type
(Typ
)
7508 and then Present
(Full_View
(Typ
))
7510 return Full_View
(Typ
);
7514 end Find_Specific_Type
;
7516 -----------------------------
7517 -- Find_Static_Alternative --
7518 -----------------------------
7520 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
7521 Expr
: constant Node_Id
:= Expression
(N
);
7522 Val
: constant Uint
:= Expr_Value
(Expr
);
7527 Alt
:= First
(Alternatives
(N
));
7530 if Nkind
(Alt
) /= N_Pragma
then
7531 Choice
:= First
(Discrete_Choices
(Alt
));
7532 while Present
(Choice
) loop
7534 -- Others choice, always matches
7536 if Nkind
(Choice
) = N_Others_Choice
then
7539 -- Range, check if value is in the range
7541 elsif Nkind
(Choice
) = N_Range
then
7543 Val
>= Expr_Value
(Low_Bound
(Choice
))
7545 Val
<= Expr_Value
(High_Bound
(Choice
));
7547 -- Choice is a subtype name. Note that we know it must
7548 -- be a static subtype, since otherwise it would have
7549 -- been diagnosed as illegal.
7551 elsif Is_Entity_Name
(Choice
)
7552 and then Is_Type
(Entity
(Choice
))
7554 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
7555 Assume_Valid
=> False);
7557 -- Choice is a subtype indication
7559 elsif Nkind
(Choice
) = N_Subtype_Indication
then
7561 C
: constant Node_Id
:= Constraint
(Choice
);
7562 R
: constant Node_Id
:= Range_Expression
(C
);
7566 Val
>= Expr_Value
(Low_Bound
(R
))
7568 Val
<= Expr_Value
(High_Bound
(R
));
7571 -- Choice is a simple expression
7574 exit Search
when Val
= Expr_Value
(Choice
);
7582 pragma Assert
(Present
(Alt
));
7585 -- The above loop *must* terminate by finding a match, since
7586 -- we know the case statement is valid, and the value of the
7587 -- expression is known at compile time. When we fall out of
7588 -- the loop, Alt points to the alternative that we know will
7589 -- be selected at run time.
7592 end Find_Static_Alternative
;
7598 function First_Actual
(Node
: Node_Id
) return Node_Id
is
7602 if No
(Parameter_Associations
(Node
)) then
7606 N
:= First
(Parameter_Associations
(Node
));
7608 if Nkind
(N
) = N_Parameter_Association
then
7609 return First_Named_Actual
(Node
);
7619 function Fix_Msg
(Id
: Entity_Id
; Msg
: String) return String is
7620 Is_Task
: constant Boolean :=
7621 Ekind_In
(Id
, E_Task_Body
, E_Task_Type
)
7622 or else Is_Single_Task_Object
(Id
);
7623 Msg_Last
: constant Natural := Msg
'Last;
7624 Msg_Index
: Natural;
7625 Res
: String (Msg
'Range) := (others => ' ');
7626 Res_Index
: Natural;
7629 -- Copy all characters from the input message Msg to result Res with
7630 -- suitable replacements.
7632 Msg_Index
:= Msg
'First;
7633 Res_Index
:= Res
'First;
7634 while Msg_Index
<= Msg_Last
loop
7636 -- Replace "subprogram" with a different word
7638 if Msg_Index
<= Msg_Last
- 10
7639 and then Msg
(Msg_Index
.. Msg_Index
+ 9) = "subprogram"
7641 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
) then
7642 Res
(Res_Index
.. Res_Index
+ 4) := "entry";
7643 Res_Index
:= Res_Index
+ 5;
7646 Res
(Res_Index
.. Res_Index
+ 8) := "task type";
7647 Res_Index
:= Res_Index
+ 9;
7650 Res
(Res_Index
.. Res_Index
+ 9) := "subprogram";
7651 Res_Index
:= Res_Index
+ 10;
7654 Msg_Index
:= Msg_Index
+ 10;
7656 -- Replace "protected" with a different word
7658 elsif Msg_Index
<= Msg_Last
- 9
7659 and then Msg
(Msg_Index
.. Msg_Index
+ 8) = "protected"
7662 Res
(Res_Index
.. Res_Index
+ 3) := "task";
7663 Res_Index
:= Res_Index
+ 4;
7664 Msg_Index
:= Msg_Index
+ 9;
7666 -- Otherwise copy the character
7669 Res
(Res_Index
) := Msg
(Msg_Index
);
7670 Msg_Index
:= Msg_Index
+ 1;
7671 Res_Index
:= Res_Index
+ 1;
7675 return Res
(Res
'First .. Res_Index
- 1);
7678 -----------------------
7679 -- Gather_Components --
7680 -----------------------
7682 procedure Gather_Components
7684 Comp_List
: Node_Id
;
7685 Governed_By
: List_Id
;
7687 Report_Errors
: out Boolean)
7691 Discrete_Choice
: Node_Id
;
7692 Comp_Item
: Node_Id
;
7694 Discrim
: Entity_Id
;
7695 Discrim_Name
: Node_Id
;
7696 Discrim_Value
: Node_Id
;
7699 Report_Errors
:= False;
7701 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
7704 elsif Present
(Component_Items
(Comp_List
)) then
7705 Comp_Item
:= First
(Component_Items
(Comp_List
));
7711 while Present
(Comp_Item
) loop
7713 -- Skip the tag of a tagged record, the interface tags, as well
7714 -- as all items that are not user components (anonymous types,
7715 -- rep clauses, Parent field, controller field).
7717 if Nkind
(Comp_Item
) = N_Component_Declaration
then
7719 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
7721 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
7722 Append_Elmt
(Comp
, Into
);
7730 if No
(Variant_Part
(Comp_List
)) then
7733 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
7734 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
7737 -- Look for the discriminant that governs this variant part.
7738 -- The discriminant *must* be in the Governed_By List
7740 Assoc
:= First
(Governed_By
);
7741 Find_Constraint
: loop
7742 Discrim
:= First
(Choices
(Assoc
));
7743 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
7744 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
7746 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
7747 Chars
(Discrim_Name
))
7748 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
7749 = Chars
(Discrim_Name
);
7751 if No
(Next
(Assoc
)) then
7752 if not Is_Constrained
(Typ
)
7753 and then Is_Derived_Type
(Typ
)
7754 and then Present
(Stored_Constraint
(Typ
))
7756 -- If the type is a tagged type with inherited discriminants,
7757 -- use the stored constraint on the parent in order to find
7758 -- the values of discriminants that are otherwise hidden by an
7759 -- explicit constraint. Renamed discriminants are handled in
7762 -- If several parent discriminants are renamed by a single
7763 -- discriminant of the derived type, the call to obtain the
7764 -- Corresponding_Discriminant field only retrieves the last
7765 -- of them. We recover the constraint on the others from the
7766 -- Stored_Constraint as well.
7773 D
:= First_Discriminant
(Etype
(Typ
));
7774 C
:= First_Elmt
(Stored_Constraint
(Typ
));
7775 while Present
(D
) and then Present
(C
) loop
7776 if Chars
(Discrim_Name
) = Chars
(D
) then
7777 if Is_Entity_Name
(Node
(C
))
7778 and then Entity
(Node
(C
)) = Entity
(Discrim
)
7780 -- D is renamed by Discrim, whose value is given in
7787 Make_Component_Association
(Sloc
(Typ
),
7789 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
7790 Duplicate_Subexpr_No_Checks
(Node
(C
)));
7792 exit Find_Constraint
;
7795 Next_Discriminant
(D
);
7802 if No
(Next
(Assoc
)) then
7803 Error_Msg_NE
(" missing value for discriminant&",
7804 First
(Governed_By
), Discrim_Name
);
7805 Report_Errors
:= True;
7810 end loop Find_Constraint
;
7812 Discrim_Value
:= Expression
(Assoc
);
7814 if not Is_OK_Static_Expression
(Discrim_Value
) then
7816 -- If the variant part is governed by a discriminant of the type
7817 -- this is an error. If the variant part and the discriminant are
7818 -- inherited from an ancestor this is legal (AI05-120) unless the
7819 -- components are being gathered for an aggregate, in which case
7820 -- the caller must check Report_Errors.
7822 if Scope
(Original_Record_Component
7823 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
7826 ("value for discriminant & must be static!",
7827 Discrim_Value
, Discrim
);
7828 Why_Not_Static
(Discrim_Value
);
7831 Report_Errors
:= True;
7835 Search_For_Discriminant_Value
: declare
7841 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
7844 Find_Discrete_Value
: while Present
(Variant
) loop
7845 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
7846 while Present
(Discrete_Choice
) loop
7847 exit Find_Discrete_Value
when
7848 Nkind
(Discrete_Choice
) = N_Others_Choice
;
7850 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
7852 UI_Low
:= Expr_Value
(Low
);
7853 UI_High
:= Expr_Value
(High
);
7855 exit Find_Discrete_Value
when
7856 UI_Low
<= UI_Discrim_Value
7858 UI_High
>= UI_Discrim_Value
;
7860 Next
(Discrete_Choice
);
7863 Next_Non_Pragma
(Variant
);
7864 end loop Find_Discrete_Value
;
7865 end Search_For_Discriminant_Value
;
7867 if No
(Variant
) then
7869 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
7870 Report_Errors
:= True;
7874 -- If we have found the corresponding choice, recursively add its
7875 -- components to the Into list. The nested components are part of
7876 -- the same record type.
7879 (Typ
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
7880 end Gather_Components
;
7882 ------------------------
7883 -- Get_Actual_Subtype --
7884 ------------------------
7886 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
7887 Typ
: constant Entity_Id
:= Etype
(N
);
7888 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
7897 -- If what we have is an identifier that references a subprogram
7898 -- formal, or a variable or constant object, then we get the actual
7899 -- subtype from the referenced entity if one has been built.
7901 if Nkind
(N
) = N_Identifier
7903 (Is_Formal
(Entity
(N
))
7904 or else Ekind
(Entity
(N
)) = E_Constant
7905 or else Ekind
(Entity
(N
)) = E_Variable
)
7906 and then Present
(Actual_Subtype
(Entity
(N
)))
7908 return Actual_Subtype
(Entity
(N
));
7910 -- Actual subtype of unchecked union is always itself. We never need
7911 -- the "real" actual subtype. If we did, we couldn't get it anyway
7912 -- because the discriminant is not available. The restrictions on
7913 -- Unchecked_Union are designed to make sure that this is OK.
7915 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
7918 -- Here for the unconstrained case, we must find actual subtype
7919 -- No actual subtype is available, so we must build it on the fly.
7921 -- Checking the type, not the underlying type, for constrainedness
7922 -- seems to be necessary. Maybe all the tests should be on the type???
7924 elsif (not Is_Constrained
(Typ
))
7925 and then (Is_Array_Type
(Utyp
)
7926 or else (Is_Record_Type
(Utyp
)
7927 and then Has_Discriminants
(Utyp
)))
7928 and then not Has_Unknown_Discriminants
(Utyp
)
7929 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
7931 -- Nothing to do if in spec expression (why not???)
7933 if In_Spec_Expression
then
7936 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
7938 -- If the type has no discriminants, there is no subtype to
7939 -- build, even if the underlying type is discriminated.
7943 -- Else build the actual subtype
7946 Decl
:= Build_Actual_Subtype
(Typ
, N
);
7947 Atyp
:= Defining_Identifier
(Decl
);
7949 -- If Build_Actual_Subtype generated a new declaration then use it
7953 -- The actual subtype is an Itype, so analyze the declaration,
7954 -- but do not attach it to the tree, to get the type defined.
7956 Set_Parent
(Decl
, N
);
7957 Set_Is_Itype
(Atyp
);
7958 Analyze
(Decl
, Suppress
=> All_Checks
);
7959 Set_Associated_Node_For_Itype
(Atyp
, N
);
7960 Set_Has_Delayed_Freeze
(Atyp
, False);
7962 -- We need to freeze the actual subtype immediately. This is
7963 -- needed, because otherwise this Itype will not get frozen
7964 -- at all, and it is always safe to freeze on creation because
7965 -- any associated types must be frozen at this point.
7967 Freeze_Itype
(Atyp
, N
);
7970 -- Otherwise we did not build a declaration, so return original
7977 -- For all remaining cases, the actual subtype is the same as
7978 -- the nominal type.
7983 end Get_Actual_Subtype
;
7985 -------------------------------------
7986 -- Get_Actual_Subtype_If_Available --
7987 -------------------------------------
7989 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
7990 Typ
: constant Entity_Id
:= Etype
(N
);
7993 -- If what we have is an identifier that references a subprogram
7994 -- formal, or a variable or constant object, then we get the actual
7995 -- subtype from the referenced entity if one has been built.
7997 if Nkind
(N
) = N_Identifier
7999 (Is_Formal
(Entity
(N
))
8000 or else Ekind
(Entity
(N
)) = E_Constant
8001 or else Ekind
(Entity
(N
)) = E_Variable
)
8002 and then Present
(Actual_Subtype
(Entity
(N
)))
8004 return Actual_Subtype
(Entity
(N
));
8006 -- Otherwise the Etype of N is returned unchanged
8011 end Get_Actual_Subtype_If_Available
;
8013 ------------------------
8014 -- Get_Body_From_Stub --
8015 ------------------------
8017 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
8019 return Proper_Body
(Unit
(Library_Unit
(N
)));
8020 end Get_Body_From_Stub
;
8022 ---------------------
8023 -- Get_Cursor_Type --
8024 ---------------------
8026 function Get_Cursor_Type
8028 Typ
: Entity_Id
) return Entity_Id
8032 First_Op
: Entity_Id
;
8036 -- If error already detected, return
8038 if Error_Posted
(Aspect
) then
8042 -- The cursor type for an Iterable aspect is the return type of a
8043 -- non-overloaded First primitive operation. Locate association for
8046 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
8048 while Present
(Assoc
) loop
8049 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
8050 First_Op
:= Expression
(Assoc
);
8057 if First_Op
= Any_Id
then
8058 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
8064 -- Locate function with desired name and profile in scope of type
8065 -- In the rare case where the type is an integer type, a base type
8066 -- is created for it, check that the base type of the first formal
8067 -- of First matches the base type of the domain.
8069 Func
:= First_Entity
(Scope
(Typ
));
8070 while Present
(Func
) loop
8071 if Chars
(Func
) = Chars
(First_Op
)
8072 and then Ekind
(Func
) = E_Function
8073 and then Present
(First_Formal
(Func
))
8074 and then Base_Type
(Etype
(First_Formal
(Func
))) = Base_Type
(Typ
)
8075 and then No
(Next_Formal
(First_Formal
(Func
)))
8077 if Cursor
/= Any_Type
then
8079 ("Operation First for iterable type must be unique", Aspect
);
8082 Cursor
:= Etype
(Func
);
8089 -- If not found, no way to resolve remaining primitives.
8091 if Cursor
= Any_Type
then
8093 ("No legal primitive operation First for Iterable type", Aspect
);
8097 end Get_Cursor_Type
;
8099 function Get_Cursor_Type
(Typ
: Entity_Id
) return Entity_Id
is
8101 return Etype
(Get_Iterable_Type_Primitive
(Typ
, Name_First
));
8102 end Get_Cursor_Type
;
8104 -------------------------------
8105 -- Get_Default_External_Name --
8106 -------------------------------
8108 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
8110 Get_Decoded_Name_String
(Chars
(E
));
8112 if Opt
.External_Name_Imp_Casing
= Uppercase
then
8113 Set_Casing
(All_Upper_Case
);
8115 Set_Casing
(All_Lower_Case
);
8119 Make_String_Literal
(Sloc
(E
),
8120 Strval
=> String_From_Name_Buffer
);
8121 end Get_Default_External_Name
;
8123 --------------------------
8124 -- Get_Enclosing_Object --
8125 --------------------------
8127 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
8129 if Is_Entity_Name
(N
) then
8133 when N_Indexed_Component |
8135 N_Selected_Component
=>
8137 -- If not generating code, a dereference may be left implicit.
8138 -- In thoses cases, return Empty.
8140 if Is_Access_Type
(Etype
(Prefix
(N
))) then
8143 return Get_Enclosing_Object
(Prefix
(N
));
8146 when N_Type_Conversion
=>
8147 return Get_Enclosing_Object
(Expression
(N
));
8153 end Get_Enclosing_Object
;
8155 ---------------------------
8156 -- Get_Enum_Lit_From_Pos --
8157 ---------------------------
8159 function Get_Enum_Lit_From_Pos
8162 Loc
: Source_Ptr
) return Node_Id
8164 Btyp
: Entity_Id
:= Base_Type
(T
);
8168 -- In the case where the literal is of type Character, Wide_Character
8169 -- or Wide_Wide_Character or of a type derived from them, there needs
8170 -- to be some special handling since there is no explicit chain of
8171 -- literals to search. Instead, an N_Character_Literal node is created
8172 -- with the appropriate Char_Code and Chars fields.
8174 if Is_Standard_Character_Type
(T
) then
8175 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
8177 Make_Character_Literal
(Loc
,
8179 Char_Literal_Value
=> Pos
);
8181 -- For all other cases, we have a complete table of literals, and
8182 -- we simply iterate through the chain of literal until the one
8183 -- with the desired position value is found.
8186 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
8187 Btyp
:= Full_View
(Btyp
);
8190 Lit
:= First_Literal
(Btyp
);
8191 for J
in 1 .. UI_To_Int
(Pos
) loop
8195 return New_Occurrence_Of
(Lit
, Loc
);
8197 end Get_Enum_Lit_From_Pos
;
8199 ------------------------
8200 -- Get_Generic_Entity --
8201 ------------------------
8203 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
8204 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
8206 if Present
(Renamed_Object
(Ent
)) then
8207 return Renamed_Object
(Ent
);
8211 end Get_Generic_Entity
;
8213 -------------------------------------
8214 -- Get_Incomplete_View_Of_Ancestor --
8215 -------------------------------------
8217 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
8218 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
8219 Par_Scope
: Entity_Id
;
8220 Par_Type
: Entity_Id
;
8223 -- The incomplete view of an ancestor is only relevant for private
8224 -- derived types in child units.
8226 if not Is_Derived_Type
(E
)
8227 or else not Is_Child_Unit
(Cur_Unit
)
8232 Par_Scope
:= Scope
(Cur_Unit
);
8233 if No
(Par_Scope
) then
8237 Par_Type
:= Etype
(Base_Type
(E
));
8239 -- Traverse list of ancestor types until we find one declared in
8240 -- a parent or grandparent unit (two levels seem sufficient).
8242 while Present
(Par_Type
) loop
8243 if Scope
(Par_Type
) = Par_Scope
8244 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
8248 elsif not Is_Derived_Type
(Par_Type
) then
8252 Par_Type
:= Etype
(Base_Type
(Par_Type
));
8256 -- If none found, there is no relevant ancestor type.
8260 end Get_Incomplete_View_Of_Ancestor
;
8262 ----------------------
8263 -- Get_Index_Bounds --
8264 ----------------------
8266 procedure Get_Index_Bounds
(N
: Node_Id
; L
, H
: out Node_Id
) is
8267 Kind
: constant Node_Kind
:= Nkind
(N
);
8271 if Kind
= N_Range
then
8273 H
:= High_Bound
(N
);
8275 elsif Kind
= N_Subtype_Indication
then
8276 R
:= Range_Expression
(Constraint
(N
));
8284 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
8285 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
8288 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
8289 if Error_Posted
(Scalar_Range
(Entity
(N
))) then
8293 elsif Nkind
(Scalar_Range
(Entity
(N
))) = N_Subtype_Indication
then
8294 Get_Index_Bounds
(Scalar_Range
(Entity
(N
)), L
, H
);
8297 L
:= Low_Bound
(Scalar_Range
(Entity
(N
)));
8298 H
:= High_Bound
(Scalar_Range
(Entity
(N
)));
8302 -- N is an expression, indicating a range with one value
8307 end Get_Index_Bounds
;
8309 ---------------------------------
8310 -- Get_Iterable_Type_Primitive --
8311 ---------------------------------
8313 function Get_Iterable_Type_Primitive
8315 Nam
: Name_Id
) return Entity_Id
8317 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
8325 Assoc
:= First
(Component_Associations
(Funcs
));
8326 while Present
(Assoc
) loop
8327 if Chars
(First
(Choices
(Assoc
))) = Nam
then
8328 return Entity
(Expression
(Assoc
));
8331 Assoc
:= Next
(Assoc
);
8336 end Get_Iterable_Type_Primitive
;
8338 ----------------------------------
8339 -- Get_Library_Unit_Name_string --
8340 ----------------------------------
8342 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
8343 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
8346 Get_Unit_Name_String
(Unit_Name_Id
);
8348 -- Remove seven last character (" (spec)" or " (body)")
8350 Name_Len
:= Name_Len
- 7;
8351 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
8352 end Get_Library_Unit_Name_String
;
8354 ------------------------
8355 -- Get_Name_Entity_Id --
8356 ------------------------
8358 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
8360 return Entity_Id
(Get_Name_Table_Int
(Id
));
8361 end Get_Name_Entity_Id
;
8363 ------------------------------
8364 -- Get_Name_From_CTC_Pragma --
8365 ------------------------------
8367 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
8368 Arg
: constant Node_Id
:=
8369 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
8371 return Strval
(Expr_Value_S
(Arg
));
8372 end Get_Name_From_CTC_Pragma
;
8374 -----------------------
8375 -- Get_Parent_Entity --
8376 -----------------------
8378 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
8380 if Nkind
(Unit
) = N_Package_Body
8381 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
8383 return Defining_Entity
8384 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
8385 elsif Nkind
(Unit
) = N_Package_Instantiation
then
8386 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
8388 return Defining_Entity
(Unit
);
8390 end Get_Parent_Entity
;
8396 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
8398 return Get_Pragma_Id
(Pragma_Name
(N
));
8401 ------------------------
8402 -- Get_Qualified_Name --
8403 ------------------------
8405 function Get_Qualified_Name
8407 Suffix
: Entity_Id
:= Empty
) return Name_Id
8409 Suffix_Nam
: Name_Id
:= No_Name
;
8412 if Present
(Suffix
) then
8413 Suffix_Nam
:= Chars
(Suffix
);
8416 return Get_Qualified_Name
(Chars
(Id
), Suffix_Nam
, Scope
(Id
));
8417 end Get_Qualified_Name
;
8419 function Get_Qualified_Name
8421 Suffix
: Name_Id
:= No_Name
;
8422 Scop
: Entity_Id
:= Current_Scope
) return Name_Id
8424 procedure Add_Scope
(S
: Entity_Id
);
8425 -- Add the fully qualified form of scope S to the name buffer. The
8433 procedure Add_Scope
(S
: Entity_Id
) is
8438 elsif S
= Standard_Standard
then
8442 Add_Scope
(Scope
(S
));
8443 Get_Name_String_And_Append
(Chars
(S
));
8444 Add_Str_To_Name_Buffer
("__");
8448 -- Start of processing for Get_Qualified_Name
8454 -- Append the base name after all scopes have been chained
8456 Get_Name_String_And_Append
(Nam
);
8458 -- Append the suffix (if present)
8460 if Suffix
/= No_Name
then
8461 Add_Str_To_Name_Buffer
("__");
8462 Get_Name_String_And_Append
(Suffix
);
8466 end Get_Qualified_Name
;
8468 -----------------------
8469 -- Get_Reason_String --
8470 -----------------------
8472 procedure Get_Reason_String
(N
: Node_Id
) is
8474 if Nkind
(N
) = N_String_Literal
then
8475 Store_String_Chars
(Strval
(N
));
8477 elsif Nkind
(N
) = N_Op_Concat
then
8478 Get_Reason_String
(Left_Opnd
(N
));
8479 Get_Reason_String
(Right_Opnd
(N
));
8481 -- If not of required form, error
8485 ("Reason for pragma Warnings has wrong form", N
);
8487 ("\must be string literal or concatenation of string literals", N
);
8490 end Get_Reason_String
;
8492 --------------------------------
8493 -- Get_Reference_Discriminant --
8494 --------------------------------
8496 function Get_Reference_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
8500 D
:= First_Discriminant
(Typ
);
8501 while Present
(D
) loop
8502 if Has_Implicit_Dereference
(D
) then
8505 Next_Discriminant
(D
);
8509 end Get_Reference_Discriminant
;
8511 ---------------------------
8512 -- Get_Referenced_Object --
8513 ---------------------------
8515 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
8520 while Is_Entity_Name
(R
)
8521 and then Present
(Renamed_Object
(Entity
(R
)))
8523 R
:= Renamed_Object
(Entity
(R
));
8527 end Get_Referenced_Object
;
8529 ------------------------
8530 -- Get_Renamed_Entity --
8531 ------------------------
8533 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
8538 while Present
(Renamed_Entity
(R
)) loop
8539 R
:= Renamed_Entity
(R
);
8543 end Get_Renamed_Entity
;
8545 -----------------------
8546 -- Get_Return_Object --
8547 -----------------------
8549 function Get_Return_Object
(N
: Node_Id
) return Entity_Id
is
8553 Decl
:= First
(Return_Object_Declarations
(N
));
8554 while Present
(Decl
) loop
8555 exit when Nkind
(Decl
) = N_Object_Declaration
8556 and then Is_Return_Object
(Defining_Identifier
(Decl
));
8560 pragma Assert
(Present
(Decl
));
8561 return Defining_Identifier
(Decl
);
8562 end Get_Return_Object
;
8564 ---------------------------
8565 -- Get_Subprogram_Entity --
8566 ---------------------------
8568 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
8570 Subp_Id
: Entity_Id
;
8573 if Nkind
(Nod
) = N_Accept_Statement
then
8574 Subp
:= Entry_Direct_Name
(Nod
);
8576 elsif Nkind
(Nod
) = N_Slice
then
8577 Subp
:= Prefix
(Nod
);
8583 -- Strip the subprogram call
8586 if Nkind_In
(Subp
, N_Explicit_Dereference
,
8587 N_Indexed_Component
,
8588 N_Selected_Component
)
8590 Subp
:= Prefix
(Subp
);
8592 elsif Nkind_In
(Subp
, N_Type_Conversion
,
8593 N_Unchecked_Type_Conversion
)
8595 Subp
:= Expression
(Subp
);
8602 -- Extract the entity of the subprogram call
8604 if Is_Entity_Name
(Subp
) then
8605 Subp_Id
:= Entity
(Subp
);
8607 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
8608 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
8611 if Is_Subprogram
(Subp_Id
) then
8617 -- The search did not find a construct that denotes a subprogram
8622 end Get_Subprogram_Entity
;
8624 -----------------------------
8625 -- Get_Task_Body_Procedure --
8626 -----------------------------
8628 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
8630 -- Note: A task type may be the completion of a private type with
8631 -- discriminants. When performing elaboration checks on a task
8632 -- declaration, the current view of the type may be the private one,
8633 -- and the procedure that holds the body of the task is held in its
8636 -- This is an odd function, why not have Task_Body_Procedure do
8637 -- the following digging???
8639 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
8640 end Get_Task_Body_Procedure
;
8642 -------------------------
8643 -- Get_User_Defined_Eq --
8644 -------------------------
8646 function Get_User_Defined_Eq
(E
: Entity_Id
) return Entity_Id
is
8651 Prim
:= First_Elmt
(Collect_Primitive_Operations
(E
));
8652 while Present
(Prim
) loop
8655 if Chars
(Op
) = Name_Op_Eq
8656 and then Etype
(Op
) = Standard_Boolean
8657 and then Etype
(First_Formal
(Op
)) = E
8658 and then Etype
(Next_Formal
(First_Formal
(Op
))) = E
8667 end Get_User_Defined_Eq
;
8675 Priv_Typ
: out Entity_Id
;
8676 Full_Typ
: out Entity_Id
;
8677 Full_Base
: out Entity_Id
;
8678 CRec_Typ
: out Entity_Id
)
8681 -- Assume that none of the views can be recovered
8688 -- The input type is private
8690 if Is_Private_Type
(Typ
) then
8692 Full_Typ
:= Full_View
(Priv_Typ
);
8694 if Present
(Full_Typ
) then
8695 Full_Base
:= Base_Type
(Full_Typ
);
8697 if Ekind_In
(Full_Typ
, E_Protected_Type
, E_Task_Type
) then
8698 CRec_Typ
:= Corresponding_Record_Type
(Full_Typ
);
8702 -- The input type is the corresponding record type of a protected or a
8705 elsif Ekind
(Typ
) = E_Record_Type
8706 and then Is_Concurrent_Record_Type
(Typ
)
8709 Full_Typ
:= Corresponding_Concurrent_Type
(CRec_Typ
);
8710 Full_Base
:= Base_Type
(Full_Typ
);
8711 Priv_Typ
:= Incomplete_Or_Partial_View
(Full_Typ
);
8713 -- Otherwise the input type could be the full view of a private type
8717 Full_Base
:= Base_Type
(Full_Typ
);
8719 if Ekind_In
(Full_Typ
, E_Protected_Type
, E_Task_Type
) then
8720 CRec_Typ
:= Corresponding_Record_Type
(Full_Typ
);
8723 -- The type is the full view of a private type, obtain the partial
8726 if Has_Private_Declaration
(Full_Typ
)
8727 and then not Is_Private_Type
(Full_Typ
)
8729 Priv_Typ
:= Incomplete_Or_Partial_View
(Full_Typ
);
8731 -- The full view of a private type should always have a partial
8734 pragma Assert
(Present
(Priv_Typ
));
8739 -----------------------
8740 -- Has_Access_Values --
8741 -----------------------
8743 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
8744 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
8747 -- Case of a private type which is not completed yet. This can only
8748 -- happen in the case of a generic format type appearing directly, or
8749 -- as a component of the type to which this function is being applied
8750 -- at the top level. Return False in this case, since we certainly do
8751 -- not know that the type contains access types.
8756 elsif Is_Access_Type
(Typ
) then
8759 elsif Is_Array_Type
(Typ
) then
8760 return Has_Access_Values
(Component_Type
(Typ
));
8762 elsif Is_Record_Type
(Typ
) then
8767 -- Loop to Check components
8769 Comp
:= First_Component_Or_Discriminant
(Typ
);
8770 while Present
(Comp
) loop
8772 -- Check for access component, tag field does not count, even
8773 -- though it is implemented internally using an access type.
8775 if Has_Access_Values
(Etype
(Comp
))
8776 and then Chars
(Comp
) /= Name_uTag
8781 Next_Component_Or_Discriminant
(Comp
);
8790 end Has_Access_Values
;
8792 ------------------------------
8793 -- Has_Compatible_Alignment --
8794 ------------------------------
8796 function Has_Compatible_Alignment
8799 Layout_Done
: Boolean) return Alignment_Result
8801 function Has_Compatible_Alignment_Internal
8804 Layout_Done
: Boolean;
8805 Default
: Alignment_Result
) return Alignment_Result
;
8806 -- This is the internal recursive function that actually does the work.
8807 -- There is one additional parameter, which says what the result should
8808 -- be if no alignment information is found, and there is no definite
8809 -- indication of compatible alignments. At the outer level, this is set
8810 -- to Unknown, but for internal recursive calls in the case where types
8811 -- are known to be correct, it is set to Known_Compatible.
8813 ---------------------------------------
8814 -- Has_Compatible_Alignment_Internal --
8815 ---------------------------------------
8817 function Has_Compatible_Alignment_Internal
8820 Layout_Done
: Boolean;
8821 Default
: Alignment_Result
) return Alignment_Result
8823 Result
: Alignment_Result
:= Known_Compatible
;
8824 -- Holds the current status of the result. Note that once a value of
8825 -- Known_Incompatible is set, it is sticky and does not get changed
8826 -- to Unknown (the value in Result only gets worse as we go along,
8829 Offs
: Uint
:= No_Uint
;
8830 -- Set to a factor of the offset from the base object when Expr is a
8831 -- selected or indexed component, based on Component_Bit_Offset and
8832 -- Component_Size respectively. A negative value is used to represent
8833 -- a value which is not known at compile time.
8835 procedure Check_Prefix
;
8836 -- Checks the prefix recursively in the case where the expression
8837 -- is an indexed or selected component.
8839 procedure Set_Result
(R
: Alignment_Result
);
8840 -- If R represents a worse outcome (unknown instead of known
8841 -- compatible, or known incompatible), then set Result to R.
8847 procedure Check_Prefix
is
8849 -- The subtlety here is that in doing a recursive call to check
8850 -- the prefix, we have to decide what to do in the case where we
8851 -- don't find any specific indication of an alignment problem.
8853 -- At the outer level, we normally set Unknown as the result in
8854 -- this case, since we can only set Known_Compatible if we really
8855 -- know that the alignment value is OK, but for the recursive
8856 -- call, in the case where the types match, and we have not
8857 -- specified a peculiar alignment for the object, we are only
8858 -- concerned about suspicious rep clauses, the default case does
8859 -- not affect us, since the compiler will, in the absence of such
8860 -- rep clauses, ensure that the alignment is correct.
8862 if Default
= Known_Compatible
8864 (Etype
(Obj
) = Etype
(Expr
)
8865 and then (Unknown_Alignment
(Obj
)
8867 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
8870 (Has_Compatible_Alignment_Internal
8871 (Obj
, Prefix
(Expr
), Layout_Done
, Known_Compatible
));
8873 -- In all other cases, we need a full check on the prefix
8877 (Has_Compatible_Alignment_Internal
8878 (Obj
, Prefix
(Expr
), Layout_Done
, Unknown
));
8886 procedure Set_Result
(R
: Alignment_Result
) is
8893 -- Start of processing for Has_Compatible_Alignment_Internal
8896 -- If Expr is a selected component, we must make sure there is no
8897 -- potentially troublesome component clause and that the record is
8898 -- not packed if the layout is not done.
8900 if Nkind
(Expr
) = N_Selected_Component
then
8902 -- Packing generates unknown alignment if layout is not done
8904 if Is_Packed
(Etype
(Prefix
(Expr
))) and then not Layout_Done
then
8905 Set_Result
(Unknown
);
8908 -- Check prefix and component offset
8911 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
8913 -- If Expr is an indexed component, we must make sure there is no
8914 -- potentially troublesome Component_Size clause and that the array
8915 -- is not bit-packed if the layout is not done.
8917 elsif Nkind
(Expr
) = N_Indexed_Component
then
8919 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
8922 -- Packing generates unknown alignment if layout is not done
8924 if Is_Bit_Packed_Array
(Typ
) and then not Layout_Done
then
8925 Set_Result
(Unknown
);
8928 -- Check prefix and component offset (or at least size)
8931 Offs
:= Indexed_Component_Bit_Offset
(Expr
);
8932 if Offs
= No_Uint
then
8933 Offs
:= Component_Size
(Typ
);
8938 -- If we have a null offset, the result is entirely determined by
8939 -- the base object and has already been computed recursively.
8941 if Offs
= Uint_0
then
8944 -- Case where we know the alignment of the object
8946 elsif Known_Alignment
(Obj
) then
8948 ObjA
: constant Uint
:= Alignment
(Obj
);
8949 ExpA
: Uint
:= No_Uint
;
8950 SizA
: Uint
:= No_Uint
;
8953 -- If alignment of Obj is 1, then we are always OK
8956 Set_Result
(Known_Compatible
);
8958 -- Alignment of Obj is greater than 1, so we need to check
8961 -- If we have an offset, see if it is compatible
8963 if Offs
/= No_Uint
and Offs
> Uint_0
then
8964 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
8965 Set_Result
(Known_Incompatible
);
8968 -- See if Expr is an object with known alignment
8970 elsif Is_Entity_Name
(Expr
)
8971 and then Known_Alignment
(Entity
(Expr
))
8973 ExpA
:= Alignment
(Entity
(Expr
));
8975 -- Otherwise, we can use the alignment of the type of
8976 -- Expr given that we already checked for
8977 -- discombobulating rep clauses for the cases of indexed
8978 -- and selected components above.
8980 elsif Known_Alignment
(Etype
(Expr
)) then
8981 ExpA
:= Alignment
(Etype
(Expr
));
8983 -- Otherwise the alignment is unknown
8986 Set_Result
(Default
);
8989 -- If we got an alignment, see if it is acceptable
8991 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
8992 Set_Result
(Known_Incompatible
);
8995 -- If Expr is not a piece of a larger object, see if size
8996 -- is given. If so, check that it is not too small for the
8997 -- required alignment.
8999 if Offs
/= No_Uint
then
9002 -- See if Expr is an object with known size
9004 elsif Is_Entity_Name
(Expr
)
9005 and then Known_Static_Esize
(Entity
(Expr
))
9007 SizA
:= Esize
(Entity
(Expr
));
9009 -- Otherwise, we check the object size of the Expr type
9011 elsif Known_Static_Esize
(Etype
(Expr
)) then
9012 SizA
:= Esize
(Etype
(Expr
));
9015 -- If we got a size, see if it is a multiple of the Obj
9016 -- alignment, if not, then the alignment cannot be
9017 -- acceptable, since the size is always a multiple of the
9020 if SizA
/= No_Uint
then
9021 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
9022 Set_Result
(Known_Incompatible
);
9028 -- If we do not know required alignment, any non-zero offset is a
9029 -- potential problem (but certainly may be OK, so result is unknown).
9031 elsif Offs
/= No_Uint
then
9032 Set_Result
(Unknown
);
9034 -- If we can't find the result by direct comparison of alignment
9035 -- values, then there is still one case that we can determine known
9036 -- result, and that is when we can determine that the types are the
9037 -- same, and no alignments are specified. Then we known that the
9038 -- alignments are compatible, even if we don't know the alignment
9039 -- value in the front end.
9041 elsif Etype
(Obj
) = Etype
(Expr
) then
9043 -- Types are the same, but we have to check for possible size
9044 -- and alignments on the Expr object that may make the alignment
9045 -- different, even though the types are the same.
9047 if Is_Entity_Name
(Expr
) then
9049 -- First check alignment of the Expr object. Any alignment less
9050 -- than Maximum_Alignment is worrisome since this is the case
9051 -- where we do not know the alignment of Obj.
9053 if Known_Alignment
(Entity
(Expr
))
9054 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
9055 Ttypes
.Maximum_Alignment
9057 Set_Result
(Unknown
);
9059 -- Now check size of Expr object. Any size that is not an
9060 -- even multiple of Maximum_Alignment is also worrisome
9061 -- since it may cause the alignment of the object to be less
9062 -- than the alignment of the type.
9064 elsif Known_Static_Esize
(Entity
(Expr
))
9066 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
9067 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
9070 Set_Result
(Unknown
);
9072 -- Otherwise same type is decisive
9075 Set_Result
(Known_Compatible
);
9079 -- Another case to deal with is when there is an explicit size or
9080 -- alignment clause when the types are not the same. If so, then the
9081 -- result is Unknown. We don't need to do this test if the Default is
9082 -- Unknown, since that result will be set in any case.
9084 elsif Default
/= Unknown
9085 and then (Has_Size_Clause
(Etype
(Expr
))
9087 Has_Alignment_Clause
(Etype
(Expr
)))
9089 Set_Result
(Unknown
);
9091 -- If no indication found, set default
9094 Set_Result
(Default
);
9097 -- Return worst result found
9100 end Has_Compatible_Alignment_Internal
;
9102 -- Start of processing for Has_Compatible_Alignment
9105 -- If Obj has no specified alignment, then set alignment from the type
9106 -- alignment. Perhaps we should always do this, but for sure we should
9107 -- do it when there is an address clause since we can do more if the
9108 -- alignment is known.
9110 if Unknown_Alignment
(Obj
) then
9111 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
9114 -- Now do the internal call that does all the work
9117 Has_Compatible_Alignment_Internal
(Obj
, Expr
, Layout_Done
, Unknown
);
9118 end Has_Compatible_Alignment
;
9120 ----------------------
9121 -- Has_Declarations --
9122 ----------------------
9124 function Has_Declarations
(N
: Node_Id
) return Boolean is
9126 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
9128 N_Compilation_Unit_Aux
,
9134 N_Package_Specification
);
9135 end Has_Declarations
;
9137 ---------------------------------
9138 -- Has_Defaulted_Discriminants --
9139 ---------------------------------
9141 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
9143 return Has_Discriminants
(Typ
)
9144 and then Present
(First_Discriminant
(Typ
))
9145 and then Present
(Discriminant_Default_Value
9146 (First_Discriminant
(Typ
)));
9147 end Has_Defaulted_Discriminants
;
9153 function Has_Denormals
(E
: Entity_Id
) return Boolean is
9155 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
9158 -------------------------------------------
9159 -- Has_Discriminant_Dependent_Constraint --
9160 -------------------------------------------
9162 function Has_Discriminant_Dependent_Constraint
9163 (Comp
: Entity_Id
) return Boolean
9165 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
9166 Subt_Indic
: Node_Id
;
9171 -- Discriminants can't depend on discriminants
9173 if Ekind
(Comp
) = E_Discriminant
then
9177 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
9179 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
9180 Constr
:= Constraint
(Subt_Indic
);
9182 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
9183 Assn
:= First
(Constraints
(Constr
));
9184 while Present
(Assn
) loop
9185 case Nkind
(Assn
) is
9186 when N_Subtype_Indication |
9190 if Depends_On_Discriminant
(Assn
) then
9194 when N_Discriminant_Association
=>
9195 if Depends_On_Discriminant
(Expression
(Assn
)) then
9210 end Has_Discriminant_Dependent_Constraint
;
9212 --------------------------------------
9213 -- Has_Effectively_Volatile_Profile --
9214 --------------------------------------
9216 function Has_Effectively_Volatile_Profile
9217 (Subp_Id
: Entity_Id
) return Boolean
9222 -- Inspect the formal parameters looking for an effectively volatile
9225 Formal
:= First_Formal
(Subp_Id
);
9226 while Present
(Formal
) loop
9227 if Is_Effectively_Volatile
(Etype
(Formal
)) then
9231 Next_Formal
(Formal
);
9234 -- Inspect the return type of functions
9236 if Ekind_In
(Subp_Id
, E_Function
, E_Generic_Function
)
9237 and then Is_Effectively_Volatile
(Etype
(Subp_Id
))
9243 end Has_Effectively_Volatile_Profile
;
9245 --------------------------
9246 -- Has_Enabled_Property --
9247 --------------------------
9249 function Has_Enabled_Property
9250 (Item_Id
: Entity_Id
;
9251 Property
: Name_Id
) return Boolean
9253 function State_Has_Enabled_Property
return Boolean;
9254 -- Determine whether a state denoted by Item_Id has the property enabled
9256 function Variable_Has_Enabled_Property
return Boolean;
9257 -- Determine whether a variable denoted by Item_Id has the property
9260 --------------------------------
9261 -- State_Has_Enabled_Property --
9262 --------------------------------
9264 function State_Has_Enabled_Property
return Boolean is
9265 Decl
: constant Node_Id
:= Parent
(Item_Id
);
9273 -- The declaration of an external abstract state appears as an
9274 -- extension aggregate. If this is not the case, properties can never
9277 if Nkind
(Decl
) /= N_Extension_Aggregate
then
9281 -- When External appears as a simple option, it automatically enables
9284 Opt
:= First
(Expressions
(Decl
));
9285 while Present
(Opt
) loop
9286 if Nkind
(Opt
) = N_Identifier
9287 and then Chars
(Opt
) = Name_External
9295 -- When External specifies particular properties, inspect those and
9296 -- find the desired one (if any).
9298 Opt
:= First
(Component_Associations
(Decl
));
9299 while Present
(Opt
) loop
9300 Opt_Nam
:= First
(Choices
(Opt
));
9302 if Nkind
(Opt_Nam
) = N_Identifier
9303 and then Chars
(Opt_Nam
) = Name_External
9305 Props
:= Expression
(Opt
);
9307 -- Multiple properties appear as an aggregate
9309 if Nkind
(Props
) = N_Aggregate
then
9311 -- Simple property form
9313 Prop
:= First
(Expressions
(Props
));
9314 while Present
(Prop
) loop
9315 if Chars
(Prop
) = Property
then
9322 -- Property with expression form
9324 Prop
:= First
(Component_Associations
(Props
));
9325 while Present
(Prop
) loop
9326 Prop_Nam
:= First
(Choices
(Prop
));
9328 -- The property can be represented in two ways:
9329 -- others => <value>
9330 -- <property> => <value>
9332 if Nkind
(Prop_Nam
) = N_Others_Choice
9333 or else (Nkind
(Prop_Nam
) = N_Identifier
9334 and then Chars
(Prop_Nam
) = Property
)
9336 return Is_True
(Expr_Value
(Expression
(Prop
)));
9345 return Chars
(Props
) = Property
;
9353 end State_Has_Enabled_Property
;
9355 -----------------------------------
9356 -- Variable_Has_Enabled_Property --
9357 -----------------------------------
9359 function Variable_Has_Enabled_Property
return Boolean is
9360 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
9361 -- Determine whether property pragma Prag (if present) denotes an
9362 -- enabled property.
9368 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
9372 if Present
(Prag
) then
9373 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
9375 -- The pragma has an optional Boolean expression, the related
9376 -- property is enabled only when the expression evaluates to
9379 if Present
(Arg1
) then
9380 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
)));
9382 -- Otherwise the lack of expression enables the property by
9389 -- The property was never set in the first place
9398 AR
: constant Node_Id
:=
9399 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
9400 AW
: constant Node_Id
:=
9401 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
9402 ER
: constant Node_Id
:=
9403 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
9404 EW
: constant Node_Id
:=
9405 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
9407 -- Start of processing for Variable_Has_Enabled_Property
9410 -- A non-effectively volatile object can never possess external
9413 if not Is_Effectively_Volatile
(Item_Id
) then
9416 -- External properties related to variables come in two flavors -
9417 -- explicit and implicit. The explicit case is characterized by the
9418 -- presence of a property pragma with an optional Boolean flag. The
9419 -- property is enabled when the flag evaluates to True or the flag is
9420 -- missing altogether.
9422 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
9425 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
9428 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
9431 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
9434 -- The implicit case lacks all property pragmas
9436 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
9442 end Variable_Has_Enabled_Property
;
9444 -- Start of processing for Has_Enabled_Property
9447 -- Abstract states and variables have a flexible scheme of specifying
9448 -- external properties.
9450 if Ekind
(Item_Id
) = E_Abstract_State
then
9451 return State_Has_Enabled_Property
;
9453 elsif Ekind
(Item_Id
) = E_Variable
then
9454 return Variable_Has_Enabled_Property
;
9456 -- Otherwise a property is enabled when the related item is effectively
9460 return Is_Effectively_Volatile
(Item_Id
);
9462 end Has_Enabled_Property
;
9464 -------------------------------------
9465 -- Has_Full_Default_Initialization --
9466 -------------------------------------
9468 function Has_Full_Default_Initialization
(Typ
: Entity_Id
) return Boolean is
9474 -- A private type and its full view is fully default initialized when it
9475 -- is subject to pragma Default_Initial_Condition without an argument or
9476 -- with a non-null argument. Since any type may act as the full view of
9477 -- a private type, this check must be performed prior to the specialized
9480 if Has_Default_Init_Cond
(Typ
)
9481 or else Has_Inherited_Default_Init_Cond
(Typ
)
9483 Prag
:= Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
9485 -- Pragma Default_Initial_Condition must be present if one of the
9486 -- related entity flags is set.
9488 pragma Assert
(Present
(Prag
));
9489 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
9491 -- A non-null argument guarantees full default initialization
9493 if Present
(Arg
) then
9494 return Nkind
(Arg
) /= N_Null
;
9496 -- Otherwise the missing argument defaults the pragma to "True" which
9497 -- is considered a non-null argument (see above).
9504 -- A scalar type is fully default initialized if it is subject to aspect
9507 if Is_Scalar_Type
(Typ
) then
9508 return Has_Default_Aspect
(Typ
);
9510 -- An array type is fully default initialized if its element type is
9511 -- scalar and the array type carries aspect Default_Component_Value or
9512 -- the element type is fully default initialized.
9514 elsif Is_Array_Type
(Typ
) then
9516 Has_Default_Aspect
(Typ
)
9517 or else Has_Full_Default_Initialization
(Component_Type
(Typ
));
9519 -- A protected type, record type, or type extension is fully default
9520 -- initialized if all its components either carry an initialization
9521 -- expression or have a type that is fully default initialized. The
9522 -- parent type of a type extension must be fully default initialized.
9524 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
9526 -- Inspect all entities defined in the scope of the type, looking for
9527 -- uninitialized components.
9529 Comp
:= First_Entity
(Typ
);
9530 while Present
(Comp
) loop
9531 if Ekind
(Comp
) = E_Component
9532 and then Comes_From_Source
(Comp
)
9533 and then No
(Expression
(Parent
(Comp
)))
9534 and then not Has_Full_Default_Initialization
(Etype
(Comp
))
9542 -- Ensure that the parent type of a type extension is fully default
9545 if Etype
(Typ
) /= Typ
9546 and then not Has_Full_Default_Initialization
(Etype
(Typ
))
9551 -- If we get here, then all components and parent portion are fully
9552 -- default initialized.
9556 -- A task type is fully default initialized by default
9558 elsif Is_Task_Type
(Typ
) then
9561 -- Otherwise the type is not fully default initialized
9566 end Has_Full_Default_Initialization
;
9568 --------------------
9569 -- Has_Infinities --
9570 --------------------
9572 function Has_Infinities
(E
: Entity_Id
) return Boolean is
9575 Is_Floating_Point_Type
(E
)
9576 and then Nkind
(Scalar_Range
(E
)) = N_Range
9577 and then Includes_Infinities
(Scalar_Range
(E
));
9580 --------------------
9581 -- Has_Interfaces --
9582 --------------------
9584 function Has_Interfaces
9586 Use_Full_View
: Boolean := True) return Boolean
9588 Typ
: Entity_Id
:= Base_Type
(T
);
9591 -- Handle concurrent types
9593 if Is_Concurrent_Type
(Typ
) then
9594 Typ
:= Corresponding_Record_Type
(Typ
);
9597 if not Present
(Typ
)
9598 or else not Is_Record_Type
(Typ
)
9599 or else not Is_Tagged_Type
(Typ
)
9604 -- Handle private types
9606 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
9607 Typ
:= Full_View
(Typ
);
9610 -- Handle concurrent record types
9612 if Is_Concurrent_Record_Type
(Typ
)
9613 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
9619 if Is_Interface
(Typ
)
9621 (Is_Record_Type
(Typ
)
9622 and then Present
(Interfaces
(Typ
))
9623 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
9628 exit when Etype
(Typ
) = Typ
9630 -- Handle private types
9632 or else (Present
(Full_View
(Etype
(Typ
)))
9633 and then Full_View
(Etype
(Typ
)) = Typ
)
9635 -- Protect frontend against wrong sources with cyclic derivations
9637 or else Etype
(Typ
) = T
;
9639 -- Climb to the ancestor type handling private types
9641 if Present
(Full_View
(Etype
(Typ
))) then
9642 Typ
:= Full_View
(Etype
(Typ
));
9651 ---------------------------------
9652 -- Has_No_Obvious_Side_Effects --
9653 ---------------------------------
9655 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
9657 -- For now, just handle literals, constants, and non-volatile
9658 -- variables and expressions combining these with operators or
9659 -- short circuit forms.
9661 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
9664 elsif Nkind
(N
) = N_Character_Literal
then
9667 elsif Nkind
(N
) in N_Unary_Op
then
9668 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
9670 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
9671 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
9673 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
9675 elsif Nkind
(N
) = N_Expression_With_Actions
9676 and then Is_Empty_List
(Actions
(N
))
9678 return Has_No_Obvious_Side_Effects
(Expression
(N
));
9680 elsif Nkind
(N
) in N_Has_Entity
then
9681 return Present
(Entity
(N
))
9682 and then Ekind_In
(Entity
(N
), E_Variable
,
9684 E_Enumeration_Literal
,
9688 and then not Is_Volatile
(Entity
(N
));
9693 end Has_No_Obvious_Side_Effects
;
9695 -----------------------------
9696 -- Has_Non_Null_Refinement --
9697 -----------------------------
9699 function Has_Non_Null_Refinement
(Id
: Entity_Id
) return Boolean is
9700 Constits
: Elist_Id
;
9703 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
9704 Constits
:= Refinement_Constituents
(Id
);
9706 -- For a refinement to be non-null, the first constituent must be
9707 -- anything other than null.
9711 and then Nkind
(Node
(First_Elmt
(Constits
))) /= N_Null
;
9712 end Has_Non_Null_Refinement
;
9718 function Has_Null_Body
(Proc_Id
: Entity_Id
) return Boolean is
9719 Body_Id
: Entity_Id
;
9726 Spec
:= Parent
(Proc_Id
);
9727 Decl
:= Parent
(Spec
);
9729 -- Retrieve the entity of the procedure body (e.g. invariant proc).
9731 if Nkind
(Spec
) = N_Procedure_Specification
9732 and then Nkind
(Decl
) = N_Subprogram_Declaration
9734 Body_Id
:= Corresponding_Body
(Decl
);
9736 -- The body acts as a spec
9742 -- The body will be generated later
9744 if No
(Body_Id
) then
9748 Spec
:= Parent
(Body_Id
);
9749 Decl
:= Parent
(Spec
);
9752 (Nkind
(Spec
) = N_Procedure_Specification
9753 and then Nkind
(Decl
) = N_Subprogram_Body
);
9755 Stmt1
:= First
(Statements
(Handled_Statement_Sequence
(Decl
)));
9757 -- Look for a null statement followed by an optional return
9760 if Nkind
(Stmt1
) = N_Null_Statement
then
9761 Stmt2
:= Next
(Stmt1
);
9763 if Present
(Stmt2
) then
9764 return Nkind
(Stmt2
) = N_Simple_Return_Statement
;
9773 ------------------------
9774 -- Has_Null_Exclusion --
9775 ------------------------
9777 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
9780 when N_Access_Definition |
9781 N_Access_Function_Definition |
9782 N_Access_Procedure_Definition |
9783 N_Access_To_Object_Definition |
9785 N_Derived_Type_Definition |
9786 N_Function_Specification |
9787 N_Subtype_Declaration
=>
9788 return Null_Exclusion_Present
(N
);
9790 when N_Component_Definition |
9791 N_Formal_Object_Declaration |
9792 N_Object_Renaming_Declaration
=>
9793 if Present
(Subtype_Mark
(N
)) then
9794 return Null_Exclusion_Present
(N
);
9795 else pragma Assert
(Present
(Access_Definition
(N
)));
9796 return Null_Exclusion_Present
(Access_Definition
(N
));
9799 when N_Discriminant_Specification
=>
9800 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
9801 return Null_Exclusion_Present
(Discriminant_Type
(N
));
9803 return Null_Exclusion_Present
(N
);
9806 when N_Object_Declaration
=>
9807 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
9808 return Null_Exclusion_Present
(Object_Definition
(N
));
9810 return Null_Exclusion_Present
(N
);
9813 when N_Parameter_Specification
=>
9814 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
9815 return Null_Exclusion_Present
(Parameter_Type
(N
));
9817 return Null_Exclusion_Present
(N
);
9824 end Has_Null_Exclusion
;
9826 ------------------------
9827 -- Has_Null_Extension --
9828 ------------------------
9830 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
9831 B
: constant Entity_Id
:= Base_Type
(T
);
9836 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
9837 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
9839 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
9841 if Present
(Ext
) then
9842 if Null_Present
(Ext
) then
9845 Comps
:= Component_List
(Ext
);
9847 -- The null component list is rewritten during analysis to
9848 -- include the parent component. Any other component indicates
9849 -- that the extension was not originally null.
9851 return Null_Present
(Comps
)
9852 or else No
(Next
(First
(Component_Items
(Comps
))));
9861 end Has_Null_Extension
;
9863 -------------------------
9864 -- Has_Null_Refinement --
9865 -------------------------
9867 function Has_Null_Refinement
(Id
: Entity_Id
) return Boolean is
9868 Constits
: Elist_Id
;
9871 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
9872 Constits
:= Refinement_Constituents
(Id
);
9874 -- For a refinement to be null, the state's sole constituent must be a
9879 and then Nkind
(Node
(First_Elmt
(Constits
))) = N_Null
;
9880 end Has_Null_Refinement
;
9882 -------------------------------
9883 -- Has_Overriding_Initialize --
9884 -------------------------------
9886 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
9887 BT
: constant Entity_Id
:= Base_Type
(T
);
9891 if Is_Controlled
(BT
) then
9892 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
9895 elsif Present
(Primitive_Operations
(BT
)) then
9896 P
:= First_Elmt
(Primitive_Operations
(BT
));
9897 while Present
(P
) loop
9899 Init
: constant Entity_Id
:= Node
(P
);
9900 Formal
: constant Entity_Id
:= First_Formal
(Init
);
9902 if Ekind
(Init
) = E_Procedure
9903 and then Chars
(Init
) = Name_Initialize
9904 and then Comes_From_Source
(Init
)
9905 and then Present
(Formal
)
9906 and then Etype
(Formal
) = BT
9907 and then No
(Next_Formal
(Formal
))
9908 and then (Ada_Version
< Ada_2012
9909 or else not Null_Present
(Parent
(Init
)))
9919 -- Here if type itself does not have a non-null Initialize operation:
9920 -- check immediate ancestor.
9922 if Is_Derived_Type
(BT
)
9923 and then Has_Overriding_Initialize
(Etype
(BT
))
9930 end Has_Overriding_Initialize
;
9932 --------------------------------------
9933 -- Has_Preelaborable_Initialization --
9934 --------------------------------------
9936 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
9939 procedure Check_Components
(E
: Entity_Id
);
9940 -- Check component/discriminant chain, sets Has_PE False if a component
9941 -- or discriminant does not meet the preelaborable initialization rules.
9943 ----------------------
9944 -- Check_Components --
9945 ----------------------
9947 procedure Check_Components
(E
: Entity_Id
) is
9951 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
9952 -- Returns True if and only if the expression denoted by N does not
9953 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
9955 ---------------------------------
9956 -- Is_Preelaborable_Expression --
9957 ---------------------------------
9959 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
9963 Comp_Type
: Entity_Id
;
9964 Is_Array_Aggr
: Boolean;
9967 if Is_OK_Static_Expression
(N
) then
9970 elsif Nkind
(N
) = N_Null
then
9973 -- Attributes are allowed in general, even if their prefix is a
9974 -- formal type. (It seems that certain attributes known not to be
9975 -- static might not be allowed, but there are no rules to prevent
9978 elsif Nkind
(N
) = N_Attribute_Reference
then
9981 -- The name of a discriminant evaluated within its parent type is
9982 -- defined to be preelaborable (10.2.1(8)). Note that we test for
9983 -- names that denote discriminals as well as discriminants to
9984 -- catch references occurring within init procs.
9986 elsif Is_Entity_Name
(N
)
9988 (Ekind
(Entity
(N
)) = E_Discriminant
9989 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
9990 and then Present
(Discriminal_Link
(Entity
(N
)))))
9994 elsif Nkind
(N
) = N_Qualified_Expression
then
9995 return Is_Preelaborable_Expression
(Expression
(N
));
9997 -- For aggregates we have to check that each of the associations
9998 -- is preelaborable.
10000 elsif Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
10001 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
10003 if Is_Array_Aggr
then
10004 Comp_Type
:= Component_Type
(Etype
(N
));
10007 -- Check the ancestor part of extension aggregates, which must
10008 -- be either the name of a type that has preelaborable init or
10009 -- an expression that is preelaborable.
10011 if Nkind
(N
) = N_Extension_Aggregate
then
10013 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
10016 if Is_Entity_Name
(Anc_Part
)
10017 and then Is_Type
(Entity
(Anc_Part
))
10019 if not Has_Preelaborable_Initialization
10020 (Entity
(Anc_Part
))
10025 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
10031 -- Check positional associations
10033 Exp
:= First
(Expressions
(N
));
10034 while Present
(Exp
) loop
10035 if not Is_Preelaborable_Expression
(Exp
) then
10042 -- Check named associations
10044 Assn
:= First
(Component_Associations
(N
));
10045 while Present
(Assn
) loop
10046 Choice
:= First
(Choices
(Assn
));
10047 while Present
(Choice
) loop
10048 if Is_Array_Aggr
then
10049 if Nkind
(Choice
) = N_Others_Choice
then
10052 elsif Nkind
(Choice
) = N_Range
then
10053 if not Is_OK_Static_Range
(Choice
) then
10057 elsif not Is_OK_Static_Expression
(Choice
) then
10062 Comp_Type
:= Etype
(Choice
);
10068 -- If the association has a <> at this point, then we have
10069 -- to check whether the component's type has preelaborable
10070 -- initialization. Note that this only occurs when the
10071 -- association's corresponding component does not have a
10072 -- default expression, the latter case having already been
10073 -- expanded as an expression for the association.
10075 if Box_Present
(Assn
) then
10076 if not Has_Preelaborable_Initialization
(Comp_Type
) then
10080 -- In the expression case we check whether the expression
10081 -- is preelaborable.
10084 not Is_Preelaborable_Expression
(Expression
(Assn
))
10092 -- If we get here then aggregate as a whole is preelaborable
10096 -- All other cases are not preelaborable
10101 end Is_Preelaborable_Expression
;
10103 -- Start of processing for Check_Components
10106 -- Loop through entities of record or protected type
10109 while Present
(Ent
) loop
10111 -- We are interested only in components and discriminants
10115 case Ekind
(Ent
) is
10116 when E_Component
=>
10118 -- Get default expression if any. If there is no declaration
10119 -- node, it means we have an internal entity. The parent and
10120 -- tag fields are examples of such entities. For such cases,
10121 -- we just test the type of the entity.
10123 if Present
(Declaration_Node
(Ent
)) then
10124 Exp
:= Expression
(Declaration_Node
(Ent
));
10127 when E_Discriminant
=>
10129 -- Note: for a renamed discriminant, the Declaration_Node
10130 -- may point to the one from the ancestor, and have a
10131 -- different expression, so use the proper attribute to
10132 -- retrieve the expression from the derived constraint.
10134 Exp
:= Discriminant_Default_Value
(Ent
);
10137 goto Check_Next_Entity
;
10140 -- A component has PI if it has no default expression and the
10141 -- component type has PI.
10144 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
10149 -- Require the default expression to be preelaborable
10151 elsif not Is_Preelaborable_Expression
(Exp
) then
10156 <<Check_Next_Entity
>>
10159 end Check_Components
;
10161 -- Start of processing for Has_Preelaborable_Initialization
10164 -- Immediate return if already marked as known preelaborable init. This
10165 -- covers types for which this function has already been called once
10166 -- and returned True (in which case the result is cached), and also
10167 -- types to which a pragma Preelaborable_Initialization applies.
10169 if Known_To_Have_Preelab_Init
(E
) then
10173 -- If the type is a subtype representing a generic actual type, then
10174 -- test whether its base type has preelaborable initialization since
10175 -- the subtype representing the actual does not inherit this attribute
10176 -- from the actual or formal. (but maybe it should???)
10178 if Is_Generic_Actual_Type
(E
) then
10179 return Has_Preelaborable_Initialization
(Base_Type
(E
));
10182 -- All elementary types have preelaborable initialization
10184 if Is_Elementary_Type
(E
) then
10187 -- Array types have PI if the component type has PI
10189 elsif Is_Array_Type
(E
) then
10190 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
10192 -- A derived type has preelaborable initialization if its parent type
10193 -- has preelaborable initialization and (in the case of a derived record
10194 -- extension) if the non-inherited components all have preelaborable
10195 -- initialization. However, a user-defined controlled type with an
10196 -- overriding Initialize procedure does not have preelaborable
10199 elsif Is_Derived_Type
(E
) then
10201 -- If the derived type is a private extension then it doesn't have
10202 -- preelaborable initialization.
10204 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
10208 -- First check whether ancestor type has preelaborable initialization
10210 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
10212 -- If OK, check extension components (if any)
10214 if Has_PE
and then Is_Record_Type
(E
) then
10215 Check_Components
(First_Entity
(E
));
10218 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
10219 -- with a user defined Initialize procedure does not have PI. If
10220 -- the type is untagged, the control primitives come from a component
10221 -- that has already been checked.
10224 and then Is_Controlled
(E
)
10225 and then Is_Tagged_Type
(E
)
10226 and then Has_Overriding_Initialize
(E
)
10231 -- Private types not derived from a type having preelaborable init and
10232 -- that are not marked with pragma Preelaborable_Initialization do not
10233 -- have preelaborable initialization.
10235 elsif Is_Private_Type
(E
) then
10238 -- Record type has PI if it is non private and all components have PI
10240 elsif Is_Record_Type
(E
) then
10242 Check_Components
(First_Entity
(E
));
10244 -- Protected types must not have entries, and components must meet
10245 -- same set of rules as for record components.
10247 elsif Is_Protected_Type
(E
) then
10248 if Has_Entries
(E
) then
10252 Check_Components
(First_Entity
(E
));
10253 Check_Components
(First_Private_Entity
(E
));
10256 -- Type System.Address always has preelaborable initialization
10258 elsif Is_RTE
(E
, RE_Address
) then
10261 -- In all other cases, type does not have preelaborable initialization
10267 -- If type has preelaborable initialization, cache result
10270 Set_Known_To_Have_Preelab_Init
(E
);
10274 end Has_Preelaborable_Initialization
;
10276 ---------------------------
10277 -- Has_Private_Component --
10278 ---------------------------
10280 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
10281 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
10282 Component
: Entity_Id
;
10285 if Error_Posted
(Type_Id
)
10286 or else Error_Posted
(Btype
)
10291 if Is_Class_Wide_Type
(Btype
) then
10292 Btype
:= Root_Type
(Btype
);
10295 if Is_Private_Type
(Btype
) then
10297 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
10300 if No
(Full_View
(Btype
)) then
10301 return not Is_Generic_Type
(Btype
)
10303 not Is_Generic_Type
(Root_Type
(Btype
));
10305 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
10308 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
10312 elsif Is_Array_Type
(Btype
) then
10313 return Has_Private_Component
(Component_Type
(Btype
));
10315 elsif Is_Record_Type
(Btype
) then
10316 Component
:= First_Component
(Btype
);
10317 while Present
(Component
) loop
10318 if Has_Private_Component
(Etype
(Component
)) then
10322 Next_Component
(Component
);
10327 elsif Is_Protected_Type
(Btype
)
10328 and then Present
(Corresponding_Record_Type
(Btype
))
10330 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
10335 end Has_Private_Component
;
10337 ----------------------
10338 -- Has_Signed_Zeros --
10339 ----------------------
10341 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
10343 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
10344 end Has_Signed_Zeros
;
10346 ------------------------------
10347 -- Has_Significant_Contract --
10348 ------------------------------
10350 function Has_Significant_Contract
(Subp_Id
: Entity_Id
) return Boolean is
10351 Subp_Nam
: constant Name_Id
:= Chars
(Subp_Id
);
10354 -- _Finalizer procedure
10356 if Subp_Nam
= Name_uFinalizer
then
10359 -- _Postconditions procedure
10361 elsif Subp_Nam
= Name_uPostconditions
then
10364 -- Predicate function
10366 elsif Ekind
(Subp_Id
) = E_Function
10367 and then Is_Predicate_Function
(Subp_Id
)
10373 elsif Get_TSS_Name
(Subp_Id
) /= TSS_Null
then
10379 end Has_Significant_Contract
;
10381 -----------------------------
10382 -- Has_Static_Array_Bounds --
10383 -----------------------------
10385 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
10386 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
10393 -- Unconstrained types do not have static bounds
10395 if not Is_Constrained
(Typ
) then
10399 -- First treat string literals specially, as the lower bound and length
10400 -- of string literals are not stored like those of arrays.
10402 -- A string literal always has static bounds
10404 if Ekind
(Typ
) = E_String_Literal_Subtype
then
10408 -- Treat all dimensions in turn
10410 Index
:= First_Index
(Typ
);
10411 for Indx
in 1 .. Ndims
loop
10413 -- In case of an illegal index which is not a discrete type, return
10414 -- that the type is not static.
10416 if not Is_Discrete_Type
(Etype
(Index
))
10417 or else Etype
(Index
) = Any_Type
10422 Get_Index_Bounds
(Index
, Low
, High
);
10424 if Error_Posted
(Low
) or else Error_Posted
(High
) then
10428 if Is_OK_Static_Expression
(Low
)
10430 Is_OK_Static_Expression
(High
)
10440 -- If we fall through the loop, all indexes matched
10443 end Has_Static_Array_Bounds
;
10449 function Has_Stream
(T
: Entity_Id
) return Boolean is
10456 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
10459 elsif Is_Array_Type
(T
) then
10460 return Has_Stream
(Component_Type
(T
));
10462 elsif Is_Record_Type
(T
) then
10463 E
:= First_Component
(T
);
10464 while Present
(E
) loop
10465 if Has_Stream
(Etype
(E
)) then
10468 Next_Component
(E
);
10474 elsif Is_Private_Type
(T
) then
10475 return Has_Stream
(Underlying_Type
(T
));
10486 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
10488 Get_Name_String
(Chars
(E
));
10489 return Name_Buffer
(Name_Len
) = Suffix
;
10496 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
10498 Get_Name_String
(Chars
(E
));
10499 Add_Char_To_Name_Buffer
(Suffix
);
10503 -------------------
10504 -- Remove_Suffix --
10505 -------------------
10507 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
10509 pragma Assert
(Has_Suffix
(E
, Suffix
));
10510 Get_Name_String
(Chars
(E
));
10511 Name_Len
:= Name_Len
- 1;
10515 ----------------------------------
10516 -- Replace_Null_By_Null_Address --
10517 ----------------------------------
10519 procedure Replace_Null_By_Null_Address
(N
: Node_Id
) is
10520 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
);
10521 -- Replace operand Op with a reference to Null_Address when the operand
10522 -- denotes a null Address. Other_Op denotes the other operand.
10524 --------------------------
10525 -- Replace_Null_Operand --
10526 --------------------------
10528 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
) is
10530 -- Check the type of the complementary operand since the N_Null node
10531 -- has not been decorated yet.
10533 if Nkind
(Op
) = N_Null
10534 and then Is_Descendant_Of_Address
(Etype
(Other_Op
))
10536 Rewrite
(Op
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(Op
)));
10538 end Replace_Null_Operand
;
10540 -- Start of processing for Replace_Null_By_Null_Address
10543 pragma Assert
(Relaxed_RM_Semantics
);
10544 pragma Assert
(Nkind_In
(N
, N_Null
,
10552 if Nkind
(N
) = N_Null
then
10553 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
10557 L
: constant Node_Id
:= Left_Opnd
(N
);
10558 R
: constant Node_Id
:= Right_Opnd
(N
);
10561 Replace_Null_Operand
(L
, Other_Op
=> R
);
10562 Replace_Null_Operand
(R
, Other_Op
=> L
);
10565 end Replace_Null_By_Null_Address
;
10567 --------------------------
10568 -- Has_Tagged_Component --
10569 --------------------------
10571 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
10575 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
10576 return Has_Tagged_Component
(Underlying_Type
(Typ
));
10578 elsif Is_Array_Type
(Typ
) then
10579 return Has_Tagged_Component
(Component_Type
(Typ
));
10581 elsif Is_Tagged_Type
(Typ
) then
10584 elsif Is_Record_Type
(Typ
) then
10585 Comp
:= First_Component
(Typ
);
10586 while Present
(Comp
) loop
10587 if Has_Tagged_Component
(Etype
(Comp
)) then
10591 Next_Component
(Comp
);
10599 end Has_Tagged_Component
;
10601 -----------------------------
10602 -- Has_Undefined_Reference --
10603 -----------------------------
10605 function Has_Undefined_Reference
(Expr
: Node_Id
) return Boolean is
10606 Has_Undef_Ref
: Boolean := False;
10607 -- Flag set when expression Expr contains at least one undefined
10610 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
;
10611 -- Determine whether N denotes a reference and if it does, whether it is
10614 ----------------------------
10615 -- Is_Undefined_Reference --
10616 ----------------------------
10618 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
is
10620 if Is_Entity_Name
(N
)
10621 and then Present
(Entity
(N
))
10622 and then Entity
(N
) = Any_Id
10624 Has_Undef_Ref
:= True;
10629 end Is_Undefined_Reference
;
10631 procedure Find_Undefined_References
is
10632 new Traverse_Proc
(Is_Undefined_Reference
);
10634 -- Start of processing for Has_Undefined_Reference
10637 Find_Undefined_References
(Expr
);
10639 return Has_Undef_Ref
;
10640 end Has_Undefined_Reference
;
10642 ----------------------------
10643 -- Has_Volatile_Component --
10644 ----------------------------
10646 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
10650 if Has_Volatile_Components
(Typ
) then
10653 elsif Is_Array_Type
(Typ
) then
10654 return Is_Volatile
(Component_Type
(Typ
));
10656 elsif Is_Record_Type
(Typ
) then
10657 Comp
:= First_Component
(Typ
);
10658 while Present
(Comp
) loop
10659 if Is_Volatile_Object
(Comp
) then
10663 Comp
:= Next_Component
(Comp
);
10668 end Has_Volatile_Component
;
10670 -------------------------
10671 -- Implementation_Kind --
10672 -------------------------
10674 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
10675 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
10678 pragma Assert
(Present
(Impl_Prag
));
10679 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
10680 return Chars
(Get_Pragma_Arg
(Arg
));
10681 end Implementation_Kind
;
10683 --------------------------
10684 -- Implements_Interface --
10685 --------------------------
10687 function Implements_Interface
10688 (Typ_Ent
: Entity_Id
;
10689 Iface_Ent
: Entity_Id
;
10690 Exclude_Parents
: Boolean := False) return Boolean
10692 Ifaces_List
: Elist_Id
;
10694 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
10695 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
10698 if Is_Class_Wide_Type
(Typ
) then
10699 Typ
:= Root_Type
(Typ
);
10702 if not Has_Interfaces
(Typ
) then
10706 if Is_Class_Wide_Type
(Iface
) then
10707 Iface
:= Root_Type
(Iface
);
10710 Collect_Interfaces
(Typ
, Ifaces_List
);
10712 Elmt
:= First_Elmt
(Ifaces_List
);
10713 while Present
(Elmt
) loop
10714 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
10715 and then Exclude_Parents
10719 elsif Node
(Elmt
) = Iface
then
10727 end Implements_Interface
;
10729 ------------------------------------
10730 -- In_Assertion_Expression_Pragma --
10731 ------------------------------------
10733 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
10735 Prag
: Node_Id
:= Empty
;
10738 -- Climb the parent chain looking for an enclosing pragma
10741 while Present
(Par
) loop
10742 if Nkind
(Par
) = N_Pragma
then
10746 -- Precondition-like pragmas are expanded into if statements, check
10747 -- the original node instead.
10749 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
10750 Prag
:= Original_Node
(Par
);
10753 -- The expansion of attribute 'Old generates a constant to capture
10754 -- the result of the prefix. If the parent traversal reaches
10755 -- one of these constants, then the node technically came from a
10756 -- postcondition-like pragma. Note that the Ekind is not tested here
10757 -- because N may be the expression of an object declaration which is
10758 -- currently being analyzed. Such objects carry Ekind of E_Void.
10760 elsif Nkind
(Par
) = N_Object_Declaration
10761 and then Constant_Present
(Par
)
10762 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
10766 -- Prevent the search from going too far
10768 elsif Is_Body_Or_Package_Declaration
(Par
) then
10772 Par
:= Parent
(Par
);
10777 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
10778 end In_Assertion_Expression_Pragma
;
10784 function In_Instance
return Boolean is
10785 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
10789 S
:= Current_Scope
;
10790 while Present
(S
) and then S
/= Standard_Standard
loop
10791 if Ekind_In
(S
, E_Function
, E_Package
, E_Procedure
)
10792 and then Is_Generic_Instance
(S
)
10794 -- A child instance is always compiled in the context of a parent
10795 -- instance. Nevertheless, the actuals are not analyzed in an
10796 -- instance context. We detect this case by examining the current
10797 -- compilation unit, which must be a child instance, and checking
10798 -- that it is not currently on the scope stack.
10800 if Is_Child_Unit
(Curr_Unit
)
10801 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
10802 N_Package_Instantiation
10803 and then not In_Open_Scopes
(Curr_Unit
)
10817 ----------------------
10818 -- In_Instance_Body --
10819 ----------------------
10821 function In_Instance_Body
return Boolean is
10825 S
:= Current_Scope
;
10826 while Present
(S
) and then S
/= Standard_Standard
loop
10827 if Ekind_In
(S
, E_Function
, E_Procedure
)
10828 and then Is_Generic_Instance
(S
)
10832 elsif Ekind
(S
) = E_Package
10833 and then In_Package_Body
(S
)
10834 and then Is_Generic_Instance
(S
)
10843 end In_Instance_Body
;
10845 -----------------------------
10846 -- In_Instance_Not_Visible --
10847 -----------------------------
10849 function In_Instance_Not_Visible
return Boolean is
10853 S
:= Current_Scope
;
10854 while Present
(S
) and then S
/= Standard_Standard
loop
10855 if Ekind_In
(S
, E_Function
, E_Procedure
)
10856 and then Is_Generic_Instance
(S
)
10860 elsif Ekind
(S
) = E_Package
10861 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
10862 and then Is_Generic_Instance
(S
)
10871 end In_Instance_Not_Visible
;
10873 ------------------------------
10874 -- In_Instance_Visible_Part --
10875 ------------------------------
10877 function In_Instance_Visible_Part
return Boolean is
10881 S
:= Current_Scope
;
10882 while Present
(S
) and then S
/= Standard_Standard
loop
10883 if Ekind
(S
) = E_Package
10884 and then Is_Generic_Instance
(S
)
10885 and then not In_Package_Body
(S
)
10886 and then not In_Private_Part
(S
)
10895 end In_Instance_Visible_Part
;
10897 ---------------------
10898 -- In_Package_Body --
10899 ---------------------
10901 function In_Package_Body
return Boolean is
10905 S
:= Current_Scope
;
10906 while Present
(S
) and then S
/= Standard_Standard
loop
10907 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
10915 end In_Package_Body
;
10917 --------------------------------
10918 -- In_Parameter_Specification --
10919 --------------------------------
10921 function In_Parameter_Specification
(N
: Node_Id
) return Boolean is
10926 while Present
(PN
) loop
10927 if Nkind
(PN
) = N_Parameter_Specification
then
10935 end In_Parameter_Specification
;
10937 --------------------------
10938 -- In_Pragma_Expression --
10939 --------------------------
10941 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
10948 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
10954 end In_Pragma_Expression
;
10956 ---------------------------
10957 -- In_Pre_Post_Condition --
10958 ---------------------------
10960 function In_Pre_Post_Condition
(N
: Node_Id
) return Boolean is
10962 Prag
: Node_Id
:= Empty
;
10963 Prag_Id
: Pragma_Id
;
10966 -- Climb the parent chain looking for an enclosing pragma
10969 while Present
(Par
) loop
10970 if Nkind
(Par
) = N_Pragma
then
10974 -- Prevent the search from going too far
10976 elsif Is_Body_Or_Package_Declaration
(Par
) then
10980 Par
:= Parent
(Par
);
10983 if Present
(Prag
) then
10984 Prag_Id
:= Get_Pragma_Id
(Prag
);
10987 Prag_Id
= Pragma_Post
10988 or else Prag_Id
= Pragma_Post_Class
10989 or else Prag_Id
= Pragma_Postcondition
10990 or else Prag_Id
= Pragma_Pre
10991 or else Prag_Id
= Pragma_Pre_Class
10992 or else Prag_Id
= Pragma_Precondition
;
10994 -- Otherwise the node is not enclosed by a pre/postcondition pragma
10999 end In_Pre_Post_Condition
;
11001 -------------------------------------
11002 -- In_Reverse_Storage_Order_Object --
11003 -------------------------------------
11005 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
11007 Btyp
: Entity_Id
:= Empty
;
11010 -- Climb up indexed components
11014 case Nkind
(Pref
) is
11015 when N_Selected_Component
=>
11016 Pref
:= Prefix
(Pref
);
11019 when N_Indexed_Component
=>
11020 Pref
:= Prefix
(Pref
);
11028 if Present
(Pref
) then
11029 Btyp
:= Base_Type
(Etype
(Pref
));
11032 return Present
(Btyp
)
11033 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
11034 and then Reverse_Storage_Order
(Btyp
);
11035 end In_Reverse_Storage_Order_Object
;
11037 --------------------------------------
11038 -- In_Subprogram_Or_Concurrent_Unit --
11039 --------------------------------------
11041 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
11046 -- Use scope chain to check successively outer scopes
11048 E
:= Current_Scope
;
11052 if K
in Subprogram_Kind
11053 or else K
in Concurrent_Kind
11054 or else K
in Generic_Subprogram_Kind
11058 elsif E
= Standard_Standard
then
11064 end In_Subprogram_Or_Concurrent_Unit
;
11066 ---------------------
11067 -- In_Visible_Part --
11068 ---------------------
11070 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
11072 return Is_Package_Or_Generic_Package
(Scope_Id
)
11073 and then In_Open_Scopes
(Scope_Id
)
11074 and then not In_Package_Body
(Scope_Id
)
11075 and then not In_Private_Part
(Scope_Id
);
11076 end In_Visible_Part
;
11078 --------------------------------
11079 -- Incomplete_Or_Partial_View --
11080 --------------------------------
11082 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
11083 function Inspect_Decls
11085 Taft
: Boolean := False) return Entity_Id
;
11086 -- Check whether a declarative region contains the incomplete or partial
11089 -------------------
11090 -- Inspect_Decls --
11091 -------------------
11093 function Inspect_Decls
11095 Taft
: Boolean := False) return Entity_Id
11101 Decl
:= First
(Decls
);
11102 while Present
(Decl
) loop
11105 -- The partial view of a Taft-amendment type is an incomplete
11109 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
11110 Match
:= Defining_Identifier
(Decl
);
11113 -- Otherwise look for a private type whose full view matches the
11114 -- input type. Note that this checks full_type_declaration nodes
11115 -- to account for derivations from a private type where the type
11116 -- declaration hold the partial view and the full view is an
11119 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
11120 N_Private_Extension_Declaration
,
11121 N_Private_Type_Declaration
)
11123 Match
:= Defining_Identifier
(Decl
);
11126 -- Guard against unanalyzed entities
11129 and then Is_Type
(Match
)
11130 and then Present
(Full_View
(Match
))
11131 and then Full_View
(Match
) = Id
11146 -- Start of processing for Incomplete_Or_Partial_View
11149 -- Deferred constant or incomplete type case
11151 Prev
:= Current_Entity_In_Scope
(Id
);
11154 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
11155 and then Present
(Full_View
(Prev
))
11156 and then Full_View
(Prev
) = Id
11161 -- Private or Taft amendment type case
11164 Pkg
: constant Entity_Id
:= Scope
(Id
);
11165 Pkg_Decl
: Node_Id
:= Pkg
;
11169 and then Ekind_In
(Pkg
, E_Generic_Package
, E_Package
)
11171 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
11172 Pkg_Decl
:= Parent
(Pkg_Decl
);
11175 -- It is knows that Typ has a private view, look for it in the
11176 -- visible declarations of the enclosing scope. A special case
11177 -- of this is when the two views have been exchanged - the full
11178 -- appears earlier than the private.
11180 if Has_Private_Declaration
(Id
) then
11181 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
11183 -- Exchanged view case, look in the private declarations
11186 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
11191 -- Otherwise if this is the package body, then Typ is a potential
11192 -- Taft amendment type. The incomplete view should be located in
11193 -- the private declarations of the enclosing scope.
11195 elsif In_Package_Body
(Pkg
) then
11196 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
11201 -- The type has no incomplete or private view
11204 end Incomplete_Or_Partial_View
;
11206 ----------------------------------
11207 -- Indexed_Component_Bit_Offset --
11208 ----------------------------------
11210 function Indexed_Component_Bit_Offset
(N
: Node_Id
) return Uint
is
11211 Exp
: constant Node_Id
:= First
(Expressions
(N
));
11212 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
11213 Off
: constant Uint
:= Component_Size
(Typ
);
11217 -- Return early if the component size is not known or variable
11219 if Off
= No_Uint
or else Off
< Uint_0
then
11223 -- Deal with the degenerate case of an empty component
11225 if Off
= Uint_0
then
11229 -- Check that both the index value and the low bound are known
11231 if not Compile_Time_Known_Value
(Exp
) then
11235 Ind
:= First_Index
(Typ
);
11240 if Nkind
(Ind
) = N_Subtype_Indication
then
11241 Ind
:= Constraint
(Ind
);
11243 if Nkind
(Ind
) = N_Range_Constraint
then
11244 Ind
:= Range_Expression
(Ind
);
11248 if Nkind
(Ind
) /= N_Range
11249 or else not Compile_Time_Known_Value
(Low_Bound
(Ind
))
11254 -- Return the scaled offset
11256 return Off
* (Expr_Value
(Exp
) - Expr_Value
(Low_Bound
((Ind
))));
11257 end Indexed_Component_Bit_Offset
;
11259 -----------------------------------------
11260 -- Inherit_Default_Init_Cond_Procedure --
11261 -----------------------------------------
11263 procedure Inherit_Default_Init_Cond_Procedure
(Typ
: Entity_Id
) is
11264 Par_Typ
: constant Entity_Id
:= Etype
(Typ
);
11267 -- A derived type inherits the default initial condition procedure of
11268 -- its parent type.
11270 if No
(Default_Init_Cond_Procedure
(Typ
)) then
11271 Set_Default_Init_Cond_Procedure
11272 (Typ
, Default_Init_Cond_Procedure
(Par_Typ
));
11274 end Inherit_Default_Init_Cond_Procedure
;
11276 ----------------------------
11277 -- Inherit_Rep_Item_Chain --
11278 ----------------------------
11280 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
11282 Next_Item
: Node_Id
;
11285 -- There are several inheritance scenarios to consider depending on
11286 -- whether both types have rep item chains and whether the destination
11287 -- type already inherits part of the source type's rep item chain.
11289 -- 1) The source type lacks a rep item chain
11290 -- From_Typ ---> Empty
11292 -- Typ --------> Item (or Empty)
11294 -- In this case inheritance cannot take place because there are no items
11297 -- 2) The destination type lacks a rep item chain
11298 -- From_Typ ---> Item ---> ...
11300 -- Typ --------> Empty
11302 -- Inheritance takes place by setting the First_Rep_Item of the
11303 -- destination type to the First_Rep_Item of the source type.
11304 -- From_Typ ---> Item ---> ...
11306 -- Typ -----------+
11308 -- 3.1) Both source and destination types have at least one rep item.
11309 -- The destination type does NOT inherit a rep item from the source
11311 -- From_Typ ---> Item ---> Item
11313 -- Typ --------> Item ---> Item
11315 -- Inheritance takes place by setting the Next_Rep_Item of the last item
11316 -- of the destination type to the First_Rep_Item of the source type.
11317 -- From_Typ -------------------> Item ---> Item
11319 -- Typ --------> Item ---> Item --+
11321 -- 3.2) Both source and destination types have at least one rep item.
11322 -- The destination type DOES inherit part of the rep item chain of the
11324 -- From_Typ ---> Item ---> Item ---> Item
11326 -- Typ --------> Item ------+
11328 -- This rare case arises when the full view of a private extension must
11329 -- inherit the rep item chain from the full view of its parent type and
11330 -- the full view of the parent type contains extra rep items. Currently
11331 -- only invariants may lead to such form of inheritance.
11333 -- type From_Typ is tagged private
11334 -- with Type_Invariant'Class => Item_2;
11336 -- type Typ is new From_Typ with private
11337 -- with Type_Invariant => Item_4;
11339 -- At this point the rep item chains contain the following items
11341 -- From_Typ -----------> Item_2 ---> Item_3
11343 -- Typ --------> Item_4 --+
11345 -- The full views of both types may introduce extra invariants
11347 -- type From_Typ is tagged null record
11348 -- with Type_Invariant => Item_1;
11350 -- type Typ is new From_Typ with null record;
11352 -- The full view of Typ would have to inherit any new rep items added to
11353 -- the full view of From_Typ.
11355 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
11357 -- Typ --------> Item_4 --+
11359 -- To achieve this form of inheritance, the destination type must first
11360 -- sever the link between its own rep chain and that of the source type,
11361 -- then inheritance 3.1 takes place.
11363 -- Case 1: The source type lacks a rep item chain
11365 if No
(First_Rep_Item
(From_Typ
)) then
11368 -- Case 2: The destination type lacks a rep item chain
11370 elsif No
(First_Rep_Item
(Typ
)) then
11371 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
11373 -- Case 3: Both the source and destination types have at least one rep
11374 -- item. Traverse the rep item chain of the destination type to find the
11379 Next_Item
:= First_Rep_Item
(Typ
);
11380 while Present
(Next_Item
) loop
11382 -- Detect a link between the destination type's rep chain and that
11383 -- of the source type. There are two possibilities:
11388 -- From_Typ ---> Item_1 --->
11390 -- Typ -----------+
11397 -- From_Typ ---> Item_1 ---> Item_2 --->
11399 -- Typ --------> Item_3 ------+
11403 if Has_Rep_Item
(From_Typ
, Next_Item
) then
11408 Next_Item
:= Next_Rep_Item
(Next_Item
);
11411 -- Inherit the source type's rep item chain
11413 if Present
(Item
) then
11414 Set_Next_Rep_Item
(Item
, First_Rep_Item
(From_Typ
));
11416 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
11419 end Inherit_Rep_Item_Chain
;
11421 ---------------------------------
11422 -- Insert_Explicit_Dereference --
11423 ---------------------------------
11425 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
11426 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
11427 Ent
: Entity_Id
:= Empty
;
11434 Save_Interps
(N
, New_Prefix
);
11437 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
11438 Prefix
=> New_Prefix
));
11440 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
11442 if Is_Overloaded
(New_Prefix
) then
11444 -- The dereference is also overloaded, and its interpretations are
11445 -- the designated types of the interpretations of the original node.
11447 Set_Etype
(N
, Any_Type
);
11449 Get_First_Interp
(New_Prefix
, I
, It
);
11450 while Present
(It
.Nam
) loop
11453 if Is_Access_Type
(T
) then
11454 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
11457 Get_Next_Interp
(I
, It
);
11463 -- Prefix is unambiguous: mark the original prefix (which might
11464 -- Come_From_Source) as a reference, since the new (relocated) one
11465 -- won't be taken into account.
11467 if Is_Entity_Name
(New_Prefix
) then
11468 Ent
:= Entity
(New_Prefix
);
11469 Pref
:= New_Prefix
;
11471 -- For a retrieval of a subcomponent of some composite object,
11472 -- retrieve the ultimate entity if there is one.
11474 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
11475 N_Indexed_Component
)
11477 Pref
:= Prefix
(New_Prefix
);
11478 while Present
(Pref
)
11479 and then Nkind_In
(Pref
, N_Selected_Component
,
11480 N_Indexed_Component
)
11482 Pref
:= Prefix
(Pref
);
11485 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
11486 Ent
:= Entity
(Pref
);
11490 -- Place the reference on the entity node
11492 if Present
(Ent
) then
11493 Generate_Reference
(Ent
, Pref
);
11496 end Insert_Explicit_Dereference
;
11498 ------------------------------------------
11499 -- Inspect_Deferred_Constant_Completion --
11500 ------------------------------------------
11502 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
11506 Decl
:= First
(Decls
);
11507 while Present
(Decl
) loop
11509 -- Deferred constant signature
11511 if Nkind
(Decl
) = N_Object_Declaration
11512 and then Constant_Present
(Decl
)
11513 and then No
(Expression
(Decl
))
11515 -- No need to check internally generated constants
11517 and then Comes_From_Source
(Decl
)
11519 -- The constant is not completed. A full object declaration or a
11520 -- pragma Import complete a deferred constant.
11522 and then not Has_Completion
(Defining_Identifier
(Decl
))
11525 ("constant declaration requires initialization expression",
11526 Defining_Identifier
(Decl
));
11529 Decl
:= Next
(Decl
);
11531 end Inspect_Deferred_Constant_Completion
;
11533 -----------------------------
11534 -- Install_Generic_Formals --
11535 -----------------------------
11537 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
11541 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
11543 E
:= First_Entity
(Subp_Id
);
11544 while Present
(E
) loop
11545 Install_Entity
(E
);
11548 end Install_Generic_Formals
;
11550 -----------------------------
11551 -- Is_Actual_Out_Parameter --
11552 -----------------------------
11554 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
11555 Formal
: Entity_Id
;
11558 Find_Actual
(N
, Formal
, Call
);
11559 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
11560 end Is_Actual_Out_Parameter
;
11562 -------------------------
11563 -- Is_Actual_Parameter --
11564 -------------------------
11566 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
11567 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
11571 when N_Parameter_Association
=>
11572 return N
= Explicit_Actual_Parameter
(Parent
(N
));
11574 when N_Subprogram_Call
=>
11575 return Is_List_Member
(N
)
11577 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
11582 end Is_Actual_Parameter
;
11584 --------------------------------
11585 -- Is_Actual_Tagged_Parameter --
11586 --------------------------------
11588 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
11589 Formal
: Entity_Id
;
11592 Find_Actual
(N
, Formal
, Call
);
11593 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
11594 end Is_Actual_Tagged_Parameter
;
11596 ---------------------
11597 -- Is_Aliased_View --
11598 ---------------------
11600 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
11604 if Is_Entity_Name
(Obj
) then
11611 or else (Present
(Renamed_Object
(E
))
11612 and then Is_Aliased_View
(Renamed_Object
(E
)))))
11614 or else ((Is_Formal
(E
)
11615 or else Ekind_In
(E
, E_Generic_In_Out_Parameter
,
11616 E_Generic_In_Parameter
))
11617 and then Is_Tagged_Type
(Etype
(E
)))
11619 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
11621 -- Current instance of type, either directly or as rewritten
11622 -- reference to the current object.
11624 or else (Is_Entity_Name
(Original_Node
(Obj
))
11625 and then Present
(Entity
(Original_Node
(Obj
)))
11626 and then Is_Type
(Entity
(Original_Node
(Obj
))))
11628 or else (Is_Type
(E
) and then E
= Current_Scope
)
11630 or else (Is_Incomplete_Or_Private_Type
(E
)
11631 and then Full_View
(E
) = Current_Scope
)
11633 -- Ada 2012 AI05-0053: the return object of an extended return
11634 -- statement is aliased if its type is immutably limited.
11636 or else (Is_Return_Object
(E
)
11637 and then Is_Limited_View
(Etype
(E
)));
11639 elsif Nkind
(Obj
) = N_Selected_Component
then
11640 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
11642 elsif Nkind
(Obj
) = N_Indexed_Component
then
11643 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
11645 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
11646 and then Has_Aliased_Components
11647 (Designated_Type
(Etype
(Prefix
(Obj
)))));
11649 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
11650 return Is_Tagged_Type
(Etype
(Obj
))
11651 and then Is_Aliased_View
(Expression
(Obj
));
11653 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
11654 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
11659 end Is_Aliased_View
;
11661 -------------------------
11662 -- Is_Ancestor_Package --
11663 -------------------------
11665 function Is_Ancestor_Package
11667 E2
: Entity_Id
) return Boolean
11673 while Present
(Par
) and then Par
/= Standard_Standard
loop
11678 Par
:= Scope
(Par
);
11682 end Is_Ancestor_Package
;
11684 ----------------------
11685 -- Is_Atomic_Object --
11686 ----------------------
11688 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
11690 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
11691 -- Determines if given object has atomic components
11693 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
11694 -- If prefix is an implicit dereference, examine designated type
11696 ----------------------
11697 -- Is_Atomic_Prefix --
11698 ----------------------
11700 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
11702 if Is_Access_Type
(Etype
(N
)) then
11704 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
11706 return Object_Has_Atomic_Components
(N
);
11708 end Is_Atomic_Prefix
;
11710 ----------------------------------
11711 -- Object_Has_Atomic_Components --
11712 ----------------------------------
11714 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
11716 if Has_Atomic_Components
(Etype
(N
))
11717 or else Is_Atomic
(Etype
(N
))
11721 elsif Is_Entity_Name
(N
)
11722 and then (Has_Atomic_Components
(Entity
(N
))
11723 or else Is_Atomic
(Entity
(N
)))
11727 elsif Nkind
(N
) = N_Selected_Component
11728 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
11732 elsif Nkind
(N
) = N_Indexed_Component
11733 or else Nkind
(N
) = N_Selected_Component
11735 return Is_Atomic_Prefix
(Prefix
(N
));
11740 end Object_Has_Atomic_Components
;
11742 -- Start of processing for Is_Atomic_Object
11745 -- Predicate is not relevant to subprograms
11747 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
11750 elsif Is_Atomic
(Etype
(N
))
11751 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
11755 elsif Nkind
(N
) = N_Selected_Component
11756 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
11760 elsif Nkind
(N
) = N_Indexed_Component
11761 or else Nkind
(N
) = N_Selected_Component
11763 return Is_Atomic_Prefix
(Prefix
(N
));
11768 end Is_Atomic_Object
;
11770 -----------------------------
11771 -- Is_Atomic_Or_VFA_Object --
11772 -----------------------------
11774 function Is_Atomic_Or_VFA_Object
(N
: Node_Id
) return Boolean is
11776 return Is_Atomic_Object
(N
)
11777 or else (Is_Object_Reference
(N
)
11778 and then Is_Entity_Name
(N
)
11779 and then (Is_Volatile_Full_Access
(Entity
(N
))
11781 Is_Volatile_Full_Access
(Etype
(Entity
(N
)))));
11782 end Is_Atomic_Or_VFA_Object
;
11784 -------------------------
11785 -- Is_Attribute_Result --
11786 -------------------------
11788 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
11790 return Nkind
(N
) = N_Attribute_Reference
11791 and then Attribute_Name
(N
) = Name_Result
;
11792 end Is_Attribute_Result
;
11794 -------------------------
11795 -- Is_Attribute_Update --
11796 -------------------------
11798 function Is_Attribute_Update
(N
: Node_Id
) return Boolean is
11800 return Nkind
(N
) = N_Attribute_Reference
11801 and then Attribute_Name
(N
) = Name_Update
;
11802 end Is_Attribute_Update
;
11804 ------------------------------------
11805 -- Is_Body_Or_Package_Declaration --
11806 ------------------------------------
11808 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
11810 return Nkind_In
(N
, N_Entry_Body
,
11812 N_Package_Declaration
,
11816 end Is_Body_Or_Package_Declaration
;
11818 -----------------------
11819 -- Is_Bounded_String --
11820 -----------------------
11822 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
11823 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
11826 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
11827 -- Super_String, or one of the [Wide_]Wide_ versions. This will
11828 -- be True for all the Bounded_String types in instances of the
11829 -- Generic_Bounded_Length generics, and for types derived from those.
11831 return Present
(Under
)
11832 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
11833 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
11834 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
11835 end Is_Bounded_String
;
11837 -------------------------
11838 -- Is_Child_Or_Sibling --
11839 -------------------------
11841 function Is_Child_Or_Sibling
11842 (Pack_1
: Entity_Id
;
11843 Pack_2
: Entity_Id
) return Boolean
11845 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
11846 -- Given an arbitrary package, return the number of "climbs" necessary
11847 -- to reach scope Standard_Standard.
11849 procedure Equalize_Depths
11850 (Pack
: in out Entity_Id
;
11851 Depth
: in out Nat
;
11852 Depth_To_Reach
: Nat
);
11853 -- Given an arbitrary package, its depth and a target depth to reach,
11854 -- climb the scope chain until the said depth is reached. The pointer
11855 -- to the package and its depth a modified during the climb.
11857 ----------------------------
11858 -- Distance_From_Standard --
11859 ----------------------------
11861 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
11868 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
11870 Scop
:= Scope
(Scop
);
11874 end Distance_From_Standard
;
11876 ---------------------
11877 -- Equalize_Depths --
11878 ---------------------
11880 procedure Equalize_Depths
11881 (Pack
: in out Entity_Id
;
11882 Depth
: in out Nat
;
11883 Depth_To_Reach
: Nat
)
11886 -- The package must be at a greater or equal depth
11888 if Depth
< Depth_To_Reach
then
11889 raise Program_Error
;
11892 -- Climb the scope chain until the desired depth is reached
11894 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
11895 Pack
:= Scope
(Pack
);
11896 Depth
:= Depth
- 1;
11898 end Equalize_Depths
;
11902 P_1
: Entity_Id
:= Pack_1
;
11903 P_1_Child
: Boolean := False;
11904 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
11905 P_2
: Entity_Id
:= Pack_2
;
11906 P_2_Child
: Boolean := False;
11907 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
11909 -- Start of processing for Is_Child_Or_Sibling
11913 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
11915 -- Both packages denote the same entity, therefore they cannot be
11916 -- children or siblings.
11921 -- One of the packages is at a deeper level than the other. Note that
11922 -- both may still come from differen hierarchies.
11930 elsif P_1_Depth
> P_2_Depth
then
11933 Depth
=> P_1_Depth
,
11934 Depth_To_Reach
=> P_2_Depth
);
11943 elsif P_2_Depth
> P_1_Depth
then
11946 Depth
=> P_2_Depth
,
11947 Depth_To_Reach
=> P_1_Depth
);
11951 -- At this stage the package pointers have been elevated to the same
11952 -- depth. If the related entities are the same, then one package is a
11953 -- potential child of the other:
11957 -- X became P_1 P_2 or vica versa
11963 return Is_Child_Unit
(Pack_1
);
11965 else pragma Assert
(P_2_Child
);
11966 return Is_Child_Unit
(Pack_2
);
11969 -- The packages may come from the same package chain or from entirely
11970 -- different hierarcies. To determine this, climb the scope stack until
11971 -- a common root is found.
11973 -- (root) (root 1) (root 2)
11978 while Present
(P_1
) and then Present
(P_2
) loop
11980 -- The two packages may be siblings
11983 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
11986 P_1
:= Scope
(P_1
);
11987 P_2
:= Scope
(P_2
);
11992 end Is_Child_Or_Sibling
;
11994 -----------------------------
11995 -- Is_Concurrent_Interface --
11996 -----------------------------
11998 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
12000 return Is_Interface
(T
)
12002 (Is_Protected_Interface
(T
)
12003 or else Is_Synchronized_Interface
(T
)
12004 or else Is_Task_Interface
(T
));
12005 end Is_Concurrent_Interface
;
12007 -----------------------
12008 -- Is_Constant_Bound --
12009 -----------------------
12011 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
12013 if Compile_Time_Known_Value
(Exp
) then
12016 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
12017 return Is_Constant_Object
(Entity
(Exp
))
12018 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
12020 elsif Nkind
(Exp
) in N_Binary_Op
then
12021 return Is_Constant_Bound
(Left_Opnd
(Exp
))
12022 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
12023 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
12028 end Is_Constant_Bound
;
12030 ---------------------------
12031 -- Is_Container_Element --
12032 ---------------------------
12034 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
12035 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
12036 Pref
: constant Node_Id
:= Prefix
(Exp
);
12039 -- Call to an indexing aspect
12041 Cont_Typ
: Entity_Id
;
12042 -- The type of the container being accessed
12044 Elem_Typ
: Entity_Id
;
12045 -- Its element type
12047 Indexing
: Entity_Id
;
12048 Is_Const
: Boolean;
12049 -- Indicates that constant indexing is used, and the element is thus
12052 Ref_Typ
: Entity_Id
;
12053 -- The reference type returned by the indexing operation
12056 -- If C is a container, in a context that imposes the element type of
12057 -- that container, the indexing notation C (X) is rewritten as:
12059 -- Indexing (C, X).Discr.all
12061 -- where Indexing is one of the indexing aspects of the container.
12062 -- If the context does not require a reference, the construct can be
12067 -- First, verify that the construct has the proper form
12069 if not Expander_Active
then
12072 elsif Nkind
(Pref
) /= N_Selected_Component
then
12075 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
12079 Call
:= Prefix
(Pref
);
12080 Ref_Typ
:= Etype
(Call
);
12083 if not Has_Implicit_Dereference
(Ref_Typ
)
12084 or else No
(First
(Parameter_Associations
(Call
)))
12085 or else not Is_Entity_Name
(Name
(Call
))
12090 -- Retrieve type of container object, and its iterator aspects
12092 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
12093 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
12096 if No
(Indexing
) then
12098 -- Container should have at least one indexing operation
12102 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
12104 -- This may be a variable indexing operation
12106 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
12109 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
12118 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
12120 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
12124 -- Check that the expression is not the target of an assignment, in
12125 -- which case the rewriting is not possible.
12127 if not Is_Const
then
12133 while Present
(Par
)
12135 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
12136 and then Par
= Name
(Parent
(Par
))
12140 -- A renaming produces a reference, and the transformation
12143 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
12147 (Nkind
(Parent
(Par
)), N_Function_Call
,
12148 N_Procedure_Call_Statement
,
12149 N_Entry_Call_Statement
)
12151 -- Check that the element is not part of an actual for an
12152 -- in-out parameter.
12159 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
12160 A
:= First
(Parameter_Associations
(Parent
(Par
)));
12161 while Present
(F
) loop
12162 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
12171 -- E_In_Parameter in a call: element is not modified.
12176 Par
:= Parent
(Par
);
12181 -- The expression has the proper form and the context requires the
12182 -- element type. Retrieve the Element function of the container and
12183 -- rewrite the construct as a call to it.
12189 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
12190 while Present
(Op
) loop
12191 exit when Chars
(Node
(Op
)) = Name_Element
;
12200 Make_Function_Call
(Loc
,
12201 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
12202 Parameter_Associations
=> Parameter_Associations
(Call
)));
12203 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
12207 end Is_Container_Element
;
12209 ----------------------------
12210 -- Is_Contract_Annotation --
12211 ----------------------------
12213 function Is_Contract_Annotation
(Item
: Node_Id
) return Boolean is
12215 return Is_Package_Contract_Annotation
(Item
)
12217 Is_Subprogram_Contract_Annotation
(Item
);
12218 end Is_Contract_Annotation
;
12220 --------------------------------------
12221 -- Is_Controlling_Limited_Procedure --
12222 --------------------------------------
12224 function Is_Controlling_Limited_Procedure
12225 (Proc_Nam
: Entity_Id
) return Boolean
12227 Param_Typ
: Entity_Id
:= Empty
;
12230 if Ekind
(Proc_Nam
) = E_Procedure
12231 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
12233 Param_Typ
:= Etype
(Parameter_Type
(First
(
12234 Parameter_Specifications
(Parent
(Proc_Nam
)))));
12236 -- In this case where an Itype was created, the procedure call has been
12239 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
12240 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
12242 Present
(Parameter_Associations
12243 (Associated_Node_For_Itype
(Proc_Nam
)))
12246 Etype
(First
(Parameter_Associations
12247 (Associated_Node_For_Itype
(Proc_Nam
))));
12250 if Present
(Param_Typ
) then
12252 Is_Interface
(Param_Typ
)
12253 and then Is_Limited_Record
(Param_Typ
);
12257 end Is_Controlling_Limited_Procedure
;
12259 -----------------------------
12260 -- Is_CPP_Constructor_Call --
12261 -----------------------------
12263 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
12265 return Nkind
(N
) = N_Function_Call
12266 and then Is_CPP_Class
(Etype
(Etype
(N
)))
12267 and then Is_Constructor
(Entity
(Name
(N
)))
12268 and then Is_Imported
(Entity
(Name
(N
)));
12269 end Is_CPP_Constructor_Call
;
12271 -------------------------
12272 -- Is_Current_Instance --
12273 -------------------------
12275 function Is_Current_Instance
(N
: Node_Id
) return Boolean is
12276 Typ
: constant Entity_Id
:= Entity
(N
);
12280 -- Simplest case: entity is a concurrent type and we are currently
12281 -- inside the body. This will eventually be expanded into a
12282 -- call to Self (for tasks) or _object (for protected objects).
12284 if Is_Concurrent_Type
(Typ
) and then In_Open_Scopes
(Typ
) then
12288 -- Check whether the context is a (sub)type declaration for the
12292 while Present
(P
) loop
12293 if Nkind_In
(P
, N_Full_Type_Declaration
,
12294 N_Private_Type_Declaration
,
12295 N_Subtype_Declaration
)
12296 and then Comes_From_Source
(P
)
12297 and then Defining_Entity
(P
) = Typ
12301 -- A subtype name may appear in an aspect specification for a
12302 -- Predicate_Failure aspect, for which we do not construct a
12303 -- wrapper procedure. The subtype will be replaced by the
12304 -- expression being tested when the corresponding predicate
12305 -- check is expanded.
12307 elsif Nkind
(P
) = N_Aspect_Specification
12308 and then Nkind
(Parent
(P
)) = N_Subtype_Declaration
12312 elsif Nkind
(P
) = N_Pragma
12314 Get_Pragma_Id
(Pragma_Name
(P
)) = Pragma_Predicate_Failure
12323 -- In any other context this is not a current occurrence
12326 end Is_Current_Instance
;
12328 --------------------
12329 -- Is_Declaration --
12330 --------------------
12332 function Is_Declaration
(N
: Node_Id
) return Boolean is
12335 when N_Abstract_Subprogram_Declaration |
12336 N_Exception_Declaration |
12337 N_Exception_Renaming_Declaration |
12338 N_Full_Type_Declaration |
12339 N_Generic_Function_Renaming_Declaration |
12340 N_Generic_Package_Declaration |
12341 N_Generic_Package_Renaming_Declaration |
12342 N_Generic_Procedure_Renaming_Declaration |
12343 N_Generic_Subprogram_Declaration |
12344 N_Number_Declaration |
12345 N_Object_Declaration |
12346 N_Object_Renaming_Declaration |
12347 N_Package_Declaration |
12348 N_Package_Renaming_Declaration |
12349 N_Private_Extension_Declaration |
12350 N_Private_Type_Declaration |
12351 N_Subprogram_Declaration |
12352 N_Subprogram_Renaming_Declaration |
12353 N_Subtype_Declaration
=>
12359 end Is_Declaration
;
12361 --------------------------------
12362 -- Is_Declared_Within_Variant --
12363 --------------------------------
12365 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
12366 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
12367 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
12369 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
12370 end Is_Declared_Within_Variant
;
12372 ----------------------------------------------
12373 -- Is_Dependent_Component_Of_Mutable_Object --
12374 ----------------------------------------------
12376 function Is_Dependent_Component_Of_Mutable_Object
12377 (Object
: Node_Id
) return Boolean
12380 Prefix_Type
: Entity_Id
;
12381 P_Aliased
: Boolean := False;
12384 Deref
: Node_Id
:= Object
;
12385 -- Dereference node, in something like X.all.Y(2)
12387 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
12390 -- Find the dereference node if any
12392 while Nkind_In
(Deref
, N_Indexed_Component
,
12393 N_Selected_Component
,
12396 Deref
:= Prefix
(Deref
);
12399 -- Ada 2005: If we have a component or slice of a dereference,
12400 -- something like X.all.Y (2), and the type of X is access-to-constant,
12401 -- Is_Variable will return False, because it is indeed a constant
12402 -- view. But it might be a view of a variable object, so we want the
12403 -- following condition to be True in that case.
12405 if Is_Variable
(Object
)
12406 or else (Ada_Version
>= Ada_2005
12407 and then Nkind
(Deref
) = N_Explicit_Dereference
)
12409 if Nkind
(Object
) = N_Selected_Component
then
12410 P
:= Prefix
(Object
);
12411 Prefix_Type
:= Etype
(P
);
12413 if Is_Entity_Name
(P
) then
12414 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
12415 Prefix_Type
:= Base_Type
(Prefix_Type
);
12418 if Is_Aliased
(Entity
(P
)) then
12422 -- A discriminant check on a selected component may be expanded
12423 -- into a dereference when removing side-effects. Recover the
12424 -- original node and its type, which may be unconstrained.
12426 elsif Nkind
(P
) = N_Explicit_Dereference
12427 and then not (Comes_From_Source
(P
))
12429 P
:= Original_Node
(P
);
12430 Prefix_Type
:= Etype
(P
);
12433 -- Check for prefix being an aliased component???
12439 -- A heap object is constrained by its initial value
12441 -- Ada 2005 (AI-363): Always assume the object could be mutable in
12442 -- the dereferenced case, since the access value might denote an
12443 -- unconstrained aliased object, whereas in Ada 95 the designated
12444 -- object is guaranteed to be constrained. A worst-case assumption
12445 -- has to apply in Ada 2005 because we can't tell at compile
12446 -- time whether the object is "constrained by its initial value"
12447 -- (despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
12448 -- rules (these rules are acknowledged to need fixing).
12450 if Ada_Version
< Ada_2005
then
12451 if Is_Access_Type
(Prefix_Type
)
12452 or else Nkind
(P
) = N_Explicit_Dereference
12457 else pragma Assert
(Ada_Version
>= Ada_2005
);
12458 if Is_Access_Type
(Prefix_Type
) then
12460 -- If the access type is pool-specific, and there is no
12461 -- constrained partial view of the designated type, then the
12462 -- designated object is known to be constrained.
12464 if Ekind
(Prefix_Type
) = E_Access_Type
12465 and then not Object_Type_Has_Constrained_Partial_View
12466 (Typ
=> Designated_Type
(Prefix_Type
),
12467 Scop
=> Current_Scope
)
12471 -- Otherwise (general access type, or there is a constrained
12472 -- partial view of the designated type), we need to check
12473 -- based on the designated type.
12476 Prefix_Type
:= Designated_Type
(Prefix_Type
);
12482 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
12484 -- As per AI-0017, the renaming is illegal in a generic body, even
12485 -- if the subtype is indefinite.
12487 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
12489 if not Is_Constrained
(Prefix_Type
)
12490 and then (Is_Definite_Subtype
(Prefix_Type
)
12492 (Is_Generic_Type
(Prefix_Type
)
12493 and then Ekind
(Current_Scope
) = E_Generic_Package
12494 and then In_Package_Body
(Current_Scope
)))
12496 and then (Is_Declared_Within_Variant
(Comp
)
12497 or else Has_Discriminant_Dependent_Constraint
(Comp
))
12498 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
12502 -- If the prefix is of an access type at this point, then we want
12503 -- to return False, rather than calling this function recursively
12504 -- on the access object (which itself might be a discriminant-
12505 -- dependent component of some other object, but that isn't
12506 -- relevant to checking the object passed to us). This avoids
12507 -- issuing wrong errors when compiling with -gnatc, where there
12508 -- can be implicit dereferences that have not been expanded.
12510 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
12515 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
12518 elsif Nkind
(Object
) = N_Indexed_Component
12519 or else Nkind
(Object
) = N_Slice
12521 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
12523 -- A type conversion that Is_Variable is a view conversion:
12524 -- go back to the denoted object.
12526 elsif Nkind
(Object
) = N_Type_Conversion
then
12528 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
12533 end Is_Dependent_Component_Of_Mutable_Object
;
12535 ---------------------
12536 -- Is_Dereferenced --
12537 ---------------------
12539 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
12540 P
: constant Node_Id
:= Parent
(N
);
12542 return Nkind_In
(P
, N_Selected_Component
,
12543 N_Explicit_Dereference
,
12544 N_Indexed_Component
,
12546 and then Prefix
(P
) = N
;
12547 end Is_Dereferenced
;
12549 ----------------------
12550 -- Is_Descendant_Of --
12551 ----------------------
12553 function Is_Descendant_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
12558 pragma Assert
(Nkind
(T1
) in N_Entity
);
12559 pragma Assert
(Nkind
(T2
) in N_Entity
);
12561 T
:= Base_Type
(T1
);
12563 -- Immediate return if the types match
12568 -- Comment needed here ???
12570 elsif Ekind
(T
) = E_Class_Wide_Type
then
12571 return Etype
(T
) = T2
;
12579 -- Done if we found the type we are looking for
12584 -- Done if no more derivations to check
12591 -- Following test catches error cases resulting from prev errors
12593 elsif No
(Etyp
) then
12596 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
12599 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
12603 T
:= Base_Type
(Etyp
);
12606 end Is_Descendant_Of
;
12608 ----------------------------------------
12609 -- Is_Descendant_Of_Suspension_Object --
12610 ----------------------------------------
12612 function Is_Descendant_Of_Suspension_Object
12613 (Typ
: Entity_Id
) return Boolean
12615 Cur_Typ
: Entity_Id
;
12616 Par_Typ
: Entity_Id
;
12619 -- Climb the type derivation chain checking each parent type against
12620 -- Suspension_Object.
12622 Cur_Typ
:= Base_Type
(Typ
);
12623 while Present
(Cur_Typ
) loop
12624 Par_Typ
:= Etype
(Cur_Typ
);
12626 -- The current type is a match
12628 if Is_Suspension_Object
(Cur_Typ
) then
12631 -- Stop the traversal once the root of the derivation chain has been
12632 -- reached. In that case the current type is its own base type.
12634 elsif Cur_Typ
= Par_Typ
then
12638 Cur_Typ
:= Base_Type
(Par_Typ
);
12642 end Is_Descendant_Of_Suspension_Object
;
12644 ---------------------------------------------
12645 -- Is_Double_Precision_Floating_Point_Type --
12646 ---------------------------------------------
12648 function Is_Double_Precision_Floating_Point_Type
12649 (E
: Entity_Id
) return Boolean is
12651 return Is_Floating_Point_Type
(E
)
12652 and then Machine_Radix_Value
(E
) = Uint_2
12653 and then Machine_Mantissa_Value
(E
) = UI_From_Int
(53)
12654 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_10
12655 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_10
);
12656 end Is_Double_Precision_Floating_Point_Type
;
12658 -----------------------------
12659 -- Is_Effectively_Volatile --
12660 -----------------------------
12662 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
12664 if Is_Type
(Id
) then
12666 -- An arbitrary type is effectively volatile when it is subject to
12667 -- pragma Atomic or Volatile.
12669 if Is_Volatile
(Id
) then
12672 -- An array type is effectively volatile when it is subject to pragma
12673 -- Atomic_Components or Volatile_Components or its component type is
12674 -- effectively volatile.
12676 elsif Is_Array_Type
(Id
) then
12678 Has_Volatile_Components
(Id
)
12680 Is_Effectively_Volatile
(Component_Type
(Base_Type
(Id
)));
12682 -- A protected type is always volatile
12684 elsif Is_Protected_Type
(Id
) then
12687 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
12688 -- automatically volatile.
12690 elsif Is_Descendant_Of_Suspension_Object
(Id
) then
12693 -- Otherwise the type is not effectively volatile
12699 -- Otherwise Id denotes an object
12704 or else Has_Volatile_Components
(Id
)
12705 or else Is_Effectively_Volatile
(Etype
(Id
));
12707 end Is_Effectively_Volatile
;
12709 ------------------------------------
12710 -- Is_Effectively_Volatile_Object --
12711 ------------------------------------
12713 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
12715 if Is_Entity_Name
(N
) then
12716 return Is_Effectively_Volatile
(Entity
(N
));
12718 elsif Nkind
(N
) = N_Indexed_Component
then
12719 return Is_Effectively_Volatile_Object
(Prefix
(N
));
12721 elsif Nkind
(N
) = N_Selected_Component
then
12723 Is_Effectively_Volatile_Object
(Prefix
(N
))
12725 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
12730 end Is_Effectively_Volatile_Object
;
12732 -------------------
12733 -- Is_Entry_Body --
12734 -------------------
12736 function Is_Entry_Body
(Id
: Entity_Id
) return Boolean is
12739 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
12740 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Body
;
12743 --------------------------
12744 -- Is_Entry_Declaration --
12745 --------------------------
12747 function Is_Entry_Declaration
(Id
: Entity_Id
) return Boolean is
12750 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
12751 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Declaration
;
12752 end Is_Entry_Declaration
;
12754 ------------------------------------
12755 -- Is_Expanded_Priority_Attribute --
12756 ------------------------------------
12758 function Is_Expanded_Priority_Attribute
(E
: Entity_Id
) return Boolean is
12761 Nkind
(E
) = N_Function_Call
12762 and then not Configurable_Run_Time_Mode
12763 and then (Entity
(Name
(E
)) = RTE
(RE_Get_Ceiling
)
12764 or else Entity
(Name
(E
)) = RTE
(RO_PE_Get_Ceiling
));
12765 end Is_Expanded_Priority_Attribute
;
12767 ----------------------------
12768 -- Is_Expression_Function --
12769 ----------------------------
12771 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
12773 if Ekind_In
(Subp
, E_Function
, E_Subprogram_Body
) then
12775 Nkind
(Original_Node
(Unit_Declaration_Node
(Subp
))) =
12776 N_Expression_Function
;
12780 end Is_Expression_Function
;
12782 ------------------------------------------
12783 -- Is_Expression_Function_Or_Completion --
12784 ------------------------------------------
12786 function Is_Expression_Function_Or_Completion
12787 (Subp
: Entity_Id
) return Boolean
12789 Subp_Decl
: Node_Id
;
12792 if Ekind
(Subp
) = E_Function
then
12793 Subp_Decl
:= Unit_Declaration_Node
(Subp
);
12795 -- The function declaration is either an expression function or is
12796 -- completed by an expression function body.
12799 Is_Expression_Function
(Subp
)
12800 or else (Nkind
(Subp_Decl
) = N_Subprogram_Declaration
12801 and then Present
(Corresponding_Body
(Subp_Decl
))
12802 and then Is_Expression_Function
12803 (Corresponding_Body
(Subp_Decl
)));
12805 elsif Ekind
(Subp
) = E_Subprogram_Body
then
12806 return Is_Expression_Function
(Subp
);
12811 end Is_Expression_Function_Or_Completion
;
12813 -----------------------
12814 -- Is_EVF_Expression --
12815 -----------------------
12817 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
12818 Orig_N
: constant Node_Id
:= Original_Node
(N
);
12824 -- Detect a reference to a formal parameter of a specific tagged type
12825 -- whose related subprogram is subject to pragma Expresions_Visible with
12828 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
12833 and then Is_Specific_Tagged_Type
(Etype
(Id
))
12834 and then Extensions_Visible_Status
(Id
) =
12835 Extensions_Visible_False
;
12837 -- A case expression is an EVF expression when it contains at least one
12838 -- EVF dependent_expression. Note that a case expression may have been
12839 -- expanded, hence the use of Original_Node.
12841 elsif Nkind
(Orig_N
) = N_Case_Expression
then
12842 Alt
:= First
(Alternatives
(Orig_N
));
12843 while Present
(Alt
) loop
12844 if Is_EVF_Expression
(Expression
(Alt
)) then
12851 -- An if expression is an EVF expression when it contains at least one
12852 -- EVF dependent_expression. Note that an if expression may have been
12853 -- expanded, hence the use of Original_Node.
12855 elsif Nkind
(Orig_N
) = N_If_Expression
then
12856 Expr
:= Next
(First
(Expressions
(Orig_N
)));
12857 while Present
(Expr
) loop
12858 if Is_EVF_Expression
(Expr
) then
12865 -- A qualified expression or a type conversion is an EVF expression when
12866 -- its operand is an EVF expression.
12868 elsif Nkind_In
(N
, N_Qualified_Expression
,
12869 N_Unchecked_Type_Conversion
,
12872 return Is_EVF_Expression
(Expression
(N
));
12874 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
12875 -- their prefix denotes an EVF expression.
12877 elsif Nkind
(N
) = N_Attribute_Reference
12878 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
12882 return Is_EVF_Expression
(Prefix
(N
));
12886 end Is_EVF_Expression
;
12892 function Is_False
(U
: Uint
) return Boolean is
12897 ---------------------------
12898 -- Is_Fixed_Model_Number --
12899 ---------------------------
12901 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
12902 S
: constant Ureal
:= Small_Value
(T
);
12903 M
: Urealp
.Save_Mark
;
12907 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
12908 Urealp
.Release
(M
);
12910 end Is_Fixed_Model_Number
;
12912 -------------------------------
12913 -- Is_Fully_Initialized_Type --
12914 -------------------------------
12916 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
12920 if Is_Scalar_Type
(Typ
) then
12922 -- A scalar type with an aspect Default_Value is fully initialized
12924 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
12925 -- of a scalar type, but we don't take that into account here, since
12926 -- we don't want these to affect warnings.
12928 return Has_Default_Aspect
(Typ
);
12930 elsif Is_Access_Type
(Typ
) then
12933 elsif Is_Array_Type
(Typ
) then
12934 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
12935 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
12940 -- An interesting case, if we have a constrained type one of whose
12941 -- bounds is known to be null, then there are no elements to be
12942 -- initialized, so all the elements are initialized.
12944 if Is_Constrained
(Typ
) then
12947 Indx_Typ
: Entity_Id
;
12948 Lbd
, Hbd
: Node_Id
;
12951 Indx
:= First_Index
(Typ
);
12952 while Present
(Indx
) loop
12953 if Etype
(Indx
) = Any_Type
then
12956 -- If index is a range, use directly
12958 elsif Nkind
(Indx
) = N_Range
then
12959 Lbd
:= Low_Bound
(Indx
);
12960 Hbd
:= High_Bound
(Indx
);
12963 Indx_Typ
:= Etype
(Indx
);
12965 if Is_Private_Type
(Indx_Typ
) then
12966 Indx_Typ
:= Full_View
(Indx_Typ
);
12969 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
12972 Lbd
:= Type_Low_Bound
(Indx_Typ
);
12973 Hbd
:= Type_High_Bound
(Indx_Typ
);
12977 if Compile_Time_Known_Value
(Lbd
)
12979 Compile_Time_Known_Value
(Hbd
)
12981 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
12991 -- If no null indexes, then type is not fully initialized
12997 elsif Is_Record_Type
(Typ
) then
12998 if Has_Discriminants
(Typ
)
13000 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
13001 and then Is_Fully_Initialized_Variant
(Typ
)
13006 -- We consider bounded string types to be fully initialized, because
13007 -- otherwise we get false alarms when the Data component is not
13008 -- default-initialized.
13010 if Is_Bounded_String
(Typ
) then
13014 -- Controlled records are considered to be fully initialized if
13015 -- there is a user defined Initialize routine. This may not be
13016 -- entirely correct, but as the spec notes, we are guessing here
13017 -- what is best from the point of view of issuing warnings.
13019 if Is_Controlled
(Typ
) then
13021 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
13024 if Present
(Utyp
) then
13026 Init
: constant Entity_Id
:=
13027 (Find_Optional_Prim_Op
13028 (Underlying_Type
(Typ
), Name_Initialize
));
13032 and then Comes_From_Source
(Init
)
13034 Is_Predefined_File_Name
13035 (File_Name
(Get_Source_File_Index
(Sloc
(Init
))))
13039 elsif Has_Null_Extension
(Typ
)
13041 Is_Fully_Initialized_Type
13042 (Etype
(Base_Type
(Typ
)))
13051 -- Otherwise see if all record components are initialized
13057 Ent
:= First_Entity
(Typ
);
13058 while Present
(Ent
) loop
13059 if Ekind
(Ent
) = E_Component
13060 and then (No
(Parent
(Ent
))
13061 or else No
(Expression
(Parent
(Ent
))))
13062 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
13064 -- Special VM case for tag components, which need to be
13065 -- defined in this case, but are never initialized as VMs
13066 -- are using other dispatching mechanisms. Ignore this
13067 -- uninitialized case. Note that this applies both to the
13068 -- uTag entry and the main vtable pointer (CPP_Class case).
13070 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
13079 -- No uninitialized components, so type is fully initialized.
13080 -- Note that this catches the case of no components as well.
13084 elsif Is_Concurrent_Type
(Typ
) then
13087 elsif Is_Private_Type
(Typ
) then
13089 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
13095 return Is_Fully_Initialized_Type
(U
);
13102 end Is_Fully_Initialized_Type
;
13104 ----------------------------------
13105 -- Is_Fully_Initialized_Variant --
13106 ----------------------------------
13108 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
13109 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
13110 Constraints
: constant List_Id
:= New_List
;
13111 Components
: constant Elist_Id
:= New_Elmt_List
;
13112 Comp_Elmt
: Elmt_Id
;
13114 Comp_List
: Node_Id
;
13116 Discr_Val
: Node_Id
;
13118 Report_Errors
: Boolean;
13119 pragma Warnings
(Off
, Report_Errors
);
13122 if Serious_Errors_Detected
> 0 then
13126 if Is_Record_Type
(Typ
)
13127 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
13128 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
13130 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
13132 Discr
:= First_Discriminant
(Typ
);
13133 while Present
(Discr
) loop
13134 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
13135 Discr_Val
:= Expression
(Parent
(Discr
));
13137 if Present
(Discr_Val
)
13138 and then Is_OK_Static_Expression
(Discr_Val
)
13140 Append_To
(Constraints
,
13141 Make_Component_Association
(Loc
,
13142 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
13143 Expression
=> New_Copy
(Discr_Val
)));
13151 Next_Discriminant
(Discr
);
13156 Comp_List
=> Comp_List
,
13157 Governed_By
=> Constraints
,
13158 Into
=> Components
,
13159 Report_Errors
=> Report_Errors
);
13161 -- Check that each component present is fully initialized
13163 Comp_Elmt
:= First_Elmt
(Components
);
13164 while Present
(Comp_Elmt
) loop
13165 Comp_Id
:= Node
(Comp_Elmt
);
13167 if Ekind
(Comp_Id
) = E_Component
13168 and then (No
(Parent
(Comp_Id
))
13169 or else No
(Expression
(Parent
(Comp_Id
))))
13170 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
13175 Next_Elmt
(Comp_Elmt
);
13180 elsif Is_Private_Type
(Typ
) then
13182 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
13188 return Is_Fully_Initialized_Variant
(U
);
13195 end Is_Fully_Initialized_Variant
;
13197 ------------------------------------
13198 -- Is_Generic_Declaration_Or_Body --
13199 ------------------------------------
13201 function Is_Generic_Declaration_Or_Body
(Decl
: Node_Id
) return Boolean is
13202 Spec_Decl
: Node_Id
;
13205 -- Package/subprogram body
13207 if Nkind_In
(Decl
, N_Package_Body
, N_Subprogram_Body
)
13208 and then Present
(Corresponding_Spec
(Decl
))
13210 Spec_Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(Decl
));
13212 -- Package/subprogram body stub
13214 elsif Nkind_In
(Decl
, N_Package_Body_Stub
, N_Subprogram_Body_Stub
)
13215 and then Present
(Corresponding_Spec_Of_Stub
(Decl
))
13218 Unit_Declaration_Node
(Corresponding_Spec_Of_Stub
(Decl
));
13226 -- Rather than inspecting the defining entity of the spec declaration,
13227 -- look at its Nkind. This takes care of the case where the analysis of
13228 -- a generic body modifies the Ekind of its spec to allow for recursive
13232 Nkind_In
(Spec_Decl
, N_Generic_Package_Declaration
,
13233 N_Generic_Subprogram_Declaration
);
13234 end Is_Generic_Declaration_Or_Body
;
13236 ----------------------------
13237 -- Is_Inherited_Operation --
13238 ----------------------------
13240 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
13241 pragma Assert
(Is_Overloadable
(E
));
13242 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
13244 return Kind
= N_Full_Type_Declaration
13245 or else Kind
= N_Private_Extension_Declaration
13246 or else Kind
= N_Subtype_Declaration
13247 or else (Ekind
(E
) = E_Enumeration_Literal
13248 and then Is_Derived_Type
(Etype
(E
)));
13249 end Is_Inherited_Operation
;
13251 -------------------------------------
13252 -- Is_Inherited_Operation_For_Type --
13253 -------------------------------------
13255 function Is_Inherited_Operation_For_Type
13257 Typ
: Entity_Id
) return Boolean
13260 -- Check that the operation has been created by the type declaration
13262 return Is_Inherited_Operation
(E
)
13263 and then Defining_Identifier
(Parent
(E
)) = Typ
;
13264 end Is_Inherited_Operation_For_Type
;
13270 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
13271 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean;
13272 -- Determine whether type Iter_Typ is a predefined forward or reversible
13275 ----------------------
13276 -- Denotes_Iterator --
13277 ----------------------
13279 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean is
13281 -- Check that the name matches, and that the ultimate ancestor is in
13282 -- a predefined unit, i.e the one that declares iterator interfaces.
13285 Nam_In
(Chars
(Iter_Typ
), Name_Forward_Iterator
,
13286 Name_Reversible_Iterator
)
13287 and then Is_Predefined_File_Name
13288 (Unit_File_Name
(Get_Source_Unit
(Root_Type
(Iter_Typ
))));
13289 end Denotes_Iterator
;
13293 Iface_Elmt
: Elmt_Id
;
13296 -- Start of processing for Is_Iterator
13299 -- The type may be a subtype of a descendant of the proper instance of
13300 -- the predefined interface type, so we must use the root type of the
13301 -- given type. The same is done for Is_Reversible_Iterator.
13303 if Is_Class_Wide_Type
(Typ
)
13304 and then Denotes_Iterator
(Root_Type
(Typ
))
13308 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
13311 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
13315 Collect_Interfaces
(Typ
, Ifaces
);
13317 Iface_Elmt
:= First_Elmt
(Ifaces
);
13318 while Present
(Iface_Elmt
) loop
13319 if Denotes_Iterator
(Node
(Iface_Elmt
)) then
13323 Next_Elmt
(Iface_Elmt
);
13330 ----------------------------
13331 -- Is_Iterator_Over_Array --
13332 ----------------------------
13334 function Is_Iterator_Over_Array
(N
: Node_Id
) return Boolean is
13335 Container
: constant Node_Id
:= Name
(N
);
13336 Container_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Container
));
13338 return Is_Array_Type
(Container_Typ
);
13339 end Is_Iterator_Over_Array
;
13345 -- We seem to have a lot of overlapping functions that do similar things
13346 -- (testing for left hand sides or lvalues???).
13348 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
13349 P
: constant Node_Id
:= Parent
(N
);
13352 -- Return True if we are the left hand side of an assignment statement
13354 if Nkind
(P
) = N_Assignment_Statement
then
13355 if Name
(P
) = N
then
13361 -- Case of prefix of indexed or selected component or slice
13363 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
13364 and then N
= Prefix
(P
)
13366 -- Here we have the case where the parent P is N.Q or N(Q .. R).
13367 -- If P is an LHS, then N is also effectively an LHS, but there
13368 -- is an important exception. If N is of an access type, then
13369 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
13370 -- case this makes N.all a left hand side but not N itself.
13372 -- If we don't know the type yet, this is the case where we return
13373 -- Unknown, since the answer depends on the type which is unknown.
13375 if No
(Etype
(N
)) then
13378 -- We have an Etype set, so we can check it
13380 elsif Is_Access_Type
(Etype
(N
)) then
13383 -- OK, not access type case, so just test whole expression
13389 -- All other cases are not left hand sides
13396 -----------------------------
13397 -- Is_Library_Level_Entity --
13398 -----------------------------
13400 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
13402 -- The following is a small optimization, and it also properly handles
13403 -- discriminals, which in task bodies might appear in expressions before
13404 -- the corresponding procedure has been created, and which therefore do
13405 -- not have an assigned scope.
13407 if Is_Formal
(E
) then
13411 -- Normal test is simply that the enclosing dynamic scope is Standard
13413 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
13414 end Is_Library_Level_Entity
;
13416 --------------------------------
13417 -- Is_Limited_Class_Wide_Type --
13418 --------------------------------
13420 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
13423 Is_Class_Wide_Type
(Typ
)
13424 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
13425 end Is_Limited_Class_Wide_Type
;
13427 ---------------------------------
13428 -- Is_Local_Variable_Reference --
13429 ---------------------------------
13431 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
13433 if not Is_Entity_Name
(Expr
) then
13438 Ent
: constant Entity_Id
:= Entity
(Expr
);
13439 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
13441 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
13444 return Present
(Sub
) and then Sub
= Current_Subprogram
;
13448 end Is_Local_Variable_Reference
;
13450 -----------------------------------------------
13451 -- Is_Nontrivial_Default_Init_Cond_Procedure --
13452 -----------------------------------------------
13454 function Is_Nontrivial_Default_Init_Cond_Procedure
13455 (Id
: Entity_Id
) return Boolean
13457 Body_Decl
: Node_Id
;
13461 if Ekind
(Id
) = E_Procedure
13462 and then Is_Default_Init_Cond_Procedure
(Id
)
13465 Unit_Declaration_Node
13466 (Corresponding_Body
(Unit_Declaration_Node
(Id
)));
13468 -- The body of the Default_Initial_Condition procedure must contain
13469 -- at least one statement, otherwise the generation of the subprogram
13472 pragma Assert
(Present
(Handled_Statement_Sequence
(Body_Decl
)));
13474 -- To qualify as nontrivial, the first statement of the procedure
13475 -- must be a check in the form of an if statement. If the original
13476 -- Default_Initial_Condition expression was folded, then the first
13477 -- statement is not a check.
13479 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Body_Decl
)));
13482 Nkind
(Stmt
) = N_If_Statement
13483 and then Nkind
(Original_Node
(Stmt
)) = N_Pragma
;
13487 end Is_Nontrivial_Default_Init_Cond_Procedure
;
13489 -------------------------
13490 -- Is_Null_Record_Type --
13491 -------------------------
13493 function Is_Null_Record_Type
(T
: Entity_Id
) return Boolean is
13494 Decl
: constant Node_Id
:= Parent
(T
);
13496 return Nkind
(Decl
) = N_Full_Type_Declaration
13497 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
13499 (No
(Component_List
(Type_Definition
(Decl
)))
13500 or else Null_Present
(Component_List
(Type_Definition
(Decl
))));
13501 end Is_Null_Record_Type
;
13503 -------------------------
13504 -- Is_Object_Reference --
13505 -------------------------
13507 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
13508 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
13509 -- Determine whether N is the name of an internally-generated renaming
13511 --------------------------------------
13512 -- Is_Internally_Generated_Renaming --
13513 --------------------------------------
13515 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
13520 while Present
(P
) loop
13521 if Nkind
(P
) = N_Object_Renaming_Declaration
then
13522 return not Comes_From_Source
(P
);
13523 elsif Is_List_Member
(P
) then
13531 end Is_Internally_Generated_Renaming
;
13533 -- Start of processing for Is_Object_Reference
13536 if Is_Entity_Name
(N
) then
13537 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
13541 when N_Indexed_Component | N_Slice
=>
13543 Is_Object_Reference
(Prefix
(N
))
13544 or else Is_Access_Type
(Etype
(Prefix
(N
)));
13546 -- In Ada 95, a function call is a constant object; a procedure
13549 when N_Function_Call
=>
13550 return Etype
(N
) /= Standard_Void_Type
;
13552 -- Attributes 'Input, 'Loop_Entry, 'Old, and 'Result produce
13555 when N_Attribute_Reference
=>
13557 Nam_In
(Attribute_Name
(N
), Name_Input
,
13562 when N_Selected_Component
=>
13564 Is_Object_Reference
(Selector_Name
(N
))
13566 (Is_Object_Reference
(Prefix
(N
))
13567 or else Is_Access_Type
(Etype
(Prefix
(N
))));
13569 when N_Explicit_Dereference
=>
13572 -- A view conversion of a tagged object is an object reference
13574 when N_Type_Conversion
=>
13575 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
13576 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
13577 and then Is_Object_Reference
(Expression
(N
));
13579 -- An unchecked type conversion is considered to be an object if
13580 -- the operand is an object (this construction arises only as a
13581 -- result of expansion activities).
13583 when N_Unchecked_Type_Conversion
=>
13586 -- Allow string literals to act as objects as long as they appear
13587 -- in internally-generated renamings. The expansion of iterators
13588 -- may generate such renamings when the range involves a string
13591 when N_String_Literal
=>
13592 return Is_Internally_Generated_Renaming
(Parent
(N
));
13594 -- AI05-0003: In Ada 2012 a qualified expression is a name.
13595 -- This allows disambiguation of function calls and the use
13596 -- of aggregates in more contexts.
13598 when N_Qualified_Expression
=>
13599 if Ada_Version
< Ada_2012
then
13602 return Is_Object_Reference
(Expression
(N
))
13603 or else Nkind
(Expression
(N
)) = N_Aggregate
;
13610 end Is_Object_Reference
;
13612 -----------------------------------
13613 -- Is_OK_Variable_For_Out_Formal --
13614 -----------------------------------
13616 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
13618 Note_Possible_Modification
(AV
, Sure
=> True);
13620 -- We must reject parenthesized variable names. Comes_From_Source is
13621 -- checked because there are currently cases where the compiler violates
13622 -- this rule (e.g. passing a task object to its controlled Initialize
13623 -- routine). This should be properly documented in sinfo???
13625 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
13628 -- A variable is always allowed
13630 elsif Is_Variable
(AV
) then
13633 -- Generalized indexing operations are rewritten as explicit
13634 -- dereferences, and it is only during resolution that we can
13635 -- check whether the context requires an access_to_variable type.
13637 elsif Nkind
(AV
) = N_Explicit_Dereference
13638 and then Ada_Version
>= Ada_2012
13639 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
13640 and then Present
(Etype
(Original_Node
(AV
)))
13641 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
13643 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
13645 -- Unchecked conversions are allowed only if they come from the
13646 -- generated code, which sometimes uses unchecked conversions for out
13647 -- parameters in cases where code generation is unaffected. We tell
13648 -- source unchecked conversions by seeing if they are rewrites of
13649 -- an original Unchecked_Conversion function call, or of an explicit
13650 -- conversion of a function call or an aggregate (as may happen in the
13651 -- expansion of a packed array aggregate).
13653 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
13654 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
13657 elsif Comes_From_Source
(AV
)
13658 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
13662 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
13663 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
13669 -- Normal type conversions are allowed if argument is a variable
13671 elsif Nkind
(AV
) = N_Type_Conversion
then
13672 if Is_Variable
(Expression
(AV
))
13673 and then Paren_Count
(Expression
(AV
)) = 0
13675 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
13678 -- We also allow a non-parenthesized expression that raises
13679 -- constraint error if it rewrites what used to be a variable
13681 elsif Raises_Constraint_Error
(Expression
(AV
))
13682 and then Paren_Count
(Expression
(AV
)) = 0
13683 and then Is_Variable
(Original_Node
(Expression
(AV
)))
13687 -- Type conversion of something other than a variable
13693 -- If this node is rewritten, then test the original form, if that is
13694 -- OK, then we consider the rewritten node OK (for example, if the
13695 -- original node is a conversion, then Is_Variable will not be true
13696 -- but we still want to allow the conversion if it converts a variable).
13698 elsif Original_Node
(AV
) /= AV
then
13700 -- In Ada 2012, the explicit dereference may be a rewritten call to a
13701 -- Reference function.
13703 if Ada_Version
>= Ada_2012
13704 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
13706 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
13709 -- Check that this is not a constant reference.
13711 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
13713 elsif Has_Implicit_Dereference
(Etype
(Original_Node
(AV
))) then
13715 not Is_Access_Constant
(Etype
13716 (Get_Reference_Discriminant
(Etype
(Original_Node
(AV
)))));
13719 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
13722 -- All other non-variables are rejected
13727 end Is_OK_Variable_For_Out_Formal
;
13729 ----------------------------
13730 -- Is_OK_Volatile_Context --
13731 ----------------------------
13733 function Is_OK_Volatile_Context
13734 (Context
: Node_Id
;
13735 Obj_Ref
: Node_Id
) return Boolean
13737 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean;
13738 -- Determine whether an arbitrary node denotes a call to a protected
13739 -- entry, function, or procedure in prefixed form where the prefix is
13742 function Within_Check
(Nod
: Node_Id
) return Boolean;
13743 -- Determine whether an arbitrary node appears in a check node
13745 function Within_Subprogram_Call
(Nod
: Node_Id
) return Boolean;
13746 -- Determine whether an arbitrary node appears in an entry, function, or
13749 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean;
13750 -- Determine whether an arbitrary entity appears in a volatile function
13752 ---------------------------------
13753 -- Is_Protected_Operation_Call --
13754 ---------------------------------
13756 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean is
13761 -- A call to a protected operations retains its selected component
13762 -- form as opposed to other prefixed calls that are transformed in
13765 if Nkind
(Nod
) = N_Selected_Component
then
13766 Pref
:= Prefix
(Nod
);
13767 Subp
:= Selector_Name
(Nod
);
13771 and then Present
(Etype
(Pref
))
13772 and then Is_Protected_Type
(Etype
(Pref
))
13773 and then Is_Entity_Name
(Subp
)
13774 and then Present
(Entity
(Subp
))
13775 and then Ekind_In
(Entity
(Subp
), E_Entry
,
13782 end Is_Protected_Operation_Call
;
13788 function Within_Check
(Nod
: Node_Id
) return Boolean is
13792 -- Climb the parent chain looking for a check node
13795 while Present
(Par
) loop
13796 if Nkind
(Par
) in N_Raise_xxx_Error
then
13799 -- Prevent the search from going too far
13801 elsif Is_Body_Or_Package_Declaration
(Par
) then
13805 Par
:= Parent
(Par
);
13811 ----------------------------
13812 -- Within_Subprogram_Call --
13813 ----------------------------
13815 function Within_Subprogram_Call
(Nod
: Node_Id
) return Boolean is
13819 -- Climb the parent chain looking for a function or procedure call
13822 while Present
(Par
) loop
13823 if Nkind_In
(Par
, N_Entry_Call_Statement
,
13825 N_Procedure_Call_Statement
)
13829 -- Prevent the search from going too far
13831 elsif Is_Body_Or_Package_Declaration
(Par
) then
13835 Par
:= Parent
(Par
);
13839 end Within_Subprogram_Call
;
13841 ------------------------------
13842 -- Within_Volatile_Function --
13843 ------------------------------
13845 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean is
13846 Func_Id
: Entity_Id
;
13849 -- Traverse the scope stack looking for a [generic] function
13852 while Present
(Func_Id
) and then Func_Id
/= Standard_Standard
loop
13853 if Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
) then
13854 return Is_Volatile_Function
(Func_Id
);
13857 Func_Id
:= Scope
(Func_Id
);
13861 end Within_Volatile_Function
;
13865 Obj_Id
: Entity_Id
;
13867 -- Start of processing for Is_OK_Volatile_Context
13870 -- The volatile object appears on either side of an assignment
13872 if Nkind
(Context
) = N_Assignment_Statement
then
13875 -- The volatile object is part of the initialization expression of
13878 elsif Nkind
(Context
) = N_Object_Declaration
13879 and then Present
(Expression
(Context
))
13880 and then Expression
(Context
) = Obj_Ref
13882 Obj_Id
:= Defining_Entity
(Context
);
13884 -- The volatile object acts as the initialization expression of an
13885 -- extended return statement. This is valid context as long as the
13886 -- function is volatile.
13888 if Is_Return_Object
(Obj_Id
) then
13889 return Within_Volatile_Function
(Obj_Id
);
13891 -- Otherwise this is a normal object initialization
13897 -- The volatile object acts as the name of a renaming declaration
13899 elsif Nkind
(Context
) = N_Object_Renaming_Declaration
13900 and then Name
(Context
) = Obj_Ref
13904 -- The volatile object appears as an actual parameter in a call to an
13905 -- instance of Unchecked_Conversion whose result is renamed.
13907 elsif Nkind
(Context
) = N_Function_Call
13908 and then Is_Entity_Name
(Name
(Context
))
13909 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
13910 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
13914 -- The volatile object is actually the prefix in a protected entry,
13915 -- function, or procedure call.
13917 elsif Is_Protected_Operation_Call
(Context
) then
13920 -- The volatile object appears as the expression of a simple return
13921 -- statement that applies to a volatile function.
13923 elsif Nkind
(Context
) = N_Simple_Return_Statement
13924 and then Expression
(Context
) = Obj_Ref
13927 Within_Volatile_Function
(Return_Statement_Entity
(Context
));
13929 -- The volatile object appears as the prefix of a name occurring in a
13930 -- non-interfering context.
13932 elsif Nkind_In
(Context
, N_Attribute_Reference
,
13933 N_Explicit_Dereference
,
13934 N_Indexed_Component
,
13935 N_Selected_Component
,
13937 and then Prefix
(Context
) = Obj_Ref
13938 and then Is_OK_Volatile_Context
13939 (Context
=> Parent
(Context
),
13940 Obj_Ref
=> Context
)
13944 -- The volatile object appears as the prefix of attributes Address,
13945 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
13948 elsif Nkind
(Context
) = N_Attribute_Reference
13949 and then Prefix
(Context
) = Obj_Ref
13950 and then Nam_In
(Attribute_Name
(Context
), Name_Address
,
13952 Name_Component_Size
,
13961 -- The volatile object appears as the expression of a type conversion
13962 -- occurring in a non-interfering context.
13964 elsif Nkind_In
(Context
, N_Type_Conversion
,
13965 N_Unchecked_Type_Conversion
)
13966 and then Expression
(Context
) = Obj_Ref
13967 and then Is_OK_Volatile_Context
13968 (Context
=> Parent
(Context
),
13969 Obj_Ref
=> Context
)
13973 -- Allow references to volatile objects in various checks. This is not a
13974 -- direct SPARK 2014 requirement.
13976 elsif Within_Check
(Context
) then
13979 -- Assume that references to effectively volatile objects that appear
13980 -- as actual parameters in a subprogram call are always legal. A full
13981 -- legality check is done when the actuals are resolved (see routine
13982 -- Resolve_Actuals).
13984 elsif Within_Subprogram_Call
(Context
) then
13987 -- Otherwise the context is not suitable for an effectively volatile
13993 end Is_OK_Volatile_Context
;
13995 ------------------------------------
13996 -- Is_Package_Contract_Annotation --
13997 ------------------------------------
13999 function Is_Package_Contract_Annotation
(Item
: Node_Id
) return Boolean is
14003 if Nkind
(Item
) = N_Aspect_Specification
then
14004 Nam
:= Chars
(Identifier
(Item
));
14006 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
14007 Nam
:= Pragma_Name
(Item
);
14010 return Nam
= Name_Abstract_State
14011 or else Nam
= Name_Initial_Condition
14012 or else Nam
= Name_Initializes
14013 or else Nam
= Name_Refined_State
;
14014 end Is_Package_Contract_Annotation
;
14016 -----------------------------------
14017 -- Is_Partially_Initialized_Type --
14018 -----------------------------------
14020 function Is_Partially_Initialized_Type
14022 Include_Implicit
: Boolean := True) return Boolean
14025 if Is_Scalar_Type
(Typ
) then
14028 elsif Is_Access_Type
(Typ
) then
14029 return Include_Implicit
;
14031 elsif Is_Array_Type
(Typ
) then
14033 -- If component type is partially initialized, so is array type
14035 if Is_Partially_Initialized_Type
14036 (Component_Type
(Typ
), Include_Implicit
)
14040 -- Otherwise we are only partially initialized if we are fully
14041 -- initialized (this is the empty array case, no point in us
14042 -- duplicating that code here).
14045 return Is_Fully_Initialized_Type
(Typ
);
14048 elsif Is_Record_Type
(Typ
) then
14050 -- A discriminated type is always partially initialized if in
14053 if Has_Discriminants
(Typ
) and then Include_Implicit
then
14056 -- A tagged type is always partially initialized
14058 elsif Is_Tagged_Type
(Typ
) then
14061 -- Case of non-discriminated record
14067 Component_Present
: Boolean := False;
14068 -- Set True if at least one component is present. If no
14069 -- components are present, then record type is fully
14070 -- initialized (another odd case, like the null array).
14073 -- Loop through components
14075 Ent
:= First_Entity
(Typ
);
14076 while Present
(Ent
) loop
14077 if Ekind
(Ent
) = E_Component
then
14078 Component_Present
:= True;
14080 -- If a component has an initialization expression then
14081 -- the enclosing record type is partially initialized
14083 if Present
(Parent
(Ent
))
14084 and then Present
(Expression
(Parent
(Ent
)))
14088 -- If a component is of a type which is itself partially
14089 -- initialized, then the enclosing record type is also.
14091 elsif Is_Partially_Initialized_Type
14092 (Etype
(Ent
), Include_Implicit
)
14101 -- No initialized components found. If we found any components
14102 -- they were all uninitialized so the result is false.
14104 if Component_Present
then
14107 -- But if we found no components, then all the components are
14108 -- initialized so we consider the type to be initialized.
14116 -- Concurrent types are always fully initialized
14118 elsif Is_Concurrent_Type
(Typ
) then
14121 -- For a private type, go to underlying type. If there is no underlying
14122 -- type then just assume this partially initialized. Not clear if this
14123 -- can happen in a non-error case, but no harm in testing for this.
14125 elsif Is_Private_Type
(Typ
) then
14127 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
14132 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
14136 -- For any other type (are there any?) assume partially initialized
14141 end Is_Partially_Initialized_Type
;
14143 ------------------------------------
14144 -- Is_Potentially_Persistent_Type --
14145 ------------------------------------
14147 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
14152 -- For private type, test corresponding full type
14154 if Is_Private_Type
(T
) then
14155 return Is_Potentially_Persistent_Type
(Full_View
(T
));
14157 -- Scalar types are potentially persistent
14159 elsif Is_Scalar_Type
(T
) then
14162 -- Record type is potentially persistent if not tagged and the types of
14163 -- all it components are potentially persistent, and no component has
14164 -- an initialization expression.
14166 elsif Is_Record_Type
(T
)
14167 and then not Is_Tagged_Type
(T
)
14168 and then not Is_Partially_Initialized_Type
(T
)
14170 Comp
:= First_Component
(T
);
14171 while Present
(Comp
) loop
14172 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
14175 Next_Entity
(Comp
);
14181 -- Array type is potentially persistent if its component type is
14182 -- potentially persistent and if all its constraints are static.
14184 elsif Is_Array_Type
(T
) then
14185 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
14189 Indx
:= First_Index
(T
);
14190 while Present
(Indx
) loop
14191 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
14200 -- All other types are not potentially persistent
14205 end Is_Potentially_Persistent_Type
;
14207 --------------------------------
14208 -- Is_Potentially_Unevaluated --
14209 --------------------------------
14211 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
14219 -- A postcondition whose expression is a short-circuit is broken down
14220 -- into individual aspects for better exception reporting. The original
14221 -- short-circuit expression is rewritten as the second operand, and an
14222 -- occurrence of 'Old in that operand is potentially unevaluated.
14223 -- See Sem_ch13.adb for details of this transformation.
14225 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
14229 while not Nkind_In
(Par
, N_If_Expression
,
14237 Par
:= Parent
(Par
);
14239 -- If the context is not an expression, or if is the result of
14240 -- expansion of an enclosing construct (such as another attribute)
14241 -- the predicate does not apply.
14243 if Nkind
(Par
) not in N_Subexpr
14244 or else not Comes_From_Source
(Par
)
14250 if Nkind
(Par
) = N_If_Expression
then
14251 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
14253 elsif Nkind
(Par
) = N_Case_Expression
then
14254 return Expr
/= Expression
(Par
);
14256 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
14257 return Expr
= Right_Opnd
(Par
);
14259 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
14260 return Expr
/= Left_Opnd
(Par
);
14265 end Is_Potentially_Unevaluated
;
14267 ---------------------------------
14268 -- Is_Protected_Self_Reference --
14269 ---------------------------------
14271 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
14273 function In_Access_Definition
(N
: Node_Id
) return Boolean;
14274 -- Returns true if N belongs to an access definition
14276 --------------------------
14277 -- In_Access_Definition --
14278 --------------------------
14280 function In_Access_Definition
(N
: Node_Id
) return Boolean is
14285 while Present
(P
) loop
14286 if Nkind
(P
) = N_Access_Definition
then
14294 end In_Access_Definition
;
14296 -- Start of processing for Is_Protected_Self_Reference
14299 -- Verify that prefix is analyzed and has the proper form. Note that
14300 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
14301 -- produce the address of an entity, do not analyze their prefix
14302 -- because they denote entities that are not necessarily visible.
14303 -- Neither of them can apply to a protected type.
14305 return Ada_Version
>= Ada_2005
14306 and then Is_Entity_Name
(N
)
14307 and then Present
(Entity
(N
))
14308 and then Is_Protected_Type
(Entity
(N
))
14309 and then In_Open_Scopes
(Entity
(N
))
14310 and then not In_Access_Definition
(N
);
14311 end Is_Protected_Self_Reference
;
14313 -----------------------------
14314 -- Is_RCI_Pkg_Spec_Or_Body --
14315 -----------------------------
14317 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
14319 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
14320 -- Return True if the unit of Cunit is an RCI package declaration
14322 ---------------------------
14323 -- Is_RCI_Pkg_Decl_Cunit --
14324 ---------------------------
14326 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
14327 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
14330 if Nkind
(The_Unit
) /= N_Package_Declaration
then
14334 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
14335 end Is_RCI_Pkg_Decl_Cunit
;
14337 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
14340 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
14342 (Nkind
(Unit
(Cunit
)) = N_Package_Body
14343 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
14344 end Is_RCI_Pkg_Spec_Or_Body
;
14346 -----------------------------------------
14347 -- Is_Remote_Access_To_Class_Wide_Type --
14348 -----------------------------------------
14350 function Is_Remote_Access_To_Class_Wide_Type
14351 (E
: Entity_Id
) return Boolean
14354 -- A remote access to class-wide type is a general access to object type
14355 -- declared in the visible part of a Remote_Types or Remote_Call_
14358 return Ekind
(E
) = E_General_Access_Type
14359 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
14360 end Is_Remote_Access_To_Class_Wide_Type
;
14362 -----------------------------------------
14363 -- Is_Remote_Access_To_Subprogram_Type --
14364 -----------------------------------------
14366 function Is_Remote_Access_To_Subprogram_Type
14367 (E
: Entity_Id
) return Boolean
14370 return (Ekind
(E
) = E_Access_Subprogram_Type
14371 or else (Ekind
(E
) = E_Record_Type
14372 and then Present
(Corresponding_Remote_Type
(E
))))
14373 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
14374 end Is_Remote_Access_To_Subprogram_Type
;
14376 --------------------
14377 -- Is_Remote_Call --
14378 --------------------
14380 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
14382 if Nkind
(N
) not in N_Subprogram_Call
then
14384 -- An entry call cannot be remote
14388 elsif Nkind
(Name
(N
)) in N_Has_Entity
14389 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
14391 -- A subprogram declared in the spec of a RCI package is remote
14395 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
14396 and then Is_Remote_Access_To_Subprogram_Type
14397 (Etype
(Prefix
(Name
(N
))))
14399 -- The dereference of a RAS is a remote call
14403 elsif Present
(Controlling_Argument
(N
))
14404 and then Is_Remote_Access_To_Class_Wide_Type
14405 (Etype
(Controlling_Argument
(N
)))
14407 -- Any primitive operation call with a controlling argument of
14408 -- a RACW type is a remote call.
14413 -- All other calls are local calls
14416 end Is_Remote_Call
;
14418 ----------------------
14419 -- Is_Renamed_Entry --
14420 ----------------------
14422 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
14423 Orig_Node
: Node_Id
:= Empty
;
14424 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
14426 function Is_Entry
(Nam
: Node_Id
) return Boolean;
14427 -- Determine whether Nam is an entry. Traverse selectors if there are
14428 -- nested selected components.
14434 function Is_Entry
(Nam
: Node_Id
) return Boolean is
14436 if Nkind
(Nam
) = N_Selected_Component
then
14437 return Is_Entry
(Selector_Name
(Nam
));
14440 return Ekind
(Entity
(Nam
)) = E_Entry
;
14443 -- Start of processing for Is_Renamed_Entry
14446 if Present
(Alias
(Proc_Nam
)) then
14447 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
14450 -- Look for a rewritten subprogram renaming declaration
14452 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
14453 and then Present
(Original_Node
(Subp_Decl
))
14455 Orig_Node
:= Original_Node
(Subp_Decl
);
14458 -- The rewritten subprogram is actually an entry
14460 if Present
(Orig_Node
)
14461 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
14462 and then Is_Entry
(Name
(Orig_Node
))
14468 end Is_Renamed_Entry
;
14470 -----------------------------
14471 -- Is_Renaming_Declaration --
14472 -----------------------------
14474 function Is_Renaming_Declaration
(N
: Node_Id
) return Boolean is
14477 when N_Exception_Renaming_Declaration |
14478 N_Generic_Function_Renaming_Declaration |
14479 N_Generic_Package_Renaming_Declaration |
14480 N_Generic_Procedure_Renaming_Declaration |
14481 N_Object_Renaming_Declaration |
14482 N_Package_Renaming_Declaration |
14483 N_Subprogram_Renaming_Declaration
=>
14489 end Is_Renaming_Declaration
;
14491 ----------------------------
14492 -- Is_Reversible_Iterator --
14493 ----------------------------
14495 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
14496 Ifaces_List
: Elist_Id
;
14497 Iface_Elmt
: Elmt_Id
;
14501 if Is_Class_Wide_Type
(Typ
)
14502 and then Chars
(Root_Type
(Typ
)) = Name_Reversible_Iterator
14503 and then Is_Predefined_File_Name
14504 (Unit_File_Name
(Get_Source_Unit
(Root_Type
(Typ
))))
14508 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
14512 Collect_Interfaces
(Typ
, Ifaces_List
);
14514 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
14515 while Present
(Iface_Elmt
) loop
14516 Iface
:= Node
(Iface_Elmt
);
14517 if Chars
(Iface
) = Name_Reversible_Iterator
14519 Is_Predefined_File_Name
14520 (Unit_File_Name
(Get_Source_Unit
(Iface
)))
14525 Next_Elmt
(Iface_Elmt
);
14530 end Is_Reversible_Iterator
;
14532 ----------------------
14533 -- Is_Selector_Name --
14534 ----------------------
14536 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
14538 if not Is_List_Member
(N
) then
14540 P
: constant Node_Id
:= Parent
(N
);
14542 return Nkind_In
(P
, N_Expanded_Name
,
14543 N_Generic_Association
,
14544 N_Parameter_Association
,
14545 N_Selected_Component
)
14546 and then Selector_Name
(P
) = N
;
14551 L
: constant List_Id
:= List_Containing
(N
);
14552 P
: constant Node_Id
:= Parent
(L
);
14554 return (Nkind
(P
) = N_Discriminant_Association
14555 and then Selector_Names
(P
) = L
)
14557 (Nkind
(P
) = N_Component_Association
14558 and then Choices
(P
) = L
);
14561 end Is_Selector_Name
;
14563 ---------------------------------
14564 -- Is_Single_Concurrent_Object --
14565 ---------------------------------
14567 function Is_Single_Concurrent_Object
(Id
: Entity_Id
) return Boolean is
14570 Is_Single_Protected_Object
(Id
) or else Is_Single_Task_Object
(Id
);
14571 end Is_Single_Concurrent_Object
;
14573 -------------------------------
14574 -- Is_Single_Concurrent_Type --
14575 -------------------------------
14577 function Is_Single_Concurrent_Type
(Id
: Entity_Id
) return Boolean is
14580 Ekind_In
(Id
, E_Protected_Type
, E_Task_Type
)
14581 and then Is_Single_Concurrent_Type_Declaration
14582 (Declaration_Node
(Id
));
14583 end Is_Single_Concurrent_Type
;
14585 -------------------------------------------
14586 -- Is_Single_Concurrent_Type_Declaration --
14587 -------------------------------------------
14589 function Is_Single_Concurrent_Type_Declaration
14590 (N
: Node_Id
) return Boolean
14593 return Nkind_In
(Original_Node
(N
), N_Single_Protected_Declaration
,
14594 N_Single_Task_Declaration
);
14595 end Is_Single_Concurrent_Type_Declaration
;
14597 ---------------------------------------------
14598 -- Is_Single_Precision_Floating_Point_Type --
14599 ---------------------------------------------
14601 function Is_Single_Precision_Floating_Point_Type
14602 (E
: Entity_Id
) return Boolean is
14604 return Is_Floating_Point_Type
(E
)
14605 and then Machine_Radix_Value
(E
) = Uint_2
14606 and then Machine_Mantissa_Value
(E
) = Uint_24
14607 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_7
14608 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_7
);
14609 end Is_Single_Precision_Floating_Point_Type
;
14611 --------------------------------
14612 -- Is_Single_Protected_Object --
14613 --------------------------------
14615 function Is_Single_Protected_Object
(Id
: Entity_Id
) return Boolean is
14618 Ekind
(Id
) = E_Variable
14619 and then Ekind
(Etype
(Id
)) = E_Protected_Type
14620 and then Is_Single_Concurrent_Type
(Etype
(Id
));
14621 end Is_Single_Protected_Object
;
14623 ---------------------------
14624 -- Is_Single_Task_Object --
14625 ---------------------------
14627 function Is_Single_Task_Object
(Id
: Entity_Id
) return Boolean is
14630 Ekind
(Id
) = E_Variable
14631 and then Ekind
(Etype
(Id
)) = E_Task_Type
14632 and then Is_Single_Concurrent_Type
(Etype
(Id
));
14633 end Is_Single_Task_Object
;
14635 -------------------------------------
14636 -- Is_SPARK_05_Initialization_Expr --
14637 -------------------------------------
14639 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
14642 Comp_Assn
: Node_Id
;
14643 Orig_N
: constant Node_Id
:= Original_Node
(N
);
14648 if not Comes_From_Source
(Orig_N
) then
14652 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
14654 case Nkind
(Orig_N
) is
14655 when N_Character_Literal |
14656 N_Integer_Literal |
14658 N_String_Literal
=>
14661 when N_Identifier |
14663 if Is_Entity_Name
(Orig_N
)
14664 and then Present
(Entity
(Orig_N
)) -- needed in some cases
14666 case Ekind
(Entity
(Orig_N
)) is
14668 E_Enumeration_Literal |
14673 if Is_Type
(Entity
(Orig_N
)) then
14681 when N_Qualified_Expression |
14682 N_Type_Conversion
=>
14683 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
14686 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
14690 N_Membership_Test
=>
14691 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
14693 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
14696 N_Extension_Aggregate
=>
14697 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
14699 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
14702 Expr
:= First
(Expressions
(Orig_N
));
14703 while Present
(Expr
) loop
14704 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
14712 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
14713 while Present
(Comp_Assn
) loop
14714 Expr
:= Expression
(Comp_Assn
);
14716 -- Note: test for Present here needed for box assocation
14719 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
14728 when N_Attribute_Reference
=>
14729 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
14730 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
14733 Expr
:= First
(Expressions
(Orig_N
));
14734 while Present
(Expr
) loop
14735 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
14743 -- Selected components might be expanded named not yet resolved, so
14744 -- default on the safe side. (Eg on sparklex.ads)
14746 when N_Selected_Component
=>
14755 end Is_SPARK_05_Initialization_Expr
;
14757 ----------------------------------
14758 -- Is_SPARK_05_Object_Reference --
14759 ----------------------------------
14761 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
14763 if Is_Entity_Name
(N
) then
14764 return Present
(Entity
(N
))
14766 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
14767 or else Ekind
(Entity
(N
)) in Formal_Kind
);
14771 when N_Selected_Component
=>
14772 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
14778 end Is_SPARK_05_Object_Reference
;
14780 -----------------------------
14781 -- Is_Specific_Tagged_Type --
14782 -----------------------------
14784 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
14785 Full_Typ
: Entity_Id
;
14788 -- Handle private types
14790 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
14791 Full_Typ
:= Full_View
(Typ
);
14796 -- A specific tagged type is a non-class-wide tagged type
14798 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
14799 end Is_Specific_Tagged_Type
;
14805 function Is_Statement
(N
: Node_Id
) return Boolean is
14808 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
14809 or else Nkind
(N
) = N_Procedure_Call_Statement
;
14812 ---------------------------------------
14813 -- Is_Subprogram_Contract_Annotation --
14814 ---------------------------------------
14816 function Is_Subprogram_Contract_Annotation
14817 (Item
: Node_Id
) return Boolean
14822 if Nkind
(Item
) = N_Aspect_Specification
then
14823 Nam
:= Chars
(Identifier
(Item
));
14825 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
14826 Nam
:= Pragma_Name
(Item
);
14829 return Nam
= Name_Contract_Cases
14830 or else Nam
= Name_Depends
14831 or else Nam
= Name_Extensions_Visible
14832 or else Nam
= Name_Global
14833 or else Nam
= Name_Post
14834 or else Nam
= Name_Post_Class
14835 or else Nam
= Name_Postcondition
14836 or else Nam
= Name_Pre
14837 or else Nam
= Name_Pre_Class
14838 or else Nam
= Name_Precondition
14839 or else Nam
= Name_Refined_Depends
14840 or else Nam
= Name_Refined_Global
14841 or else Nam
= Name_Refined_Post
14842 or else Nam
= Name_Test_Case
;
14843 end Is_Subprogram_Contract_Annotation
;
14845 --------------------------------------------------
14846 -- Is_Subprogram_Stub_Without_Prior_Declaration --
14847 --------------------------------------------------
14849 function Is_Subprogram_Stub_Without_Prior_Declaration
14850 (N
: Node_Id
) return Boolean
14853 -- A subprogram stub without prior declaration serves as declaration for
14854 -- the actual subprogram body. As such, it has an attached defining
14855 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
14857 return Nkind
(N
) = N_Subprogram_Body_Stub
14858 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
14859 end Is_Subprogram_Stub_Without_Prior_Declaration
;
14861 --------------------------
14862 -- Is_Suspension_Object --
14863 --------------------------
14865 function Is_Suspension_Object
(Id
: Entity_Id
) return Boolean is
14867 -- This approach does an exact name match rather than to rely on
14868 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
14869 -- front end at point where all auxiliary tables are locked and any
14870 -- modifications to them are treated as violations. Do not tamper with
14871 -- the tables, instead examine the Chars fields of all the scopes of Id.
14874 Chars
(Id
) = Name_Suspension_Object
14875 and then Present
(Scope
(Id
))
14876 and then Chars
(Scope
(Id
)) = Name_Synchronous_Task_Control
14877 and then Present
(Scope
(Scope
(Id
)))
14878 and then Chars
(Scope
(Scope
(Id
))) = Name_Ada
14879 and then Present
(Scope
(Scope
(Scope
(Id
))))
14880 and then Scope
(Scope
(Scope
(Id
))) = Standard_Standard
;
14881 end Is_Suspension_Object
;
14883 ----------------------------
14884 -- Is_Synchronized_Object --
14885 ----------------------------
14887 function Is_Synchronized_Object
(Id
: Entity_Id
) return Boolean is
14891 if Is_Object
(Id
) then
14893 -- The object is synchronized if it is of a type that yields a
14894 -- synchronized object.
14896 if Yields_Synchronized_Object
(Etype
(Id
)) then
14899 -- The object is synchronized if it is atomic and Async_Writers is
14902 elsif Is_Atomic
(Id
) and then Async_Writers_Enabled
(Id
) then
14905 -- A constant is a synchronized object by default
14907 elsif Ekind
(Id
) = E_Constant
then
14910 -- A variable is a synchronized object if it is subject to pragma
14911 -- Constant_After_Elaboration.
14913 elsif Ekind
(Id
) = E_Variable
then
14914 Prag
:= Get_Pragma
(Id
, Pragma_Constant_After_Elaboration
);
14916 return Present
(Prag
) and then Is_Enabled_Pragma
(Prag
);
14920 -- Otherwise the input is not an object or it does not qualify as a
14921 -- synchronized object.
14924 end Is_Synchronized_Object
;
14926 ---------------------------------
14927 -- Is_Synchronized_Tagged_Type --
14928 ---------------------------------
14930 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
14931 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
14934 -- A task or protected type derived from an interface is a tagged type.
14935 -- Such a tagged type is called a synchronized tagged type, as are
14936 -- synchronized interfaces and private extensions whose declaration
14937 -- includes the reserved word synchronized.
14939 return (Is_Tagged_Type
(E
)
14940 and then (Kind
= E_Task_Type
14942 Kind
= E_Protected_Type
))
14945 and then Is_Synchronized_Interface
(E
))
14947 (Ekind
(E
) = E_Record_Type_With_Private
14948 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
14949 and then (Synchronized_Present
(Parent
(E
))
14950 or else Is_Synchronized_Interface
(Etype
(E
))));
14951 end Is_Synchronized_Tagged_Type
;
14957 function Is_Transfer
(N
: Node_Id
) return Boolean is
14958 Kind
: constant Node_Kind
:= Nkind
(N
);
14961 if Kind
= N_Simple_Return_Statement
14963 Kind
= N_Extended_Return_Statement
14965 Kind
= N_Goto_Statement
14967 Kind
= N_Raise_Statement
14969 Kind
= N_Requeue_Statement
14973 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
14974 and then No
(Condition
(N
))
14978 elsif Kind
= N_Procedure_Call_Statement
14979 and then Is_Entity_Name
(Name
(N
))
14980 and then Present
(Entity
(Name
(N
)))
14981 and then No_Return
(Entity
(Name
(N
)))
14985 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
14997 function Is_True
(U
: Uint
) return Boolean is
15002 --------------------------------------
15003 -- Is_Unchecked_Conversion_Instance --
15004 --------------------------------------
15006 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
15010 -- Look for a function whose generic parent is the predefined intrinsic
15011 -- function Unchecked_Conversion, or for one that renames such an
15014 if Ekind
(Id
) = E_Function
then
15015 Par
:= Parent
(Id
);
15017 if Nkind
(Par
) = N_Function_Specification
then
15018 Par
:= Generic_Parent
(Par
);
15020 if Present
(Par
) then
15022 Chars
(Par
) = Name_Unchecked_Conversion
15023 and then Is_Intrinsic_Subprogram
(Par
)
15024 and then Is_Predefined_File_Name
15025 (Unit_File_Name
(Get_Source_Unit
(Par
)));
15028 Present
(Alias
(Id
))
15029 and then Is_Unchecked_Conversion_Instance
(Alias
(Id
));
15035 end Is_Unchecked_Conversion_Instance
;
15037 -------------------------------
15038 -- Is_Universal_Numeric_Type --
15039 -------------------------------
15041 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
15043 return T
= Universal_Integer
or else T
= Universal_Real
;
15044 end Is_Universal_Numeric_Type
;
15046 ----------------------------
15047 -- Is_Variable_Size_Array --
15048 ----------------------------
15050 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
15054 pragma Assert
(Is_Array_Type
(E
));
15056 -- Check if some index is initialized with a non-constant value
15058 Idx
:= First_Index
(E
);
15059 while Present
(Idx
) loop
15060 if Nkind
(Idx
) = N_Range
then
15061 if not Is_Constant_Bound
(Low_Bound
(Idx
))
15062 or else not Is_Constant_Bound
(High_Bound
(Idx
))
15068 Idx
:= Next_Index
(Idx
);
15072 end Is_Variable_Size_Array
;
15074 -----------------------------
15075 -- Is_Variable_Size_Record --
15076 -----------------------------
15078 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
15080 Comp_Typ
: Entity_Id
;
15083 pragma Assert
(Is_Record_Type
(E
));
15085 Comp
:= First_Entity
(E
);
15086 while Present
(Comp
) loop
15087 Comp_Typ
:= Etype
(Comp
);
15089 -- Recursive call if the record type has discriminants
15091 if Is_Record_Type
(Comp_Typ
)
15092 and then Has_Discriminants
(Comp_Typ
)
15093 and then Is_Variable_Size_Record
(Comp_Typ
)
15097 elsif Is_Array_Type
(Comp_Typ
)
15098 and then Is_Variable_Size_Array
(Comp_Typ
)
15103 Next_Entity
(Comp
);
15107 end Is_Variable_Size_Record
;
15113 function Is_Variable
15115 Use_Original_Node
: Boolean := True) return Boolean
15117 Orig_Node
: Node_Id
;
15119 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
15120 -- Within a protected function, the private components of the enclosing
15121 -- protected type are constants. A function nested within a (protected)
15122 -- procedure is not itself protected. Within the body of a protected
15123 -- function the current instance of the protected type is a constant.
15125 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
15126 -- Prefixes can involve implicit dereferences, in which case we must
15127 -- test for the case of a reference of a constant access type, which can
15128 -- can never be a variable.
15130 ---------------------------
15131 -- In_Protected_Function --
15132 ---------------------------
15134 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
15139 -- E is the current instance of a type
15141 if Is_Type
(E
) then
15150 if not Is_Protected_Type
(Prot
) then
15154 S
:= Current_Scope
;
15155 while Present
(S
) and then S
/= Prot
loop
15156 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
15165 end In_Protected_Function
;
15167 ------------------------
15168 -- Is_Variable_Prefix --
15169 ------------------------
15171 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
15173 if Is_Access_Type
(Etype
(P
)) then
15174 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
15176 -- For the case of an indexed component whose prefix has a packed
15177 -- array type, the prefix has been rewritten into a type conversion.
15178 -- Determine variable-ness from the converted expression.
15180 elsif Nkind
(P
) = N_Type_Conversion
15181 and then not Comes_From_Source
(P
)
15182 and then Is_Array_Type
(Etype
(P
))
15183 and then Is_Packed
(Etype
(P
))
15185 return Is_Variable
(Expression
(P
));
15188 return Is_Variable
(P
);
15190 end Is_Variable_Prefix
;
15192 -- Start of processing for Is_Variable
15195 -- Special check, allow x'Deref(expr) as a variable
15197 if Nkind
(N
) = N_Attribute_Reference
15198 and then Attribute_Name
(N
) = Name_Deref
15203 -- Check if we perform the test on the original node since this may be a
15204 -- test of syntactic categories which must not be disturbed by whatever
15205 -- rewriting might have occurred. For example, an aggregate, which is
15206 -- certainly NOT a variable, could be turned into a variable by
15209 if Use_Original_Node
then
15210 Orig_Node
:= Original_Node
(N
);
15215 -- Definitely OK if Assignment_OK is set. Since this is something that
15216 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
15218 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
15221 -- Normally we go to the original node, but there is one exception where
15222 -- we use the rewritten node, namely when it is an explicit dereference.
15223 -- The generated code may rewrite a prefix which is an access type with
15224 -- an explicit dereference. The dereference is a variable, even though
15225 -- the original node may not be (since it could be a constant of the
15228 -- In Ada 2005 we have a further case to consider: the prefix may be a
15229 -- function call given in prefix notation. The original node appears to
15230 -- be a selected component, but we need to examine the call.
15232 elsif Nkind
(N
) = N_Explicit_Dereference
15233 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
15234 and then Present
(Etype
(Orig_Node
))
15235 and then Is_Access_Type
(Etype
(Orig_Node
))
15237 -- Note that if the prefix is an explicit dereference that does not
15238 -- come from source, we must check for a rewritten function call in
15239 -- prefixed notation before other forms of rewriting, to prevent a
15243 (Nkind
(Orig_Node
) = N_Function_Call
15244 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
15246 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
15248 -- in Ada 2012, the dereference may have been added for a type with
15249 -- a declared implicit dereference aspect. Check that it is not an
15250 -- access to constant.
15252 elsif Nkind
(N
) = N_Explicit_Dereference
15253 and then Present
(Etype
(Orig_Node
))
15254 and then Ada_Version
>= Ada_2012
15255 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
15257 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
15259 -- A function call is never a variable
15261 elsif Nkind
(N
) = N_Function_Call
then
15264 -- All remaining checks use the original node
15266 elsif Is_Entity_Name
(Orig_Node
)
15267 and then Present
(Entity
(Orig_Node
))
15270 E
: constant Entity_Id
:= Entity
(Orig_Node
);
15271 K
: constant Entity_Kind
:= Ekind
(E
);
15274 return (K
= E_Variable
15275 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
15276 or else (K
= E_Component
15277 and then not In_Protected_Function
(E
))
15278 or else K
= E_Out_Parameter
15279 or else K
= E_In_Out_Parameter
15280 or else K
= E_Generic_In_Out_Parameter
15282 -- Current instance of type. If this is a protected type, check
15283 -- we are not within the body of one of its protected functions.
15285 or else (Is_Type
(E
)
15286 and then In_Open_Scopes
(E
)
15287 and then not In_Protected_Function
(E
))
15289 or else (Is_Incomplete_Or_Private_Type
(E
)
15290 and then In_Open_Scopes
(Full_View
(E
)));
15294 case Nkind
(Orig_Node
) is
15295 when N_Indexed_Component | N_Slice
=>
15296 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
15298 when N_Selected_Component
=>
15299 return (Is_Variable
(Selector_Name
(Orig_Node
))
15300 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
15302 (Nkind
(N
) = N_Expanded_Name
15303 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
15305 -- For an explicit dereference, the type of the prefix cannot
15306 -- be an access to constant or an access to subprogram.
15308 when N_Explicit_Dereference
=>
15310 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
15312 return Is_Access_Type
(Typ
)
15313 and then not Is_Access_Constant
(Root_Type
(Typ
))
15314 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
15317 -- The type conversion is the case where we do not deal with the
15318 -- context dependent special case of an actual parameter. Thus
15319 -- the type conversion is only considered a variable for the
15320 -- purposes of this routine if the target type is tagged. However,
15321 -- a type conversion is considered to be a variable if it does not
15322 -- come from source (this deals for example with the conversions
15323 -- of expressions to their actual subtypes).
15325 when N_Type_Conversion
=>
15326 return Is_Variable
(Expression
(Orig_Node
))
15328 (not Comes_From_Source
(Orig_Node
)
15330 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
15332 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
15334 -- GNAT allows an unchecked type conversion as a variable. This
15335 -- only affects the generation of internal expanded code, since
15336 -- calls to instantiations of Unchecked_Conversion are never
15337 -- considered variables (since they are function calls).
15339 when N_Unchecked_Type_Conversion
=>
15340 return Is_Variable
(Expression
(Orig_Node
));
15348 ---------------------------
15349 -- Is_Visibly_Controlled --
15350 ---------------------------
15352 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
15353 Root
: constant Entity_Id
:= Root_Type
(T
);
15355 return Chars
(Scope
(Root
)) = Name_Finalization
15356 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
15357 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
15358 end Is_Visibly_Controlled
;
15360 --------------------------
15361 -- Is_Volatile_Function --
15362 --------------------------
15364 function Is_Volatile_Function
(Func_Id
: Entity_Id
) return Boolean is
15366 pragma Assert
(Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
));
15368 -- A function declared within a protected type is volatile
15370 if Is_Protected_Type
(Scope
(Func_Id
)) then
15373 -- An instance of Ada.Unchecked_Conversion is a volatile function if
15374 -- either the source or the target are effectively volatile.
15376 elsif Is_Unchecked_Conversion_Instance
(Func_Id
)
15377 and then Has_Effectively_Volatile_Profile
(Func_Id
)
15381 -- Otherwise the function is treated as volatile if it is subject to
15382 -- enabled pragma Volatile_Function.
15386 Is_Enabled_Pragma
(Get_Pragma
(Func_Id
, Pragma_Volatile_Function
));
15388 end Is_Volatile_Function
;
15390 ------------------------
15391 -- Is_Volatile_Object --
15392 ------------------------
15394 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
15396 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
15397 -- If prefix is an implicit dereference, examine designated type
15399 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
15400 -- Determines if given object has volatile components
15402 ------------------------
15403 -- Is_Volatile_Prefix --
15404 ------------------------
15406 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
15407 Typ
: constant Entity_Id
:= Etype
(N
);
15410 if Is_Access_Type
(Typ
) then
15412 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
15415 return Is_Volatile
(Dtyp
)
15416 or else Has_Volatile_Components
(Dtyp
);
15420 return Object_Has_Volatile_Components
(N
);
15422 end Is_Volatile_Prefix
;
15424 ------------------------------------
15425 -- Object_Has_Volatile_Components --
15426 ------------------------------------
15428 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
15429 Typ
: constant Entity_Id
:= Etype
(N
);
15432 if Is_Volatile
(Typ
)
15433 or else Has_Volatile_Components
(Typ
)
15437 elsif Is_Entity_Name
(N
)
15438 and then (Has_Volatile_Components
(Entity
(N
))
15439 or else Is_Volatile
(Entity
(N
)))
15443 elsif Nkind
(N
) = N_Indexed_Component
15444 or else Nkind
(N
) = N_Selected_Component
15446 return Is_Volatile_Prefix
(Prefix
(N
));
15451 end Object_Has_Volatile_Components
;
15453 -- Start of processing for Is_Volatile_Object
15456 if Nkind
(N
) = N_Defining_Identifier
then
15457 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
15459 elsif Nkind
(N
) = N_Expanded_Name
then
15460 return Is_Volatile_Object
(Entity
(N
));
15462 elsif Is_Volatile
(Etype
(N
))
15463 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
15467 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
15468 and then Is_Volatile_Prefix
(Prefix
(N
))
15472 elsif Nkind
(N
) = N_Selected_Component
15473 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
15480 end Is_Volatile_Object
;
15482 ---------------------------
15483 -- Itype_Has_Declaration --
15484 ---------------------------
15486 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
15488 pragma Assert
(Is_Itype
(Id
));
15489 return Present
(Parent
(Id
))
15490 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
15491 N_Subtype_Declaration
)
15492 and then Defining_Entity
(Parent
(Id
)) = Id
;
15493 end Itype_Has_Declaration
;
15495 -------------------------
15496 -- Kill_Current_Values --
15497 -------------------------
15499 procedure Kill_Current_Values
15501 Last_Assignment_Only
: Boolean := False)
15504 if Is_Assignable
(Ent
) then
15505 Set_Last_Assignment
(Ent
, Empty
);
15508 if Is_Object
(Ent
) then
15509 if not Last_Assignment_Only
then
15511 Set_Current_Value
(Ent
, Empty
);
15513 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
15514 -- for a constant. Once the constant is elaborated, its value is
15515 -- not changed, therefore the associated flags that describe the
15516 -- value should not be modified either.
15518 if Ekind
(Ent
) = E_Constant
then
15521 -- Non-constant entities
15524 if not Can_Never_Be_Null
(Ent
) then
15525 Set_Is_Known_Non_Null
(Ent
, False);
15528 Set_Is_Known_Null
(Ent
, False);
15530 -- Reset the Is_Known_Valid flag unless the type is always
15531 -- valid. This does not apply to a loop parameter because its
15532 -- bounds are defined by the loop header and therefore always
15535 if not Is_Known_Valid
(Etype
(Ent
))
15536 and then Ekind
(Ent
) /= E_Loop_Parameter
15538 Set_Is_Known_Valid
(Ent
, False);
15543 end Kill_Current_Values
;
15545 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
15548 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
15549 -- Clear current value for entity E and all entities chained to E
15551 ------------------------------------------
15552 -- Kill_Current_Values_For_Entity_Chain --
15553 ------------------------------------------
15555 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
15559 while Present
(Ent
) loop
15560 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
15563 end Kill_Current_Values_For_Entity_Chain
;
15565 -- Start of processing for Kill_Current_Values
15568 -- Kill all saved checks, a special case of killing saved values
15570 if not Last_Assignment_Only
then
15574 -- Loop through relevant scopes, which includes the current scope and
15575 -- any parent scopes if the current scope is a block or a package.
15577 S
:= Current_Scope
;
15580 -- Clear current values of all entities in current scope
15582 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
15584 -- If scope is a package, also clear current values of all private
15585 -- entities in the scope.
15587 if Is_Package_Or_Generic_Package
(S
)
15588 or else Is_Concurrent_Type
(S
)
15590 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
15593 -- If this is a not a subprogram, deal with parents
15595 if not Is_Subprogram
(S
) then
15597 exit Scope_Loop
when S
= Standard_Standard
;
15601 end loop Scope_Loop
;
15602 end Kill_Current_Values
;
15604 --------------------------
15605 -- Kill_Size_Check_Code --
15606 --------------------------
15608 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
15610 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
15611 and then Present
(Size_Check_Code
(E
))
15613 Remove
(Size_Check_Code
(E
));
15614 Set_Size_Check_Code
(E
, Empty
);
15616 end Kill_Size_Check_Code
;
15618 --------------------------
15619 -- Known_To_Be_Assigned --
15620 --------------------------
15622 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
15623 P
: constant Node_Id
:= Parent
(N
);
15628 -- Test left side of assignment
15630 when N_Assignment_Statement
=>
15631 return N
= Name
(P
);
15633 -- Function call arguments are never lvalues
15635 when N_Function_Call
=>
15638 -- Positional parameter for procedure or accept call
15640 when N_Procedure_Call_Statement |
15649 Proc
:= Get_Subprogram_Entity
(P
);
15655 -- If we are not a list member, something is strange, so
15656 -- be conservative and return False.
15658 if not Is_List_Member
(N
) then
15662 -- We are going to find the right formal by stepping forward
15663 -- through the formals, as we step backwards in the actuals.
15665 Form
:= First_Formal
(Proc
);
15668 -- If no formal, something is weird, so be conservative
15669 -- and return False.
15676 exit when No
(Act
);
15677 Next_Formal
(Form
);
15680 return Ekind
(Form
) /= E_In_Parameter
;
15683 -- Named parameter for procedure or accept call
15685 when N_Parameter_Association
=>
15691 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
15697 -- Loop through formals to find the one that matches
15699 Form
:= First_Formal
(Proc
);
15701 -- If no matching formal, that's peculiar, some kind of
15702 -- previous error, so return False to be conservative.
15703 -- Actually this also happens in legal code in the case
15704 -- where P is a parameter association for an Extra_Formal???
15710 -- Else test for match
15712 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
15713 return Ekind
(Form
) /= E_In_Parameter
;
15716 Next_Formal
(Form
);
15720 -- Test for appearing in a conversion that itself appears
15721 -- in an lvalue context, since this should be an lvalue.
15723 when N_Type_Conversion
=>
15724 return Known_To_Be_Assigned
(P
);
15726 -- All other references are definitely not known to be modifications
15732 end Known_To_Be_Assigned
;
15734 ---------------------------
15735 -- Last_Source_Statement --
15736 ---------------------------
15738 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
15742 N
:= Last
(Statements
(HSS
));
15743 while Present
(N
) loop
15744 exit when Comes_From_Source
(N
);
15749 end Last_Source_Statement
;
15751 ----------------------------------
15752 -- Matching_Static_Array_Bounds --
15753 ----------------------------------
15755 function Matching_Static_Array_Bounds
15757 R_Typ
: Node_Id
) return Boolean
15759 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
15760 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
15772 if L_Ndims
/= R_Ndims
then
15776 -- Unconstrained types do not have static bounds
15778 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
15782 -- First treat specially the first dimension, as the lower bound and
15783 -- length of string literals are not stored like those of arrays.
15785 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
15786 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
15787 L_Len
:= String_Literal_Length
(L_Typ
);
15789 L_Index
:= First_Index
(L_Typ
);
15790 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
15792 if Is_OK_Static_Expression
(L_Low
)
15794 Is_OK_Static_Expression
(L_High
)
15796 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
15799 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
15806 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
15807 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
15808 R_Len
:= String_Literal_Length
(R_Typ
);
15810 R_Index
:= First_Index
(R_Typ
);
15811 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
15813 if Is_OK_Static_Expression
(R_Low
)
15815 Is_OK_Static_Expression
(R_High
)
15817 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
15820 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
15827 if (Is_OK_Static_Expression
(L_Low
)
15829 Is_OK_Static_Expression
(R_Low
))
15830 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
15831 and then L_Len
= R_Len
15838 -- Then treat all other dimensions
15840 for Indx
in 2 .. L_Ndims
loop
15844 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
15845 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
15847 if (Is_OK_Static_Expression
(L_Low
) and then
15848 Is_OK_Static_Expression
(L_High
) and then
15849 Is_OK_Static_Expression
(R_Low
) and then
15850 Is_OK_Static_Expression
(R_High
))
15851 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
15853 Expr_Value
(L_High
) = Expr_Value
(R_High
))
15861 -- If we fall through the loop, all indexes matched
15864 end Matching_Static_Array_Bounds
;
15866 -------------------
15867 -- May_Be_Lvalue --
15868 -------------------
15870 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
15871 P
: constant Node_Id
:= Parent
(N
);
15876 -- Test left side of assignment
15878 when N_Assignment_Statement
=>
15879 return N
= Name
(P
);
15881 -- Test prefix of component or attribute. Note that the prefix of an
15882 -- explicit or implicit dereference cannot be an l-value. In the case
15883 -- of a 'Read attribute, the reference can be an actual in the
15884 -- argument list of the attribute.
15886 when N_Attribute_Reference
=>
15887 return (N
= Prefix
(P
)
15888 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
)))
15890 Attribute_Name
(P
) = Name_Read
;
15892 -- For an expanded name, the name is an lvalue if the expanded name
15893 -- is an lvalue, but the prefix is never an lvalue, since it is just
15894 -- the scope where the name is found.
15896 when N_Expanded_Name
=>
15897 if N
= Prefix
(P
) then
15898 return May_Be_Lvalue
(P
);
15903 -- For a selected component A.B, A is certainly an lvalue if A.B is.
15904 -- B is a little interesting, if we have A.B := 3, there is some
15905 -- discussion as to whether B is an lvalue or not, we choose to say
15906 -- it is. Note however that A is not an lvalue if it is of an access
15907 -- type since this is an implicit dereference.
15909 when N_Selected_Component
=>
15911 and then Present
(Etype
(N
))
15912 and then Is_Access_Type
(Etype
(N
))
15916 return May_Be_Lvalue
(P
);
15919 -- For an indexed component or slice, the index or slice bounds is
15920 -- never an lvalue. The prefix is an lvalue if the indexed component
15921 -- or slice is an lvalue, except if it is an access type, where we
15922 -- have an implicit dereference.
15924 when N_Indexed_Component | N_Slice
=>
15926 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
15930 return May_Be_Lvalue
(P
);
15933 -- Prefix of a reference is an lvalue if the reference is an lvalue
15935 when N_Reference
=>
15936 return May_Be_Lvalue
(P
);
15938 -- Prefix of explicit dereference is never an lvalue
15940 when N_Explicit_Dereference
=>
15943 -- Positional parameter for subprogram, entry, or accept call.
15944 -- In older versions of Ada function call arguments are never
15945 -- lvalues. In Ada 2012 functions can have in-out parameters.
15947 when N_Subprogram_Call |
15948 N_Entry_Call_Statement |
15951 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
15955 -- The following mechanism is clumsy and fragile. A single flag
15956 -- set in Resolve_Actuals would be preferable ???
15964 Proc
:= Get_Subprogram_Entity
(P
);
15970 -- If we are not a list member, something is strange, so be
15971 -- conservative and return True.
15973 if not Is_List_Member
(N
) then
15977 -- We are going to find the right formal by stepping forward
15978 -- through the formals, as we step backwards in the actuals.
15980 Form
:= First_Formal
(Proc
);
15983 -- If no formal, something is weird, so be conservative and
15991 exit when No
(Act
);
15992 Next_Formal
(Form
);
15995 return Ekind
(Form
) /= E_In_Parameter
;
15998 -- Named parameter for procedure or accept call
16000 when N_Parameter_Association
=>
16006 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
16012 -- Loop through formals to find the one that matches
16014 Form
:= First_Formal
(Proc
);
16016 -- If no matching formal, that's peculiar, some kind of
16017 -- previous error, so return True to be conservative.
16018 -- Actually happens with legal code for an unresolved call
16019 -- where we may get the wrong homonym???
16025 -- Else test for match
16027 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
16028 return Ekind
(Form
) /= E_In_Parameter
;
16031 Next_Formal
(Form
);
16035 -- Test for appearing in a conversion that itself appears in an
16036 -- lvalue context, since this should be an lvalue.
16038 when N_Type_Conversion
=>
16039 return May_Be_Lvalue
(P
);
16041 -- Test for appearance in object renaming declaration
16043 when N_Object_Renaming_Declaration
=>
16046 -- All other references are definitely not lvalues
16054 -----------------------
16055 -- Mark_Coextensions --
16056 -----------------------
16058 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
16059 Is_Dynamic
: Boolean;
16060 -- Indicates whether the context causes nested coextensions to be
16061 -- dynamic or static
16063 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
16064 -- Recognize an allocator node and label it as a dynamic coextension
16066 --------------------
16067 -- Mark_Allocator --
16068 --------------------
16070 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
16072 if Nkind
(N
) = N_Allocator
then
16074 Set_Is_Dynamic_Coextension
(N
);
16076 -- If the allocator expression is potentially dynamic, it may
16077 -- be expanded out of order and require dynamic allocation
16078 -- anyway, so we treat the coextension itself as dynamic.
16079 -- Potential optimization ???
16081 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
16082 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
16084 Set_Is_Dynamic_Coextension
(N
);
16086 Set_Is_Static_Coextension
(N
);
16091 end Mark_Allocator
;
16093 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
16095 -- Start of processing for Mark_Coextensions
16098 -- An allocator that appears on the right-hand side of an assignment is
16099 -- treated as a potentially dynamic coextension when the right-hand side
16100 -- is an allocator or a qualified expression.
16102 -- Obj := new ...'(new Coextension ...);
16104 if Nkind
(Context_Nod
) = N_Assignment_Statement
then
16106 Nkind_In
(Expression
(Context_Nod
), N_Allocator
,
16107 N_Qualified_Expression
);
16109 -- An allocator that appears within the expression of a simple return
16110 -- statement is treated as a potentially dynamic coextension when the
16111 -- expression is either aggregate, allocator, or qualified expression.
16113 -- return (new Coextension ...);
16114 -- return new ...'(new Coextension ...);
16116 elsif Nkind
(Context_Nod
) = N_Simple_Return_Statement
then
16118 Nkind_In
(Expression
(Context_Nod
), N_Aggregate
,
16120 N_Qualified_Expression
);
16122 -- An alloctor that appears within the initialization expression of an
16123 -- object declaration is considered a potentially dynamic coextension
16124 -- when the initialization expression is an allocator or a qualified
16127 -- Obj : ... := new ...'(new Coextension ...);
16129 -- A similar case arises when the object declaration is part of an
16130 -- extended return statement.
16132 -- return Obj : ... := new ...'(new Coextension ...);
16133 -- return Obj : ... := (new Coextension ...);
16135 elsif Nkind
(Context_Nod
) = N_Object_Declaration
then
16137 Nkind_In
(Root_Nod
, N_Allocator
, N_Qualified_Expression
)
16139 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
16141 -- This routine should not be called with constructs that cannot contain
16145 raise Program_Error
;
16148 Mark_Allocators
(Root_Nod
);
16149 end Mark_Coextensions
;
16151 ----------------------
16152 -- Needs_One_Actual --
16153 ----------------------
16155 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
16156 Formal
: Entity_Id
;
16159 -- Ada 2005 or later, and formals present
16161 if Ada_Version
>= Ada_2005
and then Present
(First_Formal
(E
)) then
16162 Formal
:= Next_Formal
(First_Formal
(E
));
16163 while Present
(Formal
) loop
16164 if No
(Default_Value
(Formal
)) then
16168 Next_Formal
(Formal
);
16173 -- Ada 83/95 or no formals
16178 end Needs_One_Actual
;
16180 ------------------------
16181 -- New_Copy_List_Tree --
16182 ------------------------
16184 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
16189 if List
= No_List
then
16196 while Present
(E
) loop
16197 Append
(New_Copy_Tree
(E
), NL
);
16203 end New_Copy_List_Tree
;
16205 --------------------------------------------------
16206 -- New_Copy_Tree Auxiliary Data and Subprograms --
16207 --------------------------------------------------
16209 use Atree
.Unchecked_Access
;
16210 use Atree_Private_Part
;
16212 -- Our approach here requires a two pass traversal of the tree. The
16213 -- first pass visits all nodes that eventually will be copied looking
16214 -- for defining Itypes. If any defining Itypes are found, then they are
16215 -- copied, and an entry is added to the replacement map. In the second
16216 -- phase, the tree is copied, using the replacement map to replace any
16217 -- Itype references within the copied tree.
16219 -- The following hash tables are used if the Map supplied has more
16220 -- than hash threshold entries to speed up access to the map. If
16221 -- there are fewer entries, then the map is searched sequentially
16222 -- (because setting up a hash table for only a few entries takes
16223 -- more time than it saves.
16225 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
;
16226 -- Hash function used for hash operations
16228 -------------------
16229 -- New_Copy_Hash --
16230 -------------------
16232 function New_Copy_Hash
(E
: Entity_Id
) return NCT_Header_Num
is
16234 return Nat
(E
) mod (NCT_Header_Num
'Last + 1);
16241 -- The hash table NCT_Assoc associates old entities in the table
16242 -- with their corresponding new entities (i.e. the pairs of entries
16243 -- presented in the original Map argument are Key-Element pairs).
16245 package NCT_Assoc
is new Simple_HTable
(
16246 Header_Num
=> NCT_Header_Num
,
16247 Element
=> Entity_Id
,
16248 No_Element
=> Empty
,
16250 Hash
=> New_Copy_Hash
,
16251 Equal
=> Types
."=");
16253 ---------------------
16254 -- NCT_Itype_Assoc --
16255 ---------------------
16257 -- The hash table NCT_Itype_Assoc contains entries only for those
16258 -- old nodes which have a non-empty Associated_Node_For_Itype set.
16259 -- The key is the associated node, and the element is the new node
16260 -- itself (NOT the associated node for the new node).
16262 package NCT_Itype_Assoc
is new Simple_HTable
(
16263 Header_Num
=> NCT_Header_Num
,
16264 Element
=> Entity_Id
,
16265 No_Element
=> Empty
,
16267 Hash
=> New_Copy_Hash
,
16268 Equal
=> Types
."=");
16270 -------------------
16271 -- New_Copy_Tree --
16272 -------------------
16274 function New_Copy_Tree
16276 Map
: Elist_Id
:= No_Elist
;
16277 New_Sloc
: Source_Ptr
:= No_Location
;
16278 New_Scope
: Entity_Id
:= Empty
) return Node_Id
16280 Actual_Map
: Elist_Id
:= Map
;
16281 -- This is the actual map for the copy. It is initialized with the
16282 -- given elements, and then enlarged as required for Itypes that are
16283 -- copied during the first phase of the copy operation. The visit
16284 -- procedures add elements to this map as Itypes are encountered.
16285 -- The reason we cannot use Map directly, is that it may well be
16286 -- (and normally is) initialized to No_Elist, and if we have mapped
16287 -- entities, we have to reset it to point to a real Elist.
16289 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
;
16290 -- Called during second phase to map entities into their corresponding
16291 -- copies using Actual_Map. If the argument is not an entity, or is not
16292 -- in Actual_Map, then it is returned unchanged.
16294 procedure Build_NCT_Hash_Tables
;
16295 -- Builds hash tables (number of elements >= threshold value)
16297 function Copy_Elist_With_Replacement
16298 (Old_Elist
: Elist_Id
) return Elist_Id
;
16299 -- Called during second phase to copy element list doing replacements
16301 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
);
16302 -- Called during the second phase to process a copied Itype. The actual
16303 -- copy happened during the first phase (so that we could make the entry
16304 -- in the mapping), but we still have to deal with the descendants of
16305 -- the copied Itype and copy them where necessary.
16307 function Copy_List_With_Replacement
(Old_List
: List_Id
) return List_Id
;
16308 -- Called during second phase to copy list doing replacements
16310 function Copy_Node_With_Replacement
(Old_Node
: Node_Id
) return Node_Id
;
16311 -- Called during second phase to copy node doing replacements
16313 procedure Visit_Elist
(E
: Elist_Id
);
16314 -- Called during first phase to visit all elements of an Elist
16316 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
);
16317 -- Visit a single field, recursing to call Visit_Node or Visit_List
16318 -- if the field is a syntactic descendant of the current node (i.e.
16319 -- its parent is Node N).
16321 procedure Visit_Itype
(Old_Itype
: Entity_Id
);
16322 -- Called during first phase to visit subsidiary fields of a defining
16323 -- Itype, and also create a copy and make an entry in the replacement
16324 -- map for the new copy.
16326 procedure Visit_List
(L
: List_Id
);
16327 -- Called during first phase to visit all elements of a List
16329 procedure Visit_Node
(N
: Node_Or_Entity_Id
);
16330 -- Called during first phase to visit a node and all its subtrees
16336 function Assoc
(N
: Node_Or_Entity_Id
) return Node_Id
is
16341 if not Has_Extension
(N
) or else No
(Actual_Map
) then
16344 elsif NCT_Hash_Tables_Used
then
16345 Ent
:= NCT_Assoc
.Get
(Entity_Id
(N
));
16347 if Present
(Ent
) then
16353 -- No hash table used, do serial search
16356 E
:= First_Elmt
(Actual_Map
);
16357 while Present
(E
) loop
16358 if Node
(E
) = N
then
16359 return Node
(Next_Elmt
(E
));
16361 E
:= Next_Elmt
(Next_Elmt
(E
));
16369 ---------------------------
16370 -- Build_NCT_Hash_Tables --
16371 ---------------------------
16373 procedure Build_NCT_Hash_Tables
is
16377 if NCT_Hash_Table_Setup
then
16379 NCT_Itype_Assoc
.Reset
;
16382 Elmt
:= First_Elmt
(Actual_Map
);
16383 while Present
(Elmt
) loop
16384 Ent
:= Node
(Elmt
);
16386 -- Get new entity, and associate old and new
16389 NCT_Assoc
.Set
(Ent
, Node
(Elmt
));
16391 if Is_Type
(Ent
) then
16393 Anode
: constant Entity_Id
:=
16394 Associated_Node_For_Itype
(Ent
);
16397 if Present
(Anode
) then
16399 -- Enter a link between the associated node of the
16400 -- old Itype and the new Itype, for updating later
16401 -- when node is copied.
16403 NCT_Itype_Assoc
.Set
(Anode
, Node
(Elmt
));
16411 NCT_Hash_Tables_Used
:= True;
16412 NCT_Hash_Table_Setup
:= True;
16413 end Build_NCT_Hash_Tables
;
16415 ---------------------------------
16416 -- Copy_Elist_With_Replacement --
16417 ---------------------------------
16419 function Copy_Elist_With_Replacement
16420 (Old_Elist
: Elist_Id
) return Elist_Id
16423 New_Elist
: Elist_Id
;
16426 if No
(Old_Elist
) then
16430 New_Elist
:= New_Elmt_List
;
16432 M
:= First_Elmt
(Old_Elist
);
16433 while Present
(M
) loop
16434 Append_Elmt
(Copy_Node_With_Replacement
(Node
(M
)), New_Elist
);
16440 end Copy_Elist_With_Replacement
;
16442 ---------------------------------
16443 -- Copy_Itype_With_Replacement --
16444 ---------------------------------
16446 -- This routine exactly parallels its phase one analog Visit_Itype,
16448 procedure Copy_Itype_With_Replacement
(New_Itype
: Entity_Id
) is
16450 -- Translate Next_Entity, Scope, and Etype fields, in case they
16451 -- reference entities that have been mapped into copies.
16453 Set_Next_Entity
(New_Itype
, Assoc
(Next_Entity
(New_Itype
)));
16454 Set_Etype
(New_Itype
, Assoc
(Etype
(New_Itype
)));
16456 if Present
(New_Scope
) then
16457 Set_Scope
(New_Itype
, New_Scope
);
16459 Set_Scope
(New_Itype
, Assoc
(Scope
(New_Itype
)));
16462 -- Copy referenced fields
16464 if Is_Discrete_Type
(New_Itype
) then
16465 Set_Scalar_Range
(New_Itype
,
16466 Copy_Node_With_Replacement
(Scalar_Range
(New_Itype
)));
16468 elsif Has_Discriminants
(Base_Type
(New_Itype
)) then
16469 Set_Discriminant_Constraint
(New_Itype
,
16470 Copy_Elist_With_Replacement
16471 (Discriminant_Constraint
(New_Itype
)));
16473 elsif Is_Array_Type
(New_Itype
) then
16474 if Present
(First_Index
(New_Itype
)) then
16475 Set_First_Index
(New_Itype
,
16476 First
(Copy_List_With_Replacement
16477 (List_Containing
(First_Index
(New_Itype
)))));
16480 if Is_Packed
(New_Itype
) then
16481 Set_Packed_Array_Impl_Type
(New_Itype
,
16482 Copy_Node_With_Replacement
16483 (Packed_Array_Impl_Type
(New_Itype
)));
16486 end Copy_Itype_With_Replacement
;
16488 --------------------------------
16489 -- Copy_List_With_Replacement --
16490 --------------------------------
16492 function Copy_List_With_Replacement
16493 (Old_List
: List_Id
) return List_Id
16495 New_List
: List_Id
;
16499 if Old_List
= No_List
then
16503 New_List
:= Empty_List
;
16505 E
:= First
(Old_List
);
16506 while Present
(E
) loop
16507 Append
(Copy_Node_With_Replacement
(E
), New_List
);
16513 end Copy_List_With_Replacement
;
16515 --------------------------------
16516 -- Copy_Node_With_Replacement --
16517 --------------------------------
16519 function Copy_Node_With_Replacement
16520 (Old_Node
: Node_Id
) return Node_Id
16522 New_Node
: Node_Id
;
16524 procedure Adjust_Named_Associations
16525 (Old_Node
: Node_Id
;
16526 New_Node
: Node_Id
);
16527 -- If a call node has named associations, these are chained through
16528 -- the First_Named_Actual, Next_Named_Actual links. These must be
16529 -- propagated separately to the new parameter list, because these
16530 -- are not syntactic fields.
16532 function Copy_Field_With_Replacement
16533 (Field
: Union_Id
) return Union_Id
;
16534 -- Given Field, which is a field of Old_Node, return a copy of it
16535 -- if it is a syntactic field (i.e. its parent is Node), setting
16536 -- the parent of the copy to poit to New_Node. Otherwise returns
16537 -- the field (possibly mapped if it is an entity).
16539 -------------------------------
16540 -- Adjust_Named_Associations --
16541 -------------------------------
16543 procedure Adjust_Named_Associations
16544 (Old_Node
: Node_Id
;
16545 New_Node
: Node_Id
)
16550 Old_Next
: Node_Id
;
16551 New_Next
: Node_Id
;
16554 Old_E
:= First
(Parameter_Associations
(Old_Node
));
16555 New_E
:= First
(Parameter_Associations
(New_Node
));
16556 while Present
(Old_E
) loop
16557 if Nkind
(Old_E
) = N_Parameter_Association
16558 and then Present
(Next_Named_Actual
(Old_E
))
16560 if First_Named_Actual
(Old_Node
)
16561 = Explicit_Actual_Parameter
(Old_E
)
16563 Set_First_Named_Actual
16564 (New_Node
, Explicit_Actual_Parameter
(New_E
));
16567 -- Now scan parameter list from the beginning,to locate
16568 -- next named actual, which can be out of order.
16570 Old_Next
:= First
(Parameter_Associations
(Old_Node
));
16571 New_Next
:= First
(Parameter_Associations
(New_Node
));
16573 while Nkind
(Old_Next
) /= N_Parameter_Association
16574 or else Explicit_Actual_Parameter
(Old_Next
) /=
16575 Next_Named_Actual
(Old_E
)
16581 Set_Next_Named_Actual
16582 (New_E
, Explicit_Actual_Parameter
(New_Next
));
16588 end Adjust_Named_Associations
;
16590 ---------------------------------
16591 -- Copy_Field_With_Replacement --
16592 ---------------------------------
16594 function Copy_Field_With_Replacement
16595 (Field
: Union_Id
) return Union_Id
16598 if Field
= Union_Id
(Empty
) then
16601 elsif Field
in Node_Range
then
16603 Old_N
: constant Node_Id
:= Node_Id
(Field
);
16607 -- If syntactic field, as indicated by the parent pointer
16608 -- being set, then copy the referenced node recursively.
16610 if Parent
(Old_N
) = Old_Node
then
16611 New_N
:= Copy_Node_With_Replacement
(Old_N
);
16613 if New_N
/= Old_N
then
16614 Set_Parent
(New_N
, New_Node
);
16617 -- For semantic fields, update possible entity reference
16618 -- from the replacement map.
16621 New_N
:= Assoc
(Old_N
);
16624 return Union_Id
(New_N
);
16627 elsif Field
in List_Range
then
16629 Old_L
: constant List_Id
:= List_Id
(Field
);
16633 -- If syntactic field, as indicated by the parent pointer,
16634 -- then recursively copy the entire referenced list.
16636 if Parent
(Old_L
) = Old_Node
then
16637 New_L
:= Copy_List_With_Replacement
(Old_L
);
16638 Set_Parent
(New_L
, New_Node
);
16640 -- For semantic list, just returned unchanged
16646 return Union_Id
(New_L
);
16649 -- Anything other than a list or a node is returned unchanged
16654 end Copy_Field_With_Replacement
;
16656 -- Start of processing for Copy_Node_With_Replacement
16659 if Old_Node
<= Empty_Or_Error
then
16662 elsif Has_Extension
(Old_Node
) then
16663 return Assoc
(Old_Node
);
16666 New_Node
:= New_Copy
(Old_Node
);
16668 -- If the node we are copying is the associated node of a
16669 -- previously copied Itype, then adjust the associated node
16670 -- of the copy of that Itype accordingly.
16672 if Present
(Actual_Map
) then
16678 -- Case of hash table used
16680 if NCT_Hash_Tables_Used
then
16681 Ent
:= NCT_Itype_Assoc
.Get
(Old_Node
);
16683 if Present
(Ent
) then
16684 Set_Associated_Node_For_Itype
(Ent
, New_Node
);
16687 -- Case of no hash table used
16690 E
:= First_Elmt
(Actual_Map
);
16691 while Present
(E
) loop
16692 if Is_Itype
(Node
(E
))
16694 Old_Node
= Associated_Node_For_Itype
(Node
(E
))
16696 Set_Associated_Node_For_Itype
16697 (Node
(Next_Elmt
(E
)), New_Node
);
16700 E
:= Next_Elmt
(Next_Elmt
(E
));
16706 -- Recursively copy descendants
16709 (New_Node
, Copy_Field_With_Replacement
(Field1
(New_Node
)));
16711 (New_Node
, Copy_Field_With_Replacement
(Field2
(New_Node
)));
16713 (New_Node
, Copy_Field_With_Replacement
(Field3
(New_Node
)));
16715 (New_Node
, Copy_Field_With_Replacement
(Field4
(New_Node
)));
16717 (New_Node
, Copy_Field_With_Replacement
(Field5
(New_Node
)));
16719 -- Adjust Sloc of new node if necessary
16721 if New_Sloc
/= No_Location
then
16722 Set_Sloc
(New_Node
, New_Sloc
);
16724 -- If we adjust the Sloc, then we are essentially making a
16725 -- completely new node, so the Comes_From_Source flag should
16726 -- be reset to the proper default value.
16728 Set_Comes_From_Source
16729 (New_Node
, Default_Node
.Comes_From_Source
);
16732 -- If the node is a call and has named associations, set the
16733 -- corresponding links in the copy.
16735 if Nkind_In
(Old_Node
, N_Entry_Call_Statement
,
16737 N_Procedure_Call_Statement
)
16738 and then Present
(First_Named_Actual
(Old_Node
))
16740 Adjust_Named_Associations
(Old_Node
, New_Node
);
16743 -- Reset First_Real_Statement for Handled_Sequence_Of_Statements.
16744 -- The replacement mechanism applies to entities, and is not used
16745 -- here. Eventually we may need a more general graph-copying
16746 -- routine. For now, do a sequential search to find desired node.
16748 if Nkind
(Old_Node
) = N_Handled_Sequence_Of_Statements
16749 and then Present
(First_Real_Statement
(Old_Node
))
16752 Old_F
: constant Node_Id
:= First_Real_Statement
(Old_Node
);
16756 N1
:= First
(Statements
(Old_Node
));
16757 N2
:= First
(Statements
(New_Node
));
16759 while N1
/= Old_F
loop
16764 Set_First_Real_Statement
(New_Node
, N2
);
16769 -- All done, return copied node
16772 end Copy_Node_With_Replacement
;
16778 procedure Visit_Elist
(E
: Elist_Id
) is
16781 if Present
(E
) then
16782 Elmt
:= First_Elmt
(E
);
16784 while Elmt
/= No_Elmt
loop
16785 Visit_Node
(Node
(Elmt
));
16795 procedure Visit_Field
(F
: Union_Id
; N
: Node_Id
) is
16797 if F
= Union_Id
(Empty
) then
16800 elsif F
in Node_Range
then
16802 -- Copy node if it is syntactic, i.e. its parent pointer is
16803 -- set to point to the field that referenced it (certain
16804 -- Itypes will also meet this criterion, which is fine, since
16805 -- these are clearly Itypes that do need to be copied, since
16806 -- we are copying their parent.)
16808 if Parent
(Node_Id
(F
)) = N
then
16809 Visit_Node
(Node_Id
(F
));
16812 -- Another case, if we are pointing to an Itype, then we want
16813 -- to copy it if its associated node is somewhere in the tree
16816 -- Note: the exclusion of self-referential copies is just an
16817 -- optimization, since the search of the already copied list
16818 -- would catch it, but it is a common case (Etype pointing
16819 -- to itself for an Itype that is a base type).
16821 elsif Has_Extension
(Node_Id
(F
))
16822 and then Is_Itype
(Entity_Id
(F
))
16823 and then Node_Id
(F
) /= N
16829 P
:= Associated_Node_For_Itype
(Node_Id
(F
));
16830 while Present
(P
) loop
16832 Visit_Node
(Node_Id
(F
));
16839 -- An Itype whose parent is not being copied definitely
16840 -- should NOT be copied, since it does not belong in any
16841 -- sense to the copied subtree.
16847 elsif F
in List_Range
and then Parent
(List_Id
(F
)) = N
then
16848 Visit_List
(List_Id
(F
));
16857 procedure Visit_Itype
(Old_Itype
: Entity_Id
) is
16858 New_Itype
: Entity_Id
;
16863 -- Itypes that describe the designated type of access to subprograms
16864 -- have the structure of subprogram declarations, with signatures,
16865 -- etc. Either we duplicate the signatures completely, or choose to
16866 -- share such itypes, which is fine because their elaboration will
16867 -- have no side effects.
16869 if Ekind
(Old_Itype
) = E_Subprogram_Type
then
16873 New_Itype
:= New_Copy
(Old_Itype
);
16875 -- The new Itype has all the attributes of the old one, and
16876 -- we just copy the contents of the entity. However, the back-end
16877 -- needs different names for debugging purposes, so we create a
16878 -- new internal name for it in all cases.
16880 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
16882 -- If our associated node is an entity that has already been copied,
16883 -- then set the associated node of the copy to point to the right
16884 -- copy. If we have copied an Itype that is itself the associated
16885 -- node of some previously copied Itype, then we set the right
16886 -- pointer in the other direction.
16888 if Present
(Actual_Map
) then
16890 -- Case of hash tables used
16892 if NCT_Hash_Tables_Used
then
16894 Ent
:= NCT_Assoc
.Get
(Associated_Node_For_Itype
(Old_Itype
));
16896 if Present
(Ent
) then
16897 Set_Associated_Node_For_Itype
(New_Itype
, Ent
);
16900 Ent
:= NCT_Itype_Assoc
.Get
(Old_Itype
);
16901 if Present
(Ent
) then
16902 Set_Associated_Node_For_Itype
(Ent
, New_Itype
);
16904 -- If the hash table has no association for this Itype and
16905 -- its associated node, enter one now.
16908 NCT_Itype_Assoc
.Set
16909 (Associated_Node_For_Itype
(Old_Itype
), New_Itype
);
16912 -- Case of hash tables not used
16915 E
:= First_Elmt
(Actual_Map
);
16916 while Present
(E
) loop
16917 if Associated_Node_For_Itype
(Old_Itype
) = Node
(E
) then
16918 Set_Associated_Node_For_Itype
16919 (New_Itype
, Node
(Next_Elmt
(E
)));
16922 if Is_Type
(Node
(E
))
16923 and then Old_Itype
= Associated_Node_For_Itype
(Node
(E
))
16925 Set_Associated_Node_For_Itype
16926 (Node
(Next_Elmt
(E
)), New_Itype
);
16929 E
:= Next_Elmt
(Next_Elmt
(E
));
16934 if Present
(Freeze_Node
(New_Itype
)) then
16935 Set_Is_Frozen
(New_Itype
, False);
16936 Set_Freeze_Node
(New_Itype
, Empty
);
16939 -- Add new association to map
16941 if No
(Actual_Map
) then
16942 Actual_Map
:= New_Elmt_List
;
16945 Append_Elmt
(Old_Itype
, Actual_Map
);
16946 Append_Elmt
(New_Itype
, Actual_Map
);
16948 if NCT_Hash_Tables_Used
then
16949 NCT_Assoc
.Set
(Old_Itype
, New_Itype
);
16952 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
16954 if NCT_Table_Entries
> NCT_Hash_Threshold
then
16955 Build_NCT_Hash_Tables
;
16959 -- If a record subtype is simply copied, the entity list will be
16960 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
16962 if Ekind_In
(Old_Itype
, E_Record_Subtype
, E_Class_Wide_Subtype
) then
16963 Set_Cloned_Subtype
(New_Itype
, Old_Itype
);
16966 -- Visit descendants that eventually get copied
16968 Visit_Field
(Union_Id
(Etype
(Old_Itype
)), Old_Itype
);
16970 if Is_Discrete_Type
(Old_Itype
) then
16971 Visit_Field
(Union_Id
(Scalar_Range
(Old_Itype
)), Old_Itype
);
16973 elsif Has_Discriminants
(Base_Type
(Old_Itype
)) then
16974 -- ??? This should involve call to Visit_Field
16975 Visit_Elist
(Discriminant_Constraint
(Old_Itype
));
16977 elsif Is_Array_Type
(Old_Itype
) then
16978 if Present
(First_Index
(Old_Itype
)) then
16979 Visit_Field
(Union_Id
(List_Containing
16980 (First_Index
(Old_Itype
))),
16984 if Is_Packed
(Old_Itype
) then
16985 Visit_Field
(Union_Id
(Packed_Array_Impl_Type
(Old_Itype
)),
16995 procedure Visit_List
(L
: List_Id
) is
16998 if L
/= No_List
then
17001 while Present
(N
) loop
17012 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
17014 -- Start of processing for Visit_Node
17017 -- Handle case of an Itype, which must be copied
17019 if Has_Extension
(N
) and then Is_Itype
(N
) then
17021 -- Nothing to do if already in the list. This can happen with an
17022 -- Itype entity that appears more than once in the tree.
17023 -- Note that we do not want to visit descendants in this case.
17025 -- Test for already in list when hash table is used
17027 if NCT_Hash_Tables_Used
then
17028 if Present
(NCT_Assoc
.Get
(Entity_Id
(N
))) then
17032 -- Test for already in list when hash table not used
17038 if Present
(Actual_Map
) then
17039 E
:= First_Elmt
(Actual_Map
);
17040 while Present
(E
) loop
17041 if Node
(E
) = N
then
17044 E
:= Next_Elmt
(Next_Elmt
(E
));
17054 -- Visit descendants
17056 Visit_Field
(Field1
(N
), N
);
17057 Visit_Field
(Field2
(N
), N
);
17058 Visit_Field
(Field3
(N
), N
);
17059 Visit_Field
(Field4
(N
), N
);
17060 Visit_Field
(Field5
(N
), N
);
17063 -- Start of processing for New_Copy_Tree
17068 -- See if we should use hash table
17070 if No
(Actual_Map
) then
17071 NCT_Hash_Tables_Used
:= False;
17078 NCT_Table_Entries
:= 0;
17080 Elmt
:= First_Elmt
(Actual_Map
);
17081 while Present
(Elmt
) loop
17082 NCT_Table_Entries
:= NCT_Table_Entries
+ 1;
17087 if NCT_Table_Entries
> NCT_Hash_Threshold
then
17088 Build_NCT_Hash_Tables
;
17090 NCT_Hash_Tables_Used
:= False;
17095 -- Hash table set up if required, now start phase one by visiting
17096 -- top node (we will recursively visit the descendants).
17098 Visit_Node
(Source
);
17100 -- Now the second phase of the copy can start. First we process
17101 -- all the mapped entities, copying their descendants.
17103 if Present
(Actual_Map
) then
17106 New_Itype
: Entity_Id
;
17108 Elmt
:= First_Elmt
(Actual_Map
);
17109 while Present
(Elmt
) loop
17111 New_Itype
:= Node
(Elmt
);
17113 if Is_Itype
(New_Itype
) then
17114 Copy_Itype_With_Replacement
(New_Itype
);
17121 -- Now we can copy the actual tree
17123 return Copy_Node_With_Replacement
(Source
);
17126 -------------------------
17127 -- New_External_Entity --
17128 -------------------------
17130 function New_External_Entity
17131 (Kind
: Entity_Kind
;
17132 Scope_Id
: Entity_Id
;
17133 Sloc_Value
: Source_Ptr
;
17134 Related_Id
: Entity_Id
;
17135 Suffix
: Character;
17136 Suffix_Index
: Nat
:= 0;
17137 Prefix
: Character := ' ') return Entity_Id
17139 N
: constant Entity_Id
:=
17140 Make_Defining_Identifier
(Sloc_Value
,
17142 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
17145 Set_Ekind
(N
, Kind
);
17146 Set_Is_Internal
(N
, True);
17147 Append_Entity
(N
, Scope_Id
);
17148 Set_Public_Status
(N
);
17150 if Kind
in Type_Kind
then
17151 Init_Size_Align
(N
);
17155 end New_External_Entity
;
17157 -------------------------
17158 -- New_Internal_Entity --
17159 -------------------------
17161 function New_Internal_Entity
17162 (Kind
: Entity_Kind
;
17163 Scope_Id
: Entity_Id
;
17164 Sloc_Value
: Source_Ptr
;
17165 Id_Char
: Character) return Entity_Id
17167 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
17170 Set_Ekind
(N
, Kind
);
17171 Set_Is_Internal
(N
, True);
17172 Append_Entity
(N
, Scope_Id
);
17174 if Kind
in Type_Kind
then
17175 Init_Size_Align
(N
);
17179 end New_Internal_Entity
;
17185 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
17189 -- If we are pointing at a positional parameter, it is a member of a
17190 -- node list (the list of parameters), and the next parameter is the
17191 -- next node on the list, unless we hit a parameter association, then
17192 -- we shift to using the chain whose head is the First_Named_Actual in
17193 -- the parent, and then is threaded using the Next_Named_Actual of the
17194 -- Parameter_Association. All this fiddling is because the original node
17195 -- list is in the textual call order, and what we need is the
17196 -- declaration order.
17198 if Is_List_Member
(Actual_Id
) then
17199 N
:= Next
(Actual_Id
);
17201 if Nkind
(N
) = N_Parameter_Association
then
17202 return First_Named_Actual
(Parent
(Actual_Id
));
17208 return Next_Named_Actual
(Parent
(Actual_Id
));
17212 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
17214 Actual_Id
:= Next_Actual
(Actual_Id
);
17217 -----------------------
17218 -- Normalize_Actuals --
17219 -----------------------
17221 -- Chain actuals according to formals of subprogram. If there are no named
17222 -- associations, the chain is simply the list of Parameter Associations,
17223 -- since the order is the same as the declaration order. If there are named
17224 -- associations, then the First_Named_Actual field in the N_Function_Call
17225 -- or N_Procedure_Call_Statement node points to the Parameter_Association
17226 -- node for the parameter that comes first in declaration order. The
17227 -- remaining named parameters are then chained in declaration order using
17228 -- Next_Named_Actual.
17230 -- This routine also verifies that the number of actuals is compatible with
17231 -- the number and default values of formals, but performs no type checking
17232 -- (type checking is done by the caller).
17234 -- If the matching succeeds, Success is set to True and the caller proceeds
17235 -- with type-checking. If the match is unsuccessful, then Success is set to
17236 -- False, and the caller attempts a different interpretation, if there is
17239 -- If the flag Report is on, the call is not overloaded, and a failure to
17240 -- match can be reported here, rather than in the caller.
17242 procedure Normalize_Actuals
17246 Success
: out Boolean)
17248 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
17249 Actual
: Node_Id
:= Empty
;
17250 Formal
: Entity_Id
;
17251 Last
: Node_Id
:= Empty
;
17252 First_Named
: Node_Id
:= Empty
;
17255 Formals_To_Match
: Integer := 0;
17256 Actuals_To_Match
: Integer := 0;
17258 procedure Chain
(A
: Node_Id
);
17259 -- Add named actual at the proper place in the list, using the
17260 -- Next_Named_Actual link.
17262 function Reporting
return Boolean;
17263 -- Determines if an error is to be reported. To report an error, we
17264 -- need Report to be True, and also we do not report errors caused
17265 -- by calls to init procs that occur within other init procs. Such
17266 -- errors must always be cascaded errors, since if all the types are
17267 -- declared correctly, the compiler will certainly build decent calls.
17273 procedure Chain
(A
: Node_Id
) is
17277 -- Call node points to first actual in list
17279 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
17282 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
17286 Set_Next_Named_Actual
(Last
, Empty
);
17293 function Reporting
return Boolean is
17298 elsif not Within_Init_Proc
then
17301 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
17309 -- Start of processing for Normalize_Actuals
17312 if Is_Access_Type
(S
) then
17314 -- The name in the call is a function call that returns an access
17315 -- to subprogram. The designated type has the list of formals.
17317 Formal
:= First_Formal
(Designated_Type
(S
));
17319 Formal
:= First_Formal
(S
);
17322 while Present
(Formal
) loop
17323 Formals_To_Match
:= Formals_To_Match
+ 1;
17324 Next_Formal
(Formal
);
17327 -- Find if there is a named association, and verify that no positional
17328 -- associations appear after named ones.
17330 if Present
(Actuals
) then
17331 Actual
:= First
(Actuals
);
17334 while Present
(Actual
)
17335 and then Nkind
(Actual
) /= N_Parameter_Association
17337 Actuals_To_Match
:= Actuals_To_Match
+ 1;
17341 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
17343 -- Most common case: positional notation, no defaults
17348 elsif Actuals_To_Match
> Formals_To_Match
then
17350 -- Too many actuals: will not work
17353 if Is_Entity_Name
(Name
(N
)) then
17354 Error_Msg_N
("too many arguments in call to&", Name
(N
));
17356 Error_Msg_N
("too many arguments in call", N
);
17364 First_Named
:= Actual
;
17366 while Present
(Actual
) loop
17367 if Nkind
(Actual
) /= N_Parameter_Association
then
17369 ("positional parameters not allowed after named ones", Actual
);
17374 Actuals_To_Match
:= Actuals_To_Match
+ 1;
17380 if Present
(Actuals
) then
17381 Actual
:= First
(Actuals
);
17384 Formal
:= First_Formal
(S
);
17385 while Present
(Formal
) loop
17387 -- Match the formals in order. If the corresponding actual is
17388 -- positional, nothing to do. Else scan the list of named actuals
17389 -- to find the one with the right name.
17391 if Present
(Actual
)
17392 and then Nkind
(Actual
) /= N_Parameter_Association
17395 Actuals_To_Match
:= Actuals_To_Match
- 1;
17396 Formals_To_Match
:= Formals_To_Match
- 1;
17399 -- For named parameters, search the list of actuals to find
17400 -- one that matches the next formal name.
17402 Actual
:= First_Named
;
17404 while Present
(Actual
) loop
17405 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
17408 Actuals_To_Match
:= Actuals_To_Match
- 1;
17409 Formals_To_Match
:= Formals_To_Match
- 1;
17417 if Ekind
(Formal
) /= E_In_Parameter
17418 or else No
(Default_Value
(Formal
))
17421 if (Comes_From_Source
(S
)
17422 or else Sloc
(S
) = Standard_Location
)
17423 and then Is_Overloadable
(S
)
17427 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
17429 N_Parameter_Association
)
17430 and then Ekind
(S
) /= E_Function
17432 Set_Etype
(N
, Etype
(S
));
17435 Error_Msg_Name_1
:= Chars
(S
);
17436 Error_Msg_Sloc
:= Sloc
(S
);
17438 ("missing argument for parameter & "
17439 & "in call to % declared #", N
, Formal
);
17442 elsif Is_Overloadable
(S
) then
17443 Error_Msg_Name_1
:= Chars
(S
);
17445 -- Point to type derivation that generated the
17448 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
17451 ("missing argument for parameter & "
17452 & "in call to % (inherited) #", N
, Formal
);
17456 ("missing argument for parameter &", N
, Formal
);
17464 Formals_To_Match
:= Formals_To_Match
- 1;
17469 Next_Formal
(Formal
);
17472 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
17479 -- Find some superfluous named actual that did not get
17480 -- attached to the list of associations.
17482 Actual
:= First
(Actuals
);
17483 while Present
(Actual
) loop
17484 if Nkind
(Actual
) = N_Parameter_Association
17485 and then Actual
/= Last
17486 and then No
(Next_Named_Actual
(Actual
))
17488 -- A validity check may introduce a copy of a call that
17489 -- includes an extra actual (for example for an unrelated
17490 -- accessibility check). Check that the extra actual matches
17491 -- some extra formal, which must exist already because
17492 -- subprogram must be frozen at this point.
17494 if Present
(Extra_Formals
(S
))
17495 and then not Comes_From_Source
(Actual
)
17496 and then Nkind
(Actual
) = N_Parameter_Association
17497 and then Chars
(Extra_Formals
(S
)) =
17498 Chars
(Selector_Name
(Actual
))
17503 ("unmatched actual & in call", Selector_Name
(Actual
));
17515 end Normalize_Actuals
;
17517 --------------------------------
17518 -- Note_Possible_Modification --
17519 --------------------------------
17521 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
17522 Modification_Comes_From_Source
: constant Boolean :=
17523 Comes_From_Source
(Parent
(N
));
17529 -- Loop to find referenced entity, if there is one
17535 if Is_Entity_Name
(Exp
) then
17536 Ent
:= Entity
(Exp
);
17538 -- If the entity is missing, it is an undeclared identifier,
17539 -- and there is nothing to annotate.
17545 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
17547 P
: constant Node_Id
:= Prefix
(Exp
);
17550 -- In formal verification mode, keep track of all reads and
17551 -- writes through explicit dereferences.
17553 if GNATprove_Mode
then
17554 SPARK_Specific
.Generate_Dereference
(N
, 'm');
17557 if Nkind
(P
) = N_Selected_Component
17558 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
17560 -- Case of a reference to an entry formal
17562 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
17564 elsif Nkind
(P
) = N_Identifier
17565 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
17566 and then Present
(Expression
(Parent
(Entity
(P
))))
17567 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
17570 -- Case of a reference to a value on which side effects have
17573 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
17581 elsif Nkind_In
(Exp
, N_Type_Conversion
,
17582 N_Unchecked_Type_Conversion
)
17584 Exp
:= Expression
(Exp
);
17587 elsif Nkind_In
(Exp
, N_Slice
,
17588 N_Indexed_Component
,
17589 N_Selected_Component
)
17591 -- Special check, if the prefix is an access type, then return
17592 -- since we are modifying the thing pointed to, not the prefix.
17593 -- When we are expanding, most usually the prefix is replaced
17594 -- by an explicit dereference, and this test is not needed, but
17595 -- in some cases (notably -gnatc mode and generics) when we do
17596 -- not do full expansion, we need this special test.
17598 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
17601 -- Otherwise go to prefix and keep going
17604 Exp
:= Prefix
(Exp
);
17608 -- All other cases, not a modification
17614 -- Now look for entity being referenced
17616 if Present
(Ent
) then
17617 if Is_Object
(Ent
) then
17618 if Comes_From_Source
(Exp
)
17619 or else Modification_Comes_From_Source
17621 -- Give warning if pragma unmodified is given and we are
17622 -- sure this is a modification.
17624 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
17626 -- Note that the entity may be present only as a result
17627 -- of pragma Unused.
17629 if Has_Pragma_Unused
(Ent
) then
17630 Error_Msg_NE
("??pragma Unused given for &!", N
, Ent
);
17633 ("??pragma Unmodified given for &!", N
, Ent
);
17637 Set_Never_Set_In_Source
(Ent
, False);
17640 Set_Is_True_Constant
(Ent
, False);
17641 Set_Current_Value
(Ent
, Empty
);
17642 Set_Is_Known_Null
(Ent
, False);
17644 if not Can_Never_Be_Null
(Ent
) then
17645 Set_Is_Known_Non_Null
(Ent
, False);
17648 -- Follow renaming chain
17650 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
17651 and then Present
(Renamed_Object
(Ent
))
17653 Exp
:= Renamed_Object
(Ent
);
17655 -- If the entity is the loop variable in an iteration over
17656 -- a container, retrieve container expression to indicate
17657 -- possible modification.
17659 if Present
(Related_Expression
(Ent
))
17660 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
17661 N_Iterator_Specification
17663 Exp
:= Original_Node
(Related_Expression
(Ent
));
17668 -- The expression may be the renaming of a subcomponent of an
17669 -- array or container. The assignment to the subcomponent is
17670 -- a modification of the container.
17672 elsif Comes_From_Source
(Original_Node
(Exp
))
17673 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
17674 N_Indexed_Component
)
17676 Exp
:= Prefix
(Original_Node
(Exp
));
17680 -- Generate a reference only if the assignment comes from
17681 -- source. This excludes, for example, calls to a dispatching
17682 -- assignment operation when the left-hand side is tagged. In
17683 -- GNATprove mode, we need those references also on generated
17684 -- code, as these are used to compute the local effects of
17687 if Modification_Comes_From_Source
or GNATprove_Mode
then
17688 Generate_Reference
(Ent
, Exp
, 'm');
17690 -- If the target of the assignment is the bound variable
17691 -- in an iterator, indicate that the corresponding array
17692 -- or container is also modified.
17694 if Ada_Version
>= Ada_2012
17695 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
17698 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
17701 -- TBD : in the full version of the construct, the
17702 -- domain of iteration can be given by an expression.
17704 if Is_Entity_Name
(Domain
) then
17705 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
17706 Set_Is_True_Constant
(Entity
(Domain
), False);
17707 Set_Never_Set_In_Source
(Entity
(Domain
), False);
17716 -- If we are sure this is a modification from source, and we know
17717 -- this modifies a constant, then give an appropriate warning.
17720 and then Modification_Comes_From_Source
17721 and then Overlays_Constant
(Ent
)
17722 and then Address_Clause_Overlay_Warnings
17725 Addr
: constant Node_Id
:= Address_Clause
(Ent
);
17730 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
17732 Error_Msg_Sloc
:= Sloc
(Addr
);
17734 ("??constant& may be modified via address clause#",
17745 end Note_Possible_Modification
;
17747 --------------------------------------
17748 -- Null_To_Null_Address_Convert_OK --
17749 --------------------------------------
17751 function Null_To_Null_Address_Convert_OK
17753 Typ
: Entity_Id
:= Empty
) return Boolean
17756 if not Relaxed_RM_Semantics
then
17760 if Nkind
(N
) = N_Null
then
17761 return Present
(Typ
) and then Is_Descendant_Of_Address
(Typ
);
17763 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
, N_Op_Ne
)
17766 L
: constant Node_Id
:= Left_Opnd
(N
);
17767 R
: constant Node_Id
:= Right_Opnd
(N
);
17770 -- We check the Etype of the complementary operand since the
17771 -- N_Null node is not decorated at this stage.
17774 ((Nkind
(L
) = N_Null
17775 and then Is_Descendant_Of_Address
(Etype
(R
)))
17777 (Nkind
(R
) = N_Null
17778 and then Is_Descendant_Of_Address
(Etype
(L
))));
17783 end Null_To_Null_Address_Convert_OK
;
17785 -------------------------
17786 -- Object_Access_Level --
17787 -------------------------
17789 -- Returns the static accessibility level of the view denoted by Obj. Note
17790 -- that the value returned is the result of a call to Scope_Depth. Only
17791 -- scope depths associated with dynamic scopes can actually be returned.
17792 -- Since only relative levels matter for accessibility checking, the fact
17793 -- that the distance between successive levels of accessibility is not
17794 -- always one is immaterial (invariant: if level(E2) is deeper than
17795 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
17797 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
17798 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
17799 -- Determine whether N is a construct of the form
17800 -- Some_Type (Operand._tag'Address)
17801 -- This construct appears in the context of dispatching calls.
17803 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
17804 -- An explicit dereference is created when removing side-effects from
17805 -- expressions for constraint checking purposes. In this case a local
17806 -- access type is created for it. The correct access level is that of
17807 -- the original source node. We detect this case by noting that the
17808 -- prefix of the dereference is created by an object declaration whose
17809 -- initial expression is a reference.
17811 -----------------------------
17812 -- Is_Interface_Conversion --
17813 -----------------------------
17815 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
17817 return Nkind
(N
) = N_Unchecked_Type_Conversion
17818 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
17819 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
17820 end Is_Interface_Conversion
;
17826 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
17827 Pref
: constant Node_Id
:= Prefix
(Obj
);
17829 if Is_Entity_Name
(Pref
)
17830 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
17831 and then Present
(Expression
(Parent
(Entity
(Pref
))))
17832 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
17834 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
17844 -- Start of processing for Object_Access_Level
17847 if Nkind
(Obj
) = N_Defining_Identifier
17848 or else Is_Entity_Name
(Obj
)
17850 if Nkind
(Obj
) = N_Defining_Identifier
then
17856 if Is_Prival
(E
) then
17857 E
:= Prival_Link
(E
);
17860 -- If E is a type then it denotes a current instance. For this case
17861 -- we add one to the normal accessibility level of the type to ensure
17862 -- that current instances are treated as always being deeper than
17863 -- than the level of any visible named access type (see 3.10.2(21)).
17865 if Is_Type
(E
) then
17866 return Type_Access_Level
(E
) + 1;
17868 elsif Present
(Renamed_Object
(E
)) then
17869 return Object_Access_Level
(Renamed_Object
(E
));
17871 -- Similarly, if E is a component of the current instance of a
17872 -- protected type, any instance of it is assumed to be at a deeper
17873 -- level than the type. For a protected object (whose type is an
17874 -- anonymous protected type) its components are at the same level
17875 -- as the type itself.
17877 elsif not Is_Overloadable
(E
)
17878 and then Ekind
(Scope
(E
)) = E_Protected_Type
17879 and then Comes_From_Source
(Scope
(E
))
17881 return Type_Access_Level
(Scope
(E
)) + 1;
17884 -- Aliased formals of functions take their access level from the
17885 -- point of call, i.e. require a dynamic check. For static check
17886 -- purposes, this is smaller than the level of the subprogram
17887 -- itself. For procedures the aliased makes no difference.
17890 and then Is_Aliased
(E
)
17891 and then Ekind
(Scope
(E
)) = E_Function
17893 return Type_Access_Level
(Etype
(E
));
17896 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
17900 elsif Nkind
(Obj
) = N_Selected_Component
then
17901 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
17902 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
17904 return Object_Access_Level
(Prefix
(Obj
));
17907 elsif Nkind
(Obj
) = N_Indexed_Component
then
17908 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
17909 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
17911 return Object_Access_Level
(Prefix
(Obj
));
17914 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
17916 -- If the prefix is a selected access discriminant then we make a
17917 -- recursive call on the prefix, which will in turn check the level
17918 -- of the prefix object of the selected discriminant.
17920 -- In Ada 2012, if the discriminant has implicit dereference and
17921 -- the context is a selected component, treat this as an object of
17922 -- unknown scope (see below). This is necessary in compile-only mode;
17923 -- otherwise expansion will already have transformed the prefix into
17926 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
17927 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
17929 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
17931 (not Has_Implicit_Dereference
17932 (Entity
(Selector_Name
(Prefix
(Obj
))))
17933 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
17935 return Object_Access_Level
(Prefix
(Obj
));
17937 -- Detect an interface conversion in the context of a dispatching
17938 -- call. Use the original form of the conversion to find the access
17939 -- level of the operand.
17941 elsif Is_Interface
(Etype
(Obj
))
17942 and then Is_Interface_Conversion
(Prefix
(Obj
))
17943 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
17945 return Object_Access_Level
(Original_Node
(Obj
));
17947 elsif not Comes_From_Source
(Obj
) then
17949 Ref
: constant Node_Id
:= Reference_To
(Obj
);
17951 if Present
(Ref
) then
17952 return Object_Access_Level
(Ref
);
17954 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
17959 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
17962 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
17963 return Object_Access_Level
(Expression
(Obj
));
17965 elsif Nkind
(Obj
) = N_Function_Call
then
17967 -- Function results are objects, so we get either the access level of
17968 -- the function or, in the case of an indirect call, the level of the
17969 -- access-to-subprogram type. (This code is used for Ada 95, but it
17970 -- looks wrong, because it seems that we should be checking the level
17971 -- of the call itself, even for Ada 95. However, using the Ada 2005
17972 -- version of the code causes regressions in several tests that are
17973 -- compiled with -gnat95. ???)
17975 if Ada_Version
< Ada_2005
then
17976 if Is_Entity_Name
(Name
(Obj
)) then
17977 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
17979 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
17982 -- For Ada 2005, the level of the result object of a function call is
17983 -- defined to be the level of the call's innermost enclosing master.
17984 -- We determine that by querying the depth of the innermost enclosing
17988 Return_Master_Scope_Depth_Of_Call
: declare
17990 function Innermost_Master_Scope_Depth
17991 (N
: Node_Id
) return Uint
;
17992 -- Returns the scope depth of the given node's innermost
17993 -- enclosing dynamic scope (effectively the accessibility
17994 -- level of the innermost enclosing master).
17996 ----------------------------------
17997 -- Innermost_Master_Scope_Depth --
17998 ----------------------------------
18000 function Innermost_Master_Scope_Depth
18001 (N
: Node_Id
) return Uint
18003 Node_Par
: Node_Id
:= Parent
(N
);
18006 -- Locate the nearest enclosing node (by traversing Parents)
18007 -- that Defining_Entity can be applied to, and return the
18008 -- depth of that entity's nearest enclosing dynamic scope.
18010 while Present
(Node_Par
) loop
18011 case Nkind
(Node_Par
) is
18012 when N_Component_Declaration |
18013 N_Entry_Declaration |
18014 N_Formal_Object_Declaration |
18015 N_Formal_Type_Declaration |
18016 N_Full_Type_Declaration |
18017 N_Incomplete_Type_Declaration |
18018 N_Loop_Parameter_Specification |
18019 N_Object_Declaration |
18020 N_Protected_Type_Declaration |
18021 N_Private_Extension_Declaration |
18022 N_Private_Type_Declaration |
18023 N_Subtype_Declaration |
18024 N_Function_Specification |
18025 N_Procedure_Specification |
18026 N_Task_Type_Declaration |
18028 N_Generic_Instantiation |
18030 N_Implicit_Label_Declaration |
18031 N_Package_Declaration |
18032 N_Single_Task_Declaration |
18033 N_Subprogram_Declaration |
18034 N_Generic_Declaration |
18035 N_Renaming_Declaration |
18036 N_Block_Statement |
18037 N_Formal_Subprogram_Declaration |
18038 N_Abstract_Subprogram_Declaration |
18040 N_Exception_Declaration |
18041 N_Formal_Package_Declaration |
18042 N_Number_Declaration |
18043 N_Package_Specification |
18044 N_Parameter_Specification |
18045 N_Single_Protected_Declaration |
18049 (Nearest_Dynamic_Scope
18050 (Defining_Entity
(Node_Par
)));
18056 Node_Par
:= Parent
(Node_Par
);
18059 pragma Assert
(False);
18061 -- Should never reach the following return
18063 return Scope_Depth
(Current_Scope
) + 1;
18064 end Innermost_Master_Scope_Depth
;
18066 -- Start of processing for Return_Master_Scope_Depth_Of_Call
18069 return Innermost_Master_Scope_Depth
(Obj
);
18070 end Return_Master_Scope_Depth_Of_Call
;
18073 -- For convenience we handle qualified expressions, even though they
18074 -- aren't technically object names.
18076 elsif Nkind
(Obj
) = N_Qualified_Expression
then
18077 return Object_Access_Level
(Expression
(Obj
));
18079 -- Ditto for aggregates. They have the level of the temporary that
18080 -- will hold their value.
18082 elsif Nkind
(Obj
) = N_Aggregate
then
18083 return Object_Access_Level
(Current_Scope
);
18085 -- Otherwise return the scope level of Standard. (If there are cases
18086 -- that fall through to this point they will be treated as having
18087 -- global accessibility for now. ???)
18090 return Scope_Depth
(Standard_Standard
);
18092 end Object_Access_Level
;
18094 ---------------------------------
18095 -- Original_Aspect_Pragma_Name --
18096 ---------------------------------
18098 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
18100 Item_Nam
: Name_Id
;
18103 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
18107 -- The pragma was generated to emulate an aspect, use the original
18108 -- aspect specification.
18110 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
18111 Item
:= Corresponding_Aspect
(Item
);
18114 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
18115 -- Post and Post_Class rewrite their pragma identifier to preserve the
18117 -- ??? this is kludgey
18119 if Nkind
(Item
) = N_Pragma
then
18120 Item_Nam
:= Chars
(Original_Node
(Pragma_Identifier
(Item
)));
18123 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
18124 Item_Nam
:= Chars
(Identifier
(Item
));
18127 -- Deal with 'Class by converting the name to its _XXX form
18129 if Class_Present
(Item
) then
18130 if Item_Nam
= Name_Invariant
then
18131 Item_Nam
:= Name_uInvariant
;
18133 elsif Item_Nam
= Name_Post
then
18134 Item_Nam
:= Name_uPost
;
18136 elsif Item_Nam
= Name_Pre
then
18137 Item_Nam
:= Name_uPre
;
18139 elsif Nam_In
(Item_Nam
, Name_Type_Invariant
,
18140 Name_Type_Invariant_Class
)
18142 Item_Nam
:= Name_uType_Invariant
;
18144 -- Nothing to do for other cases (e.g. a Check that derived from
18145 -- Pre_Class and has the flag set). Also we do nothing if the name
18146 -- is already in special _xxx form.
18152 end Original_Aspect_Pragma_Name
;
18154 --------------------------------------
18155 -- Original_Corresponding_Operation --
18156 --------------------------------------
18158 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
18160 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
18163 -- If S is an inherited primitive S2 the original corresponding
18164 -- operation of S is the original corresponding operation of S2
18166 if Present
(Alias
(S
))
18167 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
18169 return Original_Corresponding_Operation
(Alias
(S
));
18171 -- If S overrides an inherited subprogram S2 the original corresponding
18172 -- operation of S is the original corresponding operation of S2
18174 elsif Present
(Overridden_Operation
(S
)) then
18175 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
18177 -- otherwise it is S itself
18182 end Original_Corresponding_Operation
;
18184 -------------------
18185 -- Output_Entity --
18186 -------------------
18188 procedure Output_Entity
(Id
: Entity_Id
) is
18192 Scop
:= Scope
(Id
);
18194 -- The entity may lack a scope when it is in the process of being
18195 -- analyzed. Use the current scope as an approximation.
18198 Scop
:= Current_Scope
;
18201 Output_Name
(Chars
(Id
), Scop
);
18208 procedure Output_Name
(Nam
: Name_Id
; Scop
: Entity_Id
:= Current_Scope
) is
18212 (Get_Qualified_Name
18219 ----------------------
18220 -- Policy_In_Effect --
18221 ----------------------
18223 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
18224 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
18225 -- Determine the mode of a policy in a N_Pragma list
18227 --------------------
18228 -- Policy_In_List --
18229 --------------------
18231 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
18238 while Present
(Prag
) loop
18239 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
18240 Arg2
:= Next
(Arg1
);
18242 Arg1
:= Get_Pragma_Arg
(Arg1
);
18243 Arg2
:= Get_Pragma_Arg
(Arg2
);
18245 -- The current Check_Policy pragma matches the requested policy or
18246 -- appears in the single argument form (Assertion, policy_id).
18248 if Nam_In
(Chars
(Arg1
), Name_Assertion
, Policy
) then
18249 return Chars
(Arg2
);
18252 Prag
:= Next_Pragma
(Prag
);
18256 end Policy_In_List
;
18262 -- Start of processing for Policy_In_Effect
18265 if not Is_Valid_Assertion_Kind
(Policy
) then
18266 raise Program_Error
;
18269 -- Inspect all policy pragmas that appear within scopes (if any)
18271 Kind
:= Policy_In_List
(Check_Policy_List
);
18273 -- Inspect all configuration policy pragmas (if any)
18275 if Kind
= No_Name
then
18276 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
18279 -- The context lacks policy pragmas, determine the mode based on whether
18280 -- assertions are enabled at the configuration level. This ensures that
18281 -- the policy is preserved when analyzing generics.
18283 if Kind
= No_Name
then
18284 if Assertions_Enabled_Config
then
18285 Kind
:= Name_Check
;
18287 Kind
:= Name_Ignore
;
18292 end Policy_In_Effect
;
18294 ----------------------------------
18295 -- Predicate_Tests_On_Arguments --
18296 ----------------------------------
18298 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
18300 -- Always test predicates on indirect call
18302 if Ekind
(Subp
) = E_Subprogram_Type
then
18305 -- Do not test predicates on call to generated default Finalize, since
18306 -- we are not interested in whether something we are finalizing (and
18307 -- typically destroying) satisfies its predicates.
18309 elsif Chars
(Subp
) = Name_Finalize
18310 and then not Comes_From_Source
(Subp
)
18314 -- Do not test predicates on any internally generated routines
18316 elsif Is_Internal_Name
(Chars
(Subp
)) then
18319 -- Do not test predicates on call to Init_Proc, since if needed the
18320 -- predicate test will occur at some other point.
18322 elsif Is_Init_Proc
(Subp
) then
18325 -- Do not test predicates on call to predicate function, since this
18326 -- would cause infinite recursion.
18328 elsif Ekind
(Subp
) = E_Function
18329 and then (Is_Predicate_Function
(Subp
)
18331 Is_Predicate_Function_M
(Subp
))
18335 -- For now, no other exceptions
18340 end Predicate_Tests_On_Arguments
;
18342 -----------------------
18343 -- Private_Component --
18344 -----------------------
18346 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
18347 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
18349 function Trace_Components
18351 Check
: Boolean) return Entity_Id
;
18352 -- Recursive function that does the work, and checks against circular
18353 -- definition for each subcomponent type.
18355 ----------------------
18356 -- Trace_Components --
18357 ----------------------
18359 function Trace_Components
18361 Check
: Boolean) return Entity_Id
18363 Btype
: constant Entity_Id
:= Base_Type
(T
);
18364 Component
: Entity_Id
;
18366 Candidate
: Entity_Id
:= Empty
;
18369 if Check
and then Btype
= Ancestor
then
18370 Error_Msg_N
("circular type definition", Type_Id
);
18374 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
18375 if Present
(Full_View
(Btype
))
18376 and then Is_Record_Type
(Full_View
(Btype
))
18377 and then not Is_Frozen
(Btype
)
18379 -- To indicate that the ancestor depends on a private type, the
18380 -- current Btype is sufficient. However, to check for circular
18381 -- definition we must recurse on the full view.
18383 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
18385 if Candidate
= Any_Type
then
18395 elsif Is_Array_Type
(Btype
) then
18396 return Trace_Components
(Component_Type
(Btype
), True);
18398 elsif Is_Record_Type
(Btype
) then
18399 Component
:= First_Entity
(Btype
);
18400 while Present
(Component
)
18401 and then Comes_From_Source
(Component
)
18403 -- Skip anonymous types generated by constrained components
18405 if not Is_Type
(Component
) then
18406 P
:= Trace_Components
(Etype
(Component
), True);
18408 if Present
(P
) then
18409 if P
= Any_Type
then
18417 Next_Entity
(Component
);
18425 end Trace_Components
;
18427 -- Start of processing for Private_Component
18430 return Trace_Components
(Type_Id
, False);
18431 end Private_Component
;
18433 ---------------------------
18434 -- Primitive_Names_Match --
18435 ---------------------------
18437 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
18439 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
18440 -- Given an internal name, returns the corresponding non-internal name
18442 ------------------------
18443 -- Non_Internal_Name --
18444 ------------------------
18446 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
18448 Get_Name_String
(Chars
(E
));
18449 Name_Len
:= Name_Len
- 1;
18451 end Non_Internal_Name
;
18453 -- Start of processing for Primitive_Names_Match
18456 pragma Assert
(Present
(E1
) and then Present
(E2
));
18458 return Chars
(E1
) = Chars
(E2
)
18460 (not Is_Internal_Name
(Chars
(E1
))
18461 and then Is_Internal_Name
(Chars
(E2
))
18462 and then Non_Internal_Name
(E2
) = Chars
(E1
))
18464 (not Is_Internal_Name
(Chars
(E2
))
18465 and then Is_Internal_Name
(Chars
(E1
))
18466 and then Non_Internal_Name
(E1
) = Chars
(E2
))
18468 (Is_Predefined_Dispatching_Operation
(E1
)
18469 and then Is_Predefined_Dispatching_Operation
(E2
)
18470 and then Same_TSS
(E1
, E2
))
18472 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
18473 end Primitive_Names_Match
;
18475 -----------------------
18476 -- Process_End_Label --
18477 -----------------------
18479 procedure Process_End_Label
18488 Label_Ref
: Boolean;
18489 -- Set True if reference to end label itself is required
18492 -- Gets set to the operator symbol or identifier that references the
18493 -- entity Ent. For the child unit case, this is the identifier from the
18494 -- designator. For other cases, this is simply Endl.
18496 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
18497 -- N is an identifier node that appears as a parent unit reference in
18498 -- the case where Ent is a child unit. This procedure generates an
18499 -- appropriate cross-reference entry. E is the corresponding entity.
18501 -------------------------
18502 -- Generate_Parent_Ref --
18503 -------------------------
18505 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
18507 -- If names do not match, something weird, skip reference
18509 if Chars
(E
) = Chars
(N
) then
18511 -- Generate the reference. We do NOT consider this as a reference
18512 -- for unreferenced symbol purposes.
18514 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
18516 if Style_Check
then
18517 Style
.Check_Identifier
(N
, E
);
18520 end Generate_Parent_Ref
;
18522 -- Start of processing for Process_End_Label
18525 -- If no node, ignore. This happens in some error situations, and
18526 -- also for some internally generated structures where no end label
18527 -- references are required in any case.
18533 -- Nothing to do if no End_Label, happens for internally generated
18534 -- constructs where we don't want an end label reference anyway. Also
18535 -- nothing to do if Endl is a string literal, which means there was
18536 -- some prior error (bad operator symbol)
18538 Endl
:= End_Label
(N
);
18540 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
18544 -- Reference node is not in extended main source unit
18546 if not In_Extended_Main_Source_Unit
(N
) then
18548 -- Generally we do not collect references except for the extended
18549 -- main source unit. The one exception is the 'e' entry for a
18550 -- package spec, where it is useful for a client to have the
18551 -- ending information to define scopes.
18557 Label_Ref
:= False;
18559 -- For this case, we can ignore any parent references, but we
18560 -- need the package name itself for the 'e' entry.
18562 if Nkind
(Endl
) = N_Designator
then
18563 Endl
:= Identifier
(Endl
);
18567 -- Reference is in extended main source unit
18572 -- For designator, generate references for the parent entries
18574 if Nkind
(Endl
) = N_Designator
then
18576 -- Generate references for the prefix if the END line comes from
18577 -- source (otherwise we do not need these references) We climb the
18578 -- scope stack to find the expected entities.
18580 if Comes_From_Source
(Endl
) then
18581 Nam
:= Name
(Endl
);
18582 Scop
:= Current_Scope
;
18583 while Nkind
(Nam
) = N_Selected_Component
loop
18584 Scop
:= Scope
(Scop
);
18585 exit when No
(Scop
);
18586 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
18587 Nam
:= Prefix
(Nam
);
18590 if Present
(Scop
) then
18591 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
18595 Endl
:= Identifier
(Endl
);
18599 -- If the end label is not for the given entity, then either we have
18600 -- some previous error, or this is a generic instantiation for which
18601 -- we do not need to make a cross-reference in this case anyway. In
18602 -- either case we simply ignore the call.
18604 if Chars
(Ent
) /= Chars
(Endl
) then
18608 -- If label was really there, then generate a normal reference and then
18609 -- adjust the location in the end label to point past the name (which
18610 -- should almost always be the semicolon).
18612 Loc
:= Sloc
(Endl
);
18614 if Comes_From_Source
(Endl
) then
18616 -- If a label reference is required, then do the style check and
18617 -- generate an l-type cross-reference entry for the label
18620 if Style_Check
then
18621 Style
.Check_Identifier
(Endl
, Ent
);
18624 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
18627 -- Set the location to point past the label (normally this will
18628 -- mean the semicolon immediately following the label). This is
18629 -- done for the sake of the 'e' or 't' entry generated below.
18631 Get_Decoded_Name_String
(Chars
(Endl
));
18632 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
18635 -- In SPARK mode, no missing label is allowed for packages and
18636 -- subprogram bodies. Detect those cases by testing whether
18637 -- Process_End_Label was called for a body (Typ = 't') or a package.
18639 if Restriction_Check_Required
(SPARK_05
)
18640 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
18642 Error_Msg_Node_1
:= Endl
;
18643 Check_SPARK_05_Restriction
18644 ("`END &` required", Endl
, Force
=> True);
18648 -- Now generate the e/t reference
18650 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
18652 -- Restore Sloc, in case modified above, since we have an identifier
18653 -- and the normal Sloc should be left set in the tree.
18655 Set_Sloc
(Endl
, Loc
);
18656 end Process_End_Label
;
18658 ------------------------------------
18659 -- Propagate_Invariant_Attributes --
18660 ------------------------------------
18662 procedure Propagate_Invariant_Attributes
18664 From_Typ
: Entity_Id
)
18666 Full_IP
: Entity_Id
;
18667 Part_IP
: Entity_Id
;
18670 if Present
(Typ
) and then Present
(From_Typ
) then
18671 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
18673 -- Nothing to do if both the source and the destination denote the
18676 if From_Typ
= Typ
then
18680 Full_IP
:= Invariant_Procedure
(From_Typ
);
18681 Part_IP
:= Partial_Invariant_Procedure
(From_Typ
);
18683 -- The setting of the attributes is intentionally conservative. This
18684 -- prevents accidental clobbering of enabled attributes.
18686 if Has_Inheritable_Invariants
(From_Typ
)
18687 and then not Has_Inheritable_Invariants
(Typ
)
18689 Set_Has_Inheritable_Invariants
(Typ
, True);
18692 if Has_Inherited_Invariants
(From_Typ
)
18693 and then not Has_Inherited_Invariants
(Typ
)
18695 Set_Has_Inherited_Invariants
(Typ
, True);
18698 if Has_Own_Invariants
(From_Typ
)
18699 and then not Has_Own_Invariants
(Typ
)
18701 Set_Has_Own_Invariants
(Typ
, True);
18704 if Present
(Full_IP
) and then No
(Invariant_Procedure
(Typ
)) then
18705 Set_Invariant_Procedure
(Typ
, Full_IP
);
18708 if Present
(Part_IP
) and then No
(Partial_Invariant_Procedure
(Typ
))
18710 Set_Partial_Invariant_Procedure
(Typ
, Part_IP
);
18713 end Propagate_Invariant_Attributes
;
18715 --------------------------------
18716 -- Propagate_Concurrent_Flags --
18717 --------------------------------
18719 procedure Propagate_Concurrent_Flags
18721 Comp_Typ
: Entity_Id
)
18724 if Has_Task
(Comp_Typ
) then
18725 Set_Has_Task
(Typ
);
18728 if Has_Protected
(Comp_Typ
) then
18729 Set_Has_Protected
(Typ
);
18732 if Has_Timing_Event
(Comp_Typ
) then
18733 Set_Has_Timing_Event
(Typ
);
18735 end Propagate_Concurrent_Flags
;
18737 ---------------------------------------
18738 -- Record_Possible_Part_Of_Reference --
18739 ---------------------------------------
18741 procedure Record_Possible_Part_Of_Reference
18742 (Var_Id
: Entity_Id
;
18745 Encap
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
18749 -- The variable is a constituent of a single protected/task type. Such
18750 -- a variable acts as a component of the type and must appear within a
18751 -- specific region (SPARK RM 9.3). Instead of recording the reference,
18752 -- verify its legality now.
18754 if Present
(Encap
) and then Is_Single_Concurrent_Object
(Encap
) then
18755 Check_Part_Of_Reference
(Var_Id
, Ref
);
18757 -- The variable is subject to pragma Part_Of and may eventually become a
18758 -- constituent of a single protected/task type. Record the reference to
18759 -- verify its placement when the contract of the variable is analyzed.
18761 elsif Present
(Get_Pragma
(Var_Id
, Pragma_Part_Of
)) then
18762 Refs
:= Part_Of_References
(Var_Id
);
18765 Refs
:= New_Elmt_List
;
18766 Set_Part_Of_References
(Var_Id
, Refs
);
18769 Append_Elmt
(Ref
, Refs
);
18771 end Record_Possible_Part_Of_Reference
;
18777 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
18778 Seen
: Boolean := False;
18780 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
18781 -- Determine whether node N denotes a reference to Id. If this is the
18782 -- case, set global flag Seen to True and stop the traversal.
18788 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
18790 if Is_Entity_Name
(N
)
18791 and then Present
(Entity
(N
))
18792 and then Entity
(N
) = Id
18801 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
18803 -- Start of processing for Referenced
18806 Inspect_Expression
(Expr
);
18810 ------------------------------------
18811 -- References_Generic_Formal_Type --
18812 ------------------------------------
18814 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
18816 function Process
(N
: Node_Id
) return Traverse_Result
;
18817 -- Process one node in search for generic formal type
18823 function Process
(N
: Node_Id
) return Traverse_Result
is
18825 if Nkind
(N
) in N_Has_Entity
then
18827 E
: constant Entity_Id
:= Entity
(N
);
18829 if Present
(E
) then
18830 if Is_Generic_Type
(E
) then
18832 elsif Present
(Etype
(E
))
18833 and then Is_Generic_Type
(Etype
(E
))
18844 function Traverse
is new Traverse_Func
(Process
);
18845 -- Traverse tree to look for generic type
18848 if Inside_A_Generic
then
18849 return Traverse
(N
) = Abandon
;
18853 end References_Generic_Formal_Type
;
18855 --------------------
18856 -- Remove_Homonym --
18857 --------------------
18859 procedure Remove_Homonym
(E
: Entity_Id
) is
18860 Prev
: Entity_Id
:= Empty
;
18864 if E
= Current_Entity
(E
) then
18865 if Present
(Homonym
(E
)) then
18866 Set_Current_Entity
(Homonym
(E
));
18868 Set_Name_Entity_Id
(Chars
(E
), Empty
);
18872 H
:= Current_Entity
(E
);
18873 while Present
(H
) and then H
/= E
loop
18878 -- If E is not on the homonym chain, nothing to do
18880 if Present
(H
) then
18881 Set_Homonym
(Prev
, Homonym
(E
));
18884 end Remove_Homonym
;
18886 ------------------------------
18887 -- Remove_Overloaded_Entity --
18888 ------------------------------
18890 procedure Remove_Overloaded_Entity
(Id
: Entity_Id
) is
18891 procedure Remove_Primitive_Of
(Typ
: Entity_Id
);
18892 -- Remove primitive subprogram Id from the list of primitives that
18893 -- belong to type Typ.
18895 -------------------------
18896 -- Remove_Primitive_Of --
18897 -------------------------
18899 procedure Remove_Primitive_Of
(Typ
: Entity_Id
) is
18903 if Is_Tagged_Type
(Typ
) then
18904 Prims
:= Direct_Primitive_Operations
(Typ
);
18906 if Present
(Prims
) then
18907 Remove
(Prims
, Id
);
18910 end Remove_Primitive_Of
;
18914 Scop
: constant Entity_Id
:= Scope
(Id
);
18915 Formal
: Entity_Id
;
18916 Prev_Id
: Entity_Id
;
18918 -- Start of processing for Remove_Overloaded_Entity
18921 -- Remove the entity from the homonym chain. When the entity is the
18922 -- head of the chain, associate the entry in the name table with its
18923 -- homonym effectively making it the new head of the chain.
18925 if Current_Entity
(Id
) = Id
then
18926 Set_Name_Entity_Id
(Chars
(Id
), Homonym
(Id
));
18928 -- Otherwise link the previous and next homonyms
18931 Prev_Id
:= Current_Entity
(Id
);
18932 while Present
(Prev_Id
) and then Homonym
(Prev_Id
) /= Id
loop
18933 Prev_Id
:= Homonym
(Prev_Id
);
18936 Set_Homonym
(Prev_Id
, Homonym
(Id
));
18939 -- Remove the entity from the scope entity chain. When the entity is
18940 -- the head of the chain, set the next entity as the new head of the
18943 if First_Entity
(Scop
) = Id
then
18945 Set_First_Entity
(Scop
, Next_Entity
(Id
));
18947 -- Otherwise the entity is either in the middle of the chain or it acts
18948 -- as its tail. Traverse and link the previous and next entities.
18951 Prev_Id
:= First_Entity
(Scop
);
18952 while Present
(Prev_Id
) and then Next_Entity
(Prev_Id
) /= Id
loop
18953 Next_Entity
(Prev_Id
);
18956 Set_Next_Entity
(Prev_Id
, Next_Entity
(Id
));
18959 -- Handle the case where the entity acts as the tail of the scope entity
18962 if Last_Entity
(Scop
) = Id
then
18963 Set_Last_Entity
(Scop
, Prev_Id
);
18966 -- The entity denotes a primitive subprogram. Remove it from the list of
18967 -- primitives of the associated controlling type.
18969 if Ekind_In
(Id
, E_Function
, E_Procedure
) and then Is_Primitive
(Id
) then
18970 Formal
:= First_Formal
(Id
);
18971 while Present
(Formal
) loop
18972 if Is_Controlling_Formal
(Formal
) then
18973 Remove_Primitive_Of
(Etype
(Formal
));
18977 Next_Formal
(Formal
);
18980 if Ekind
(Id
) = E_Function
and then Has_Controlling_Result
(Id
) then
18981 Remove_Primitive_Of
(Etype
(Id
));
18984 end Remove_Overloaded_Entity
;
18986 ---------------------
18987 -- Rep_To_Pos_Flag --
18988 ---------------------
18990 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
18992 return New_Occurrence_Of
18993 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
18994 end Rep_To_Pos_Flag
;
18996 --------------------
18997 -- Require_Entity --
18998 --------------------
19000 procedure Require_Entity
(N
: Node_Id
) is
19002 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
19003 if Total_Errors_Detected
/= 0 then
19004 Set_Entity
(N
, Any_Id
);
19006 raise Program_Error
;
19009 end Require_Entity
;
19011 ------------------------------
19012 -- Requires_Transient_Scope --
19013 ------------------------------
19015 -- A transient scope is required when variable-sized temporaries are
19016 -- allocated on the secondary stack, or when finalization actions must be
19017 -- generated before the next instruction.
19019 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
19020 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
19021 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
19022 -- the time being. New_Requires_Transient_Scope is used by default; the
19023 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
19024 -- instead. The intent is to use this temporarily to measure before/after
19025 -- efficiency. Note: when this temporary code is removed, the documentation
19026 -- of dQ in debug.adb should be removed.
19028 procedure Results_Differ
(Id
: Entity_Id
);
19029 -- ???Debugging code. Called when the Old_ and New_ results differ. Will be
19030 -- removed when New_Requires_Transient_Scope becomes
19031 -- Requires_Transient_Scope and Old_Requires_Transient_Scope is eliminated.
19033 procedure Results_Differ
(Id
: Entity_Id
) is
19035 if False then -- False to disable; True for debugging
19036 Treepr
.Print_Tree_Node
(Id
);
19038 if Old_Requires_Transient_Scope
(Id
) =
19039 New_Requires_Transient_Scope
(Id
)
19041 raise Program_Error
;
19044 end Results_Differ
;
19046 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
19047 Old_Result
: constant Boolean := Old_Requires_Transient_Scope
(Id
);
19050 if Debug_Flag_QQ
then
19055 New_Result
: constant Boolean := New_Requires_Transient_Scope
(Id
);
19058 -- Assert that we're not putting things on the secondary stack if we
19059 -- didn't before; we are trying to AVOID secondary stack when
19062 if not Old_Result
then
19063 pragma Assert
(not New_Result
);
19067 if New_Result
/= Old_Result
then
19068 Results_Differ
(Id
);
19073 end Requires_Transient_Scope
;
19075 ----------------------------------
19076 -- Old_Requires_Transient_Scope --
19077 ----------------------------------
19079 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
19080 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
19083 -- This is a private type which is not completed yet. This can only
19084 -- happen in a default expression (of a formal parameter or of a
19085 -- record component). Do not expand transient scope in this case.
19090 -- Do not expand transient scope for non-existent procedure return
19092 elsif Typ
= Standard_Void_Type
then
19095 -- Elementary types do not require a transient scope
19097 elsif Is_Elementary_Type
(Typ
) then
19100 -- Generally, indefinite subtypes require a transient scope, since the
19101 -- back end cannot generate temporaries, since this is not a valid type
19102 -- for declaring an object. It might be possible to relax this in the
19103 -- future, e.g. by declaring the maximum possible space for the type.
19105 elsif not Is_Definite_Subtype
(Typ
) then
19108 -- Functions returning tagged types may dispatch on result so their
19109 -- returned value is allocated on the secondary stack. Controlled
19110 -- type temporaries need finalization.
19112 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
19117 elsif Is_Record_Type
(Typ
) then
19122 Comp
:= First_Entity
(Typ
);
19123 while Present
(Comp
) loop
19124 if Ekind
(Comp
) = E_Component
then
19126 -- ???It's not clear we need a full recursive call to
19127 -- Old_Requires_Transient_Scope here. Note that the
19128 -- following can't happen.
19130 pragma Assert
(Is_Definite_Subtype
(Etype
(Comp
)));
19131 pragma Assert
(not Has_Controlled_Component
(Etype
(Comp
)));
19133 if Old_Requires_Transient_Scope
(Etype
(Comp
)) then
19138 Next_Entity
(Comp
);
19144 -- String literal types never require transient scope
19146 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
19149 -- Array type. Note that we already know that this is a constrained
19150 -- array, since unconstrained arrays will fail the indefinite test.
19152 elsif Is_Array_Type
(Typ
) then
19154 -- If component type requires a transient scope, the array does too
19156 if Old_Requires_Transient_Scope
(Component_Type
(Typ
)) then
19159 -- Otherwise, we only need a transient scope if the size depends on
19160 -- the value of one or more discriminants.
19163 return Size_Depends_On_Discriminant
(Typ
);
19166 -- All other cases do not require a transient scope
19169 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
19172 end Old_Requires_Transient_Scope
;
19174 ----------------------------------
19175 -- New_Requires_Transient_Scope --
19176 ----------------------------------
19178 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
19180 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean;
19181 -- This is called for untagged records and protected types, with
19182 -- nondefaulted discriminants. Returns True if the size of function
19183 -- results is known at the call site, False otherwise. Returns False
19184 -- if there is a variant part that depends on the discriminants of
19185 -- this type, or if there is an array constrained by the discriminants
19186 -- of this type. ???Currently, this is overly conservative (the array
19187 -- could be nested inside some other record that is constrained by
19188 -- nondiscriminants). That is, the recursive calls are too conservative.
19190 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean;
19191 -- Returns True if Typ is a nonlimited record with defaulted
19192 -- discriminants whose max size makes it unsuitable for allocating on
19193 -- the primary stack.
19195 ------------------------------
19196 -- Caller_Known_Size_Record --
19197 ------------------------------
19199 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean is
19200 pragma Assert
(Typ
= Underlying_Type
(Typ
));
19203 if Has_Variant_Part
(Typ
) and then not Is_Definite_Subtype
(Typ
) then
19211 Comp
:= First_Entity
(Typ
);
19212 while Present
(Comp
) loop
19214 -- Only look at E_Component entities. No need to look at
19215 -- E_Discriminant entities, and we must ignore internal
19216 -- subtypes generated for constrained components.
19218 if Ekind
(Comp
) = E_Component
then
19220 Comp_Type
: constant Entity_Id
:=
19221 Underlying_Type
(Etype
(Comp
));
19224 if Is_Record_Type
(Comp_Type
)
19226 Is_Protected_Type
(Comp_Type
)
19228 if not Caller_Known_Size_Record
(Comp_Type
) then
19232 elsif Is_Array_Type
(Comp_Type
) then
19233 if Size_Depends_On_Discriminant
(Comp_Type
) then
19240 Next_Entity
(Comp
);
19245 end Caller_Known_Size_Record
;
19247 ------------------------------
19248 -- Large_Max_Size_Mutable --
19249 ------------------------------
19251 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean is
19252 pragma Assert
(Typ
= Underlying_Type
(Typ
));
19254 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean;
19255 -- Returns true if the discrete type T has a large range
19257 ----------------------------
19258 -- Is_Large_Discrete_Type --
19259 ----------------------------
19261 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean is
19262 Threshold
: constant Int
:= 16;
19263 -- Arbitrary threshold above which we consider it "large". We want
19264 -- a fairly large threshold, because these large types really
19265 -- shouldn't have default discriminants in the first place, in
19269 return UI_To_Int
(RM_Size
(T
)) > Threshold
;
19270 end Is_Large_Discrete_Type
;
19273 if Is_Record_Type
(Typ
)
19274 and then not Is_Limited_View
(Typ
)
19275 and then Has_Defaulted_Discriminants
(Typ
)
19277 -- Loop through the components, looking for an array whose upper
19278 -- bound(s) depends on discriminants, where both the subtype of
19279 -- the discriminant and the index subtype are too large.
19285 Comp
:= First_Entity
(Typ
);
19286 while Present
(Comp
) loop
19287 if Ekind
(Comp
) = E_Component
then
19289 Comp_Type
: constant Entity_Id
:=
19290 Underlying_Type
(Etype
(Comp
));
19296 if Is_Array_Type
(Comp_Type
) then
19297 Indx
:= First_Index
(Comp_Type
);
19299 while Present
(Indx
) loop
19300 Ityp
:= Etype
(Indx
);
19301 Hi
:= Type_High_Bound
(Ityp
);
19303 if Nkind
(Hi
) = N_Identifier
19304 and then Ekind
(Entity
(Hi
)) = E_Discriminant
19305 and then Is_Large_Discrete_Type
(Ityp
)
19306 and then Is_Large_Discrete_Type
19307 (Etype
(Entity
(Hi
)))
19318 Next_Entity
(Comp
);
19324 end Large_Max_Size_Mutable
;
19326 -- Local declarations
19328 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
19330 -- Start of processing for New_Requires_Transient_Scope
19333 -- This is a private type which is not completed yet. This can only
19334 -- happen in a default expression (of a formal parameter or of a
19335 -- record component). Do not expand transient scope in this case.
19340 -- Do not expand transient scope for non-existent procedure return or
19341 -- string literal types.
19343 elsif Typ
= Standard_Void_Type
19344 or else Ekind
(Typ
) = E_String_Literal_Subtype
19348 -- If Typ is a generic formal incomplete type, then we want to look at
19349 -- the actual type.
19351 elsif Ekind
(Typ
) = E_Record_Subtype
19352 and then Present
(Cloned_Subtype
(Typ
))
19354 return New_Requires_Transient_Scope
(Cloned_Subtype
(Typ
));
19356 -- Functions returning specific tagged types may dispatch on result, so
19357 -- their returned value is allocated on the secondary stack, even in the
19358 -- definite case. We must treat nondispatching functions the same way,
19359 -- because access-to-function types can point at both, so the calling
19360 -- conventions must be compatible. Is_Tagged_Type includes controlled
19361 -- types and class-wide types. Controlled type temporaries need
19364 -- ???It's not clear why we need to return noncontrolled types with
19365 -- controlled components on the secondary stack.
19367 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
19370 -- Untagged definite subtypes are known size. This includes all
19371 -- elementary [sub]types. Tasks are known size even if they have
19372 -- discriminants. So we return False here, with one exception:
19373 -- For a type like:
19374 -- type T (Last : Natural := 0) is
19375 -- X : String (1 .. Last);
19377 -- we return True. That's because for "P(F(...));", where F returns T,
19378 -- we don't know the size of the result at the call site, so if we
19379 -- allocated it on the primary stack, we would have to allocate the
19380 -- maximum size, which is way too big.
19382 elsif Is_Definite_Subtype
(Typ
) or else Is_Task_Type
(Typ
) then
19383 return Large_Max_Size_Mutable
(Typ
);
19385 -- Indefinite (discriminated) untagged record or protected type
19387 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
19388 return not Caller_Known_Size_Record
(Typ
);
19390 -- Unconstrained array
19393 pragma Assert
(Is_Array_Type
(Typ
) and not Is_Definite_Subtype
(Typ
));
19396 end New_Requires_Transient_Scope
;
19398 --------------------------
19399 -- Reset_Analyzed_Flags --
19400 --------------------------
19402 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
19404 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
19405 -- Function used to reset Analyzed flags in tree. Note that we do
19406 -- not reset Analyzed flags in entities, since there is no need to
19407 -- reanalyze entities, and indeed, it is wrong to do so, since it
19408 -- can result in generating auxiliary stuff more than once.
19410 --------------------
19411 -- Clear_Analyzed --
19412 --------------------
19414 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
19416 if not Has_Extension
(N
) then
19417 Set_Analyzed
(N
, False);
19421 end Clear_Analyzed
;
19423 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
19425 -- Start of processing for Reset_Analyzed_Flags
19428 Reset_Analyzed
(N
);
19429 end Reset_Analyzed_Flags
;
19431 ------------------------
19432 -- Restore_SPARK_Mode --
19433 ------------------------
19435 procedure Restore_SPARK_Mode
(Mode
: SPARK_Mode_Type
) is
19437 SPARK_Mode
:= Mode
;
19438 end Restore_SPARK_Mode
;
19440 --------------------------------
19441 -- Returns_Unconstrained_Type --
19442 --------------------------------
19444 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
19446 return Ekind
(Subp
) = E_Function
19447 and then not Is_Scalar_Type
(Etype
(Subp
))
19448 and then not Is_Access_Type
(Etype
(Subp
))
19449 and then not Is_Constrained
(Etype
(Subp
));
19450 end Returns_Unconstrained_Type
;
19452 ----------------------------
19453 -- Root_Type_Of_Full_View --
19454 ----------------------------
19456 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
19457 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
19460 -- The root type of the full view may itself be a private type. Keep
19461 -- looking for the ultimate derivation parent.
19463 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
19464 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
19468 end Root_Type_Of_Full_View
;
19470 ---------------------------
19471 -- Safe_To_Capture_Value --
19472 ---------------------------
19474 function Safe_To_Capture_Value
19477 Cond
: Boolean := False) return Boolean
19480 -- The only entities for which we track constant values are variables
19481 -- which are not renamings, constants, out parameters, and in out
19482 -- parameters, so check if we have this case.
19484 -- Note: it may seem odd to track constant values for constants, but in
19485 -- fact this routine is used for other purposes than simply capturing
19486 -- the value. In particular, the setting of Known[_Non]_Null.
19488 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
19490 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
19494 -- For conditionals, we also allow loop parameters and all formals,
19495 -- including in parameters.
19497 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
19500 -- For all other cases, not just unsafe, but impossible to capture
19501 -- Current_Value, since the above are the only entities which have
19502 -- Current_Value fields.
19508 -- Skip if volatile or aliased, since funny things might be going on in
19509 -- these cases which we cannot necessarily track. Also skip any variable
19510 -- for which an address clause is given, or whose address is taken. Also
19511 -- never capture value of library level variables (an attempt to do so
19512 -- can occur in the case of package elaboration code).
19514 if Treat_As_Volatile
(Ent
)
19515 or else Is_Aliased
(Ent
)
19516 or else Present
(Address_Clause
(Ent
))
19517 or else Address_Taken
(Ent
)
19518 or else (Is_Library_Level_Entity
(Ent
)
19519 and then Ekind
(Ent
) = E_Variable
)
19524 -- OK, all above conditions are met. We also require that the scope of
19525 -- the reference be the same as the scope of the entity, not counting
19526 -- packages and blocks and loops.
19529 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
19530 R_Scope
: Entity_Id
;
19533 R_Scope
:= Current_Scope
;
19534 while R_Scope
/= Standard_Standard
loop
19535 exit when R_Scope
= E_Scope
;
19537 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
19540 R_Scope
:= Scope
(R_Scope
);
19545 -- We also require that the reference does not appear in a context
19546 -- where it is not sure to be executed (i.e. a conditional context
19547 -- or an exception handler). We skip this if Cond is True, since the
19548 -- capturing of values from conditional tests handles this ok.
19561 -- Seems dubious that case expressions are not handled here ???
19564 while Present
(P
) loop
19565 if Nkind
(P
) = N_If_Statement
19566 or else Nkind
(P
) = N_Case_Statement
19567 or else (Nkind
(P
) in N_Short_Circuit
19568 and then Desc
= Right_Opnd
(P
))
19569 or else (Nkind
(P
) = N_If_Expression
19570 and then Desc
/= First
(Expressions
(P
)))
19571 or else Nkind
(P
) = N_Exception_Handler
19572 or else Nkind
(P
) = N_Selective_Accept
19573 or else Nkind
(P
) = N_Conditional_Entry_Call
19574 or else Nkind
(P
) = N_Timed_Entry_Call
19575 or else Nkind
(P
) = N_Asynchronous_Select
19583 -- A special Ada 2012 case: the original node may be part
19584 -- of the else_actions of a conditional expression, in which
19585 -- case it might not have been expanded yet, and appears in
19586 -- a non-syntactic list of actions. In that case it is clearly
19587 -- not safe to save a value.
19590 and then Is_List_Member
(Desc
)
19591 and then No
(Parent
(List_Containing
(Desc
)))
19599 -- OK, looks safe to set value
19602 end Safe_To_Capture_Value
;
19608 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
19609 K1
: constant Node_Kind
:= Nkind
(N1
);
19610 K2
: constant Node_Kind
:= Nkind
(N2
);
19613 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
19614 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
19616 return Chars
(N1
) = Chars
(N2
);
19618 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
19619 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
19621 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
19622 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
19633 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
19634 N1
: constant Node_Id
:= Original_Node
(Node1
);
19635 N2
: constant Node_Id
:= Original_Node
(Node2
);
19636 -- We do the tests on original nodes, since we are most interested
19637 -- in the original source, not any expansion that got in the way.
19639 K1
: constant Node_Kind
:= Nkind
(N1
);
19640 K2
: constant Node_Kind
:= Nkind
(N2
);
19643 -- First case, both are entities with same entity
19645 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
19647 EN1
: constant Entity_Id
:= Entity
(N1
);
19648 EN2
: constant Entity_Id
:= Entity
(N2
);
19650 if Present
(EN1
) and then Present
(EN2
)
19651 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
19652 or else Is_Formal
(EN1
))
19660 -- Second case, selected component with same selector, same record
19662 if K1
= N_Selected_Component
19663 and then K2
= N_Selected_Component
19664 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
19666 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
19668 -- Third case, indexed component with same subscripts, same array
19670 elsif K1
= N_Indexed_Component
19671 and then K2
= N_Indexed_Component
19672 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
19677 E1
:= First
(Expressions
(N1
));
19678 E2
:= First
(Expressions
(N2
));
19679 while Present
(E1
) loop
19680 if not Same_Value
(E1
, E2
) then
19691 -- Fourth case, slice of same array with same bounds
19694 and then K2
= N_Slice
19695 and then Nkind
(Discrete_Range
(N1
)) = N_Range
19696 and then Nkind
(Discrete_Range
(N2
)) = N_Range
19697 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
19698 Low_Bound
(Discrete_Range
(N2
)))
19699 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
19700 High_Bound
(Discrete_Range
(N2
)))
19702 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
19704 -- All other cases, not clearly the same object
19715 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
19720 elsif not Is_Constrained
(T1
)
19721 and then not Is_Constrained
(T2
)
19722 and then Base_Type
(T1
) = Base_Type
(T2
)
19726 -- For now don't bother with case of identical constraints, to be
19727 -- fiddled with later on perhaps (this is only used for optimization
19728 -- purposes, so it is not critical to do a best possible job)
19739 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
19741 if Compile_Time_Known_Value
(Node1
)
19742 and then Compile_Time_Known_Value
(Node2
)
19743 and then Expr_Value
(Node1
) = Expr_Value
(Node2
)
19746 elsif Same_Object
(Node1
, Node2
) then
19753 -----------------------------
19754 -- Save_SPARK_Mode_And_Set --
19755 -----------------------------
19757 procedure Save_SPARK_Mode_And_Set
19758 (Context
: Entity_Id
;
19759 Mode
: out SPARK_Mode_Type
)
19762 -- Save the current mode in effect
19764 Mode
:= SPARK_Mode
;
19766 -- Do not consider illegal or partially decorated constructs
19768 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
19771 elsif Present
(SPARK_Pragma
(Context
)) then
19772 SPARK_Mode
:= Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Context
));
19774 end Save_SPARK_Mode_And_Set
;
19776 -------------------------
19777 -- Scalar_Part_Present --
19778 -------------------------
19780 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
19784 if Is_Scalar_Type
(T
) then
19787 elsif Is_Array_Type
(T
) then
19788 return Scalar_Part_Present
(Component_Type
(T
));
19790 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
19791 C
:= First_Component_Or_Discriminant
(T
);
19792 while Present
(C
) loop
19793 if Scalar_Part_Present
(Etype
(C
)) then
19796 Next_Component_Or_Discriminant
(C
);
19802 end Scalar_Part_Present
;
19804 ------------------------
19805 -- Scope_Is_Transient --
19806 ------------------------
19808 function Scope_Is_Transient
return Boolean is
19810 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
19811 end Scope_Is_Transient
;
19817 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
19822 while Scop
/= Standard_Standard
loop
19823 Scop
:= Scope
(Scop
);
19825 if Scop
= Scope2
then
19833 --------------------------
19834 -- Scope_Within_Or_Same --
19835 --------------------------
19837 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
19842 while Scop
/= Standard_Standard
loop
19843 if Scop
= Scope2
then
19846 Scop
:= Scope
(Scop
);
19851 end Scope_Within_Or_Same
;
19853 --------------------
19854 -- Set_Convention --
19855 --------------------
19857 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
19859 Basic_Set_Convention
(E
, Val
);
19862 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
19863 and then Has_Foreign_Convention
(E
)
19866 -- A pragma Convention in an instance may apply to the subtype
19867 -- created for a formal, in which case we have already verified
19868 -- that conventions of actual and formal match and there is nothing
19869 -- to flag on the subtype.
19871 if In_Instance
then
19874 Set_Can_Use_Internal_Rep
(E
, False);
19878 -- If E is an object or component, and the type of E is an anonymous
19879 -- access type with no convention set, then also set the convention of
19880 -- the anonymous access type. We do not do this for anonymous protected
19881 -- types, since protected types always have the default convention.
19883 if Present
(Etype
(E
))
19884 and then (Is_Object
(E
)
19885 or else Ekind
(E
) = E_Component
19887 -- Allow E_Void (happens for pragma Convention appearing
19888 -- in the middle of a record applying to a component)
19890 or else Ekind
(E
) = E_Void
)
19893 Typ
: constant Entity_Id
:= Etype
(E
);
19896 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
19897 E_Anonymous_Access_Subprogram_Type
)
19898 and then not Has_Convention_Pragma
(Typ
)
19900 Basic_Set_Convention
(Typ
, Val
);
19901 Set_Has_Convention_Pragma
(Typ
);
19903 -- And for the access subprogram type, deal similarly with the
19904 -- designated E_Subprogram_Type if it is also internal (which
19907 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
19909 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
19911 if Ekind
(Dtype
) = E_Subprogram_Type
19912 and then Is_Itype
(Dtype
)
19913 and then not Has_Convention_Pragma
(Dtype
)
19915 Basic_Set_Convention
(Dtype
, Val
);
19916 Set_Has_Convention_Pragma
(Dtype
);
19923 end Set_Convention
;
19925 ------------------------
19926 -- Set_Current_Entity --
19927 ------------------------
19929 -- The given entity is to be set as the currently visible definition of its
19930 -- associated name (i.e. the Node_Id associated with its name). All we have
19931 -- to do is to get the name from the identifier, and then set the
19932 -- associated Node_Id to point to the given entity.
19934 procedure Set_Current_Entity
(E
: Entity_Id
) is
19936 Set_Name_Entity_Id
(Chars
(E
), E
);
19937 end Set_Current_Entity
;
19939 ---------------------------
19940 -- Set_Debug_Info_Needed --
19941 ---------------------------
19943 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
19945 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
19946 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
19947 -- Used to set debug info in a related node if not set already
19949 --------------------------------------
19950 -- Set_Debug_Info_Needed_If_Not_Set --
19951 --------------------------------------
19953 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
19955 if Present
(E
) and then not Needs_Debug_Info
(E
) then
19956 Set_Debug_Info_Needed
(E
);
19958 -- For a private type, indicate that the full view also needs
19959 -- debug information.
19962 and then Is_Private_Type
(E
)
19963 and then Present
(Full_View
(E
))
19965 Set_Debug_Info_Needed
(Full_View
(E
));
19968 end Set_Debug_Info_Needed_If_Not_Set
;
19970 -- Start of processing for Set_Debug_Info_Needed
19973 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
19974 -- indicates that Debug_Info_Needed is never required for the entity.
19975 -- Nothing to do if entity comes from a predefined file. Library files
19976 -- are compiled without debug information, but inlined bodies of these
19977 -- routines may appear in user code, and debug information on them ends
19978 -- up complicating debugging the user code.
19981 or else Debug_Info_Off
(T
)
19985 elsif In_Inlined_Body
19986 and then Is_Predefined_File_Name
19987 (Unit_File_Name
(Get_Source_Unit
(Sloc
(T
))))
19989 Set_Needs_Debug_Info
(T
, False);
19992 -- Set flag in entity itself. Note that we will go through the following
19993 -- circuitry even if the flag is already set on T. That's intentional,
19994 -- it makes sure that the flag will be set in subsidiary entities.
19996 Set_Needs_Debug_Info
(T
);
19998 -- Set flag on subsidiary entities if not set already
20000 if Is_Object
(T
) then
20001 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
20003 elsif Is_Type
(T
) then
20004 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
20006 if Is_Record_Type
(T
) then
20008 Ent
: Entity_Id
:= First_Entity
(T
);
20010 while Present
(Ent
) loop
20011 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
20016 -- For a class wide subtype, we also need debug information
20017 -- for the equivalent type.
20019 if Ekind
(T
) = E_Class_Wide_Subtype
then
20020 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
20023 elsif Is_Array_Type
(T
) then
20024 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
20027 Indx
: Node_Id
:= First_Index
(T
);
20029 while Present
(Indx
) loop
20030 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
20031 Indx
:= Next_Index
(Indx
);
20035 -- For a packed array type, we also need debug information for
20036 -- the type used to represent the packed array. Conversely, we
20037 -- also need it for the former if we need it for the latter.
20039 if Is_Packed
(T
) then
20040 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
20043 if Is_Packed_Array_Impl_Type
(T
) then
20044 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
20047 elsif Is_Access_Type
(T
) then
20048 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
20050 elsif Is_Private_Type
(T
) then
20052 FV
: constant Entity_Id
:= Full_View
(T
);
20055 Set_Debug_Info_Needed_If_Not_Set
(FV
);
20057 -- If the full view is itself a derived private type, we need
20058 -- debug information on its underlying type.
20061 and then Is_Private_Type
(FV
)
20062 and then Present
(Underlying_Full_View
(FV
))
20064 Set_Needs_Debug_Info
(Underlying_Full_View
(FV
));
20068 elsif Is_Protected_Type
(T
) then
20069 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
20071 elsif Is_Scalar_Type
(T
) then
20073 -- If the subrange bounds are materialized by dedicated constant
20074 -- objects, also include them in the debug info to make sure the
20075 -- debugger can properly use them.
20077 if Present
(Scalar_Range
(T
))
20078 and then Nkind
(Scalar_Range
(T
)) = N_Range
20081 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
20082 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
20085 if Is_Entity_Name
(Low_Bnd
) then
20086 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
20089 if Is_Entity_Name
(High_Bnd
) then
20090 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
20096 end Set_Debug_Info_Needed
;
20098 ----------------------------
20099 -- Set_Entity_With_Checks --
20100 ----------------------------
20102 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
20103 Val_Actual
: Entity_Id
;
20105 Post_Node
: Node_Id
;
20108 -- Unconditionally set the entity
20110 Set_Entity
(N
, Val
);
20112 -- The node to post on is the selector in the case of an expanded name,
20113 -- and otherwise the node itself.
20115 if Nkind
(N
) = N_Expanded_Name
then
20116 Post_Node
:= Selector_Name
(N
);
20121 -- Check for violation of No_Fixed_IO
20123 if Restriction_Check_Required
(No_Fixed_IO
)
20125 ((RTU_Loaded
(Ada_Text_IO
)
20126 and then (Is_RTE
(Val
, RE_Decimal_IO
)
20128 Is_RTE
(Val
, RE_Fixed_IO
)))
20131 (RTU_Loaded
(Ada_Wide_Text_IO
)
20132 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
20134 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
20137 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
20138 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
20140 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
20142 -- A special extra check, don't complain about a reference from within
20143 -- the Ada.Interrupts package itself!
20145 and then not In_Same_Extended_Unit
(N
, Val
)
20147 Check_Restriction
(No_Fixed_IO
, Post_Node
);
20150 -- Remaining checks are only done on source nodes. Note that we test
20151 -- for violation of No_Fixed_IO even on non-source nodes, because the
20152 -- cases for checking violations of this restriction are instantiations
20153 -- where the reference in the instance has Comes_From_Source False.
20155 if not Comes_From_Source
(N
) then
20159 -- Check for violation of No_Abort_Statements, which is triggered by
20160 -- call to Ada.Task_Identification.Abort_Task.
20162 if Restriction_Check_Required
(No_Abort_Statements
)
20163 and then (Is_RTE
(Val
, RE_Abort_Task
))
20165 -- A special extra check, don't complain about a reference from within
20166 -- the Ada.Task_Identification package itself!
20168 and then not In_Same_Extended_Unit
(N
, Val
)
20170 Check_Restriction
(No_Abort_Statements
, Post_Node
);
20173 if Val
= Standard_Long_Long_Integer
then
20174 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
20177 -- Check for violation of No_Dynamic_Attachment
20179 if Restriction_Check_Required
(No_Dynamic_Attachment
)
20180 and then RTU_Loaded
(Ada_Interrupts
)
20181 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
20182 Is_RTE
(Val
, RE_Is_Attached
) or else
20183 Is_RTE
(Val
, RE_Current_Handler
) or else
20184 Is_RTE
(Val
, RE_Attach_Handler
) or else
20185 Is_RTE
(Val
, RE_Exchange_Handler
) or else
20186 Is_RTE
(Val
, RE_Detach_Handler
) or else
20187 Is_RTE
(Val
, RE_Reference
))
20189 -- A special extra check, don't complain about a reference from within
20190 -- the Ada.Interrupts package itself!
20192 and then not In_Same_Extended_Unit
(N
, Val
)
20194 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
20197 -- Check for No_Implementation_Identifiers
20199 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
20201 -- We have an implementation defined entity if it is marked as
20202 -- implementation defined, or is defined in a package marked as
20203 -- implementation defined. However, library packages themselves
20204 -- are excluded (we don't want to flag Interfaces itself, just
20205 -- the entities within it).
20207 if (Is_Implementation_Defined
(Val
)
20209 (Present
(Scope
(Val
))
20210 and then Is_Implementation_Defined
(Scope
(Val
))))
20211 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
20212 and then Is_Library_Level_Entity
(Val
))
20214 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
20218 -- Do the style check
20221 and then not Suppress_Style_Checks
(Val
)
20222 and then not In_Instance
20224 if Nkind
(N
) = N_Identifier
then
20226 elsif Nkind
(N
) = N_Expanded_Name
then
20227 Nod
:= Selector_Name
(N
);
20232 -- A special situation arises for derived operations, where we want
20233 -- to do the check against the parent (since the Sloc of the derived
20234 -- operation points to the derived type declaration itself).
20237 while not Comes_From_Source
(Val_Actual
)
20238 and then Nkind
(Val_Actual
) in N_Entity
20239 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
20240 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
20241 and then Present
(Alias
(Val_Actual
))
20243 Val_Actual
:= Alias
(Val_Actual
);
20246 -- Renaming declarations for generic actuals do not come from source,
20247 -- and have a different name from that of the entity they rename, so
20248 -- there is no style check to perform here.
20250 if Chars
(Nod
) = Chars
(Val_Actual
) then
20251 Style
.Check_Identifier
(Nod
, Val_Actual
);
20255 Set_Entity
(N
, Val
);
20256 end Set_Entity_With_Checks
;
20258 ------------------------
20259 -- Set_Name_Entity_Id --
20260 ------------------------
20262 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
20264 Set_Name_Table_Int
(Id
, Int
(Val
));
20265 end Set_Name_Entity_Id
;
20267 ---------------------
20268 -- Set_Next_Actual --
20269 ---------------------
20271 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
20273 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
20274 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
20276 end Set_Next_Actual
;
20278 ----------------------------------
20279 -- Set_Optimize_Alignment_Flags --
20280 ----------------------------------
20282 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
20284 if Optimize_Alignment
= 'S' then
20285 Set_Optimize_Alignment_Space
(E
);
20286 elsif Optimize_Alignment
= 'T' then
20287 Set_Optimize_Alignment_Time
(E
);
20289 end Set_Optimize_Alignment_Flags
;
20291 -----------------------
20292 -- Set_Public_Status --
20293 -----------------------
20295 procedure Set_Public_Status
(Id
: Entity_Id
) is
20296 S
: constant Entity_Id
:= Current_Scope
;
20298 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
20299 -- Determines if E is defined within handled statement sequence or
20300 -- an if statement, returns True if so, False otherwise.
20302 ----------------------
20303 -- Within_HSS_Or_If --
20304 ----------------------
20306 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
20309 N
:= Declaration_Node
(E
);
20316 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
20322 end Within_HSS_Or_If
;
20324 -- Start of processing for Set_Public_Status
20327 -- Everything in the scope of Standard is public
20329 if S
= Standard_Standard
then
20330 Set_Is_Public
(Id
);
20332 -- Entity is definitely not public if enclosing scope is not public
20334 elsif not Is_Public
(S
) then
20337 -- An object or function declaration that occurs in a handled sequence
20338 -- of statements or within an if statement is the declaration for a
20339 -- temporary object or local subprogram generated by the expander. It
20340 -- never needs to be made public and furthermore, making it public can
20341 -- cause back end problems.
20343 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
20344 N_Function_Specification
)
20345 and then Within_HSS_Or_If
(Id
)
20349 -- Entities in public packages or records are public
20351 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
20352 Set_Is_Public
(Id
);
20354 -- The bounds of an entry family declaration can generate object
20355 -- declarations that are visible to the back-end, e.g. in the
20356 -- the declaration of a composite type that contains tasks.
20358 elsif Is_Concurrent_Type
(S
)
20359 and then not Has_Completion
(S
)
20360 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
20362 Set_Is_Public
(Id
);
20364 end Set_Public_Status
;
20366 -----------------------------
20367 -- Set_Referenced_Modified --
20368 -----------------------------
20370 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
20374 -- Deal with indexed or selected component where prefix is modified
20376 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
20377 Pref
:= Prefix
(N
);
20379 -- If prefix is access type, then it is the designated object that is
20380 -- being modified, which means we have no entity to set the flag on.
20382 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
20385 -- Otherwise chase the prefix
20388 Set_Referenced_Modified
(Pref
, Out_Param
);
20391 -- Otherwise see if we have an entity name (only other case to process)
20393 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
20394 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
20395 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
20397 end Set_Referenced_Modified
;
20399 ----------------------------
20400 -- Set_Scope_Is_Transient --
20401 ----------------------------
20403 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
20405 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
20406 end Set_Scope_Is_Transient
;
20408 -------------------
20409 -- Set_Size_Info --
20410 -------------------
20412 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
20414 -- We copy Esize, but not RM_Size, since in general RM_Size is
20415 -- subtype specific and does not get inherited by all subtypes.
20417 Set_Esize
(T1
, Esize
(T2
));
20418 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
20420 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
20422 Is_Discrete_Or_Fixed_Point_Type
(T2
)
20424 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
20427 Set_Alignment
(T1
, Alignment
(T2
));
20430 --------------------
20431 -- Static_Boolean --
20432 --------------------
20434 function Static_Boolean
(N
: Node_Id
) return Uint
is
20436 Analyze_And_Resolve
(N
, Standard_Boolean
);
20439 or else Error_Posted
(N
)
20440 or else Etype
(N
) = Any_Type
20445 if Is_OK_Static_Expression
(N
) then
20446 if not Raises_Constraint_Error
(N
) then
20447 return Expr_Value
(N
);
20452 elsif Etype
(N
) = Any_Type
then
20456 Flag_Non_Static_Expr
20457 ("static boolean expression required here", N
);
20460 end Static_Boolean
;
20462 --------------------
20463 -- Static_Integer --
20464 --------------------
20466 function Static_Integer
(N
: Node_Id
) return Uint
is
20468 Analyze_And_Resolve
(N
, Any_Integer
);
20471 or else Error_Posted
(N
)
20472 or else Etype
(N
) = Any_Type
20477 if Is_OK_Static_Expression
(N
) then
20478 if not Raises_Constraint_Error
(N
) then
20479 return Expr_Value
(N
);
20484 elsif Etype
(N
) = Any_Type
then
20488 Flag_Non_Static_Expr
20489 ("static integer expression required here", N
);
20492 end Static_Integer
;
20494 --------------------------
20495 -- Statically_Different --
20496 --------------------------
20498 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
20499 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
20500 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
20502 return Is_Entity_Name
(R1
)
20503 and then Is_Entity_Name
(R2
)
20504 and then Entity
(R1
) /= Entity
(R2
)
20505 and then not Is_Formal
(Entity
(R1
))
20506 and then not Is_Formal
(Entity
(R2
));
20507 end Statically_Different
;
20509 --------------------------------------
20510 -- Subject_To_Loop_Entry_Attributes --
20511 --------------------------------------
20513 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
20519 -- The expansion mechanism transform a loop subject to at least one
20520 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
20521 -- the conditional part.
20523 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
20524 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
20526 Stmt
:= Original_Node
(N
);
20530 Nkind
(Stmt
) = N_Loop_Statement
20531 and then Present
(Identifier
(Stmt
))
20532 and then Present
(Entity
(Identifier
(Stmt
)))
20533 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
20534 end Subject_To_Loop_Entry_Attributes
;
20536 -----------------------------
20537 -- Subprogram_Access_Level --
20538 -----------------------------
20540 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
20542 if Present
(Alias
(Subp
)) then
20543 return Subprogram_Access_Level
(Alias
(Subp
));
20545 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
20547 end Subprogram_Access_Level
;
20549 -------------------------------
20550 -- Support_Atomic_Primitives --
20551 -------------------------------
20553 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
20557 -- Verify the alignment of Typ is known
20559 if not Known_Alignment
(Typ
) then
20563 if Known_Static_Esize
(Typ
) then
20564 Size
:= UI_To_Int
(Esize
(Typ
));
20566 -- If the Esize (Object_Size) is unknown at compile time, look at the
20567 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
20569 elsif Known_Static_RM_Size
(Typ
) then
20570 Size
:= UI_To_Int
(RM_Size
(Typ
));
20572 -- Otherwise, the size is considered to be unknown.
20578 -- Check that the size of the component is 8, 16, 32, or 64 bits and
20579 -- that Typ is properly aligned.
20582 when 8 |
16 |
32 |
64 =>
20583 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
20587 end Support_Atomic_Primitives
;
20593 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
20595 if Debug_Flag_W
then
20596 for J
in 0 .. Scope_Stack
.Last
loop
20601 Write_Name
(Chars
(E
));
20602 Write_Str
(" from ");
20603 Write_Location
(Sloc
(N
));
20608 -----------------------
20609 -- Transfer_Entities --
20610 -----------------------
20612 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
20613 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
20614 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
20615 -- Set_Public_Status. If successfull and Id denotes a record type, set
20616 -- the Is_Public attribute of its fields.
20618 --------------------------
20619 -- Set_Public_Status_Of --
20620 --------------------------
20622 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
20626 if not Is_Public
(Id
) then
20627 Set_Public_Status
(Id
);
20629 -- When the input entity is a public record type, ensure that all
20630 -- its internal fields are also exposed to the linker. The fields
20631 -- of a class-wide type are never made public.
20634 and then Is_Record_Type
(Id
)
20635 and then not Is_Class_Wide_Type
(Id
)
20637 Field
:= First_Entity
(Id
);
20638 while Present
(Field
) loop
20639 Set_Is_Public
(Field
);
20640 Next_Entity
(Field
);
20644 end Set_Public_Status_Of
;
20648 Full_Id
: Entity_Id
;
20651 -- Start of processing for Transfer_Entities
20654 Id
:= First_Entity
(From
);
20656 if Present
(Id
) then
20658 -- Merge the entity chain of the source scope with that of the
20659 -- destination scope.
20661 if Present
(Last_Entity
(To
)) then
20662 Set_Next_Entity
(Last_Entity
(To
), Id
);
20664 Set_First_Entity
(To
, Id
);
20667 Set_Last_Entity
(To
, Last_Entity
(From
));
20669 -- Inspect the entities of the source scope and update their Scope
20672 while Present
(Id
) loop
20673 Set_Scope
(Id
, To
);
20674 Set_Public_Status_Of
(Id
);
20676 -- Handle an internally generated full view for a private type
20678 if Is_Private_Type
(Id
)
20679 and then Present
(Full_View
(Id
))
20680 and then Is_Itype
(Full_View
(Id
))
20682 Full_Id
:= Full_View
(Id
);
20684 Set_Scope
(Full_Id
, To
);
20685 Set_Public_Status_Of
(Full_Id
);
20691 Set_First_Entity
(From
, Empty
);
20692 Set_Last_Entity
(From
, Empty
);
20694 end Transfer_Entities
;
20696 -----------------------
20697 -- Type_Access_Level --
20698 -----------------------
20700 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
20704 Btyp
:= Base_Type
(Typ
);
20706 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
20707 -- simply use the level where the type is declared. This is true for
20708 -- stand-alone object declarations, and for anonymous access types
20709 -- associated with components the level is the same as that of the
20710 -- enclosing composite type. However, special treatment is needed for
20711 -- the cases of access parameters, return objects of an anonymous access
20712 -- type, and, in Ada 95, access discriminants of limited types.
20714 if Is_Access_Type
(Btyp
) then
20715 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
20717 -- If the type is a nonlocal anonymous access type (such as for
20718 -- an access parameter) we treat it as being declared at the
20719 -- library level to ensure that names such as X.all'access don't
20720 -- fail static accessibility checks.
20722 if not Is_Local_Anonymous_Access
(Typ
) then
20723 return Scope_Depth
(Standard_Standard
);
20725 -- If this is a return object, the accessibility level is that of
20726 -- the result subtype of the enclosing function. The test here is
20727 -- little complicated, because we have to account for extended
20728 -- return statements that have been rewritten as blocks, in which
20729 -- case we have to find and the Is_Return_Object attribute of the
20730 -- itype's associated object. It would be nice to find a way to
20731 -- simplify this test, but it doesn't seem worthwhile to add a new
20732 -- flag just for purposes of this test. ???
20734 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
20737 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
20738 N_Object_Declaration
20739 and then Is_Return_Object
20740 (Defining_Identifier
20741 (Associated_Node_For_Itype
(Btyp
))))
20747 Scop
:= Scope
(Scope
(Btyp
));
20748 while Present
(Scop
) loop
20749 exit when Ekind
(Scop
) = E_Function
;
20750 Scop
:= Scope
(Scop
);
20753 -- Treat the return object's type as having the level of the
20754 -- function's result subtype (as per RM05-6.5(5.3/2)).
20756 return Type_Access_Level
(Etype
(Scop
));
20761 Btyp
:= Root_Type
(Btyp
);
20763 -- The accessibility level of anonymous access types associated with
20764 -- discriminants is that of the current instance of the type, and
20765 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
20767 -- AI-402: access discriminants have accessibility based on the
20768 -- object rather than the type in Ada 2005, so the above paragraph
20771 -- ??? Needs completion with rules from AI-416
20773 if Ada_Version
<= Ada_95
20774 and then Ekind
(Typ
) = E_Anonymous_Access_Type
20775 and then Present
(Associated_Node_For_Itype
(Typ
))
20776 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
20777 N_Discriminant_Specification
20779 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
20783 -- Return library level for a generic formal type. This is done because
20784 -- RM(10.3.2) says that "The statically deeper relationship does not
20785 -- apply to ... a descendant of a generic formal type". Rather than
20786 -- checking at each point where a static accessibility check is
20787 -- performed to see if we are dealing with a formal type, this rule is
20788 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
20789 -- return extreme values for a formal type; Deepest_Type_Access_Level
20790 -- returns Int'Last. By calling the appropriate function from among the
20791 -- two, we ensure that the static accessibility check will pass if we
20792 -- happen to run into a formal type. More specifically, we should call
20793 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
20794 -- call occurs as part of a static accessibility check and the error
20795 -- case is the case where the type's level is too shallow (as opposed
20798 if Is_Generic_Type
(Root_Type
(Btyp
)) then
20799 return Scope_Depth
(Standard_Standard
);
20802 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
20803 end Type_Access_Level
;
20805 ------------------------------------
20806 -- Type_Without_Stream_Operation --
20807 ------------------------------------
20809 function Type_Without_Stream_Operation
20811 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
20813 BT
: constant Entity_Id
:= Base_Type
(T
);
20814 Op_Missing
: Boolean;
20817 if not Restriction_Active
(No_Default_Stream_Attributes
) then
20821 if Is_Elementary_Type
(T
) then
20822 if Op
= TSS_Null
then
20824 No
(TSS
(BT
, TSS_Stream_Read
))
20825 or else No
(TSS
(BT
, TSS_Stream_Write
));
20828 Op_Missing
:= No
(TSS
(BT
, Op
));
20837 elsif Is_Array_Type
(T
) then
20838 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
20840 elsif Is_Record_Type
(T
) then
20846 Comp
:= First_Component
(T
);
20847 while Present
(Comp
) loop
20848 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
20850 if Present
(C_Typ
) then
20854 Next_Component
(Comp
);
20860 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
20861 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
20865 end Type_Without_Stream_Operation
;
20867 ----------------------------
20868 -- Unique_Defining_Entity --
20869 ----------------------------
20871 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
20873 return Unique_Entity
(Defining_Entity
(N
));
20874 end Unique_Defining_Entity
;
20876 -------------------
20877 -- Unique_Entity --
20878 -------------------
20880 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
20881 U
: Entity_Id
:= E
;
20887 if Present
(Full_View
(E
)) then
20888 U
:= Full_View
(E
);
20892 if Nkind
(Parent
(E
)) = N_Entry_Body
then
20894 Prot_Item
: Entity_Id
;
20896 -- Traverse the entity list of the protected type and locate
20897 -- an entry declaration which matches the entry body.
20899 Prot_Item
:= First_Entity
(Scope
(E
));
20900 while Present
(Prot_Item
) loop
20901 if Ekind
(Prot_Item
) = E_Entry
20902 and then Corresponding_Body
(Parent
(Prot_Item
)) = E
20908 Next_Entity
(Prot_Item
);
20913 when Formal_Kind
=>
20914 if Present
(Spec_Entity
(E
)) then
20915 U
:= Spec_Entity
(E
);
20918 when E_Package_Body
=>
20921 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
20925 if Nkind
(P
) = N_Package_Body
20926 and then Present
(Corresponding_Spec
(P
))
20928 U
:= Corresponding_Spec
(P
);
20930 elsif Nkind
(P
) = N_Package_Body_Stub
20931 and then Present
(Corresponding_Spec_Of_Stub
(P
))
20933 U
:= Corresponding_Spec_Of_Stub
(P
);
20936 when E_Protected_Body
=>
20939 if Nkind
(P
) = N_Protected_Body
20940 and then Present
(Corresponding_Spec
(P
))
20942 U
:= Corresponding_Spec
(P
);
20944 elsif Nkind
(P
) = N_Protected_Body_Stub
20945 and then Present
(Corresponding_Spec_Of_Stub
(P
))
20947 U
:= Corresponding_Spec_Of_Stub
(P
);
20950 when E_Subprogram_Body
=>
20953 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
20959 if Nkind
(P
) = N_Subprogram_Body
20960 and then Present
(Corresponding_Spec
(P
))
20962 U
:= Corresponding_Spec
(P
);
20964 elsif Nkind
(P
) = N_Subprogram_Body_Stub
20965 and then Present
(Corresponding_Spec_Of_Stub
(P
))
20967 U
:= Corresponding_Spec_Of_Stub
(P
);
20969 elsif Nkind
(P
) = N_Subprogram_Renaming_Declaration
then
20970 U
:= Corresponding_Spec
(P
);
20973 when E_Task_Body
=>
20976 if Nkind
(P
) = N_Task_Body
20977 and then Present
(Corresponding_Spec
(P
))
20979 U
:= Corresponding_Spec
(P
);
20981 elsif Nkind
(P
) = N_Task_Body_Stub
20982 and then Present
(Corresponding_Spec_Of_Stub
(P
))
20984 U
:= Corresponding_Spec_Of_Stub
(P
);
20988 if Present
(Full_View
(E
)) then
20989 U
:= Full_View
(E
);
21003 function Unique_Name
(E
: Entity_Id
) return String is
21005 -- Names of E_Subprogram_Body or E_Package_Body entities are not
21006 -- reliable, as they may not include the overloading suffix. Instead,
21007 -- when looking for the name of E or one of its enclosing scope, we get
21008 -- the name of the corresponding Unique_Entity.
21010 function Get_Scoped_Name
(E
: Entity_Id
) return String;
21011 -- Return the name of E prefixed by all the names of the scopes to which
21012 -- E belongs, except for Standard.
21014 ---------------------
21015 -- Get_Scoped_Name --
21016 ---------------------
21018 function Get_Scoped_Name
(E
: Entity_Id
) return String is
21019 Name
: constant String := Get_Name_String
(Chars
(E
));
21021 if Has_Fully_Qualified_Name
(E
)
21022 or else Scope
(E
) = Standard_Standard
21026 return Get_Scoped_Name
(Unique_Entity
(Scope
(E
))) & "__" & Name
;
21028 end Get_Scoped_Name
;
21030 -- Start of processing for Unique_Name
21033 if E
= Standard_Standard
then
21034 return Get_Name_String
(Name_Standard
);
21036 elsif Scope
(E
) = Standard_Standard
21037 and then not (Ekind
(E
) = E_Package
or else Is_Subprogram
(E
))
21039 return Get_Name_String
(Name_Standard
) & "__" &
21040 Get_Name_String
(Chars
(E
));
21042 elsif Ekind
(E
) = E_Enumeration_Literal
then
21043 return Unique_Name
(Etype
(E
)) & "__" & Get_Name_String
(Chars
(E
));
21046 return Get_Scoped_Name
(Unique_Entity
(E
));
21050 ---------------------
21051 -- Unit_Is_Visible --
21052 ---------------------
21054 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
21055 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
21056 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
21058 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
21059 -- For a child unit, check whether unit appears in a with_clause
21062 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
21063 -- Scan the context clause of one compilation unit looking for a
21064 -- with_clause for the unit in question.
21066 ----------------------------
21067 -- Unit_In_Parent_Context --
21068 ----------------------------
21070 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
21072 if Unit_In_Context
(Par_Unit
) then
21075 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
21076 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
21081 end Unit_In_Parent_Context
;
21083 ---------------------
21084 -- Unit_In_Context --
21085 ---------------------
21087 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
21091 Clause
:= First
(Context_Items
(Comp_Unit
));
21092 while Present
(Clause
) loop
21093 if Nkind
(Clause
) = N_With_Clause
then
21094 if Library_Unit
(Clause
) = U
then
21097 -- The with_clause may denote a renaming of the unit we are
21098 -- looking for, eg. Text_IO which renames Ada.Text_IO.
21101 Renamed_Entity
(Entity
(Name
(Clause
))) =
21102 Defining_Entity
(Unit
(U
))
21112 end Unit_In_Context
;
21114 -- Start of processing for Unit_Is_Visible
21117 -- The currrent unit is directly visible
21122 elsif Unit_In_Context
(Curr
) then
21125 -- If the current unit is a body, check the context of the spec
21127 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
21129 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
21130 and then not Acts_As_Spec
(Unit
(Curr
)))
21132 if Unit_In_Context
(Library_Unit
(Curr
)) then
21137 -- If the spec is a child unit, examine the parents
21139 if Is_Child_Unit
(Curr_Entity
) then
21140 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
21142 Unit_In_Parent_Context
21143 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
21145 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
21151 end Unit_Is_Visible
;
21153 ------------------------------
21154 -- Universal_Interpretation --
21155 ------------------------------
21157 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
21158 Index
: Interp_Index
;
21162 -- The argument may be a formal parameter of an operator or subprogram
21163 -- with multiple interpretations, or else an expression for an actual.
21165 if Nkind
(Opnd
) = N_Defining_Identifier
21166 or else not Is_Overloaded
(Opnd
)
21168 if Etype
(Opnd
) = Universal_Integer
21169 or else Etype
(Opnd
) = Universal_Real
21171 return Etype
(Opnd
);
21177 Get_First_Interp
(Opnd
, Index
, It
);
21178 while Present
(It
.Typ
) loop
21179 if It
.Typ
= Universal_Integer
21180 or else It
.Typ
= Universal_Real
21185 Get_Next_Interp
(Index
, It
);
21190 end Universal_Interpretation
;
21196 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
21198 -- Recurse to handle unlikely case of multiple levels of qualification
21200 if Nkind
(Expr
) = N_Qualified_Expression
then
21201 return Unqualify
(Expression
(Expr
));
21203 -- Normal case, not a qualified expression
21210 -----------------------
21211 -- Visible_Ancestors --
21212 -----------------------
21214 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
21220 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
21222 -- Collect all the parents and progenitors of Typ. If the full-view of
21223 -- private parents and progenitors is available then it is used to
21224 -- generate the list of visible ancestors; otherwise their partial
21225 -- view is added to the resulting list.
21230 Use_Full_View
=> True);
21234 Ifaces_List
=> List_2
,
21235 Exclude_Parents
=> True,
21236 Use_Full_View
=> True);
21238 -- Join the two lists. Avoid duplications because an interface may
21239 -- simultaneously be parent and progenitor of a type.
21241 Elmt
:= First_Elmt
(List_2
);
21242 while Present
(Elmt
) loop
21243 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
21248 end Visible_Ancestors
;
21250 ----------------------
21251 -- Within_Init_Proc --
21252 ----------------------
21254 function Within_Init_Proc
return Boolean is
21258 S
:= Current_Scope
;
21259 while not Is_Overloadable
(S
) loop
21260 if S
= Standard_Standard
then
21267 return Is_Init_Proc
(S
);
21268 end Within_Init_Proc
;
21274 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
21276 return Scope_Within_Or_Same
(Scope
(E
), S
);
21283 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
21284 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
21285 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
21287 Matching_Field
: Entity_Id
;
21288 -- Entity to give a more precise suggestion on how to write a one-
21289 -- element positional aggregate.
21291 function Has_One_Matching_Field
return Boolean;
21292 -- Determines if Expec_Type is a record type with a single component or
21293 -- discriminant whose type matches the found type or is one dimensional
21294 -- array whose component type matches the found type. In the case of
21295 -- one discriminant, we ignore the variant parts. That's not accurate,
21296 -- but good enough for the warning.
21298 ----------------------------
21299 -- Has_One_Matching_Field --
21300 ----------------------------
21302 function Has_One_Matching_Field
return Boolean is
21306 Matching_Field
:= Empty
;
21308 if Is_Array_Type
(Expec_Type
)
21309 and then Number_Dimensions
(Expec_Type
) = 1
21310 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
21312 -- Use type name if available. This excludes multidimensional
21313 -- arrays and anonymous arrays.
21315 if Comes_From_Source
(Expec_Type
) then
21316 Matching_Field
:= Expec_Type
;
21318 -- For an assignment, use name of target
21320 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
21321 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
21323 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
21328 elsif not Is_Record_Type
(Expec_Type
) then
21332 E
:= First_Entity
(Expec_Type
);
21337 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
21338 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
21347 if not Covers
(Etype
(E
), Found_Type
) then
21350 elsif Present
(Next_Entity
(E
))
21351 and then (Ekind
(E
) = E_Component
21352 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
21357 Matching_Field
:= E
;
21361 end Has_One_Matching_Field
;
21363 -- Start of processing for Wrong_Type
21366 -- Don't output message if either type is Any_Type, or if a message
21367 -- has already been posted for this node. We need to do the latter
21368 -- check explicitly (it is ordinarily done in Errout), because we
21369 -- are using ! to force the output of the error messages.
21371 if Expec_Type
= Any_Type
21372 or else Found_Type
= Any_Type
21373 or else Error_Posted
(Expr
)
21377 -- If one of the types is a Taft-Amendment type and the other it its
21378 -- completion, it must be an illegal use of a TAT in the spec, for
21379 -- which an error was already emitted. Avoid cascaded errors.
21381 elsif Is_Incomplete_Type
(Expec_Type
)
21382 and then Has_Completion_In_Body
(Expec_Type
)
21383 and then Full_View
(Expec_Type
) = Etype
(Expr
)
21387 elsif Is_Incomplete_Type
(Etype
(Expr
))
21388 and then Has_Completion_In_Body
(Etype
(Expr
))
21389 and then Full_View
(Etype
(Expr
)) = Expec_Type
21393 -- In an instance, there is an ongoing problem with completion of
21394 -- type derived from private types. Their structure is what Gigi
21395 -- expects, but the Etype is the parent type rather than the
21396 -- derived private type itself. Do not flag error in this case. The
21397 -- private completion is an entity without a parent, like an Itype.
21398 -- Similarly, full and partial views may be incorrect in the instance.
21399 -- There is no simple way to insure that it is consistent ???
21401 -- A similar view discrepancy can happen in an inlined body, for the
21402 -- same reason: inserted body may be outside of the original package
21403 -- and only partial views are visible at the point of insertion.
21405 elsif In_Instance
or else In_Inlined_Body
then
21406 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
21408 (Has_Private_Declaration
(Expected_Type
)
21409 or else Has_Private_Declaration
(Etype
(Expr
)))
21410 and then No
(Parent
(Expected_Type
))
21414 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
21415 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
21419 elsif Is_Private_Type
(Expected_Type
)
21420 and then Present
(Full_View
(Expected_Type
))
21421 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
21425 -- Conversely, type of expression may be the private one
21427 elsif Is_Private_Type
(Base_Type
(Etype
(Expr
)))
21428 and then Full_View
(Base_Type
(Etype
(Expr
))) = Expected_Type
21434 -- An interesting special check. If the expression is parenthesized
21435 -- and its type corresponds to the type of the sole component of the
21436 -- expected record type, or to the component type of the expected one
21437 -- dimensional array type, then assume we have a bad aggregate attempt.
21439 if Nkind
(Expr
) in N_Subexpr
21440 and then Paren_Count
(Expr
) /= 0
21441 and then Has_One_Matching_Field
21443 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
21445 if Present
(Matching_Field
) then
21446 if Is_Array_Type
(Expec_Type
) then
21448 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
21451 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
21455 -- Another special check, if we are looking for a pool-specific access
21456 -- type and we found an E_Access_Attribute_Type, then we have the case
21457 -- of an Access attribute being used in a context which needs a pool-
21458 -- specific type, which is never allowed. The one extra check we make
21459 -- is that the expected designated type covers the Found_Type.
21461 elsif Is_Access_Type
(Expec_Type
)
21462 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
21463 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
21464 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
21466 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
21468 Error_Msg_N
-- CODEFIX
21469 ("result must be general access type!", Expr
);
21470 Error_Msg_NE
-- CODEFIX
21471 ("add ALL to }!", Expr
, Expec_Type
);
21473 -- Another special check, if the expected type is an integer type,
21474 -- but the expression is of type System.Address, and the parent is
21475 -- an addition or subtraction operation whose left operand is the
21476 -- expression in question and whose right operand is of an integral
21477 -- type, then this is an attempt at address arithmetic, so give
21478 -- appropriate message.
21480 elsif Is_Integer_Type
(Expec_Type
)
21481 and then Is_RTE
(Found_Type
, RE_Address
)
21482 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
21483 and then Expr
= Left_Opnd
(Parent
(Expr
))
21484 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
21487 ("address arithmetic not predefined in package System",
21490 ("\possible missing with/use of System.Storage_Elements",
21494 -- If the expected type is an anonymous access type, as for access
21495 -- parameters and discriminants, the error is on the designated types.
21497 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
21498 if Comes_From_Source
(Expec_Type
) then
21499 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
21502 ("expected an access type with designated}",
21503 Expr
, Designated_Type
(Expec_Type
));
21506 if Is_Access_Type
(Found_Type
)
21507 and then not Comes_From_Source
(Found_Type
)
21510 ("\\found an access type with designated}!",
21511 Expr
, Designated_Type
(Found_Type
));
21513 if From_Limited_With
(Found_Type
) then
21514 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
21515 Error_Msg_Qual_Level
:= 99;
21516 Error_Msg_NE
-- CODEFIX
21517 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
21518 Error_Msg_Qual_Level
:= 0;
21520 Error_Msg_NE
("found}!", Expr
, Found_Type
);
21524 -- Normal case of one type found, some other type expected
21527 -- If the names of the two types are the same, see if some number
21528 -- of levels of qualification will help. Don't try more than three
21529 -- levels, and if we get to standard, it's no use (and probably
21530 -- represents an error in the compiler) Also do not bother with
21531 -- internal scope names.
21534 Expec_Scope
: Entity_Id
;
21535 Found_Scope
: Entity_Id
;
21538 Expec_Scope
:= Expec_Type
;
21539 Found_Scope
:= Found_Type
;
21541 for Levels
in Nat
range 0 .. 3 loop
21542 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
21543 Error_Msg_Qual_Level
:= Levels
;
21547 Expec_Scope
:= Scope
(Expec_Scope
);
21548 Found_Scope
:= Scope
(Found_Scope
);
21550 exit when Expec_Scope
= Standard_Standard
21551 or else Found_Scope
= Standard_Standard
21552 or else not Comes_From_Source
(Expec_Scope
)
21553 or else not Comes_From_Source
(Found_Scope
);
21557 if Is_Record_Type
(Expec_Type
)
21558 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
21560 Error_Msg_NE
("expected}!", Expr
,
21561 Corresponding_Remote_Type
(Expec_Type
));
21563 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
21566 if Is_Entity_Name
(Expr
)
21567 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
21569 Error_Msg_N
("\\found package name!", Expr
);
21571 elsif Is_Entity_Name
(Expr
)
21572 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
21574 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
21576 ("found procedure name, possibly missing Access attribute!",
21580 ("\\found procedure name instead of function!", Expr
);
21583 elsif Nkind
(Expr
) = N_Function_Call
21584 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
21585 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
21586 and then No
(Parameter_Associations
(Expr
))
21589 ("found function name, possibly missing Access attribute!",
21592 -- Catch common error: a prefix or infix operator which is not
21593 -- directly visible because the type isn't.
21595 elsif Nkind
(Expr
) in N_Op
21596 and then Is_Overloaded
(Expr
)
21597 and then not Is_Immediately_Visible
(Expec_Type
)
21598 and then not Is_Potentially_Use_Visible
(Expec_Type
)
21599 and then not In_Use
(Expec_Type
)
21600 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
21603 ("operator of the type is not directly visible!", Expr
);
21605 elsif Ekind
(Found_Type
) = E_Void
21606 and then Present
(Parent
(Found_Type
))
21607 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
21609 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
21612 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
21615 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
21616 -- of the same modular type, and (M1 and M2) = 0 was intended.
21618 if Expec_Type
= Standard_Boolean
21619 and then Is_Modular_Integer_Type
(Found_Type
)
21620 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
21621 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
21624 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
21625 L
: constant Node_Id
:= Left_Opnd
(Op
);
21626 R
: constant Node_Id
:= Right_Opnd
(Op
);
21629 -- The case for the message is when the left operand of the
21630 -- comparison is the same modular type, or when it is an
21631 -- integer literal (or other universal integer expression),
21632 -- which would have been typed as the modular type if the
21633 -- parens had been there.
21635 if (Etype
(L
) = Found_Type
21637 Etype
(L
) = Universal_Integer
)
21638 and then Is_Integer_Type
(Etype
(R
))
21641 ("\\possible missing parens for modular operation", Expr
);
21646 -- Reset error message qualification indication
21648 Error_Msg_Qual_Level
:= 0;
21652 --------------------------------
21653 -- Yields_Synchronized_Object --
21654 --------------------------------
21656 function Yields_Synchronized_Object
(Typ
: Entity_Id
) return Boolean is
21657 Has_Sync_Comp
: Boolean := False;
21661 -- An array type yields a synchronized object if its component type
21662 -- yields a synchronized object.
21664 if Is_Array_Type
(Typ
) then
21665 return Yields_Synchronized_Object
(Component_Type
(Typ
));
21667 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
21668 -- yields a synchronized object by default.
21670 elsif Is_Descendant_Of_Suspension_Object
(Typ
) then
21673 -- A protected type yields a synchronized object by default
21675 elsif Is_Protected_Type
(Typ
) then
21678 -- A record type or type extension yields a synchronized object when its
21679 -- discriminants (if any) lack default values and all components are of
21680 -- a type that yelds a synchronized object.
21682 elsif Is_Record_Type
(Typ
) then
21684 -- Inspect all entities defined in the scope of the type, looking for
21685 -- components of a type that does not yeld a synchronized object or
21686 -- for discriminants with default values.
21688 Id
:= First_Entity
(Typ
);
21689 while Present
(Id
) loop
21690 if Comes_From_Source
(Id
) then
21691 if Ekind
(Id
) = E_Component
then
21692 if Yields_Synchronized_Object
(Etype
(Id
)) then
21693 Has_Sync_Comp
:= True;
21695 -- The component does not yield a synchronized object
21701 elsif Ekind
(Id
) = E_Discriminant
21702 and then Present
(Expression
(Parent
(Id
)))
21711 -- Ensure that the parent type of a type extension yields a
21712 -- synchronized object.
21714 if Etype
(Typ
) /= Typ
21715 and then not Yields_Synchronized_Object
(Etype
(Typ
))
21720 -- If we get here, then all discriminants lack default values and all
21721 -- components are of a type that yields a synchronized object.
21723 return Has_Sync_Comp
;
21725 -- A synchronized interface type yields a synchronized object by default
21727 elsif Is_Synchronized_Interface
(Typ
) then
21730 -- A task type yelds a synchronized object by default
21732 elsif Is_Task_Type
(Typ
) then
21735 -- Otherwise the type does not yield a synchronized object
21740 end Yields_Synchronized_Object
;
21742 ---------------------------
21743 -- Yields_Universal_Type --
21744 ---------------------------
21746 function Yields_Universal_Type
(N
: Node_Id
) return Boolean is
21748 -- Integer and real literals are of a universal type
21750 if Nkind_In
(N
, N_Integer_Literal
, N_Real_Literal
) then
21753 -- The values of certain attributes are of a universal type
21755 elsif Nkind
(N
) = N_Attribute_Reference
then
21757 Universal_Type_Attribute
(Get_Attribute_Id
(Attribute_Name
(N
)));
21759 -- ??? There are possibly other cases to consider
21764 end Yields_Universal_Type
;