1 ------------------------------------------------------------------------------
3 -- GNAT COMPILER COMPONENTS --
9 -- Copyright (C) 1992-2017, 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 Erroutc
; use Erroutc
;
36 with Exp_Ch11
; use Exp_Ch11
;
37 with Exp_Disp
; use Exp_Disp
;
38 with Exp_Util
; use Exp_Util
;
39 with Fname
; use Fname
;
40 with Freeze
; use Freeze
;
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_Disp
; use Sem_Disp
;
56 with Sem_Eval
; use Sem_Eval
;
57 with Sem_Prag
; use Sem_Prag
;
58 with Sem_Res
; use Sem_Res
;
59 with Sem_Warn
; use Sem_Warn
;
60 with Sem_Type
; use Sem_Type
;
61 with Sinfo
; use Sinfo
;
62 with Sinput
; use Sinput
;
63 with Stand
; use Stand
;
65 with Stringt
; use Stringt
;
66 with Targparm
; use Targparm
;
67 with Tbuild
; use Tbuild
;
68 with Ttypes
; use Ttypes
;
69 with Uname
; use Uname
;
71 with GNAT
.HTable
; use GNAT
.HTable
;
73 package body Sem_Util
is
75 -----------------------
76 -- Local Subprograms --
77 -----------------------
79 function Build_Component_Subtype
82 T
: Entity_Id
) return Node_Id
;
83 -- This function builds the subtype for Build_Actual_Subtype_Of_Component
84 -- and Build_Discriminal_Subtype_Of_Component. C is a list of constraints,
85 -- Loc is the source location, T is the original subtype.
87 function Has_Enabled_Property
89 Property
: Name_Id
) return Boolean;
90 -- Subsidiary to routines Async_xxx_Enabled and Effective_xxx_Enabled.
91 -- Determine whether an abstract state or a variable denoted by entity
92 -- Item_Id has enabled property Property.
94 function Has_Null_Extension
(T
: Entity_Id
) return Boolean;
95 -- T is a derived tagged type. Check whether the type extension is null.
96 -- If the parent type is fully initialized, T can be treated as such.
98 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean;
99 -- Subsidiary to Is_Fully_Initialized_Type. For an unconstrained type
100 -- with discriminants whose default values are static, examine only the
101 -- components in the selected variant to determine whether all of them
104 type Null_Status_Kind
is
106 -- This value indicates that a subexpression is known to have a null
107 -- value at compile time.
110 -- This value indicates that a subexpression is known to have a non-null
111 -- value at compile time.
114 -- This value indicates that it cannot be determined at compile time
115 -- whether a subexpression yields a null or non-null value.
117 function Null_Status
(N
: Node_Id
) return Null_Status_Kind
;
118 -- Determine whether subexpression N of an access type yields a null value,
119 -- a non-null value, or the value cannot be determined at compile time. The
120 -- routine does not take simple flow diagnostics into account, it relies on
121 -- static facts such as the presence of null exclusions.
123 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
124 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean;
125 -- ???We retain the old and new algorithms for Requires_Transient_Scope for
126 -- the time being. New_Requires_Transient_Scope is used by default; the
127 -- debug switch -gnatdQ can be used to do Old_Requires_Transient_Scope
128 -- instead. The intent is to use this temporarily to measure before/after
129 -- efficiency. Note: when this temporary code is removed, the documentation
130 -- of dQ in debug.adb should be removed.
132 procedure Results_Differ
136 -- ???Debugging code. Called when the Old_Val and New_Val differ. This
137 -- routine will be removed eventially when New_Requires_Transient_Scope
138 -- becomes Requires_Transient_Scope and Old_Requires_Transient_Scope is
141 function Subprogram_Name
(N
: Node_Id
) return String;
142 -- Return the fully qualified name of the enclosing subprogram for the
145 ------------------------------
146 -- Abstract_Interface_List --
147 ------------------------------
149 function Abstract_Interface_List
(Typ
: Entity_Id
) return List_Id
is
153 if Is_Concurrent_Type
(Typ
) then
155 -- If we are dealing with a synchronized subtype, go to the base
156 -- type, whose declaration has the interface list.
158 -- Shouldn't this be Declaration_Node???
160 Nod
:= Parent
(Base_Type
(Typ
));
162 if Nkind
(Nod
) = N_Full_Type_Declaration
then
166 elsif Ekind
(Typ
) = E_Record_Type_With_Private
then
167 if Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
then
168 Nod
:= Type_Definition
(Parent
(Typ
));
170 elsif Nkind
(Parent
(Typ
)) = N_Private_Type_Declaration
then
171 if Present
(Full_View
(Typ
))
173 Nkind
(Parent
(Full_View
(Typ
))) = N_Full_Type_Declaration
175 Nod
:= Type_Definition
(Parent
(Full_View
(Typ
)));
177 -- If the full-view is not available we cannot do anything else
178 -- here (the source has errors).
184 -- Support for generic formals with interfaces is still missing ???
186 elsif Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
191 (Nkind
(Parent
(Typ
)) = N_Private_Extension_Declaration
);
195 elsif Ekind
(Typ
) = E_Record_Subtype
then
196 Nod
:= Type_Definition
(Parent
(Etype
(Typ
)));
198 elsif Ekind
(Typ
) = E_Record_Subtype_With_Private
then
200 -- Recurse, because parent may still be a private extension. Also
201 -- note that the full view of the subtype or the full view of its
202 -- base type may (both) be unavailable.
204 return Abstract_Interface_List
(Etype
(Typ
));
206 elsif Ekind
(Typ
) = E_Record_Type
then
207 if Nkind
(Parent
(Typ
)) = N_Formal_Type_Declaration
then
208 Nod
:= Formal_Type_Definition
(Parent
(Typ
));
210 Nod
:= Type_Definition
(Parent
(Typ
));
213 -- Otherwise the type is of a kind which does not implement interfaces
219 return Interface_List
(Nod
);
220 end Abstract_Interface_List
;
222 --------------------------------
223 -- Add_Access_Type_To_Process --
224 --------------------------------
226 procedure Add_Access_Type_To_Process
(E
: Entity_Id
; A
: Entity_Id
) is
230 Ensure_Freeze_Node
(E
);
231 L
:= Access_Types_To_Process
(Freeze_Node
(E
));
235 Set_Access_Types_To_Process
(Freeze_Node
(E
), L
);
239 end Add_Access_Type_To_Process
;
241 --------------------------
242 -- Add_Block_Identifier --
243 --------------------------
245 procedure Add_Block_Identifier
(N
: Node_Id
; Id
: out Entity_Id
) is
246 Loc
: constant Source_Ptr
:= Sloc
(N
);
249 pragma Assert
(Nkind
(N
) = N_Block_Statement
);
251 -- The block already has a label, return its entity
253 if Present
(Identifier
(N
)) then
254 Id
:= Entity
(Identifier
(N
));
256 -- Create a new block label and set its attributes
259 Id
:= New_Internal_Entity
(E_Block
, Current_Scope
, Loc
, 'B');
260 Set_Etype
(Id
, Standard_Void_Type
);
263 Set_Identifier
(N
, New_Occurrence_Of
(Id
, Loc
));
264 Set_Block_Node
(Id
, Identifier
(N
));
266 end Add_Block_Identifier
;
268 ----------------------------
269 -- Add_Global_Declaration --
270 ----------------------------
272 procedure Add_Global_Declaration
(N
: Node_Id
) is
273 Aux_Node
: constant Node_Id
:= Aux_Decls_Node
(Cunit
(Current_Sem_Unit
));
276 if No
(Declarations
(Aux_Node
)) then
277 Set_Declarations
(Aux_Node
, New_List
);
280 Append_To
(Declarations
(Aux_Node
), N
);
282 end Add_Global_Declaration
;
284 --------------------------------
285 -- Address_Integer_Convert_OK --
286 --------------------------------
288 function Address_Integer_Convert_OK
(T1
, T2
: Entity_Id
) return Boolean is
290 if Allow_Integer_Address
291 and then ((Is_Descendant_Of_Address
(T1
)
292 and then Is_Private_Type
(T1
)
293 and then Is_Integer_Type
(T2
))
295 (Is_Descendant_Of_Address
(T2
)
296 and then Is_Private_Type
(T2
)
297 and then Is_Integer_Type
(T1
)))
303 end Address_Integer_Convert_OK
;
309 function Address_Value
(N
: Node_Id
) return Node_Id
is
314 -- For constant, get constant expression
316 if Is_Entity_Name
(Expr
)
317 and then Ekind
(Entity
(Expr
)) = E_Constant
319 Expr
:= Constant_Value
(Entity
(Expr
));
321 -- For unchecked conversion, get result to convert
323 elsif Nkind
(Expr
) = N_Unchecked_Type_Conversion
then
324 Expr
:= Expression
(Expr
);
326 -- For (common case) of To_Address call, get argument
328 elsif Nkind
(Expr
) = N_Function_Call
329 and then Is_Entity_Name
(Name
(Expr
))
330 and then Is_RTE
(Entity
(Name
(Expr
)), RE_To_Address
)
332 Expr
:= First
(Parameter_Associations
(Expr
));
334 if Nkind
(Expr
) = N_Parameter_Association
then
335 Expr
:= Explicit_Actual_Parameter
(Expr
);
338 -- We finally have the real expression
352 -- For now, just 8/16/32/64
354 function Addressable
(V
: Uint
) return Boolean is
356 return V
= Uint_8
or else
362 function Addressable
(V
: Int
) return Boolean is
370 ---------------------------------
371 -- Aggregate_Constraint_Checks --
372 ---------------------------------
374 procedure Aggregate_Constraint_Checks
376 Check_Typ
: Entity_Id
)
378 Exp_Typ
: constant Entity_Id
:= Etype
(Exp
);
381 if Raises_Constraint_Error
(Exp
) then
385 -- Ada 2005 (AI-230): Generate a conversion to an anonymous access
386 -- component's type to force the appropriate accessibility checks.
388 -- Ada 2005 (AI-231): Generate conversion to the null-excluding type to
389 -- force the corresponding run-time check
391 if Is_Access_Type
(Check_Typ
)
392 and then Is_Local_Anonymous_Access
(Check_Typ
)
394 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
395 Analyze_And_Resolve
(Exp
, Check_Typ
);
396 Check_Unset_Reference
(Exp
);
399 -- What follows is really expansion activity, so check that expansion
400 -- is on and is allowed. In GNATprove mode, we also want check flags to
401 -- be added in the tree, so that the formal verification can rely on
402 -- those to be present. In GNATprove mode for formal verification, some
403 -- treatment typically only done during expansion needs to be performed
404 -- on the tree, but it should not be applied inside generics. Otherwise,
405 -- this breaks the name resolution mechanism for generic instances.
407 if not Expander_Active
408 and (Inside_A_Generic
or not Full_Analysis
or not GNATprove_Mode
)
413 if Is_Access_Type
(Check_Typ
)
414 and then Can_Never_Be_Null
(Check_Typ
)
415 and then not Can_Never_Be_Null
(Exp_Typ
)
417 Install_Null_Excluding_Check
(Exp
);
420 -- First check if we have to insert discriminant checks
422 if Has_Discriminants
(Exp_Typ
) then
423 Apply_Discriminant_Check
(Exp
, Check_Typ
);
425 -- Next emit length checks for array aggregates
427 elsif Is_Array_Type
(Exp_Typ
) then
428 Apply_Length_Check
(Exp
, Check_Typ
);
430 -- Finally emit scalar and string checks. If we are dealing with a
431 -- scalar literal we need to check by hand because the Etype of
432 -- literals is not necessarily correct.
434 elsif Is_Scalar_Type
(Exp_Typ
)
435 and then Compile_Time_Known_Value
(Exp
)
437 if Is_Out_Of_Range
(Exp
, Base_Type
(Check_Typ
)) then
438 Apply_Compile_Time_Constraint_Error
439 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
440 Ent
=> Base_Type
(Check_Typ
),
441 Typ
=> Base_Type
(Check_Typ
));
443 elsif Is_Out_Of_Range
(Exp
, Check_Typ
) then
444 Apply_Compile_Time_Constraint_Error
445 (Exp
, "value not in range of}??", CE_Range_Check_Failed
,
449 elsif not Range_Checks_Suppressed
(Check_Typ
) then
450 Apply_Scalar_Range_Check
(Exp
, Check_Typ
);
453 -- Verify that target type is also scalar, to prevent view anomalies
454 -- in instantiations.
456 elsif (Is_Scalar_Type
(Exp_Typ
)
457 or else Nkind
(Exp
) = N_String_Literal
)
458 and then Is_Scalar_Type
(Check_Typ
)
459 and then Exp_Typ
/= Check_Typ
461 if Is_Entity_Name
(Exp
)
462 and then Ekind
(Entity
(Exp
)) = E_Constant
464 -- If expression is a constant, it is worthwhile checking whether
465 -- it is a bound of the type.
467 if (Is_Entity_Name
(Type_Low_Bound
(Check_Typ
))
468 and then Entity
(Exp
) = Entity
(Type_Low_Bound
(Check_Typ
)))
470 (Is_Entity_Name
(Type_High_Bound
(Check_Typ
))
471 and then Entity
(Exp
) = Entity
(Type_High_Bound
(Check_Typ
)))
476 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
477 Analyze_And_Resolve
(Exp
, Check_Typ
);
478 Check_Unset_Reference
(Exp
);
481 -- Could use a comment on this case ???
484 Rewrite
(Exp
, Convert_To
(Check_Typ
, Relocate_Node
(Exp
)));
485 Analyze_And_Resolve
(Exp
, Check_Typ
);
486 Check_Unset_Reference
(Exp
);
490 end Aggregate_Constraint_Checks
;
492 -----------------------
493 -- Alignment_In_Bits --
494 -----------------------
496 function Alignment_In_Bits
(E
: Entity_Id
) return Uint
is
498 return Alignment
(E
) * System_Storage_Unit
;
499 end Alignment_In_Bits
;
501 --------------------------------------
502 -- All_Composite_Constraints_Static --
503 --------------------------------------
505 function All_Composite_Constraints_Static
506 (Constr
: Node_Id
) return Boolean
509 if No
(Constr
) or else Error_Posted
(Constr
) then
513 case Nkind
(Constr
) is
515 if Nkind
(Constr
) in N_Has_Entity
516 and then Present
(Entity
(Constr
))
518 if Is_Type
(Entity
(Constr
)) then
520 not Is_Discrete_Type
(Entity
(Constr
))
521 or else Is_OK_Static_Subtype
(Entity
(Constr
));
524 elsif Nkind
(Constr
) = N_Range
then
526 Is_OK_Static_Expression
(Low_Bound
(Constr
))
528 Is_OK_Static_Expression
(High_Bound
(Constr
));
530 elsif Nkind
(Constr
) = N_Attribute_Reference
531 and then Attribute_Name
(Constr
) = Name_Range
534 Is_OK_Static_Expression
535 (Type_Low_Bound
(Etype
(Prefix
(Constr
))))
537 Is_OK_Static_Expression
538 (Type_High_Bound
(Etype
(Prefix
(Constr
))));
542 not Present
(Etype
(Constr
)) -- previous error
543 or else not Is_Discrete_Type
(Etype
(Constr
))
544 or else Is_OK_Static_Expression
(Constr
);
546 when N_Discriminant_Association
=>
547 return All_Composite_Constraints_Static
(Expression
(Constr
));
549 when N_Range_Constraint
=>
551 All_Composite_Constraints_Static
(Range_Expression
(Constr
));
553 when N_Index_Or_Discriminant_Constraint
=>
555 One_Cstr
: Entity_Id
;
557 One_Cstr
:= First
(Constraints
(Constr
));
558 while Present
(One_Cstr
) loop
559 if not All_Composite_Constraints_Static
(One_Cstr
) then
569 when N_Subtype_Indication
=>
571 All_Composite_Constraints_Static
(Subtype_Mark
(Constr
))
573 All_Composite_Constraints_Static
(Constraint
(Constr
));
578 end All_Composite_Constraints_Static
;
580 ------------------------
581 -- Append_Entity_Name --
582 ------------------------
584 procedure Append_Entity_Name
(Buf
: in out Bounded_String
; E
: Entity_Id
) is
585 Temp
: Bounded_String
;
587 procedure Inner
(E
: Entity_Id
);
588 -- Inner recursive routine, keep outer routine nonrecursive to ease
589 -- debugging when we get strange results from this routine.
595 procedure Inner
(E
: Entity_Id
) is
597 -- If entity has an internal name, skip by it, and print its scope.
598 -- Note that we strip a final R from the name before the test; this
599 -- is needed for some cases of instantiations.
602 E_Name
: Bounded_String
;
605 Append
(E_Name
, Chars
(E
));
607 if E_Name
.Chars
(E_Name
.Length
) = 'R' then
608 E_Name
.Length
:= E_Name
.Length
- 1;
611 if Is_Internal_Name
(E_Name
) then
617 -- Just print entity name if its scope is at the outer level
619 if Scope
(E
) = Standard_Standard
then
622 -- If scope comes from source, write scope and entity
624 elsif Comes_From_Source
(Scope
(E
)) then
625 Append_Entity_Name
(Temp
, Scope
(E
));
628 -- If in wrapper package skip past it
630 elsif Is_Wrapper_Package
(Scope
(E
)) then
631 Append_Entity_Name
(Temp
, Scope
(Scope
(E
)));
634 -- Otherwise nothing to output (happens in unnamed block statements)
643 E_Name
: Bounded_String
;
646 Append_Unqualified_Decoded
(E_Name
, Chars
(E
));
648 -- Remove trailing upper-case letters from the name (useful for
649 -- dealing with some cases of internal names generated in the case
650 -- of references from within a generic).
652 while E_Name
.Length
> 1
653 and then E_Name
.Chars
(E_Name
.Length
) in 'A' .. 'Z'
655 E_Name
.Length
:= E_Name
.Length
- 1;
658 -- Adjust casing appropriately (gets name from source if possible)
660 Adjust_Name_Case
(E_Name
, Sloc
(E
));
661 Append
(Temp
, E_Name
);
665 -- Start of processing for Append_Entity_Name
670 end Append_Entity_Name
;
672 ---------------------------------
673 -- Append_Inherited_Subprogram --
674 ---------------------------------
676 procedure Append_Inherited_Subprogram
(S
: Entity_Id
) is
677 Par
: constant Entity_Id
:= Alias
(S
);
678 -- The parent subprogram
680 Scop
: constant Entity_Id
:= Scope
(Par
);
681 -- The scope of definition of the parent subprogram
683 Typ
: constant Entity_Id
:= Defining_Entity
(Parent
(S
));
684 -- The derived type of which S is a primitive operation
690 if Ekind
(Current_Scope
) = E_Package
691 and then In_Private_Part
(Current_Scope
)
692 and then Has_Private_Declaration
(Typ
)
693 and then Is_Tagged_Type
(Typ
)
694 and then Scop
= Current_Scope
696 -- The inherited operation is available at the earliest place after
697 -- the derived type declaration ( RM 7.3.1 (6/1)). This is only
698 -- relevant for type extensions. If the parent operation appears
699 -- after the type extension, the operation is not visible.
702 (Visible_Declarations
703 (Package_Specification
(Current_Scope
)));
704 while Present
(Decl
) loop
705 if Nkind
(Decl
) = N_Private_Extension_Declaration
706 and then Defining_Entity
(Decl
) = Typ
708 if Sloc
(Decl
) > Sloc
(Par
) then
709 Next_E
:= Next_Entity
(Par
);
710 Set_Next_Entity
(Par
, S
);
711 Set_Next_Entity
(S
, Next_E
);
723 -- If partial view is not a type extension, or it appears before the
724 -- subprogram declaration, insert normally at end of entity list.
726 Append_Entity
(S
, Current_Scope
);
727 end Append_Inherited_Subprogram
;
729 -----------------------------------------
730 -- Apply_Compile_Time_Constraint_Error --
731 -----------------------------------------
733 procedure Apply_Compile_Time_Constraint_Error
736 Reason
: RT_Exception_Code
;
737 Ent
: Entity_Id
:= Empty
;
738 Typ
: Entity_Id
:= Empty
;
739 Loc
: Source_Ptr
:= No_Location
;
740 Rep
: Boolean := True;
741 Warn
: Boolean := False)
743 Stat
: constant Boolean := Is_Static_Expression
(N
);
744 R_Stat
: constant Node_Id
:=
745 Make_Raise_Constraint_Error
(Sloc
(N
), Reason
=> Reason
);
756 (Compile_Time_Constraint_Error
(N
, Msg
, Ent
, Loc
, Warn
=> Warn
));
758 -- In GNATprove mode, do not replace the node with an exception raised.
759 -- In such a case, either the call to Compile_Time_Constraint_Error
760 -- issues an error which stops analysis, or it issues a warning in
761 -- a few cases where a suitable check flag is set for GNATprove to
762 -- generate a check message.
764 if not Rep
or GNATprove_Mode
then
768 -- Now we replace the node by an N_Raise_Constraint_Error node
769 -- This does not need reanalyzing, so set it as analyzed now.
772 Set_Analyzed
(N
, True);
775 Set_Raises_Constraint_Error
(N
);
777 -- Now deal with possible local raise handling
779 Possible_Local_Raise
(N
, Standard_Constraint_Error
);
781 -- If the original expression was marked as static, the result is
782 -- still marked as static, but the Raises_Constraint_Error flag is
783 -- always set so that further static evaluation is not attempted.
786 Set_Is_Static_Expression
(N
);
788 end Apply_Compile_Time_Constraint_Error
;
790 ---------------------------
791 -- Async_Readers_Enabled --
792 ---------------------------
794 function Async_Readers_Enabled
(Id
: Entity_Id
) return Boolean is
796 return Has_Enabled_Property
(Id
, Name_Async_Readers
);
797 end Async_Readers_Enabled
;
799 ---------------------------
800 -- Async_Writers_Enabled --
801 ---------------------------
803 function Async_Writers_Enabled
(Id
: Entity_Id
) return Boolean is
805 return Has_Enabled_Property
(Id
, Name_Async_Writers
);
806 end Async_Writers_Enabled
;
808 --------------------------------------
809 -- Available_Full_View_Of_Component --
810 --------------------------------------
812 function Available_Full_View_Of_Component
(T
: Entity_Id
) return Boolean is
813 ST
: constant Entity_Id
:= Scope
(T
);
814 SCT
: constant Entity_Id
:= Scope
(Component_Type
(T
));
816 return In_Open_Scopes
(ST
)
817 and then In_Open_Scopes
(SCT
)
818 and then Scope_Depth
(ST
) >= Scope_Depth
(SCT
);
819 end Available_Full_View_Of_Component
;
825 procedure Bad_Attribute
828 Warn
: Boolean := False)
831 Error_Msg_Warn
:= Warn
;
832 Error_Msg_N
("unrecognized attribute&<<", N
);
834 -- Check for possible misspelling
836 Error_Msg_Name_1
:= First_Attribute_Name
;
837 while Error_Msg_Name_1
<= Last_Attribute_Name
loop
838 if Is_Bad_Spelling_Of
(Nam
, Error_Msg_Name_1
) then
839 Error_Msg_N
-- CODEFIX
840 ("\possible misspelling of %<<", N
);
844 Error_Msg_Name_1
:= Error_Msg_Name_1
+ 1;
848 --------------------------------
849 -- Bad_Predicated_Subtype_Use --
850 --------------------------------
852 procedure Bad_Predicated_Subtype_Use
856 Suggest_Static
: Boolean := False)
861 -- Avoid cascaded errors
863 if Error_Posted
(N
) then
867 if Inside_A_Generic
then
868 Gen
:= Current_Scope
;
869 while Present
(Gen
) and then Ekind
(Gen
) /= E_Generic_Package
loop
877 if Is_Generic_Formal
(Typ
) and then Is_Discrete_Type
(Typ
) then
878 Set_No_Predicate_On_Actual
(Typ
);
881 elsif Has_Predicates
(Typ
) then
882 if Is_Generic_Actual_Type
(Typ
) then
884 -- The restriction on loop parameters is only that the type
885 -- should have no dynamic predicates.
887 if Nkind
(Parent
(N
)) = N_Loop_Parameter_Specification
888 and then not Has_Dynamic_Predicate_Aspect
(Typ
)
889 and then Is_OK_Static_Subtype
(Typ
)
894 Gen
:= Current_Scope
;
895 while not Is_Generic_Instance
(Gen
) loop
899 pragma Assert
(Present
(Gen
));
901 if Ekind
(Gen
) = E_Package
and then In_Package_Body
(Gen
) then
902 Error_Msg_Warn
:= SPARK_Mode
/= On
;
903 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
904 Error_Msg_F
("\Program_Error [<<", N
);
907 Make_Raise_Program_Error
(Sloc
(N
),
908 Reason
=> PE_Bad_Predicated_Generic_Type
));
911 Error_Msg_FE
(Msg
& "<<", N
, Typ
);
915 Error_Msg_FE
(Msg
, N
, Typ
);
918 -- Emit an optional suggestion on how to remedy the error if the
919 -- context warrants it.
921 if Suggest_Static
and then Has_Static_Predicate
(Typ
) then
922 Error_Msg_FE
("\predicate of & should be marked static", N
, Typ
);
925 end Bad_Predicated_Subtype_Use
;
927 -----------------------------------------
928 -- Bad_Unordered_Enumeration_Reference --
929 -----------------------------------------
931 function Bad_Unordered_Enumeration_Reference
933 T
: Entity_Id
) return Boolean
936 return Is_Enumeration_Type
(T
)
937 and then Warn_On_Unordered_Enumeration_Type
938 and then not Is_Generic_Type
(T
)
939 and then Comes_From_Source
(N
)
940 and then not Has_Pragma_Ordered
(T
)
941 and then not In_Same_Extended_Unit
(N
, T
);
942 end Bad_Unordered_Enumeration_Reference
;
944 --------------------------
945 -- Build_Actual_Subtype --
946 --------------------------
948 function Build_Actual_Subtype
950 N
: Node_Or_Entity_Id
) return Node_Id
953 -- Normally Sloc (N), but may point to corresponding body in some cases
955 Constraints
: List_Id
;
961 Disc_Type
: Entity_Id
;
967 if Nkind
(N
) = N_Defining_Identifier
then
968 Obj
:= New_Occurrence_Of
(N
, Loc
);
970 -- If this is a formal parameter of a subprogram declaration, and
971 -- we are compiling the body, we want the declaration for the
972 -- actual subtype to carry the source position of the body, to
973 -- prevent anomalies in gdb when stepping through the code.
975 if Is_Formal
(N
) then
977 Decl
: constant Node_Id
:= Unit_Declaration_Node
(Scope
(N
));
979 if Nkind
(Decl
) = N_Subprogram_Declaration
980 and then Present
(Corresponding_Body
(Decl
))
982 Loc
:= Sloc
(Corresponding_Body
(Decl
));
991 if Is_Array_Type
(T
) then
992 Constraints
:= New_List
;
993 for J
in 1 .. Number_Dimensions
(T
) loop
995 -- Build an array subtype declaration with the nominal subtype and
996 -- the bounds of the actual. Add the declaration in front of the
997 -- local declarations for the subprogram, for analysis before any
998 -- reference to the formal in the body.
1001 Make_Attribute_Reference
(Loc
,
1003 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
1004 Attribute_Name
=> Name_First
,
1005 Expressions
=> New_List
(
1006 Make_Integer_Literal
(Loc
, J
)));
1009 Make_Attribute_Reference
(Loc
,
1011 Duplicate_Subexpr_No_Checks
(Obj
, Name_Req
=> True),
1012 Attribute_Name
=> Name_Last
,
1013 Expressions
=> New_List
(
1014 Make_Integer_Literal
(Loc
, J
)));
1016 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1019 -- If the type has unknown discriminants there is no constrained
1020 -- subtype to build. This is never called for a formal or for a
1021 -- lhs, so returning the type is ok ???
1023 elsif Has_Unknown_Discriminants
(T
) then
1027 Constraints
:= New_List
;
1029 -- Type T is a generic derived type, inherit the discriminants from
1032 if Is_Private_Type
(T
)
1033 and then No
(Full_View
(T
))
1035 -- T was flagged as an error if it was declared as a formal
1036 -- derived type with known discriminants. In this case there
1037 -- is no need to look at the parent type since T already carries
1038 -- its own discriminants.
1040 and then not Error_Posted
(T
)
1042 Disc_Type
:= Etype
(Base_Type
(T
));
1047 Discr
:= First_Discriminant
(Disc_Type
);
1048 while Present
(Discr
) loop
1049 Append_To
(Constraints
,
1050 Make_Selected_Component
(Loc
,
1052 Duplicate_Subexpr_No_Checks
(Obj
),
1053 Selector_Name
=> New_Occurrence_Of
(Discr
, Loc
)));
1054 Next_Discriminant
(Discr
);
1058 Subt
:= Make_Temporary
(Loc
, 'S', Related_Node
=> N
);
1059 Set_Is_Internal
(Subt
);
1062 Make_Subtype_Declaration
(Loc
,
1063 Defining_Identifier
=> Subt
,
1064 Subtype_Indication
=>
1065 Make_Subtype_Indication
(Loc
,
1066 Subtype_Mark
=> New_Occurrence_Of
(T
, Loc
),
1068 Make_Index_Or_Discriminant_Constraint
(Loc
,
1069 Constraints
=> Constraints
)));
1071 Mark_Rewrite_Insertion
(Decl
);
1073 end Build_Actual_Subtype
;
1075 ---------------------------------------
1076 -- Build_Actual_Subtype_Of_Component --
1077 ---------------------------------------
1079 function Build_Actual_Subtype_Of_Component
1081 N
: Node_Id
) return Node_Id
1083 Loc
: constant Source_Ptr
:= Sloc
(N
);
1084 P
: constant Node_Id
:= Prefix
(N
);
1087 Index_Typ
: Entity_Id
;
1089 Desig_Typ
: Entity_Id
;
1090 -- This is either a copy of T, or if T is an access type, then it is
1091 -- the directly designated type of this access type.
1093 function Build_Actual_Array_Constraint
return List_Id
;
1094 -- If one or more of the bounds of the component depends on
1095 -- discriminants, build actual constraint using the discriminants
1098 function Build_Actual_Record_Constraint
return List_Id
;
1099 -- Similar to previous one, for discriminated components constrained
1100 -- by the discriminant of the enclosing object.
1102 -----------------------------------
1103 -- Build_Actual_Array_Constraint --
1104 -----------------------------------
1106 function Build_Actual_Array_Constraint
return List_Id
is
1107 Constraints
: constant List_Id
:= New_List
;
1115 Indx
:= First_Index
(Desig_Typ
);
1116 while Present
(Indx
) loop
1117 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1118 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1120 if Denotes_Discriminant
(Old_Lo
) then
1122 Make_Selected_Component
(Loc
,
1123 Prefix
=> New_Copy_Tree
(P
),
1124 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Lo
), Loc
));
1127 Lo
:= New_Copy_Tree
(Old_Lo
);
1129 -- The new bound will be reanalyzed in the enclosing
1130 -- declaration. For literal bounds that come from a type
1131 -- declaration, the type of the context must be imposed, so
1132 -- insure that analysis will take place. For non-universal
1133 -- types this is not strictly necessary.
1135 Set_Analyzed
(Lo
, False);
1138 if Denotes_Discriminant
(Old_Hi
) then
1140 Make_Selected_Component
(Loc
,
1141 Prefix
=> New_Copy_Tree
(P
),
1142 Selector_Name
=> New_Occurrence_Of
(Entity
(Old_Hi
), Loc
));
1145 Hi
:= New_Copy_Tree
(Old_Hi
);
1146 Set_Analyzed
(Hi
, False);
1149 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1154 end Build_Actual_Array_Constraint
;
1156 ------------------------------------
1157 -- Build_Actual_Record_Constraint --
1158 ------------------------------------
1160 function Build_Actual_Record_Constraint
return List_Id
is
1161 Constraints
: constant List_Id
:= New_List
;
1166 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1167 while Present
(D
) loop
1168 if Denotes_Discriminant
(Node
(D
)) then
1169 D_Val
:= Make_Selected_Component
(Loc
,
1170 Prefix
=> New_Copy_Tree
(P
),
1171 Selector_Name
=> New_Occurrence_Of
(Entity
(Node
(D
)), Loc
));
1174 D_Val
:= New_Copy_Tree
(Node
(D
));
1177 Append
(D_Val
, Constraints
);
1182 end Build_Actual_Record_Constraint
;
1184 -- Start of processing for Build_Actual_Subtype_Of_Component
1187 -- Why the test for Spec_Expression mode here???
1189 if In_Spec_Expression
then
1192 -- More comments for the rest of this body would be good ???
1194 elsif Nkind
(N
) = N_Explicit_Dereference
then
1195 if Is_Composite_Type
(T
)
1196 and then not Is_Constrained
(T
)
1197 and then not (Is_Class_Wide_Type
(T
)
1198 and then Is_Constrained
(Root_Type
(T
)))
1199 and then not Has_Unknown_Discriminants
(T
)
1201 -- If the type of the dereference is already constrained, it is an
1204 if Is_Array_Type
(Etype
(N
))
1205 and then Is_Constrained
(Etype
(N
))
1209 Remove_Side_Effects
(P
);
1210 return Build_Actual_Subtype
(T
, N
);
1217 if Ekind
(T
) = E_Access_Subtype
then
1218 Desig_Typ
:= Designated_Type
(T
);
1223 if Ekind
(Desig_Typ
) = E_Array_Subtype
then
1224 Id
:= First_Index
(Desig_Typ
);
1225 while Present
(Id
) loop
1226 Index_Typ
:= Underlying_Type
(Etype
(Id
));
1228 if Denotes_Discriminant
(Type_Low_Bound
(Index_Typ
))
1230 Denotes_Discriminant
(Type_High_Bound
(Index_Typ
))
1232 Remove_Side_Effects
(P
);
1234 Build_Component_Subtype
1235 (Build_Actual_Array_Constraint
, Loc
, Base_Type
(T
));
1241 elsif Is_Composite_Type
(Desig_Typ
)
1242 and then Has_Discriminants
(Desig_Typ
)
1243 and then not Has_Unknown_Discriminants
(Desig_Typ
)
1245 if Is_Private_Type
(Desig_Typ
)
1246 and then No
(Discriminant_Constraint
(Desig_Typ
))
1248 Desig_Typ
:= Full_View
(Desig_Typ
);
1251 D
:= First_Elmt
(Discriminant_Constraint
(Desig_Typ
));
1252 while Present
(D
) loop
1253 if Denotes_Discriminant
(Node
(D
)) then
1254 Remove_Side_Effects
(P
);
1256 Build_Component_Subtype
(
1257 Build_Actual_Record_Constraint
, Loc
, Base_Type
(T
));
1264 -- If none of the above, the actual and nominal subtypes are the same
1267 end Build_Actual_Subtype_Of_Component
;
1269 ---------------------------------
1270 -- Build_Class_Wide_Clone_Body --
1271 ---------------------------------
1273 procedure Build_Class_Wide_Clone_Body
1274 (Spec_Id
: Entity_Id
;
1277 Loc
: constant Source_Ptr
:= Sloc
(Bod
);
1278 Clone_Id
: constant Entity_Id
:= Class_Wide_Clone
(Spec_Id
);
1279 Clone_Body
: Node_Id
;
1282 -- The declaration of the class-wide clone was created when the
1283 -- corresponding class-wide condition was analyzed.
1286 Make_Subprogram_Body
(Loc
,
1288 Copy_Subprogram_Spec
(Parent
(Clone_Id
)),
1289 Declarations
=> Declarations
(Bod
),
1290 Handled_Statement_Sequence
=> Handled_Statement_Sequence
(Bod
));
1292 -- The new operation is internal and overriding indicators do not apply
1293 -- (the original primitive may have carried one).
1295 Set_Must_Override
(Specification
(Clone_Body
), False);
1296 Insert_Before
(Bod
, Clone_Body
);
1297 Analyze
(Clone_Body
);
1298 end Build_Class_Wide_Clone_Body
;
1300 ---------------------------------
1301 -- Build_Class_Wide_Clone_Call --
1302 ---------------------------------
1304 function Build_Class_Wide_Clone_Call
1307 Spec_Id
: Entity_Id
;
1308 Spec
: Node_Id
) return Node_Id
1310 Clone_Id
: constant Entity_Id
:= Class_Wide_Clone
(Spec_Id
);
1311 Par_Type
: constant Entity_Id
:= Find_Dispatching_Type
(Spec_Id
);
1317 New_F_Spec
: Entity_Id
;
1318 New_Formal
: Entity_Id
;
1321 Actuals
:= Empty_List
;
1322 Formal
:= First_Formal
(Spec_Id
);
1323 New_F_Spec
:= First
(Parameter_Specifications
(Spec
));
1325 -- Build parameter association for call to class-wide clone.
1327 while Present
(Formal
) loop
1328 New_Formal
:= Defining_Identifier
(New_F_Spec
);
1330 -- If controlling argument and operation is inherited, add conversion
1331 -- to parent type for the call.
1333 if Etype
(Formal
) = Par_Type
1334 and then not Is_Empty_List
(Decls
)
1337 Make_Type_Conversion
(Loc
,
1338 New_Occurrence_Of
(Par_Type
, Loc
),
1339 New_Occurrence_Of
(New_Formal
, Loc
)));
1342 Append_To
(Actuals
, New_Occurrence_Of
(New_Formal
, Loc
));
1345 Next_Formal
(Formal
);
1349 if Ekind
(Spec_Id
) = E_Procedure
then
1351 Make_Procedure_Call_Statement
(Loc
,
1352 Name
=> New_Occurrence_Of
(Clone_Id
, Loc
),
1353 Parameter_Associations
=> Actuals
);
1356 Make_Simple_Return_Statement
(Loc
,
1358 Make_Function_Call
(Loc
,
1359 Name
=> New_Occurrence_Of
(Clone_Id
, Loc
),
1360 Parameter_Associations
=> Actuals
));
1364 Make_Subprogram_Body
(Loc
,
1366 Copy_Subprogram_Spec
(Spec
),
1367 Declarations
=> Decls
,
1368 Handled_Statement_Sequence
=>
1369 Make_Handled_Sequence_Of_Statements
(Loc
,
1370 Statements
=> New_List
(Call
),
1371 End_Label
=> Make_Identifier
(Loc
, Chars
(Spec_Id
))));
1374 end Build_Class_Wide_Clone_Call
;
1376 ---------------------------------
1377 -- Build_Class_Wide_Clone_Decl --
1378 ---------------------------------
1380 procedure Build_Class_Wide_Clone_Decl
(Spec_Id
: Entity_Id
) is
1381 Loc
: constant Source_Ptr
:= Sloc
(Spec_Id
);
1382 Clone_Id
: constant Entity_Id
:=
1383 Make_Defining_Identifier
(Loc
,
1384 New_External_Name
(Chars
(Spec_Id
), Suffix
=> "CL"));
1390 Spec
:= Copy_Subprogram_Spec
(Parent
(Spec_Id
));
1391 Set_Must_Override
(Spec
, False);
1392 Set_Must_Not_Override
(Spec
, False);
1393 Set_Defining_Unit_Name
(Spec
, Clone_Id
);
1395 Decl
:= Make_Subprogram_Declaration
(Loc
, Spec
);
1396 Append
(Decl
, List_Containing
(Unit_Declaration_Node
(Spec_Id
)));
1398 -- Link clone to original subprogram, for use when building body and
1399 -- wrapper call to inherited operation.
1401 Set_Class_Wide_Clone
(Spec_Id
, Clone_Id
);
1402 end Build_Class_Wide_Clone_Decl
;
1404 -----------------------------
1405 -- Build_Component_Subtype --
1406 -----------------------------
1408 function Build_Component_Subtype
1411 T
: Entity_Id
) return Node_Id
1417 -- Unchecked_Union components do not require component subtypes
1419 if Is_Unchecked_Union
(T
) then
1423 Subt
:= Make_Temporary
(Loc
, 'S');
1424 Set_Is_Internal
(Subt
);
1427 Make_Subtype_Declaration
(Loc
,
1428 Defining_Identifier
=> Subt
,
1429 Subtype_Indication
=>
1430 Make_Subtype_Indication
(Loc
,
1431 Subtype_Mark
=> New_Occurrence_Of
(Base_Type
(T
), Loc
),
1433 Make_Index_Or_Discriminant_Constraint
(Loc
,
1434 Constraints
=> C
)));
1436 Mark_Rewrite_Insertion
(Decl
);
1438 end Build_Component_Subtype
;
1440 ---------------------------
1441 -- Build_Default_Subtype --
1442 ---------------------------
1444 function Build_Default_Subtype
1446 N
: Node_Id
) return Entity_Id
1448 Loc
: constant Source_Ptr
:= Sloc
(N
);
1452 -- The base type that is to be constrained by the defaults
1455 if not Has_Discriminants
(T
) or else Is_Constrained
(T
) then
1459 Bas
:= Base_Type
(T
);
1461 -- If T is non-private but its base type is private, this is the
1462 -- completion of a subtype declaration whose parent type is private
1463 -- (see Complete_Private_Subtype in Sem_Ch3). The proper discriminants
1464 -- are to be found in the full view of the base. Check that the private
1465 -- status of T and its base differ.
1467 if Is_Private_Type
(Bas
)
1468 and then not Is_Private_Type
(T
)
1469 and then Present
(Full_View
(Bas
))
1471 Bas
:= Full_View
(Bas
);
1474 Disc
:= First_Discriminant
(T
);
1476 if No
(Discriminant_Default_Value
(Disc
)) then
1481 Act
: constant Entity_Id
:= Make_Temporary
(Loc
, 'S');
1482 Constraints
: constant List_Id
:= New_List
;
1486 while Present
(Disc
) loop
1487 Append_To
(Constraints
,
1488 New_Copy_Tree
(Discriminant_Default_Value
(Disc
)));
1489 Next_Discriminant
(Disc
);
1493 Make_Subtype_Declaration
(Loc
,
1494 Defining_Identifier
=> Act
,
1495 Subtype_Indication
=>
1496 Make_Subtype_Indication
(Loc
,
1497 Subtype_Mark
=> New_Occurrence_Of
(Bas
, Loc
),
1499 Make_Index_Or_Discriminant_Constraint
(Loc
,
1500 Constraints
=> Constraints
)));
1502 Insert_Action
(N
, Decl
);
1504 -- If the context is a component declaration the subtype declaration
1505 -- will be analyzed when the enclosing type is frozen, otherwise do
1508 if Ekind
(Current_Scope
) /= E_Record_Type
then
1514 end Build_Default_Subtype
;
1516 --------------------------------------------
1517 -- Build_Discriminal_Subtype_Of_Component --
1518 --------------------------------------------
1520 function Build_Discriminal_Subtype_Of_Component
1521 (T
: Entity_Id
) return Node_Id
1523 Loc
: constant Source_Ptr
:= Sloc
(T
);
1527 function Build_Discriminal_Array_Constraint
return List_Id
;
1528 -- If one or more of the bounds of the component depends on
1529 -- discriminants, build actual constraint using the discriminants
1532 function Build_Discriminal_Record_Constraint
return List_Id
;
1533 -- Similar to previous one, for discriminated components constrained by
1534 -- the discriminant of the enclosing object.
1536 ----------------------------------------
1537 -- Build_Discriminal_Array_Constraint --
1538 ----------------------------------------
1540 function Build_Discriminal_Array_Constraint
return List_Id
is
1541 Constraints
: constant List_Id
:= New_List
;
1549 Indx
:= First_Index
(T
);
1550 while Present
(Indx
) loop
1551 Old_Lo
:= Type_Low_Bound
(Etype
(Indx
));
1552 Old_Hi
:= Type_High_Bound
(Etype
(Indx
));
1554 if Denotes_Discriminant
(Old_Lo
) then
1555 Lo
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Lo
)), Loc
);
1558 Lo
:= New_Copy_Tree
(Old_Lo
);
1561 if Denotes_Discriminant
(Old_Hi
) then
1562 Hi
:= New_Occurrence_Of
(Discriminal
(Entity
(Old_Hi
)), Loc
);
1565 Hi
:= New_Copy_Tree
(Old_Hi
);
1568 Append
(Make_Range
(Loc
, Lo
, Hi
), Constraints
);
1573 end Build_Discriminal_Array_Constraint
;
1575 -----------------------------------------
1576 -- Build_Discriminal_Record_Constraint --
1577 -----------------------------------------
1579 function Build_Discriminal_Record_Constraint
return List_Id
is
1580 Constraints
: constant List_Id
:= New_List
;
1585 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1586 while Present
(D
) loop
1587 if Denotes_Discriminant
(Node
(D
)) then
1589 New_Occurrence_Of
(Discriminal
(Entity
(Node
(D
))), Loc
);
1591 D_Val
:= New_Copy_Tree
(Node
(D
));
1594 Append
(D_Val
, Constraints
);
1599 end Build_Discriminal_Record_Constraint
;
1601 -- Start of processing for Build_Discriminal_Subtype_Of_Component
1604 if Ekind
(T
) = E_Array_Subtype
then
1605 Id
:= First_Index
(T
);
1606 while Present
(Id
) loop
1607 if Denotes_Discriminant
(Type_Low_Bound
(Etype
(Id
)))
1609 Denotes_Discriminant
(Type_High_Bound
(Etype
(Id
)))
1611 return Build_Component_Subtype
1612 (Build_Discriminal_Array_Constraint
, Loc
, T
);
1618 elsif Ekind
(T
) = E_Record_Subtype
1619 and then Has_Discriminants
(T
)
1620 and then not Has_Unknown_Discriminants
(T
)
1622 D
:= First_Elmt
(Discriminant_Constraint
(T
));
1623 while Present
(D
) loop
1624 if Denotes_Discriminant
(Node
(D
)) then
1625 return Build_Component_Subtype
1626 (Build_Discriminal_Record_Constraint
, Loc
, T
);
1633 -- If none of the above, the actual and nominal subtypes are the same
1636 end Build_Discriminal_Subtype_Of_Component
;
1638 ------------------------------
1639 -- Build_Elaboration_Entity --
1640 ------------------------------
1642 procedure Build_Elaboration_Entity
(N
: Node_Id
; Spec_Id
: Entity_Id
) is
1643 Loc
: constant Source_Ptr
:= Sloc
(N
);
1645 Elab_Ent
: Entity_Id
;
1647 procedure Set_Package_Name
(Ent
: Entity_Id
);
1648 -- Given an entity, sets the fully qualified name of the entity in
1649 -- Name_Buffer, with components separated by double underscores. This
1650 -- is a recursive routine that climbs the scope chain to Standard.
1652 ----------------------
1653 -- Set_Package_Name --
1654 ----------------------
1656 procedure Set_Package_Name
(Ent
: Entity_Id
) is
1658 if Scope
(Ent
) /= Standard_Standard
then
1659 Set_Package_Name
(Scope
(Ent
));
1662 Nam
: constant String := Get_Name_String
(Chars
(Ent
));
1664 Name_Buffer
(Name_Len
+ 1) := '_';
1665 Name_Buffer
(Name_Len
+ 2) := '_';
1666 Name_Buffer
(Name_Len
+ 3 .. Name_Len
+ Nam
'Length + 2) := Nam
;
1667 Name_Len
:= Name_Len
+ Nam
'Length + 2;
1671 Get_Name_String
(Chars
(Ent
));
1673 end Set_Package_Name
;
1675 -- Start of processing for Build_Elaboration_Entity
1678 -- Ignore call if already constructed
1680 if Present
(Elaboration_Entity
(Spec_Id
)) then
1683 -- Ignore in ASIS mode, elaboration entity is not in source and plays
1684 -- no role in analysis.
1686 elsif ASIS_Mode
then
1689 -- Do not generate an elaboration entity in GNATprove move because the
1690 -- elaboration counter is a form of expansion.
1692 elsif GNATprove_Mode
then
1695 -- See if we need elaboration entity
1697 -- We always need an elaboration entity when preserving control flow, as
1698 -- we want to remain explicit about the unit's elaboration order.
1700 elsif Opt
.Suppress_Control_Flow_Optimizations
then
1703 -- We always need an elaboration entity for the dynamic elaboration
1704 -- model, since it is needed to properly generate the PE exception for
1705 -- access before elaboration.
1707 elsif Dynamic_Elaboration_Checks
then
1710 -- For the static model, we don't need the elaboration counter if this
1711 -- unit is sure to have no elaboration code, since that means there
1712 -- is no elaboration unit to be called. Note that we can't just decide
1713 -- after the fact by looking to see whether there was elaboration code,
1714 -- because that's too late to make this decision.
1716 elsif Restriction_Active
(No_Elaboration_Code
) then
1719 -- Similarly, for the static model, we can skip the elaboration counter
1720 -- if we have the No_Multiple_Elaboration restriction, since for the
1721 -- static model, that's the only purpose of the counter (to avoid
1722 -- multiple elaboration).
1724 elsif Restriction_Active
(No_Multiple_Elaboration
) then
1728 -- Here we need the elaboration entity
1730 -- Construct name of elaboration entity as xxx_E, where xxx is the unit
1731 -- name with dots replaced by double underscore. We have to manually
1732 -- construct this name, since it will be elaborated in the outer scope,
1733 -- and thus will not have the unit name automatically prepended.
1735 Set_Package_Name
(Spec_Id
);
1736 Add_Str_To_Name_Buffer
("_E");
1738 -- Create elaboration counter
1740 Elab_Ent
:= Make_Defining_Identifier
(Loc
, Chars
=> Name_Find
);
1741 Set_Elaboration_Entity
(Spec_Id
, Elab_Ent
);
1744 Make_Object_Declaration
(Loc
,
1745 Defining_Identifier
=> Elab_Ent
,
1746 Object_Definition
=>
1747 New_Occurrence_Of
(Standard_Short_Integer
, Loc
),
1748 Expression
=> Make_Integer_Literal
(Loc
, Uint_0
));
1750 Push_Scope
(Standard_Standard
);
1751 Add_Global_Declaration
(Decl
);
1754 -- Reset True_Constant indication, since we will indeed assign a value
1755 -- to the variable in the binder main. We also kill the Current_Value
1756 -- and Last_Assignment fields for the same reason.
1758 Set_Is_True_Constant
(Elab_Ent
, False);
1759 Set_Current_Value
(Elab_Ent
, Empty
);
1760 Set_Last_Assignment
(Elab_Ent
, Empty
);
1762 -- We do not want any further qualification of the name (if we did not
1763 -- do this, we would pick up the name of the generic package in the case
1764 -- of a library level generic instantiation).
1766 Set_Has_Qualified_Name
(Elab_Ent
);
1767 Set_Has_Fully_Qualified_Name
(Elab_Ent
);
1768 end Build_Elaboration_Entity
;
1770 --------------------------------
1771 -- Build_Explicit_Dereference --
1772 --------------------------------
1774 procedure Build_Explicit_Dereference
1778 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
1783 -- An entity of a type with a reference aspect is overloaded with
1784 -- both interpretations: with and without the dereference. Now that
1785 -- the dereference is made explicit, set the type of the node properly,
1786 -- to prevent anomalies in the backend. Same if the expression is an
1787 -- overloaded function call whose return type has a reference aspect.
1789 if Is_Entity_Name
(Expr
) then
1790 Set_Etype
(Expr
, Etype
(Entity
(Expr
)));
1792 -- The designated entity will not be examined again when resolving
1793 -- the dereference, so generate a reference to it now.
1795 Generate_Reference
(Entity
(Expr
), Expr
);
1797 elsif Nkind
(Expr
) = N_Function_Call
then
1799 -- If the name of the indexing function is overloaded, locate the one
1800 -- whose return type has an implicit dereference on the desired
1801 -- discriminant, and set entity and type of function call.
1803 if Is_Overloaded
(Name
(Expr
)) then
1804 Get_First_Interp
(Name
(Expr
), I
, It
);
1806 while Present
(It
.Nam
) loop
1807 if Ekind
((It
.Typ
)) = E_Record_Type
1808 and then First_Entity
((It
.Typ
)) = Disc
1810 Set_Entity
(Name
(Expr
), It
.Nam
);
1811 Set_Etype
(Name
(Expr
), Etype
(It
.Nam
));
1815 Get_Next_Interp
(I
, It
);
1819 -- Set type of call from resolved function name.
1821 Set_Etype
(Expr
, Etype
(Name
(Expr
)));
1824 Set_Is_Overloaded
(Expr
, False);
1826 -- The expression will often be a generalized indexing that yields a
1827 -- container element that is then dereferenced, in which case the
1828 -- generalized indexing call is also non-overloaded.
1830 if Nkind
(Expr
) = N_Indexed_Component
1831 and then Present
(Generalized_Indexing
(Expr
))
1833 Set_Is_Overloaded
(Generalized_Indexing
(Expr
), False);
1837 Make_Explicit_Dereference
(Loc
,
1839 Make_Selected_Component
(Loc
,
1840 Prefix
=> Relocate_Node
(Expr
),
1841 Selector_Name
=> New_Occurrence_Of
(Disc
, Loc
))));
1842 Set_Etype
(Prefix
(Expr
), Etype
(Disc
));
1843 Set_Etype
(Expr
, Designated_Type
(Etype
(Disc
)));
1844 end Build_Explicit_Dereference
;
1846 ---------------------------
1847 -- Build_Overriding_Spec --
1848 ---------------------------
1850 function Build_Overriding_Spec
1852 Typ
: Entity_Id
) return Node_Id
1854 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
1855 Par_Typ
: constant Entity_Id
:= Find_Dispatching_Type
(Op
);
1856 Spec
: constant Node_Id
:= Specification
(Unit_Declaration_Node
(Op
));
1858 Formal_Spec
: Node_Id
;
1859 Formal_Type
: Node_Id
;
1863 New_Spec
:= Copy_Subprogram_Spec
(Spec
);
1865 Formal_Spec
:= First
(Parameter_Specifications
(New_Spec
));
1866 while Present
(Formal_Spec
) loop
1867 Formal_Type
:= Parameter_Type
(Formal_Spec
);
1869 if Is_Entity_Name
(Formal_Type
)
1870 and then Entity
(Formal_Type
) = Par_Typ
1872 Rewrite
(Formal_Type
, New_Occurrence_Of
(Typ
, Loc
));
1875 -- Nothing needs to be done for access parameters
1881 end Build_Overriding_Spec
;
1883 -----------------------------------
1884 -- Cannot_Raise_Constraint_Error --
1885 -----------------------------------
1887 function Cannot_Raise_Constraint_Error
(Expr
: Node_Id
) return Boolean is
1889 if Compile_Time_Known_Value
(Expr
) then
1892 elsif Do_Range_Check
(Expr
) then
1895 elsif Raises_Constraint_Error
(Expr
) then
1899 case Nkind
(Expr
) is
1900 when N_Identifier
=>
1903 when N_Expanded_Name
=>
1906 when N_Selected_Component
=>
1907 return not Do_Discriminant_Check
(Expr
);
1909 when N_Attribute_Reference
=>
1910 if Do_Overflow_Check
(Expr
) then
1913 elsif No
(Expressions
(Expr
)) then
1921 N
:= First
(Expressions
(Expr
));
1922 while Present
(N
) loop
1923 if Cannot_Raise_Constraint_Error
(N
) then
1934 when N_Type_Conversion
=>
1935 if Do_Overflow_Check
(Expr
)
1936 or else Do_Length_Check
(Expr
)
1937 or else Do_Tag_Check
(Expr
)
1941 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1944 when N_Unchecked_Type_Conversion
=>
1945 return Cannot_Raise_Constraint_Error
(Expression
(Expr
));
1948 if Do_Overflow_Check
(Expr
) then
1951 return Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1958 if Do_Division_Check
(Expr
)
1960 Do_Overflow_Check
(Expr
)
1965 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1967 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
1986 | N_Op_Shift_Right_Arithmetic
1990 if Do_Overflow_Check
(Expr
) then
1994 Cannot_Raise_Constraint_Error
(Left_Opnd
(Expr
))
1996 Cannot_Raise_Constraint_Error
(Right_Opnd
(Expr
));
2003 end Cannot_Raise_Constraint_Error
;
2005 -----------------------------------------
2006 -- Check_Dynamically_Tagged_Expression --
2007 -----------------------------------------
2009 procedure Check_Dynamically_Tagged_Expression
2012 Related_Nod
: Node_Id
)
2015 pragma Assert
(Is_Tagged_Type
(Typ
));
2017 -- In order to avoid spurious errors when analyzing the expanded code,
2018 -- this check is done only for nodes that come from source and for
2019 -- actuals of generic instantiations.
2021 if (Comes_From_Source
(Related_Nod
)
2022 or else In_Generic_Actual
(Expr
))
2023 and then (Is_Class_Wide_Type
(Etype
(Expr
))
2024 or else Is_Dynamically_Tagged
(Expr
))
2025 and then Is_Tagged_Type
(Typ
)
2026 and then not Is_Class_Wide_Type
(Typ
)
2028 Error_Msg_N
("dynamically tagged expression not allowed!", Expr
);
2030 end Check_Dynamically_Tagged_Expression
;
2032 --------------------------
2033 -- Check_Fully_Declared --
2034 --------------------------
2036 procedure Check_Fully_Declared
(T
: Entity_Id
; N
: Node_Id
) is
2038 if Ekind
(T
) = E_Incomplete_Type
then
2040 -- Ada 2005 (AI-50217): If the type is available through a limited
2041 -- with_clause, verify that its full view has been analyzed.
2043 if From_Limited_With
(T
)
2044 and then Present
(Non_Limited_View
(T
))
2045 and then Ekind
(Non_Limited_View
(T
)) /= E_Incomplete_Type
2047 -- The non-limited view is fully declared
2053 ("premature usage of incomplete}", N
, First_Subtype
(T
));
2056 -- Need comments for these tests ???
2058 elsif Has_Private_Component
(T
)
2059 and then not Is_Generic_Type
(Root_Type
(T
))
2060 and then not In_Spec_Expression
2062 -- Special case: if T is the anonymous type created for a single
2063 -- task or protected object, use the name of the source object.
2065 if Is_Concurrent_Type
(T
)
2066 and then not Comes_From_Source
(T
)
2067 and then Nkind
(N
) = N_Object_Declaration
2070 ("type of& has incomplete component",
2071 N
, Defining_Identifier
(N
));
2074 ("premature usage of incomplete}",
2075 N
, First_Subtype
(T
));
2078 end Check_Fully_Declared
;
2080 -------------------------------------------
2081 -- Check_Function_With_Address_Parameter --
2082 -------------------------------------------
2084 procedure Check_Function_With_Address_Parameter
(Subp_Id
: Entity_Id
) is
2089 F
:= First_Formal
(Subp_Id
);
2090 while Present
(F
) loop
2093 if Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
2097 if Is_Descendant_Of_Address
(T
) or else Is_Limited_Type
(T
) then
2098 Set_Is_Pure
(Subp_Id
, False);
2104 end Check_Function_With_Address_Parameter
;
2106 -------------------------------------
2107 -- Check_Function_Writable_Actuals --
2108 -------------------------------------
2110 procedure Check_Function_Writable_Actuals
(N
: Node_Id
) is
2111 Writable_Actuals_List
: Elist_Id
:= No_Elist
;
2112 Identifiers_List
: Elist_Id
:= No_Elist
;
2113 Aggr_Error_Node
: Node_Id
:= Empty
;
2114 Error_Node
: Node_Id
:= Empty
;
2116 procedure Collect_Identifiers
(N
: Node_Id
);
2117 -- In a single traversal of subtree N collect in Writable_Actuals_List
2118 -- all the actuals of functions with writable actuals, and in the list
2119 -- Identifiers_List collect all the identifiers that are not actuals of
2120 -- functions with writable actuals. If a writable actual is referenced
2121 -- twice as writable actual then Error_Node is set to reference its
2122 -- second occurrence, the error is reported, and the tree traversal
2125 procedure Preanalyze_Without_Errors
(N
: Node_Id
);
2126 -- Preanalyze N without reporting errors. Very dubious, you can't just
2127 -- go analyzing things more than once???
2129 -------------------------
2130 -- Collect_Identifiers --
2131 -------------------------
2133 procedure Collect_Identifiers
(N
: Node_Id
) is
2135 function Check_Node
(N
: Node_Id
) return Traverse_Result
;
2136 -- Process a single node during the tree traversal to collect the
2137 -- writable actuals of functions and all the identifiers which are
2138 -- not writable actuals of functions.
2140 function Contains
(List
: Elist_Id
; N
: Node_Id
) return Boolean;
2141 -- Returns True if List has a node whose Entity is Entity (N)
2147 function Check_Node
(N
: Node_Id
) return Traverse_Result
is
2148 Is_Writable_Actual
: Boolean := False;
2152 if Nkind
(N
) = N_Identifier
then
2154 -- No analysis possible if the entity is not decorated
2156 if No
(Entity
(N
)) then
2159 -- Don't collect identifiers of packages, called functions, etc
2161 elsif Ekind_In
(Entity
(N
), E_Package
,
2168 -- For rewritten nodes, continue the traversal in the original
2169 -- subtree. Needed to handle aggregates in original expressions
2170 -- extracted from the tree by Remove_Side_Effects.
2172 elsif Is_Rewrite_Substitution
(N
) then
2173 Collect_Identifiers
(Original_Node
(N
));
2176 -- For now we skip aggregate discriminants, since they require
2177 -- performing the analysis in two phases to identify conflicts:
2178 -- first one analyzing discriminants and second one analyzing
2179 -- the rest of components (since at run time, discriminants are
2180 -- evaluated prior to components): too much computation cost
2181 -- to identify a corner case???
2183 elsif Nkind
(Parent
(N
)) = N_Component_Association
2184 and then Nkind_In
(Parent
(Parent
(N
)),
2186 N_Extension_Aggregate
)
2189 Choice
: constant Node_Id
:= First
(Choices
(Parent
(N
)));
2192 if Ekind
(Entity
(N
)) = E_Discriminant
then
2195 elsif Expression
(Parent
(N
)) = N
2196 and then Nkind
(Choice
) = N_Identifier
2197 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2203 -- Analyze if N is a writable actual of a function
2205 elsif Nkind
(Parent
(N
)) = N_Function_Call
then
2207 Call
: constant Node_Id
:= Parent
(N
);
2212 Id
:= Get_Called_Entity
(Call
);
2214 -- In case of previous error, no check is possible
2220 if Ekind_In
(Id
, E_Function
, E_Generic_Function
)
2221 and then Has_Out_Or_In_Out_Parameter
(Id
)
2223 Formal
:= First_Formal
(Id
);
2224 Actual
:= First_Actual
(Call
);
2225 while Present
(Actual
) and then Present
(Formal
) loop
2227 if Ekind_In
(Formal
, E_Out_Parameter
,
2230 Is_Writable_Actual
:= True;
2236 Next_Formal
(Formal
);
2237 Next_Actual
(Actual
);
2243 if Is_Writable_Actual
then
2245 -- Skip checking the error in non-elementary types since
2246 -- RM 6.4.1(6.15/3) is restricted to elementary types, but
2247 -- store this actual in Writable_Actuals_List since it is
2248 -- needed to perform checks on other constructs that have
2249 -- arbitrary order of evaluation (for example, aggregates).
2251 if not Is_Elementary_Type
(Etype
(N
)) then
2252 if not Contains
(Writable_Actuals_List
, N
) then
2253 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2256 -- Second occurrence of an elementary type writable actual
2258 elsif Contains
(Writable_Actuals_List
, N
) then
2260 -- Report the error on the second occurrence of the
2261 -- identifier. We cannot assume that N is the second
2262 -- occurrence (according to their location in the
2263 -- sources), since Traverse_Func walks through Field2
2264 -- last (see comment in the body of Traverse_Func).
2270 Elmt
:= First_Elmt
(Writable_Actuals_List
);
2271 while Present
(Elmt
)
2272 and then Entity
(Node
(Elmt
)) /= Entity
(N
)
2277 if Sloc
(N
) > Sloc
(Node
(Elmt
)) then
2280 Error_Node
:= Node
(Elmt
);
2284 ("value may be affected by call to & "
2285 & "because order of evaluation is arbitrary",
2290 -- First occurrence of a elementary type writable actual
2293 Append_New_Elmt
(N
, To
=> Writable_Actuals_List
);
2297 if Identifiers_List
= No_Elist
then
2298 Identifiers_List
:= New_Elmt_List
;
2301 Append_Unique_Elmt
(N
, Identifiers_List
);
2314 N
: Node_Id
) return Boolean
2316 pragma Assert
(Nkind
(N
) in N_Has_Entity
);
2321 if List
= No_Elist
then
2325 Elmt
:= First_Elmt
(List
);
2326 while Present
(Elmt
) loop
2327 if Entity
(Node
(Elmt
)) = Entity
(N
) then
2341 procedure Do_Traversal
is new Traverse_Proc
(Check_Node
);
2342 -- The traversal procedure
2344 -- Start of processing for Collect_Identifiers
2347 if Present
(Error_Node
) then
2351 if Nkind
(N
) in N_Subexpr
and then Is_OK_Static_Expression
(N
) then
2356 end Collect_Identifiers
;
2358 -------------------------------
2359 -- Preanalyze_Without_Errors --
2360 -------------------------------
2362 procedure Preanalyze_Without_Errors
(N
: Node_Id
) is
2363 Status
: constant Boolean := Get_Ignore_Errors
;
2365 Set_Ignore_Errors
(True);
2367 Set_Ignore_Errors
(Status
);
2368 end Preanalyze_Without_Errors
;
2370 -- Start of processing for Check_Function_Writable_Actuals
2373 -- The check only applies to Ada 2012 code on which Check_Actuals has
2374 -- been set, and only to constructs that have multiple constituents
2375 -- whose order of evaluation is not specified by the language.
2377 if Ada_Version
< Ada_2012
2378 or else not Check_Actuals
(N
)
2379 or else (not (Nkind
(N
) in N_Op
)
2380 and then not (Nkind
(N
) in N_Membership_Test
)
2381 and then not Nkind_In
(N
, N_Range
,
2383 N_Extension_Aggregate
,
2384 N_Full_Type_Declaration
,
2386 N_Procedure_Call_Statement
,
2387 N_Entry_Call_Statement
))
2388 or else (Nkind
(N
) = N_Full_Type_Declaration
2389 and then not Is_Record_Type
(Defining_Identifier
(N
)))
2391 -- In addition, this check only applies to source code, not to code
2392 -- generated by constraint checks.
2394 or else not Comes_From_Source
(N
)
2399 -- If a construct C has two or more direct constituents that are names
2400 -- or expressions whose evaluation may occur in an arbitrary order, at
2401 -- least one of which contains a function call with an in out or out
2402 -- parameter, then the construct is legal only if: for each name N that
2403 -- is passed as a parameter of mode in out or out to some inner function
2404 -- call C2 (not including the construct C itself), there is no other
2405 -- name anywhere within a direct constituent of the construct C other
2406 -- than the one containing C2, that is known to refer to the same
2407 -- object (RM 6.4.1(6.17/3)).
2411 Collect_Identifiers
(Low_Bound
(N
));
2412 Collect_Identifiers
(High_Bound
(N
));
2414 when N_Membership_Test
2421 Collect_Identifiers
(Left_Opnd
(N
));
2423 if Present
(Right_Opnd
(N
)) then
2424 Collect_Identifiers
(Right_Opnd
(N
));
2427 if Nkind_In
(N
, N_In
, N_Not_In
)
2428 and then Present
(Alternatives
(N
))
2430 Expr
:= First
(Alternatives
(N
));
2431 while Present
(Expr
) loop
2432 Collect_Identifiers
(Expr
);
2439 when N_Full_Type_Declaration
=>
2441 function Get_Record_Part
(N
: Node_Id
) return Node_Id
;
2442 -- Return the record part of this record type definition
2444 function Get_Record_Part
(N
: Node_Id
) return Node_Id
is
2445 Type_Def
: constant Node_Id
:= Type_Definition
(N
);
2447 if Nkind
(Type_Def
) = N_Derived_Type_Definition
then
2448 return Record_Extension_Part
(Type_Def
);
2452 end Get_Record_Part
;
2455 Def_Id
: Entity_Id
:= Defining_Identifier
(N
);
2456 Rec
: Node_Id
:= Get_Record_Part
(N
);
2459 -- No need to perform any analysis if the record has no
2462 if No
(Rec
) or else No
(Component_List
(Rec
)) then
2466 -- Collect the identifiers starting from the deepest
2467 -- derivation. Done to report the error in the deepest
2471 if Present
(Component_List
(Rec
)) then
2472 Comp
:= First
(Component_Items
(Component_List
(Rec
)));
2473 while Present
(Comp
) loop
2474 if Nkind
(Comp
) = N_Component_Declaration
2475 and then Present
(Expression
(Comp
))
2477 Collect_Identifiers
(Expression
(Comp
));
2484 exit when No
(Underlying_Type
(Etype
(Def_Id
)))
2485 or else Base_Type
(Underlying_Type
(Etype
(Def_Id
)))
2488 Def_Id
:= Base_Type
(Underlying_Type
(Etype
(Def_Id
)));
2489 Rec
:= Get_Record_Part
(Parent
(Def_Id
));
2493 when N_Entry_Call_Statement
2497 Id
: constant Entity_Id
:= Get_Called_Entity
(N
);
2502 Formal
:= First_Formal
(Id
);
2503 Actual
:= First_Actual
(N
);
2504 while Present
(Actual
) and then Present
(Formal
) loop
2505 if Ekind_In
(Formal
, E_Out_Parameter
,
2508 Collect_Identifiers
(Actual
);
2511 Next_Formal
(Formal
);
2512 Next_Actual
(Actual
);
2517 | N_Extension_Aggregate
2522 Comp_Expr
: Node_Id
;
2525 -- Handle the N_Others_Choice of array aggregates with static
2526 -- bounds. There is no need to perform this analysis in
2527 -- aggregates without static bounds since we cannot evaluate
2528 -- if the N_Others_Choice covers several elements. There is
2529 -- no need to handle the N_Others choice of record aggregates
2530 -- since at this stage it has been already expanded by
2531 -- Resolve_Record_Aggregate.
2533 if Is_Array_Type
(Etype
(N
))
2534 and then Nkind
(N
) = N_Aggregate
2535 and then Present
(Aggregate_Bounds
(N
))
2536 and then Compile_Time_Known_Bounds
(Etype
(N
))
2537 and then Expr_Value
(High_Bound
(Aggregate_Bounds
(N
)))
2539 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
)))
2542 Count_Components
: Uint
:= Uint_0
;
2543 Num_Components
: Uint
;
2544 Others_Assoc
: Node_Id
;
2545 Others_Choice
: Node_Id
:= Empty
;
2546 Others_Box_Present
: Boolean := False;
2549 -- Count positional associations
2551 if Present
(Expressions
(N
)) then
2552 Comp_Expr
:= First
(Expressions
(N
));
2553 while Present
(Comp_Expr
) loop
2554 Count_Components
:= Count_Components
+ 1;
2559 -- Count the rest of elements and locate the N_Others
2562 Assoc
:= First
(Component_Associations
(N
));
2563 while Present
(Assoc
) loop
2564 Choice
:= First
(Choices
(Assoc
));
2565 while Present
(Choice
) loop
2566 if Nkind
(Choice
) = N_Others_Choice
then
2567 Others_Assoc
:= Assoc
;
2568 Others_Choice
:= Choice
;
2569 Others_Box_Present
:= Box_Present
(Assoc
);
2571 -- Count several components
2573 elsif Nkind_In
(Choice
, N_Range
,
2574 N_Subtype_Indication
)
2575 or else (Is_Entity_Name
(Choice
)
2576 and then Is_Type
(Entity
(Choice
)))
2581 Get_Index_Bounds
(Choice
, L
, H
);
2583 (Compile_Time_Known_Value
(L
)
2584 and then Compile_Time_Known_Value
(H
));
2587 + Expr_Value
(H
) - Expr_Value
(L
) + 1;
2590 -- Count single component. No other case available
2591 -- since we are handling an aggregate with static
2595 pragma Assert
(Is_OK_Static_Expression
(Choice
)
2596 or else Nkind
(Choice
) = N_Identifier
2597 or else Nkind
(Choice
) = N_Integer_Literal
);
2599 Count_Components
:= Count_Components
+ 1;
2609 Expr_Value
(High_Bound
(Aggregate_Bounds
(N
))) -
2610 Expr_Value
(Low_Bound
(Aggregate_Bounds
(N
))) + 1;
2612 pragma Assert
(Count_Components
<= Num_Components
);
2614 -- Handle the N_Others choice if it covers several
2617 if Present
(Others_Choice
)
2618 and then (Num_Components
- Count_Components
) > 1
2620 if not Others_Box_Present
then
2622 -- At this stage, if expansion is active, the
2623 -- expression of the others choice has not been
2624 -- analyzed. Hence we generate a duplicate and
2625 -- we analyze it silently to have available the
2626 -- minimum decoration required to collect the
2629 if not Expander_Active
then
2630 Comp_Expr
:= Expression
(Others_Assoc
);
2633 New_Copy_Tree
(Expression
(Others_Assoc
));
2634 Preanalyze_Without_Errors
(Comp_Expr
);
2637 Collect_Identifiers
(Comp_Expr
);
2639 if Writable_Actuals_List
/= No_Elist
then
2641 -- As suggested by Robert, at current stage we
2642 -- report occurrences of this case as warnings.
2645 ("writable function parameter may affect "
2646 & "value in other component because order "
2647 & "of evaluation is unspecified??",
2648 Node
(First_Elmt
(Writable_Actuals_List
)));
2654 -- For an array aggregate, a discrete_choice_list that has
2655 -- a nonstatic range is considered as two or more separate
2656 -- occurrences of the expression (RM 6.4.1(20/3)).
2658 elsif Is_Array_Type
(Etype
(N
))
2659 and then Nkind
(N
) = N_Aggregate
2660 and then Present
(Aggregate_Bounds
(N
))
2661 and then not Compile_Time_Known_Bounds
(Etype
(N
))
2663 -- Collect identifiers found in the dynamic bounds
2666 Count_Components
: Natural := 0;
2667 Low
, High
: Node_Id
;
2670 Assoc
:= First
(Component_Associations
(N
));
2671 while Present
(Assoc
) loop
2672 Choice
:= First
(Choices
(Assoc
));
2673 while Present
(Choice
) loop
2674 if Nkind_In
(Choice
, N_Range
,
2675 N_Subtype_Indication
)
2676 or else (Is_Entity_Name
(Choice
)
2677 and then Is_Type
(Entity
(Choice
)))
2679 Get_Index_Bounds
(Choice
, Low
, High
);
2681 if not Compile_Time_Known_Value
(Low
) then
2682 Collect_Identifiers
(Low
);
2684 if No
(Aggr_Error_Node
) then
2685 Aggr_Error_Node
:= Low
;
2689 if not Compile_Time_Known_Value
(High
) then
2690 Collect_Identifiers
(High
);
2692 if No
(Aggr_Error_Node
) then
2693 Aggr_Error_Node
:= High
;
2697 -- The RM rule is violated if there is more than
2698 -- a single choice in a component association.
2701 Count_Components
:= Count_Components
+ 1;
2703 if No
(Aggr_Error_Node
)
2704 and then Count_Components
> 1
2706 Aggr_Error_Node
:= Choice
;
2709 if not Compile_Time_Known_Value
(Choice
) then
2710 Collect_Identifiers
(Choice
);
2722 -- Handle ancestor part of extension aggregates
2724 if Nkind
(N
) = N_Extension_Aggregate
then
2725 Collect_Identifiers
(Ancestor_Part
(N
));
2728 -- Handle positional associations
2730 if Present
(Expressions
(N
)) then
2731 Comp_Expr
:= First
(Expressions
(N
));
2732 while Present
(Comp_Expr
) loop
2733 if not Is_OK_Static_Expression
(Comp_Expr
) then
2734 Collect_Identifiers
(Comp_Expr
);
2741 -- Handle discrete associations
2743 if Present
(Component_Associations
(N
)) then
2744 Assoc
:= First
(Component_Associations
(N
));
2745 while Present
(Assoc
) loop
2747 if not Box_Present
(Assoc
) then
2748 Choice
:= First
(Choices
(Assoc
));
2749 while Present
(Choice
) loop
2751 -- For now we skip discriminants since it requires
2752 -- performing the analysis in two phases: first one
2753 -- analyzing discriminants and second one analyzing
2754 -- the rest of components since discriminants are
2755 -- evaluated prior to components: too much extra
2756 -- work to detect a corner case???
2758 if Nkind
(Choice
) in N_Has_Entity
2759 and then Present
(Entity
(Choice
))
2760 and then Ekind
(Entity
(Choice
)) = E_Discriminant
2764 elsif Box_Present
(Assoc
) then
2768 if not Analyzed
(Expression
(Assoc
)) then
2770 New_Copy_Tree
(Expression
(Assoc
));
2771 Set_Parent
(Comp_Expr
, Parent
(N
));
2772 Preanalyze_Without_Errors
(Comp_Expr
);
2774 Comp_Expr
:= Expression
(Assoc
);
2777 Collect_Identifiers
(Comp_Expr
);
2793 -- No further action needed if we already reported an error
2795 if Present
(Error_Node
) then
2799 -- Check violation of RM 6.20/3 in aggregates
2801 if Present
(Aggr_Error_Node
)
2802 and then Writable_Actuals_List
/= No_Elist
2805 ("value may be affected by call in other component because they "
2806 & "are evaluated in unspecified order",
2807 Node
(First_Elmt
(Writable_Actuals_List
)));
2811 -- Check if some writable argument of a function is referenced
2813 if Writable_Actuals_List
/= No_Elist
2814 and then Identifiers_List
/= No_Elist
2821 Elmt_1
:= First_Elmt
(Writable_Actuals_List
);
2822 while Present
(Elmt_1
) loop
2823 Elmt_2
:= First_Elmt
(Identifiers_List
);
2824 while Present
(Elmt_2
) loop
2825 if Entity
(Node
(Elmt_1
)) = Entity
(Node
(Elmt_2
)) then
2826 case Nkind
(Parent
(Node
(Elmt_2
))) is
2828 | N_Component_Association
2829 | N_Component_Declaration
2832 ("value may be affected by call in other "
2833 & "component because they are evaluated "
2834 & "in unspecified order",
2841 ("value may be affected by call in other "
2842 & "alternative because they are evaluated "
2843 & "in unspecified order",
2848 ("value of actual may be affected by call in "
2849 & "other actual because they are evaluated "
2850 & "in unspecified order",
2862 end Check_Function_Writable_Actuals
;
2864 --------------------------------
2865 -- Check_Implicit_Dereference --
2866 --------------------------------
2868 procedure Check_Implicit_Dereference
(N
: Node_Id
; Typ
: Entity_Id
) is
2874 if Nkind
(N
) = N_Indexed_Component
2875 and then Present
(Generalized_Indexing
(N
))
2877 Nam
:= Generalized_Indexing
(N
);
2882 if Ada_Version
< Ada_2012
2883 or else not Has_Implicit_Dereference
(Base_Type
(Typ
))
2887 elsif not Comes_From_Source
(N
)
2888 and then Nkind
(N
) /= N_Indexed_Component
2892 elsif Is_Entity_Name
(Nam
) and then Is_Type
(Entity
(Nam
)) then
2896 Disc
:= First_Discriminant
(Typ
);
2897 while Present
(Disc
) loop
2898 if Has_Implicit_Dereference
(Disc
) then
2899 Desig
:= Designated_Type
(Etype
(Disc
));
2900 Add_One_Interp
(Nam
, Disc
, Desig
);
2902 -- If the node is a generalized indexing, add interpretation
2903 -- to that node as well, for subsequent resolution.
2905 if Nkind
(N
) = N_Indexed_Component
then
2906 Add_One_Interp
(N
, Disc
, Desig
);
2909 -- If the operation comes from a generic unit and the context
2910 -- is a selected component, the selector name may be global
2911 -- and set in the instance already. Remove the entity to
2912 -- force resolution of the selected component, and the
2913 -- generation of an explicit dereference if needed.
2916 and then Nkind
(Parent
(Nam
)) = N_Selected_Component
2918 Set_Entity
(Selector_Name
(Parent
(Nam
)), Empty
);
2924 Next_Discriminant
(Disc
);
2927 end Check_Implicit_Dereference
;
2929 ----------------------------------
2930 -- Check_Internal_Protected_Use --
2931 ----------------------------------
2933 procedure Check_Internal_Protected_Use
(N
: Node_Id
; Nam
: Entity_Id
) is
2941 while Present
(S
) loop
2942 if S
= Standard_Standard
then
2945 elsif Ekind
(S
) = E_Function
2946 and then Ekind
(Scope
(S
)) = E_Protected_Type
2956 and then Scope
(Nam
) = Prot
2957 and then Ekind
(Nam
) /= E_Function
2959 -- An indirect function call (e.g. a callback within a protected
2960 -- function body) is not statically illegal. If the access type is
2961 -- anonymous and is the type of an access parameter, the scope of Nam
2962 -- will be the protected type, but it is not a protected operation.
2964 if Ekind
(Nam
) = E_Subprogram_Type
2965 and then Nkind
(Associated_Node_For_Itype
(Nam
)) =
2966 N_Function_Specification
2970 elsif Nkind
(N
) = N_Subprogram_Renaming_Declaration
then
2972 ("within protected function cannot use protected procedure in "
2973 & "renaming or as generic actual", N
);
2975 elsif Nkind
(N
) = N_Attribute_Reference
then
2977 ("within protected function cannot take access of protected "
2982 ("within protected function, protected object is constant", N
);
2984 ("\cannot call operation that may modify it", N
);
2988 -- Verify that an internal call does not appear within a precondition
2989 -- of a protected operation. This implements AI12-0166.
2990 -- The precondition aspect has been rewritten as a pragma Precondition
2991 -- and we check whether the scope of the called subprogram is the same
2992 -- as that of the entity to which the aspect applies.
2994 if Convention
(Nam
) = Convention_Protected
then
3000 while Present
(P
) loop
3001 if Nkind
(P
) = N_Pragma
3002 and then Chars
(Pragma_Identifier
(P
)) = Name_Precondition
3003 and then From_Aspect_Specification
(P
)
3005 Scope
(Entity
(Corresponding_Aspect
(P
))) = Scope
(Nam
)
3008 ("internal call cannot appear in precondition of "
3009 & "protected operation", N
);
3012 elsif Nkind
(P
) = N_Pragma
3013 and then Chars
(Pragma_Identifier
(P
)) = Name_Contract_Cases
3015 -- Check whether call is in a case guard. It is legal in a
3019 while Present
(P
) loop
3020 if Nkind
(Parent
(P
)) = N_Component_Association
3021 and then P
/= Expression
(Parent
(P
))
3024 ("internal call cannot appear in case guard in a "
3025 & "contract case", N
);
3033 elsif Nkind
(P
) = N_Parameter_Specification
3034 and then Scope
(Current_Scope
) = Scope
(Nam
)
3035 and then Nkind_In
(Parent
(P
), N_Entry_Declaration
,
3036 N_Subprogram_Declaration
)
3039 ("internal call cannot appear in default for formal of "
3040 & "protected operation", N
);
3048 end Check_Internal_Protected_Use
;
3050 ---------------------------------------
3051 -- Check_Later_Vs_Basic_Declarations --
3052 ---------------------------------------
3054 procedure Check_Later_Vs_Basic_Declarations
3056 During_Parsing
: Boolean)
3058 Body_Sloc
: Source_Ptr
;
3061 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean;
3062 -- Return whether Decl is considered as a declarative item.
3063 -- When During_Parsing is True, the semantics of Ada 83 is followed.
3064 -- When During_Parsing is False, the semantics of SPARK is followed.
3066 -------------------------------
3067 -- Is_Later_Declarative_Item --
3068 -------------------------------
3070 function Is_Later_Declarative_Item
(Decl
: Node_Id
) return Boolean is
3072 if Nkind
(Decl
) in N_Later_Decl_Item
then
3075 elsif Nkind
(Decl
) = N_Pragma
then
3078 elsif During_Parsing
then
3081 -- In SPARK, a package declaration is not considered as a later
3082 -- declarative item.
3084 elsif Nkind
(Decl
) = N_Package_Declaration
then
3087 -- In SPARK, a renaming is considered as a later declarative item
3089 elsif Nkind
(Decl
) in N_Renaming_Declaration
then
3095 end Is_Later_Declarative_Item
;
3097 -- Start of processing for Check_Later_Vs_Basic_Declarations
3100 Decl
:= First
(Decls
);
3102 -- Loop through sequence of basic declarative items
3104 Outer
: while Present
(Decl
) loop
3105 if not Nkind_In
(Decl
, N_Subprogram_Body
, N_Package_Body
, N_Task_Body
)
3106 and then Nkind
(Decl
) not in N_Body_Stub
3110 -- Once a body is encountered, we only allow later declarative
3111 -- items. The inner loop checks the rest of the list.
3114 Body_Sloc
:= Sloc
(Decl
);
3116 Inner
: while Present
(Decl
) loop
3117 if not Is_Later_Declarative_Item
(Decl
) then
3118 if During_Parsing
then
3119 if Ada_Version
= Ada_83
then
3120 Error_Msg_Sloc
:= Body_Sloc
;
3122 ("(Ada 83) decl cannot appear after body#", Decl
);
3125 Error_Msg_Sloc
:= Body_Sloc
;
3126 Check_SPARK_05_Restriction
3127 ("decl cannot appear after body#", Decl
);
3135 end Check_Later_Vs_Basic_Declarations
;
3137 ---------------------------
3138 -- Check_No_Hidden_State --
3139 ---------------------------
3141 procedure Check_No_Hidden_State
(Id
: Entity_Id
) is
3142 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean;
3143 -- Determine whether the entity of a package denoted by Pkg has a null
3146 -----------------------------
3147 -- Has_Null_Abstract_State --
3148 -----------------------------
3150 function Has_Null_Abstract_State
(Pkg
: Entity_Id
) return Boolean is
3151 States
: constant Elist_Id
:= Abstract_States
(Pkg
);
3154 -- Check first available state of related package. A null abstract
3155 -- state always appears as the sole element of the state list.
3159 and then Is_Null_State
(Node
(First_Elmt
(States
)));
3160 end Has_Null_Abstract_State
;
3164 Context
: Entity_Id
:= Empty
;
3165 Not_Visible
: Boolean := False;
3168 -- Start of processing for Check_No_Hidden_State
3171 pragma Assert
(Ekind_In
(Id
, E_Abstract_State
, E_Variable
));
3173 -- Find the proper context where the object or state appears
3176 while Present
(Scop
) loop
3179 -- Keep track of the context's visibility
3181 Not_Visible
:= Not_Visible
or else In_Private_Part
(Context
);
3183 -- Prevent the search from going too far
3185 if Context
= Standard_Standard
then
3188 -- Objects and states that appear immediately within a subprogram or
3189 -- inside a construct nested within a subprogram do not introduce a
3190 -- hidden state. They behave as local variable declarations.
3192 elsif Is_Subprogram
(Context
) then
3195 -- When examining a package body, use the entity of the spec as it
3196 -- carries the abstract state declarations.
3198 elsif Ekind
(Context
) = E_Package_Body
then
3199 Context
:= Spec_Entity
(Context
);
3202 -- Stop the traversal when a package subject to a null abstract state
3205 if Ekind_In
(Context
, E_Generic_Package
, E_Package
)
3206 and then Has_Null_Abstract_State
(Context
)
3211 Scop
:= Scope
(Scop
);
3214 -- At this point we know that there is at least one package with a null
3215 -- abstract state in visibility. Emit an error message unconditionally
3216 -- if the entity being processed is a state because the placement of the
3217 -- related package is irrelevant. This is not the case for objects as
3218 -- the intermediate context matters.
3220 if Present
(Context
)
3221 and then (Ekind
(Id
) = E_Abstract_State
or else Not_Visible
)
3223 Error_Msg_N
("cannot introduce hidden state &", Id
);
3224 Error_Msg_NE
("\package & has null abstract state", Id
, Context
);
3226 end Check_No_Hidden_State
;
3228 ----------------------------------------
3229 -- Check_Nonvolatile_Function_Profile --
3230 ----------------------------------------
3232 procedure Check_Nonvolatile_Function_Profile
(Func_Id
: Entity_Id
) is
3236 -- Inspect all formal parameters
3238 Formal
:= First_Formal
(Func_Id
);
3239 while Present
(Formal
) loop
3240 if Is_Effectively_Volatile
(Etype
(Formal
)) then
3242 ("nonvolatile function & cannot have a volatile parameter",
3246 Next_Formal
(Formal
);
3249 -- Inspect the return type
3251 if Is_Effectively_Volatile
(Etype
(Func_Id
)) then
3253 ("nonvolatile function & cannot have a volatile return type",
3254 Result_Definition
(Parent
(Func_Id
)), Func_Id
);
3256 end Check_Nonvolatile_Function_Profile
;
3258 -----------------------------
3259 -- Check_Part_Of_Reference --
3260 -----------------------------
3262 procedure Check_Part_Of_Reference
(Var_Id
: Entity_Id
; Ref
: Node_Id
) is
3263 Conc_Obj
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
3265 OK_Use
: Boolean := False;
3268 Spec_Id
: Entity_Id
;
3271 -- Traverse the parent chain looking for a suitable context for the
3272 -- reference to the concurrent constituent.
3274 Par
:= Parent
(Ref
);
3275 while Present
(Par
) loop
3276 if Nkind
(Par
) = N_Pragma
then
3277 Prag_Nam
:= Pragma_Name
(Par
);
3279 -- A concurrent constituent is allowed to appear in pragmas
3280 -- Initial_Condition and Initializes as this is part of the
3281 -- elaboration checks for the constituent (SPARK RM 9.3).
3283 if Nam_In
(Prag_Nam
, Name_Initial_Condition
, Name_Initializes
) then
3287 -- When the reference appears within pragma Depends or Global,
3288 -- check whether the pragma applies to a single task type. Note
3289 -- that the pragma is not encapsulated by the type definition,
3290 -- but this is still a valid context.
3292 elsif Nam_In
(Prag_Nam
, Name_Depends
, Name_Global
) then
3293 Decl
:= Find_Related_Declaration_Or_Body
(Par
);
3295 if Nkind
(Decl
) = N_Object_Declaration
3296 and then Defining_Entity
(Decl
) = Conc_Obj
3303 -- The reference appears somewhere in the definition of the single
3304 -- protected/task type (SPARK RM 9.3).
3306 elsif Nkind_In
(Par
, N_Single_Protected_Declaration
,
3307 N_Single_Task_Declaration
)
3308 and then Defining_Entity
(Par
) = Conc_Obj
3313 -- The reference appears within the expanded declaration or the body
3314 -- of the single protected/task type (SPARK RM 9.3).
3316 elsif Nkind_In
(Par
, N_Protected_Body
,
3317 N_Protected_Type_Declaration
,
3319 N_Task_Type_Declaration
)
3321 Spec_Id
:= Unique_Defining_Entity
(Par
);
3323 if Present
(Anonymous_Object
(Spec_Id
))
3324 and then Anonymous_Object
(Spec_Id
) = Conc_Obj
3330 -- The reference has been relocated within an internally generated
3331 -- package or subprogram. Assume that the reference is legal as the
3332 -- real check was already performed in the original context of the
3335 elsif Nkind_In
(Par
, N_Package_Body
,
3336 N_Package_Declaration
,
3338 N_Subprogram_Declaration
)
3339 and then not Comes_From_Source
(Par
)
3341 -- Continue to examine the context if the reference appears in a
3342 -- subprogram body which was previously an expression function.
3344 if Nkind
(Par
) = N_Subprogram_Body
3345 and then Was_Expression_Function
(Par
)
3349 -- Otherwise the reference is legal
3356 -- The reference has been relocated to an inlined body for GNATprove.
3357 -- Assume that the reference is legal as the real check was already
3358 -- performed in the original context of the reference.
3360 elsif GNATprove_Mode
3361 and then Nkind
(Par
) = N_Subprogram_Body
3362 and then Chars
(Defining_Entity
(Par
)) = Name_uParent
3368 Par
:= Parent
(Par
);
3371 -- The reference is illegal as it appears outside the definition or
3372 -- body of the single protected/task type.
3376 ("reference to variable & cannot appear in this context",
3378 Error_Msg_Name_1
:= Chars
(Var_Id
);
3380 if Is_Single_Protected_Object
(Conc_Obj
) then
3382 ("\% is constituent of single protected type &", Ref
, Conc_Obj
);
3386 ("\% is constituent of single task type &", Ref
, Conc_Obj
);
3389 end Check_Part_Of_Reference
;
3391 ------------------------------------------
3392 -- Check_Potentially_Blocking_Operation --
3393 ------------------------------------------
3395 procedure Check_Potentially_Blocking_Operation
(N
: Node_Id
) is
3399 -- N is one of the potentially blocking operations listed in 9.5.1(8).
3400 -- When pragma Detect_Blocking is active, the run time will raise
3401 -- Program_Error. Here we only issue a warning, since we generally
3402 -- support the use of potentially blocking operations in the absence
3405 -- Indirect blocking through a subprogram call cannot be diagnosed
3406 -- statically without interprocedural analysis, so we do not attempt
3409 S
:= Scope
(Current_Scope
);
3410 while Present
(S
) and then S
/= Standard_Standard
loop
3411 if Is_Protected_Type
(S
) then
3413 ("potentially blocking operation in protected operation??", N
);
3419 end Check_Potentially_Blocking_Operation
;
3421 ------------------------------------
3422 -- Check_Previous_Null_Procedure --
3423 ------------------------------------
3425 procedure Check_Previous_Null_Procedure
3430 if Ekind
(Prev
) = E_Procedure
3431 and then Nkind
(Parent
(Prev
)) = N_Procedure_Specification
3432 and then Null_Present
(Parent
(Prev
))
3434 Error_Msg_Sloc
:= Sloc
(Prev
);
3436 ("declaration cannot complete previous null procedure#", Decl
);
3438 end Check_Previous_Null_Procedure
;
3440 ---------------------------------
3441 -- Check_Result_And_Post_State --
3442 ---------------------------------
3444 procedure Check_Result_And_Post_State
(Subp_Id
: Entity_Id
) is
3445 procedure Check_Result_And_Post_State_In_Pragma
3447 Result_Seen
: in out Boolean);
3448 -- Determine whether pragma Prag mentions attribute 'Result and whether
3449 -- the pragma contains an expression that evaluates differently in pre-
3450 -- and post-state. Prag is a [refined] postcondition or a contract-cases
3451 -- pragma. Result_Seen is set when the pragma mentions attribute 'Result
3453 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean;
3454 -- Determine whether subprogram Subp_Id contains at least one IN OUT
3455 -- formal parameter.
3457 -------------------------------------------
3458 -- Check_Result_And_Post_State_In_Pragma --
3459 -------------------------------------------
3461 procedure Check_Result_And_Post_State_In_Pragma
3463 Result_Seen
: in out Boolean)
3465 procedure Check_Conjunct
(Expr
: Node_Id
);
3466 -- Check an individual conjunct in a conjunction of Boolean
3467 -- expressions, connected by "and" or "and then" operators.
3469 procedure Check_Conjuncts
(Expr
: Node_Id
);
3470 -- Apply the post-state check to every conjunct in an expression, in
3471 -- case this is a conjunction of Boolean expressions. Otherwise apply
3472 -- it to the expression as a whole.
3474 procedure Check_Expression
(Expr
: Node_Id
);
3475 -- Perform the 'Result and post-state checks on a given expression
3477 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
;
3478 -- Attempt to find attribute 'Result in a subtree denoted by N
3480 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean;
3481 -- Determine whether source node N denotes "True" or "False"
3483 function Mentions_Post_State
(N
: Node_Id
) return Boolean;
3484 -- Determine whether a subtree denoted by N mentions any construct
3485 -- that denotes a post-state.
3487 procedure Check_Function_Result
is
3488 new Traverse_Proc
(Is_Function_Result
);
3490 --------------------
3491 -- Check_Conjunct --
3492 --------------------
3494 procedure Check_Conjunct
(Expr
: Node_Id
) is
3495 function Adjust_Message
(Msg
: String) return String;
3496 -- Prepend a prefix to the input message Msg denoting that the
3497 -- message applies to a conjunct in the expression, when this
3500 function Applied_On_Conjunct
return Boolean;
3501 -- Returns True if the message applies to a conjunct in the
3502 -- expression, instead of the whole expression.
3504 --------------------
3505 -- Adjust_Message --
3506 --------------------
3508 function Adjust_Message
(Msg
: String) return String is
3510 if Applied_On_Conjunct
then
3511 return "conjunct in " & Msg
;
3517 -------------------------
3518 -- Applied_On_Conjunct --
3519 -------------------------
3521 function Applied_On_Conjunct
return Boolean is
3523 -- Expr is the conjunct of an enclosing "and" expression
3525 return Nkind
(Parent
(Expr
)) in N_Subexpr
3527 -- or Expr is a conjunct of an enclosing "and then"
3528 -- expression in a postcondition aspect that was split into
3529 -- multiple pragmas. The first conjunct has the "and then"
3530 -- expression as Original_Node, and other conjuncts have
3531 -- Split_PCC set to True.
3533 or else Nkind
(Original_Node
(Expr
)) = N_And_Then
3534 or else Split_PPC
(Prag
);
3535 end Applied_On_Conjunct
;
3540 -- Error node when reporting a warning on a (refined)
3543 -- Start of processing for Check_Conjunct
3546 if Applied_On_Conjunct
then
3552 if not Is_Trivial_Boolean
(Expr
)
3553 and then not Mentions_Post_State
(Expr
)
3555 if Pragma_Name
(Prag
) = Name_Contract_Cases
then
3556 Error_Msg_NE
(Adjust_Message
3557 ("contract case does not check the outcome of calling "
3558 & "&?T?"), Expr
, Subp_Id
);
3560 elsif Pragma_Name
(Prag
) = Name_Refined_Post
then
3561 Error_Msg_NE
(Adjust_Message
3562 ("refined postcondition does not check the outcome of "
3563 & "calling &?T?"), Err_Node
, Subp_Id
);
3566 Error_Msg_NE
(Adjust_Message
3567 ("postcondition does not check the outcome of calling "
3568 & "&?T?"), Err_Node
, Subp_Id
);
3573 ---------------------
3574 -- Check_Conjuncts --
3575 ---------------------
3577 procedure Check_Conjuncts
(Expr
: Node_Id
) is
3579 if Nkind_In
(Expr
, N_Op_And
, N_And_Then
) then
3580 Check_Conjuncts
(Left_Opnd
(Expr
));
3581 Check_Conjuncts
(Right_Opnd
(Expr
));
3583 Check_Conjunct
(Expr
);
3585 end Check_Conjuncts
;
3587 ----------------------
3588 -- Check_Expression --
3589 ----------------------
3591 procedure Check_Expression
(Expr
: Node_Id
) is
3593 if not Is_Trivial_Boolean
(Expr
) then
3594 Check_Function_Result
(Expr
);
3595 Check_Conjuncts
(Expr
);
3597 end Check_Expression
;
3599 ------------------------
3600 -- Is_Function_Result --
3601 ------------------------
3603 function Is_Function_Result
(N
: Node_Id
) return Traverse_Result
is
3605 if Is_Attribute_Result
(N
) then
3606 Result_Seen
:= True;
3609 -- Continue the traversal
3614 end Is_Function_Result
;
3616 ------------------------
3617 -- Is_Trivial_Boolean --
3618 ------------------------
3620 function Is_Trivial_Boolean
(N
: Node_Id
) return Boolean is
3623 Comes_From_Source
(N
)
3624 and then Is_Entity_Name
(N
)
3625 and then (Entity
(N
) = Standard_True
3627 Entity
(N
) = Standard_False
);
3628 end Is_Trivial_Boolean
;
3630 -------------------------
3631 -- Mentions_Post_State --
3632 -------------------------
3634 function Mentions_Post_State
(N
: Node_Id
) return Boolean is
3635 Post_State_Seen
: Boolean := False;
3637 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
;
3638 -- Attempt to find a construct that denotes a post-state. If this
3639 -- is the case, set flag Post_State_Seen.
3645 function Is_Post_State
(N
: Node_Id
) return Traverse_Result
is
3649 if Nkind_In
(N
, N_Explicit_Dereference
, N_Function_Call
) then
3650 Post_State_Seen
:= True;
3653 elsif Nkind_In
(N
, N_Expanded_Name
, N_Identifier
) then
3656 -- Treat an undecorated reference as OK
3660 -- A reference to an assignable entity is considered a
3661 -- change in the post-state of a subprogram.
3663 or else Ekind_In
(Ent
, E_Generic_In_Out_Parameter
,
3668 -- The reference may be modified through a dereference
3670 or else (Is_Access_Type
(Etype
(Ent
))
3671 and then Nkind
(Parent
(N
)) =
3672 N_Selected_Component
)
3674 Post_State_Seen
:= True;
3678 elsif Nkind
(N
) = N_Attribute_Reference
then
3679 if Attribute_Name
(N
) = Name_Old
then
3682 elsif Attribute_Name
(N
) = Name_Result
then
3683 Post_State_Seen
:= True;
3691 procedure Find_Post_State
is new Traverse_Proc
(Is_Post_State
);
3693 -- Start of processing for Mentions_Post_State
3696 Find_Post_State
(N
);
3698 return Post_State_Seen
;
3699 end Mentions_Post_State
;
3703 Expr
: constant Node_Id
:=
3705 (First
(Pragma_Argument_Associations
(Prag
)));
3706 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
3709 -- Start of processing for Check_Result_And_Post_State_In_Pragma
3712 -- Examine all consequences
3714 if Nam
= Name_Contract_Cases
then
3715 CCase
:= First
(Component_Associations
(Expr
));
3716 while Present
(CCase
) loop
3717 Check_Expression
(Expression
(CCase
));
3722 -- Examine the expression of a postcondition
3724 else pragma Assert
(Nam_In
(Nam
, Name_Postcondition
,
3725 Name_Refined_Post
));
3726 Check_Expression
(Expr
);
3728 end Check_Result_And_Post_State_In_Pragma
;
3730 --------------------------
3731 -- Has_In_Out_Parameter --
3732 --------------------------
3734 function Has_In_Out_Parameter
(Subp_Id
: Entity_Id
) return Boolean is
3738 -- Traverse the formals looking for an IN OUT parameter
3740 Formal
:= First_Formal
(Subp_Id
);
3741 while Present
(Formal
) loop
3742 if Ekind
(Formal
) = E_In_Out_Parameter
then
3746 Next_Formal
(Formal
);
3750 end Has_In_Out_Parameter
;
3754 Items
: constant Node_Id
:= Contract
(Subp_Id
);
3755 Subp_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Subp_Id
);
3756 Case_Prag
: Node_Id
:= Empty
;
3757 Post_Prag
: Node_Id
:= Empty
;
3759 Seen_In_Case
: Boolean := False;
3760 Seen_In_Post
: Boolean := False;
3761 Spec_Id
: Entity_Id
;
3763 -- Start of processing for Check_Result_And_Post_State
3766 -- The lack of attribute 'Result or a post-state is classified as a
3767 -- suspicious contract. Do not perform the check if the corresponding
3768 -- swich is not set.
3770 if not Warn_On_Suspicious_Contract
then
3773 -- Nothing to do if there is no contract
3775 elsif No
(Items
) then
3779 -- Retrieve the entity of the subprogram spec (if any)
3781 if Nkind
(Subp_Decl
) = N_Subprogram_Body
3782 and then Present
(Corresponding_Spec
(Subp_Decl
))
3784 Spec_Id
:= Corresponding_Spec
(Subp_Decl
);
3786 elsif Nkind
(Subp_Decl
) = N_Subprogram_Body_Stub
3787 and then Present
(Corresponding_Spec_Of_Stub
(Subp_Decl
))
3789 Spec_Id
:= Corresponding_Spec_Of_Stub
(Subp_Decl
);
3795 -- Examine all postconditions for attribute 'Result and a post-state
3797 Prag
:= Pre_Post_Conditions
(Items
);
3798 while Present
(Prag
) loop
3799 if Nam_In
(Pragma_Name_Unmapped
(Prag
),
3800 Name_Postcondition
, Name_Refined_Post
)
3801 and then not Error_Posted
(Prag
)
3804 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Post
);
3807 Prag
:= Next_Pragma
(Prag
);
3810 -- Examine the contract cases of the subprogram for attribute 'Result
3811 -- and a post-state.
3813 Prag
:= Contract_Test_Cases
(Items
);
3814 while Present
(Prag
) loop
3815 if Pragma_Name
(Prag
) = Name_Contract_Cases
3816 and then not Error_Posted
(Prag
)
3819 Check_Result_And_Post_State_In_Pragma
(Prag
, Seen_In_Case
);
3822 Prag
:= Next_Pragma
(Prag
);
3825 -- Do not emit any errors if the subprogram is not a function
3827 if not Ekind_In
(Spec_Id
, E_Function
, E_Generic_Function
) then
3830 -- Regardless of whether the function has postconditions or contract
3831 -- cases, or whether they mention attribute 'Result, an IN OUT formal
3832 -- parameter is always treated as a result.
3834 elsif Has_In_Out_Parameter
(Spec_Id
) then
3837 -- The function has both a postcondition and contract cases and they do
3838 -- not mention attribute 'Result.
3840 elsif Present
(Case_Prag
)
3841 and then not Seen_In_Case
3842 and then Present
(Post_Prag
)
3843 and then not Seen_In_Post
3846 ("neither postcondition nor contract cases mention function "
3847 & "result?T?", Post_Prag
);
3849 -- The function has contract cases only and they do not mention
3850 -- attribute 'Result.
3852 elsif Present
(Case_Prag
) and then not Seen_In_Case
then
3853 Error_Msg_N
("contract cases do not mention result?T?", Case_Prag
);
3855 -- The function has postconditions only and they do not mention
3856 -- attribute 'Result.
3858 elsif Present
(Post_Prag
) and then not Seen_In_Post
then
3860 ("postcondition does not mention function result?T?", Post_Prag
);
3862 end Check_Result_And_Post_State
;
3864 -----------------------------
3865 -- Check_State_Refinements --
3866 -----------------------------
3868 procedure Check_State_Refinements
3870 Is_Main_Unit
: Boolean := False)
3872 procedure Check_Package
(Pack
: Node_Id
);
3873 -- Verify that all abstract states of a [generic] package denoted by its
3874 -- declarative node Pack have proper refinement. Recursively verify the
3875 -- visible and private declarations of the [generic] package for other
3878 procedure Check_Packages_In
(Decls
: List_Id
);
3879 -- Seek out [generic] package declarations within declarative list Decls
3880 -- and verify the status of their abstract state refinement.
3882 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean;
3883 -- Determine whether construct N is subject to pragma SPARK_Mode Off
3889 procedure Check_Package
(Pack
: Node_Id
) is
3890 Body_Id
: constant Entity_Id
:= Corresponding_Body
(Pack
);
3891 Spec
: constant Node_Id
:= Specification
(Pack
);
3892 States
: constant Elist_Id
:=
3893 Abstract_States
(Defining_Entity
(Pack
));
3895 State_Elmt
: Elmt_Id
;
3896 State_Id
: Entity_Id
;
3899 -- Do not verify proper state refinement when the package is subject
3900 -- to pragma SPARK_Mode Off because this disables the requirement for
3901 -- state refinement.
3903 if SPARK_Mode_Is_Off
(Pack
) then
3906 -- State refinement can only occur in a completing packge body. Do
3907 -- not verify proper state refinement when the body is subject to
3908 -- pragma SPARK_Mode Off because this disables the requirement for
3909 -- state refinement.
3911 elsif Present
(Body_Id
)
3912 and then SPARK_Mode_Is_Off
(Unit_Declaration_Node
(Body_Id
))
3916 -- Do not verify proper state refinement when the package is an
3917 -- instance as this check was already performed in the generic.
3919 elsif Present
(Generic_Parent
(Spec
)) then
3922 -- Otherwise examine the contents of the package
3925 if Present
(States
) then
3926 State_Elmt
:= First_Elmt
(States
);
3927 while Present
(State_Elmt
) loop
3928 State_Id
:= Node
(State_Elmt
);
3930 -- Emit an error when a non-null state lacks any form of
3933 if not Is_Null_State
(State_Id
)
3934 and then not Has_Null_Refinement
(State_Id
)
3935 and then not Has_Non_Null_Refinement
(State_Id
)
3937 Error_Msg_N
("state & requires refinement", State_Id
);
3940 Next_Elmt
(State_Elmt
);
3944 Check_Packages_In
(Visible_Declarations
(Spec
));
3945 Check_Packages_In
(Private_Declarations
(Spec
));
3949 -----------------------
3950 -- Check_Packages_In --
3951 -----------------------
3953 procedure Check_Packages_In
(Decls
: List_Id
) is
3957 if Present
(Decls
) then
3958 Decl
:= First
(Decls
);
3959 while Present
(Decl
) loop
3960 if Nkind_In
(Decl
, N_Generic_Package_Declaration
,
3961 N_Package_Declaration
)
3963 Check_Package
(Decl
);
3969 end Check_Packages_In
;
3971 -----------------------
3972 -- SPARK_Mode_Is_Off --
3973 -----------------------
3975 function SPARK_Mode_Is_Off
(N
: Node_Id
) return Boolean is
3976 Id
: constant Entity_Id
:= Defining_Entity
(N
);
3977 Prag
: constant Node_Id
:= SPARK_Pragma
(Id
);
3980 -- Default the mode to "off" when the context is an instance and all
3981 -- SPARK_Mode pragmas found within are to be ignored.
3983 if Ignore_SPARK_Mode_Pragmas
(Id
) then
3989 and then Get_SPARK_Mode_From_Annotation
(Prag
) = Off
;
3991 end SPARK_Mode_Is_Off
;
3993 -- Start of processing for Check_State_Refinements
3996 -- A block may declare a nested package
3998 if Nkind
(Context
) = N_Block_Statement
then
3999 Check_Packages_In
(Declarations
(Context
));
4001 -- An entry, protected, subprogram, or task body may declare a nested
4004 elsif Nkind_In
(Context
, N_Entry_Body
,
4009 -- Do not verify proper state refinement when the body is subject to
4010 -- pragma SPARK_Mode Off because this disables the requirement for
4011 -- state refinement.
4013 if not SPARK_Mode_Is_Off
(Context
) then
4014 Check_Packages_In
(Declarations
(Context
));
4017 -- A package body may declare a nested package
4019 elsif Nkind
(Context
) = N_Package_Body
then
4020 Check_Package
(Unit_Declaration_Node
(Corresponding_Spec
(Context
)));
4022 -- Do not verify proper state refinement when the body is subject to
4023 -- pragma SPARK_Mode Off because this disables the requirement for
4024 -- state refinement.
4026 if not SPARK_Mode_Is_Off
(Context
) then
4027 Check_Packages_In
(Declarations
(Context
));
4030 -- A library level [generic] package may declare a nested package
4032 elsif Nkind_In
(Context
, N_Generic_Package_Declaration
,
4033 N_Package_Declaration
)
4034 and then Is_Main_Unit
4036 Check_Package
(Context
);
4038 end Check_State_Refinements
;
4040 ------------------------------
4041 -- Check_Unprotected_Access --
4042 ------------------------------
4044 procedure Check_Unprotected_Access
4048 Cont_Encl_Typ
: Entity_Id
;
4049 Pref_Encl_Typ
: Entity_Id
;
4051 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
;
4052 -- Check whether Obj is a private component of a protected object.
4053 -- Return the protected type where the component resides, Empty
4056 function Is_Public_Operation
return Boolean;
4057 -- Verify that the enclosing operation is callable from outside the
4058 -- protected object, to minimize false positives.
4060 ------------------------------
4061 -- Enclosing_Protected_Type --
4062 ------------------------------
4064 function Enclosing_Protected_Type
(Obj
: Node_Id
) return Entity_Id
is
4066 if Is_Entity_Name
(Obj
) then
4068 Ent
: Entity_Id
:= Entity
(Obj
);
4071 -- The object can be a renaming of a private component, use
4072 -- the original record component.
4074 if Is_Prival
(Ent
) then
4075 Ent
:= Prival_Link
(Ent
);
4078 if Is_Protected_Type
(Scope
(Ent
)) then
4084 -- For indexed and selected components, recursively check the prefix
4086 if Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
4087 return Enclosing_Protected_Type
(Prefix
(Obj
));
4089 -- The object does not denote a protected component
4094 end Enclosing_Protected_Type
;
4096 -------------------------
4097 -- Is_Public_Operation --
4098 -------------------------
4100 function Is_Public_Operation
return Boolean is
4106 while Present
(S
) and then S
/= Pref_Encl_Typ
loop
4107 if Scope
(S
) = Pref_Encl_Typ
then
4108 E
:= First_Entity
(Pref_Encl_Typ
);
4110 and then E
/= First_Private_Entity
(Pref_Encl_Typ
)
4124 end Is_Public_Operation
;
4126 -- Start of processing for Check_Unprotected_Access
4129 if Nkind
(Expr
) = N_Attribute_Reference
4130 and then Attribute_Name
(Expr
) = Name_Unchecked_Access
4132 Cont_Encl_Typ
:= Enclosing_Protected_Type
(Context
);
4133 Pref_Encl_Typ
:= Enclosing_Protected_Type
(Prefix
(Expr
));
4135 -- Check whether we are trying to export a protected component to a
4136 -- context with an equal or lower access level.
4138 if Present
(Pref_Encl_Typ
)
4139 and then No
(Cont_Encl_Typ
)
4140 and then Is_Public_Operation
4141 and then Scope_Depth
(Pref_Encl_Typ
) >=
4142 Object_Access_Level
(Context
)
4145 ("??possible unprotected access to protected data", Expr
);
4148 end Check_Unprotected_Access
;
4150 ------------------------------
4151 -- Check_Unused_Body_States --
4152 ------------------------------
4154 procedure Check_Unused_Body_States
(Body_Id
: Entity_Id
) is
4155 procedure Process_Refinement_Clause
4158 -- Inspect all constituents of refinement clause Clause and remove any
4159 -- matches from body state list States.
4161 procedure Report_Unused_Body_States
(States
: Elist_Id
);
4162 -- Emit errors for each abstract state or object found in list States
4164 -------------------------------
4165 -- Process_Refinement_Clause --
4166 -------------------------------
4168 procedure Process_Refinement_Clause
4172 procedure Process_Constituent
(Constit
: Node_Id
);
4173 -- Remove constituent Constit from body state list States
4175 -------------------------
4176 -- Process_Constituent --
4177 -------------------------
4179 procedure Process_Constituent
(Constit
: Node_Id
) is
4180 Constit_Id
: Entity_Id
;
4183 -- Guard against illegal constituents. Only abstract states and
4184 -- objects can appear on the right hand side of a refinement.
4186 if Is_Entity_Name
(Constit
) then
4187 Constit_Id
:= Entity_Of
(Constit
);
4189 if Present
(Constit_Id
)
4190 and then Ekind_In
(Constit_Id
, E_Abstract_State
,
4194 Remove
(States
, Constit_Id
);
4197 end Process_Constituent
;
4203 -- Start of processing for Process_Refinement_Clause
4206 if Nkind
(Clause
) = N_Component_Association
then
4207 Constit
:= Expression
(Clause
);
4209 -- Multiple constituents appear as an aggregate
4211 if Nkind
(Constit
) = N_Aggregate
then
4212 Constit
:= First
(Expressions
(Constit
));
4213 while Present
(Constit
) loop
4214 Process_Constituent
(Constit
);
4218 -- Various forms of a single constituent
4221 Process_Constituent
(Constit
);
4224 end Process_Refinement_Clause
;
4226 -------------------------------
4227 -- Report_Unused_Body_States --
4228 -------------------------------
4230 procedure Report_Unused_Body_States
(States
: Elist_Id
) is
4231 Posted
: Boolean := False;
4232 State_Elmt
: Elmt_Id
;
4233 State_Id
: Entity_Id
;
4236 if Present
(States
) then
4237 State_Elmt
:= First_Elmt
(States
);
4238 while Present
(State_Elmt
) loop
4239 State_Id
:= Node
(State_Elmt
);
4241 -- Constants are part of the hidden state of a package, but the
4242 -- compiler cannot determine whether they have variable input
4243 -- (SPARK RM 7.1.1(2)) and cannot classify them properly as a
4244 -- hidden state. Do not emit an error when a constant does not
4245 -- participate in a state refinement, even though it acts as a
4248 if Ekind
(State_Id
) = E_Constant
then
4251 -- Generate an error message of the form:
4253 -- body of package ... has unused hidden states
4254 -- abstract state ... defined at ...
4255 -- variable ... defined at ...
4261 ("body of package & has unused hidden states", Body_Id
);
4264 Error_Msg_Sloc
:= Sloc
(State_Id
);
4266 if Ekind
(State_Id
) = E_Abstract_State
then
4268 ("\abstract state & defined #", Body_Id
, State_Id
);
4271 SPARK_Msg_NE
("\variable & defined #", Body_Id
, State_Id
);
4275 Next_Elmt
(State_Elmt
);
4278 end Report_Unused_Body_States
;
4282 Prag
: constant Node_Id
:= Get_Pragma
(Body_Id
, Pragma_Refined_State
);
4283 Spec_Id
: constant Entity_Id
:= Spec_Entity
(Body_Id
);
4287 -- Start of processing for Check_Unused_Body_States
4290 -- Inspect the clauses of pragma Refined_State and determine whether all
4291 -- visible states declared within the package body participate in the
4294 if Present
(Prag
) then
4295 Clause
:= Expression
(Get_Argument
(Prag
, Spec_Id
));
4296 States
:= Collect_Body_States
(Body_Id
);
4298 -- Multiple non-null state refinements appear as an aggregate
4300 if Nkind
(Clause
) = N_Aggregate
then
4301 Clause
:= First
(Component_Associations
(Clause
));
4302 while Present
(Clause
) loop
4303 Process_Refinement_Clause
(Clause
, States
);
4307 -- Various forms of a single state refinement
4310 Process_Refinement_Clause
(Clause
, States
);
4313 -- Ensure that all abstract states and objects declared in the
4314 -- package body state space are utilized as constituents.
4316 Report_Unused_Body_States
(States
);
4318 end Check_Unused_Body_States
;
4324 function Choice_List
(N
: Node_Id
) return List_Id
is
4326 if Nkind
(N
) = N_Iterated_Component_Association
then
4327 return Discrete_Choices
(N
);
4333 -------------------------
4334 -- Collect_Body_States --
4335 -------------------------
4337 function Collect_Body_States
(Body_Id
: Entity_Id
) return Elist_Id
is
4338 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean;
4339 -- Determine whether object Obj_Id is a suitable visible state of a
4342 procedure Collect_Visible_States
4343 (Pack_Id
: Entity_Id
;
4344 States
: in out Elist_Id
);
4345 -- Gather the entities of all abstract states and objects declared in
4346 -- the visible state space of package Pack_Id.
4348 ----------------------------
4349 -- Collect_Visible_States --
4350 ----------------------------
4352 procedure Collect_Visible_States
4353 (Pack_Id
: Entity_Id
;
4354 States
: in out Elist_Id
)
4356 Item_Id
: Entity_Id
;
4359 -- Traverse the entity chain of the package and inspect all visible
4362 Item_Id
:= First_Entity
(Pack_Id
);
4363 while Present
(Item_Id
) and then not In_Private_Part
(Item_Id
) loop
4365 -- Do not consider internally generated items as those cannot be
4366 -- named and participate in refinement.
4368 if not Comes_From_Source
(Item_Id
) then
4371 elsif Ekind
(Item_Id
) = E_Abstract_State
then
4372 Append_New_Elmt
(Item_Id
, States
);
4374 elsif Ekind_In
(Item_Id
, E_Constant
, E_Variable
)
4375 and then Is_Visible_Object
(Item_Id
)
4377 Append_New_Elmt
(Item_Id
, States
);
4379 -- Recursively gather the visible states of a nested package
4381 elsif Ekind
(Item_Id
) = E_Package
then
4382 Collect_Visible_States
(Item_Id
, States
);
4385 Next_Entity
(Item_Id
);
4387 end Collect_Visible_States
;
4389 -----------------------
4390 -- Is_Visible_Object --
4391 -----------------------
4393 function Is_Visible_Object
(Obj_Id
: Entity_Id
) return Boolean is
4395 -- Objects that map generic formals to their actuals are not visible
4396 -- from outside the generic instantiation.
4398 if Present
(Corresponding_Generic_Association
4399 (Declaration_Node
(Obj_Id
)))
4403 -- Constituents of a single protected/task type act as components of
4404 -- the type and are not visible from outside the type.
4406 elsif Ekind
(Obj_Id
) = E_Variable
4407 and then Present
(Encapsulating_State
(Obj_Id
))
4408 and then Is_Single_Concurrent_Object
(Encapsulating_State
(Obj_Id
))
4415 end Is_Visible_Object
;
4419 Body_Decl
: constant Node_Id
:= Unit_Declaration_Node
(Body_Id
);
4421 Item_Id
: Entity_Id
;
4422 States
: Elist_Id
:= No_Elist
;
4424 -- Start of processing for Collect_Body_States
4427 -- Inspect the declarations of the body looking for source objects,
4428 -- packages and package instantiations. Note that even though this
4429 -- processing is very similar to Collect_Visible_States, a package
4430 -- body does not have a First/Next_Entity list.
4432 Decl
:= First
(Declarations
(Body_Decl
));
4433 while Present
(Decl
) loop
4435 -- Capture source objects as internally generated temporaries cannot
4436 -- be named and participate in refinement.
4438 if Nkind
(Decl
) = N_Object_Declaration
then
4439 Item_Id
:= Defining_Entity
(Decl
);
4441 if Comes_From_Source
(Item_Id
)
4442 and then Is_Visible_Object
(Item_Id
)
4444 Append_New_Elmt
(Item_Id
, States
);
4447 -- Capture the visible abstract states and objects of a source
4448 -- package [instantiation].
4450 elsif Nkind
(Decl
) = N_Package_Declaration
then
4451 Item_Id
:= Defining_Entity
(Decl
);
4453 if Comes_From_Source
(Item_Id
) then
4454 Collect_Visible_States
(Item_Id
, States
);
4462 end Collect_Body_States
;
4464 ------------------------
4465 -- Collect_Interfaces --
4466 ------------------------
4468 procedure Collect_Interfaces
4470 Ifaces_List
: out Elist_Id
;
4471 Exclude_Parents
: Boolean := False;
4472 Use_Full_View
: Boolean := True)
4474 procedure Collect
(Typ
: Entity_Id
);
4475 -- Subsidiary subprogram used to traverse the whole list
4476 -- of directly and indirectly implemented interfaces
4482 procedure Collect
(Typ
: Entity_Id
) is
4483 Ancestor
: Entity_Id
;
4491 -- Handle private types and subtypes
4494 and then Is_Private_Type
(Typ
)
4495 and then Present
(Full_View
(Typ
))
4497 Full_T
:= Full_View
(Typ
);
4499 if Ekind
(Full_T
) = E_Record_Subtype
then
4500 Full_T
:= Etype
(Typ
);
4502 if Present
(Full_View
(Full_T
)) then
4503 Full_T
:= Full_View
(Full_T
);
4508 -- Include the ancestor if we are generating the whole list of
4509 -- abstract interfaces.
4511 if Etype
(Full_T
) /= Typ
4513 -- Protect the frontend against wrong sources. For example:
4516 -- type A is tagged null record;
4517 -- type B is new A with private;
4518 -- type C is new A with private;
4520 -- type B is new C with null record;
4521 -- type C is new B with null record;
4524 and then Etype
(Full_T
) /= T
4526 Ancestor
:= Etype
(Full_T
);
4529 if Is_Interface
(Ancestor
) and then not Exclude_Parents
then
4530 Append_Unique_Elmt
(Ancestor
, Ifaces_List
);
4534 -- Traverse the graph of ancestor interfaces
4536 if Is_Non_Empty_List
(Abstract_Interface_List
(Full_T
)) then
4537 Id
:= First
(Abstract_Interface_List
(Full_T
));
4538 while Present
(Id
) loop
4539 Iface
:= Etype
(Id
);
4541 -- Protect against wrong uses. For example:
4542 -- type I is interface;
4543 -- type O is tagged null record;
4544 -- type Wrong is new I and O with null record; -- ERROR
4546 if Is_Interface
(Iface
) then
4548 and then Etype
(T
) /= T
4549 and then Interface_Present_In_Ancestor
(Etype
(T
), Iface
)
4554 Append_Unique_Elmt
(Iface
, Ifaces_List
);
4563 -- Start of processing for Collect_Interfaces
4566 pragma Assert
(Is_Tagged_Type
(T
) or else Is_Concurrent_Type
(T
));
4567 Ifaces_List
:= New_Elmt_List
;
4569 end Collect_Interfaces
;
4571 ----------------------------------
4572 -- Collect_Interface_Components --
4573 ----------------------------------
4575 procedure Collect_Interface_Components
4576 (Tagged_Type
: Entity_Id
;
4577 Components_List
: out Elist_Id
)
4579 procedure Collect
(Typ
: Entity_Id
);
4580 -- Subsidiary subprogram used to climb to the parents
4586 procedure Collect
(Typ
: Entity_Id
) is
4587 Tag_Comp
: Entity_Id
;
4588 Parent_Typ
: Entity_Id
;
4591 -- Handle private types
4593 if Present
(Full_View
(Etype
(Typ
))) then
4594 Parent_Typ
:= Full_View
(Etype
(Typ
));
4596 Parent_Typ
:= Etype
(Typ
);
4599 if Parent_Typ
/= Typ
4601 -- Protect the frontend against wrong sources. For example:
4604 -- type A is tagged null record;
4605 -- type B is new A with private;
4606 -- type C is new A with private;
4608 -- type B is new C with null record;
4609 -- type C is new B with null record;
4612 and then Parent_Typ
/= Tagged_Type
4614 Collect
(Parent_Typ
);
4617 -- Collect the components containing tags of secondary dispatch
4620 Tag_Comp
:= Next_Tag_Component
(First_Tag_Component
(Typ
));
4621 while Present
(Tag_Comp
) loop
4622 pragma Assert
(Present
(Related_Type
(Tag_Comp
)));
4623 Append_Elmt
(Tag_Comp
, Components_List
);
4625 Tag_Comp
:= Next_Tag_Component
(Tag_Comp
);
4629 -- Start of processing for Collect_Interface_Components
4632 pragma Assert
(Ekind
(Tagged_Type
) = E_Record_Type
4633 and then Is_Tagged_Type
(Tagged_Type
));
4635 Components_List
:= New_Elmt_List
;
4636 Collect
(Tagged_Type
);
4637 end Collect_Interface_Components
;
4639 -----------------------------
4640 -- Collect_Interfaces_Info --
4641 -----------------------------
4643 procedure Collect_Interfaces_Info
4645 Ifaces_List
: out Elist_Id
;
4646 Components_List
: out Elist_Id
;
4647 Tags_List
: out Elist_Id
)
4649 Comps_List
: Elist_Id
;
4650 Comp_Elmt
: Elmt_Id
;
4651 Comp_Iface
: Entity_Id
;
4652 Iface_Elmt
: Elmt_Id
;
4655 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
;
4656 -- Search for the secondary tag associated with the interface type
4657 -- Iface that is implemented by T.
4663 function Search_Tag
(Iface
: Entity_Id
) return Entity_Id
is
4666 if not Is_CPP_Class
(T
) then
4667 ADT
:= Next_Elmt
(Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
))));
4669 ADT
:= Next_Elmt
(First_Elmt
(Access_Disp_Table
(T
)));
4673 and then Is_Tag
(Node
(ADT
))
4674 and then Related_Type
(Node
(ADT
)) /= Iface
4676 -- Skip secondary dispatch table referencing thunks to user
4677 -- defined primitives covered by this interface.
4679 pragma Assert
(Has_Suffix
(Node
(ADT
), 'P'));
4682 -- Skip secondary dispatch tables of Ada types
4684 if not Is_CPP_Class
(T
) then
4686 -- Skip secondary dispatch table referencing thunks to
4687 -- predefined primitives.
4689 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Y'));
4692 -- Skip secondary dispatch table referencing user-defined
4693 -- primitives covered by this interface.
4695 pragma Assert
(Has_Suffix
(Node
(ADT
), 'D'));
4698 -- Skip secondary dispatch table referencing predefined
4701 pragma Assert
(Has_Suffix
(Node
(ADT
), 'Z'));
4706 pragma Assert
(Is_Tag
(Node
(ADT
)));
4710 -- Start of processing for Collect_Interfaces_Info
4713 Collect_Interfaces
(T
, Ifaces_List
);
4714 Collect_Interface_Components
(T
, Comps_List
);
4716 -- Search for the record component and tag associated with each
4717 -- interface type of T.
4719 Components_List
:= New_Elmt_List
;
4720 Tags_List
:= New_Elmt_List
;
4722 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
4723 while Present
(Iface_Elmt
) loop
4724 Iface
:= Node
(Iface_Elmt
);
4726 -- Associate the primary tag component and the primary dispatch table
4727 -- with all the interfaces that are parents of T
4729 if Is_Ancestor
(Iface
, T
, Use_Full_View
=> True) then
4730 Append_Elmt
(First_Tag_Component
(T
), Components_List
);
4731 Append_Elmt
(Node
(First_Elmt
(Access_Disp_Table
(T
))), Tags_List
);
4733 -- Otherwise search for the tag component and secondary dispatch
4737 Comp_Elmt
:= First_Elmt
(Comps_List
);
4738 while Present
(Comp_Elmt
) loop
4739 Comp_Iface
:= Related_Type
(Node
(Comp_Elmt
));
4741 if Comp_Iface
= Iface
4742 or else Is_Ancestor
(Iface
, Comp_Iface
, Use_Full_View
=> True)
4744 Append_Elmt
(Node
(Comp_Elmt
), Components_List
);
4745 Append_Elmt
(Search_Tag
(Comp_Iface
), Tags_List
);
4749 Next_Elmt
(Comp_Elmt
);
4751 pragma Assert
(Present
(Comp_Elmt
));
4754 Next_Elmt
(Iface_Elmt
);
4756 end Collect_Interfaces_Info
;
4758 ---------------------
4759 -- Collect_Parents --
4760 ---------------------
4762 procedure Collect_Parents
4764 List
: out Elist_Id
;
4765 Use_Full_View
: Boolean := True)
4767 Current_Typ
: Entity_Id
:= T
;
4768 Parent_Typ
: Entity_Id
;
4771 List
:= New_Elmt_List
;
4773 -- No action if the if the type has no parents
4775 if T
= Etype
(T
) then
4780 Parent_Typ
:= Etype
(Current_Typ
);
4782 if Is_Private_Type
(Parent_Typ
)
4783 and then Present
(Full_View
(Parent_Typ
))
4784 and then Use_Full_View
4786 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
4789 Append_Elmt
(Parent_Typ
, List
);
4791 exit when Parent_Typ
= Current_Typ
;
4792 Current_Typ
:= Parent_Typ
;
4794 end Collect_Parents
;
4796 ----------------------------------
4797 -- Collect_Primitive_Operations --
4798 ----------------------------------
4800 function Collect_Primitive_Operations
(T
: Entity_Id
) return Elist_Id
is
4801 B_Type
: constant Entity_Id
:= Base_Type
(T
);
4802 B_Decl
: constant Node_Id
:= Original_Node
(Parent
(B_Type
));
4803 B_Scope
: Entity_Id
:= Scope
(B_Type
);
4807 Is_Type_In_Pkg
: Boolean;
4808 Formal_Derived
: Boolean := False;
4811 function Match
(E
: Entity_Id
) return Boolean;
4812 -- True if E's base type is B_Type, or E is of an anonymous access type
4813 -- and the base type of its designated type is B_Type.
4819 function Match
(E
: Entity_Id
) return Boolean is
4820 Etyp
: Entity_Id
:= Etype
(E
);
4823 if Ekind
(Etyp
) = E_Anonymous_Access_Type
then
4824 Etyp
:= Designated_Type
(Etyp
);
4827 -- In Ada 2012 a primitive operation may have a formal of an
4828 -- incomplete view of the parent type.
4830 return Base_Type
(Etyp
) = B_Type
4832 (Ada_Version
>= Ada_2012
4833 and then Ekind
(Etyp
) = E_Incomplete_Type
4834 and then Full_View
(Etyp
) = B_Type
);
4837 -- Start of processing for Collect_Primitive_Operations
4840 -- For tagged types, the primitive operations are collected as they
4841 -- are declared, and held in an explicit list which is simply returned.
4843 if Is_Tagged_Type
(B_Type
) then
4844 return Primitive_Operations
(B_Type
);
4846 -- An untagged generic type that is a derived type inherits the
4847 -- primitive operations of its parent type. Other formal types only
4848 -- have predefined operators, which are not explicitly represented.
4850 elsif Is_Generic_Type
(B_Type
) then
4851 if Nkind
(B_Decl
) = N_Formal_Type_Declaration
4852 and then Nkind
(Formal_Type_Definition
(B_Decl
)) =
4853 N_Formal_Derived_Type_Definition
4855 Formal_Derived
:= True;
4857 return New_Elmt_List
;
4861 Op_List
:= New_Elmt_List
;
4863 if B_Scope
= Standard_Standard
then
4864 if B_Type
= Standard_String
then
4865 Append_Elmt
(Standard_Op_Concat
, Op_List
);
4867 elsif B_Type
= Standard_Wide_String
then
4868 Append_Elmt
(Standard_Op_Concatw
, Op_List
);
4874 -- Locate the primitive subprograms of the type
4877 -- The primitive operations appear after the base type, except
4878 -- if the derivation happens within the private part of B_Scope
4879 -- and the type is a private type, in which case both the type
4880 -- and some primitive operations may appear before the base
4881 -- type, and the list of candidates starts after the type.
4883 if In_Open_Scopes
(B_Scope
)
4884 and then Scope
(T
) = B_Scope
4885 and then In_Private_Part
(B_Scope
)
4887 Id
:= Next_Entity
(T
);
4889 -- In Ada 2012, If the type has an incomplete partial view, there
4890 -- may be primitive operations declared before the full view, so
4891 -- we need to start scanning from the incomplete view, which is
4892 -- earlier on the entity chain.
4894 elsif Nkind
(Parent
(B_Type
)) = N_Full_Type_Declaration
4895 and then Present
(Incomplete_View
(Parent
(B_Type
)))
4897 Id
:= Defining_Entity
(Incomplete_View
(Parent
(B_Type
)));
4899 -- If T is a derived from a type with an incomplete view declared
4900 -- elsewhere, that incomplete view is irrelevant, we want the
4901 -- operations in the scope of T.
4903 if Scope
(Id
) /= Scope
(B_Type
) then
4904 Id
:= Next_Entity
(B_Type
);
4908 Id
:= Next_Entity
(B_Type
);
4911 -- Set flag if this is a type in a package spec
4914 Is_Package_Or_Generic_Package
(B_Scope
)
4916 Nkind
(Parent
(Declaration_Node
(First_Subtype
(T
)))) /=
4919 while Present
(Id
) loop
4921 -- Test whether the result type or any of the parameter types of
4922 -- each subprogram following the type match that type when the
4923 -- type is declared in a package spec, is a derived type, or the
4924 -- subprogram is marked as primitive. (The Is_Primitive test is
4925 -- needed to find primitives of nonderived types in declarative
4926 -- parts that happen to override the predefined "=" operator.)
4928 -- Note that generic formal subprograms are not considered to be
4929 -- primitive operations and thus are never inherited.
4931 if Is_Overloadable
(Id
)
4932 and then (Is_Type_In_Pkg
4933 or else Is_Derived_Type
(B_Type
)
4934 or else Is_Primitive
(Id
))
4935 and then Nkind
(Parent
(Parent
(Id
)))
4936 not in N_Formal_Subprogram_Declaration
4944 Formal
:= First_Formal
(Id
);
4945 while Present
(Formal
) loop
4946 if Match
(Formal
) then
4951 Next_Formal
(Formal
);
4955 -- For a formal derived type, the only primitives are the ones
4956 -- inherited from the parent type. Operations appearing in the
4957 -- package declaration are not primitive for it.
4960 and then (not Formal_Derived
or else Present
(Alias
(Id
)))
4962 -- In the special case of an equality operator aliased to
4963 -- an overriding dispatching equality belonging to the same
4964 -- type, we don't include it in the list of primitives.
4965 -- This avoids inheriting multiple equality operators when
4966 -- deriving from untagged private types whose full type is
4967 -- tagged, which can otherwise cause ambiguities. Note that
4968 -- this should only happen for this kind of untagged parent
4969 -- type, since normally dispatching operations are inherited
4970 -- using the type's Primitive_Operations list.
4972 if Chars
(Id
) = Name_Op_Eq
4973 and then Is_Dispatching_Operation
(Id
)
4974 and then Present
(Alias
(Id
))
4975 and then Present
(Overridden_Operation
(Alias
(Id
)))
4976 and then Base_Type
(Etype
(First_Entity
(Id
))) =
4977 Base_Type
(Etype
(First_Entity
(Alias
(Id
))))
4981 -- Include the subprogram in the list of primitives
4984 Append_Elmt
(Id
, Op_List
);
4991 -- For a type declared in System, some of its operations may
4992 -- appear in the target-specific extension to System.
4995 and then B_Scope
= RTU_Entity
(System
)
4996 and then Present_System_Aux
4998 B_Scope
:= System_Aux_Id
;
4999 Id
:= First_Entity
(System_Aux_Id
);
5005 end Collect_Primitive_Operations
;
5007 -----------------------------------
5008 -- Compile_Time_Constraint_Error --
5009 -----------------------------------
5011 function Compile_Time_Constraint_Error
5014 Ent
: Entity_Id
:= Empty
;
5015 Loc
: Source_Ptr
:= No_Location
;
5016 Warn
: Boolean := False) return Node_Id
5018 Msgc
: String (1 .. Msg
'Length + 3);
5019 -- Copy of message, with room for possible ?? or << and ! at end
5025 -- Start of processing for Compile_Time_Constraint_Error
5028 -- If this is a warning, convert it into an error if we are in code
5029 -- subject to SPARK_Mode being set On, unless Warn is True to force a
5030 -- warning. The rationale is that a compile-time constraint error should
5031 -- lead to an error instead of a warning when SPARK_Mode is On, but in
5032 -- a few cases we prefer to issue a warning and generate both a suitable
5033 -- run-time error in GNAT and a suitable check message in GNATprove.
5034 -- Those cases are those that likely correspond to deactivated SPARK
5035 -- code, so that this kind of code can be compiled and analyzed instead
5036 -- of being rejected.
5038 Error_Msg_Warn
:= Warn
or SPARK_Mode
/= On
;
5040 -- A static constraint error in an instance body is not a fatal error.
5041 -- we choose to inhibit the message altogether, because there is no
5042 -- obvious node (for now) on which to post it. On the other hand the
5043 -- offending node must be replaced with a constraint_error in any case.
5045 -- No messages are generated if we already posted an error on this node
5047 if not Error_Posted
(N
) then
5048 if Loc
/= No_Location
then
5054 -- Copy message to Msgc, converting any ? in the message into <
5055 -- instead, so that we have an error in GNATprove mode.
5059 for J
in 1 .. Msgl
loop
5060 if Msg
(J
) = '?' and then (J
= 1 or else Msg
(J
- 1) /= ''') then
5063 Msgc
(J
) := Msg
(J
);
5067 -- Message is a warning, even in Ada 95 case
5069 if Msg
(Msg
'Last) = '?' or else Msg
(Msg
'Last) = '<' then
5072 -- In Ada 83, all messages are warnings. In the private part and the
5073 -- body of an instance, constraint_checks are only warnings. We also
5074 -- make this a warning if the Warn parameter is set.
5077 or else (Ada_Version
= Ada_83
and then Comes_From_Source
(N
))
5078 or else In_Instance_Not_Visible
5086 -- Otherwise we have a real error message (Ada 95 static case) and we
5087 -- make this an unconditional message. Note that in the warning case
5088 -- we do not make the message unconditional, it seems reasonable to
5089 -- delete messages like this (about exceptions that will be raised)
5098 -- One more test, skip the warning if the related expression is
5099 -- statically unevaluated, since we don't want to warn about what
5100 -- will happen when something is evaluated if it never will be
5103 if not Is_Statically_Unevaluated
(N
) then
5104 if Present
(Ent
) then
5105 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Ent
, Eloc
);
5107 Error_Msg_NEL
(Msgc
(1 .. Msgl
), N
, Etype
(N
), Eloc
);
5112 -- Check whether the context is an Init_Proc
5114 if Inside_Init_Proc
then
5116 Conc_Typ
: constant Entity_Id
:=
5117 Corresponding_Concurrent_Type
5118 (Entity
(Parameter_Type
(First
5119 (Parameter_Specifications
5120 (Parent
(Current_Scope
))))));
5123 -- Don't complain if the corresponding concurrent type
5124 -- doesn't come from source (i.e. a single task/protected
5127 if Present
(Conc_Typ
)
5128 and then not Comes_From_Source
(Conc_Typ
)
5131 ("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
5134 if GNATprove_Mode
then
5136 ("\& would have been raised for objects of this "
5137 & "type", N
, Standard_Constraint_Error
, Eloc
);
5140 ("\& will be raised for objects of this type??",
5141 N
, Standard_Constraint_Error
, Eloc
);
5147 Error_Msg_NEL
("\& [<<", N
, Standard_Constraint_Error
, Eloc
);
5151 Error_Msg
("\static expression fails Constraint_Check", Eloc
);
5152 Set_Error_Posted
(N
);
5158 end Compile_Time_Constraint_Error
;
5160 -----------------------
5161 -- Conditional_Delay --
5162 -----------------------
5164 procedure Conditional_Delay
(New_Ent
, Old_Ent
: Entity_Id
) is
5166 if Has_Delayed_Freeze
(Old_Ent
) and then not Is_Frozen
(Old_Ent
) then
5167 Set_Has_Delayed_Freeze
(New_Ent
);
5169 end Conditional_Delay
;
5171 ----------------------------
5172 -- Contains_Refined_State --
5173 ----------------------------
5175 function Contains_Refined_State
(Prag
: Node_Id
) return Boolean is
5176 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean;
5177 -- Determine whether a dependency list mentions a state with a visible
5180 function Has_State_In_Global
(List
: Node_Id
) return Boolean;
5181 -- Determine whether a global list mentions a state with a visible
5184 function Is_Refined_State
(Item
: Node_Id
) return Boolean;
5185 -- Determine whether Item is a reference to an abstract state with a
5186 -- visible refinement.
5188 -----------------------------
5189 -- Has_State_In_Dependency --
5190 -----------------------------
5192 function Has_State_In_Dependency
(List
: Node_Id
) return Boolean is
5197 -- A null dependency list does not mention any states
5199 if Nkind
(List
) = N_Null
then
5202 -- Dependency clauses appear as component associations of an
5205 elsif Nkind
(List
) = N_Aggregate
5206 and then Present
(Component_Associations
(List
))
5208 Clause
:= First
(Component_Associations
(List
));
5209 while Present
(Clause
) loop
5211 -- Inspect the outputs of a dependency clause
5213 Output
:= First
(Choices
(Clause
));
5214 while Present
(Output
) loop
5215 if Is_Refined_State
(Output
) then
5222 -- Inspect the outputs of a dependency clause
5224 if Is_Refined_State
(Expression
(Clause
)) then
5231 -- If we get here, then none of the dependency clauses mention a
5232 -- state with visible refinement.
5236 -- An illegal pragma managed to sneak in
5239 raise Program_Error
;
5241 end Has_State_In_Dependency
;
5243 -------------------------
5244 -- Has_State_In_Global --
5245 -------------------------
5247 function Has_State_In_Global
(List
: Node_Id
) return Boolean is
5251 -- A null global list does not mention any states
5253 if Nkind
(List
) = N_Null
then
5256 -- Simple global list or moded global list declaration
5258 elsif Nkind
(List
) = N_Aggregate
then
5260 -- The declaration of a simple global list appear as a collection
5263 if Present
(Expressions
(List
)) then
5264 Item
:= First
(Expressions
(List
));
5265 while Present
(Item
) loop
5266 if Is_Refined_State
(Item
) then
5273 -- The declaration of a moded global list appears as a collection
5274 -- of component associations where individual choices denote
5278 Item
:= First
(Component_Associations
(List
));
5279 while Present
(Item
) loop
5280 if Has_State_In_Global
(Expression
(Item
)) then
5288 -- If we get here, then the simple/moded global list did not
5289 -- mention any states with a visible refinement.
5293 -- Single global item declaration
5295 elsif Is_Entity_Name
(List
) then
5296 return Is_Refined_State
(List
);
5298 -- An illegal pragma managed to sneak in
5301 raise Program_Error
;
5303 end Has_State_In_Global
;
5305 ----------------------
5306 -- Is_Refined_State --
5307 ----------------------
5309 function Is_Refined_State
(Item
: Node_Id
) return Boolean is
5311 Item_Id
: Entity_Id
;
5314 if Nkind
(Item
) = N_Null
then
5317 -- States cannot be subject to attribute 'Result. This case arises
5318 -- in dependency relations.
5320 elsif Nkind
(Item
) = N_Attribute_Reference
5321 and then Attribute_Name
(Item
) = Name_Result
5325 -- Multiple items appear as an aggregate. This case arises in
5326 -- dependency relations.
5328 elsif Nkind
(Item
) = N_Aggregate
5329 and then Present
(Expressions
(Item
))
5331 Elmt
:= First
(Expressions
(Item
));
5332 while Present
(Elmt
) loop
5333 if Is_Refined_State
(Elmt
) then
5340 -- If we get here, then none of the inputs or outputs reference a
5341 -- state with visible refinement.
5348 Item_Id
:= Entity_Of
(Item
);
5352 and then Ekind
(Item_Id
) = E_Abstract_State
5353 and then Has_Visible_Refinement
(Item_Id
);
5355 end Is_Refined_State
;
5359 Arg
: constant Node_Id
:=
5360 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(Prag
)));
5361 Nam
: constant Name_Id
:= Pragma_Name
(Prag
);
5363 -- Start of processing for Contains_Refined_State
5366 if Nam
= Name_Depends
then
5367 return Has_State_In_Dependency
(Arg
);
5369 else pragma Assert
(Nam
= Name_Global
);
5370 return Has_State_In_Global
(Arg
);
5372 end Contains_Refined_State
;
5374 -------------------------
5375 -- Copy_Component_List --
5376 -------------------------
5378 function Copy_Component_List
5380 Loc
: Source_Ptr
) return List_Id
5383 Comps
: constant List_Id
:= New_List
;
5386 Comp
:= First_Component
(Underlying_Type
(R_Typ
));
5387 while Present
(Comp
) loop
5388 if Comes_From_Source
(Comp
) then
5390 Comp_Decl
: constant Node_Id
:= Declaration_Node
(Comp
);
5393 Make_Component_Declaration
(Loc
,
5394 Defining_Identifier
=>
5395 Make_Defining_Identifier
(Loc
, Chars
(Comp
)),
5396 Component_Definition
=>
5398 (Component_Definition
(Comp_Decl
), New_Sloc
=> Loc
)));
5402 Next_Component
(Comp
);
5406 end Copy_Component_List
;
5408 -------------------------
5409 -- Copy_Parameter_List --
5410 -------------------------
5412 function Copy_Parameter_List
(Subp_Id
: Entity_Id
) return List_Id
is
5413 Loc
: constant Source_Ptr
:= Sloc
(Subp_Id
);
5418 if No
(First_Formal
(Subp_Id
)) then
5422 Formal
:= First_Formal
(Subp_Id
);
5423 while Present
(Formal
) loop
5425 Make_Parameter_Specification
(Loc
,
5426 Defining_Identifier
=>
5427 Make_Defining_Identifier
(Sloc
(Formal
), Chars
(Formal
)),
5428 In_Present
=> In_Present
(Parent
(Formal
)),
5429 Out_Present
=> Out_Present
(Parent
(Formal
)),
5431 New_Occurrence_Of
(Etype
(Formal
), Loc
),
5433 New_Copy_Tree
(Expression
(Parent
(Formal
)))));
5435 Next_Formal
(Formal
);
5440 end Copy_Parameter_List
;
5442 ----------------------------
5443 -- Copy_SPARK_Mode_Aspect --
5444 ----------------------------
5446 procedure Copy_SPARK_Mode_Aspect
(From
: Node_Id
; To
: Node_Id
) is
5447 pragma Assert
(not Has_Aspects
(To
));
5451 if Has_Aspects
(From
) then
5452 Asp
:= Find_Aspect
(Defining_Entity
(From
), Aspect_SPARK_Mode
);
5454 if Present
(Asp
) then
5455 Set_Aspect_Specifications
(To
, New_List
(New_Copy_Tree
(Asp
)));
5456 Set_Has_Aspects
(To
, True);
5459 end Copy_SPARK_Mode_Aspect
;
5461 --------------------------
5462 -- Copy_Subprogram_Spec --
5463 --------------------------
5465 function Copy_Subprogram_Spec
(Spec
: Node_Id
) return Node_Id
is
5467 Formal_Spec
: Node_Id
;
5471 -- The structure of the original tree must be replicated without any
5472 -- alterations. Use New_Copy_Tree for this purpose.
5474 Result
:= New_Copy_Tree
(Spec
);
5476 -- However, the spec of a null procedure carries the corresponding null
5477 -- statement of the body (created by the parser), and this cannot be
5478 -- shared with the new subprogram spec.
5480 if Nkind
(Result
) = N_Procedure_Specification
then
5481 Set_Null_Statement
(Result
, Empty
);
5484 -- Create a new entity for the defining unit name
5486 Def_Id
:= Defining_Unit_Name
(Result
);
5487 Set_Defining_Unit_Name
(Result
,
5488 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
5490 -- Create new entities for the formal parameters
5492 if Present
(Parameter_Specifications
(Result
)) then
5493 Formal_Spec
:= First
(Parameter_Specifications
(Result
));
5494 while Present
(Formal_Spec
) loop
5495 Def_Id
:= Defining_Identifier
(Formal_Spec
);
5496 Set_Defining_Identifier
(Formal_Spec
,
5497 Make_Defining_Identifier
(Sloc
(Def_Id
), Chars
(Def_Id
)));
5504 end Copy_Subprogram_Spec
;
5506 --------------------------------
5507 -- Corresponding_Generic_Type --
5508 --------------------------------
5510 function Corresponding_Generic_Type
(T
: Entity_Id
) return Entity_Id
is
5516 if not Is_Generic_Actual_Type
(T
) then
5519 -- If the actual is the actual of an enclosing instance, resolution
5520 -- was correct in the generic.
5522 elsif Nkind
(Parent
(T
)) = N_Subtype_Declaration
5523 and then Is_Entity_Name
(Subtype_Indication
(Parent
(T
)))
5525 Is_Generic_Actual_Type
(Entity
(Subtype_Indication
(Parent
(T
))))
5532 if Is_Wrapper_Package
(Inst
) then
5533 Inst
:= Related_Instance
(Inst
);
5538 (Specification
(Unit_Declaration_Node
(Inst
)));
5540 -- Generic actual has the same name as the corresponding formal
5542 Typ
:= First_Entity
(Gen
);
5543 while Present
(Typ
) loop
5544 if Chars
(Typ
) = Chars
(T
) then
5553 end Corresponding_Generic_Type
;
5555 --------------------
5556 -- Current_Entity --
5557 --------------------
5559 -- The currently visible definition for a given identifier is the
5560 -- one most chained at the start of the visibility chain, i.e. the
5561 -- one that is referenced by the Node_Id value of the name of the
5562 -- given identifier.
5564 function Current_Entity
(N
: Node_Id
) return Entity_Id
is
5566 return Get_Name_Entity_Id
(Chars
(N
));
5569 -----------------------------
5570 -- Current_Entity_In_Scope --
5571 -----------------------------
5573 function Current_Entity_In_Scope
(N
: Node_Id
) return Entity_Id
is
5575 CS
: constant Entity_Id
:= Current_Scope
;
5577 Transient_Case
: constant Boolean := Scope_Is_Transient
;
5580 E
:= Get_Name_Entity_Id
(Chars
(N
));
5582 and then Scope
(E
) /= CS
5583 and then (not Transient_Case
or else Scope
(E
) /= Scope
(CS
))
5589 end Current_Entity_In_Scope
;
5595 function Current_Scope
return Entity_Id
is
5597 if Scope_Stack
.Last
= -1 then
5598 return Standard_Standard
;
5601 C
: constant Entity_Id
:=
5602 Scope_Stack
.Table
(Scope_Stack
.Last
).Entity
;
5607 return Standard_Standard
;
5613 ----------------------------
5614 -- Current_Scope_No_Loops --
5615 ----------------------------
5617 function Current_Scope_No_Loops
return Entity_Id
is
5621 -- Examine the scope stack starting from the current scope and skip any
5622 -- internally generated loops.
5625 while Present
(S
) and then S
/= Standard_Standard
loop
5626 if Ekind
(S
) = E_Loop
and then not Comes_From_Source
(S
) then
5634 end Current_Scope_No_Loops
;
5636 ------------------------
5637 -- Current_Subprogram --
5638 ------------------------
5640 function Current_Subprogram
return Entity_Id
is
5641 Scop
: constant Entity_Id
:= Current_Scope
;
5643 if Is_Subprogram_Or_Generic_Subprogram
(Scop
) then
5646 return Enclosing_Subprogram
(Scop
);
5648 end Current_Subprogram
;
5650 ----------------------------------
5651 -- Deepest_Type_Access_Level --
5652 ----------------------------------
5654 function Deepest_Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
5656 if Ekind
(Typ
) = E_Anonymous_Access_Type
5657 and then not Is_Local_Anonymous_Access
(Typ
)
5658 and then Nkind
(Associated_Node_For_Itype
(Typ
)) = N_Object_Declaration
5660 -- Typ is the type of an Ada 2012 stand-alone object of an anonymous
5664 Scope_Depth
(Enclosing_Dynamic_Scope
5665 (Defining_Identifier
5666 (Associated_Node_For_Itype
(Typ
))));
5668 -- For generic formal type, return Int'Last (infinite).
5669 -- See comment preceding Is_Generic_Type call in Type_Access_Level.
5671 elsif Is_Generic_Type
(Root_Type
(Typ
)) then
5672 return UI_From_Int
(Int
'Last);
5675 return Type_Access_Level
(Typ
);
5677 end Deepest_Type_Access_Level
;
5679 ---------------------
5680 -- Defining_Entity --
5681 ---------------------
5683 function Defining_Entity
5685 Empty_On_Errors
: Boolean := False) return Entity_Id
5687 Err
: Entity_Id
:= Empty
;
5691 when N_Abstract_Subprogram_Declaration
5692 | N_Expression_Function
5693 | N_Formal_Subprogram_Declaration
5694 | N_Generic_Package_Declaration
5695 | N_Generic_Subprogram_Declaration
5696 | N_Package_Declaration
5698 | N_Subprogram_Body_Stub
5699 | N_Subprogram_Declaration
5700 | N_Subprogram_Renaming_Declaration
5702 return Defining_Entity
(Specification
(N
));
5704 when N_Component_Declaration
5705 | N_Defining_Program_Unit_Name
5706 | N_Discriminant_Specification
5708 | N_Entry_Declaration
5709 | N_Entry_Index_Specification
5710 | N_Exception_Declaration
5711 | N_Exception_Renaming_Declaration
5712 | N_Formal_Object_Declaration
5713 | N_Formal_Package_Declaration
5714 | N_Formal_Type_Declaration
5715 | N_Full_Type_Declaration
5716 | N_Implicit_Label_Declaration
5717 | N_Incomplete_Type_Declaration
5718 | N_Iterator_Specification
5719 | N_Loop_Parameter_Specification
5720 | N_Number_Declaration
5721 | N_Object_Declaration
5722 | N_Object_Renaming_Declaration
5723 | N_Package_Body_Stub
5724 | N_Parameter_Specification
5725 | N_Private_Extension_Declaration
5726 | N_Private_Type_Declaration
5728 | N_Protected_Body_Stub
5729 | N_Protected_Type_Declaration
5730 | N_Single_Protected_Declaration
5731 | N_Single_Task_Declaration
5732 | N_Subtype_Declaration
5735 | N_Task_Type_Declaration
5737 return Defining_Identifier
(N
);
5740 return Defining_Entity
(Proper_Body
(N
));
5742 when N_Function_Instantiation
5743 | N_Function_Specification
5744 | N_Generic_Function_Renaming_Declaration
5745 | N_Generic_Package_Renaming_Declaration
5746 | N_Generic_Procedure_Renaming_Declaration
5748 | N_Package_Instantiation
5749 | N_Package_Renaming_Declaration
5750 | N_Package_Specification
5751 | N_Procedure_Instantiation
5752 | N_Procedure_Specification
5755 Nam
: constant Node_Id
:= Defining_Unit_Name
(N
);
5758 if Nkind
(Nam
) in N_Entity
then
5761 -- For Error, make up a name and attach to declaration so we
5762 -- can continue semantic analysis.
5764 elsif Nam
= Error
then
5765 if Empty_On_Errors
then
5768 Err
:= Make_Temporary
(Sloc
(N
), 'T');
5769 Set_Defining_Unit_Name
(N
, Err
);
5774 -- If not an entity, get defining identifier
5777 return Defining_Identifier
(Nam
);
5781 when N_Block_Statement
5784 return Entity
(Identifier
(N
));
5787 if Empty_On_Errors
then
5790 raise Program_Error
;
5793 end Defining_Entity
;
5795 --------------------------
5796 -- Denotes_Discriminant --
5797 --------------------------
5799 function Denotes_Discriminant
5801 Check_Concurrent
: Boolean := False) return Boolean
5806 if not Is_Entity_Name
(N
) or else No
(Entity
(N
)) then
5812 -- If we are checking for a protected type, the discriminant may have
5813 -- been rewritten as the corresponding discriminal of the original type
5814 -- or of the corresponding concurrent record, depending on whether we
5815 -- are in the spec or body of the protected type.
5817 return Ekind
(E
) = E_Discriminant
5820 and then Ekind
(E
) = E_In_Parameter
5821 and then Present
(Discriminal_Link
(E
))
5823 (Is_Concurrent_Type
(Scope
(Discriminal_Link
(E
)))
5825 Is_Concurrent_Record_Type
(Scope
(Discriminal_Link
(E
)))));
5826 end Denotes_Discriminant
;
5828 -------------------------
5829 -- Denotes_Same_Object --
5830 -------------------------
5832 function Denotes_Same_Object
(A1
, A2
: Node_Id
) return Boolean is
5833 Obj1
: Node_Id
:= A1
;
5834 Obj2
: Node_Id
:= A2
;
5836 function Has_Prefix
(N
: Node_Id
) return Boolean;
5837 -- Return True if N has attribute Prefix
5839 function Is_Renaming
(N
: Node_Id
) return Boolean;
5840 -- Return true if N names a renaming entity
5842 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean;
5843 -- For renamings, return False if the prefix of any dereference within
5844 -- the renamed object_name is a variable, or any expression within the
5845 -- renamed object_name contains references to variables or calls on
5846 -- nonstatic functions; otherwise return True (RM 6.4.1(6.10/3))
5852 function Has_Prefix
(N
: Node_Id
) return Boolean is
5856 N_Attribute_Reference
,
5858 N_Explicit_Dereference
,
5859 N_Indexed_Component
,
5861 N_Selected_Component
,
5869 function Is_Renaming
(N
: Node_Id
) return Boolean is
5871 return Is_Entity_Name
(N
)
5872 and then Present
(Renamed_Entity
(Entity
(N
)));
5875 -----------------------
5876 -- Is_Valid_Renaming --
5877 -----------------------
5879 function Is_Valid_Renaming
(N
: Node_Id
) return Boolean is
5881 function Check_Renaming
(N
: Node_Id
) return Boolean;
5882 -- Recursive function used to traverse all the prefixes of N
5884 function Check_Renaming
(N
: Node_Id
) return Boolean is
5887 and then not Check_Renaming
(Renamed_Entity
(Entity
(N
)))
5892 if Nkind
(N
) = N_Indexed_Component
then
5897 Indx
:= First
(Expressions
(N
));
5898 while Present
(Indx
) loop
5899 if not Is_OK_Static_Expression
(Indx
) then
5908 if Has_Prefix
(N
) then
5910 P
: constant Node_Id
:= Prefix
(N
);
5913 if Nkind
(N
) = N_Explicit_Dereference
5914 and then Is_Variable
(P
)
5918 elsif Is_Entity_Name
(P
)
5919 and then Ekind
(Entity
(P
)) = E_Function
5923 elsif Nkind
(P
) = N_Function_Call
then
5927 -- Recursion to continue traversing the prefix of the
5928 -- renaming expression
5930 return Check_Renaming
(P
);
5937 -- Start of processing for Is_Valid_Renaming
5940 return Check_Renaming
(N
);
5941 end Is_Valid_Renaming
;
5943 -- Start of processing for Denotes_Same_Object
5946 -- Both names statically denote the same stand-alone object or parameter
5947 -- (RM 6.4.1(6.5/3))
5949 if Is_Entity_Name
(Obj1
)
5950 and then Is_Entity_Name
(Obj2
)
5951 and then Entity
(Obj1
) = Entity
(Obj2
)
5956 -- For renamings, the prefix of any dereference within the renamed
5957 -- object_name is not a variable, and any expression within the
5958 -- renamed object_name contains no references to variables nor
5959 -- calls on nonstatic functions (RM 6.4.1(6.10/3)).
5961 if Is_Renaming
(Obj1
) then
5962 if Is_Valid_Renaming
(Obj1
) then
5963 Obj1
:= Renamed_Entity
(Entity
(Obj1
));
5969 if Is_Renaming
(Obj2
) then
5970 if Is_Valid_Renaming
(Obj2
) then
5971 Obj2
:= Renamed_Entity
(Entity
(Obj2
));
5977 -- No match if not same node kind (such cases are handled by
5978 -- Denotes_Same_Prefix)
5980 if Nkind
(Obj1
) /= Nkind
(Obj2
) then
5983 -- After handling valid renamings, one of the two names statically
5984 -- denoted a renaming declaration whose renamed object_name is known
5985 -- to denote the same object as the other (RM 6.4.1(6.10/3))
5987 elsif Is_Entity_Name
(Obj1
) then
5988 if Is_Entity_Name
(Obj2
) then
5989 return Entity
(Obj1
) = Entity
(Obj2
);
5994 -- Both names are selected_components, their prefixes are known to
5995 -- denote the same object, and their selector_names denote the same
5996 -- component (RM 6.4.1(6.6/3)).
5998 elsif Nkind
(Obj1
) = N_Selected_Component
then
5999 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
6001 Entity
(Selector_Name
(Obj1
)) = Entity
(Selector_Name
(Obj2
));
6003 -- Both names are dereferences and the dereferenced names are known to
6004 -- denote the same object (RM 6.4.1(6.7/3))
6006 elsif Nkind
(Obj1
) = N_Explicit_Dereference
then
6007 return Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
));
6009 -- Both names are indexed_components, their prefixes are known to denote
6010 -- the same object, and each of the pairs of corresponding index values
6011 -- are either both static expressions with the same static value or both
6012 -- names that are known to denote the same object (RM 6.4.1(6.8/3))
6014 elsif Nkind
(Obj1
) = N_Indexed_Component
then
6015 if not Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
)) then
6023 Indx1
:= First
(Expressions
(Obj1
));
6024 Indx2
:= First
(Expressions
(Obj2
));
6025 while Present
(Indx1
) loop
6027 -- Indexes must denote the same static value or same object
6029 if Is_OK_Static_Expression
(Indx1
) then
6030 if not Is_OK_Static_Expression
(Indx2
) then
6033 elsif Expr_Value
(Indx1
) /= Expr_Value
(Indx2
) then
6037 elsif not Denotes_Same_Object
(Indx1
, Indx2
) then
6049 -- Both names are slices, their prefixes are known to denote the same
6050 -- object, and the two slices have statically matching index constraints
6051 -- (RM 6.4.1(6.9/3))
6053 elsif Nkind
(Obj1
) = N_Slice
6054 and then Denotes_Same_Object
(Prefix
(Obj1
), Prefix
(Obj2
))
6057 Lo1
, Lo2
, Hi1
, Hi2
: Node_Id
;
6060 Get_Index_Bounds
(Etype
(Obj1
), Lo1
, Hi1
);
6061 Get_Index_Bounds
(Etype
(Obj2
), Lo2
, Hi2
);
6063 -- Check whether bounds are statically identical. There is no
6064 -- attempt to detect partial overlap of slices.
6066 return Denotes_Same_Object
(Lo1
, Lo2
)
6068 Denotes_Same_Object
(Hi1
, Hi2
);
6071 -- In the recursion, literals appear as indexes
6073 elsif Nkind
(Obj1
) = N_Integer_Literal
6075 Nkind
(Obj2
) = N_Integer_Literal
6077 return Intval
(Obj1
) = Intval
(Obj2
);
6082 end Denotes_Same_Object
;
6084 -------------------------
6085 -- Denotes_Same_Prefix --
6086 -------------------------
6088 function Denotes_Same_Prefix
(A1
, A2
: Node_Id
) return Boolean is
6090 if Is_Entity_Name
(A1
) then
6091 if Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
)
6092 and then not Is_Access_Type
(Etype
(A1
))
6094 return Denotes_Same_Object
(A1
, Prefix
(A2
))
6095 or else Denotes_Same_Prefix
(A1
, Prefix
(A2
));
6100 elsif Is_Entity_Name
(A2
) then
6101 return Denotes_Same_Prefix
(A1
=> A2
, A2
=> A1
);
6103 elsif Nkind_In
(A1
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
6105 Nkind_In
(A2
, N_Selected_Component
, N_Indexed_Component
, N_Slice
)
6108 Root1
, Root2
: Node_Id
;
6109 Depth1
, Depth2
: Nat
:= 0;
6112 Root1
:= Prefix
(A1
);
6113 while not Is_Entity_Name
(Root1
) loop
6115 (Root1
, N_Selected_Component
, N_Indexed_Component
)
6119 Root1
:= Prefix
(Root1
);
6122 Depth1
:= Depth1
+ 1;
6125 Root2
:= Prefix
(A2
);
6126 while not Is_Entity_Name
(Root2
) loop
6127 if not Nkind_In
(Root2
, N_Selected_Component
,
6128 N_Indexed_Component
)
6132 Root2
:= Prefix
(Root2
);
6135 Depth2
:= Depth2
+ 1;
6138 -- If both have the same depth and they do not denote the same
6139 -- object, they are disjoint and no warning is needed.
6141 if Depth1
= Depth2
then
6144 elsif Depth1
> Depth2
then
6145 Root1
:= Prefix
(A1
);
6146 for J
in 1 .. Depth1
- Depth2
- 1 loop
6147 Root1
:= Prefix
(Root1
);
6150 return Denotes_Same_Object
(Root1
, A2
);
6153 Root2
:= Prefix
(A2
);
6154 for J
in 1 .. Depth2
- Depth1
- 1 loop
6155 Root2
:= Prefix
(Root2
);
6158 return Denotes_Same_Object
(A1
, Root2
);
6165 end Denotes_Same_Prefix
;
6167 ----------------------
6168 -- Denotes_Variable --
6169 ----------------------
6171 function Denotes_Variable
(N
: Node_Id
) return Boolean is
6173 return Is_Variable
(N
) and then Paren_Count
(N
) = 0;
6174 end Denotes_Variable
;
6176 -----------------------------
6177 -- Depends_On_Discriminant --
6178 -----------------------------
6180 function Depends_On_Discriminant
(N
: Node_Id
) return Boolean is
6185 Get_Index_Bounds
(N
, L
, H
);
6186 return Denotes_Discriminant
(L
) or else Denotes_Discriminant
(H
);
6187 end Depends_On_Discriminant
;
6189 -------------------------
6190 -- Designate_Same_Unit --
6191 -------------------------
6193 function Designate_Same_Unit
6195 Name2
: Node_Id
) return Boolean
6197 K1
: constant Node_Kind
:= Nkind
(Name1
);
6198 K2
: constant Node_Kind
:= Nkind
(Name2
);
6200 function Prefix_Node
(N
: Node_Id
) return Node_Id
;
6201 -- Returns the parent unit name node of a defining program unit name
6202 -- or the prefix if N is a selected component or an expanded name.
6204 function Select_Node
(N
: Node_Id
) return Node_Id
;
6205 -- Returns the defining identifier node of a defining program unit
6206 -- name or the selector node if N is a selected component or an
6213 function Prefix_Node
(N
: Node_Id
) return Node_Id
is
6215 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
6226 function Select_Node
(N
: Node_Id
) return Node_Id
is
6228 if Nkind
(N
) = N_Defining_Program_Unit_Name
then
6229 return Defining_Identifier
(N
);
6231 return Selector_Name
(N
);
6235 -- Start of processing for Designate_Same_Unit
6238 if Nkind_In
(K1
, N_Identifier
, N_Defining_Identifier
)
6240 Nkind_In
(K2
, N_Identifier
, N_Defining_Identifier
)
6242 return Chars
(Name1
) = Chars
(Name2
);
6244 elsif Nkind_In
(K1
, N_Expanded_Name
,
6245 N_Selected_Component
,
6246 N_Defining_Program_Unit_Name
)
6248 Nkind_In
(K2
, N_Expanded_Name
,
6249 N_Selected_Component
,
6250 N_Defining_Program_Unit_Name
)
6253 (Chars
(Select_Node
(Name1
)) = Chars
(Select_Node
(Name2
)))
6255 Designate_Same_Unit
(Prefix_Node
(Name1
), Prefix_Node
(Name2
));
6260 end Designate_Same_Unit
;
6262 ---------------------------------------------
6263 -- Diagnose_Iterated_Component_Association --
6264 ---------------------------------------------
6266 procedure Diagnose_Iterated_Component_Association
(N
: Node_Id
) is
6267 Def_Id
: constant Entity_Id
:= Defining_Identifier
(N
);
6271 -- Determine whether the iterated component association appears within
6272 -- an aggregate. If this is the case, raise Program_Error because the
6273 -- iterated component association cannot be left in the tree as is and
6274 -- must always be processed by the related aggregate.
6277 while Present
(Aggr
) loop
6278 if Nkind
(Aggr
) = N_Aggregate
then
6279 raise Program_Error
;
6281 -- Prevent the search from going too far
6283 elsif Is_Body_Or_Package_Declaration
(Aggr
) then
6287 Aggr
:= Parent
(Aggr
);
6290 -- At this point it is known that the iterated component association is
6291 -- not within an aggregate. This is really a quantified expression with
6292 -- a missing "all" or "some" quantifier.
6294 Error_Msg_N
("missing quantifier", Def_Id
);
6296 -- Rewrite the iterated component association as True to prevent any
6299 Rewrite
(N
, New_Occurrence_Of
(Standard_True
, Sloc
(N
)));
6301 end Diagnose_Iterated_Component_Association
;
6303 ---------------------------------
6304 -- Dynamic_Accessibility_Level --
6305 ---------------------------------
6307 function Dynamic_Accessibility_Level
(Expr
: Node_Id
) return Node_Id
is
6308 Loc
: constant Source_Ptr
:= Sloc
(Expr
);
6310 function Make_Level_Literal
(Level
: Uint
) return Node_Id
;
6311 -- Construct an integer literal representing an accessibility level
6312 -- with its type set to Natural.
6314 ------------------------
6315 -- Make_Level_Literal --
6316 ------------------------
6318 function Make_Level_Literal
(Level
: Uint
) return Node_Id
is
6319 Result
: constant Node_Id
:= Make_Integer_Literal
(Loc
, Level
);
6322 Set_Etype
(Result
, Standard_Natural
);
6324 end Make_Level_Literal
;
6330 -- Start of processing for Dynamic_Accessibility_Level
6333 if Is_Entity_Name
(Expr
) then
6336 if Present
(Renamed_Object
(E
)) then
6337 return Dynamic_Accessibility_Level
(Renamed_Object
(E
));
6340 if Is_Formal
(E
) or else Ekind_In
(E
, E_Variable
, E_Constant
) then
6341 if Present
(Extra_Accessibility
(E
)) then
6342 return New_Occurrence_Of
(Extra_Accessibility
(E
), Loc
);
6347 -- Unimplemented: Ptr.all'Access, where Ptr has Extra_Accessibility ???
6349 case Nkind
(Expr
) is
6351 -- For access discriminant, the level of the enclosing object
6353 when N_Selected_Component
=>
6354 if Ekind
(Entity
(Selector_Name
(Expr
))) = E_Discriminant
6355 and then Ekind
(Etype
(Entity
(Selector_Name
(Expr
)))) =
6356 E_Anonymous_Access_Type
6358 return Make_Level_Literal
(Object_Access_Level
(Expr
));
6361 when N_Attribute_Reference
=>
6362 case Get_Attribute_Id
(Attribute_Name
(Expr
)) is
6364 -- For X'Access, the level of the prefix X
6366 when Attribute_Access
=>
6367 return Make_Level_Literal
6368 (Object_Access_Level
(Prefix
(Expr
)));
6370 -- Treat the unchecked attributes as library-level
6372 when Attribute_Unchecked_Access
6373 | Attribute_Unrestricted_Access
6375 return Make_Level_Literal
(Scope_Depth
(Standard_Standard
));
6377 -- No other access-valued attributes
6380 raise Program_Error
;
6385 -- Unimplemented: depends on context. As an actual parameter where
6386 -- formal type is anonymous, use
6387 -- Scope_Depth (Current_Scope) + 1.
6388 -- For other cases, see 3.10.2(14/3) and following. ???
6392 when N_Type_Conversion
=>
6393 if not Is_Local_Anonymous_Access
(Etype
(Expr
)) then
6395 -- Handle type conversions introduced for a rename of an
6396 -- Ada 2012 stand-alone object of an anonymous access type.
6398 return Dynamic_Accessibility_Level
(Expression
(Expr
));
6405 return Make_Level_Literal
(Type_Access_Level
(Etype
(Expr
)));
6406 end Dynamic_Accessibility_Level
;
6408 ------------------------
6409 -- Discriminated_Size --
6410 ------------------------
6412 function Discriminated_Size
(Comp
: Entity_Id
) return Boolean is
6413 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean;
6414 -- Check whether the bound of an index is non-static and does denote
6415 -- a discriminant, in which case any object of the type (protected or
6416 -- otherwise) will have a non-static size.
6418 ----------------------
6419 -- Non_Static_Bound --
6420 ----------------------
6422 function Non_Static_Bound
(Bound
: Node_Id
) return Boolean is
6424 if Is_OK_Static_Expression
(Bound
) then
6427 -- If the bound is given by a discriminant it is non-static
6428 -- (A static constraint replaces the reference with the value).
6429 -- In an protected object the discriminant has been replaced by
6430 -- the corresponding discriminal within the protected operation.
6432 elsif Is_Entity_Name
(Bound
)
6434 (Ekind
(Entity
(Bound
)) = E_Discriminant
6435 or else Present
(Discriminal_Link
(Entity
(Bound
))))
6442 end Non_Static_Bound
;
6446 Typ
: constant Entity_Id
:= Etype
(Comp
);
6449 -- Start of processing for Discriminated_Size
6452 if not Is_Array_Type
(Typ
) then
6456 if Ekind
(Typ
) = E_Array_Subtype
then
6457 Index
:= First_Index
(Typ
);
6458 while Present
(Index
) loop
6459 if Non_Static_Bound
(Low_Bound
(Index
))
6460 or else Non_Static_Bound
(High_Bound
(Index
))
6472 end Discriminated_Size
;
6474 -----------------------------------
6475 -- Effective_Extra_Accessibility --
6476 -----------------------------------
6478 function Effective_Extra_Accessibility
(Id
: Entity_Id
) return Entity_Id
is
6480 if Present
(Renamed_Object
(Id
))
6481 and then Is_Entity_Name
(Renamed_Object
(Id
))
6483 return Effective_Extra_Accessibility
(Entity
(Renamed_Object
(Id
)));
6485 return Extra_Accessibility
(Id
);
6487 end Effective_Extra_Accessibility
;
6489 -----------------------------
6490 -- Effective_Reads_Enabled --
6491 -----------------------------
6493 function Effective_Reads_Enabled
(Id
: Entity_Id
) return Boolean is
6495 return Has_Enabled_Property
(Id
, Name_Effective_Reads
);
6496 end Effective_Reads_Enabled
;
6498 ------------------------------
6499 -- Effective_Writes_Enabled --
6500 ------------------------------
6502 function Effective_Writes_Enabled
(Id
: Entity_Id
) return Boolean is
6504 return Has_Enabled_Property
(Id
, Name_Effective_Writes
);
6505 end Effective_Writes_Enabled
;
6507 ------------------------------
6508 -- Enclosing_Comp_Unit_Node --
6509 ------------------------------
6511 function Enclosing_Comp_Unit_Node
(N
: Node_Id
) return Node_Id
is
6512 Current_Node
: Node_Id
;
6516 while Present
(Current_Node
)
6517 and then Nkind
(Current_Node
) /= N_Compilation_Unit
6519 Current_Node
:= Parent
(Current_Node
);
6522 if Nkind
(Current_Node
) /= N_Compilation_Unit
then
6525 return Current_Node
;
6527 end Enclosing_Comp_Unit_Node
;
6529 --------------------------
6530 -- Enclosing_CPP_Parent --
6531 --------------------------
6533 function Enclosing_CPP_Parent
(Typ
: Entity_Id
) return Entity_Id
is
6534 Parent_Typ
: Entity_Id
:= Typ
;
6537 while not Is_CPP_Class
(Parent_Typ
)
6538 and then Etype
(Parent_Typ
) /= Parent_Typ
6540 Parent_Typ
:= Etype
(Parent_Typ
);
6542 if Is_Private_Type
(Parent_Typ
) then
6543 Parent_Typ
:= Full_View
(Base_Type
(Parent_Typ
));
6547 pragma Assert
(Is_CPP_Class
(Parent_Typ
));
6549 end Enclosing_CPP_Parent
;
6551 ---------------------------
6552 -- Enclosing_Declaration --
6553 ---------------------------
6555 function Enclosing_Declaration
(N
: Node_Id
) return Node_Id
is
6556 Decl
: Node_Id
:= N
;
6559 while Present
(Decl
)
6560 and then not (Nkind
(Decl
) in N_Declaration
6562 Nkind
(Decl
) in N_Later_Decl_Item
)
6564 Decl
:= Parent
(Decl
);
6568 end Enclosing_Declaration
;
6570 ----------------------------
6571 -- Enclosing_Generic_Body --
6572 ----------------------------
6574 function Enclosing_Generic_Body
6575 (N
: Node_Id
) return Node_Id
6583 while Present
(P
) loop
6584 if Nkind
(P
) = N_Package_Body
6585 or else Nkind
(P
) = N_Subprogram_Body
6587 Spec
:= Corresponding_Spec
(P
);
6589 if Present
(Spec
) then
6590 Decl
:= Unit_Declaration_Node
(Spec
);
6592 if Nkind
(Decl
) = N_Generic_Package_Declaration
6593 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
6604 end Enclosing_Generic_Body
;
6606 ----------------------------
6607 -- Enclosing_Generic_Unit --
6608 ----------------------------
6610 function Enclosing_Generic_Unit
6611 (N
: Node_Id
) return Node_Id
6619 while Present
(P
) loop
6620 if Nkind
(P
) = N_Generic_Package_Declaration
6621 or else Nkind
(P
) = N_Generic_Subprogram_Declaration
6625 elsif Nkind
(P
) = N_Package_Body
6626 or else Nkind
(P
) = N_Subprogram_Body
6628 Spec
:= Corresponding_Spec
(P
);
6630 if Present
(Spec
) then
6631 Decl
:= Unit_Declaration_Node
(Spec
);
6633 if Nkind
(Decl
) = N_Generic_Package_Declaration
6634 or else Nkind
(Decl
) = N_Generic_Subprogram_Declaration
6645 end Enclosing_Generic_Unit
;
6647 -------------------------------
6648 -- Enclosing_Lib_Unit_Entity --
6649 -------------------------------
6651 function Enclosing_Lib_Unit_Entity
6652 (E
: Entity_Id
:= Current_Scope
) return Entity_Id
6654 Unit_Entity
: Entity_Id
;
6657 -- Look for enclosing library unit entity by following scope links.
6658 -- Equivalent to, but faster than indexing through the scope stack.
6661 while (Present
(Scope
(Unit_Entity
))
6662 and then Scope
(Unit_Entity
) /= Standard_Standard
)
6663 and not Is_Child_Unit
(Unit_Entity
)
6665 Unit_Entity
:= Scope
(Unit_Entity
);
6669 end Enclosing_Lib_Unit_Entity
;
6671 -----------------------------
6672 -- Enclosing_Lib_Unit_Node --
6673 -----------------------------
6675 function Enclosing_Lib_Unit_Node
(N
: Node_Id
) return Node_Id
is
6676 Encl_Unit
: Node_Id
;
6679 Encl_Unit
:= Enclosing_Comp_Unit_Node
(N
);
6680 while Present
(Encl_Unit
)
6681 and then Nkind
(Unit
(Encl_Unit
)) = N_Subunit
6683 Encl_Unit
:= Library_Unit
(Encl_Unit
);
6686 pragma Assert
(Nkind
(Encl_Unit
) = N_Compilation_Unit
);
6688 end Enclosing_Lib_Unit_Node
;
6690 -----------------------
6691 -- Enclosing_Package --
6692 -----------------------
6694 function Enclosing_Package
(E
: Entity_Id
) return Entity_Id
is
6695 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
6698 if Dynamic_Scope
= Standard_Standard
then
6699 return Standard_Standard
;
6701 elsif Dynamic_Scope
= Empty
then
6704 elsif Ekind_In
(Dynamic_Scope
, E_Package
, E_Package_Body
,
6707 return Dynamic_Scope
;
6710 return Enclosing_Package
(Dynamic_Scope
);
6712 end Enclosing_Package
;
6714 -------------------------------------
6715 -- Enclosing_Package_Or_Subprogram --
6716 -------------------------------------
6718 function Enclosing_Package_Or_Subprogram
(E
: Entity_Id
) return Entity_Id
is
6723 while Present
(S
) loop
6724 if Is_Package_Or_Generic_Package
(S
)
6725 or else Ekind
(S
) = E_Package_Body
6729 elsif Is_Subprogram_Or_Generic_Subprogram
(S
)
6730 or else Ekind
(S
) = E_Subprogram_Body
6740 end Enclosing_Package_Or_Subprogram
;
6742 --------------------------
6743 -- Enclosing_Subprogram --
6744 --------------------------
6746 function Enclosing_Subprogram
(E
: Entity_Id
) return Entity_Id
is
6747 Dynamic_Scope
: constant Entity_Id
:= Enclosing_Dynamic_Scope
(E
);
6750 if Dynamic_Scope
= Standard_Standard
then
6753 elsif Dynamic_Scope
= Empty
then
6756 elsif Ekind
(Dynamic_Scope
) = E_Subprogram_Body
then
6757 return Corresponding_Spec
(Parent
(Parent
(Dynamic_Scope
)));
6759 elsif Ekind
(Dynamic_Scope
) = E_Block
6760 or else Ekind
(Dynamic_Scope
) = E_Return_Statement
6762 return Enclosing_Subprogram
(Dynamic_Scope
);
6764 elsif Ekind
(Dynamic_Scope
) = E_Task_Type
then
6765 return Get_Task_Body_Procedure
(Dynamic_Scope
);
6767 elsif Ekind
(Dynamic_Scope
) = E_Limited_Private_Type
6768 and then Present
(Full_View
(Dynamic_Scope
))
6769 and then Ekind
(Full_View
(Dynamic_Scope
)) = E_Task_Type
6771 return Get_Task_Body_Procedure
(Full_View
(Dynamic_Scope
));
6773 -- No body is generated if the protected operation is eliminated
6775 elsif Convention
(Dynamic_Scope
) = Convention_Protected
6776 and then not Is_Eliminated
(Dynamic_Scope
)
6777 and then Present
(Protected_Body_Subprogram
(Dynamic_Scope
))
6779 return Protected_Body_Subprogram
(Dynamic_Scope
);
6782 return Dynamic_Scope
;
6784 end Enclosing_Subprogram
;
6786 ------------------------
6787 -- Ensure_Freeze_Node --
6788 ------------------------
6790 procedure Ensure_Freeze_Node
(E
: Entity_Id
) is
6793 if No
(Freeze_Node
(E
)) then
6794 FN
:= Make_Freeze_Entity
(Sloc
(E
));
6795 Set_Has_Delayed_Freeze
(E
);
6796 Set_Freeze_Node
(E
, FN
);
6797 Set_Access_Types_To_Process
(FN
, No_Elist
);
6798 Set_TSS_Elist
(FN
, No_Elist
);
6801 end Ensure_Freeze_Node
;
6807 procedure Enter_Name
(Def_Id
: Entity_Id
) is
6808 C
: constant Entity_Id
:= Current_Entity
(Def_Id
);
6809 E
: constant Entity_Id
:= Current_Entity_In_Scope
(Def_Id
);
6810 S
: constant Entity_Id
:= Current_Scope
;
6813 Generate_Definition
(Def_Id
);
6815 -- Add new name to current scope declarations. Check for duplicate
6816 -- declaration, which may or may not be a genuine error.
6820 -- Case of previous entity entered because of a missing declaration
6821 -- or else a bad subtype indication. Best is to use the new entity,
6822 -- and make the previous one invisible.
6824 if Etype
(E
) = Any_Type
then
6825 Set_Is_Immediately_Visible
(E
, False);
6827 -- Case of renaming declaration constructed for package instances.
6828 -- if there is an explicit declaration with the same identifier,
6829 -- the renaming is not immediately visible any longer, but remains
6830 -- visible through selected component notation.
6832 elsif Nkind
(Parent
(E
)) = N_Package_Renaming_Declaration
6833 and then not Comes_From_Source
(E
)
6835 Set_Is_Immediately_Visible
(E
, False);
6837 -- The new entity may be the package renaming, which has the same
6838 -- same name as a generic formal which has been seen already.
6840 elsif Nkind
(Parent
(Def_Id
)) = N_Package_Renaming_Declaration
6841 and then not Comes_From_Source
(Def_Id
)
6843 Set_Is_Immediately_Visible
(E
, False);
6845 -- For a fat pointer corresponding to a remote access to subprogram,
6846 -- we use the same identifier as the RAS type, so that the proper
6847 -- name appears in the stub. This type is only retrieved through
6848 -- the RAS type and never by visibility, and is not added to the
6849 -- visibility list (see below).
6851 elsif Nkind
(Parent
(Def_Id
)) = N_Full_Type_Declaration
6852 and then Ekind
(Def_Id
) = E_Record_Type
6853 and then Present
(Corresponding_Remote_Type
(Def_Id
))
6857 -- Case of an implicit operation or derived literal. The new entity
6858 -- hides the implicit one, which is removed from all visibility,
6859 -- i.e. the entity list of its scope, and homonym chain of its name.
6861 elsif (Is_Overloadable
(E
) and then Is_Inherited_Operation
(E
))
6862 or else Is_Internal
(E
)
6865 Decl
: constant Node_Id
:= Parent
(E
);
6867 Prev_Vis
: Entity_Id
;
6870 -- If E is an implicit declaration, it cannot be the first
6871 -- entity in the scope.
6873 Prev
:= First_Entity
(Current_Scope
);
6874 while Present
(Prev
) and then Next_Entity
(Prev
) /= E
loop
6880 -- If E is not on the entity chain of the current scope,
6881 -- it is an implicit declaration in the generic formal
6882 -- part of a generic subprogram. When analyzing the body,
6883 -- the generic formals are visible but not on the entity
6884 -- chain of the subprogram. The new entity will become
6885 -- the visible one in the body.
6888 (Nkind
(Parent
(Decl
)) = N_Generic_Subprogram_Declaration
);
6892 Set_Next_Entity
(Prev
, Next_Entity
(E
));
6894 if No
(Next_Entity
(Prev
)) then
6895 Set_Last_Entity
(Current_Scope
, Prev
);
6898 if E
= Current_Entity
(E
) then
6902 Prev_Vis
:= Current_Entity
(E
);
6903 while Homonym
(Prev_Vis
) /= E
loop
6904 Prev_Vis
:= Homonym
(Prev_Vis
);
6908 if Present
(Prev_Vis
) then
6910 -- Skip E in the visibility chain
6912 Set_Homonym
(Prev_Vis
, Homonym
(E
));
6915 Set_Name_Entity_Id
(Chars
(E
), Homonym
(E
));
6920 -- This section of code could use a comment ???
6922 elsif Present
(Etype
(E
))
6923 and then Is_Concurrent_Type
(Etype
(E
))
6928 -- If the homograph is a protected component renaming, it should not
6929 -- be hiding the current entity. Such renamings are treated as weak
6932 elsif Is_Prival
(E
) then
6933 Set_Is_Immediately_Visible
(E
, False);
6935 -- In this case the current entity is a protected component renaming.
6936 -- Perform minimal decoration by setting the scope and return since
6937 -- the prival should not be hiding other visible entities.
6939 elsif Is_Prival
(Def_Id
) then
6940 Set_Scope
(Def_Id
, Current_Scope
);
6943 -- Analogous to privals, the discriminal generated for an entry index
6944 -- parameter acts as a weak declaration. Perform minimal decoration
6945 -- to avoid bogus errors.
6947 elsif Is_Discriminal
(Def_Id
)
6948 and then Ekind
(Discriminal_Link
(Def_Id
)) = E_Entry_Index_Parameter
6950 Set_Scope
(Def_Id
, Current_Scope
);
6953 -- In the body or private part of an instance, a type extension may
6954 -- introduce a component with the same name as that of an actual. The
6955 -- legality rule is not enforced, but the semantics of the full type
6956 -- with two components of same name are not clear at this point???
6958 elsif In_Instance_Not_Visible
then
6961 -- When compiling a package body, some child units may have become
6962 -- visible. They cannot conflict with local entities that hide them.
6964 elsif Is_Child_Unit
(E
)
6965 and then In_Open_Scopes
(Scope
(E
))
6966 and then not Is_Immediately_Visible
(E
)
6970 -- Conversely, with front-end inlining we may compile the parent body
6971 -- first, and a child unit subsequently. The context is now the
6972 -- parent spec, and body entities are not visible.
6974 elsif Is_Child_Unit
(Def_Id
)
6975 and then Is_Package_Body_Entity
(E
)
6976 and then not In_Package_Body
(Current_Scope
)
6980 -- Case of genuine duplicate declaration
6983 Error_Msg_Sloc
:= Sloc
(E
);
6985 -- If the previous declaration is an incomplete type declaration
6986 -- this may be an attempt to complete it with a private type. The
6987 -- following avoids confusing cascaded errors.
6989 if Nkind
(Parent
(E
)) = N_Incomplete_Type_Declaration
6990 and then Nkind
(Parent
(Def_Id
)) = N_Private_Type_Declaration
6993 ("incomplete type cannot be completed with a private " &
6994 "declaration", Parent
(Def_Id
));
6995 Set_Is_Immediately_Visible
(E
, False);
6996 Set_Full_View
(E
, Def_Id
);
6998 -- An inherited component of a record conflicts with a new
6999 -- discriminant. The discriminant is inserted first in the scope,
7000 -- but the error should be posted on it, not on the component.
7002 elsif Ekind
(E
) = E_Discriminant
7003 and then Present
(Scope
(Def_Id
))
7004 and then Scope
(Def_Id
) /= Current_Scope
7006 Error_Msg_Sloc
:= Sloc
(Def_Id
);
7007 Error_Msg_N
("& conflicts with declaration#", E
);
7010 -- If the name of the unit appears in its own context clause, a
7011 -- dummy package with the name has already been created, and the
7012 -- error emitted. Try to continue quietly.
7014 elsif Error_Posted
(E
)
7015 and then Sloc
(E
) = No_Location
7016 and then Nkind
(Parent
(E
)) = N_Package_Specification
7017 and then Current_Scope
= Standard_Standard
7019 Set_Scope
(Def_Id
, Current_Scope
);
7023 Error_Msg_N
("& conflicts with declaration#", Def_Id
);
7025 -- Avoid cascaded messages with duplicate components in
7028 if Ekind_In
(E
, E_Component
, E_Discriminant
) then
7033 if Nkind
(Parent
(Parent
(Def_Id
))) =
7034 N_Generic_Subprogram_Declaration
7036 Defining_Entity
(Specification
(Parent
(Parent
(Def_Id
))))
7038 Error_Msg_N
("\generic units cannot be overloaded", Def_Id
);
7041 -- If entity is in standard, then we are in trouble, because it
7042 -- means that we have a library package with a duplicated name.
7043 -- That's hard to recover from, so abort.
7045 if S
= Standard_Standard
then
7046 raise Unrecoverable_Error
;
7048 -- Otherwise we continue with the declaration. Having two
7049 -- identical declarations should not cause us too much trouble.
7057 -- If we fall through, declaration is OK, at least OK enough to continue
7059 -- If Def_Id is a discriminant or a record component we are in the midst
7060 -- of inheriting components in a derived record definition. Preserve
7061 -- their Ekind and Etype.
7063 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
) then
7066 -- If a type is already set, leave it alone (happens when a type
7067 -- declaration is reanalyzed following a call to the optimizer).
7069 elsif Present
(Etype
(Def_Id
)) then
7072 -- Otherwise, the kind E_Void insures that premature uses of the entity
7073 -- will be detected. Any_Type insures that no cascaded errors will occur
7076 Set_Ekind
(Def_Id
, E_Void
);
7077 Set_Etype
(Def_Id
, Any_Type
);
7080 -- Inherited discriminants and components in derived record types are
7081 -- immediately visible. Itypes are not.
7083 -- Unless the Itype is for a record type with a corresponding remote
7084 -- type (what is that about, it was not commented ???)
7086 if Ekind_In
(Def_Id
, E_Discriminant
, E_Component
)
7088 ((not Is_Record_Type
(Def_Id
)
7089 or else No
(Corresponding_Remote_Type
(Def_Id
)))
7090 and then not Is_Itype
(Def_Id
))
7092 Set_Is_Immediately_Visible
(Def_Id
);
7093 Set_Current_Entity
(Def_Id
);
7096 Set_Homonym
(Def_Id
, C
);
7097 Append_Entity
(Def_Id
, S
);
7098 Set_Public_Status
(Def_Id
);
7100 -- Declaring a homonym is not allowed in SPARK ...
7102 if Present
(C
) and then Restriction_Check_Required
(SPARK_05
) then
7104 Enclosing_Subp
: constant Node_Id
:= Enclosing_Subprogram
(Def_Id
);
7105 Enclosing_Pack
: constant Node_Id
:= Enclosing_Package
(Def_Id
);
7106 Other_Scope
: constant Node_Id
:= Enclosing_Dynamic_Scope
(C
);
7109 -- ... unless the new declaration is in a subprogram, and the
7110 -- visible declaration is a variable declaration or a parameter
7111 -- specification outside that subprogram.
7113 if Present
(Enclosing_Subp
)
7114 and then Nkind_In
(Parent
(C
), N_Object_Declaration
,
7115 N_Parameter_Specification
)
7116 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Subp
)
7120 -- ... or the new declaration is in a package, and the visible
7121 -- declaration occurs outside that package.
7123 elsif Present
(Enclosing_Pack
)
7124 and then not Scope_Within_Or_Same
(Other_Scope
, Enclosing_Pack
)
7128 -- ... or the new declaration is a component declaration in a
7129 -- record type definition.
7131 elsif Nkind
(Parent
(Def_Id
)) = N_Component_Declaration
then
7134 -- Don't issue error for non-source entities
7136 elsif Comes_From_Source
(Def_Id
)
7137 and then Comes_From_Source
(C
)
7139 Error_Msg_Sloc
:= Sloc
(C
);
7140 Check_SPARK_05_Restriction
7141 ("redeclaration of identifier &#", Def_Id
);
7146 -- Warn if new entity hides an old one
7148 if Warn_On_Hiding
and then Present
(C
)
7150 -- Don't warn for record components since they always have a well
7151 -- defined scope which does not confuse other uses. Note that in
7152 -- some cases, Ekind has not been set yet.
7154 and then Ekind
(C
) /= E_Component
7155 and then Ekind
(C
) /= E_Discriminant
7156 and then Nkind
(Parent
(C
)) /= N_Component_Declaration
7157 and then Ekind
(Def_Id
) /= E_Component
7158 and then Ekind
(Def_Id
) /= E_Discriminant
7159 and then Nkind
(Parent
(Def_Id
)) /= N_Component_Declaration
7161 -- Don't warn for one character variables. It is too common to use
7162 -- such variables as locals and will just cause too many false hits.
7164 and then Length_Of_Name
(Chars
(C
)) /= 1
7166 -- Don't warn for non-source entities
7168 and then Comes_From_Source
(C
)
7169 and then Comes_From_Source
(Def_Id
)
7171 -- Don't warn unless entity in question is in extended main source
7173 and then In_Extended_Main_Source_Unit
(Def_Id
)
7175 -- Finally, the hidden entity must be either immediately visible or
7176 -- use visible (i.e. from a used package).
7179 (Is_Immediately_Visible
(C
)
7181 Is_Potentially_Use_Visible
(C
))
7183 Error_Msg_Sloc
:= Sloc
(C
);
7184 Error_Msg_N
("declaration hides &#?h?", Def_Id
);
7192 function Entity_Of
(N
: Node_Id
) return Entity_Id
is
7197 -- Assume that the arbitrary node does not have an entity
7201 if Is_Entity_Name
(N
) then
7204 -- Follow a possible chain of renamings to reach the earliest renamed
7208 and then Is_Object
(Id
)
7209 and then Present
(Renamed_Object
(Id
))
7211 Ren
:= Renamed_Object
(Id
);
7213 -- The reference renames an abstract state or a whole object
7216 -- Ren : ... renames Obj;
7218 if Is_Entity_Name
(Ren
) then
7221 -- The reference renames a function result. Check the original
7222 -- node in case expansion relocates the function call.
7224 -- Ren : ... renames Func_Call;
7226 elsif Nkind
(Original_Node
(Ren
)) = N_Function_Call
then
7229 -- Otherwise the reference renames something which does not yield
7230 -- an abstract state or a whole object. Treat the reference as not
7231 -- having a proper entity for SPARK legality purposes.
7243 --------------------------
7244 -- Explain_Limited_Type --
7245 --------------------------
7247 procedure Explain_Limited_Type
(T
: Entity_Id
; N
: Node_Id
) is
7251 -- For array, component type must be limited
7253 if Is_Array_Type
(T
) then
7254 Error_Msg_Node_2
:= T
;
7256 ("\component type& of type& is limited", N
, Component_Type
(T
));
7257 Explain_Limited_Type
(Component_Type
(T
), N
);
7259 elsif Is_Record_Type
(T
) then
7261 -- No need for extra messages if explicit limited record
7263 if Is_Limited_Record
(Base_Type
(T
)) then
7267 -- Otherwise find a limited component. Check only components that
7268 -- come from source, or inherited components that appear in the
7269 -- source of the ancestor.
7271 C
:= First_Component
(T
);
7272 while Present
(C
) loop
7273 if Is_Limited_Type
(Etype
(C
))
7275 (Comes_From_Source
(C
)
7277 (Present
(Original_Record_Component
(C
))
7279 Comes_From_Source
(Original_Record_Component
(C
))))
7281 Error_Msg_Node_2
:= T
;
7282 Error_Msg_NE
("\component& of type& has limited type", N
, C
);
7283 Explain_Limited_Type
(Etype
(C
), N
);
7290 -- The type may be declared explicitly limited, even if no component
7291 -- of it is limited, in which case we fall out of the loop.
7294 end Explain_Limited_Type
;
7296 ---------------------------------------
7297 -- Expression_Of_Expression_Function --
7298 ---------------------------------------
7300 function Expression_Of_Expression_Function
7301 (Subp
: Entity_Id
) return Node_Id
7303 Expr_Func
: Node_Id
;
7306 pragma Assert
(Is_Expression_Function_Or_Completion
(Subp
));
7308 if Nkind
(Original_Node
(Subprogram_Spec
(Subp
))) =
7309 N_Expression_Function
7311 Expr_Func
:= Original_Node
(Subprogram_Spec
(Subp
));
7313 elsif Nkind
(Original_Node
(Subprogram_Body
(Subp
))) =
7314 N_Expression_Function
7316 Expr_Func
:= Original_Node
(Subprogram_Body
(Subp
));
7319 pragma Assert
(False);
7323 return Original_Node
(Expression
(Expr_Func
));
7324 end Expression_Of_Expression_Function
;
7326 -------------------------------
7327 -- Extensions_Visible_Status --
7328 -------------------------------
7330 function Extensions_Visible_Status
7331 (Id
: Entity_Id
) return Extensions_Visible_Mode
7340 -- When a formal parameter is subject to Extensions_Visible, the pragma
7341 -- is stored in the contract of related subprogram.
7343 if Is_Formal
(Id
) then
7346 elsif Is_Subprogram_Or_Generic_Subprogram
(Id
) then
7349 -- No other construct carries this pragma
7352 return Extensions_Visible_None
;
7355 Prag
:= Get_Pragma
(Subp
, Pragma_Extensions_Visible
);
7357 -- In certain cases analysis may request the Extensions_Visible status
7358 -- of an expression function before the pragma has been analyzed yet.
7359 -- Inspect the declarative items after the expression function looking
7360 -- for the pragma (if any).
7362 if No
(Prag
) and then Is_Expression_Function
(Subp
) then
7363 Decl
:= Next
(Unit_Declaration_Node
(Subp
));
7364 while Present
(Decl
) loop
7365 if Nkind
(Decl
) = N_Pragma
7366 and then Pragma_Name
(Decl
) = Name_Extensions_Visible
7371 -- A source construct ends the region where Extensions_Visible may
7372 -- appear, stop the traversal. An expanded expression function is
7373 -- no longer a source construct, but it must still be recognized.
7375 elsif Comes_From_Source
(Decl
)
7377 (Nkind_In
(Decl
, N_Subprogram_Body
,
7378 N_Subprogram_Declaration
)
7379 and then Is_Expression_Function
(Defining_Entity
(Decl
)))
7388 -- Extract the value from the Boolean expression (if any)
7390 if Present
(Prag
) then
7391 Arg
:= First
(Pragma_Argument_Associations
(Prag
));
7393 if Present
(Arg
) then
7394 Expr
:= Get_Pragma_Arg
(Arg
);
7396 -- When the associated subprogram is an expression function, the
7397 -- argument of the pragma may not have been analyzed.
7399 if not Analyzed
(Expr
) then
7400 Preanalyze_And_Resolve
(Expr
, Standard_Boolean
);
7403 -- Guard against cascading errors when the argument of pragma
7404 -- Extensions_Visible is not a valid static Boolean expression.
7406 if Error_Posted
(Expr
) then
7407 return Extensions_Visible_None
;
7409 elsif Is_True
(Expr_Value
(Expr
)) then
7410 return Extensions_Visible_True
;
7413 return Extensions_Visible_False
;
7416 -- Otherwise the aspect or pragma defaults to True
7419 return Extensions_Visible_True
;
7422 -- Otherwise aspect or pragma Extensions_Visible is not inherited or
7423 -- directly specified. In SPARK code, its value defaults to "False".
7425 elsif SPARK_Mode
= On
then
7426 return Extensions_Visible_False
;
7428 -- In non-SPARK code, aspect or pragma Extensions_Visible defaults to
7432 return Extensions_Visible_True
;
7434 end Extensions_Visible_Status
;
7440 procedure Find_Actual
7442 Formal
: out Entity_Id
;
7445 Context
: constant Node_Id
:= Parent
(N
);
7450 if Nkind_In
(Context
, N_Indexed_Component
, N_Selected_Component
)
7451 and then N
= Prefix
(Context
)
7453 Find_Actual
(Context
, Formal
, Call
);
7456 elsif Nkind
(Context
) = N_Parameter_Association
7457 and then N
= Explicit_Actual_Parameter
(Context
)
7459 Call
:= Parent
(Context
);
7461 elsif Nkind_In
(Context
, N_Entry_Call_Statement
,
7463 N_Procedure_Call_Statement
)
7473 -- If we have a call to a subprogram look for the parameter. Note that
7474 -- we exclude overloaded calls, since we don't know enough to be sure
7475 -- of giving the right answer in this case.
7477 if Nkind_In
(Call
, N_Entry_Call_Statement
,
7479 N_Procedure_Call_Statement
)
7481 Call_Nam
:= Name
(Call
);
7483 -- A call to a protected or task entry appears as a selected
7484 -- component rather than an expanded name.
7486 if Nkind
(Call_Nam
) = N_Selected_Component
then
7487 Call_Nam
:= Selector_Name
(Call_Nam
);
7490 if Is_Entity_Name
(Call_Nam
)
7491 and then Present
(Entity
(Call_Nam
))
7492 and then Is_Overloadable
(Entity
(Call_Nam
))
7493 and then not Is_Overloaded
(Call_Nam
)
7495 -- If node is name in call it is not an actual
7497 if N
= Call_Nam
then
7503 -- Fall here if we are definitely a parameter
7505 Actual
:= First_Actual
(Call
);
7506 Formal
:= First_Formal
(Entity
(Call_Nam
));
7507 while Present
(Formal
) and then Present
(Actual
) loop
7511 -- An actual that is the prefix in a prefixed call may have
7512 -- been rewritten in the call, after the deferred reference
7513 -- was collected. Check if sloc and kinds and names match.
7515 elsif Sloc
(Actual
) = Sloc
(N
)
7516 and then Nkind
(Actual
) = N_Identifier
7517 and then Nkind
(Actual
) = Nkind
(N
)
7518 and then Chars
(Actual
) = Chars
(N
)
7523 Actual
:= Next_Actual
(Actual
);
7524 Formal
:= Next_Formal
(Formal
);
7530 -- Fall through here if we did not find matching actual
7536 ---------------------------
7537 -- Find_Body_Discriminal --
7538 ---------------------------
7540 function Find_Body_Discriminal
7541 (Spec_Discriminant
: Entity_Id
) return Entity_Id
7547 -- If expansion is suppressed, then the scope can be the concurrent type
7548 -- itself rather than a corresponding concurrent record type.
7550 if Is_Concurrent_Type
(Scope
(Spec_Discriminant
)) then
7551 Tsk
:= Scope
(Spec_Discriminant
);
7554 pragma Assert
(Is_Concurrent_Record_Type
(Scope
(Spec_Discriminant
)));
7556 Tsk
:= Corresponding_Concurrent_Type
(Scope
(Spec_Discriminant
));
7559 -- Find discriminant of original concurrent type, and use its current
7560 -- discriminal, which is the renaming within the task/protected body.
7562 Disc
:= First_Discriminant
(Tsk
);
7563 while Present
(Disc
) loop
7564 if Chars
(Disc
) = Chars
(Spec_Discriminant
) then
7565 return Discriminal
(Disc
);
7568 Next_Discriminant
(Disc
);
7571 -- That loop should always succeed in finding a matching entry and
7572 -- returning. Fatal error if not.
7574 raise Program_Error
;
7575 end Find_Body_Discriminal
;
7577 -------------------------------------
7578 -- Find_Corresponding_Discriminant --
7579 -------------------------------------
7581 function Find_Corresponding_Discriminant
7583 Typ
: Entity_Id
) return Entity_Id
7585 Par_Disc
: Entity_Id
;
7586 Old_Disc
: Entity_Id
;
7587 New_Disc
: Entity_Id
;
7590 Par_Disc
:= Original_Record_Component
(Original_Discriminant
(Id
));
7592 -- The original type may currently be private, and the discriminant
7593 -- only appear on its full view.
7595 if Is_Private_Type
(Scope
(Par_Disc
))
7596 and then not Has_Discriminants
(Scope
(Par_Disc
))
7597 and then Present
(Full_View
(Scope
(Par_Disc
)))
7599 Old_Disc
:= First_Discriminant
(Full_View
(Scope
(Par_Disc
)));
7601 Old_Disc
:= First_Discriminant
(Scope
(Par_Disc
));
7604 if Is_Class_Wide_Type
(Typ
) then
7605 New_Disc
:= First_Discriminant
(Root_Type
(Typ
));
7607 New_Disc
:= First_Discriminant
(Typ
);
7610 while Present
(Old_Disc
) and then Present
(New_Disc
) loop
7611 if Old_Disc
= Par_Disc
then
7615 Next_Discriminant
(Old_Disc
);
7616 Next_Discriminant
(New_Disc
);
7619 -- Should always find it
7621 raise Program_Error
;
7622 end Find_Corresponding_Discriminant
;
7624 ----------------------------------
7625 -- Find_Enclosing_Iterator_Loop --
7626 ----------------------------------
7628 function Find_Enclosing_Iterator_Loop
(Id
: Entity_Id
) return Entity_Id
is
7633 -- Traverse the scope chain looking for an iterator loop. Such loops are
7634 -- usually transformed into blocks, hence the use of Original_Node.
7637 while Present
(S
) and then S
/= Standard_Standard
loop
7638 if Ekind
(S
) = E_Loop
7639 and then Nkind
(Parent
(S
)) = N_Implicit_Label_Declaration
7641 Constr
:= Original_Node
(Label_Construct
(Parent
(S
)));
7643 if Nkind
(Constr
) = N_Loop_Statement
7644 and then Present
(Iteration_Scheme
(Constr
))
7645 and then Nkind
(Iterator_Specification
7646 (Iteration_Scheme
(Constr
))) =
7647 N_Iterator_Specification
7657 end Find_Enclosing_Iterator_Loop
;
7659 ------------------------------------
7660 -- Find_Loop_In_Conditional_Block --
7661 ------------------------------------
7663 function Find_Loop_In_Conditional_Block
(N
: Node_Id
) return Node_Id
is
7669 if Nkind
(Stmt
) = N_If_Statement
then
7670 Stmt
:= First
(Then_Statements
(Stmt
));
7673 pragma Assert
(Nkind
(Stmt
) = N_Block_Statement
);
7675 -- Inspect the statements of the conditional block. In general the loop
7676 -- should be the first statement in the statement sequence of the block,
7677 -- but the finalization machinery may have introduced extra object
7680 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Stmt
)));
7681 while Present
(Stmt
) loop
7682 if Nkind
(Stmt
) = N_Loop_Statement
then
7689 -- The expansion of attribute 'Loop_Entry produced a malformed block
7691 raise Program_Error
;
7692 end Find_Loop_In_Conditional_Block
;
7694 --------------------------
7695 -- Find_Overlaid_Entity --
7696 --------------------------
7698 procedure Find_Overlaid_Entity
7700 Ent
: out Entity_Id
;
7706 -- We are looking for one of the two following forms:
7708 -- for X'Address use Y'Address
7712 -- Const : constant Address := expr;
7714 -- for X'Address use Const;
7716 -- In the second case, the expr is either Y'Address, or recursively a
7717 -- constant that eventually references Y'Address.
7722 if Nkind
(N
) = N_Attribute_Definition_Clause
7723 and then Chars
(N
) = Name_Address
7725 Expr
:= Expression
(N
);
7727 -- This loop checks the form of the expression for Y'Address,
7728 -- using recursion to deal with intermediate constants.
7731 -- Check for Y'Address
7733 if Nkind
(Expr
) = N_Attribute_Reference
7734 and then Attribute_Name
(Expr
) = Name_Address
7736 Expr
:= Prefix
(Expr
);
7739 -- Check for Const where Const is a constant entity
7741 elsif Is_Entity_Name
(Expr
)
7742 and then Ekind
(Entity
(Expr
)) = E_Constant
7744 Expr
:= Constant_Value
(Entity
(Expr
));
7746 -- Anything else does not need checking
7753 -- This loop checks the form of the prefix for an entity, using
7754 -- recursion to deal with intermediate components.
7757 -- Check for Y where Y is an entity
7759 if Is_Entity_Name
(Expr
) then
7760 Ent
:= Entity
(Expr
);
7763 -- Check for components
7766 Nkind_In
(Expr
, N_Selected_Component
, N_Indexed_Component
)
7768 Expr
:= Prefix
(Expr
);
7771 -- Anything else does not need checking
7778 end Find_Overlaid_Entity
;
7780 -------------------------
7781 -- Find_Parameter_Type --
7782 -------------------------
7784 function Find_Parameter_Type
(Param
: Node_Id
) return Entity_Id
is
7786 if Nkind
(Param
) /= N_Parameter_Specification
then
7789 -- For an access parameter, obtain the type from the formal entity
7790 -- itself, because access to subprogram nodes do not carry a type.
7791 -- Shouldn't we always use the formal entity ???
7793 elsif Nkind
(Parameter_Type
(Param
)) = N_Access_Definition
then
7794 return Etype
(Defining_Identifier
(Param
));
7797 return Etype
(Parameter_Type
(Param
));
7799 end Find_Parameter_Type
;
7801 -----------------------------------
7802 -- Find_Placement_In_State_Space --
7803 -----------------------------------
7805 procedure Find_Placement_In_State_Space
7806 (Item_Id
: Entity_Id
;
7807 Placement
: out State_Space_Kind
;
7808 Pack_Id
: out Entity_Id
)
7810 Context
: Entity_Id
;
7813 -- Assume that the item does not appear in the state space of a package
7815 Placement
:= Not_In_Package
;
7818 -- Climb the scope stack and examine the enclosing context
7820 Context
:= Scope
(Item_Id
);
7821 while Present
(Context
) and then Context
/= Standard_Standard
loop
7822 if Ekind
(Context
) = E_Package
then
7825 -- A package body is a cut off point for the traversal as the item
7826 -- cannot be visible to the outside from this point on. Note that
7827 -- this test must be done first as a body is also classified as a
7830 if In_Package_Body
(Context
) then
7831 Placement
:= Body_State_Space
;
7834 -- The private part of a package is a cut off point for the
7835 -- traversal as the item cannot be visible to the outside from
7838 elsif In_Private_Part
(Context
) then
7839 Placement
:= Private_State_Space
;
7842 -- When the item appears in the visible state space of a package,
7843 -- continue to climb the scope stack as this may not be the final
7847 Placement
:= Visible_State_Space
;
7849 -- The visible state space of a child unit acts as the proper
7850 -- placement of an item.
7852 if Is_Child_Unit
(Context
) then
7857 -- The item or its enclosing package appear in a construct that has
7861 Placement
:= Not_In_Package
;
7865 Context
:= Scope
(Context
);
7867 end Find_Placement_In_State_Space
;
7869 ------------------------
7870 -- Find_Specific_Type --
7871 ------------------------
7873 function Find_Specific_Type
(CW
: Entity_Id
) return Entity_Id
is
7874 Typ
: Entity_Id
:= Root_Type
(CW
);
7877 if Ekind
(Typ
) = E_Incomplete_Type
then
7878 if From_Limited_With
(Typ
) then
7879 Typ
:= Non_Limited_View
(Typ
);
7881 Typ
:= Full_View
(Typ
);
7885 if Is_Private_Type
(Typ
)
7886 and then not Is_Tagged_Type
(Typ
)
7887 and then Present
(Full_View
(Typ
))
7889 return Full_View
(Typ
);
7893 end Find_Specific_Type
;
7895 -----------------------------
7896 -- Find_Static_Alternative --
7897 -----------------------------
7899 function Find_Static_Alternative
(N
: Node_Id
) return Node_Id
is
7900 Expr
: constant Node_Id
:= Expression
(N
);
7901 Val
: constant Uint
:= Expr_Value
(Expr
);
7906 Alt
:= First
(Alternatives
(N
));
7909 if Nkind
(Alt
) /= N_Pragma
then
7910 Choice
:= First
(Discrete_Choices
(Alt
));
7911 while Present
(Choice
) loop
7913 -- Others choice, always matches
7915 if Nkind
(Choice
) = N_Others_Choice
then
7918 -- Range, check if value is in the range
7920 elsif Nkind
(Choice
) = N_Range
then
7922 Val
>= Expr_Value
(Low_Bound
(Choice
))
7924 Val
<= Expr_Value
(High_Bound
(Choice
));
7926 -- Choice is a subtype name. Note that we know it must
7927 -- be a static subtype, since otherwise it would have
7928 -- been diagnosed as illegal.
7930 elsif Is_Entity_Name
(Choice
)
7931 and then Is_Type
(Entity
(Choice
))
7933 exit Search
when Is_In_Range
(Expr
, Etype
(Choice
),
7934 Assume_Valid
=> False);
7936 -- Choice is a subtype indication
7938 elsif Nkind
(Choice
) = N_Subtype_Indication
then
7940 C
: constant Node_Id
:= Constraint
(Choice
);
7941 R
: constant Node_Id
:= Range_Expression
(C
);
7945 Val
>= Expr_Value
(Low_Bound
(R
))
7947 Val
<= Expr_Value
(High_Bound
(R
));
7950 -- Choice is a simple expression
7953 exit Search
when Val
= Expr_Value
(Choice
);
7961 pragma Assert
(Present
(Alt
));
7964 -- The above loop *must* terminate by finding a match, since we know the
7965 -- case statement is valid, and the value of the expression is known at
7966 -- compile time. When we fall out of the loop, Alt points to the
7967 -- alternative that we know will be selected at run time.
7970 end Find_Static_Alternative
;
7976 function First_Actual
(Node
: Node_Id
) return Node_Id
is
7980 if No
(Parameter_Associations
(Node
)) then
7984 N
:= First
(Parameter_Associations
(Node
));
7986 if Nkind
(N
) = N_Parameter_Association
then
7987 return First_Named_Actual
(Node
);
7997 function Fix_Msg
(Id
: Entity_Id
; Msg
: String) return String is
7998 Is_Task
: constant Boolean :=
7999 Ekind_In
(Id
, E_Task_Body
, E_Task_Type
)
8000 or else Is_Single_Task_Object
(Id
);
8001 Msg_Last
: constant Natural := Msg
'Last;
8002 Msg_Index
: Natural;
8003 Res
: String (Msg
'Range) := (others => ' ');
8004 Res_Index
: Natural;
8007 -- Copy all characters from the input message Msg to result Res with
8008 -- suitable replacements.
8010 Msg_Index
:= Msg
'First;
8011 Res_Index
:= Res
'First;
8012 while Msg_Index
<= Msg_Last
loop
8014 -- Replace "subprogram" with a different word
8016 if Msg_Index
<= Msg_Last
- 10
8017 and then Msg
(Msg_Index
.. Msg_Index
+ 9) = "subprogram"
8019 if Ekind_In
(Id
, E_Entry
, E_Entry_Family
) then
8020 Res
(Res_Index
.. Res_Index
+ 4) := "entry";
8021 Res_Index
:= Res_Index
+ 5;
8024 Res
(Res_Index
.. Res_Index
+ 8) := "task type";
8025 Res_Index
:= Res_Index
+ 9;
8028 Res
(Res_Index
.. Res_Index
+ 9) := "subprogram";
8029 Res_Index
:= Res_Index
+ 10;
8032 Msg_Index
:= Msg_Index
+ 10;
8034 -- Replace "protected" with a different word
8036 elsif Msg_Index
<= Msg_Last
- 9
8037 and then Msg
(Msg_Index
.. Msg_Index
+ 8) = "protected"
8040 Res
(Res_Index
.. Res_Index
+ 3) := "task";
8041 Res_Index
:= Res_Index
+ 4;
8042 Msg_Index
:= Msg_Index
+ 9;
8044 -- Otherwise copy the character
8047 Res
(Res_Index
) := Msg
(Msg_Index
);
8048 Msg_Index
:= Msg_Index
+ 1;
8049 Res_Index
:= Res_Index
+ 1;
8053 return Res
(Res
'First .. Res_Index
- 1);
8056 -------------------------
8057 -- From_Nested_Package --
8058 -------------------------
8060 function From_Nested_Package
(T
: Entity_Id
) return Boolean is
8061 Pack
: constant Entity_Id
:= Scope
(T
);
8065 Ekind
(Pack
) = E_Package
8066 and then not Is_Frozen
(Pack
)
8067 and then not Scope_Within_Or_Same
(Current_Scope
, Pack
)
8068 and then In_Open_Scopes
(Scope
(Pack
));
8069 end From_Nested_Package
;
8071 -----------------------
8072 -- Gather_Components --
8073 -----------------------
8075 procedure Gather_Components
8077 Comp_List
: Node_Id
;
8078 Governed_By
: List_Id
;
8080 Report_Errors
: out Boolean)
8084 Discrete_Choice
: Node_Id
;
8085 Comp_Item
: Node_Id
;
8087 Discrim
: Entity_Id
;
8088 Discrim_Name
: Node_Id
;
8089 Discrim_Value
: Node_Id
;
8092 Report_Errors
:= False;
8094 if No
(Comp_List
) or else Null_Present
(Comp_List
) then
8097 elsif Present
(Component_Items
(Comp_List
)) then
8098 Comp_Item
:= First
(Component_Items
(Comp_List
));
8104 while Present
(Comp_Item
) loop
8106 -- Skip the tag of a tagged record, the interface tags, as well
8107 -- as all items that are not user components (anonymous types,
8108 -- rep clauses, Parent field, controller field).
8110 if Nkind
(Comp_Item
) = N_Component_Declaration
then
8112 Comp
: constant Entity_Id
:= Defining_Identifier
(Comp_Item
);
8114 if not Is_Tag
(Comp
) and then Chars
(Comp
) /= Name_uParent
then
8115 Append_Elmt
(Comp
, Into
);
8123 if No
(Variant_Part
(Comp_List
)) then
8126 Discrim_Name
:= Name
(Variant_Part
(Comp_List
));
8127 Variant
:= First_Non_Pragma
(Variants
(Variant_Part
(Comp_List
)));
8130 -- Look for the discriminant that governs this variant part.
8131 -- The discriminant *must* be in the Governed_By List
8133 Assoc
:= First
(Governed_By
);
8134 Find_Constraint
: loop
8135 Discrim
:= First
(Choices
(Assoc
));
8136 exit Find_Constraint
when Chars
(Discrim_Name
) = Chars
(Discrim
)
8137 or else (Present
(Corresponding_Discriminant
(Entity
(Discrim
)))
8139 Chars
(Corresponding_Discriminant
(Entity
(Discrim
))) =
8140 Chars
(Discrim_Name
))
8141 or else Chars
(Original_Record_Component
(Entity
(Discrim
)))
8142 = Chars
(Discrim_Name
);
8144 if No
(Next
(Assoc
)) then
8145 if not Is_Constrained
(Typ
)
8146 and then Is_Derived_Type
(Typ
)
8147 and then Present
(Stored_Constraint
(Typ
))
8149 -- If the type is a tagged type with inherited discriminants,
8150 -- use the stored constraint on the parent in order to find
8151 -- the values of discriminants that are otherwise hidden by an
8152 -- explicit constraint. Renamed discriminants are handled in
8155 -- If several parent discriminants are renamed by a single
8156 -- discriminant of the derived type, the call to obtain the
8157 -- Corresponding_Discriminant field only retrieves the last
8158 -- of them. We recover the constraint on the others from the
8159 -- Stored_Constraint as well.
8166 D
:= First_Discriminant
(Etype
(Typ
));
8167 C
:= First_Elmt
(Stored_Constraint
(Typ
));
8168 while Present
(D
) and then Present
(C
) loop
8169 if Chars
(Discrim_Name
) = Chars
(D
) then
8170 if Is_Entity_Name
(Node
(C
))
8171 and then Entity
(Node
(C
)) = Entity
(Discrim
)
8173 -- D is renamed by Discrim, whose value is given in
8180 Make_Component_Association
(Sloc
(Typ
),
8182 (New_Occurrence_Of
(D
, Sloc
(Typ
))),
8183 Duplicate_Subexpr_No_Checks
(Node
(C
)));
8185 exit Find_Constraint
;
8188 Next_Discriminant
(D
);
8195 if No
(Next
(Assoc
)) then
8196 Error_Msg_NE
(" missing value for discriminant&",
8197 First
(Governed_By
), Discrim_Name
);
8198 Report_Errors
:= True;
8203 end loop Find_Constraint
;
8205 Discrim_Value
:= Expression
(Assoc
);
8207 if not Is_OK_Static_Expression
(Discrim_Value
) then
8209 -- If the variant part is governed by a discriminant of the type
8210 -- this is an error. If the variant part and the discriminant are
8211 -- inherited from an ancestor this is legal (AI05-120) unless the
8212 -- components are being gathered for an aggregate, in which case
8213 -- the caller must check Report_Errors.
8215 if Scope
(Original_Record_Component
8216 ((Entity
(First
(Choices
(Assoc
)))))) = Typ
8219 ("value for discriminant & must be static!",
8220 Discrim_Value
, Discrim
);
8221 Why_Not_Static
(Discrim_Value
);
8224 Report_Errors
:= True;
8228 Search_For_Discriminant_Value
: declare
8234 UI_Discrim_Value
: constant Uint
:= Expr_Value
(Discrim_Value
);
8237 Find_Discrete_Value
: while Present
(Variant
) loop
8238 Discrete_Choice
:= First
(Discrete_Choices
(Variant
));
8239 while Present
(Discrete_Choice
) loop
8240 exit Find_Discrete_Value
when
8241 Nkind
(Discrete_Choice
) = N_Others_Choice
;
8243 Get_Index_Bounds
(Discrete_Choice
, Low
, High
);
8245 UI_Low
:= Expr_Value
(Low
);
8246 UI_High
:= Expr_Value
(High
);
8248 exit Find_Discrete_Value
when
8249 UI_Low
<= UI_Discrim_Value
8251 UI_High
>= UI_Discrim_Value
;
8253 Next
(Discrete_Choice
);
8256 Next_Non_Pragma
(Variant
);
8257 end loop Find_Discrete_Value
;
8258 end Search_For_Discriminant_Value
;
8260 -- The case statement must include a variant that corresponds to the
8261 -- value of the discriminant, unless the discriminant type has a
8262 -- static predicate. In that case the absence of an others_choice that
8263 -- would cover this value becomes a run-time error (3.8,1 (21.1/2)).
8266 and then not Has_Static_Predicate
(Etype
(Discrim_Name
))
8269 ("value of discriminant & is out of range", Discrim_Value
, Discrim
);
8270 Report_Errors
:= True;
8274 -- If we have found the corresponding choice, recursively add its
8275 -- components to the Into list. The nested components are part of
8276 -- the same record type.
8278 if Present
(Variant
) then
8280 (Typ
, Component_List
(Variant
), Governed_By
, Into
, Report_Errors
);
8282 end Gather_Components
;
8284 ------------------------
8285 -- Get_Actual_Subtype --
8286 ------------------------
8288 function Get_Actual_Subtype
(N
: Node_Id
) return Entity_Id
is
8289 Typ
: constant Entity_Id
:= Etype
(N
);
8290 Utyp
: Entity_Id
:= Underlying_Type
(Typ
);
8299 -- If what we have is an identifier that references a subprogram
8300 -- formal, or a variable or constant object, then we get the actual
8301 -- subtype from the referenced entity if one has been built.
8303 if Nkind
(N
) = N_Identifier
8305 (Is_Formal
(Entity
(N
))
8306 or else Ekind
(Entity
(N
)) = E_Constant
8307 or else Ekind
(Entity
(N
)) = E_Variable
)
8308 and then Present
(Actual_Subtype
(Entity
(N
)))
8310 return Actual_Subtype
(Entity
(N
));
8312 -- Actual subtype of unchecked union is always itself. We never need
8313 -- the "real" actual subtype. If we did, we couldn't get it anyway
8314 -- because the discriminant is not available. The restrictions on
8315 -- Unchecked_Union are designed to make sure that this is OK.
8317 elsif Is_Unchecked_Union
(Base_Type
(Utyp
)) then
8320 -- Here for the unconstrained case, we must find actual subtype
8321 -- No actual subtype is available, so we must build it on the fly.
8323 -- Checking the type, not the underlying type, for constrainedness
8324 -- seems to be necessary. Maybe all the tests should be on the type???
8326 elsif (not Is_Constrained
(Typ
))
8327 and then (Is_Array_Type
(Utyp
)
8328 or else (Is_Record_Type
(Utyp
)
8329 and then Has_Discriminants
(Utyp
)))
8330 and then not Has_Unknown_Discriminants
(Utyp
)
8331 and then not (Ekind
(Utyp
) = E_String_Literal_Subtype
)
8333 -- Nothing to do if in spec expression (why not???)
8335 if In_Spec_Expression
then
8338 elsif Is_Private_Type
(Typ
) and then not Has_Discriminants
(Typ
) then
8340 -- If the type has no discriminants, there is no subtype to
8341 -- build, even if the underlying type is discriminated.
8345 -- Else build the actual subtype
8348 Decl
:= Build_Actual_Subtype
(Typ
, N
);
8349 Atyp
:= Defining_Identifier
(Decl
);
8351 -- If Build_Actual_Subtype generated a new declaration then use it
8355 -- The actual subtype is an Itype, so analyze the declaration,
8356 -- but do not attach it to the tree, to get the type defined.
8358 Set_Parent
(Decl
, N
);
8359 Set_Is_Itype
(Atyp
);
8360 Analyze
(Decl
, Suppress
=> All_Checks
);
8361 Set_Associated_Node_For_Itype
(Atyp
, N
);
8362 Set_Has_Delayed_Freeze
(Atyp
, False);
8364 -- We need to freeze the actual subtype immediately. This is
8365 -- needed, because otherwise this Itype will not get frozen
8366 -- at all, and it is always safe to freeze on creation because
8367 -- any associated types must be frozen at this point.
8369 Freeze_Itype
(Atyp
, N
);
8372 -- Otherwise we did not build a declaration, so return original
8379 -- For all remaining cases, the actual subtype is the same as
8380 -- the nominal type.
8385 end Get_Actual_Subtype
;
8387 -------------------------------------
8388 -- Get_Actual_Subtype_If_Available --
8389 -------------------------------------
8391 function Get_Actual_Subtype_If_Available
(N
: Node_Id
) return Entity_Id
is
8392 Typ
: constant Entity_Id
:= Etype
(N
);
8395 -- If what we have is an identifier that references a subprogram
8396 -- formal, or a variable or constant object, then we get the actual
8397 -- subtype from the referenced entity if one has been built.
8399 if Nkind
(N
) = N_Identifier
8401 (Is_Formal
(Entity
(N
))
8402 or else Ekind
(Entity
(N
)) = E_Constant
8403 or else Ekind
(Entity
(N
)) = E_Variable
)
8404 and then Present
(Actual_Subtype
(Entity
(N
)))
8406 return Actual_Subtype
(Entity
(N
));
8408 -- Otherwise the Etype of N is returned unchanged
8413 end Get_Actual_Subtype_If_Available
;
8415 ------------------------
8416 -- Get_Body_From_Stub --
8417 ------------------------
8419 function Get_Body_From_Stub
(N
: Node_Id
) return Node_Id
is
8421 return Proper_Body
(Unit
(Library_Unit
(N
)));
8422 end Get_Body_From_Stub
;
8424 ---------------------
8425 -- Get_Cursor_Type --
8426 ---------------------
8428 function Get_Cursor_Type
8430 Typ
: Entity_Id
) return Entity_Id
8434 First_Op
: Entity_Id
;
8438 -- If error already detected, return
8440 if Error_Posted
(Aspect
) then
8444 -- The cursor type for an Iterable aspect is the return type of a
8445 -- non-overloaded First primitive operation. Locate association for
8448 Assoc
:= First
(Component_Associations
(Expression
(Aspect
)));
8450 while Present
(Assoc
) loop
8451 if Chars
(First
(Choices
(Assoc
))) = Name_First
then
8452 First_Op
:= Expression
(Assoc
);
8459 if First_Op
= Any_Id
then
8460 Error_Msg_N
("aspect Iterable must specify First operation", Aspect
);
8466 -- Locate function with desired name and profile in scope of type
8467 -- In the rare case where the type is an integer type, a base type
8468 -- is created for it, check that the base type of the first formal
8469 -- of First matches the base type of the domain.
8471 Func
:= First_Entity
(Scope
(Typ
));
8472 while Present
(Func
) loop
8473 if Chars
(Func
) = Chars
(First_Op
)
8474 and then Ekind
(Func
) = E_Function
8475 and then Present
(First_Formal
(Func
))
8476 and then Base_Type
(Etype
(First_Formal
(Func
))) = Base_Type
(Typ
)
8477 and then No
(Next_Formal
(First_Formal
(Func
)))
8479 if Cursor
/= Any_Type
then
8481 ("Operation First for iterable type must be unique", Aspect
);
8484 Cursor
:= Etype
(Func
);
8491 -- If not found, no way to resolve remaining primitives.
8493 if Cursor
= Any_Type
then
8495 ("No legal primitive operation First for Iterable type", Aspect
);
8499 end Get_Cursor_Type
;
8501 function Get_Cursor_Type
(Typ
: Entity_Id
) return Entity_Id
is
8503 return Etype
(Get_Iterable_Type_Primitive
(Typ
, Name_First
));
8504 end Get_Cursor_Type
;
8506 -------------------------------
8507 -- Get_Default_External_Name --
8508 -------------------------------
8510 function Get_Default_External_Name
(E
: Node_Or_Entity_Id
) return Node_Id
is
8512 Get_Decoded_Name_String
(Chars
(E
));
8514 if Opt
.External_Name_Imp_Casing
= Uppercase
then
8515 Set_Casing
(All_Upper_Case
);
8517 Set_Casing
(All_Lower_Case
);
8521 Make_String_Literal
(Sloc
(E
),
8522 Strval
=> String_From_Name_Buffer
);
8523 end Get_Default_External_Name
;
8525 --------------------------
8526 -- Get_Enclosing_Object --
8527 --------------------------
8529 function Get_Enclosing_Object
(N
: Node_Id
) return Entity_Id
is
8531 if Is_Entity_Name
(N
) then
8535 when N_Indexed_Component
8536 | N_Selected_Component
8539 -- If not generating code, a dereference may be left implicit.
8540 -- In thoses cases, return Empty.
8542 if Is_Access_Type
(Etype
(Prefix
(N
))) then
8545 return Get_Enclosing_Object
(Prefix
(N
));
8548 when N_Type_Conversion
=>
8549 return Get_Enclosing_Object
(Expression
(N
));
8555 end Get_Enclosing_Object
;
8557 ---------------------------
8558 -- Get_Enum_Lit_From_Pos --
8559 ---------------------------
8561 function Get_Enum_Lit_From_Pos
8564 Loc
: Source_Ptr
) return Node_Id
8566 Btyp
: Entity_Id
:= Base_Type
(T
);
8571 -- In the case where the literal is of type Character, Wide_Character
8572 -- or Wide_Wide_Character or of a type derived from them, there needs
8573 -- to be some special handling since there is no explicit chain of
8574 -- literals to search. Instead, an N_Character_Literal node is created
8575 -- with the appropriate Char_Code and Chars fields.
8577 if Is_Standard_Character_Type
(T
) then
8578 Set_Character_Literal_Name
(UI_To_CC
(Pos
));
8581 Make_Character_Literal
(Loc
,
8583 Char_Literal_Value
=> Pos
);
8585 -- For all other cases, we have a complete table of literals, and
8586 -- we simply iterate through the chain of literal until the one
8587 -- with the desired position value is found.
8590 if Is_Private_Type
(Btyp
) and then Present
(Full_View
(Btyp
)) then
8591 Btyp
:= Full_View
(Btyp
);
8594 Lit
:= First_Literal
(Btyp
);
8595 for J
in 1 .. UI_To_Int
(Pos
) loop
8598 -- If Lit is Empty, Pos is not in range, so raise Constraint_Error
8599 -- inside the loop to avoid calling Next_Literal on Empty.
8602 raise Constraint_Error
;
8606 -- Create a new node from Lit, with source location provided by Loc
8607 -- if not equal to No_Location, or by copying the source location of
8612 if LLoc
= No_Location
then
8616 return New_Occurrence_Of
(Lit
, LLoc
);
8618 end Get_Enum_Lit_From_Pos
;
8620 ------------------------
8621 -- Get_Generic_Entity --
8622 ------------------------
8624 function Get_Generic_Entity
(N
: Node_Id
) return Entity_Id
is
8625 Ent
: constant Entity_Id
:= Entity
(Name
(N
));
8627 if Present
(Renamed_Object
(Ent
)) then
8628 return Renamed_Object
(Ent
);
8632 end Get_Generic_Entity
;
8634 -------------------------------------
8635 -- Get_Incomplete_View_Of_Ancestor --
8636 -------------------------------------
8638 function Get_Incomplete_View_Of_Ancestor
(E
: Entity_Id
) return Entity_Id
is
8639 Cur_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
8640 Par_Scope
: Entity_Id
;
8641 Par_Type
: Entity_Id
;
8644 -- The incomplete view of an ancestor is only relevant for private
8645 -- derived types in child units.
8647 if not Is_Derived_Type
(E
)
8648 or else not Is_Child_Unit
(Cur_Unit
)
8653 Par_Scope
:= Scope
(Cur_Unit
);
8654 if No
(Par_Scope
) then
8658 Par_Type
:= Etype
(Base_Type
(E
));
8660 -- Traverse list of ancestor types until we find one declared in
8661 -- a parent or grandparent unit (two levels seem sufficient).
8663 while Present
(Par_Type
) loop
8664 if Scope
(Par_Type
) = Par_Scope
8665 or else Scope
(Par_Type
) = Scope
(Par_Scope
)
8669 elsif not Is_Derived_Type
(Par_Type
) then
8673 Par_Type
:= Etype
(Base_Type
(Par_Type
));
8677 -- If none found, there is no relevant ancestor type.
8681 end Get_Incomplete_View_Of_Ancestor
;
8683 ----------------------
8684 -- Get_Index_Bounds --
8685 ----------------------
8687 procedure Get_Index_Bounds
8691 Use_Full_View
: Boolean := False)
8693 function Scalar_Range_Of_Type
(Typ
: Entity_Id
) return Node_Id
;
8694 -- Obtain the scalar range of type Typ. If flag Use_Full_View is set and
8695 -- Typ qualifies, the scalar range is obtained from the full view of the
8698 --------------------------
8699 -- Scalar_Range_Of_Type --
8700 --------------------------
8702 function Scalar_Range_Of_Type
(Typ
: Entity_Id
) return Node_Id
is
8703 T
: Entity_Id
:= Typ
;
8706 if Use_Full_View
and then Present
(Full_View
(T
)) then
8710 return Scalar_Range
(T
);
8711 end Scalar_Range_Of_Type
;
8715 Kind
: constant Node_Kind
:= Nkind
(N
);
8718 -- Start of processing for Get_Index_Bounds
8721 if Kind
= N_Range
then
8723 H
:= High_Bound
(N
);
8725 elsif Kind
= N_Subtype_Indication
then
8726 Rng
:= Range_Expression
(Constraint
(N
));
8734 L
:= Low_Bound
(Range_Expression
(Constraint
(N
)));
8735 H
:= High_Bound
(Range_Expression
(Constraint
(N
)));
8738 elsif Is_Entity_Name
(N
) and then Is_Type
(Entity
(N
)) then
8739 Rng
:= Scalar_Range_Of_Type
(Entity
(N
));
8741 if Error_Posted
(Rng
) then
8745 elsif Nkind
(Rng
) = N_Subtype_Indication
then
8746 Get_Index_Bounds
(Rng
, L
, H
);
8749 L
:= Low_Bound
(Rng
);
8750 H
:= High_Bound
(Rng
);
8754 -- N is an expression, indicating a range with one value
8759 end Get_Index_Bounds
;
8761 -----------------------------
8762 -- Get_Interfacing_Aspects --
8763 -----------------------------
8765 procedure Get_Interfacing_Aspects
8766 (Iface_Asp
: Node_Id
;
8767 Conv_Asp
: out Node_Id
;
8768 EN_Asp
: out Node_Id
;
8769 Expo_Asp
: out Node_Id
;
8770 Imp_Asp
: out Node_Id
;
8771 LN_Asp
: out Node_Id
;
8772 Do_Checks
: Boolean := False)
8774 procedure Save_Or_Duplication_Error
8776 To
: in out Node_Id
);
8777 -- Save the value of aspect Asp in node To. If To already has a value,
8778 -- then this is considered a duplicate use of aspect. Emit an error if
8779 -- flag Do_Checks is set.
8781 -------------------------------
8782 -- Save_Or_Duplication_Error --
8783 -------------------------------
8785 procedure Save_Or_Duplication_Error
8787 To
: in out Node_Id
)
8790 -- Detect an extra aspect and issue an error
8792 if Present
(To
) then
8794 Error_Msg_Name_1
:= Chars
(Identifier
(Asp
));
8795 Error_Msg_Sloc
:= Sloc
(To
);
8796 Error_Msg_N
("aspect % previously given #", Asp
);
8799 -- Otherwise capture the aspect
8804 end Save_Or_Duplication_Error
;
8811 -- The following variables capture each individual aspect
8813 Conv
: Node_Id
:= Empty
;
8814 EN
: Node_Id
:= Empty
;
8815 Expo
: Node_Id
:= Empty
;
8816 Imp
: Node_Id
:= Empty
;
8817 LN
: Node_Id
:= Empty
;
8819 -- Start of processing for Get_Interfacing_Aspects
8822 -- The input interfacing aspect should reside in an aspect specification
8825 pragma Assert
(Is_List_Member
(Iface_Asp
));
8827 -- Examine the aspect specifications of the related entity. Find and
8828 -- capture all interfacing aspects. Detect duplicates and emit errors
8831 Asp
:= First
(List_Containing
(Iface_Asp
));
8832 while Present
(Asp
) loop
8833 Asp_Id
:= Get_Aspect_Id
(Asp
);
8835 if Asp_Id
= Aspect_Convention
then
8836 Save_Or_Duplication_Error
(Asp
, Conv
);
8838 elsif Asp_Id
= Aspect_External_Name
then
8839 Save_Or_Duplication_Error
(Asp
, EN
);
8841 elsif Asp_Id
= Aspect_Export
then
8842 Save_Or_Duplication_Error
(Asp
, Expo
);
8844 elsif Asp_Id
= Aspect_Import
then
8845 Save_Or_Duplication_Error
(Asp
, Imp
);
8847 elsif Asp_Id
= Aspect_Link_Name
then
8848 Save_Or_Duplication_Error
(Asp
, LN
);
8859 end Get_Interfacing_Aspects
;
8861 ---------------------------------
8862 -- Get_Iterable_Type_Primitive --
8863 ---------------------------------
8865 function Get_Iterable_Type_Primitive
8867 Nam
: Name_Id
) return Entity_Id
8869 Funcs
: constant Node_Id
:= Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
);
8877 Assoc
:= First
(Component_Associations
(Funcs
));
8878 while Present
(Assoc
) loop
8879 if Chars
(First
(Choices
(Assoc
))) = Nam
then
8880 return Entity
(Expression
(Assoc
));
8883 Assoc
:= Next
(Assoc
);
8888 end Get_Iterable_Type_Primitive
;
8890 ----------------------------------
8891 -- Get_Library_Unit_Name_string --
8892 ----------------------------------
8894 procedure Get_Library_Unit_Name_String
(Decl_Node
: Node_Id
) is
8895 Unit_Name_Id
: constant Unit_Name_Type
:= Get_Unit_Name
(Decl_Node
);
8898 Get_Unit_Name_String
(Unit_Name_Id
);
8900 -- Remove seven last character (" (spec)" or " (body)")
8902 Name_Len
:= Name_Len
- 7;
8903 pragma Assert
(Name_Buffer
(Name_Len
+ 1) = ' ');
8904 end Get_Library_Unit_Name_String
;
8906 --------------------------
8907 -- Get_Max_Queue_Length --
8908 --------------------------
8910 function Get_Max_Queue_Length
(Id
: Entity_Id
) return Uint
is
8911 pragma Assert
(Is_Entry
(Id
));
8912 Prag
: constant Entity_Id
:= Get_Pragma
(Id
, Pragma_Max_Queue_Length
);
8915 -- A value of 0 represents no maximum specified, and entries and entry
8916 -- families with no Max_Queue_Length aspect or pragma default to it.
8918 if not Present
(Prag
) then
8922 return Intval
(Expression
(First
(Pragma_Argument_Associations
(Prag
))));
8923 end Get_Max_Queue_Length
;
8925 ------------------------
8926 -- Get_Name_Entity_Id --
8927 ------------------------
8929 function Get_Name_Entity_Id
(Id
: Name_Id
) return Entity_Id
is
8931 return Entity_Id
(Get_Name_Table_Int
(Id
));
8932 end Get_Name_Entity_Id
;
8934 ------------------------------
8935 -- Get_Name_From_CTC_Pragma --
8936 ------------------------------
8938 function Get_Name_From_CTC_Pragma
(N
: Node_Id
) return String_Id
is
8939 Arg
: constant Node_Id
:=
8940 Get_Pragma_Arg
(First
(Pragma_Argument_Associations
(N
)));
8942 return Strval
(Expr_Value_S
(Arg
));
8943 end Get_Name_From_CTC_Pragma
;
8945 -----------------------
8946 -- Get_Parent_Entity --
8947 -----------------------
8949 function Get_Parent_Entity
(Unit
: Node_Id
) return Entity_Id
is
8951 if Nkind
(Unit
) = N_Package_Body
8952 and then Nkind
(Original_Node
(Unit
)) = N_Package_Instantiation
8954 return Defining_Entity
8955 (Specification
(Instance_Spec
(Original_Node
(Unit
))));
8956 elsif Nkind
(Unit
) = N_Package_Instantiation
then
8957 return Defining_Entity
(Specification
(Instance_Spec
(Unit
)));
8959 return Defining_Entity
(Unit
);
8961 end Get_Parent_Entity
;
8967 function Get_Pragma_Id
(N
: Node_Id
) return Pragma_Id
is
8969 return Get_Pragma_Id
(Pragma_Name_Unmapped
(N
));
8972 ------------------------
8973 -- Get_Qualified_Name --
8974 ------------------------
8976 function Get_Qualified_Name
8978 Suffix
: Entity_Id
:= Empty
) return Name_Id
8980 Suffix_Nam
: Name_Id
:= No_Name
;
8983 if Present
(Suffix
) then
8984 Suffix_Nam
:= Chars
(Suffix
);
8987 return Get_Qualified_Name
(Chars
(Id
), Suffix_Nam
, Scope
(Id
));
8988 end Get_Qualified_Name
;
8990 function Get_Qualified_Name
8992 Suffix
: Name_Id
:= No_Name
;
8993 Scop
: Entity_Id
:= Current_Scope
) return Name_Id
8995 procedure Add_Scope
(S
: Entity_Id
);
8996 -- Add the fully qualified form of scope S to the name buffer. The
9004 procedure Add_Scope
(S
: Entity_Id
) is
9009 elsif S
= Standard_Standard
then
9013 Add_Scope
(Scope
(S
));
9014 Get_Name_String_And_Append
(Chars
(S
));
9015 Add_Str_To_Name_Buffer
("__");
9019 -- Start of processing for Get_Qualified_Name
9025 -- Append the base name after all scopes have been chained
9027 Get_Name_String_And_Append
(Nam
);
9029 -- Append the suffix (if present)
9031 if Suffix
/= No_Name
then
9032 Add_Str_To_Name_Buffer
("__");
9033 Get_Name_String_And_Append
(Suffix
);
9037 end Get_Qualified_Name
;
9039 -----------------------
9040 -- Get_Reason_String --
9041 -----------------------
9043 procedure Get_Reason_String
(N
: Node_Id
) is
9045 if Nkind
(N
) = N_String_Literal
then
9046 Store_String_Chars
(Strval
(N
));
9048 elsif Nkind
(N
) = N_Op_Concat
then
9049 Get_Reason_String
(Left_Opnd
(N
));
9050 Get_Reason_String
(Right_Opnd
(N
));
9052 -- If not of required form, error
9056 ("Reason for pragma Warnings has wrong form", N
);
9058 ("\must be string literal or concatenation of string literals", N
);
9061 end Get_Reason_String
;
9063 --------------------------------
9064 -- Get_Reference_Discriminant --
9065 --------------------------------
9067 function Get_Reference_Discriminant
(Typ
: Entity_Id
) return Entity_Id
is
9071 D
:= First_Discriminant
(Typ
);
9072 while Present
(D
) loop
9073 if Has_Implicit_Dereference
(D
) then
9076 Next_Discriminant
(D
);
9080 end Get_Reference_Discriminant
;
9082 ---------------------------
9083 -- Get_Referenced_Object --
9084 ---------------------------
9086 function Get_Referenced_Object
(N
: Node_Id
) return Node_Id
is
9091 while Is_Entity_Name
(R
)
9092 and then Present
(Renamed_Object
(Entity
(R
)))
9094 R
:= Renamed_Object
(Entity
(R
));
9098 end Get_Referenced_Object
;
9100 ------------------------
9101 -- Get_Renamed_Entity --
9102 ------------------------
9104 function Get_Renamed_Entity
(E
: Entity_Id
) return Entity_Id
is
9109 while Present
(Renamed_Entity
(R
)) loop
9110 R
:= Renamed_Entity
(R
);
9114 end Get_Renamed_Entity
;
9116 -----------------------
9117 -- Get_Return_Object --
9118 -----------------------
9120 function Get_Return_Object
(N
: Node_Id
) return Entity_Id
is
9124 Decl
:= First
(Return_Object_Declarations
(N
));
9125 while Present
(Decl
) loop
9126 exit when Nkind
(Decl
) = N_Object_Declaration
9127 and then Is_Return_Object
(Defining_Identifier
(Decl
));
9131 pragma Assert
(Present
(Decl
));
9132 return Defining_Identifier
(Decl
);
9133 end Get_Return_Object
;
9135 ---------------------------
9136 -- Get_Subprogram_Entity --
9137 ---------------------------
9139 function Get_Subprogram_Entity
(Nod
: Node_Id
) return Entity_Id
is
9141 Subp_Id
: Entity_Id
;
9144 if Nkind
(Nod
) = N_Accept_Statement
then
9145 Subp
:= Entry_Direct_Name
(Nod
);
9147 elsif Nkind
(Nod
) = N_Slice
then
9148 Subp
:= Prefix
(Nod
);
9154 -- Strip the subprogram call
9157 if Nkind_In
(Subp
, N_Explicit_Dereference
,
9158 N_Indexed_Component
,
9159 N_Selected_Component
)
9161 Subp
:= Prefix
(Subp
);
9163 elsif Nkind_In
(Subp
, N_Type_Conversion
,
9164 N_Unchecked_Type_Conversion
)
9166 Subp
:= Expression
(Subp
);
9173 -- Extract the entity of the subprogram call
9175 if Is_Entity_Name
(Subp
) then
9176 Subp_Id
:= Entity
(Subp
);
9178 if Ekind
(Subp_Id
) = E_Access_Subprogram_Type
then
9179 Subp_Id
:= Directly_Designated_Type
(Subp_Id
);
9182 if Is_Subprogram
(Subp_Id
) then
9188 -- The search did not find a construct that denotes a subprogram
9193 end Get_Subprogram_Entity
;
9195 -----------------------------
9196 -- Get_Task_Body_Procedure --
9197 -----------------------------
9199 function Get_Task_Body_Procedure
(E
: Entity_Id
) return Node_Id
is
9201 -- Note: A task type may be the completion of a private type with
9202 -- discriminants. When performing elaboration checks on a task
9203 -- declaration, the current view of the type may be the private one,
9204 -- and the procedure that holds the body of the task is held in its
9207 -- This is an odd function, why not have Task_Body_Procedure do
9208 -- the following digging???
9210 return Task_Body_Procedure
(Underlying_Type
(Root_Type
(E
)));
9211 end Get_Task_Body_Procedure
;
9213 -------------------------
9214 -- Get_User_Defined_Eq --
9215 -------------------------
9217 function Get_User_Defined_Eq
(E
: Entity_Id
) return Entity_Id
is
9222 Prim
:= First_Elmt
(Collect_Primitive_Operations
(E
));
9223 while Present
(Prim
) loop
9226 if Chars
(Op
) = Name_Op_Eq
9227 and then Etype
(Op
) = Standard_Boolean
9228 and then Etype
(First_Formal
(Op
)) = E
9229 and then Etype
(Next_Formal
(First_Formal
(Op
))) = E
9238 end Get_User_Defined_Eq
;
9246 Priv_Typ
: out Entity_Id
;
9247 Full_Typ
: out Entity_Id
;
9248 Full_Base
: out Entity_Id
;
9249 CRec_Typ
: out Entity_Id
)
9251 IP_View
: Entity_Id
;
9254 -- Assume that none of the views can be recovered
9261 -- The input type is the corresponding record type of a protected or a
9264 if Ekind
(Typ
) = E_Record_Type
9265 and then Is_Concurrent_Record_Type
(Typ
)
9268 Full_Typ
:= Corresponding_Concurrent_Type
(CRec_Typ
);
9269 Full_Base
:= Base_Type
(Full_Typ
);
9270 Priv_Typ
:= Incomplete_Or_Partial_View
(Full_Typ
);
9272 -- Otherwise the input type denotes an arbitrary type
9275 IP_View
:= Incomplete_Or_Partial_View
(Typ
);
9277 -- The input type denotes the full view of a private type
9279 if Present
(IP_View
) then
9280 Priv_Typ
:= IP_View
;
9283 -- The input type is a private type
9285 elsif Is_Private_Type
(Typ
) then
9287 Full_Typ
:= Full_View
(Priv_Typ
);
9289 -- Otherwise the input type does not have any views
9295 if Present
(Full_Typ
) then
9296 Full_Base
:= Base_Type
(Full_Typ
);
9298 if Ekind_In
(Full_Typ
, E_Protected_Type
, E_Task_Type
) then
9299 CRec_Typ
:= Corresponding_Record_Type
(Full_Typ
);
9305 -----------------------
9306 -- Has_Access_Values --
9307 -----------------------
9309 function Has_Access_Values
(T
: Entity_Id
) return Boolean is
9310 Typ
: constant Entity_Id
:= Underlying_Type
(T
);
9313 -- Case of a private type which is not completed yet. This can only
9314 -- happen in the case of a generic format type appearing directly, or
9315 -- as a component of the type to which this function is being applied
9316 -- at the top level. Return False in this case, since we certainly do
9317 -- not know that the type contains access types.
9322 elsif Is_Access_Type
(Typ
) then
9325 elsif Is_Array_Type
(Typ
) then
9326 return Has_Access_Values
(Component_Type
(Typ
));
9328 elsif Is_Record_Type
(Typ
) then
9333 -- Loop to Check components
9335 Comp
:= First_Component_Or_Discriminant
(Typ
);
9336 while Present
(Comp
) loop
9338 -- Check for access component, tag field does not count, even
9339 -- though it is implemented internally using an access type.
9341 if Has_Access_Values
(Etype
(Comp
))
9342 and then Chars
(Comp
) /= Name_uTag
9347 Next_Component_Or_Discriminant
(Comp
);
9356 end Has_Access_Values
;
9358 ------------------------------
9359 -- Has_Compatible_Alignment --
9360 ------------------------------
9362 function Has_Compatible_Alignment
9365 Layout_Done
: Boolean) return Alignment_Result
9367 function Has_Compatible_Alignment_Internal
9370 Layout_Done
: Boolean;
9371 Default
: Alignment_Result
) return Alignment_Result
;
9372 -- This is the internal recursive function that actually does the work.
9373 -- There is one additional parameter, which says what the result should
9374 -- be if no alignment information is found, and there is no definite
9375 -- indication of compatible alignments. At the outer level, this is set
9376 -- to Unknown, but for internal recursive calls in the case where types
9377 -- are known to be correct, it is set to Known_Compatible.
9379 ---------------------------------------
9380 -- Has_Compatible_Alignment_Internal --
9381 ---------------------------------------
9383 function Has_Compatible_Alignment_Internal
9386 Layout_Done
: Boolean;
9387 Default
: Alignment_Result
) return Alignment_Result
9389 Result
: Alignment_Result
:= Known_Compatible
;
9390 -- Holds the current status of the result. Note that once a value of
9391 -- Known_Incompatible is set, it is sticky and does not get changed
9392 -- to Unknown (the value in Result only gets worse as we go along,
9395 Offs
: Uint
:= No_Uint
;
9396 -- Set to a factor of the offset from the base object when Expr is a
9397 -- selected or indexed component, based on Component_Bit_Offset and
9398 -- Component_Size respectively. A negative value is used to represent
9399 -- a value which is not known at compile time.
9401 procedure Check_Prefix
;
9402 -- Checks the prefix recursively in the case where the expression
9403 -- is an indexed or selected component.
9405 procedure Set_Result
(R
: Alignment_Result
);
9406 -- If R represents a worse outcome (unknown instead of known
9407 -- compatible, or known incompatible), then set Result to R.
9413 procedure Check_Prefix
is
9415 -- The subtlety here is that in doing a recursive call to check
9416 -- the prefix, we have to decide what to do in the case where we
9417 -- don't find any specific indication of an alignment problem.
9419 -- At the outer level, we normally set Unknown as the result in
9420 -- this case, since we can only set Known_Compatible if we really
9421 -- know that the alignment value is OK, but for the recursive
9422 -- call, in the case where the types match, and we have not
9423 -- specified a peculiar alignment for the object, we are only
9424 -- concerned about suspicious rep clauses, the default case does
9425 -- not affect us, since the compiler will, in the absence of such
9426 -- rep clauses, ensure that the alignment is correct.
9428 if Default
= Known_Compatible
9430 (Etype
(Obj
) = Etype
(Expr
)
9431 and then (Unknown_Alignment
(Obj
)
9433 Alignment
(Obj
) = Alignment
(Etype
(Obj
))))
9436 (Has_Compatible_Alignment_Internal
9437 (Obj
, Prefix
(Expr
), Layout_Done
, Known_Compatible
));
9439 -- In all other cases, we need a full check on the prefix
9443 (Has_Compatible_Alignment_Internal
9444 (Obj
, Prefix
(Expr
), Layout_Done
, Unknown
));
9452 procedure Set_Result
(R
: Alignment_Result
) is
9459 -- Start of processing for Has_Compatible_Alignment_Internal
9462 -- If Expr is a selected component, we must make sure there is no
9463 -- potentially troublesome component clause and that the record is
9464 -- not packed if the layout is not done.
9466 if Nkind
(Expr
) = N_Selected_Component
then
9468 -- Packing generates unknown alignment if layout is not done
9470 if Is_Packed
(Etype
(Prefix
(Expr
))) and then not Layout_Done
then
9471 Set_Result
(Unknown
);
9474 -- Check prefix and component offset
9477 Offs
:= Component_Bit_Offset
(Entity
(Selector_Name
(Expr
)));
9479 -- If Expr is an indexed component, we must make sure there is no
9480 -- potentially troublesome Component_Size clause and that the array
9481 -- is not bit-packed if the layout is not done.
9483 elsif Nkind
(Expr
) = N_Indexed_Component
then
9485 Typ
: constant Entity_Id
:= Etype
(Prefix
(Expr
));
9488 -- Packing generates unknown alignment if layout is not done
9490 if Is_Bit_Packed_Array
(Typ
) and then not Layout_Done
then
9491 Set_Result
(Unknown
);
9494 -- Check prefix and component offset (or at least size)
9497 Offs
:= Indexed_Component_Bit_Offset
(Expr
);
9498 if Offs
= No_Uint
then
9499 Offs
:= Component_Size
(Typ
);
9504 -- If we have a null offset, the result is entirely determined by
9505 -- the base object and has already been computed recursively.
9507 if Offs
= Uint_0
then
9510 -- Case where we know the alignment of the object
9512 elsif Known_Alignment
(Obj
) then
9514 ObjA
: constant Uint
:= Alignment
(Obj
);
9515 ExpA
: Uint
:= No_Uint
;
9516 SizA
: Uint
:= No_Uint
;
9519 -- If alignment of Obj is 1, then we are always OK
9522 Set_Result
(Known_Compatible
);
9524 -- Alignment of Obj is greater than 1, so we need to check
9527 -- If we have an offset, see if it is compatible
9529 if Offs
/= No_Uint
and Offs
> Uint_0
then
9530 if Offs
mod (System_Storage_Unit
* ObjA
) /= 0 then
9531 Set_Result
(Known_Incompatible
);
9534 -- See if Expr is an object with known alignment
9536 elsif Is_Entity_Name
(Expr
)
9537 and then Known_Alignment
(Entity
(Expr
))
9539 ExpA
:= Alignment
(Entity
(Expr
));
9541 -- Otherwise, we can use the alignment of the type of
9542 -- Expr given that we already checked for
9543 -- discombobulating rep clauses for the cases of indexed
9544 -- and selected components above.
9546 elsif Known_Alignment
(Etype
(Expr
)) then
9547 ExpA
:= Alignment
(Etype
(Expr
));
9549 -- Otherwise the alignment is unknown
9552 Set_Result
(Default
);
9555 -- If we got an alignment, see if it is acceptable
9557 if ExpA
/= No_Uint
and then ExpA
< ObjA
then
9558 Set_Result
(Known_Incompatible
);
9561 -- If Expr is not a piece of a larger object, see if size
9562 -- is given. If so, check that it is not too small for the
9563 -- required alignment.
9565 if Offs
/= No_Uint
then
9568 -- See if Expr is an object with known size
9570 elsif Is_Entity_Name
(Expr
)
9571 and then Known_Static_Esize
(Entity
(Expr
))
9573 SizA
:= Esize
(Entity
(Expr
));
9575 -- Otherwise, we check the object size of the Expr type
9577 elsif Known_Static_Esize
(Etype
(Expr
)) then
9578 SizA
:= Esize
(Etype
(Expr
));
9581 -- If we got a size, see if it is a multiple of the Obj
9582 -- alignment, if not, then the alignment cannot be
9583 -- acceptable, since the size is always a multiple of the
9586 if SizA
/= No_Uint
then
9587 if SizA
mod (ObjA
* Ttypes
.System_Storage_Unit
) /= 0 then
9588 Set_Result
(Known_Incompatible
);
9594 -- If we do not know required alignment, any non-zero offset is a
9595 -- potential problem (but certainly may be OK, so result is unknown).
9597 elsif Offs
/= No_Uint
then
9598 Set_Result
(Unknown
);
9600 -- If we can't find the result by direct comparison of alignment
9601 -- values, then there is still one case that we can determine known
9602 -- result, and that is when we can determine that the types are the
9603 -- same, and no alignments are specified. Then we known that the
9604 -- alignments are compatible, even if we don't know the alignment
9605 -- value in the front end.
9607 elsif Etype
(Obj
) = Etype
(Expr
) then
9609 -- Types are the same, but we have to check for possible size
9610 -- and alignments on the Expr object that may make the alignment
9611 -- different, even though the types are the same.
9613 if Is_Entity_Name
(Expr
) then
9615 -- First check alignment of the Expr object. Any alignment less
9616 -- than Maximum_Alignment is worrisome since this is the case
9617 -- where we do not know the alignment of Obj.
9619 if Known_Alignment
(Entity
(Expr
))
9620 and then UI_To_Int
(Alignment
(Entity
(Expr
))) <
9621 Ttypes
.Maximum_Alignment
9623 Set_Result
(Unknown
);
9625 -- Now check size of Expr object. Any size that is not an
9626 -- even multiple of Maximum_Alignment is also worrisome
9627 -- since it may cause the alignment of the object to be less
9628 -- than the alignment of the type.
9630 elsif Known_Static_Esize
(Entity
(Expr
))
9632 (UI_To_Int
(Esize
(Entity
(Expr
))) mod
9633 (Ttypes
.Maximum_Alignment
* Ttypes
.System_Storage_Unit
))
9636 Set_Result
(Unknown
);
9638 -- Otherwise same type is decisive
9641 Set_Result
(Known_Compatible
);
9645 -- Another case to deal with is when there is an explicit size or
9646 -- alignment clause when the types are not the same. If so, then the
9647 -- result is Unknown. We don't need to do this test if the Default is
9648 -- Unknown, since that result will be set in any case.
9650 elsif Default
/= Unknown
9651 and then (Has_Size_Clause
(Etype
(Expr
))
9653 Has_Alignment_Clause
(Etype
(Expr
)))
9655 Set_Result
(Unknown
);
9657 -- If no indication found, set default
9660 Set_Result
(Default
);
9663 -- Return worst result found
9666 end Has_Compatible_Alignment_Internal
;
9668 -- Start of processing for Has_Compatible_Alignment
9671 -- If Obj has no specified alignment, then set alignment from the type
9672 -- alignment. Perhaps we should always do this, but for sure we should
9673 -- do it when there is an address clause since we can do more if the
9674 -- alignment is known.
9676 if Unknown_Alignment
(Obj
) then
9677 Set_Alignment
(Obj
, Alignment
(Etype
(Obj
)));
9680 -- Now do the internal call that does all the work
9683 Has_Compatible_Alignment_Internal
(Obj
, Expr
, Layout_Done
, Unknown
);
9684 end Has_Compatible_Alignment
;
9686 ----------------------
9687 -- Has_Declarations --
9688 ----------------------
9690 function Has_Declarations
(N
: Node_Id
) return Boolean is
9692 return Nkind_In
(Nkind
(N
), N_Accept_Statement
,
9694 N_Compilation_Unit_Aux
,
9700 N_Package_Specification
);
9701 end Has_Declarations
;
9703 ---------------------------------
9704 -- Has_Defaulted_Discriminants --
9705 ---------------------------------
9707 function Has_Defaulted_Discriminants
(Typ
: Entity_Id
) return Boolean is
9709 return Has_Discriminants
(Typ
)
9710 and then Present
(First_Discriminant
(Typ
))
9711 and then Present
(Discriminant_Default_Value
9712 (First_Discriminant
(Typ
)));
9713 end Has_Defaulted_Discriminants
;
9719 function Has_Denormals
(E
: Entity_Id
) return Boolean is
9721 return Is_Floating_Point_Type
(E
) and then Denorm_On_Target
;
9724 -------------------------------------------
9725 -- Has_Discriminant_Dependent_Constraint --
9726 -------------------------------------------
9728 function Has_Discriminant_Dependent_Constraint
9729 (Comp
: Entity_Id
) return Boolean
9731 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
9732 Subt_Indic
: Node_Id
;
9737 -- Discriminants can't depend on discriminants
9739 if Ekind
(Comp
) = E_Discriminant
then
9743 Subt_Indic
:= Subtype_Indication
(Component_Definition
(Comp_Decl
));
9745 if Nkind
(Subt_Indic
) = N_Subtype_Indication
then
9746 Constr
:= Constraint
(Subt_Indic
);
9748 if Nkind
(Constr
) = N_Index_Or_Discriminant_Constraint
then
9749 Assn
:= First
(Constraints
(Constr
));
9750 while Present
(Assn
) loop
9751 case Nkind
(Assn
) is
9754 | N_Subtype_Indication
9756 if Depends_On_Discriminant
(Assn
) then
9760 when N_Discriminant_Association
=>
9761 if Depends_On_Discriminant
(Expression
(Assn
)) then
9776 end Has_Discriminant_Dependent_Constraint
;
9778 --------------------------------------
9779 -- Has_Effectively_Volatile_Profile --
9780 --------------------------------------
9782 function Has_Effectively_Volatile_Profile
9783 (Subp_Id
: Entity_Id
) return Boolean
9788 -- Inspect the formal parameters looking for an effectively volatile
9791 Formal
:= First_Formal
(Subp_Id
);
9792 while Present
(Formal
) loop
9793 if Is_Effectively_Volatile
(Etype
(Formal
)) then
9797 Next_Formal
(Formal
);
9800 -- Inspect the return type of functions
9802 if Ekind_In
(Subp_Id
, E_Function
, E_Generic_Function
)
9803 and then Is_Effectively_Volatile
(Etype
(Subp_Id
))
9809 end Has_Effectively_Volatile_Profile
;
9811 --------------------------
9812 -- Has_Enabled_Property --
9813 --------------------------
9815 function Has_Enabled_Property
9816 (Item_Id
: Entity_Id
;
9817 Property
: Name_Id
) return Boolean
9819 function Protected_Object_Has_Enabled_Property
return Boolean;
9820 -- Determine whether a protected object denoted by Item_Id has the
9821 -- property enabled.
9823 function State_Has_Enabled_Property
return Boolean;
9824 -- Determine whether a state denoted by Item_Id has the property enabled
9826 function Variable_Has_Enabled_Property
return Boolean;
9827 -- Determine whether a variable denoted by Item_Id has the property
9830 -------------------------------------------
9831 -- Protected_Object_Has_Enabled_Property --
9832 -------------------------------------------
9834 function Protected_Object_Has_Enabled_Property
return Boolean is
9835 Constits
: constant Elist_Id
:= Part_Of_Constituents
(Item_Id
);
9836 Constit_Elmt
: Elmt_Id
;
9837 Constit_Id
: Entity_Id
;
9840 -- Protected objects always have the properties Async_Readers and
9841 -- Async_Writers (SPARK RM 7.1.2(16)).
9843 if Property
= Name_Async_Readers
9844 or else Property
= Name_Async_Writers
9848 -- Protected objects that have Part_Of components also inherit their
9849 -- properties Effective_Reads and Effective_Writes
9850 -- (SPARK RM 7.1.2(16)).
9852 elsif Present
(Constits
) then
9853 Constit_Elmt
:= First_Elmt
(Constits
);
9854 while Present
(Constit_Elmt
) loop
9855 Constit_Id
:= Node
(Constit_Elmt
);
9857 if Has_Enabled_Property
(Constit_Id
, Property
) then
9861 Next_Elmt
(Constit_Elmt
);
9866 end Protected_Object_Has_Enabled_Property
;
9868 --------------------------------
9869 -- State_Has_Enabled_Property --
9870 --------------------------------
9872 function State_Has_Enabled_Property
return Boolean is
9873 Decl
: constant Node_Id
:= Parent
(Item_Id
);
9881 -- The declaration of an external abstract state appears as an
9882 -- extension aggregate. If this is not the case, properties can never
9885 if Nkind
(Decl
) /= N_Extension_Aggregate
then
9889 -- When External appears as a simple option, it automatically enables
9892 Opt
:= First
(Expressions
(Decl
));
9893 while Present
(Opt
) loop
9894 if Nkind
(Opt
) = N_Identifier
9895 and then Chars
(Opt
) = Name_External
9903 -- When External specifies particular properties, inspect those and
9904 -- find the desired one (if any).
9906 Opt
:= First
(Component_Associations
(Decl
));
9907 while Present
(Opt
) loop
9908 Opt_Nam
:= First
(Choices
(Opt
));
9910 if Nkind
(Opt_Nam
) = N_Identifier
9911 and then Chars
(Opt_Nam
) = Name_External
9913 Props
:= Expression
(Opt
);
9915 -- Multiple properties appear as an aggregate
9917 if Nkind
(Props
) = N_Aggregate
then
9919 -- Simple property form
9921 Prop
:= First
(Expressions
(Props
));
9922 while Present
(Prop
) loop
9923 if Chars
(Prop
) = Property
then
9930 -- Property with expression form
9932 Prop
:= First
(Component_Associations
(Props
));
9933 while Present
(Prop
) loop
9934 Prop_Nam
:= First
(Choices
(Prop
));
9936 -- The property can be represented in two ways:
9937 -- others => <value>
9938 -- <property> => <value>
9940 if Nkind
(Prop_Nam
) = N_Others_Choice
9941 or else (Nkind
(Prop_Nam
) = N_Identifier
9942 and then Chars
(Prop_Nam
) = Property
)
9944 return Is_True
(Expr_Value
(Expression
(Prop
)));
9953 return Chars
(Props
) = Property
;
9961 end State_Has_Enabled_Property
;
9963 -----------------------------------
9964 -- Variable_Has_Enabled_Property --
9965 -----------------------------------
9967 function Variable_Has_Enabled_Property
return Boolean is
9968 function Is_Enabled
(Prag
: Node_Id
) return Boolean;
9969 -- Determine whether property pragma Prag (if present) denotes an
9970 -- enabled property.
9976 function Is_Enabled
(Prag
: Node_Id
) return Boolean is
9980 if Present
(Prag
) then
9981 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
9983 -- The pragma has an optional Boolean expression, the related
9984 -- property is enabled only when the expression evaluates to
9987 if Present
(Arg1
) then
9988 return Is_True
(Expr_Value
(Get_Pragma_Arg
(Arg1
)));
9990 -- Otherwise the lack of expression enables the property by
9997 -- The property was never set in the first place
10006 AR
: constant Node_Id
:=
10007 Get_Pragma
(Item_Id
, Pragma_Async_Readers
);
10008 AW
: constant Node_Id
:=
10009 Get_Pragma
(Item_Id
, Pragma_Async_Writers
);
10010 ER
: constant Node_Id
:=
10011 Get_Pragma
(Item_Id
, Pragma_Effective_Reads
);
10012 EW
: constant Node_Id
:=
10013 Get_Pragma
(Item_Id
, Pragma_Effective_Writes
);
10015 -- Start of processing for Variable_Has_Enabled_Property
10018 -- A non-effectively volatile object can never possess external
10021 if not Is_Effectively_Volatile
(Item_Id
) then
10024 -- External properties related to variables come in two flavors -
10025 -- explicit and implicit. The explicit case is characterized by the
10026 -- presence of a property pragma with an optional Boolean flag. The
10027 -- property is enabled when the flag evaluates to True or the flag is
10028 -- missing altogether.
10030 elsif Property
= Name_Async_Readers
and then Is_Enabled
(AR
) then
10033 elsif Property
= Name_Async_Writers
and then Is_Enabled
(AW
) then
10036 elsif Property
= Name_Effective_Reads
and then Is_Enabled
(ER
) then
10039 elsif Property
= Name_Effective_Writes
and then Is_Enabled
(EW
) then
10042 -- The implicit case lacks all property pragmas
10044 elsif No
(AR
) and then No
(AW
) and then No
(ER
) and then No
(EW
) then
10045 if Is_Protected_Type
(Etype
(Item_Id
)) then
10046 return Protected_Object_Has_Enabled_Property
;
10054 end Variable_Has_Enabled_Property
;
10056 -- Start of processing for Has_Enabled_Property
10059 -- Abstract states and variables have a flexible scheme of specifying
10060 -- external properties.
10062 if Ekind
(Item_Id
) = E_Abstract_State
then
10063 return State_Has_Enabled_Property
;
10065 elsif Ekind
(Item_Id
) = E_Variable
then
10066 return Variable_Has_Enabled_Property
;
10068 -- By default, protected objects only have the properties Async_Readers
10069 -- and Async_Writers. If they have Part_Of components, they also inherit
10070 -- their properties Effective_Reads and Effective_Writes
10071 -- (SPARK RM 7.1.2(16)).
10073 elsif Ekind
(Item_Id
) = E_Protected_Object
then
10074 return Protected_Object_Has_Enabled_Property
;
10076 -- Otherwise a property is enabled when the related item is effectively
10080 return Is_Effectively_Volatile
(Item_Id
);
10082 end Has_Enabled_Property
;
10084 -------------------------------------
10085 -- Has_Full_Default_Initialization --
10086 -------------------------------------
10088 function Has_Full_Default_Initialization
(Typ
: Entity_Id
) return Boolean is
10093 -- A type subject to pragma Default_Initial_Condition is fully default
10094 -- initialized when the pragma appears with a non-null argument. Since
10095 -- any type may act as the full view of a private type, this check must
10096 -- be performed prior to the specialized tests below.
10098 if Has_DIC
(Typ
) then
10099 Prag
:= Get_Pragma
(Typ
, Pragma_Default_Initial_Condition
);
10100 pragma Assert
(Present
(Prag
));
10102 return Is_Verifiable_DIC_Pragma
(Prag
);
10105 -- A scalar type is fully default initialized if it is subject to aspect
10108 if Is_Scalar_Type
(Typ
) then
10109 return Has_Default_Aspect
(Typ
);
10111 -- An array type is fully default initialized if its element type is
10112 -- scalar and the array type carries aspect Default_Component_Value or
10113 -- the element type is fully default initialized.
10115 elsif Is_Array_Type
(Typ
) then
10117 Has_Default_Aspect
(Typ
)
10118 or else Has_Full_Default_Initialization
(Component_Type
(Typ
));
10120 -- A protected type, record type, or type extension is fully default
10121 -- initialized if all its components either carry an initialization
10122 -- expression or have a type that is fully default initialized. The
10123 -- parent type of a type extension must be fully default initialized.
10125 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
10127 -- Inspect all entities defined in the scope of the type, looking for
10128 -- uninitialized components.
10130 Comp
:= First_Entity
(Typ
);
10131 while Present
(Comp
) loop
10132 if Ekind
(Comp
) = E_Component
10133 and then Comes_From_Source
(Comp
)
10134 and then No
(Expression
(Parent
(Comp
)))
10135 and then not Has_Full_Default_Initialization
(Etype
(Comp
))
10140 Next_Entity
(Comp
);
10143 -- Ensure that the parent type of a type extension is fully default
10146 if Etype
(Typ
) /= Typ
10147 and then not Has_Full_Default_Initialization
(Etype
(Typ
))
10152 -- If we get here, then all components and parent portion are fully
10153 -- default initialized.
10157 -- A task type is fully default initialized by default
10159 elsif Is_Task_Type
(Typ
) then
10162 -- Otherwise the type is not fully default initialized
10167 end Has_Full_Default_Initialization
;
10169 --------------------
10170 -- Has_Infinities --
10171 --------------------
10173 function Has_Infinities
(E
: Entity_Id
) return Boolean is
10176 Is_Floating_Point_Type
(E
)
10177 and then Nkind
(Scalar_Range
(E
)) = N_Range
10178 and then Includes_Infinities
(Scalar_Range
(E
));
10179 end Has_Infinities
;
10181 --------------------
10182 -- Has_Interfaces --
10183 --------------------
10185 function Has_Interfaces
10187 Use_Full_View
: Boolean := True) return Boolean
10189 Typ
: Entity_Id
:= Base_Type
(T
);
10192 -- Handle concurrent types
10194 if Is_Concurrent_Type
(Typ
) then
10195 Typ
:= Corresponding_Record_Type
(Typ
);
10198 if not Present
(Typ
)
10199 or else not Is_Record_Type
(Typ
)
10200 or else not Is_Tagged_Type
(Typ
)
10205 -- Handle private types
10207 if Use_Full_View
and then Present
(Full_View
(Typ
)) then
10208 Typ
:= Full_View
(Typ
);
10211 -- Handle concurrent record types
10213 if Is_Concurrent_Record_Type
(Typ
)
10214 and then Is_Non_Empty_List
(Abstract_Interface_List
(Typ
))
10220 if Is_Interface
(Typ
)
10222 (Is_Record_Type
(Typ
)
10223 and then Present
(Interfaces
(Typ
))
10224 and then not Is_Empty_Elmt_List
(Interfaces
(Typ
)))
10229 exit when Etype
(Typ
) = Typ
10231 -- Handle private types
10233 or else (Present
(Full_View
(Etype
(Typ
)))
10234 and then Full_View
(Etype
(Typ
)) = Typ
)
10236 -- Protect frontend against wrong sources with cyclic derivations
10238 or else Etype
(Typ
) = T
;
10240 -- Climb to the ancestor type handling private types
10242 if Present
(Full_View
(Etype
(Typ
))) then
10243 Typ
:= Full_View
(Etype
(Typ
));
10245 Typ
:= Etype
(Typ
);
10250 end Has_Interfaces
;
10252 --------------------------
10253 -- Has_Max_Queue_Length --
10254 --------------------------
10256 function Has_Max_Queue_Length
(Id
: Entity_Id
) return Boolean is
10259 Ekind
(Id
) = E_Entry
10260 and then Present
(Get_Pragma
(Id
, Pragma_Max_Queue_Length
));
10261 end Has_Max_Queue_Length
;
10263 ---------------------------------
10264 -- Has_No_Obvious_Side_Effects --
10265 ---------------------------------
10267 function Has_No_Obvious_Side_Effects
(N
: Node_Id
) return Boolean is
10269 -- For now handle literals, constants, and non-volatile variables and
10270 -- expressions combining these with operators or short circuit forms.
10272 if Nkind
(N
) in N_Numeric_Or_String_Literal
then
10275 elsif Nkind
(N
) = N_Character_Literal
then
10278 elsif Nkind
(N
) in N_Unary_Op
then
10279 return Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
10281 elsif Nkind
(N
) in N_Binary_Op
or else Nkind
(N
) in N_Short_Circuit
then
10282 return Has_No_Obvious_Side_Effects
(Left_Opnd
(N
))
10284 Has_No_Obvious_Side_Effects
(Right_Opnd
(N
));
10286 elsif Nkind
(N
) = N_Expression_With_Actions
10287 and then Is_Empty_List
(Actions
(N
))
10289 return Has_No_Obvious_Side_Effects
(Expression
(N
));
10291 elsif Nkind
(N
) in N_Has_Entity
then
10292 return Present
(Entity
(N
))
10293 and then Ekind_In
(Entity
(N
), E_Variable
,
10295 E_Enumeration_Literal
,
10298 E_In_Out_Parameter
)
10299 and then not Is_Volatile
(Entity
(N
));
10304 end Has_No_Obvious_Side_Effects
;
10306 -----------------------------
10307 -- Has_Non_Null_Refinement --
10308 -----------------------------
10310 function Has_Non_Null_Refinement
(Id
: Entity_Id
) return Boolean is
10311 Constits
: Elist_Id
;
10314 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
10315 Constits
:= Refinement_Constituents
(Id
);
10317 -- For a refinement to be non-null, the first constituent must be
10318 -- anything other than null.
10322 and then Nkind
(Node
(First_Elmt
(Constits
))) /= N_Null
;
10323 end Has_Non_Null_Refinement
;
10325 ----------------------------------
10326 -- Has_Non_Trivial_Precondition --
10327 ----------------------------------
10329 function Has_Non_Trivial_Precondition
(P
: Entity_Id
) return Boolean is
10330 Cont
: constant Node_Id
:= Find_Aspect
(P
, Aspect_Pre
);
10332 return Present
(Cont
)
10333 and then Class_Present
(Cont
)
10334 and then not Is_Entity_Name
(Expression
(Cont
));
10335 end Has_Non_Trivial_Precondition
;
10337 -------------------
10338 -- Has_Null_Body --
10339 -------------------
10341 function Has_Null_Body
(Proc_Id
: Entity_Id
) return Boolean is
10342 Body_Id
: Entity_Id
;
10349 Spec
:= Parent
(Proc_Id
);
10350 Decl
:= Parent
(Spec
);
10352 -- Retrieve the entity of the procedure body (e.g. invariant proc).
10354 if Nkind
(Spec
) = N_Procedure_Specification
10355 and then Nkind
(Decl
) = N_Subprogram_Declaration
10357 Body_Id
:= Corresponding_Body
(Decl
);
10359 -- The body acts as a spec
10362 Body_Id
:= Proc_Id
;
10365 -- The body will be generated later
10367 if No
(Body_Id
) then
10371 Spec
:= Parent
(Body_Id
);
10372 Decl
:= Parent
(Spec
);
10375 (Nkind
(Spec
) = N_Procedure_Specification
10376 and then Nkind
(Decl
) = N_Subprogram_Body
);
10378 Stmt1
:= First
(Statements
(Handled_Statement_Sequence
(Decl
)));
10380 -- Look for a null statement followed by an optional return
10383 if Nkind
(Stmt1
) = N_Null_Statement
then
10384 Stmt2
:= Next
(Stmt1
);
10386 if Present
(Stmt2
) then
10387 return Nkind
(Stmt2
) = N_Simple_Return_Statement
;
10396 ------------------------
10397 -- Has_Null_Exclusion --
10398 ------------------------
10400 function Has_Null_Exclusion
(N
: Node_Id
) return Boolean is
10403 when N_Access_Definition
10404 | N_Access_Function_Definition
10405 | N_Access_Procedure_Definition
10406 | N_Access_To_Object_Definition
10408 | N_Derived_Type_Definition
10409 | N_Function_Specification
10410 | N_Subtype_Declaration
10412 return Null_Exclusion_Present
(N
);
10414 when N_Component_Definition
10415 | N_Formal_Object_Declaration
10416 | N_Object_Renaming_Declaration
10418 if Present
(Subtype_Mark
(N
)) then
10419 return Null_Exclusion_Present
(N
);
10420 else pragma Assert
(Present
(Access_Definition
(N
)));
10421 return Null_Exclusion_Present
(Access_Definition
(N
));
10424 when N_Discriminant_Specification
=>
10425 if Nkind
(Discriminant_Type
(N
)) = N_Access_Definition
then
10426 return Null_Exclusion_Present
(Discriminant_Type
(N
));
10428 return Null_Exclusion_Present
(N
);
10431 when N_Object_Declaration
=>
10432 if Nkind
(Object_Definition
(N
)) = N_Access_Definition
then
10433 return Null_Exclusion_Present
(Object_Definition
(N
));
10435 return Null_Exclusion_Present
(N
);
10438 when N_Parameter_Specification
=>
10439 if Nkind
(Parameter_Type
(N
)) = N_Access_Definition
then
10440 return Null_Exclusion_Present
(Parameter_Type
(N
));
10442 return Null_Exclusion_Present
(N
);
10448 end Has_Null_Exclusion
;
10450 ------------------------
10451 -- Has_Null_Extension --
10452 ------------------------
10454 function Has_Null_Extension
(T
: Entity_Id
) return Boolean is
10455 B
: constant Entity_Id
:= Base_Type
(T
);
10460 if Nkind
(Parent
(B
)) = N_Full_Type_Declaration
10461 and then Present
(Record_Extension_Part
(Type_Definition
(Parent
(B
))))
10463 Ext
:= Record_Extension_Part
(Type_Definition
(Parent
(B
)));
10465 if Present
(Ext
) then
10466 if Null_Present
(Ext
) then
10469 Comps
:= Component_List
(Ext
);
10471 -- The null component list is rewritten during analysis to
10472 -- include the parent component. Any other component indicates
10473 -- that the extension was not originally null.
10475 return Null_Present
(Comps
)
10476 or else No
(Next
(First
(Component_Items
(Comps
))));
10485 end Has_Null_Extension
;
10487 -------------------------
10488 -- Has_Null_Refinement --
10489 -------------------------
10491 function Has_Null_Refinement
(Id
: Entity_Id
) return Boolean is
10492 Constits
: Elist_Id
;
10495 pragma Assert
(Ekind
(Id
) = E_Abstract_State
);
10496 Constits
:= Refinement_Constituents
(Id
);
10498 -- For a refinement to be null, the state's sole constituent must be a
10503 and then Nkind
(Node
(First_Elmt
(Constits
))) = N_Null
;
10504 end Has_Null_Refinement
;
10506 -------------------------------
10507 -- Has_Overriding_Initialize --
10508 -------------------------------
10510 function Has_Overriding_Initialize
(T
: Entity_Id
) return Boolean is
10511 BT
: constant Entity_Id
:= Base_Type
(T
);
10515 if Is_Controlled
(BT
) then
10516 if Is_RTU
(Scope
(BT
), Ada_Finalization
) then
10519 elsif Present
(Primitive_Operations
(BT
)) then
10520 P
:= First_Elmt
(Primitive_Operations
(BT
));
10521 while Present
(P
) loop
10523 Init
: constant Entity_Id
:= Node
(P
);
10524 Formal
: constant Entity_Id
:= First_Formal
(Init
);
10526 if Ekind
(Init
) = E_Procedure
10527 and then Chars
(Init
) = Name_Initialize
10528 and then Comes_From_Source
(Init
)
10529 and then Present
(Formal
)
10530 and then Etype
(Formal
) = BT
10531 and then No
(Next_Formal
(Formal
))
10532 and then (Ada_Version
< Ada_2012
10533 or else not Null_Present
(Parent
(Init
)))
10543 -- Here if type itself does not have a non-null Initialize operation:
10544 -- check immediate ancestor.
10546 if Is_Derived_Type
(BT
)
10547 and then Has_Overriding_Initialize
(Etype
(BT
))
10554 end Has_Overriding_Initialize
;
10556 --------------------------------------
10557 -- Has_Preelaborable_Initialization --
10558 --------------------------------------
10560 function Has_Preelaborable_Initialization
(E
: Entity_Id
) return Boolean is
10563 procedure Check_Components
(E
: Entity_Id
);
10564 -- Check component/discriminant chain, sets Has_PE False if a component
10565 -- or discriminant does not meet the preelaborable initialization rules.
10567 ----------------------
10568 -- Check_Components --
10569 ----------------------
10571 procedure Check_Components
(E
: Entity_Id
) is
10575 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean;
10576 -- Returns True if and only if the expression denoted by N does not
10577 -- violate restrictions on preelaborable constructs (RM-10.2.1(5-9)).
10579 ---------------------------------
10580 -- Is_Preelaborable_Expression --
10581 ---------------------------------
10583 function Is_Preelaborable_Expression
(N
: Node_Id
) return Boolean is
10587 Comp_Type
: Entity_Id
;
10588 Is_Array_Aggr
: Boolean;
10591 if Is_OK_Static_Expression
(N
) then
10594 elsif Nkind
(N
) = N_Null
then
10597 -- Attributes are allowed in general, even if their prefix is a
10598 -- formal type. (It seems that certain attributes known not to be
10599 -- static might not be allowed, but there are no rules to prevent
10602 elsif Nkind
(N
) = N_Attribute_Reference
then
10605 -- The name of a discriminant evaluated within its parent type is
10606 -- defined to be preelaborable (10.2.1(8)). Note that we test for
10607 -- names that denote discriminals as well as discriminants to
10608 -- catch references occurring within init procs.
10610 elsif Is_Entity_Name
(N
)
10612 (Ekind
(Entity
(N
)) = E_Discriminant
10613 or else (Ekind_In
(Entity
(N
), E_Constant
, E_In_Parameter
)
10614 and then Present
(Discriminal_Link
(Entity
(N
)))))
10618 elsif Nkind
(N
) = N_Qualified_Expression
then
10619 return Is_Preelaborable_Expression
(Expression
(N
));
10621 -- For aggregates we have to check that each of the associations
10622 -- is preelaborable.
10624 elsif Nkind_In
(N
, N_Aggregate
, N_Extension_Aggregate
) then
10625 Is_Array_Aggr
:= Is_Array_Type
(Etype
(N
));
10627 if Is_Array_Aggr
then
10628 Comp_Type
:= Component_Type
(Etype
(N
));
10631 -- Check the ancestor part of extension aggregates, which must
10632 -- be either the name of a type that has preelaborable init or
10633 -- an expression that is preelaborable.
10635 if Nkind
(N
) = N_Extension_Aggregate
then
10637 Anc_Part
: constant Node_Id
:= Ancestor_Part
(N
);
10640 if Is_Entity_Name
(Anc_Part
)
10641 and then Is_Type
(Entity
(Anc_Part
))
10643 if not Has_Preelaborable_Initialization
10644 (Entity
(Anc_Part
))
10649 elsif not Is_Preelaborable_Expression
(Anc_Part
) then
10655 -- Check positional associations
10657 Exp
:= First
(Expressions
(N
));
10658 while Present
(Exp
) loop
10659 if not Is_Preelaborable_Expression
(Exp
) then
10666 -- Check named associations
10668 Assn
:= First
(Component_Associations
(N
));
10669 while Present
(Assn
) loop
10670 Choice
:= First
(Choices
(Assn
));
10671 while Present
(Choice
) loop
10672 if Is_Array_Aggr
then
10673 if Nkind
(Choice
) = N_Others_Choice
then
10676 elsif Nkind
(Choice
) = N_Range
then
10677 if not Is_OK_Static_Range
(Choice
) then
10681 elsif not Is_OK_Static_Expression
(Choice
) then
10686 Comp_Type
:= Etype
(Choice
);
10692 -- If the association has a <> at this point, then we have
10693 -- to check whether the component's type has preelaborable
10694 -- initialization. Note that this only occurs when the
10695 -- association's corresponding component does not have a
10696 -- default expression, the latter case having already been
10697 -- expanded as an expression for the association.
10699 if Box_Present
(Assn
) then
10700 if not Has_Preelaborable_Initialization
(Comp_Type
) then
10704 -- In the expression case we check whether the expression
10705 -- is preelaborable.
10708 not Is_Preelaborable_Expression
(Expression
(Assn
))
10716 -- If we get here then aggregate as a whole is preelaborable
10720 -- All other cases are not preelaborable
10725 end Is_Preelaborable_Expression
;
10727 -- Start of processing for Check_Components
10730 -- Loop through entities of record or protected type
10733 while Present
(Ent
) loop
10735 -- We are interested only in components and discriminants
10739 case Ekind
(Ent
) is
10740 when E_Component
=>
10742 -- Get default expression if any. If there is no declaration
10743 -- node, it means we have an internal entity. The parent and
10744 -- tag fields are examples of such entities. For such cases,
10745 -- we just test the type of the entity.
10747 if Present
(Declaration_Node
(Ent
)) then
10748 Exp
:= Expression
(Declaration_Node
(Ent
));
10751 when E_Discriminant
=>
10753 -- Note: for a renamed discriminant, the Declaration_Node
10754 -- may point to the one from the ancestor, and have a
10755 -- different expression, so use the proper attribute to
10756 -- retrieve the expression from the derived constraint.
10758 Exp
:= Discriminant_Default_Value
(Ent
);
10761 goto Check_Next_Entity
;
10764 -- A component has PI if it has no default expression and the
10765 -- component type has PI.
10768 if not Has_Preelaborable_Initialization
(Etype
(Ent
)) then
10773 -- Require the default expression to be preelaborable
10775 elsif not Is_Preelaborable_Expression
(Exp
) then
10780 <<Check_Next_Entity
>>
10783 end Check_Components
;
10785 -- Start of processing for Has_Preelaborable_Initialization
10788 -- Immediate return if already marked as known preelaborable init. This
10789 -- covers types for which this function has already been called once
10790 -- and returned True (in which case the result is cached), and also
10791 -- types to which a pragma Preelaborable_Initialization applies.
10793 if Known_To_Have_Preelab_Init
(E
) then
10797 -- If the type is a subtype representing a generic actual type, then
10798 -- test whether its base type has preelaborable initialization since
10799 -- the subtype representing the actual does not inherit this attribute
10800 -- from the actual or formal. (but maybe it should???)
10802 if Is_Generic_Actual_Type
(E
) then
10803 return Has_Preelaborable_Initialization
(Base_Type
(E
));
10806 -- All elementary types have preelaborable initialization
10808 if Is_Elementary_Type
(E
) then
10811 -- Array types have PI if the component type has PI
10813 elsif Is_Array_Type
(E
) then
10814 Has_PE
:= Has_Preelaborable_Initialization
(Component_Type
(E
));
10816 -- A derived type has preelaborable initialization if its parent type
10817 -- has preelaborable initialization and (in the case of a derived record
10818 -- extension) if the non-inherited components all have preelaborable
10819 -- initialization. However, a user-defined controlled type with an
10820 -- overriding Initialize procedure does not have preelaborable
10823 elsif Is_Derived_Type
(E
) then
10825 -- If the derived type is a private extension then it doesn't have
10826 -- preelaborable initialization.
10828 if Ekind
(Base_Type
(E
)) = E_Record_Type_With_Private
then
10832 -- First check whether ancestor type has preelaborable initialization
10834 Has_PE
:= Has_Preelaborable_Initialization
(Etype
(Base_Type
(E
)));
10836 -- If OK, check extension components (if any)
10838 if Has_PE
and then Is_Record_Type
(E
) then
10839 Check_Components
(First_Entity
(E
));
10842 -- Check specifically for 10.2.1(11.4/2) exception: a controlled type
10843 -- with a user defined Initialize procedure does not have PI. If
10844 -- the type is untagged, the control primitives come from a component
10845 -- that has already been checked.
10848 and then Is_Controlled
(E
)
10849 and then Is_Tagged_Type
(E
)
10850 and then Has_Overriding_Initialize
(E
)
10855 -- Private types not derived from a type having preelaborable init and
10856 -- that are not marked with pragma Preelaborable_Initialization do not
10857 -- have preelaborable initialization.
10859 elsif Is_Private_Type
(E
) then
10862 -- Record type has PI if it is non private and all components have PI
10864 elsif Is_Record_Type
(E
) then
10866 Check_Components
(First_Entity
(E
));
10868 -- Protected types must not have entries, and components must meet
10869 -- same set of rules as for record components.
10871 elsif Is_Protected_Type
(E
) then
10872 if Has_Entries
(E
) then
10876 Check_Components
(First_Entity
(E
));
10877 Check_Components
(First_Private_Entity
(E
));
10880 -- Type System.Address always has preelaborable initialization
10882 elsif Is_RTE
(E
, RE_Address
) then
10885 -- In all other cases, type does not have preelaborable initialization
10891 -- If type has preelaborable initialization, cache result
10894 Set_Known_To_Have_Preelab_Init
(E
);
10898 end Has_Preelaborable_Initialization
;
10900 ---------------------------
10901 -- Has_Private_Component --
10902 ---------------------------
10904 function Has_Private_Component
(Type_Id
: Entity_Id
) return Boolean is
10905 Btype
: Entity_Id
:= Base_Type
(Type_Id
);
10906 Component
: Entity_Id
;
10909 if Error_Posted
(Type_Id
)
10910 or else Error_Posted
(Btype
)
10915 if Is_Class_Wide_Type
(Btype
) then
10916 Btype
:= Root_Type
(Btype
);
10919 if Is_Private_Type
(Btype
) then
10921 UT
: constant Entity_Id
:= Underlying_Type
(Btype
);
10924 if No
(Full_View
(Btype
)) then
10925 return not Is_Generic_Type
(Btype
)
10927 not Is_Generic_Type
(Root_Type
(Btype
));
10929 return not Is_Generic_Type
(Root_Type
(Full_View
(Btype
)));
10932 return not Is_Frozen
(UT
) and then Has_Private_Component
(UT
);
10936 elsif Is_Array_Type
(Btype
) then
10937 return Has_Private_Component
(Component_Type
(Btype
));
10939 elsif Is_Record_Type
(Btype
) then
10940 Component
:= First_Component
(Btype
);
10941 while Present
(Component
) loop
10942 if Has_Private_Component
(Etype
(Component
)) then
10946 Next_Component
(Component
);
10951 elsif Is_Protected_Type
(Btype
)
10952 and then Present
(Corresponding_Record_Type
(Btype
))
10954 return Has_Private_Component
(Corresponding_Record_Type
(Btype
));
10959 end Has_Private_Component
;
10961 ----------------------
10962 -- Has_Signed_Zeros --
10963 ----------------------
10965 function Has_Signed_Zeros
(E
: Entity_Id
) return Boolean is
10967 return Is_Floating_Point_Type
(E
) and then Signed_Zeros_On_Target
;
10968 end Has_Signed_Zeros
;
10970 ------------------------------
10971 -- Has_Significant_Contract --
10972 ------------------------------
10974 function Has_Significant_Contract
(Subp_Id
: Entity_Id
) return Boolean is
10975 Subp_Nam
: constant Name_Id
:= Chars
(Subp_Id
);
10978 -- _Finalizer procedure
10980 if Subp_Nam
= Name_uFinalizer
then
10983 -- _Postconditions procedure
10985 elsif Subp_Nam
= Name_uPostconditions
then
10988 -- Predicate function
10990 elsif Ekind
(Subp_Id
) = E_Function
10991 and then Is_Predicate_Function
(Subp_Id
)
10997 elsif Get_TSS_Name
(Subp_Id
) /= TSS_Null
then
11003 end Has_Significant_Contract
;
11005 -----------------------------
11006 -- Has_Static_Array_Bounds --
11007 -----------------------------
11009 function Has_Static_Array_Bounds
(Typ
: Node_Id
) return Boolean is
11010 Ndims
: constant Nat
:= Number_Dimensions
(Typ
);
11017 -- Unconstrained types do not have static bounds
11019 if not Is_Constrained
(Typ
) then
11023 -- First treat string literals specially, as the lower bound and length
11024 -- of string literals are not stored like those of arrays.
11026 -- A string literal always has static bounds
11028 if Ekind
(Typ
) = E_String_Literal_Subtype
then
11032 -- Treat all dimensions in turn
11034 Index
:= First_Index
(Typ
);
11035 for Indx
in 1 .. Ndims
loop
11037 -- In case of an illegal index which is not a discrete type, return
11038 -- that the type is not static.
11040 if not Is_Discrete_Type
(Etype
(Index
))
11041 or else Etype
(Index
) = Any_Type
11046 Get_Index_Bounds
(Index
, Low
, High
);
11048 if Error_Posted
(Low
) or else Error_Posted
(High
) then
11052 if Is_OK_Static_Expression
(Low
)
11054 Is_OK_Static_Expression
(High
)
11064 -- If we fall through the loop, all indexes matched
11067 end Has_Static_Array_Bounds
;
11073 function Has_Stream
(T
: Entity_Id
) return Boolean is
11080 elsif Is_RTE
(Root_Type
(T
), RE_Root_Stream_Type
) then
11083 elsif Is_Array_Type
(T
) then
11084 return Has_Stream
(Component_Type
(T
));
11086 elsif Is_Record_Type
(T
) then
11087 E
:= First_Component
(T
);
11088 while Present
(E
) loop
11089 if Has_Stream
(Etype
(E
)) then
11092 Next_Component
(E
);
11098 elsif Is_Private_Type
(T
) then
11099 return Has_Stream
(Underlying_Type
(T
));
11110 function Has_Suffix
(E
: Entity_Id
; Suffix
: Character) return Boolean is
11112 Get_Name_String
(Chars
(E
));
11113 return Name_Buffer
(Name_Len
) = Suffix
;
11120 function Add_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
11122 Get_Name_String
(Chars
(E
));
11123 Add_Char_To_Name_Buffer
(Suffix
);
11127 -------------------
11128 -- Remove_Suffix --
11129 -------------------
11131 function Remove_Suffix
(E
: Entity_Id
; Suffix
: Character) return Name_Id
is
11133 pragma Assert
(Has_Suffix
(E
, Suffix
));
11134 Get_Name_String
(Chars
(E
));
11135 Name_Len
:= Name_Len
- 1;
11139 ----------------------------------
11140 -- Replace_Null_By_Null_Address --
11141 ----------------------------------
11143 procedure Replace_Null_By_Null_Address
(N
: Node_Id
) is
11144 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
);
11145 -- Replace operand Op with a reference to Null_Address when the operand
11146 -- denotes a null Address. Other_Op denotes the other operand.
11148 --------------------------
11149 -- Replace_Null_Operand --
11150 --------------------------
11152 procedure Replace_Null_Operand
(Op
: Node_Id
; Other_Op
: Node_Id
) is
11154 -- Check the type of the complementary operand since the N_Null node
11155 -- has not been decorated yet.
11157 if Nkind
(Op
) = N_Null
11158 and then Is_Descendant_Of_Address
(Etype
(Other_Op
))
11160 Rewrite
(Op
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(Op
)));
11162 end Replace_Null_Operand
;
11164 -- Start of processing for Replace_Null_By_Null_Address
11167 pragma Assert
(Relaxed_RM_Semantics
);
11168 pragma Assert
(Nkind_In
(N
, N_Null
,
11176 if Nkind
(N
) = N_Null
then
11177 Rewrite
(N
, New_Occurrence_Of
(RTE
(RE_Null_Address
), Sloc
(N
)));
11181 L
: constant Node_Id
:= Left_Opnd
(N
);
11182 R
: constant Node_Id
:= Right_Opnd
(N
);
11185 Replace_Null_Operand
(L
, Other_Op
=> R
);
11186 Replace_Null_Operand
(R
, Other_Op
=> L
);
11189 end Replace_Null_By_Null_Address
;
11191 --------------------------
11192 -- Has_Tagged_Component --
11193 --------------------------
11195 function Has_Tagged_Component
(Typ
: Entity_Id
) return Boolean is
11199 if Is_Private_Type
(Typ
) and then Present
(Underlying_Type
(Typ
)) then
11200 return Has_Tagged_Component
(Underlying_Type
(Typ
));
11202 elsif Is_Array_Type
(Typ
) then
11203 return Has_Tagged_Component
(Component_Type
(Typ
));
11205 elsif Is_Tagged_Type
(Typ
) then
11208 elsif Is_Record_Type
(Typ
) then
11209 Comp
:= First_Component
(Typ
);
11210 while Present
(Comp
) loop
11211 if Has_Tagged_Component
(Etype
(Comp
)) then
11215 Next_Component
(Comp
);
11223 end Has_Tagged_Component
;
11225 -----------------------------
11226 -- Has_Undefined_Reference --
11227 -----------------------------
11229 function Has_Undefined_Reference
(Expr
: Node_Id
) return Boolean is
11230 Has_Undef_Ref
: Boolean := False;
11231 -- Flag set when expression Expr contains at least one undefined
11234 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
;
11235 -- Determine whether N denotes a reference and if it does, whether it is
11238 ----------------------------
11239 -- Is_Undefined_Reference --
11240 ----------------------------
11242 function Is_Undefined_Reference
(N
: Node_Id
) return Traverse_Result
is
11244 if Is_Entity_Name
(N
)
11245 and then Present
(Entity
(N
))
11246 and then Entity
(N
) = Any_Id
11248 Has_Undef_Ref
:= True;
11253 end Is_Undefined_Reference
;
11255 procedure Find_Undefined_References
is
11256 new Traverse_Proc
(Is_Undefined_Reference
);
11258 -- Start of processing for Has_Undefined_Reference
11261 Find_Undefined_References
(Expr
);
11263 return Has_Undef_Ref
;
11264 end Has_Undefined_Reference
;
11266 ----------------------------
11267 -- Has_Volatile_Component --
11268 ----------------------------
11270 function Has_Volatile_Component
(Typ
: Entity_Id
) return Boolean is
11274 if Has_Volatile_Components
(Typ
) then
11277 elsif Is_Array_Type
(Typ
) then
11278 return Is_Volatile
(Component_Type
(Typ
));
11280 elsif Is_Record_Type
(Typ
) then
11281 Comp
:= First_Component
(Typ
);
11282 while Present
(Comp
) loop
11283 if Is_Volatile_Object
(Comp
) then
11287 Comp
:= Next_Component
(Comp
);
11292 end Has_Volatile_Component
;
11294 -------------------------
11295 -- Implementation_Kind --
11296 -------------------------
11298 function Implementation_Kind
(Subp
: Entity_Id
) return Name_Id
is
11299 Impl_Prag
: constant Node_Id
:= Get_Rep_Pragma
(Subp
, Name_Implemented
);
11302 pragma Assert
(Present
(Impl_Prag
));
11303 Arg
:= Last
(Pragma_Argument_Associations
(Impl_Prag
));
11304 return Chars
(Get_Pragma_Arg
(Arg
));
11305 end Implementation_Kind
;
11307 --------------------------
11308 -- Implements_Interface --
11309 --------------------------
11311 function Implements_Interface
11312 (Typ_Ent
: Entity_Id
;
11313 Iface_Ent
: Entity_Id
;
11314 Exclude_Parents
: Boolean := False) return Boolean
11316 Ifaces_List
: Elist_Id
;
11318 Iface
: Entity_Id
:= Base_Type
(Iface_Ent
);
11319 Typ
: Entity_Id
:= Base_Type
(Typ_Ent
);
11322 if Is_Class_Wide_Type
(Typ
) then
11323 Typ
:= Root_Type
(Typ
);
11326 if not Has_Interfaces
(Typ
) then
11330 if Is_Class_Wide_Type
(Iface
) then
11331 Iface
:= Root_Type
(Iface
);
11334 Collect_Interfaces
(Typ
, Ifaces_List
);
11336 Elmt
:= First_Elmt
(Ifaces_List
);
11337 while Present
(Elmt
) loop
11338 if Is_Ancestor
(Node
(Elmt
), Typ
, Use_Full_View
=> True)
11339 and then Exclude_Parents
11343 elsif Node
(Elmt
) = Iface
then
11351 end Implements_Interface
;
11353 ------------------------------------
11354 -- In_Assertion_Expression_Pragma --
11355 ------------------------------------
11357 function In_Assertion_Expression_Pragma
(N
: Node_Id
) return Boolean is
11359 Prag
: Node_Id
:= Empty
;
11362 -- Climb the parent chain looking for an enclosing pragma
11365 while Present
(Par
) loop
11366 if Nkind
(Par
) = N_Pragma
then
11370 -- Precondition-like pragmas are expanded into if statements, check
11371 -- the original node instead.
11373 elsif Nkind
(Original_Node
(Par
)) = N_Pragma
then
11374 Prag
:= Original_Node
(Par
);
11377 -- The expansion of attribute 'Old generates a constant to capture
11378 -- the result of the prefix. If the parent traversal reaches
11379 -- one of these constants, then the node technically came from a
11380 -- postcondition-like pragma. Note that the Ekind is not tested here
11381 -- because N may be the expression of an object declaration which is
11382 -- currently being analyzed. Such objects carry Ekind of E_Void.
11384 elsif Nkind
(Par
) = N_Object_Declaration
11385 and then Constant_Present
(Par
)
11386 and then Stores_Attribute_Old_Prefix
(Defining_Entity
(Par
))
11390 -- Prevent the search from going too far
11392 elsif Is_Body_Or_Package_Declaration
(Par
) then
11396 Par
:= Parent
(Par
);
11401 and then Assertion_Expression_Pragma
(Get_Pragma_Id
(Prag
));
11402 end In_Assertion_Expression_Pragma
;
11404 ----------------------
11405 -- In_Generic_Scope --
11406 ----------------------
11408 function In_Generic_Scope
(E
: Entity_Id
) return Boolean is
11413 while Present
(S
) and then S
/= Standard_Standard
loop
11414 if Is_Generic_Unit
(S
) then
11422 end In_Generic_Scope
;
11428 function In_Instance
return Boolean is
11429 Curr_Unit
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
11433 S
:= Current_Scope
;
11434 while Present
(S
) and then S
/= Standard_Standard
loop
11435 if Is_Generic_Instance
(S
) then
11437 -- A child instance is always compiled in the context of a parent
11438 -- instance. Nevertheless, the actuals are not analyzed in an
11439 -- instance context. We detect this case by examining the current
11440 -- compilation unit, which must be a child instance, and checking
11441 -- that it is not currently on the scope stack.
11443 if Is_Child_Unit
(Curr_Unit
)
11444 and then Nkind
(Unit
(Cunit
(Current_Sem_Unit
))) =
11445 N_Package_Instantiation
11446 and then not In_Open_Scopes
(Curr_Unit
)
11460 ----------------------
11461 -- In_Instance_Body --
11462 ----------------------
11464 function In_Instance_Body
return Boolean is
11468 S
:= Current_Scope
;
11469 while Present
(S
) and then S
/= Standard_Standard
loop
11470 if Ekind_In
(S
, E_Function
, E_Procedure
)
11471 and then Is_Generic_Instance
(S
)
11475 elsif Ekind
(S
) = E_Package
11476 and then In_Package_Body
(S
)
11477 and then Is_Generic_Instance
(S
)
11486 end In_Instance_Body
;
11488 -----------------------------
11489 -- In_Instance_Not_Visible --
11490 -----------------------------
11492 function In_Instance_Not_Visible
return Boolean is
11496 S
:= Current_Scope
;
11497 while Present
(S
) and then S
/= Standard_Standard
loop
11498 if Ekind_In
(S
, E_Function
, E_Procedure
)
11499 and then Is_Generic_Instance
(S
)
11503 elsif Ekind
(S
) = E_Package
11504 and then (In_Package_Body
(S
) or else In_Private_Part
(S
))
11505 and then Is_Generic_Instance
(S
)
11514 end In_Instance_Not_Visible
;
11516 ------------------------------
11517 -- In_Instance_Visible_Part --
11518 ------------------------------
11520 function In_Instance_Visible_Part
return Boolean is
11524 S
:= Current_Scope
;
11525 while Present
(S
) and then S
/= Standard_Standard
loop
11526 if Ekind
(S
) = E_Package
11527 and then Is_Generic_Instance
(S
)
11528 and then not In_Package_Body
(S
)
11529 and then not In_Private_Part
(S
)
11538 end In_Instance_Visible_Part
;
11540 ---------------------
11541 -- In_Package_Body --
11542 ---------------------
11544 function In_Package_Body
return Boolean is
11548 S
:= Current_Scope
;
11549 while Present
(S
) and then S
/= Standard_Standard
loop
11550 if Ekind
(S
) = E_Package
and then In_Package_Body
(S
) then
11558 end In_Package_Body
;
11560 --------------------------
11561 -- In_Pragma_Expression --
11562 --------------------------
11564 function In_Pragma_Expression
(N
: Node_Id
; Nam
: Name_Id
) return Boolean is
11571 elsif Nkind
(P
) = N_Pragma
and then Pragma_Name
(P
) = Nam
then
11577 end In_Pragma_Expression
;
11579 ---------------------------
11580 -- In_Pre_Post_Condition --
11581 ---------------------------
11583 function In_Pre_Post_Condition
(N
: Node_Id
) return Boolean is
11585 Prag
: Node_Id
:= Empty
;
11586 Prag_Id
: Pragma_Id
;
11589 -- Climb the parent chain looking for an enclosing pragma
11592 while Present
(Par
) loop
11593 if Nkind
(Par
) = N_Pragma
then
11597 -- Prevent the search from going too far
11599 elsif Is_Body_Or_Package_Declaration
(Par
) then
11603 Par
:= Parent
(Par
);
11606 if Present
(Prag
) then
11607 Prag_Id
:= Get_Pragma_Id
(Prag
);
11610 Prag_Id
= Pragma_Post
11611 or else Prag_Id
= Pragma_Post_Class
11612 or else Prag_Id
= Pragma_Postcondition
11613 or else Prag_Id
= Pragma_Pre
11614 or else Prag_Id
= Pragma_Pre_Class
11615 or else Prag_Id
= Pragma_Precondition
;
11617 -- Otherwise the node is not enclosed by a pre/postcondition pragma
11622 end In_Pre_Post_Condition
;
11624 -------------------------------------
11625 -- In_Reverse_Storage_Order_Object --
11626 -------------------------------------
11628 function In_Reverse_Storage_Order_Object
(N
: Node_Id
) return Boolean is
11630 Btyp
: Entity_Id
:= Empty
;
11633 -- Climb up indexed components
11637 case Nkind
(Pref
) is
11638 when N_Selected_Component
=>
11639 Pref
:= Prefix
(Pref
);
11642 when N_Indexed_Component
=>
11643 Pref
:= Prefix
(Pref
);
11651 if Present
(Pref
) then
11652 Btyp
:= Base_Type
(Etype
(Pref
));
11655 return Present
(Btyp
)
11656 and then (Is_Record_Type
(Btyp
) or else Is_Array_Type
(Btyp
))
11657 and then Reverse_Storage_Order
(Btyp
);
11658 end In_Reverse_Storage_Order_Object
;
11660 --------------------------------------
11661 -- In_Subprogram_Or_Concurrent_Unit --
11662 --------------------------------------
11664 function In_Subprogram_Or_Concurrent_Unit
return Boolean is
11669 -- Use scope chain to check successively outer scopes
11671 E
:= Current_Scope
;
11675 if K
in Subprogram_Kind
11676 or else K
in Concurrent_Kind
11677 or else K
in Generic_Subprogram_Kind
11681 elsif E
= Standard_Standard
then
11687 end In_Subprogram_Or_Concurrent_Unit
;
11693 function In_Subtree
(Root
: Node_Id
; N
: Node_Id
) return Boolean is
11698 while Present
(Curr
) loop
11699 if Curr
= Root
then
11703 Curr
:= Parent
(Curr
);
11709 ---------------------
11710 -- In_Visible_Part --
11711 ---------------------
11713 function In_Visible_Part
(Scope_Id
: Entity_Id
) return Boolean is
11715 return Is_Package_Or_Generic_Package
(Scope_Id
)
11716 and then In_Open_Scopes
(Scope_Id
)
11717 and then not In_Package_Body
(Scope_Id
)
11718 and then not In_Private_Part
(Scope_Id
);
11719 end In_Visible_Part
;
11721 --------------------------------
11722 -- Incomplete_Or_Partial_View --
11723 --------------------------------
11725 function Incomplete_Or_Partial_View
(Id
: Entity_Id
) return Entity_Id
is
11726 function Inspect_Decls
11728 Taft
: Boolean := False) return Entity_Id
;
11729 -- Check whether a declarative region contains the incomplete or partial
11732 -------------------
11733 -- Inspect_Decls --
11734 -------------------
11736 function Inspect_Decls
11738 Taft
: Boolean := False) return Entity_Id
11744 Decl
:= First
(Decls
);
11745 while Present
(Decl
) loop
11748 -- The partial view of a Taft-amendment type is an incomplete
11752 if Nkind
(Decl
) = N_Incomplete_Type_Declaration
then
11753 Match
:= Defining_Identifier
(Decl
);
11756 -- Otherwise look for a private type whose full view matches the
11757 -- input type. Note that this checks full_type_declaration nodes
11758 -- to account for derivations from a private type where the type
11759 -- declaration hold the partial view and the full view is an
11762 elsif Nkind_In
(Decl
, N_Full_Type_Declaration
,
11763 N_Private_Extension_Declaration
,
11764 N_Private_Type_Declaration
)
11766 Match
:= Defining_Identifier
(Decl
);
11769 -- Guard against unanalyzed entities
11772 and then Is_Type
(Match
)
11773 and then Present
(Full_View
(Match
))
11774 and then Full_View
(Match
) = Id
11789 -- Start of processing for Incomplete_Or_Partial_View
11792 -- Deferred constant or incomplete type case
11794 Prev
:= Current_Entity_In_Scope
(Id
);
11797 and then (Is_Incomplete_Type
(Prev
) or else Ekind
(Prev
) = E_Constant
)
11798 and then Present
(Full_View
(Prev
))
11799 and then Full_View
(Prev
) = Id
11804 -- Private or Taft amendment type case
11807 Pkg
: constant Entity_Id
:= Scope
(Id
);
11808 Pkg_Decl
: Node_Id
:= Pkg
;
11812 and then Ekind_In
(Pkg
, E_Generic_Package
, E_Package
)
11814 while Nkind
(Pkg_Decl
) /= N_Package_Specification
loop
11815 Pkg_Decl
:= Parent
(Pkg_Decl
);
11818 -- It is knows that Typ has a private view, look for it in the
11819 -- visible declarations of the enclosing scope. A special case
11820 -- of this is when the two views have been exchanged - the full
11821 -- appears earlier than the private.
11823 if Has_Private_Declaration
(Id
) then
11824 Prev
:= Inspect_Decls
(Visible_Declarations
(Pkg_Decl
));
11826 -- Exchanged view case, look in the private declarations
11829 Prev
:= Inspect_Decls
(Private_Declarations
(Pkg_Decl
));
11834 -- Otherwise if this is the package body, then Typ is a potential
11835 -- Taft amendment type. The incomplete view should be located in
11836 -- the private declarations of the enclosing scope.
11838 elsif In_Package_Body
(Pkg
) then
11839 return Inspect_Decls
(Private_Declarations
(Pkg_Decl
), True);
11844 -- The type has no incomplete or private view
11847 end Incomplete_Or_Partial_View
;
11849 ----------------------------------
11850 -- Indexed_Component_Bit_Offset --
11851 ----------------------------------
11853 function Indexed_Component_Bit_Offset
(N
: Node_Id
) return Uint
is
11854 Exp
: constant Node_Id
:= First
(Expressions
(N
));
11855 Typ
: constant Entity_Id
:= Etype
(Prefix
(N
));
11856 Off
: constant Uint
:= Component_Size
(Typ
);
11860 -- Return early if the component size is not known or variable
11862 if Off
= No_Uint
or else Off
< Uint_0
then
11866 -- Deal with the degenerate case of an empty component
11868 if Off
= Uint_0
then
11872 -- Check that both the index value and the low bound are known
11874 if not Compile_Time_Known_Value
(Exp
) then
11878 Ind
:= First_Index
(Typ
);
11883 if Nkind
(Ind
) = N_Subtype_Indication
then
11884 Ind
:= Constraint
(Ind
);
11886 if Nkind
(Ind
) = N_Range_Constraint
then
11887 Ind
:= Range_Expression
(Ind
);
11891 if Nkind
(Ind
) /= N_Range
11892 or else not Compile_Time_Known_Value
(Low_Bound
(Ind
))
11897 -- Return the scaled offset
11899 return Off
* (Expr_Value
(Exp
) - Expr_Value
(Low_Bound
((Ind
))));
11900 end Indexed_Component_Bit_Offset
;
11902 ----------------------------
11903 -- Inherit_Rep_Item_Chain --
11904 ----------------------------
11906 procedure Inherit_Rep_Item_Chain
(Typ
: Entity_Id
; From_Typ
: Entity_Id
) is
11908 Next_Item
: Node_Id
;
11911 -- There are several inheritance scenarios to consider depending on
11912 -- whether both types have rep item chains and whether the destination
11913 -- type already inherits part of the source type's rep item chain.
11915 -- 1) The source type lacks a rep item chain
11916 -- From_Typ ---> Empty
11918 -- Typ --------> Item (or Empty)
11920 -- In this case inheritance cannot take place because there are no items
11923 -- 2) The destination type lacks a rep item chain
11924 -- From_Typ ---> Item ---> ...
11926 -- Typ --------> Empty
11928 -- Inheritance takes place by setting the First_Rep_Item of the
11929 -- destination type to the First_Rep_Item of the source type.
11930 -- From_Typ ---> Item ---> ...
11932 -- Typ -----------+
11934 -- 3.1) Both source and destination types have at least one rep item.
11935 -- The destination type does NOT inherit a rep item from the source
11937 -- From_Typ ---> Item ---> Item
11939 -- Typ --------> Item ---> Item
11941 -- Inheritance takes place by setting the Next_Rep_Item of the last item
11942 -- of the destination type to the First_Rep_Item of the source type.
11943 -- From_Typ -------------------> Item ---> Item
11945 -- Typ --------> Item ---> Item --+
11947 -- 3.2) Both source and destination types have at least one rep item.
11948 -- The destination type DOES inherit part of the rep item chain of the
11950 -- From_Typ ---> Item ---> Item ---> Item
11952 -- Typ --------> Item ------+
11954 -- This rare case arises when the full view of a private extension must
11955 -- inherit the rep item chain from the full view of its parent type and
11956 -- the full view of the parent type contains extra rep items. Currently
11957 -- only invariants may lead to such form of inheritance.
11959 -- type From_Typ is tagged private
11960 -- with Type_Invariant'Class => Item_2;
11962 -- type Typ is new From_Typ with private
11963 -- with Type_Invariant => Item_4;
11965 -- At this point the rep item chains contain the following items
11967 -- From_Typ -----------> Item_2 ---> Item_3
11969 -- Typ --------> Item_4 --+
11971 -- The full views of both types may introduce extra invariants
11973 -- type From_Typ is tagged null record
11974 -- with Type_Invariant => Item_1;
11976 -- type Typ is new From_Typ with null record;
11978 -- The full view of Typ would have to inherit any new rep items added to
11979 -- the full view of From_Typ.
11981 -- From_Typ -----------> Item_1 ---> Item_2 ---> Item_3
11983 -- Typ --------> Item_4 --+
11985 -- To achieve this form of inheritance, the destination type must first
11986 -- sever the link between its own rep chain and that of the source type,
11987 -- then inheritance 3.1 takes place.
11989 -- Case 1: The source type lacks a rep item chain
11991 if No
(First_Rep_Item
(From_Typ
)) then
11994 -- Case 2: The destination type lacks a rep item chain
11996 elsif No
(First_Rep_Item
(Typ
)) then
11997 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
11999 -- Case 3: Both the source and destination types have at least one rep
12000 -- item. Traverse the rep item chain of the destination type to find the
12005 Next_Item
:= First_Rep_Item
(Typ
);
12006 while Present
(Next_Item
) loop
12008 -- Detect a link between the destination type's rep chain and that
12009 -- of the source type. There are two possibilities:
12014 -- From_Typ ---> Item_1 --->
12016 -- Typ -----------+
12023 -- From_Typ ---> Item_1 ---> Item_2 --->
12025 -- Typ --------> Item_3 ------+
12029 if Has_Rep_Item
(From_Typ
, Next_Item
) then
12034 Next_Item
:= Next_Rep_Item
(Next_Item
);
12037 -- Inherit the source type's rep item chain
12039 if Present
(Item
) then
12040 Set_Next_Rep_Item
(Item
, First_Rep_Item
(From_Typ
));
12042 Set_First_Rep_Item
(Typ
, First_Rep_Item
(From_Typ
));
12045 end Inherit_Rep_Item_Chain
;
12047 ---------------------------------
12048 -- Insert_Explicit_Dereference --
12049 ---------------------------------
12051 procedure Insert_Explicit_Dereference
(N
: Node_Id
) is
12052 New_Prefix
: constant Node_Id
:= Relocate_Node
(N
);
12053 Ent
: Entity_Id
:= Empty
;
12060 Save_Interps
(N
, New_Prefix
);
12063 Make_Explicit_Dereference
(Sloc
(Parent
(N
)),
12064 Prefix
=> New_Prefix
));
12066 Set_Etype
(N
, Designated_Type
(Etype
(New_Prefix
)));
12068 if Is_Overloaded
(New_Prefix
) then
12070 -- The dereference is also overloaded, and its interpretations are
12071 -- the designated types of the interpretations of the original node.
12073 Set_Etype
(N
, Any_Type
);
12075 Get_First_Interp
(New_Prefix
, I
, It
);
12076 while Present
(It
.Nam
) loop
12079 if Is_Access_Type
(T
) then
12080 Add_One_Interp
(N
, Designated_Type
(T
), Designated_Type
(T
));
12083 Get_Next_Interp
(I
, It
);
12089 -- Prefix is unambiguous: mark the original prefix (which might
12090 -- Come_From_Source) as a reference, since the new (relocated) one
12091 -- won't be taken into account.
12093 if Is_Entity_Name
(New_Prefix
) then
12094 Ent
:= Entity
(New_Prefix
);
12095 Pref
:= New_Prefix
;
12097 -- For a retrieval of a subcomponent of some composite object,
12098 -- retrieve the ultimate entity if there is one.
12100 elsif Nkind_In
(New_Prefix
, N_Selected_Component
,
12101 N_Indexed_Component
)
12103 Pref
:= Prefix
(New_Prefix
);
12104 while Present
(Pref
)
12105 and then Nkind_In
(Pref
, N_Selected_Component
,
12106 N_Indexed_Component
)
12108 Pref
:= Prefix
(Pref
);
12111 if Present
(Pref
) and then Is_Entity_Name
(Pref
) then
12112 Ent
:= Entity
(Pref
);
12116 -- Place the reference on the entity node
12118 if Present
(Ent
) then
12119 Generate_Reference
(Ent
, Pref
);
12122 end Insert_Explicit_Dereference
;
12124 ------------------------------------------
12125 -- Inspect_Deferred_Constant_Completion --
12126 ------------------------------------------
12128 procedure Inspect_Deferred_Constant_Completion
(Decls
: List_Id
) is
12132 Decl
:= First
(Decls
);
12133 while Present
(Decl
) loop
12135 -- Deferred constant signature
12137 if Nkind
(Decl
) = N_Object_Declaration
12138 and then Constant_Present
(Decl
)
12139 and then No
(Expression
(Decl
))
12141 -- No need to check internally generated constants
12143 and then Comes_From_Source
(Decl
)
12145 -- The constant is not completed. A full object declaration or a
12146 -- pragma Import complete a deferred constant.
12148 and then not Has_Completion
(Defining_Identifier
(Decl
))
12151 ("constant declaration requires initialization expression",
12152 Defining_Identifier
(Decl
));
12155 Decl
:= Next
(Decl
);
12157 end Inspect_Deferred_Constant_Completion
;
12159 -----------------------------
12160 -- Install_Generic_Formals --
12161 -----------------------------
12163 procedure Install_Generic_Formals
(Subp_Id
: Entity_Id
) is
12167 pragma Assert
(Is_Generic_Subprogram
(Subp_Id
));
12169 E
:= First_Entity
(Subp_Id
);
12170 while Present
(E
) loop
12171 Install_Entity
(E
);
12174 end Install_Generic_Formals
;
12176 ------------------------
12177 -- Install_SPARK_Mode --
12178 ------------------------
12180 procedure Install_SPARK_Mode
(Mode
: SPARK_Mode_Type
; Prag
: Node_Id
) is
12182 SPARK_Mode
:= Mode
;
12183 SPARK_Mode_Pragma
:= Prag
;
12184 end Install_SPARK_Mode
;
12186 -----------------------------
12187 -- Is_Actual_Out_Parameter --
12188 -----------------------------
12190 function Is_Actual_Out_Parameter
(N
: Node_Id
) return Boolean is
12191 Formal
: Entity_Id
;
12194 Find_Actual
(N
, Formal
, Call
);
12195 return Present
(Formal
) and then Ekind
(Formal
) = E_Out_Parameter
;
12196 end Is_Actual_Out_Parameter
;
12198 -------------------------
12199 -- Is_Actual_Parameter --
12200 -------------------------
12202 function Is_Actual_Parameter
(N
: Node_Id
) return Boolean is
12203 PK
: constant Node_Kind
:= Nkind
(Parent
(N
));
12207 when N_Parameter_Association
=>
12208 return N
= Explicit_Actual_Parameter
(Parent
(N
));
12210 when N_Subprogram_Call
=>
12211 return Is_List_Member
(N
)
12213 List_Containing
(N
) = Parameter_Associations
(Parent
(N
));
12218 end Is_Actual_Parameter
;
12220 --------------------------------
12221 -- Is_Actual_Tagged_Parameter --
12222 --------------------------------
12224 function Is_Actual_Tagged_Parameter
(N
: Node_Id
) return Boolean is
12225 Formal
: Entity_Id
;
12228 Find_Actual
(N
, Formal
, Call
);
12229 return Present
(Formal
) and then Is_Tagged_Type
(Etype
(Formal
));
12230 end Is_Actual_Tagged_Parameter
;
12232 ---------------------
12233 -- Is_Aliased_View --
12234 ---------------------
12236 function Is_Aliased_View
(Obj
: Node_Id
) return Boolean is
12240 if Is_Entity_Name
(Obj
) then
12247 or else (Present
(Renamed_Object
(E
))
12248 and then Is_Aliased_View
(Renamed_Object
(E
)))))
12250 or else ((Is_Formal
(E
)
12251 or else Ekind_In
(E
, E_Generic_In_Out_Parameter
,
12252 E_Generic_In_Parameter
))
12253 and then Is_Tagged_Type
(Etype
(E
)))
12255 or else (Is_Concurrent_Type
(E
) and then In_Open_Scopes
(E
))
12257 -- Current instance of type, either directly or as rewritten
12258 -- reference to the current object.
12260 or else (Is_Entity_Name
(Original_Node
(Obj
))
12261 and then Present
(Entity
(Original_Node
(Obj
)))
12262 and then Is_Type
(Entity
(Original_Node
(Obj
))))
12264 or else (Is_Type
(E
) and then E
= Current_Scope
)
12266 or else (Is_Incomplete_Or_Private_Type
(E
)
12267 and then Full_View
(E
) = Current_Scope
)
12269 -- Ada 2012 AI05-0053: the return object of an extended return
12270 -- statement is aliased if its type is immutably limited.
12272 or else (Is_Return_Object
(E
)
12273 and then Is_Limited_View
(Etype
(E
)));
12275 elsif Nkind
(Obj
) = N_Selected_Component
then
12276 return Is_Aliased
(Entity
(Selector_Name
(Obj
)));
12278 elsif Nkind
(Obj
) = N_Indexed_Component
then
12279 return Has_Aliased_Components
(Etype
(Prefix
(Obj
)))
12281 (Is_Access_Type
(Etype
(Prefix
(Obj
)))
12282 and then Has_Aliased_Components
12283 (Designated_Type
(Etype
(Prefix
(Obj
)))));
12285 elsif Nkind_In
(Obj
, N_Unchecked_Type_Conversion
, N_Type_Conversion
) then
12286 return Is_Tagged_Type
(Etype
(Obj
))
12287 and then Is_Aliased_View
(Expression
(Obj
));
12289 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
12290 return Nkind
(Original_Node
(Obj
)) /= N_Function_Call
;
12295 end Is_Aliased_View
;
12297 -------------------------
12298 -- Is_Ancestor_Package --
12299 -------------------------
12301 function Is_Ancestor_Package
12303 E2
: Entity_Id
) return Boolean
12309 while Present
(Par
) and then Par
/= Standard_Standard
loop
12314 Par
:= Scope
(Par
);
12318 end Is_Ancestor_Package
;
12320 ----------------------
12321 -- Is_Atomic_Object --
12322 ----------------------
12324 function Is_Atomic_Object
(N
: Node_Id
) return Boolean is
12326 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean;
12327 -- Determines if given object has atomic components
12329 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean;
12330 -- If prefix is an implicit dereference, examine designated type
12332 ----------------------
12333 -- Is_Atomic_Prefix --
12334 ----------------------
12336 function Is_Atomic_Prefix
(N
: Node_Id
) return Boolean is
12338 if Is_Access_Type
(Etype
(N
)) then
12340 Has_Atomic_Components
(Designated_Type
(Etype
(N
)));
12342 return Object_Has_Atomic_Components
(N
);
12344 end Is_Atomic_Prefix
;
12346 ----------------------------------
12347 -- Object_Has_Atomic_Components --
12348 ----------------------------------
12350 function Object_Has_Atomic_Components
(N
: Node_Id
) return Boolean is
12352 if Has_Atomic_Components
(Etype
(N
))
12353 or else Is_Atomic
(Etype
(N
))
12357 elsif Is_Entity_Name
(N
)
12358 and then (Has_Atomic_Components
(Entity
(N
))
12359 or else Is_Atomic
(Entity
(N
)))
12363 elsif Nkind
(N
) = N_Selected_Component
12364 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
12368 elsif Nkind
(N
) = N_Indexed_Component
12369 or else Nkind
(N
) = N_Selected_Component
12371 return Is_Atomic_Prefix
(Prefix
(N
));
12376 end Object_Has_Atomic_Components
;
12378 -- Start of processing for Is_Atomic_Object
12381 -- Predicate is not relevant to subprograms
12383 if Is_Entity_Name
(N
) and then Is_Overloadable
(Entity
(N
)) then
12386 elsif Is_Atomic
(Etype
(N
))
12387 or else (Is_Entity_Name
(N
) and then Is_Atomic
(Entity
(N
)))
12391 elsif Nkind
(N
) = N_Selected_Component
12392 and then Is_Atomic
(Entity
(Selector_Name
(N
)))
12396 elsif Nkind
(N
) = N_Indexed_Component
12397 or else Nkind
(N
) = N_Selected_Component
12399 return Is_Atomic_Prefix
(Prefix
(N
));
12404 end Is_Atomic_Object
;
12406 -----------------------------
12407 -- Is_Atomic_Or_VFA_Object --
12408 -----------------------------
12410 function Is_Atomic_Or_VFA_Object
(N
: Node_Id
) return Boolean is
12412 return Is_Atomic_Object
(N
)
12413 or else (Is_Object_Reference
(N
)
12414 and then Is_Entity_Name
(N
)
12415 and then (Is_Volatile_Full_Access
(Entity
(N
))
12417 Is_Volatile_Full_Access
(Etype
(Entity
(N
)))));
12418 end Is_Atomic_Or_VFA_Object
;
12420 -------------------------
12421 -- Is_Attribute_Result --
12422 -------------------------
12424 function Is_Attribute_Result
(N
: Node_Id
) return Boolean is
12426 return Nkind
(N
) = N_Attribute_Reference
12427 and then Attribute_Name
(N
) = Name_Result
;
12428 end Is_Attribute_Result
;
12430 -------------------------
12431 -- Is_Attribute_Update --
12432 -------------------------
12434 function Is_Attribute_Update
(N
: Node_Id
) return Boolean is
12436 return Nkind
(N
) = N_Attribute_Reference
12437 and then Attribute_Name
(N
) = Name_Update
;
12438 end Is_Attribute_Update
;
12440 ------------------------------------
12441 -- Is_Body_Or_Package_Declaration --
12442 ------------------------------------
12444 function Is_Body_Or_Package_Declaration
(N
: Node_Id
) return Boolean is
12446 return Nkind_In
(N
, N_Entry_Body
,
12448 N_Package_Declaration
,
12452 end Is_Body_Or_Package_Declaration
;
12454 -----------------------
12455 -- Is_Bounded_String --
12456 -----------------------
12458 function Is_Bounded_String
(T
: Entity_Id
) return Boolean is
12459 Under
: constant Entity_Id
:= Underlying_Type
(Root_Type
(T
));
12462 -- Check whether T is ultimately derived from Ada.Strings.Superbounded.
12463 -- Super_String, or one of the [Wide_]Wide_ versions. This will
12464 -- be True for all the Bounded_String types in instances of the
12465 -- Generic_Bounded_Length generics, and for types derived from those.
12467 return Present
(Under
)
12468 and then (Is_RTE
(Root_Type
(Under
), RO_SU_Super_String
) or else
12469 Is_RTE
(Root_Type
(Under
), RO_WI_Super_String
) or else
12470 Is_RTE
(Root_Type
(Under
), RO_WW_Super_String
));
12471 end Is_Bounded_String
;
12473 ---------------------
12474 -- Is_CCT_Instance --
12475 ---------------------
12477 function Is_CCT_Instance
12478 (Ref_Id
: Entity_Id
;
12479 Context_Id
: Entity_Id
) return Boolean
12482 pragma Assert
(Ekind_In
(Ref_Id
, E_Protected_Type
, E_Task_Type
));
12484 if Is_Single_Task_Object
(Context_Id
) then
12485 return Scope_Within_Or_Same
(Etype
(Context_Id
), Ref_Id
);
12488 pragma Assert
(Ekind_In
(Context_Id
, E_Entry
,
12496 return Scope_Within_Or_Same
(Context_Id
, Ref_Id
);
12498 end Is_CCT_Instance
;
12500 -------------------------
12501 -- Is_Child_Or_Sibling --
12502 -------------------------
12504 function Is_Child_Or_Sibling
12505 (Pack_1
: Entity_Id
;
12506 Pack_2
: Entity_Id
) return Boolean
12508 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
;
12509 -- Given an arbitrary package, return the number of "climbs" necessary
12510 -- to reach scope Standard_Standard.
12512 procedure Equalize_Depths
12513 (Pack
: in out Entity_Id
;
12514 Depth
: in out Nat
;
12515 Depth_To_Reach
: Nat
);
12516 -- Given an arbitrary package, its depth and a target depth to reach,
12517 -- climb the scope chain until the said depth is reached. The pointer
12518 -- to the package and its depth a modified during the climb.
12520 ----------------------------
12521 -- Distance_From_Standard --
12522 ----------------------------
12524 function Distance_From_Standard
(Pack
: Entity_Id
) return Nat
is
12531 while Present
(Scop
) and then Scop
/= Standard_Standard
loop
12533 Scop
:= Scope
(Scop
);
12537 end Distance_From_Standard
;
12539 ---------------------
12540 -- Equalize_Depths --
12541 ---------------------
12543 procedure Equalize_Depths
12544 (Pack
: in out Entity_Id
;
12545 Depth
: in out Nat
;
12546 Depth_To_Reach
: Nat
)
12549 -- The package must be at a greater or equal depth
12551 if Depth
< Depth_To_Reach
then
12552 raise Program_Error
;
12555 -- Climb the scope chain until the desired depth is reached
12557 while Present
(Pack
) and then Depth
/= Depth_To_Reach
loop
12558 Pack
:= Scope
(Pack
);
12559 Depth
:= Depth
- 1;
12561 end Equalize_Depths
;
12565 P_1
: Entity_Id
:= Pack_1
;
12566 P_1_Child
: Boolean := False;
12567 P_1_Depth
: Nat
:= Distance_From_Standard
(P_1
);
12568 P_2
: Entity_Id
:= Pack_2
;
12569 P_2_Child
: Boolean := False;
12570 P_2_Depth
: Nat
:= Distance_From_Standard
(P_2
);
12572 -- Start of processing for Is_Child_Or_Sibling
12576 (Ekind
(Pack_1
) = E_Package
and then Ekind
(Pack_2
) = E_Package
);
12578 -- Both packages denote the same entity, therefore they cannot be
12579 -- children or siblings.
12584 -- One of the packages is at a deeper level than the other. Note that
12585 -- both may still come from different hierarchies.
12593 elsif P_1_Depth
> P_2_Depth
then
12596 Depth
=> P_1_Depth
,
12597 Depth_To_Reach
=> P_2_Depth
);
12606 elsif P_2_Depth
> P_1_Depth
then
12609 Depth
=> P_2_Depth
,
12610 Depth_To_Reach
=> P_1_Depth
);
12614 -- At this stage the package pointers have been elevated to the same
12615 -- depth. If the related entities are the same, then one package is a
12616 -- potential child of the other:
12620 -- X became P_1 P_2 or vice versa
12626 return Is_Child_Unit
(Pack_1
);
12628 else pragma Assert
(P_2_Child
);
12629 return Is_Child_Unit
(Pack_2
);
12632 -- The packages may come from the same package chain or from entirely
12633 -- different hierarcies. To determine this, climb the scope stack until
12634 -- a common root is found.
12636 -- (root) (root 1) (root 2)
12641 while Present
(P_1
) and then Present
(P_2
) loop
12643 -- The two packages may be siblings
12646 return Is_Child_Unit
(Pack_1
) and then Is_Child_Unit
(Pack_2
);
12649 P_1
:= Scope
(P_1
);
12650 P_2
:= Scope
(P_2
);
12655 end Is_Child_Or_Sibling
;
12657 -----------------------------
12658 -- Is_Concurrent_Interface --
12659 -----------------------------
12661 function Is_Concurrent_Interface
(T
: Entity_Id
) return Boolean is
12663 return Is_Interface
(T
)
12665 (Is_Protected_Interface
(T
)
12666 or else Is_Synchronized_Interface
(T
)
12667 or else Is_Task_Interface
(T
));
12668 end Is_Concurrent_Interface
;
12670 -----------------------
12671 -- Is_Constant_Bound --
12672 -----------------------
12674 function Is_Constant_Bound
(Exp
: Node_Id
) return Boolean is
12676 if Compile_Time_Known_Value
(Exp
) then
12679 elsif Is_Entity_Name
(Exp
) and then Present
(Entity
(Exp
)) then
12680 return Is_Constant_Object
(Entity
(Exp
))
12681 or else Ekind
(Entity
(Exp
)) = E_Enumeration_Literal
;
12683 elsif Nkind
(Exp
) in N_Binary_Op
then
12684 return Is_Constant_Bound
(Left_Opnd
(Exp
))
12685 and then Is_Constant_Bound
(Right_Opnd
(Exp
))
12686 and then Scope
(Entity
(Exp
)) = Standard_Standard
;
12691 end Is_Constant_Bound
;
12693 ---------------------------
12694 -- Is_Container_Element --
12695 ---------------------------
12697 function Is_Container_Element
(Exp
: Node_Id
) return Boolean is
12698 Loc
: constant Source_Ptr
:= Sloc
(Exp
);
12699 Pref
: constant Node_Id
:= Prefix
(Exp
);
12702 -- Call to an indexing aspect
12704 Cont_Typ
: Entity_Id
;
12705 -- The type of the container being accessed
12707 Elem_Typ
: Entity_Id
;
12708 -- Its element type
12710 Indexing
: Entity_Id
;
12711 Is_Const
: Boolean;
12712 -- Indicates that constant indexing is used, and the element is thus
12715 Ref_Typ
: Entity_Id
;
12716 -- The reference type returned by the indexing operation
12719 -- If C is a container, in a context that imposes the element type of
12720 -- that container, the indexing notation C (X) is rewritten as:
12722 -- Indexing (C, X).Discr.all
12724 -- where Indexing is one of the indexing aspects of the container.
12725 -- If the context does not require a reference, the construct can be
12730 -- First, verify that the construct has the proper form
12732 if not Expander_Active
then
12735 elsif Nkind
(Pref
) /= N_Selected_Component
then
12738 elsif Nkind
(Prefix
(Pref
)) /= N_Function_Call
then
12742 Call
:= Prefix
(Pref
);
12743 Ref_Typ
:= Etype
(Call
);
12746 if not Has_Implicit_Dereference
(Ref_Typ
)
12747 or else No
(First
(Parameter_Associations
(Call
)))
12748 or else not Is_Entity_Name
(Name
(Call
))
12753 -- Retrieve type of container object, and its iterator aspects
12755 Cont_Typ
:= Etype
(First
(Parameter_Associations
(Call
)));
12756 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Constant_Indexing
);
12759 if No
(Indexing
) then
12761 -- Container should have at least one indexing operation
12765 elsif Entity
(Name
(Call
)) /= Entity
(Indexing
) then
12767 -- This may be a variable indexing operation
12769 Indexing
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Variable_Indexing
);
12772 or else Entity
(Name
(Call
)) /= Entity
(Indexing
)
12781 Elem_Typ
:= Find_Value_Of_Aspect
(Cont_Typ
, Aspect_Iterator_Element
);
12783 if No
(Elem_Typ
) or else Entity
(Elem_Typ
) /= Etype
(Exp
) then
12787 -- Check that the expression is not the target of an assignment, in
12788 -- which case the rewriting is not possible.
12790 if not Is_Const
then
12796 while Present
(Par
)
12798 if Nkind
(Parent
(Par
)) = N_Assignment_Statement
12799 and then Par
= Name
(Parent
(Par
))
12803 -- A renaming produces a reference, and the transformation
12806 elsif Nkind
(Parent
(Par
)) = N_Object_Renaming_Declaration
then
12810 (Nkind
(Parent
(Par
)), N_Function_Call
,
12811 N_Procedure_Call_Statement
,
12812 N_Entry_Call_Statement
)
12814 -- Check that the element is not part of an actual for an
12815 -- in-out parameter.
12822 F
:= First_Formal
(Entity
(Name
(Parent
(Par
))));
12823 A
:= First
(Parameter_Associations
(Parent
(Par
)));
12824 while Present
(F
) loop
12825 if A
= Par
and then Ekind
(F
) /= E_In_Parameter
then
12834 -- E_In_Parameter in a call: element is not modified.
12839 Par
:= Parent
(Par
);
12844 -- The expression has the proper form and the context requires the
12845 -- element type. Retrieve the Element function of the container and
12846 -- rewrite the construct as a call to it.
12852 Op
:= First_Elmt
(Primitive_Operations
(Cont_Typ
));
12853 while Present
(Op
) loop
12854 exit when Chars
(Node
(Op
)) = Name_Element
;
12863 Make_Function_Call
(Loc
,
12864 Name
=> New_Occurrence_Of
(Node
(Op
), Loc
),
12865 Parameter_Associations
=> Parameter_Associations
(Call
)));
12866 Analyze_And_Resolve
(Exp
, Entity
(Elem_Typ
));
12870 end Is_Container_Element
;
12872 ----------------------------
12873 -- Is_Contract_Annotation --
12874 ----------------------------
12876 function Is_Contract_Annotation
(Item
: Node_Id
) return Boolean is
12878 return Is_Package_Contract_Annotation
(Item
)
12880 Is_Subprogram_Contract_Annotation
(Item
);
12881 end Is_Contract_Annotation
;
12883 --------------------------------------
12884 -- Is_Controlling_Limited_Procedure --
12885 --------------------------------------
12887 function Is_Controlling_Limited_Procedure
12888 (Proc_Nam
: Entity_Id
) return Boolean
12890 Param_Typ
: Entity_Id
:= Empty
;
12893 if Ekind
(Proc_Nam
) = E_Procedure
12894 and then Present
(Parameter_Specifications
(Parent
(Proc_Nam
)))
12896 Param_Typ
:= Etype
(Parameter_Type
(First
(
12897 Parameter_Specifications
(Parent
(Proc_Nam
)))));
12899 -- In this case where an Itype was created, the procedure call has been
12902 elsif Present
(Associated_Node_For_Itype
(Proc_Nam
))
12903 and then Present
(Original_Node
(Associated_Node_For_Itype
(Proc_Nam
)))
12905 Present
(Parameter_Associations
12906 (Associated_Node_For_Itype
(Proc_Nam
)))
12909 Etype
(First
(Parameter_Associations
12910 (Associated_Node_For_Itype
(Proc_Nam
))));
12913 if Present
(Param_Typ
) then
12915 Is_Interface
(Param_Typ
)
12916 and then Is_Limited_Record
(Param_Typ
);
12920 end Is_Controlling_Limited_Procedure
;
12922 -----------------------------
12923 -- Is_CPP_Constructor_Call --
12924 -----------------------------
12926 function Is_CPP_Constructor_Call
(N
: Node_Id
) return Boolean is
12928 return Nkind
(N
) = N_Function_Call
12929 and then Is_CPP_Class
(Etype
(Etype
(N
)))
12930 and then Is_Constructor
(Entity
(Name
(N
)))
12931 and then Is_Imported
(Entity
(Name
(N
)));
12932 end Is_CPP_Constructor_Call
;
12934 -------------------------
12935 -- Is_Current_Instance --
12936 -------------------------
12938 function Is_Current_Instance
(N
: Node_Id
) return Boolean is
12939 Typ
: constant Entity_Id
:= Entity
(N
);
12943 -- Simplest case: entity is a concurrent type and we are currently
12944 -- inside the body. This will eventually be expanded into a
12945 -- call to Self (for tasks) or _object (for protected objects).
12947 if Is_Concurrent_Type
(Typ
) and then In_Open_Scopes
(Typ
) then
12951 -- Check whether the context is a (sub)type declaration for the
12955 while Present
(P
) loop
12956 if Nkind_In
(P
, N_Full_Type_Declaration
,
12957 N_Private_Type_Declaration
,
12958 N_Subtype_Declaration
)
12959 and then Comes_From_Source
(P
)
12960 and then Defining_Entity
(P
) = Typ
12964 -- A subtype name may appear in an aspect specification for a
12965 -- Predicate_Failure aspect, for which we do not construct a
12966 -- wrapper procedure. The subtype will be replaced by the
12967 -- expression being tested when the corresponding predicate
12968 -- check is expanded.
12970 elsif Nkind
(P
) = N_Aspect_Specification
12971 and then Nkind
(Parent
(P
)) = N_Subtype_Declaration
12975 elsif Nkind
(P
) = N_Pragma
12977 Get_Pragma_Id
(P
) = Pragma_Predicate_Failure
12986 -- In any other context this is not a current occurrence
12989 end Is_Current_Instance
;
12991 --------------------
12992 -- Is_Declaration --
12993 --------------------
12995 function Is_Declaration
(N
: Node_Id
) return Boolean is
12998 Is_Declaration_Other_Than_Renaming
(N
)
12999 or else Is_Renaming_Declaration
(N
);
13000 end Is_Declaration
;
13002 ----------------------------------------
13003 -- Is_Declaration_Other_Than_Renaming --
13004 ----------------------------------------
13006 function Is_Declaration_Other_Than_Renaming
(N
: Node_Id
) return Boolean is
13009 when N_Abstract_Subprogram_Declaration
13010 | N_Exception_Declaration
13011 | N_Expression_Function
13012 | N_Full_Type_Declaration
13013 | N_Generic_Package_Declaration
13014 | N_Generic_Subprogram_Declaration
13015 | N_Number_Declaration
13016 | N_Object_Declaration
13017 | N_Package_Declaration
13018 | N_Private_Extension_Declaration
13019 | N_Private_Type_Declaration
13020 | N_Subprogram_Declaration
13021 | N_Subtype_Declaration
13028 end Is_Declaration_Other_Than_Renaming
;
13030 --------------------------------
13031 -- Is_Declared_Within_Variant --
13032 --------------------------------
13034 function Is_Declared_Within_Variant
(Comp
: Entity_Id
) return Boolean is
13035 Comp_Decl
: constant Node_Id
:= Parent
(Comp
);
13036 Comp_List
: constant Node_Id
:= Parent
(Comp_Decl
);
13038 return Nkind
(Parent
(Comp_List
)) = N_Variant
;
13039 end Is_Declared_Within_Variant
;
13041 ----------------------------------------------
13042 -- Is_Dependent_Component_Of_Mutable_Object --
13043 ----------------------------------------------
13045 function Is_Dependent_Component_Of_Mutable_Object
13046 (Object
: Node_Id
) return Boolean
13049 Prefix_Type
: Entity_Id
;
13050 P_Aliased
: Boolean := False;
13053 Deref
: Node_Id
:= Object
;
13054 -- Dereference node, in something like X.all.Y(2)
13056 -- Start of processing for Is_Dependent_Component_Of_Mutable_Object
13059 -- Find the dereference node if any
13061 while Nkind_In
(Deref
, N_Indexed_Component
,
13062 N_Selected_Component
,
13065 Deref
:= Prefix
(Deref
);
13068 -- Ada 2005: If we have a component or slice of a dereference,
13069 -- something like X.all.Y (2), and the type of X is access-to-constant,
13070 -- Is_Variable will return False, because it is indeed a constant
13071 -- view. But it might be a view of a variable object, so we want the
13072 -- following condition to be True in that case.
13074 if Is_Variable
(Object
)
13075 or else (Ada_Version
>= Ada_2005
13076 and then Nkind
(Deref
) = N_Explicit_Dereference
)
13078 if Nkind
(Object
) = N_Selected_Component
then
13079 P
:= Prefix
(Object
);
13080 Prefix_Type
:= Etype
(P
);
13082 if Is_Entity_Name
(P
) then
13083 if Ekind
(Entity
(P
)) = E_Generic_In_Out_Parameter
then
13084 Prefix_Type
:= Base_Type
(Prefix_Type
);
13087 if Is_Aliased
(Entity
(P
)) then
13091 -- A discriminant check on a selected component may be expanded
13092 -- into a dereference when removing side-effects. Recover the
13093 -- original node and its type, which may be unconstrained.
13095 elsif Nkind
(P
) = N_Explicit_Dereference
13096 and then not (Comes_From_Source
(P
))
13098 P
:= Original_Node
(P
);
13099 Prefix_Type
:= Etype
(P
);
13102 -- Check for prefix being an aliased component???
13108 -- A heap object is constrained by its initial value
13110 -- Ada 2005 (AI-363): Always assume the object could be mutable in
13111 -- the dereferenced case, since the access value might denote an
13112 -- unconstrained aliased object, whereas in Ada 95 the designated
13113 -- object is guaranteed to be constrained. A worst-case assumption
13114 -- has to apply in Ada 2005 because we can't tell at compile
13115 -- time whether the object is "constrained by its initial value",
13116 -- despite the fact that 3.10.2(26/2) and 8.5.1(5/2) are semantic
13117 -- rules (these rules are acknowledged to need fixing). We don't
13118 -- impose this more stringent checking for earlier Ada versions or
13119 -- when Relaxed_RM_Semantics applies (the latter for CodePeer's
13120 -- benefit, though it's unclear on why using -gnat95 would not be
13123 if Ada_Version
< Ada_2005
or else Relaxed_RM_Semantics
then
13124 if Is_Access_Type
(Prefix_Type
)
13125 or else Nkind
(P
) = N_Explicit_Dereference
13130 else pragma Assert
(Ada_Version
>= Ada_2005
);
13131 if Is_Access_Type
(Prefix_Type
) then
13133 -- If the access type is pool-specific, and there is no
13134 -- constrained partial view of the designated type, then the
13135 -- designated object is known to be constrained.
13137 if Ekind
(Prefix_Type
) = E_Access_Type
13138 and then not Object_Type_Has_Constrained_Partial_View
13139 (Typ
=> Designated_Type
(Prefix_Type
),
13140 Scop
=> Current_Scope
)
13144 -- Otherwise (general access type, or there is a constrained
13145 -- partial view of the designated type), we need to check
13146 -- based on the designated type.
13149 Prefix_Type
:= Designated_Type
(Prefix_Type
);
13155 Original_Record_Component
(Entity
(Selector_Name
(Object
)));
13157 -- As per AI-0017, the renaming is illegal in a generic body, even
13158 -- if the subtype is indefinite.
13160 -- Ada 2005 (AI-363): In Ada 2005 an aliased object can be mutable
13162 if not Is_Constrained
(Prefix_Type
)
13163 and then (Is_Definite_Subtype
(Prefix_Type
)
13165 (Is_Generic_Type
(Prefix_Type
)
13166 and then Ekind
(Current_Scope
) = E_Generic_Package
13167 and then In_Package_Body
(Current_Scope
)))
13169 and then (Is_Declared_Within_Variant
(Comp
)
13170 or else Has_Discriminant_Dependent_Constraint
(Comp
))
13171 and then (not P_Aliased
or else Ada_Version
>= Ada_2005
)
13175 -- If the prefix is of an access type at this point, then we want
13176 -- to return False, rather than calling this function recursively
13177 -- on the access object (which itself might be a discriminant-
13178 -- dependent component of some other object, but that isn't
13179 -- relevant to checking the object passed to us). This avoids
13180 -- issuing wrong errors when compiling with -gnatc, where there
13181 -- can be implicit dereferences that have not been expanded.
13183 elsif Is_Access_Type
(Etype
(Prefix
(Object
))) then
13188 Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
13191 elsif Nkind
(Object
) = N_Indexed_Component
13192 or else Nkind
(Object
) = N_Slice
13194 return Is_Dependent_Component_Of_Mutable_Object
(Prefix
(Object
));
13196 -- A type conversion that Is_Variable is a view conversion:
13197 -- go back to the denoted object.
13199 elsif Nkind
(Object
) = N_Type_Conversion
then
13201 Is_Dependent_Component_Of_Mutable_Object
(Expression
(Object
));
13206 end Is_Dependent_Component_Of_Mutable_Object
;
13208 ---------------------
13209 -- Is_Dereferenced --
13210 ---------------------
13212 function Is_Dereferenced
(N
: Node_Id
) return Boolean is
13213 P
: constant Node_Id
:= Parent
(N
);
13215 return Nkind_In
(P
, N_Selected_Component
,
13216 N_Explicit_Dereference
,
13217 N_Indexed_Component
,
13219 and then Prefix
(P
) = N
;
13220 end Is_Dereferenced
;
13222 ----------------------
13223 -- Is_Descendant_Of --
13224 ----------------------
13226 function Is_Descendant_Of
(T1
: Entity_Id
; T2
: Entity_Id
) return Boolean is
13231 pragma Assert
(Nkind
(T1
) in N_Entity
);
13232 pragma Assert
(Nkind
(T2
) in N_Entity
);
13234 T
:= Base_Type
(T1
);
13236 -- Immediate return if the types match
13241 -- Comment needed here ???
13243 elsif Ekind
(T
) = E_Class_Wide_Type
then
13244 return Etype
(T
) = T2
;
13252 -- Done if we found the type we are looking for
13257 -- Done if no more derivations to check
13264 -- Following test catches error cases resulting from prev errors
13266 elsif No
(Etyp
) then
13269 elsif Is_Private_Type
(T
) and then Etyp
= Full_View
(T
) then
13272 elsif Is_Private_Type
(Etyp
) and then Full_View
(Etyp
) = T
then
13276 T
:= Base_Type
(Etyp
);
13279 end Is_Descendant_Of
;
13281 ----------------------------------------
13282 -- Is_Descendant_Of_Suspension_Object --
13283 ----------------------------------------
13285 function Is_Descendant_Of_Suspension_Object
13286 (Typ
: Entity_Id
) return Boolean
13288 Cur_Typ
: Entity_Id
;
13289 Par_Typ
: Entity_Id
;
13292 -- Climb the type derivation chain checking each parent type against
13293 -- Suspension_Object.
13295 Cur_Typ
:= Base_Type
(Typ
);
13296 while Present
(Cur_Typ
) loop
13297 Par_Typ
:= Etype
(Cur_Typ
);
13299 -- The current type is a match
13301 if Is_Suspension_Object
(Cur_Typ
) then
13304 -- Stop the traversal once the root of the derivation chain has been
13305 -- reached. In that case the current type is its own base type.
13307 elsif Cur_Typ
= Par_Typ
then
13311 Cur_Typ
:= Base_Type
(Par_Typ
);
13315 end Is_Descendant_Of_Suspension_Object
;
13317 ---------------------------------------------
13318 -- Is_Double_Precision_Floating_Point_Type --
13319 ---------------------------------------------
13321 function Is_Double_Precision_Floating_Point_Type
13322 (E
: Entity_Id
) return Boolean is
13324 return Is_Floating_Point_Type
(E
)
13325 and then Machine_Radix_Value
(E
) = Uint_2
13326 and then Machine_Mantissa_Value
(E
) = UI_From_Int
(53)
13327 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_10
13328 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_10
);
13329 end Is_Double_Precision_Floating_Point_Type
;
13331 -----------------------------
13332 -- Is_Effectively_Volatile --
13333 -----------------------------
13335 function Is_Effectively_Volatile
(Id
: Entity_Id
) return Boolean is
13337 if Is_Type
(Id
) then
13339 -- An arbitrary type is effectively volatile when it is subject to
13340 -- pragma Atomic or Volatile.
13342 if Is_Volatile
(Id
) then
13345 -- An array type is effectively volatile when it is subject to pragma
13346 -- Atomic_Components or Volatile_Components or its component type is
13347 -- effectively volatile.
13349 elsif Is_Array_Type
(Id
) then
13351 Anc
: Entity_Id
:= Base_Type
(Id
);
13353 if Is_Private_Type
(Anc
) then
13354 Anc
:= Full_View
(Anc
);
13357 -- Test for presence of ancestor, as the full view of a private
13358 -- type may be missing in case of error.
13361 Has_Volatile_Components
(Id
)
13364 and then Is_Effectively_Volatile
(Component_Type
(Anc
)));
13367 -- A protected type is always volatile
13369 elsif Is_Protected_Type
(Id
) then
13372 -- A descendant of Ada.Synchronous_Task_Control.Suspension_Object is
13373 -- automatically volatile.
13375 elsif Is_Descendant_Of_Suspension_Object
(Id
) then
13378 -- Otherwise the type is not effectively volatile
13384 -- Otherwise Id denotes an object
13389 or else Has_Volatile_Components
(Id
)
13390 or else Is_Effectively_Volatile
(Etype
(Id
));
13392 end Is_Effectively_Volatile
;
13394 ------------------------------------
13395 -- Is_Effectively_Volatile_Object --
13396 ------------------------------------
13398 function Is_Effectively_Volatile_Object
(N
: Node_Id
) return Boolean is
13400 if Is_Entity_Name
(N
) then
13401 return Is_Effectively_Volatile
(Entity
(N
));
13403 elsif Nkind
(N
) = N_Indexed_Component
then
13404 return Is_Effectively_Volatile_Object
(Prefix
(N
));
13406 elsif Nkind
(N
) = N_Selected_Component
then
13408 Is_Effectively_Volatile_Object
(Prefix
(N
))
13410 Is_Effectively_Volatile_Object
(Selector_Name
(N
));
13415 end Is_Effectively_Volatile_Object
;
13417 -------------------
13418 -- Is_Entry_Body --
13419 -------------------
13421 function Is_Entry_Body
(Id
: Entity_Id
) return Boolean is
13424 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
13425 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Body
;
13428 --------------------------
13429 -- Is_Entry_Declaration --
13430 --------------------------
13432 function Is_Entry_Declaration
(Id
: Entity_Id
) return Boolean is
13435 Ekind_In
(Id
, E_Entry
, E_Entry_Family
)
13436 and then Nkind
(Unit_Declaration_Node
(Id
)) = N_Entry_Declaration
;
13437 end Is_Entry_Declaration
;
13439 ------------------------------------
13440 -- Is_Expanded_Priority_Attribute --
13441 ------------------------------------
13443 function Is_Expanded_Priority_Attribute
(E
: Entity_Id
) return Boolean is
13446 Nkind
(E
) = N_Function_Call
13447 and then not Configurable_Run_Time_Mode
13448 and then (Entity
(Name
(E
)) = RTE
(RE_Get_Ceiling
)
13449 or else Entity
(Name
(E
)) = RTE
(RO_PE_Get_Ceiling
));
13450 end Is_Expanded_Priority_Attribute
;
13452 ----------------------------
13453 -- Is_Expression_Function --
13454 ----------------------------
13456 function Is_Expression_Function
(Subp
: Entity_Id
) return Boolean is
13458 if Ekind_In
(Subp
, E_Function
, E_Subprogram_Body
) then
13460 Nkind
(Original_Node
(Unit_Declaration_Node
(Subp
))) =
13461 N_Expression_Function
;
13465 end Is_Expression_Function
;
13467 ------------------------------------------
13468 -- Is_Expression_Function_Or_Completion --
13469 ------------------------------------------
13471 function Is_Expression_Function_Or_Completion
13472 (Subp
: Entity_Id
) return Boolean
13474 Subp_Decl
: Node_Id
;
13477 if Ekind
(Subp
) = E_Function
then
13478 Subp_Decl
:= Unit_Declaration_Node
(Subp
);
13480 -- The function declaration is either an expression function or is
13481 -- completed by an expression function body.
13484 Is_Expression_Function
(Subp
)
13485 or else (Nkind
(Subp_Decl
) = N_Subprogram_Declaration
13486 and then Present
(Corresponding_Body
(Subp_Decl
))
13487 and then Is_Expression_Function
13488 (Corresponding_Body
(Subp_Decl
)));
13490 elsif Ekind
(Subp
) = E_Subprogram_Body
then
13491 return Is_Expression_Function
(Subp
);
13496 end Is_Expression_Function_Or_Completion
;
13498 -----------------------
13499 -- Is_EVF_Expression --
13500 -----------------------
13502 function Is_EVF_Expression
(N
: Node_Id
) return Boolean is
13503 Orig_N
: constant Node_Id
:= Original_Node
(N
);
13509 -- Detect a reference to a formal parameter of a specific tagged type
13510 -- whose related subprogram is subject to pragma Expresions_Visible with
13513 if Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
13518 and then Is_Specific_Tagged_Type
(Etype
(Id
))
13519 and then Extensions_Visible_Status
(Id
) =
13520 Extensions_Visible_False
;
13522 -- A case expression is an EVF expression when it contains at least one
13523 -- EVF dependent_expression. Note that a case expression may have been
13524 -- expanded, hence the use of Original_Node.
13526 elsif Nkind
(Orig_N
) = N_Case_Expression
then
13527 Alt
:= First
(Alternatives
(Orig_N
));
13528 while Present
(Alt
) loop
13529 if Is_EVF_Expression
(Expression
(Alt
)) then
13536 -- An if expression is an EVF expression when it contains at least one
13537 -- EVF dependent_expression. Note that an if expression may have been
13538 -- expanded, hence the use of Original_Node.
13540 elsif Nkind
(Orig_N
) = N_If_Expression
then
13541 Expr
:= Next
(First
(Expressions
(Orig_N
)));
13542 while Present
(Expr
) loop
13543 if Is_EVF_Expression
(Expr
) then
13550 -- A qualified expression or a type conversion is an EVF expression when
13551 -- its operand is an EVF expression.
13553 elsif Nkind_In
(N
, N_Qualified_Expression
,
13554 N_Unchecked_Type_Conversion
,
13557 return Is_EVF_Expression
(Expression
(N
));
13559 -- Attributes 'Loop_Entry, 'Old, and 'Update are EVF expressions when
13560 -- their prefix denotes an EVF expression.
13562 elsif Nkind
(N
) = N_Attribute_Reference
13563 and then Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
13567 return Is_EVF_Expression
(Prefix
(N
));
13571 end Is_EVF_Expression
;
13577 function Is_False
(U
: Uint
) return Boolean is
13582 ---------------------------
13583 -- Is_Fixed_Model_Number --
13584 ---------------------------
13586 function Is_Fixed_Model_Number
(U
: Ureal
; T
: Entity_Id
) return Boolean is
13587 S
: constant Ureal
:= Small_Value
(T
);
13588 M
: Urealp
.Save_Mark
;
13593 R
:= (U
= UR_Trunc
(U
/ S
) * S
);
13594 Urealp
.Release
(M
);
13596 end Is_Fixed_Model_Number
;
13598 -------------------------------
13599 -- Is_Fully_Initialized_Type --
13600 -------------------------------
13602 function Is_Fully_Initialized_Type
(Typ
: Entity_Id
) return Boolean is
13606 if Is_Scalar_Type
(Typ
) then
13608 -- A scalar type with an aspect Default_Value is fully initialized
13610 -- Note: Iniitalize/Normalize_Scalars also ensure full initialization
13611 -- of a scalar type, but we don't take that into account here, since
13612 -- we don't want these to affect warnings.
13614 return Has_Default_Aspect
(Typ
);
13616 elsif Is_Access_Type
(Typ
) then
13619 elsif Is_Array_Type
(Typ
) then
13620 if Is_Fully_Initialized_Type
(Component_Type
(Typ
))
13621 or else (Ada_Version
>= Ada_2012
and then Has_Default_Aspect
(Typ
))
13626 -- An interesting case, if we have a constrained type one of whose
13627 -- bounds is known to be null, then there are no elements to be
13628 -- initialized, so all the elements are initialized.
13630 if Is_Constrained
(Typ
) then
13633 Indx_Typ
: Entity_Id
;
13634 Lbd
, Hbd
: Node_Id
;
13637 Indx
:= First_Index
(Typ
);
13638 while Present
(Indx
) loop
13639 if Etype
(Indx
) = Any_Type
then
13642 -- If index is a range, use directly
13644 elsif Nkind
(Indx
) = N_Range
then
13645 Lbd
:= Low_Bound
(Indx
);
13646 Hbd
:= High_Bound
(Indx
);
13649 Indx_Typ
:= Etype
(Indx
);
13651 if Is_Private_Type
(Indx_Typ
) then
13652 Indx_Typ
:= Full_View
(Indx_Typ
);
13655 if No
(Indx_Typ
) or else Etype
(Indx_Typ
) = Any_Type
then
13658 Lbd
:= Type_Low_Bound
(Indx_Typ
);
13659 Hbd
:= Type_High_Bound
(Indx_Typ
);
13663 if Compile_Time_Known_Value
(Lbd
)
13665 Compile_Time_Known_Value
(Hbd
)
13667 if Expr_Value
(Hbd
) < Expr_Value
(Lbd
) then
13677 -- If no null indexes, then type is not fully initialized
13683 elsif Is_Record_Type
(Typ
) then
13684 if Has_Discriminants
(Typ
)
13686 Present
(Discriminant_Default_Value
(First_Discriminant
(Typ
)))
13687 and then Is_Fully_Initialized_Variant
(Typ
)
13692 -- We consider bounded string types to be fully initialized, because
13693 -- otherwise we get false alarms when the Data component is not
13694 -- default-initialized.
13696 if Is_Bounded_String
(Typ
) then
13700 -- Controlled records are considered to be fully initialized if
13701 -- there is a user defined Initialize routine. This may not be
13702 -- entirely correct, but as the spec notes, we are guessing here
13703 -- what is best from the point of view of issuing warnings.
13705 if Is_Controlled
(Typ
) then
13707 Utyp
: constant Entity_Id
:= Underlying_Type
(Typ
);
13710 if Present
(Utyp
) then
13712 Init
: constant Entity_Id
:=
13713 (Find_Optional_Prim_Op
13714 (Underlying_Type
(Typ
), Name_Initialize
));
13718 and then Comes_From_Source
(Init
)
13719 and then not In_Predefined_Unit
(Init
)
13723 elsif Has_Null_Extension
(Typ
)
13725 Is_Fully_Initialized_Type
13726 (Etype
(Base_Type
(Typ
)))
13735 -- Otherwise see if all record components are initialized
13741 Ent
:= First_Entity
(Typ
);
13742 while Present
(Ent
) loop
13743 if Ekind
(Ent
) = E_Component
13744 and then (No
(Parent
(Ent
))
13745 or else No
(Expression
(Parent
(Ent
))))
13746 and then not Is_Fully_Initialized_Type
(Etype
(Ent
))
13748 -- Special VM case for tag components, which need to be
13749 -- defined in this case, but are never initialized as VMs
13750 -- are using other dispatching mechanisms. Ignore this
13751 -- uninitialized case. Note that this applies both to the
13752 -- uTag entry and the main vtable pointer (CPP_Class case).
13754 and then (Tagged_Type_Expansion
or else not Is_Tag
(Ent
))
13763 -- No uninitialized components, so type is fully initialized.
13764 -- Note that this catches the case of no components as well.
13768 elsif Is_Concurrent_Type
(Typ
) then
13771 elsif Is_Private_Type
(Typ
) then
13773 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
13779 return Is_Fully_Initialized_Type
(U
);
13786 end Is_Fully_Initialized_Type
;
13788 ----------------------------------
13789 -- Is_Fully_Initialized_Variant --
13790 ----------------------------------
13792 function Is_Fully_Initialized_Variant
(Typ
: Entity_Id
) return Boolean is
13793 Loc
: constant Source_Ptr
:= Sloc
(Typ
);
13794 Constraints
: constant List_Id
:= New_List
;
13795 Components
: constant Elist_Id
:= New_Elmt_List
;
13796 Comp_Elmt
: Elmt_Id
;
13798 Comp_List
: Node_Id
;
13800 Discr_Val
: Node_Id
;
13802 Report_Errors
: Boolean;
13803 pragma Warnings
(Off
, Report_Errors
);
13806 if Serious_Errors_Detected
> 0 then
13810 if Is_Record_Type
(Typ
)
13811 and then Nkind
(Parent
(Typ
)) = N_Full_Type_Declaration
13812 and then Nkind
(Type_Definition
(Parent
(Typ
))) = N_Record_Definition
13814 Comp_List
:= Component_List
(Type_Definition
(Parent
(Typ
)));
13816 Discr
:= First_Discriminant
(Typ
);
13817 while Present
(Discr
) loop
13818 if Nkind
(Parent
(Discr
)) = N_Discriminant_Specification
then
13819 Discr_Val
:= Expression
(Parent
(Discr
));
13821 if Present
(Discr_Val
)
13822 and then Is_OK_Static_Expression
(Discr_Val
)
13824 Append_To
(Constraints
,
13825 Make_Component_Association
(Loc
,
13826 Choices
=> New_List
(New_Occurrence_Of
(Discr
, Loc
)),
13827 Expression
=> New_Copy
(Discr_Val
)));
13835 Next_Discriminant
(Discr
);
13840 Comp_List
=> Comp_List
,
13841 Governed_By
=> Constraints
,
13842 Into
=> Components
,
13843 Report_Errors
=> Report_Errors
);
13845 -- Check that each component present is fully initialized
13847 Comp_Elmt
:= First_Elmt
(Components
);
13848 while Present
(Comp_Elmt
) loop
13849 Comp_Id
:= Node
(Comp_Elmt
);
13851 if Ekind
(Comp_Id
) = E_Component
13852 and then (No
(Parent
(Comp_Id
))
13853 or else No
(Expression
(Parent
(Comp_Id
))))
13854 and then not Is_Fully_Initialized_Type
(Etype
(Comp_Id
))
13859 Next_Elmt
(Comp_Elmt
);
13864 elsif Is_Private_Type
(Typ
) then
13866 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
13872 return Is_Fully_Initialized_Variant
(U
);
13879 end Is_Fully_Initialized_Variant
;
13881 ------------------------------------
13882 -- Is_Generic_Declaration_Or_Body --
13883 ------------------------------------
13885 function Is_Generic_Declaration_Or_Body
(Decl
: Node_Id
) return Boolean is
13886 Spec_Decl
: Node_Id
;
13889 -- Package/subprogram body
13891 if Nkind_In
(Decl
, N_Package_Body
, N_Subprogram_Body
)
13892 and then Present
(Corresponding_Spec
(Decl
))
13894 Spec_Decl
:= Unit_Declaration_Node
(Corresponding_Spec
(Decl
));
13896 -- Package/subprogram body stub
13898 elsif Nkind_In
(Decl
, N_Package_Body_Stub
, N_Subprogram_Body_Stub
)
13899 and then Present
(Corresponding_Spec_Of_Stub
(Decl
))
13902 Unit_Declaration_Node
(Corresponding_Spec_Of_Stub
(Decl
));
13910 -- Rather than inspecting the defining entity of the spec declaration,
13911 -- look at its Nkind. This takes care of the case where the analysis of
13912 -- a generic body modifies the Ekind of its spec to allow for recursive
13916 Nkind_In
(Spec_Decl
, N_Generic_Package_Declaration
,
13917 N_Generic_Subprogram_Declaration
);
13918 end Is_Generic_Declaration_Or_Body
;
13920 ----------------------------
13921 -- Is_Inherited_Operation --
13922 ----------------------------
13924 function Is_Inherited_Operation
(E
: Entity_Id
) return Boolean is
13925 pragma Assert
(Is_Overloadable
(E
));
13926 Kind
: constant Node_Kind
:= Nkind
(Parent
(E
));
13928 return Kind
= N_Full_Type_Declaration
13929 or else Kind
= N_Private_Extension_Declaration
13930 or else Kind
= N_Subtype_Declaration
13931 or else (Ekind
(E
) = E_Enumeration_Literal
13932 and then Is_Derived_Type
(Etype
(E
)));
13933 end Is_Inherited_Operation
;
13935 -------------------------------------
13936 -- Is_Inherited_Operation_For_Type --
13937 -------------------------------------
13939 function Is_Inherited_Operation_For_Type
13941 Typ
: Entity_Id
) return Boolean
13944 -- Check that the operation has been created by the type declaration
13946 return Is_Inherited_Operation
(E
)
13947 and then Defining_Identifier
(Parent
(E
)) = Typ
;
13948 end Is_Inherited_Operation_For_Type
;
13950 --------------------------------------
13951 -- Is_Inlinable_Expression_Function --
13952 --------------------------------------
13954 function Is_Inlinable_Expression_Function
13955 (Subp
: Entity_Id
) return Boolean
13957 Return_Expr
: Node_Id
;
13960 if Is_Expression_Function_Or_Completion
(Subp
)
13961 and then Has_Pragma_Inline_Always
(Subp
)
13962 and then Needs_No_Actuals
(Subp
)
13963 and then No
(Contract
(Subp
))
13964 and then not Is_Dispatching_Operation
(Subp
)
13965 and then Needs_Finalization
(Etype
(Subp
))
13966 and then not Is_Class_Wide_Type
(Etype
(Subp
))
13967 and then not (Has_Invariants
(Etype
(Subp
)))
13968 and then Present
(Subprogram_Body
(Subp
))
13969 and then Was_Expression_Function
(Subprogram_Body
(Subp
))
13971 Return_Expr
:= Expression_Of_Expression_Function
(Subp
);
13973 -- The returned object must not have a qualified expression and its
13974 -- nominal subtype must be statically compatible with the result
13975 -- subtype of the expression function.
13978 Nkind
(Return_Expr
) = N_Identifier
13979 and then Etype
(Return_Expr
) = Etype
(Subp
);
13983 end Is_Inlinable_Expression_Function
;
13989 function Is_Iterator
(Typ
: Entity_Id
) return Boolean is
13990 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean;
13991 -- Determine whether type Iter_Typ is a predefined forward or reversible
13994 ----------------------
13995 -- Denotes_Iterator --
13996 ----------------------
13998 function Denotes_Iterator
(Iter_Typ
: Entity_Id
) return Boolean is
14000 -- Check that the name matches, and that the ultimate ancestor is in
14001 -- a predefined unit, i.e the one that declares iterator interfaces.
14004 Nam_In
(Chars
(Iter_Typ
), Name_Forward_Iterator
,
14005 Name_Reversible_Iterator
)
14006 and then In_Predefined_Unit
(Root_Type
(Iter_Typ
));
14007 end Denotes_Iterator
;
14011 Iface_Elmt
: Elmt_Id
;
14014 -- Start of processing for Is_Iterator
14017 -- The type may be a subtype of a descendant of the proper instance of
14018 -- the predefined interface type, so we must use the root type of the
14019 -- given type. The same is done for Is_Reversible_Iterator.
14021 if Is_Class_Wide_Type
(Typ
)
14022 and then Denotes_Iterator
(Root_Type
(Typ
))
14026 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
14029 elsif Present
(Find_Value_Of_Aspect
(Typ
, Aspect_Iterable
)) then
14033 Collect_Interfaces
(Typ
, Ifaces
);
14035 Iface_Elmt
:= First_Elmt
(Ifaces
);
14036 while Present
(Iface_Elmt
) loop
14037 if Denotes_Iterator
(Node
(Iface_Elmt
)) then
14041 Next_Elmt
(Iface_Elmt
);
14048 ----------------------------
14049 -- Is_Iterator_Over_Array --
14050 ----------------------------
14052 function Is_Iterator_Over_Array
(N
: Node_Id
) return Boolean is
14053 Container
: constant Node_Id
:= Name
(N
);
14054 Container_Typ
: constant Entity_Id
:= Base_Type
(Etype
(Container
));
14056 return Is_Array_Type
(Container_Typ
);
14057 end Is_Iterator_Over_Array
;
14063 -- We seem to have a lot of overlapping functions that do similar things
14064 -- (testing for left hand sides or lvalues???).
14066 function Is_LHS
(N
: Node_Id
) return Is_LHS_Result
is
14067 P
: constant Node_Id
:= Parent
(N
);
14070 -- Return True if we are the left hand side of an assignment statement
14072 if Nkind
(P
) = N_Assignment_Statement
then
14073 if Name
(P
) = N
then
14079 -- Case of prefix of indexed or selected component or slice
14081 elsif Nkind_In
(P
, N_Indexed_Component
, N_Selected_Component
, N_Slice
)
14082 and then N
= Prefix
(P
)
14084 -- Here we have the case where the parent P is N.Q or N(Q .. R).
14085 -- If P is an LHS, then N is also effectively an LHS, but there
14086 -- is an important exception. If N is of an access type, then
14087 -- what we really have is N.all.Q (or N.all(Q .. R)). In either
14088 -- case this makes N.all a left hand side but not N itself.
14090 -- If we don't know the type yet, this is the case where we return
14091 -- Unknown, since the answer depends on the type which is unknown.
14093 if No
(Etype
(N
)) then
14096 -- We have an Etype set, so we can check it
14098 elsif Is_Access_Type
(Etype
(N
)) then
14101 -- OK, not access type case, so just test whole expression
14107 -- All other cases are not left hand sides
14114 -----------------------------
14115 -- Is_Library_Level_Entity --
14116 -----------------------------
14118 function Is_Library_Level_Entity
(E
: Entity_Id
) return Boolean is
14120 -- The following is a small optimization, and it also properly handles
14121 -- discriminals, which in task bodies might appear in expressions before
14122 -- the corresponding procedure has been created, and which therefore do
14123 -- not have an assigned scope.
14125 if Is_Formal
(E
) then
14129 -- Normal test is simply that the enclosing dynamic scope is Standard
14131 return Enclosing_Dynamic_Scope
(E
) = Standard_Standard
;
14132 end Is_Library_Level_Entity
;
14134 --------------------------------
14135 -- Is_Limited_Class_Wide_Type --
14136 --------------------------------
14138 function Is_Limited_Class_Wide_Type
(Typ
: Entity_Id
) return Boolean is
14141 Is_Class_Wide_Type
(Typ
)
14142 and then (Is_Limited_Type
(Typ
) or else From_Limited_With
(Typ
));
14143 end Is_Limited_Class_Wide_Type
;
14145 ---------------------------------
14146 -- Is_Local_Variable_Reference --
14147 ---------------------------------
14149 function Is_Local_Variable_Reference
(Expr
: Node_Id
) return Boolean is
14151 if not Is_Entity_Name
(Expr
) then
14156 Ent
: constant Entity_Id
:= Entity
(Expr
);
14157 Sub
: constant Entity_Id
:= Enclosing_Subprogram
(Ent
);
14159 if not Ekind_In
(Ent
, E_Variable
, E_In_Out_Parameter
) then
14162 return Present
(Sub
) and then Sub
= Current_Subprogram
;
14166 end Is_Local_Variable_Reference
;
14168 -----------------------
14169 -- Is_Name_Reference --
14170 -----------------------
14172 function Is_Name_Reference
(N
: Node_Id
) return Boolean is
14174 if Is_Entity_Name
(N
) then
14175 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
14179 when N_Indexed_Component
14183 Is_Name_Reference
(Prefix
(N
))
14184 or else Is_Access_Type
(Etype
(Prefix
(N
)));
14186 -- Attributes 'Input, 'Old and 'Result produce objects
14188 when N_Attribute_Reference
=>
14190 Nam_In
(Attribute_Name
(N
), Name_Input
, Name_Old
, Name_Result
);
14192 when N_Selected_Component
=>
14194 Is_Name_Reference
(Selector_Name
(N
))
14196 (Is_Name_Reference
(Prefix
(N
))
14197 or else Is_Access_Type
(Etype
(Prefix
(N
))));
14199 when N_Explicit_Dereference
=>
14202 -- A view conversion of a tagged name is a name reference
14204 when N_Type_Conversion
=>
14206 Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
14207 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
14208 and then Is_Name_Reference
(Expression
(N
));
14210 -- An unchecked type conversion is considered to be a name if the
14211 -- operand is a name (this construction arises only as a result of
14212 -- expansion activities).
14214 when N_Unchecked_Type_Conversion
=>
14215 return Is_Name_Reference
(Expression
(N
));
14220 end Is_Name_Reference
;
14222 ---------------------------------
14223 -- Is_Nontrivial_DIC_Procedure --
14224 ---------------------------------
14226 function Is_Nontrivial_DIC_Procedure
(Id
: Entity_Id
) return Boolean is
14227 Body_Decl
: Node_Id
;
14231 if Ekind
(Id
) = E_Procedure
and then Is_DIC_Procedure
(Id
) then
14233 Unit_Declaration_Node
14234 (Corresponding_Body
(Unit_Declaration_Node
(Id
)));
14236 -- The body of the Default_Initial_Condition procedure must contain
14237 -- at least one statement, otherwise the generation of the subprogram
14240 pragma Assert
(Present
(Handled_Statement_Sequence
(Body_Decl
)));
14242 -- To qualify as nontrivial, the first statement of the procedure
14243 -- must be a check in the form of an if statement. If the original
14244 -- Default_Initial_Condition expression was folded, then the first
14245 -- statement is not a check.
14247 Stmt
:= First
(Statements
(Handled_Statement_Sequence
(Body_Decl
)));
14250 Nkind
(Stmt
) = N_If_Statement
14251 and then Nkind
(Original_Node
(Stmt
)) = N_Pragma
;
14255 end Is_Nontrivial_DIC_Procedure
;
14257 -------------------------
14258 -- Is_Null_Record_Type --
14259 -------------------------
14261 function Is_Null_Record_Type
(T
: Entity_Id
) return Boolean is
14262 Decl
: constant Node_Id
:= Parent
(T
);
14264 return Nkind
(Decl
) = N_Full_Type_Declaration
14265 and then Nkind
(Type_Definition
(Decl
)) = N_Record_Definition
14267 (No
(Component_List
(Type_Definition
(Decl
)))
14268 or else Null_Present
(Component_List
(Type_Definition
(Decl
))));
14269 end Is_Null_Record_Type
;
14271 ---------------------
14272 -- Is_Object_Image --
14273 ---------------------
14275 function Is_Object_Image
(Prefix
: Node_Id
) return Boolean is
14277 -- When the type of the prefix is not scalar, then the prefix is not
14278 -- valid in any scenario.
14280 if not Is_Scalar_Type
(Etype
(Prefix
)) then
14284 -- Here we test for the case that the prefix is not a type and assume
14285 -- if it is not then it must be a named value or an object reference.
14286 -- This is because the parser always checks that prefixes of attributes
14289 return not (Is_Entity_Name
(Prefix
) and then Is_Type
(Entity
(Prefix
)));
14290 end Is_Object_Image
;
14292 -------------------------
14293 -- Is_Object_Reference --
14294 -------------------------
14296 function Is_Object_Reference
(N
: Node_Id
) return Boolean is
14297 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean;
14298 -- Determine whether N is the name of an internally-generated renaming
14300 --------------------------------------
14301 -- Is_Internally_Generated_Renaming --
14302 --------------------------------------
14304 function Is_Internally_Generated_Renaming
(N
: Node_Id
) return Boolean is
14309 while Present
(P
) loop
14310 if Nkind
(P
) = N_Object_Renaming_Declaration
then
14311 return not Comes_From_Source
(P
);
14312 elsif Is_List_Member
(P
) then
14320 end Is_Internally_Generated_Renaming
;
14322 -- Start of processing for Is_Object_Reference
14325 if Is_Entity_Name
(N
) then
14326 return Present
(Entity
(N
)) and then Is_Object
(Entity
(N
));
14330 when N_Indexed_Component
14334 Is_Object_Reference
(Prefix
(N
))
14335 or else Is_Access_Type
(Etype
(Prefix
(N
)));
14337 -- In Ada 95, a function call is a constant object; a procedure
14340 -- Note that predefined operators are functions as well, and so
14341 -- are attributes that are (can be renamed as) functions.
14347 return Etype
(N
) /= Standard_Void_Type
;
14349 -- Attributes references 'Loop_Entry, 'Old, and 'Result yield
14350 -- objects, even though they are not functions.
14352 when N_Attribute_Reference
=>
14354 Nam_In
(Attribute_Name
(N
), Name_Loop_Entry
,
14357 or else Is_Function_Attribute_Name
(Attribute_Name
(N
));
14359 when N_Selected_Component
=>
14361 Is_Object_Reference
(Selector_Name
(N
))
14363 (Is_Object_Reference
(Prefix
(N
))
14364 or else Is_Access_Type
(Etype
(Prefix
(N
))));
14366 -- An explicit dereference denotes an object, except that a
14367 -- conditional expression gets turned into an explicit dereference
14368 -- in some cases, and conditional expressions are not object
14371 when N_Explicit_Dereference
=>
14372 return not Nkind_In
(Original_Node
(N
), N_Case_Expression
,
14375 -- A view conversion of a tagged object is an object reference
14377 when N_Type_Conversion
=>
14378 return Is_Tagged_Type
(Etype
(Subtype_Mark
(N
)))
14379 and then Is_Tagged_Type
(Etype
(Expression
(N
)))
14380 and then Is_Object_Reference
(Expression
(N
));
14382 -- An unchecked type conversion is considered to be an object if
14383 -- the operand is an object (this construction arises only as a
14384 -- result of expansion activities).
14386 when N_Unchecked_Type_Conversion
=>
14389 -- Allow string literals to act as objects as long as they appear
14390 -- in internally-generated renamings. The expansion of iterators
14391 -- may generate such renamings when the range involves a string
14394 when N_String_Literal
=>
14395 return Is_Internally_Generated_Renaming
(Parent
(N
));
14397 -- AI05-0003: In Ada 2012 a qualified expression is a name.
14398 -- This allows disambiguation of function calls and the use
14399 -- of aggregates in more contexts.
14401 when N_Qualified_Expression
=>
14402 if Ada_Version
< Ada_2012
then
14405 return Is_Object_Reference
(Expression
(N
))
14406 or else Nkind
(Expression
(N
)) = N_Aggregate
;
14413 end Is_Object_Reference
;
14415 -----------------------------------
14416 -- Is_OK_Variable_For_Out_Formal --
14417 -----------------------------------
14419 function Is_OK_Variable_For_Out_Formal
(AV
: Node_Id
) return Boolean is
14421 Note_Possible_Modification
(AV
, Sure
=> True);
14423 -- We must reject parenthesized variable names. Comes_From_Source is
14424 -- checked because there are currently cases where the compiler violates
14425 -- this rule (e.g. passing a task object to its controlled Initialize
14426 -- routine). This should be properly documented in sinfo???
14428 if Paren_Count
(AV
) > 0 and then Comes_From_Source
(AV
) then
14431 -- A variable is always allowed
14433 elsif Is_Variable
(AV
) then
14436 -- Generalized indexing operations are rewritten as explicit
14437 -- dereferences, and it is only during resolution that we can
14438 -- check whether the context requires an access_to_variable type.
14440 elsif Nkind
(AV
) = N_Explicit_Dereference
14441 and then Ada_Version
>= Ada_2012
14442 and then Nkind
(Original_Node
(AV
)) = N_Indexed_Component
14443 and then Present
(Etype
(Original_Node
(AV
)))
14444 and then Has_Implicit_Dereference
(Etype
(Original_Node
(AV
)))
14446 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
14448 -- Unchecked conversions are allowed only if they come from the
14449 -- generated code, which sometimes uses unchecked conversions for out
14450 -- parameters in cases where code generation is unaffected. We tell
14451 -- source unchecked conversions by seeing if they are rewrites of
14452 -- an original Unchecked_Conversion function call, or of an explicit
14453 -- conversion of a function call or an aggregate (as may happen in the
14454 -- expansion of a packed array aggregate).
14456 elsif Nkind
(AV
) = N_Unchecked_Type_Conversion
then
14457 if Nkind_In
(Original_Node
(AV
), N_Function_Call
, N_Aggregate
) then
14460 elsif Comes_From_Source
(AV
)
14461 and then Nkind
(Original_Node
(Expression
(AV
))) = N_Function_Call
14465 elsif Nkind
(Original_Node
(AV
)) = N_Type_Conversion
then
14466 return Is_OK_Variable_For_Out_Formal
(Expression
(AV
));
14472 -- Normal type conversions are allowed if argument is a variable
14474 elsif Nkind
(AV
) = N_Type_Conversion
then
14475 if Is_Variable
(Expression
(AV
))
14476 and then Paren_Count
(Expression
(AV
)) = 0
14478 Note_Possible_Modification
(Expression
(AV
), Sure
=> True);
14481 -- We also allow a non-parenthesized expression that raises
14482 -- constraint error if it rewrites what used to be a variable
14484 elsif Raises_Constraint_Error
(Expression
(AV
))
14485 and then Paren_Count
(Expression
(AV
)) = 0
14486 and then Is_Variable
(Original_Node
(Expression
(AV
)))
14490 -- Type conversion of something other than a variable
14496 -- If this node is rewritten, then test the original form, if that is
14497 -- OK, then we consider the rewritten node OK (for example, if the
14498 -- original node is a conversion, then Is_Variable will not be true
14499 -- but we still want to allow the conversion if it converts a variable).
14501 elsif Original_Node
(AV
) /= AV
then
14503 -- In Ada 2012, the explicit dereference may be a rewritten call to a
14504 -- Reference function.
14506 if Ada_Version
>= Ada_2012
14507 and then Nkind
(Original_Node
(AV
)) = N_Function_Call
14509 Has_Implicit_Dereference
(Etype
(Name
(Original_Node
(AV
))))
14512 -- Check that this is not a constant reference.
14514 return not Is_Access_Constant
(Etype
(Prefix
(AV
)));
14516 elsif Has_Implicit_Dereference
(Etype
(Original_Node
(AV
))) then
14518 not Is_Access_Constant
(Etype
14519 (Get_Reference_Discriminant
(Etype
(Original_Node
(AV
)))));
14522 return Is_OK_Variable_For_Out_Formal
(Original_Node
(AV
));
14525 -- All other non-variables are rejected
14530 end Is_OK_Variable_For_Out_Formal
;
14532 ----------------------------
14533 -- Is_OK_Volatile_Context --
14534 ----------------------------
14536 function Is_OK_Volatile_Context
14537 (Context
: Node_Id
;
14538 Obj_Ref
: Node_Id
) return Boolean
14540 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean;
14541 -- Determine whether an arbitrary node denotes a call to a protected
14542 -- entry, function, or procedure in prefixed form where the prefix is
14545 function Within_Check
(Nod
: Node_Id
) return Boolean;
14546 -- Determine whether an arbitrary node appears in a check node
14548 function Within_Subprogram_Call
(Nod
: Node_Id
) return Boolean;
14549 -- Determine whether an arbitrary node appears in an entry, function, or
14552 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean;
14553 -- Determine whether an arbitrary entity appears in a volatile function
14555 ---------------------------------
14556 -- Is_Protected_Operation_Call --
14557 ---------------------------------
14559 function Is_Protected_Operation_Call
(Nod
: Node_Id
) return Boolean is
14564 -- A call to a protected operations retains its selected component
14565 -- form as opposed to other prefixed calls that are transformed in
14568 if Nkind
(Nod
) = N_Selected_Component
then
14569 Pref
:= Prefix
(Nod
);
14570 Subp
:= Selector_Name
(Nod
);
14574 and then Present
(Etype
(Pref
))
14575 and then Is_Protected_Type
(Etype
(Pref
))
14576 and then Is_Entity_Name
(Subp
)
14577 and then Present
(Entity
(Subp
))
14578 and then Ekind_In
(Entity
(Subp
), E_Entry
,
14585 end Is_Protected_Operation_Call
;
14591 function Within_Check
(Nod
: Node_Id
) return Boolean is
14595 -- Climb the parent chain looking for a check node
14598 while Present
(Par
) loop
14599 if Nkind
(Par
) in N_Raise_xxx_Error
then
14602 -- Prevent the search from going too far
14604 elsif Is_Body_Or_Package_Declaration
(Par
) then
14608 Par
:= Parent
(Par
);
14614 ----------------------------
14615 -- Within_Subprogram_Call --
14616 ----------------------------
14618 function Within_Subprogram_Call
(Nod
: Node_Id
) return Boolean is
14622 -- Climb the parent chain looking for a function or procedure call
14625 while Present
(Par
) loop
14626 if Nkind_In
(Par
, N_Entry_Call_Statement
,
14628 N_Procedure_Call_Statement
)
14632 -- Prevent the search from going too far
14634 elsif Is_Body_Or_Package_Declaration
(Par
) then
14638 Par
:= Parent
(Par
);
14642 end Within_Subprogram_Call
;
14644 ------------------------------
14645 -- Within_Volatile_Function --
14646 ------------------------------
14648 function Within_Volatile_Function
(Id
: Entity_Id
) return Boolean is
14649 Func_Id
: Entity_Id
;
14652 -- Traverse the scope stack looking for a [generic] function
14655 while Present
(Func_Id
) and then Func_Id
/= Standard_Standard
loop
14656 if Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
) then
14657 return Is_Volatile_Function
(Func_Id
);
14660 Func_Id
:= Scope
(Func_Id
);
14664 end Within_Volatile_Function
;
14668 Obj_Id
: Entity_Id
;
14670 -- Start of processing for Is_OK_Volatile_Context
14673 -- The volatile object appears on either side of an assignment
14675 if Nkind
(Context
) = N_Assignment_Statement
then
14678 -- The volatile object is part of the initialization expression of
14681 elsif Nkind
(Context
) = N_Object_Declaration
14682 and then Present
(Expression
(Context
))
14683 and then Expression
(Context
) = Obj_Ref
14685 Obj_Id
:= Defining_Entity
(Context
);
14687 -- The volatile object acts as the initialization expression of an
14688 -- extended return statement. This is valid context as long as the
14689 -- function is volatile.
14691 if Is_Return_Object
(Obj_Id
) then
14692 return Within_Volatile_Function
(Obj_Id
);
14694 -- Otherwise this is a normal object initialization
14700 -- The volatile object acts as the name of a renaming declaration
14702 elsif Nkind
(Context
) = N_Object_Renaming_Declaration
14703 and then Name
(Context
) = Obj_Ref
14707 -- The volatile object appears as an actual parameter in a call to an
14708 -- instance of Unchecked_Conversion whose result is renamed.
14710 elsif Nkind
(Context
) = N_Function_Call
14711 and then Is_Entity_Name
(Name
(Context
))
14712 and then Is_Unchecked_Conversion_Instance
(Entity
(Name
(Context
)))
14713 and then Nkind
(Parent
(Context
)) = N_Object_Renaming_Declaration
14717 -- The volatile object is actually the prefix in a protected entry,
14718 -- function, or procedure call.
14720 elsif Is_Protected_Operation_Call
(Context
) then
14723 -- The volatile object appears as the expression of a simple return
14724 -- statement that applies to a volatile function.
14726 elsif Nkind
(Context
) = N_Simple_Return_Statement
14727 and then Expression
(Context
) = Obj_Ref
14730 Within_Volatile_Function
(Return_Statement_Entity
(Context
));
14732 -- The volatile object appears as the prefix of a name occurring in a
14733 -- non-interfering context.
14735 elsif Nkind_In
(Context
, N_Attribute_Reference
,
14736 N_Explicit_Dereference
,
14737 N_Indexed_Component
,
14738 N_Selected_Component
,
14740 and then Prefix
(Context
) = Obj_Ref
14741 and then Is_OK_Volatile_Context
14742 (Context
=> Parent
(Context
),
14743 Obj_Ref
=> Context
)
14747 -- The volatile object appears as the prefix of attributes Address,
14748 -- Alignment, Component_Size, First_Bit, Last_Bit, Position, Size,
14751 elsif Nkind
(Context
) = N_Attribute_Reference
14752 and then Prefix
(Context
) = Obj_Ref
14753 and then Nam_In
(Attribute_Name
(Context
), Name_Address
,
14755 Name_Component_Size
,
14764 -- The volatile object appears as the expression of a type conversion
14765 -- occurring in a non-interfering context.
14767 elsif Nkind_In
(Context
, N_Type_Conversion
,
14768 N_Unchecked_Type_Conversion
)
14769 and then Expression
(Context
) = Obj_Ref
14770 and then Is_OK_Volatile_Context
14771 (Context
=> Parent
(Context
),
14772 Obj_Ref
=> Context
)
14776 -- The volatile object appears as the expression in a delay statement
14778 elsif Nkind
(Context
) in N_Delay_Statement
then
14781 -- Allow references to volatile objects in various checks. This is not a
14782 -- direct SPARK 2014 requirement.
14784 elsif Within_Check
(Context
) then
14787 -- Assume that references to effectively volatile objects that appear
14788 -- as actual parameters in a subprogram call are always legal. A full
14789 -- legality check is done when the actuals are resolved (see routine
14790 -- Resolve_Actuals).
14792 elsif Within_Subprogram_Call
(Context
) then
14795 -- Otherwise the context is not suitable for an effectively volatile
14801 end Is_OK_Volatile_Context
;
14803 ------------------------------------
14804 -- Is_Package_Contract_Annotation --
14805 ------------------------------------
14807 function Is_Package_Contract_Annotation
(Item
: Node_Id
) return Boolean is
14811 if Nkind
(Item
) = N_Aspect_Specification
then
14812 Nam
:= Chars
(Identifier
(Item
));
14814 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
14815 Nam
:= Pragma_Name
(Item
);
14818 return Nam
= Name_Abstract_State
14819 or else Nam
= Name_Initial_Condition
14820 or else Nam
= Name_Initializes
14821 or else Nam
= Name_Refined_State
;
14822 end Is_Package_Contract_Annotation
;
14824 -----------------------------------
14825 -- Is_Partially_Initialized_Type --
14826 -----------------------------------
14828 function Is_Partially_Initialized_Type
14830 Include_Implicit
: Boolean := True) return Boolean
14833 if Is_Scalar_Type
(Typ
) then
14836 elsif Is_Access_Type
(Typ
) then
14837 return Include_Implicit
;
14839 elsif Is_Array_Type
(Typ
) then
14841 -- If component type is partially initialized, so is array type
14843 if Is_Partially_Initialized_Type
14844 (Component_Type
(Typ
), Include_Implicit
)
14848 -- Otherwise we are only partially initialized if we are fully
14849 -- initialized (this is the empty array case, no point in us
14850 -- duplicating that code here).
14853 return Is_Fully_Initialized_Type
(Typ
);
14856 elsif Is_Record_Type
(Typ
) then
14858 -- A discriminated type is always partially initialized if in
14861 if Has_Discriminants
(Typ
) and then Include_Implicit
then
14864 -- A tagged type is always partially initialized
14866 elsif Is_Tagged_Type
(Typ
) then
14869 -- Case of non-discriminated record
14875 Component_Present
: Boolean := False;
14876 -- Set True if at least one component is present. If no
14877 -- components are present, then record type is fully
14878 -- initialized (another odd case, like the null array).
14881 -- Loop through components
14883 Ent
:= First_Entity
(Typ
);
14884 while Present
(Ent
) loop
14885 if Ekind
(Ent
) = E_Component
then
14886 Component_Present
:= True;
14888 -- If a component has an initialization expression then
14889 -- the enclosing record type is partially initialized
14891 if Present
(Parent
(Ent
))
14892 and then Present
(Expression
(Parent
(Ent
)))
14896 -- If a component is of a type which is itself partially
14897 -- initialized, then the enclosing record type is also.
14899 elsif Is_Partially_Initialized_Type
14900 (Etype
(Ent
), Include_Implicit
)
14909 -- No initialized components found. If we found any components
14910 -- they were all uninitialized so the result is false.
14912 if Component_Present
then
14915 -- But if we found no components, then all the components are
14916 -- initialized so we consider the type to be initialized.
14924 -- Concurrent types are always fully initialized
14926 elsif Is_Concurrent_Type
(Typ
) then
14929 -- For a private type, go to underlying type. If there is no underlying
14930 -- type then just assume this partially initialized. Not clear if this
14931 -- can happen in a non-error case, but no harm in testing for this.
14933 elsif Is_Private_Type
(Typ
) then
14935 U
: constant Entity_Id
:= Underlying_Type
(Typ
);
14940 return Is_Partially_Initialized_Type
(U
, Include_Implicit
);
14944 -- For any other type (are there any?) assume partially initialized
14949 end Is_Partially_Initialized_Type
;
14951 ------------------------------------
14952 -- Is_Potentially_Persistent_Type --
14953 ------------------------------------
14955 function Is_Potentially_Persistent_Type
(T
: Entity_Id
) return Boolean is
14960 -- For private type, test corresponding full type
14962 if Is_Private_Type
(T
) then
14963 return Is_Potentially_Persistent_Type
(Full_View
(T
));
14965 -- Scalar types are potentially persistent
14967 elsif Is_Scalar_Type
(T
) then
14970 -- Record type is potentially persistent if not tagged and the types of
14971 -- all it components are potentially persistent, and no component has
14972 -- an initialization expression.
14974 elsif Is_Record_Type
(T
)
14975 and then not Is_Tagged_Type
(T
)
14976 and then not Is_Partially_Initialized_Type
(T
)
14978 Comp
:= First_Component
(T
);
14979 while Present
(Comp
) loop
14980 if not Is_Potentially_Persistent_Type
(Etype
(Comp
)) then
14983 Next_Entity
(Comp
);
14989 -- Array type is potentially persistent if its component type is
14990 -- potentially persistent and if all its constraints are static.
14992 elsif Is_Array_Type
(T
) then
14993 if not Is_Potentially_Persistent_Type
(Component_Type
(T
)) then
14997 Indx
:= First_Index
(T
);
14998 while Present
(Indx
) loop
14999 if not Is_OK_Static_Subtype
(Etype
(Indx
)) then
15008 -- All other types are not potentially persistent
15013 end Is_Potentially_Persistent_Type
;
15015 --------------------------------
15016 -- Is_Potentially_Unevaluated --
15017 --------------------------------
15019 function Is_Potentially_Unevaluated
(N
: Node_Id
) return Boolean is
15027 -- A postcondition whose expression is a short-circuit is broken down
15028 -- into individual aspects for better exception reporting. The original
15029 -- short-circuit expression is rewritten as the second operand, and an
15030 -- occurrence of 'Old in that operand is potentially unevaluated.
15031 -- See Sem_ch13.adb for details of this transformation.
15033 if Nkind
(Original_Node
(Par
)) = N_And_Then
then
15037 while not Nkind_In
(Par
, N_If_Expression
,
15043 N_Quantified_Expression
)
15046 Par
:= Parent
(Par
);
15048 -- If the context is not an expression, or if is the result of
15049 -- expansion of an enclosing construct (such as another attribute)
15050 -- the predicate does not apply.
15052 if Nkind
(Par
) = N_Case_Expression_Alternative
then
15055 elsif Nkind
(Par
) not in N_Subexpr
15056 or else not Comes_From_Source
(Par
)
15062 if Nkind
(Par
) = N_If_Expression
then
15063 return Is_Elsif
(Par
) or else Expr
/= First
(Expressions
(Par
));
15065 elsif Nkind
(Par
) = N_Case_Expression
then
15066 return Expr
/= Expression
(Par
);
15068 elsif Nkind_In
(Par
, N_And_Then
, N_Or_Else
) then
15069 return Expr
= Right_Opnd
(Par
);
15071 elsif Nkind_In
(Par
, N_In
, N_Not_In
) then
15073 -- If the membership includes several alternatives, only the first is
15074 -- definitely evaluated.
15076 if Present
(Alternatives
(Par
)) then
15077 return Expr
/= First
(Alternatives
(Par
));
15079 -- If this is a range membership both bounds are evaluated
15085 elsif Nkind
(Par
) = N_Quantified_Expression
then
15086 return Expr
= Condition
(Par
);
15091 end Is_Potentially_Unevaluated
;
15093 ---------------------------------
15094 -- Is_Protected_Self_Reference --
15095 ---------------------------------
15097 function Is_Protected_Self_Reference
(N
: Node_Id
) return Boolean is
15099 function In_Access_Definition
(N
: Node_Id
) return Boolean;
15100 -- Returns true if N belongs to an access definition
15102 --------------------------
15103 -- In_Access_Definition --
15104 --------------------------
15106 function In_Access_Definition
(N
: Node_Id
) return Boolean is
15111 while Present
(P
) loop
15112 if Nkind
(P
) = N_Access_Definition
then
15120 end In_Access_Definition
;
15122 -- Start of processing for Is_Protected_Self_Reference
15125 -- Verify that prefix is analyzed and has the proper form. Note that
15126 -- the attributes Elab_Spec, Elab_Body, and Elab_Subp_Body, which also
15127 -- produce the address of an entity, do not analyze their prefix
15128 -- because they denote entities that are not necessarily visible.
15129 -- Neither of them can apply to a protected type.
15131 return Ada_Version
>= Ada_2005
15132 and then Is_Entity_Name
(N
)
15133 and then Present
(Entity
(N
))
15134 and then Is_Protected_Type
(Entity
(N
))
15135 and then In_Open_Scopes
(Entity
(N
))
15136 and then not In_Access_Definition
(N
);
15137 end Is_Protected_Self_Reference
;
15139 -----------------------------
15140 -- Is_RCI_Pkg_Spec_Or_Body --
15141 -----------------------------
15143 function Is_RCI_Pkg_Spec_Or_Body
(Cunit
: Node_Id
) return Boolean is
15145 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean;
15146 -- Return True if the unit of Cunit is an RCI package declaration
15148 ---------------------------
15149 -- Is_RCI_Pkg_Decl_Cunit --
15150 ---------------------------
15152 function Is_RCI_Pkg_Decl_Cunit
(Cunit
: Node_Id
) return Boolean is
15153 The_Unit
: constant Node_Id
:= Unit
(Cunit
);
15156 if Nkind
(The_Unit
) /= N_Package_Declaration
then
15160 return Is_Remote_Call_Interface
(Defining_Entity
(The_Unit
));
15161 end Is_RCI_Pkg_Decl_Cunit
;
15163 -- Start of processing for Is_RCI_Pkg_Spec_Or_Body
15166 return Is_RCI_Pkg_Decl_Cunit
(Cunit
)
15168 (Nkind
(Unit
(Cunit
)) = N_Package_Body
15169 and then Is_RCI_Pkg_Decl_Cunit
(Library_Unit
(Cunit
)));
15170 end Is_RCI_Pkg_Spec_Or_Body
;
15172 -----------------------------------------
15173 -- Is_Remote_Access_To_Class_Wide_Type --
15174 -----------------------------------------
15176 function Is_Remote_Access_To_Class_Wide_Type
15177 (E
: Entity_Id
) return Boolean
15180 -- A remote access to class-wide type is a general access to object type
15181 -- declared in the visible part of a Remote_Types or Remote_Call_
15184 return Ekind
(E
) = E_General_Access_Type
15185 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
15186 end Is_Remote_Access_To_Class_Wide_Type
;
15188 -----------------------------------------
15189 -- Is_Remote_Access_To_Subprogram_Type --
15190 -----------------------------------------
15192 function Is_Remote_Access_To_Subprogram_Type
15193 (E
: Entity_Id
) return Boolean
15196 return (Ekind
(E
) = E_Access_Subprogram_Type
15197 or else (Ekind
(E
) = E_Record_Type
15198 and then Present
(Corresponding_Remote_Type
(E
))))
15199 and then (Is_Remote_Call_Interface
(E
) or else Is_Remote_Types
(E
));
15200 end Is_Remote_Access_To_Subprogram_Type
;
15202 --------------------
15203 -- Is_Remote_Call --
15204 --------------------
15206 function Is_Remote_Call
(N
: Node_Id
) return Boolean is
15208 if Nkind
(N
) not in N_Subprogram_Call
then
15210 -- An entry call cannot be remote
15214 elsif Nkind
(Name
(N
)) in N_Has_Entity
15215 and then Is_Remote_Call_Interface
(Entity
(Name
(N
)))
15217 -- A subprogram declared in the spec of a RCI package is remote
15221 elsif Nkind
(Name
(N
)) = N_Explicit_Dereference
15222 and then Is_Remote_Access_To_Subprogram_Type
15223 (Etype
(Prefix
(Name
(N
))))
15225 -- The dereference of a RAS is a remote call
15229 elsif Present
(Controlling_Argument
(N
))
15230 and then Is_Remote_Access_To_Class_Wide_Type
15231 (Etype
(Controlling_Argument
(N
)))
15233 -- Any primitive operation call with a controlling argument of
15234 -- a RACW type is a remote call.
15239 -- All other calls are local calls
15242 end Is_Remote_Call
;
15244 ----------------------
15245 -- Is_Renamed_Entry --
15246 ----------------------
15248 function Is_Renamed_Entry
(Proc_Nam
: Entity_Id
) return Boolean is
15249 Orig_Node
: Node_Id
:= Empty
;
15250 Subp_Decl
: Node_Id
:= Parent
(Parent
(Proc_Nam
));
15252 function Is_Entry
(Nam
: Node_Id
) return Boolean;
15253 -- Determine whether Nam is an entry. Traverse selectors if there are
15254 -- nested selected components.
15260 function Is_Entry
(Nam
: Node_Id
) return Boolean is
15262 if Nkind
(Nam
) = N_Selected_Component
then
15263 return Is_Entry
(Selector_Name
(Nam
));
15266 return Ekind
(Entity
(Nam
)) = E_Entry
;
15269 -- Start of processing for Is_Renamed_Entry
15272 if Present
(Alias
(Proc_Nam
)) then
15273 Subp_Decl
:= Parent
(Parent
(Alias
(Proc_Nam
)));
15276 -- Look for a rewritten subprogram renaming declaration
15278 if Nkind
(Subp_Decl
) = N_Subprogram_Declaration
15279 and then Present
(Original_Node
(Subp_Decl
))
15281 Orig_Node
:= Original_Node
(Subp_Decl
);
15284 -- The rewritten subprogram is actually an entry
15286 if Present
(Orig_Node
)
15287 and then Nkind
(Orig_Node
) = N_Subprogram_Renaming_Declaration
15288 and then Is_Entry
(Name
(Orig_Node
))
15294 end Is_Renamed_Entry
;
15296 -----------------------------
15297 -- Is_Renaming_Declaration --
15298 -----------------------------
15300 function Is_Renaming_Declaration
(N
: Node_Id
) return Boolean is
15303 when N_Exception_Renaming_Declaration
15304 | N_Generic_Function_Renaming_Declaration
15305 | N_Generic_Package_Renaming_Declaration
15306 | N_Generic_Procedure_Renaming_Declaration
15307 | N_Object_Renaming_Declaration
15308 | N_Package_Renaming_Declaration
15309 | N_Subprogram_Renaming_Declaration
15316 end Is_Renaming_Declaration
;
15318 ----------------------------
15319 -- Is_Reversible_Iterator --
15320 ----------------------------
15322 function Is_Reversible_Iterator
(Typ
: Entity_Id
) return Boolean is
15323 Ifaces_List
: Elist_Id
;
15324 Iface_Elmt
: Elmt_Id
;
15328 if Is_Class_Wide_Type
(Typ
)
15329 and then Chars
(Root_Type
(Typ
)) = Name_Reversible_Iterator
15330 and then In_Predefined_Unit
(Root_Type
(Typ
))
15334 elsif not Is_Tagged_Type
(Typ
) or else not Is_Derived_Type
(Typ
) then
15338 Collect_Interfaces
(Typ
, Ifaces_List
);
15340 Iface_Elmt
:= First_Elmt
(Ifaces_List
);
15341 while Present
(Iface_Elmt
) loop
15342 Iface
:= Node
(Iface_Elmt
);
15343 if Chars
(Iface
) = Name_Reversible_Iterator
15344 and then In_Predefined_Unit
(Iface
)
15349 Next_Elmt
(Iface_Elmt
);
15354 end Is_Reversible_Iterator
;
15356 ----------------------
15357 -- Is_Selector_Name --
15358 ----------------------
15360 function Is_Selector_Name
(N
: Node_Id
) return Boolean is
15362 if not Is_List_Member
(N
) then
15364 P
: constant Node_Id
:= Parent
(N
);
15366 return Nkind_In
(P
, N_Expanded_Name
,
15367 N_Generic_Association
,
15368 N_Parameter_Association
,
15369 N_Selected_Component
)
15370 and then Selector_Name
(P
) = N
;
15375 L
: constant List_Id
:= List_Containing
(N
);
15376 P
: constant Node_Id
:= Parent
(L
);
15378 return (Nkind
(P
) = N_Discriminant_Association
15379 and then Selector_Names
(P
) = L
)
15381 (Nkind
(P
) = N_Component_Association
15382 and then Choices
(P
) = L
);
15385 end Is_Selector_Name
;
15387 ---------------------------------
15388 -- Is_Single_Concurrent_Object --
15389 ---------------------------------
15391 function Is_Single_Concurrent_Object
(Id
: Entity_Id
) return Boolean is
15394 Is_Single_Protected_Object
(Id
) or else Is_Single_Task_Object
(Id
);
15395 end Is_Single_Concurrent_Object
;
15397 -------------------------------
15398 -- Is_Single_Concurrent_Type --
15399 -------------------------------
15401 function Is_Single_Concurrent_Type
(Id
: Entity_Id
) return Boolean is
15404 Ekind_In
(Id
, E_Protected_Type
, E_Task_Type
)
15405 and then Is_Single_Concurrent_Type_Declaration
15406 (Declaration_Node
(Id
));
15407 end Is_Single_Concurrent_Type
;
15409 -------------------------------------------
15410 -- Is_Single_Concurrent_Type_Declaration --
15411 -------------------------------------------
15413 function Is_Single_Concurrent_Type_Declaration
15414 (N
: Node_Id
) return Boolean
15417 return Nkind_In
(Original_Node
(N
), N_Single_Protected_Declaration
,
15418 N_Single_Task_Declaration
);
15419 end Is_Single_Concurrent_Type_Declaration
;
15421 ---------------------------------------------
15422 -- Is_Single_Precision_Floating_Point_Type --
15423 ---------------------------------------------
15425 function Is_Single_Precision_Floating_Point_Type
15426 (E
: Entity_Id
) return Boolean is
15428 return Is_Floating_Point_Type
(E
)
15429 and then Machine_Radix_Value
(E
) = Uint_2
15430 and then Machine_Mantissa_Value
(E
) = Uint_24
15431 and then Machine_Emax_Value
(E
) = Uint_2
** Uint_7
15432 and then Machine_Emin_Value
(E
) = Uint_3
- (Uint_2
** Uint_7
);
15433 end Is_Single_Precision_Floating_Point_Type
;
15435 --------------------------------
15436 -- Is_Single_Protected_Object --
15437 --------------------------------
15439 function Is_Single_Protected_Object
(Id
: Entity_Id
) return Boolean is
15442 Ekind
(Id
) = E_Variable
15443 and then Ekind
(Etype
(Id
)) = E_Protected_Type
15444 and then Is_Single_Concurrent_Type
(Etype
(Id
));
15445 end Is_Single_Protected_Object
;
15447 ---------------------------
15448 -- Is_Single_Task_Object --
15449 ---------------------------
15451 function Is_Single_Task_Object
(Id
: Entity_Id
) return Boolean is
15454 Ekind
(Id
) = E_Variable
15455 and then Ekind
(Etype
(Id
)) = E_Task_Type
15456 and then Is_Single_Concurrent_Type
(Etype
(Id
));
15457 end Is_Single_Task_Object
;
15459 -------------------------------------
15460 -- Is_SPARK_05_Initialization_Expr --
15461 -------------------------------------
15463 function Is_SPARK_05_Initialization_Expr
(N
: Node_Id
) return Boolean is
15466 Comp_Assn
: Node_Id
;
15467 Orig_N
: constant Node_Id
:= Original_Node
(N
);
15472 if not Comes_From_Source
(Orig_N
) then
15476 pragma Assert
(Nkind
(Orig_N
) in N_Subexpr
);
15478 case Nkind
(Orig_N
) is
15479 when N_Character_Literal
15480 | N_Integer_Literal
15486 when N_Expanded_Name
15489 if Is_Entity_Name
(Orig_N
)
15490 and then Present
(Entity
(Orig_N
)) -- needed in some cases
15492 case Ekind
(Entity
(Orig_N
)) is
15494 | E_Enumeration_Literal
15501 if Is_Type
(Entity
(Orig_N
)) then
15509 when N_Qualified_Expression
15510 | N_Type_Conversion
15512 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Expression
(Orig_N
));
15515 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
15518 | N_Membership_Test
15521 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Left_Opnd
(Orig_N
))
15523 Is_SPARK_05_Initialization_Expr
(Right_Opnd
(Orig_N
));
15526 | N_Extension_Aggregate
15528 if Nkind
(Orig_N
) = N_Extension_Aggregate
then
15530 Is_SPARK_05_Initialization_Expr
(Ancestor_Part
(Orig_N
));
15533 Expr
:= First
(Expressions
(Orig_N
));
15534 while Present
(Expr
) loop
15535 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
15543 Comp_Assn
:= First
(Component_Associations
(Orig_N
));
15544 while Present
(Comp_Assn
) loop
15545 Expr
:= Expression
(Comp_Assn
);
15547 -- Note: test for Present here needed for box assocation
15550 and then not Is_SPARK_05_Initialization_Expr
(Expr
)
15559 when N_Attribute_Reference
=>
15560 if Nkind
(Prefix
(Orig_N
)) in N_Subexpr
then
15561 Is_Ok
:= Is_SPARK_05_Initialization_Expr
(Prefix
(Orig_N
));
15564 Expr
:= First
(Expressions
(Orig_N
));
15565 while Present
(Expr
) loop
15566 if not Is_SPARK_05_Initialization_Expr
(Expr
) then
15574 -- Selected components might be expanded named not yet resolved, so
15575 -- default on the safe side. (Eg on sparklex.ads)
15577 when N_Selected_Component
=>
15586 end Is_SPARK_05_Initialization_Expr
;
15588 ----------------------------------
15589 -- Is_SPARK_05_Object_Reference --
15590 ----------------------------------
15592 function Is_SPARK_05_Object_Reference
(N
: Node_Id
) return Boolean is
15594 if Is_Entity_Name
(N
) then
15595 return Present
(Entity
(N
))
15597 (Ekind_In
(Entity
(N
), E_Constant
, E_Variable
)
15598 or else Ekind
(Entity
(N
)) in Formal_Kind
);
15602 when N_Selected_Component
=>
15603 return Is_SPARK_05_Object_Reference
(Prefix
(N
));
15609 end Is_SPARK_05_Object_Reference
;
15611 -----------------------------
15612 -- Is_Specific_Tagged_Type --
15613 -----------------------------
15615 function Is_Specific_Tagged_Type
(Typ
: Entity_Id
) return Boolean is
15616 Full_Typ
: Entity_Id
;
15619 -- Handle private types
15621 if Is_Private_Type
(Typ
) and then Present
(Full_View
(Typ
)) then
15622 Full_Typ
:= Full_View
(Typ
);
15627 -- A specific tagged type is a non-class-wide tagged type
15629 return Is_Tagged_Type
(Full_Typ
) and not Is_Class_Wide_Type
(Full_Typ
);
15630 end Is_Specific_Tagged_Type
;
15636 function Is_Statement
(N
: Node_Id
) return Boolean is
15639 Nkind
(N
) in N_Statement_Other_Than_Procedure_Call
15640 or else Nkind
(N
) = N_Procedure_Call_Statement
;
15643 ---------------------------------------
15644 -- Is_Subprogram_Contract_Annotation --
15645 ---------------------------------------
15647 function Is_Subprogram_Contract_Annotation
15648 (Item
: Node_Id
) return Boolean
15653 if Nkind
(Item
) = N_Aspect_Specification
then
15654 Nam
:= Chars
(Identifier
(Item
));
15656 else pragma Assert
(Nkind
(Item
) = N_Pragma
);
15657 Nam
:= Pragma_Name
(Item
);
15660 return Nam
= Name_Contract_Cases
15661 or else Nam
= Name_Depends
15662 or else Nam
= Name_Extensions_Visible
15663 or else Nam
= Name_Global
15664 or else Nam
= Name_Post
15665 or else Nam
= Name_Post_Class
15666 or else Nam
= Name_Postcondition
15667 or else Nam
= Name_Pre
15668 or else Nam
= Name_Pre_Class
15669 or else Nam
= Name_Precondition
15670 or else Nam
= Name_Refined_Depends
15671 or else Nam
= Name_Refined_Global
15672 or else Nam
= Name_Refined_Post
15673 or else Nam
= Name_Test_Case
;
15674 end Is_Subprogram_Contract_Annotation
;
15676 --------------------------------------------------
15677 -- Is_Subprogram_Stub_Without_Prior_Declaration --
15678 --------------------------------------------------
15680 function Is_Subprogram_Stub_Without_Prior_Declaration
15681 (N
: Node_Id
) return Boolean
15684 -- A subprogram stub without prior declaration serves as declaration for
15685 -- the actual subprogram body. As such, it has an attached defining
15686 -- entity of E_[Generic_]Function or E_[Generic_]Procedure.
15688 return Nkind
(N
) = N_Subprogram_Body_Stub
15689 and then Ekind
(Defining_Entity
(N
)) /= E_Subprogram_Body
;
15690 end Is_Subprogram_Stub_Without_Prior_Declaration
;
15692 --------------------------
15693 -- Is_Suspension_Object --
15694 --------------------------
15696 function Is_Suspension_Object
(Id
: Entity_Id
) return Boolean is
15698 -- This approach does an exact name match rather than to rely on
15699 -- RTSfind. Routine Is_Effectively_Volatile is used by clients of the
15700 -- front end at point where all auxiliary tables are locked and any
15701 -- modifications to them are treated as violations. Do not tamper with
15702 -- the tables, instead examine the Chars fields of all the scopes of Id.
15705 Chars
(Id
) = Name_Suspension_Object
15706 and then Present
(Scope
(Id
))
15707 and then Chars
(Scope
(Id
)) = Name_Synchronous_Task_Control
15708 and then Present
(Scope
(Scope
(Id
)))
15709 and then Chars
(Scope
(Scope
(Id
))) = Name_Ada
15710 and then Present
(Scope
(Scope
(Scope
(Id
))))
15711 and then Scope
(Scope
(Scope
(Id
))) = Standard_Standard
;
15712 end Is_Suspension_Object
;
15714 ----------------------------
15715 -- Is_Synchronized_Object --
15716 ----------------------------
15718 function Is_Synchronized_Object
(Id
: Entity_Id
) return Boolean is
15722 if Is_Object
(Id
) then
15724 -- The object is synchronized if it is of a type that yields a
15725 -- synchronized object.
15727 if Yields_Synchronized_Object
(Etype
(Id
)) then
15730 -- The object is synchronized if it is atomic and Async_Writers is
15733 elsif Is_Atomic
(Id
) and then Async_Writers_Enabled
(Id
) then
15736 -- A constant is a synchronized object by default
15738 elsif Ekind
(Id
) = E_Constant
then
15741 -- A variable is a synchronized object if it is subject to pragma
15742 -- Constant_After_Elaboration.
15744 elsif Ekind
(Id
) = E_Variable
then
15745 Prag
:= Get_Pragma
(Id
, Pragma_Constant_After_Elaboration
);
15747 return Present
(Prag
) and then Is_Enabled_Pragma
(Prag
);
15751 -- Otherwise the input is not an object or it does not qualify as a
15752 -- synchronized object.
15755 end Is_Synchronized_Object
;
15757 ---------------------------------
15758 -- Is_Synchronized_Tagged_Type --
15759 ---------------------------------
15761 function Is_Synchronized_Tagged_Type
(E
: Entity_Id
) return Boolean is
15762 Kind
: constant Entity_Kind
:= Ekind
(Base_Type
(E
));
15765 -- A task or protected type derived from an interface is a tagged type.
15766 -- Such a tagged type is called a synchronized tagged type, as are
15767 -- synchronized interfaces and private extensions whose declaration
15768 -- includes the reserved word synchronized.
15770 return (Is_Tagged_Type
(E
)
15771 and then (Kind
= E_Task_Type
15773 Kind
= E_Protected_Type
))
15776 and then Is_Synchronized_Interface
(E
))
15778 (Ekind
(E
) = E_Record_Type_With_Private
15779 and then Nkind
(Parent
(E
)) = N_Private_Extension_Declaration
15780 and then (Synchronized_Present
(Parent
(E
))
15781 or else Is_Synchronized_Interface
(Etype
(E
))));
15782 end Is_Synchronized_Tagged_Type
;
15788 function Is_Transfer
(N
: Node_Id
) return Boolean is
15789 Kind
: constant Node_Kind
:= Nkind
(N
);
15792 if Kind
= N_Simple_Return_Statement
15794 Kind
= N_Extended_Return_Statement
15796 Kind
= N_Goto_Statement
15798 Kind
= N_Raise_Statement
15800 Kind
= N_Requeue_Statement
15804 elsif (Kind
= N_Exit_Statement
or else Kind
in N_Raise_xxx_Error
)
15805 and then No
(Condition
(N
))
15809 elsif Kind
= N_Procedure_Call_Statement
15810 and then Is_Entity_Name
(Name
(N
))
15811 and then Present
(Entity
(Name
(N
)))
15812 and then No_Return
(Entity
(Name
(N
)))
15816 elsif Nkind
(Original_Node
(N
)) = N_Raise_Statement
then
15828 function Is_True
(U
: Uint
) return Boolean is
15833 --------------------------------------
15834 -- Is_Unchecked_Conversion_Instance --
15835 --------------------------------------
15837 function Is_Unchecked_Conversion_Instance
(Id
: Entity_Id
) return Boolean is
15841 -- Look for a function whose generic parent is the predefined intrinsic
15842 -- function Unchecked_Conversion, or for one that renames such an
15845 if Ekind
(Id
) = E_Function
then
15846 Par
:= Parent
(Id
);
15848 if Nkind
(Par
) = N_Function_Specification
then
15849 Par
:= Generic_Parent
(Par
);
15851 if Present
(Par
) then
15853 Chars
(Par
) = Name_Unchecked_Conversion
15854 and then Is_Intrinsic_Subprogram
(Par
)
15855 and then In_Predefined_Unit
(Par
);
15858 Present
(Alias
(Id
))
15859 and then Is_Unchecked_Conversion_Instance
(Alias
(Id
));
15865 end Is_Unchecked_Conversion_Instance
;
15867 -------------------------------
15868 -- Is_Universal_Numeric_Type --
15869 -------------------------------
15871 function Is_Universal_Numeric_Type
(T
: Entity_Id
) return Boolean is
15873 return T
= Universal_Integer
or else T
= Universal_Real
;
15874 end Is_Universal_Numeric_Type
;
15876 ------------------------------
15877 -- Is_User_Defined_Equality --
15878 ------------------------------
15880 function Is_User_Defined_Equality
(Id
: Entity_Id
) return Boolean is
15882 return Ekind
(Id
) = E_Function
15883 and then Chars
(Id
) = Name_Op_Eq
15884 and then Comes_From_Source
(Id
)
15886 -- Internally generated equalities have a full type declaration
15887 -- as their parent.
15889 and then Nkind
(Parent
(Id
)) = N_Function_Specification
;
15890 end Is_User_Defined_Equality
;
15892 --------------------------------------
15893 -- Is_Validation_Variable_Reference --
15894 --------------------------------------
15896 function Is_Validation_Variable_Reference
(N
: Node_Id
) return Boolean is
15897 Var
: constant Node_Id
:= Unqual_Conv
(N
);
15898 Var_Id
: Entity_Id
;
15903 if Is_Entity_Name
(Var
) then
15904 Var_Id
:= Entity
(Var
);
15909 and then Ekind
(Var_Id
) = E_Variable
15910 and then Present
(Validated_Object
(Var_Id
));
15911 end Is_Validation_Variable_Reference
;
15913 ----------------------------
15914 -- Is_Variable_Size_Array --
15915 ----------------------------
15917 function Is_Variable_Size_Array
(E
: Entity_Id
) return Boolean is
15921 pragma Assert
(Is_Array_Type
(E
));
15923 -- Check if some index is initialized with a non-constant value
15925 Idx
:= First_Index
(E
);
15926 while Present
(Idx
) loop
15927 if Nkind
(Idx
) = N_Range
then
15928 if not Is_Constant_Bound
(Low_Bound
(Idx
))
15929 or else not Is_Constant_Bound
(High_Bound
(Idx
))
15935 Idx
:= Next_Index
(Idx
);
15939 end Is_Variable_Size_Array
;
15941 -----------------------------
15942 -- Is_Variable_Size_Record --
15943 -----------------------------
15945 function Is_Variable_Size_Record
(E
: Entity_Id
) return Boolean is
15947 Comp_Typ
: Entity_Id
;
15950 pragma Assert
(Is_Record_Type
(E
));
15952 Comp
:= First_Entity
(E
);
15953 while Present
(Comp
) loop
15954 Comp_Typ
:= Etype
(Comp
);
15956 -- Recursive call if the record type has discriminants
15958 if Is_Record_Type
(Comp_Typ
)
15959 and then Has_Discriminants
(Comp_Typ
)
15960 and then Is_Variable_Size_Record
(Comp_Typ
)
15964 elsif Is_Array_Type
(Comp_Typ
)
15965 and then Is_Variable_Size_Array
(Comp_Typ
)
15970 Next_Entity
(Comp
);
15974 end Is_Variable_Size_Record
;
15980 function Is_Variable
15982 Use_Original_Node
: Boolean := True) return Boolean
15984 Orig_Node
: Node_Id
;
15986 function In_Protected_Function
(E
: Entity_Id
) return Boolean;
15987 -- Within a protected function, the private components of the enclosing
15988 -- protected type are constants. A function nested within a (protected)
15989 -- procedure is not itself protected. Within the body of a protected
15990 -- function the current instance of the protected type is a constant.
15992 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean;
15993 -- Prefixes can involve implicit dereferences, in which case we must
15994 -- test for the case of a reference of a constant access type, which can
15995 -- can never be a variable.
15997 ---------------------------
15998 -- In_Protected_Function --
15999 ---------------------------
16001 function In_Protected_Function
(E
: Entity_Id
) return Boolean is
16006 -- E is the current instance of a type
16008 if Is_Type
(E
) then
16017 if not Is_Protected_Type
(Prot
) then
16021 S
:= Current_Scope
;
16022 while Present
(S
) and then S
/= Prot
loop
16023 if Ekind
(S
) = E_Function
and then Scope
(S
) = Prot
then
16032 end In_Protected_Function
;
16034 ------------------------
16035 -- Is_Variable_Prefix --
16036 ------------------------
16038 function Is_Variable_Prefix
(P
: Node_Id
) return Boolean is
16040 if Is_Access_Type
(Etype
(P
)) then
16041 return not Is_Access_Constant
(Root_Type
(Etype
(P
)));
16043 -- For the case of an indexed component whose prefix has a packed
16044 -- array type, the prefix has been rewritten into a type conversion.
16045 -- Determine variable-ness from the converted expression.
16047 elsif Nkind
(P
) = N_Type_Conversion
16048 and then not Comes_From_Source
(P
)
16049 and then Is_Array_Type
(Etype
(P
))
16050 and then Is_Packed
(Etype
(P
))
16052 return Is_Variable
(Expression
(P
));
16055 return Is_Variable
(P
);
16057 end Is_Variable_Prefix
;
16059 -- Start of processing for Is_Variable
16062 -- Special check, allow x'Deref(expr) as a variable
16064 if Nkind
(N
) = N_Attribute_Reference
16065 and then Attribute_Name
(N
) = Name_Deref
16070 -- Check if we perform the test on the original node since this may be a
16071 -- test of syntactic categories which must not be disturbed by whatever
16072 -- rewriting might have occurred. For example, an aggregate, which is
16073 -- certainly NOT a variable, could be turned into a variable by
16076 if Use_Original_Node
then
16077 Orig_Node
:= Original_Node
(N
);
16082 -- Definitely OK if Assignment_OK is set. Since this is something that
16083 -- only gets set for expanded nodes, the test is on N, not Orig_Node.
16085 if Nkind
(N
) in N_Subexpr
and then Assignment_OK
(N
) then
16088 -- Normally we go to the original node, but there is one exception where
16089 -- we use the rewritten node, namely when it is an explicit dereference.
16090 -- The generated code may rewrite a prefix which is an access type with
16091 -- an explicit dereference. The dereference is a variable, even though
16092 -- the original node may not be (since it could be a constant of the
16095 -- In Ada 2005 we have a further case to consider: the prefix may be a
16096 -- function call given in prefix notation. The original node appears to
16097 -- be a selected component, but we need to examine the call.
16099 elsif Nkind
(N
) = N_Explicit_Dereference
16100 and then Nkind
(Orig_Node
) /= N_Explicit_Dereference
16101 and then Present
(Etype
(Orig_Node
))
16102 and then Is_Access_Type
(Etype
(Orig_Node
))
16104 -- Note that if the prefix is an explicit dereference that does not
16105 -- come from source, we must check for a rewritten function call in
16106 -- prefixed notation before other forms of rewriting, to prevent a
16110 (Nkind
(Orig_Node
) = N_Function_Call
16111 and then not Is_Access_Constant
(Etype
(Prefix
(N
))))
16113 Is_Variable_Prefix
(Original_Node
(Prefix
(N
)));
16115 -- in Ada 2012, the dereference may have been added for a type with
16116 -- a declared implicit dereference aspect. Check that it is not an
16117 -- access to constant.
16119 elsif Nkind
(N
) = N_Explicit_Dereference
16120 and then Present
(Etype
(Orig_Node
))
16121 and then Ada_Version
>= Ada_2012
16122 and then Has_Implicit_Dereference
(Etype
(Orig_Node
))
16124 return not Is_Access_Constant
(Etype
(Prefix
(N
)));
16126 -- A function call is never a variable
16128 elsif Nkind
(N
) = N_Function_Call
then
16131 -- All remaining checks use the original node
16133 elsif Is_Entity_Name
(Orig_Node
)
16134 and then Present
(Entity
(Orig_Node
))
16137 E
: constant Entity_Id
:= Entity
(Orig_Node
);
16138 K
: constant Entity_Kind
:= Ekind
(E
);
16141 return (K
= E_Variable
16142 and then Nkind
(Parent
(E
)) /= N_Exception_Handler
)
16143 or else (K
= E_Component
16144 and then not In_Protected_Function
(E
))
16145 or else K
= E_Out_Parameter
16146 or else K
= E_In_Out_Parameter
16147 or else K
= E_Generic_In_Out_Parameter
16149 -- Current instance of type. If this is a protected type, check
16150 -- we are not within the body of one of its protected functions.
16152 or else (Is_Type
(E
)
16153 and then In_Open_Scopes
(E
)
16154 and then not In_Protected_Function
(E
))
16156 or else (Is_Incomplete_Or_Private_Type
(E
)
16157 and then In_Open_Scopes
(Full_View
(E
)));
16161 case Nkind
(Orig_Node
) is
16162 when N_Indexed_Component
16165 return Is_Variable_Prefix
(Prefix
(Orig_Node
));
16167 when N_Selected_Component
=>
16168 return (Is_Variable
(Selector_Name
(Orig_Node
))
16169 and then Is_Variable_Prefix
(Prefix
(Orig_Node
)))
16171 (Nkind
(N
) = N_Expanded_Name
16172 and then Scope
(Entity
(N
)) = Entity
(Prefix
(N
)));
16174 -- For an explicit dereference, the type of the prefix cannot
16175 -- be an access to constant or an access to subprogram.
16177 when N_Explicit_Dereference
=>
16179 Typ
: constant Entity_Id
:= Etype
(Prefix
(Orig_Node
));
16181 return Is_Access_Type
(Typ
)
16182 and then not Is_Access_Constant
(Root_Type
(Typ
))
16183 and then Ekind
(Typ
) /= E_Access_Subprogram_Type
;
16186 -- The type conversion is the case where we do not deal with the
16187 -- context dependent special case of an actual parameter. Thus
16188 -- the type conversion is only considered a variable for the
16189 -- purposes of this routine if the target type is tagged. However,
16190 -- a type conversion is considered to be a variable if it does not
16191 -- come from source (this deals for example with the conversions
16192 -- of expressions to their actual subtypes).
16194 when N_Type_Conversion
=>
16195 return Is_Variable
(Expression
(Orig_Node
))
16197 (not Comes_From_Source
(Orig_Node
)
16199 (Is_Tagged_Type
(Etype
(Subtype_Mark
(Orig_Node
)))
16201 Is_Tagged_Type
(Etype
(Expression
(Orig_Node
)))));
16203 -- GNAT allows an unchecked type conversion as a variable. This
16204 -- only affects the generation of internal expanded code, since
16205 -- calls to instantiations of Unchecked_Conversion are never
16206 -- considered variables (since they are function calls).
16208 when N_Unchecked_Type_Conversion
=>
16209 return Is_Variable
(Expression
(Orig_Node
));
16217 ------------------------------
16218 -- Is_Verifiable_DIC_Pragma --
16219 ------------------------------
16221 function Is_Verifiable_DIC_Pragma
(Prag
: Node_Id
) return Boolean is
16222 Args
: constant List_Id
:= Pragma_Argument_Associations
(Prag
);
16225 -- To qualify as verifiable, a DIC pragma must have a non-null argument
16229 and then Nkind
(Get_Pragma_Arg
(First
(Args
))) /= N_Null
;
16230 end Is_Verifiable_DIC_Pragma
;
16232 ---------------------------
16233 -- Is_Visibly_Controlled --
16234 ---------------------------
16236 function Is_Visibly_Controlled
(T
: Entity_Id
) return Boolean is
16237 Root
: constant Entity_Id
:= Root_Type
(T
);
16239 return Chars
(Scope
(Root
)) = Name_Finalization
16240 and then Chars
(Scope
(Scope
(Root
))) = Name_Ada
16241 and then Scope
(Scope
(Scope
(Root
))) = Standard_Standard
;
16242 end Is_Visibly_Controlled
;
16244 --------------------------
16245 -- Is_Volatile_Function --
16246 --------------------------
16248 function Is_Volatile_Function
(Func_Id
: Entity_Id
) return Boolean is
16250 pragma Assert
(Ekind_In
(Func_Id
, E_Function
, E_Generic_Function
));
16252 -- A function declared within a protected type is volatile
16254 if Is_Protected_Type
(Scope
(Func_Id
)) then
16257 -- An instance of Ada.Unchecked_Conversion is a volatile function if
16258 -- either the source or the target are effectively volatile.
16260 elsif Is_Unchecked_Conversion_Instance
(Func_Id
)
16261 and then Has_Effectively_Volatile_Profile
(Func_Id
)
16265 -- Otherwise the function is treated as volatile if it is subject to
16266 -- enabled pragma Volatile_Function.
16270 Is_Enabled_Pragma
(Get_Pragma
(Func_Id
, Pragma_Volatile_Function
));
16272 end Is_Volatile_Function
;
16274 ------------------------
16275 -- Is_Volatile_Object --
16276 ------------------------
16278 function Is_Volatile_Object
(N
: Node_Id
) return Boolean is
16279 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean;
16280 -- If prefix is an implicit dereference, examine designated type
16282 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean;
16283 -- Determines if given object has volatile components
16285 ------------------------
16286 -- Is_Volatile_Prefix --
16287 ------------------------
16289 function Is_Volatile_Prefix
(N
: Node_Id
) return Boolean is
16290 Typ
: constant Entity_Id
:= Etype
(N
);
16293 if Is_Access_Type
(Typ
) then
16295 Dtyp
: constant Entity_Id
:= Designated_Type
(Typ
);
16298 return Is_Volatile
(Dtyp
)
16299 or else Has_Volatile_Components
(Dtyp
);
16303 return Object_Has_Volatile_Components
(N
);
16305 end Is_Volatile_Prefix
;
16307 ------------------------------------
16308 -- Object_Has_Volatile_Components --
16309 ------------------------------------
16311 function Object_Has_Volatile_Components
(N
: Node_Id
) return Boolean is
16312 Typ
: constant Entity_Id
:= Etype
(N
);
16315 if Is_Volatile
(Typ
)
16316 or else Has_Volatile_Components
(Typ
)
16320 elsif Is_Entity_Name
(N
)
16321 and then (Has_Volatile_Components
(Entity
(N
))
16322 or else Is_Volatile
(Entity
(N
)))
16326 elsif Nkind
(N
) = N_Indexed_Component
16327 or else Nkind
(N
) = N_Selected_Component
16329 return Is_Volatile_Prefix
(Prefix
(N
));
16334 end Object_Has_Volatile_Components
;
16336 -- Start of processing for Is_Volatile_Object
16339 if Nkind
(N
) = N_Defining_Identifier
then
16340 return Is_Volatile
(N
) or else Is_Volatile
(Etype
(N
));
16342 elsif Nkind
(N
) = N_Expanded_Name
then
16343 return Is_Volatile_Object
(Entity
(N
));
16345 elsif Is_Volatile
(Etype
(N
))
16346 or else (Is_Entity_Name
(N
) and then Is_Volatile
(Entity
(N
)))
16350 elsif Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
)
16351 and then Is_Volatile_Prefix
(Prefix
(N
))
16355 elsif Nkind
(N
) = N_Selected_Component
16356 and then Is_Volatile
(Entity
(Selector_Name
(N
)))
16363 end Is_Volatile_Object
;
16365 -----------------------------
16366 -- Iterate_Call_Parameters --
16367 -----------------------------
16369 procedure Iterate_Call_Parameters
(Call
: Node_Id
) is
16370 Formal
: Entity_Id
:= First_Formal
(Get_Called_Entity
(Call
));
16371 Actual
: Node_Id
:= First_Actual
(Call
);
16374 while Present
(Formal
) and then Present
(Actual
) loop
16375 Handle_Parameter
(Formal
, Actual
);
16376 Formal
:= Next_Formal
(Formal
);
16377 Actual
:= Next_Actual
(Actual
);
16379 end Iterate_Call_Parameters
;
16381 ---------------------------
16382 -- Itype_Has_Declaration --
16383 ---------------------------
16385 function Itype_Has_Declaration
(Id
: Entity_Id
) return Boolean is
16387 pragma Assert
(Is_Itype
(Id
));
16388 return Present
(Parent
(Id
))
16389 and then Nkind_In
(Parent
(Id
), N_Full_Type_Declaration
,
16390 N_Subtype_Declaration
)
16391 and then Defining_Entity
(Parent
(Id
)) = Id
;
16392 end Itype_Has_Declaration
;
16394 -------------------------
16395 -- Kill_Current_Values --
16396 -------------------------
16398 procedure Kill_Current_Values
16400 Last_Assignment_Only
: Boolean := False)
16403 if Is_Assignable
(Ent
) then
16404 Set_Last_Assignment
(Ent
, Empty
);
16407 if Is_Object
(Ent
) then
16408 if not Last_Assignment_Only
then
16410 Set_Current_Value
(Ent
, Empty
);
16412 -- Do not reset the Is_Known_[Non_]Null and Is_Known_Valid flags
16413 -- for a constant. Once the constant is elaborated, its value is
16414 -- not changed, therefore the associated flags that describe the
16415 -- value should not be modified either.
16417 if Ekind
(Ent
) = E_Constant
then
16420 -- Non-constant entities
16423 if not Can_Never_Be_Null
(Ent
) then
16424 Set_Is_Known_Non_Null
(Ent
, False);
16427 Set_Is_Known_Null
(Ent
, False);
16429 -- Reset the Is_Known_Valid flag unless the type is always
16430 -- valid. This does not apply to a loop parameter because its
16431 -- bounds are defined by the loop header and therefore always
16434 if not Is_Known_Valid
(Etype
(Ent
))
16435 and then Ekind
(Ent
) /= E_Loop_Parameter
16437 Set_Is_Known_Valid
(Ent
, False);
16442 end Kill_Current_Values
;
16444 procedure Kill_Current_Values
(Last_Assignment_Only
: Boolean := False) is
16447 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
);
16448 -- Clear current value for entity E and all entities chained to E
16450 ------------------------------------------
16451 -- Kill_Current_Values_For_Entity_Chain --
16452 ------------------------------------------
16454 procedure Kill_Current_Values_For_Entity_Chain
(E
: Entity_Id
) is
16458 while Present
(Ent
) loop
16459 Kill_Current_Values
(Ent
, Last_Assignment_Only
);
16462 end Kill_Current_Values_For_Entity_Chain
;
16464 -- Start of processing for Kill_Current_Values
16467 -- Kill all saved checks, a special case of killing saved values
16469 if not Last_Assignment_Only
then
16473 -- Loop through relevant scopes, which includes the current scope and
16474 -- any parent scopes if the current scope is a block or a package.
16476 S
:= Current_Scope
;
16479 -- Clear current values of all entities in current scope
16481 Kill_Current_Values_For_Entity_Chain
(First_Entity
(S
));
16483 -- If scope is a package, also clear current values of all private
16484 -- entities in the scope.
16486 if Is_Package_Or_Generic_Package
(S
)
16487 or else Is_Concurrent_Type
(S
)
16489 Kill_Current_Values_For_Entity_Chain
(First_Private_Entity
(S
));
16492 -- If this is a not a subprogram, deal with parents
16494 if not Is_Subprogram
(S
) then
16496 exit Scope_Loop
when S
= Standard_Standard
;
16500 end loop Scope_Loop
;
16501 end Kill_Current_Values
;
16503 --------------------------
16504 -- Kill_Size_Check_Code --
16505 --------------------------
16507 procedure Kill_Size_Check_Code
(E
: Entity_Id
) is
16509 if (Ekind
(E
) = E_Constant
or else Ekind
(E
) = E_Variable
)
16510 and then Present
(Size_Check_Code
(E
))
16512 Remove
(Size_Check_Code
(E
));
16513 Set_Size_Check_Code
(E
, Empty
);
16515 end Kill_Size_Check_Code
;
16517 --------------------
16518 -- Known_Non_Null --
16519 --------------------
16521 function Known_Non_Null
(N
: Node_Id
) return Boolean is
16522 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
16529 -- The expression yields a non-null value ignoring simple flow analysis
16531 if Status
= Is_Non_Null
then
16534 -- Otherwise check whether N is a reference to an entity that appears
16535 -- within a conditional construct.
16537 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
16539 -- First check if we are in decisive conditional
16541 Get_Current_Value_Condition
(N
, Op
, Val
);
16543 if Known_Null
(Val
) then
16544 if Op
= N_Op_Eq
then
16546 elsif Op
= N_Op_Ne
then
16551 -- If OK to do replacement, test Is_Known_Non_Null flag
16555 if OK_To_Do_Constant_Replacement
(Id
) then
16556 return Is_Known_Non_Null
(Id
);
16560 -- Otherwise it is not possible to determine whether N yields a non-null
16564 end Known_Non_Null
;
16570 function Known_Null
(N
: Node_Id
) return Boolean is
16571 Status
: constant Null_Status_Kind
:= Null_Status
(N
);
16578 -- The expression yields a null value ignoring simple flow analysis
16580 if Status
= Is_Null
then
16583 -- Otherwise check whether N is a reference to an entity that appears
16584 -- within a conditional construct.
16586 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
16588 -- First check if we are in decisive conditional
16590 Get_Current_Value_Condition
(N
, Op
, Val
);
16592 if Known_Null
(Val
) then
16593 if Op
= N_Op_Eq
then
16595 elsif Op
= N_Op_Ne
then
16600 -- If OK to do replacement, test Is_Known_Null flag
16604 if OK_To_Do_Constant_Replacement
(Id
) then
16605 return Is_Known_Null
(Id
);
16609 -- Otherwise it is not possible to determine whether N yields a null
16615 --------------------------
16616 -- Known_To_Be_Assigned --
16617 --------------------------
16619 function Known_To_Be_Assigned
(N
: Node_Id
) return Boolean is
16620 P
: constant Node_Id
:= Parent
(N
);
16625 -- Test left side of assignment
16627 when N_Assignment_Statement
=>
16628 return N
= Name
(P
);
16630 -- Function call arguments are never lvalues
16632 when N_Function_Call
=>
16635 -- Positional parameter for procedure or accept call
16637 when N_Accept_Statement
16638 | N_Procedure_Call_Statement
16646 Proc
:= Get_Subprogram_Entity
(P
);
16652 -- If we are not a list member, something is strange, so
16653 -- be conservative and return False.
16655 if not Is_List_Member
(N
) then
16659 -- We are going to find the right formal by stepping forward
16660 -- through the formals, as we step backwards in the actuals.
16662 Form
:= First_Formal
(Proc
);
16665 -- If no formal, something is weird, so be conservative
16666 -- and return False.
16673 exit when No
(Act
);
16674 Next_Formal
(Form
);
16677 return Ekind
(Form
) /= E_In_Parameter
;
16680 -- Named parameter for procedure or accept call
16682 when N_Parameter_Association
=>
16688 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
16694 -- Loop through formals to find the one that matches
16696 Form
:= First_Formal
(Proc
);
16698 -- If no matching formal, that's peculiar, some kind of
16699 -- previous error, so return False to be conservative.
16700 -- Actually this also happens in legal code in the case
16701 -- where P is a parameter association for an Extra_Formal???
16707 -- Else test for match
16709 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
16710 return Ekind
(Form
) /= E_In_Parameter
;
16713 Next_Formal
(Form
);
16717 -- Test for appearing in a conversion that itself appears
16718 -- in an lvalue context, since this should be an lvalue.
16720 when N_Type_Conversion
=>
16721 return Known_To_Be_Assigned
(P
);
16723 -- All other references are definitely not known to be modifications
16728 end Known_To_Be_Assigned
;
16730 ---------------------------
16731 -- Last_Source_Statement --
16732 ---------------------------
16734 function Last_Source_Statement
(HSS
: Node_Id
) return Node_Id
is
16738 N
:= Last
(Statements
(HSS
));
16739 while Present
(N
) loop
16740 exit when Comes_From_Source
(N
);
16745 end Last_Source_Statement
;
16747 ----------------------------------
16748 -- Matching_Static_Array_Bounds --
16749 ----------------------------------
16751 function Matching_Static_Array_Bounds
16753 R_Typ
: Node_Id
) return Boolean
16755 L_Ndims
: constant Nat
:= Number_Dimensions
(L_Typ
);
16756 R_Ndims
: constant Nat
:= Number_Dimensions
(R_Typ
);
16768 if L_Ndims
/= R_Ndims
then
16772 -- Unconstrained types do not have static bounds
16774 if not Is_Constrained
(L_Typ
) or else not Is_Constrained
(R_Typ
) then
16778 -- First treat specially the first dimension, as the lower bound and
16779 -- length of string literals are not stored like those of arrays.
16781 if Ekind
(L_Typ
) = E_String_Literal_Subtype
then
16782 L_Low
:= String_Literal_Low_Bound
(L_Typ
);
16783 L_Len
:= String_Literal_Length
(L_Typ
);
16785 L_Index
:= First_Index
(L_Typ
);
16786 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
16788 if Is_OK_Static_Expression
(L_Low
)
16790 Is_OK_Static_Expression
(L_High
)
16792 if Expr_Value
(L_High
) < Expr_Value
(L_Low
) then
16795 L_Len
:= (Expr_Value
(L_High
) - Expr_Value
(L_Low
)) + 1;
16802 if Ekind
(R_Typ
) = E_String_Literal_Subtype
then
16803 R_Low
:= String_Literal_Low_Bound
(R_Typ
);
16804 R_Len
:= String_Literal_Length
(R_Typ
);
16806 R_Index
:= First_Index
(R_Typ
);
16807 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
16809 if Is_OK_Static_Expression
(R_Low
)
16811 Is_OK_Static_Expression
(R_High
)
16813 if Expr_Value
(R_High
) < Expr_Value
(R_Low
) then
16816 R_Len
:= (Expr_Value
(R_High
) - Expr_Value
(R_Low
)) + 1;
16823 if (Is_OK_Static_Expression
(L_Low
)
16825 Is_OK_Static_Expression
(R_Low
))
16826 and then Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
16827 and then L_Len
= R_Len
16834 -- Then treat all other dimensions
16836 for Indx
in 2 .. L_Ndims
loop
16840 Get_Index_Bounds
(L_Index
, L_Low
, L_High
);
16841 Get_Index_Bounds
(R_Index
, R_Low
, R_High
);
16843 if (Is_OK_Static_Expression
(L_Low
) and then
16844 Is_OK_Static_Expression
(L_High
) and then
16845 Is_OK_Static_Expression
(R_Low
) and then
16846 Is_OK_Static_Expression
(R_High
))
16847 and then (Expr_Value
(L_Low
) = Expr_Value
(R_Low
)
16849 Expr_Value
(L_High
) = Expr_Value
(R_High
))
16857 -- If we fall through the loop, all indexes matched
16860 end Matching_Static_Array_Bounds
;
16862 -------------------
16863 -- May_Be_Lvalue --
16864 -------------------
16866 function May_Be_Lvalue
(N
: Node_Id
) return Boolean is
16867 P
: constant Node_Id
:= Parent
(N
);
16872 -- Test left side of assignment
16874 when N_Assignment_Statement
=>
16875 return N
= Name
(P
);
16877 -- Test prefix of component or attribute. Note that the prefix of an
16878 -- explicit or implicit dereference cannot be an l-value. In the case
16879 -- of a 'Read attribute, the reference can be an actual in the
16880 -- argument list of the attribute.
16882 when N_Attribute_Reference
=>
16883 return (N
= Prefix
(P
)
16884 and then Name_Implies_Lvalue_Prefix
(Attribute_Name
(P
)))
16886 Attribute_Name
(P
) = Name_Read
;
16888 -- For an expanded name, the name is an lvalue if the expanded name
16889 -- is an lvalue, but the prefix is never an lvalue, since it is just
16890 -- the scope where the name is found.
16892 when N_Expanded_Name
=>
16893 if N
= Prefix
(P
) then
16894 return May_Be_Lvalue
(P
);
16899 -- For a selected component A.B, A is certainly an lvalue if A.B is.
16900 -- B is a little interesting, if we have A.B := 3, there is some
16901 -- discussion as to whether B is an lvalue or not, we choose to say
16902 -- it is. Note however that A is not an lvalue if it is of an access
16903 -- type since this is an implicit dereference.
16905 when N_Selected_Component
=>
16907 and then Present
(Etype
(N
))
16908 and then Is_Access_Type
(Etype
(N
))
16912 return May_Be_Lvalue
(P
);
16915 -- For an indexed component or slice, the index or slice bounds is
16916 -- never an lvalue. The prefix is an lvalue if the indexed component
16917 -- or slice is an lvalue, except if it is an access type, where we
16918 -- have an implicit dereference.
16920 when N_Indexed_Component
16924 or else (Present
(Etype
(N
)) and then Is_Access_Type
(Etype
(N
)))
16928 return May_Be_Lvalue
(P
);
16931 -- Prefix of a reference is an lvalue if the reference is an lvalue
16933 when N_Reference
=>
16934 return May_Be_Lvalue
(P
);
16936 -- Prefix of explicit dereference is never an lvalue
16938 when N_Explicit_Dereference
=>
16941 -- Positional parameter for subprogram, entry, or accept call.
16942 -- In older versions of Ada function call arguments are never
16943 -- lvalues. In Ada 2012 functions can have in-out parameters.
16945 when N_Accept_Statement
16946 | N_Entry_Call_Statement
16947 | N_Subprogram_Call
16949 if Nkind
(P
) = N_Function_Call
and then Ada_Version
< Ada_2012
then
16953 -- The following mechanism is clumsy and fragile. A single flag
16954 -- set in Resolve_Actuals would be preferable ???
16962 Proc
:= Get_Subprogram_Entity
(P
);
16968 -- If we are not a list member, something is strange, so be
16969 -- conservative and return True.
16971 if not Is_List_Member
(N
) then
16975 -- We are going to find the right formal by stepping forward
16976 -- through the formals, as we step backwards in the actuals.
16978 Form
:= First_Formal
(Proc
);
16981 -- If no formal, something is weird, so be conservative and
16989 exit when No
(Act
);
16990 Next_Formal
(Form
);
16993 return Ekind
(Form
) /= E_In_Parameter
;
16996 -- Named parameter for procedure or accept call
16998 when N_Parameter_Association
=>
17004 Proc
:= Get_Subprogram_Entity
(Parent
(P
));
17010 -- Loop through formals to find the one that matches
17012 Form
:= First_Formal
(Proc
);
17014 -- If no matching formal, that's peculiar, some kind of
17015 -- previous error, so return True to be conservative.
17016 -- Actually happens with legal code for an unresolved call
17017 -- where we may get the wrong homonym???
17023 -- Else test for match
17025 if Chars
(Form
) = Chars
(Selector_Name
(P
)) then
17026 return Ekind
(Form
) /= E_In_Parameter
;
17029 Next_Formal
(Form
);
17033 -- Test for appearing in a conversion that itself appears in an
17034 -- lvalue context, since this should be an lvalue.
17036 when N_Type_Conversion
=>
17037 return May_Be_Lvalue
(P
);
17039 -- Test for appearance in object renaming declaration
17041 when N_Object_Renaming_Declaration
=>
17044 -- All other references are definitely not lvalues
17051 -----------------------
17052 -- Mark_Coextensions --
17053 -----------------------
17055 procedure Mark_Coextensions
(Context_Nod
: Node_Id
; Root_Nod
: Node_Id
) is
17056 Is_Dynamic
: Boolean;
17057 -- Indicates whether the context causes nested coextensions to be
17058 -- dynamic or static
17060 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
;
17061 -- Recognize an allocator node and label it as a dynamic coextension
17063 --------------------
17064 -- Mark_Allocator --
17065 --------------------
17067 function Mark_Allocator
(N
: Node_Id
) return Traverse_Result
is
17069 if Nkind
(N
) = N_Allocator
then
17071 Set_Is_Dynamic_Coextension
(N
);
17073 -- If the allocator expression is potentially dynamic, it may
17074 -- be expanded out of order and require dynamic allocation
17075 -- anyway, so we treat the coextension itself as dynamic.
17076 -- Potential optimization ???
17078 elsif Nkind
(Expression
(N
)) = N_Qualified_Expression
17079 and then Nkind
(Expression
(Expression
(N
))) = N_Op_Concat
17081 Set_Is_Dynamic_Coextension
(N
);
17083 Set_Is_Static_Coextension
(N
);
17088 end Mark_Allocator
;
17090 procedure Mark_Allocators
is new Traverse_Proc
(Mark_Allocator
);
17092 -- Start of processing for Mark_Coextensions
17095 -- An allocator that appears on the right-hand side of an assignment is
17096 -- treated as a potentially dynamic coextension when the right-hand side
17097 -- is an allocator or a qualified expression.
17099 -- Obj := new ...'(new Coextension ...);
17101 if Nkind
(Context_Nod
) = N_Assignment_Statement
then
17103 Nkind_In
(Expression
(Context_Nod
), N_Allocator
,
17104 N_Qualified_Expression
);
17106 -- An allocator that appears within the expression of a simple return
17107 -- statement is treated as a potentially dynamic coextension when the
17108 -- expression is either aggregate, allocator, or qualified expression.
17110 -- return (new Coextension ...);
17111 -- return new ...'(new Coextension ...);
17113 elsif Nkind
(Context_Nod
) = N_Simple_Return_Statement
then
17115 Nkind_In
(Expression
(Context_Nod
), N_Aggregate
,
17117 N_Qualified_Expression
);
17119 -- An allocator that appears within the initialization expression of an
17120 -- object declaration is considered a potentially dynamic coextension
17121 -- when the initialization expression is an allocator or a qualified
17124 -- Obj : ... := new ...'(new Coextension ...);
17126 -- A similar case arises when the object declaration is part of an
17127 -- extended return statement.
17129 -- return Obj : ... := new ...'(new Coextension ...);
17130 -- return Obj : ... := (new Coextension ...);
17132 elsif Nkind
(Context_Nod
) = N_Object_Declaration
then
17134 Nkind_In
(Root_Nod
, N_Allocator
, N_Qualified_Expression
)
17136 Nkind
(Parent
(Context_Nod
)) = N_Extended_Return_Statement
;
17138 -- This routine should not be called with constructs that cannot contain
17142 raise Program_Error
;
17145 Mark_Allocators
(Root_Nod
);
17146 end Mark_Coextensions
;
17152 function Might_Raise
(N
: Node_Id
) return Boolean is
17153 Result
: Boolean := False;
17155 function Process
(N
: Node_Id
) return Traverse_Result
;
17156 -- Set Result to True if we find something that could raise an exception
17162 function Process
(N
: Node_Id
) return Traverse_Result
is
17164 if Nkind_In
(N
, N_Procedure_Call_Statement
,
17167 N_Raise_Constraint_Error
,
17168 N_Raise_Program_Error
,
17169 N_Raise_Storage_Error
)
17178 procedure Set_Result
is new Traverse_Proc
(Process
);
17180 -- Start of processing for Might_Raise
17183 -- False if exceptions can't be propagated
17185 if No_Exception_Handlers_Set
then
17189 -- If the checks handled by the back end are not disabled, we cannot
17190 -- ensure that no exception will be raised.
17192 if not Access_Checks_Suppressed
(Empty
)
17193 or else not Discriminant_Checks_Suppressed
(Empty
)
17194 or else not Range_Checks_Suppressed
(Empty
)
17195 or else not Index_Checks_Suppressed
(Empty
)
17196 or else Opt
.Stack_Checking_Enabled
17205 --------------------------------
17206 -- Nearest_Enclosing_Instance --
17207 --------------------------------
17209 function Nearest_Enclosing_Instance
(E
: Entity_Id
) return Entity_Id
is
17214 while Present
(Inst
) and then Inst
/= Standard_Standard
loop
17215 if Is_Generic_Instance
(Inst
) then
17219 Inst
:= Scope
(Inst
);
17223 end Nearest_Enclosing_Instance
;
17225 ----------------------
17226 -- Needs_One_Actual --
17227 ----------------------
17229 function Needs_One_Actual
(E
: Entity_Id
) return Boolean is
17230 Formal
: Entity_Id
;
17233 -- Ada 2005 or later, and formals present. The first formal must be
17234 -- of a type that supports prefix notation: a controlling argument,
17235 -- a class-wide type, or an access to such.
17237 if Ada_Version
>= Ada_2005
17238 and then Present
(First_Formal
(E
))
17239 and then No
(Default_Value
(First_Formal
(E
)))
17241 (Is_Controlling_Formal
(First_Formal
(E
))
17242 or else Is_Class_Wide_Type
(Etype
(First_Formal
(E
)))
17243 or else Is_Anonymous_Access_Type
(Etype
(First_Formal
(E
))))
17245 Formal
:= Next_Formal
(First_Formal
(E
));
17246 while Present
(Formal
) loop
17247 if No
(Default_Value
(Formal
)) then
17251 Next_Formal
(Formal
);
17256 -- Ada 83/95 or no formals
17261 end Needs_One_Actual
;
17263 ------------------------
17264 -- New_Copy_List_Tree --
17265 ------------------------
17267 function New_Copy_List_Tree
(List
: List_Id
) return List_Id
is
17272 if List
= No_List
then
17279 while Present
(E
) loop
17280 Append
(New_Copy_Tree
(E
), NL
);
17286 end New_Copy_List_Tree
;
17288 -------------------
17289 -- New_Copy_Tree --
17290 -------------------
17292 -- The following tables play a key role in replicating entities and Itypes.
17293 -- They are intentionally declared at the library level rather than within
17294 -- New_Copy_Tree to avoid elaborating them on each call. This performance
17295 -- optimization saves up to 2% of the entire compilation time spent in the
17296 -- front end. Care should be taken to reset the tables on each new call to
17299 NCT_Table_Max
: constant := 511;
17301 subtype NCT_Table_Index
is Nat
range 0 .. NCT_Table_Max
- 1;
17303 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
;
17304 -- Obtain the hash value of node or entity Key
17306 NCT_Tables_In_Use
: Boolean := False;
17307 -- This flag keeps track of whether the two tables NCT_New_Entities and
17308 -- NCT_Pending_Itypes are in use. The flag is part of an optimization
17309 -- where certain operations are not performed if the tables are not in
17310 -- use. This saves up to 8% of the entire compilation time spent in the
17313 --------------------
17314 -- NCT_Table_Hash --
17315 --------------------
17317 function NCT_Table_Hash
(Key
: Node_Or_Entity_Id
) return NCT_Table_Index
is
17319 return NCT_Table_Index
(Key
mod NCT_Table_Max
);
17320 end NCT_Table_Hash
;
17322 ----------------------
17323 -- NCT_New_Entities --
17324 ----------------------
17326 -- The following table maps old entities and Itypes to their corresponding
17327 -- new entities and Itypes.
17331 package NCT_New_Entities
is new Simple_HTable
(
17332 Header_Num
=> NCT_Table_Index
,
17333 Element
=> Entity_Id
,
17334 No_Element
=> Empty
,
17336 Hash
=> NCT_Table_Hash
,
17339 ------------------------
17340 -- NCT_Pending_Itypes --
17341 ------------------------
17343 -- The following table maps old Associated_Node_For_Itype nodes to a set of
17344 -- new itypes. Given a set of old Itypes Aaa, Bbb, and Ccc, where all three
17345 -- have the same Associated_Node_For_Itype Ppp, and their corresponding new
17346 -- Itypes Xxx, Yyy, Zzz, the table contains the following mapping:
17348 -- Ppp -> (Xxx, Yyy, Zzz)
17350 -- The set is expressed as an Elist
17352 package NCT_Pending_Itypes
is new Simple_HTable
(
17353 Header_Num
=> NCT_Table_Index
,
17354 Element
=> Elist_Id
,
17355 No_Element
=> No_Elist
,
17357 Hash
=> NCT_Table_Hash
,
17360 -------------------
17361 -- New_Copy_Tree --
17362 -------------------
17364 function New_Copy_Tree
17366 Map
: Elist_Id
:= No_Elist
;
17367 New_Sloc
: Source_Ptr
:= No_Location
;
17368 New_Scope
: Entity_Id
:= Empty
) return Node_Id
17370 -- This routine performs low-level tree manipulations and needs access
17371 -- to the internals of the tree.
17373 use Atree
.Unchecked_Access
;
17374 use Atree_Private_Part
;
17376 EWA_Level
: Nat
:= 0;
17377 -- This counter keeps track of how many N_Expression_With_Actions nodes
17378 -- are encountered during a depth-first traversal of the subtree. These
17379 -- nodes may define new entities in their Actions lists and thus require
17380 -- special processing.
17382 EWA_Inner_Scope_Level
: Nat
:= 0;
17383 -- This counter keeps track of how many scoping constructs appear within
17384 -- an N_Expression_With_Actions node.
17386 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
);
17387 pragma Inline
(Add_New_Entity
);
17388 -- Add an entry in the NCT_New_Entities table which maps key Old_Id to
17389 -- value New_Id. Old_Id is an entity which appears within the Actions
17390 -- list of an N_Expression_With_Actions node, or within an entity map.
17391 -- New_Id is the corresponding new entity generated during Phase 1.
17393 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
);
17394 pragma Inline
(Add_New_Entity
);
17395 -- Add an entry in the NCT_Pending_Itypes which maps key Assoc_Nod to
17396 -- value Itype. Assoc_Nod is the associated node of an itype. Itype is
17399 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
);
17400 pragma Inline
(Build_NCT_Tables
);
17401 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with the
17402 -- information supplied in entity map Entity_Map. The format of the
17403 -- entity map must be as follows:
17405 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
17407 function Copy_Any_Node_With_Replacement
17408 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
;
17409 pragma Inline
(Copy_Any_Node_With_Replacement
);
17410 -- Replicate entity or node N by invoking one of the following routines:
17412 -- Copy_Node_With_Replacement
17413 -- Corresponding_Entity
17415 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
;
17416 -- Replicate the elements of entity list List
17418 function Copy_Field_With_Replacement
17420 Old_Par
: Node_Id
:= Empty
;
17421 New_Par
: Node_Id
:= Empty
;
17422 Semantic
: Boolean := False) return Union_Id
;
17423 -- Replicate field Field by invoking one of the following routines:
17425 -- Copy_Elist_With_Replacement
17426 -- Copy_List_With_Replacement
17427 -- Copy_Node_With_Replacement
17428 -- Corresponding_Entity
17430 -- If the field is not an entity list, entity, itype, syntactic list,
17431 -- or node, then the field is returned unchanged. The routine always
17432 -- replicates entities, itypes, and valid syntactic fields. Old_Par is
17433 -- the expected parent of a syntactic field. New_Par is the new parent
17434 -- associated with a replicated syntactic field. Flag Semantic should
17435 -- be set when the input is a semantic field.
17437 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
;
17438 -- Replicate the elements of syntactic list List
17440 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
;
17441 -- Replicate node N
17443 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
;
17444 pragma Inline
(Corresponding_Entity
);
17445 -- Return the corresponding new entity of Id generated during Phase 1.
17446 -- If there is no such entity, return Id.
17448 function In_Entity_Map
17450 Entity_Map
: Elist_Id
) return Boolean;
17451 pragma Inline
(In_Entity_Map
);
17452 -- Determine whether entity Id is one of the old ids specified in entity
17453 -- map Entity_Map. The format of the entity map must be as follows:
17455 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
17457 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
);
17458 pragma Inline
(Update_CFS_Sloc
);
17459 -- Update the Comes_From_Source and Sloc attributes of node or entity N
17461 procedure Update_First_Real_Statement
17462 (Old_HSS
: Node_Id
;
17463 New_HSS
: Node_Id
);
17464 pragma Inline
(Update_First_Real_Statement
);
17465 -- Update semantic attribute First_Real_Statement of handled sequence of
17466 -- statements New_HSS based on handled sequence of statements Old_HSS.
17468 procedure Update_Named_Associations
17469 (Old_Call
: Node_Id
;
17470 New_Call
: Node_Id
);
17471 pragma Inline
(Update_Named_Associations
);
17472 -- Update semantic chain First/Next_Named_Association of call New_call
17473 -- based on call Old_Call.
17475 procedure Update_New_Entities
(Entity_Map
: Elist_Id
);
17476 pragma Inline
(Update_New_Entities
);
17477 -- Update the semantic attributes of all new entities generated during
17478 -- Phase 1 that do not appear in entity map Entity_Map. The format of
17479 -- the entity map must be as follows:
17481 -- Old_Id1, New_Id1, Old_Id2, New_Id2, .., Old_IdN, New_IdN
17483 procedure Update_Pending_Itypes
17484 (Old_Assoc
: Node_Id
;
17485 New_Assoc
: Node_Id
);
17486 pragma Inline
(Update_Pending_Itypes
);
17487 -- Update semantic attribute Associated_Node_For_Itype to refer to node
17488 -- New_Assoc for all itypes whose associated node is Old_Assoc.
17490 procedure Update_Semantic_Fields
(Id
: Entity_Id
);
17491 pragma Inline
(Update_Semantic_Fields
);
17492 -- Subsidiary to Update_New_Entities. Update semantic fields of entity
17495 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
);
17496 pragma Inline
(Visit_Any_Node
);
17497 -- Visit entity of node N by invoking one of the following routines:
17503 procedure Visit_Elist
(List
: Elist_Id
);
17504 -- Visit the elements of entity list List
17506 procedure Visit_Entity
(Id
: Entity_Id
);
17507 -- Visit entity Id. This action may create a new entity of Id and save
17508 -- it in table NCT_New_Entities.
17510 procedure Visit_Field
17512 Par_Nod
: Node_Id
:= Empty
;
17513 Semantic
: Boolean := False);
17514 -- Visit field Field by invoking one of the following routines:
17522 -- If the field is not an entity list, entity, itype, syntactic list,
17523 -- or node, then the field is not visited. The routine always visits
17524 -- valid syntactic fields. Par_Nod is the expected parent of the
17525 -- syntactic field. Flag Semantic should be set when the input is a
17528 procedure Visit_Itype
(Itype
: Entity_Id
);
17529 -- Visit itype Itype. This action may create a new entity for Itype and
17530 -- save it in table NCT_New_Entities. In addition, the routine may map
17531 -- the associated node of Itype to the new itype in NCT_Pending_Itypes.
17533 procedure Visit_List
(List
: List_Id
);
17534 -- Visit the elements of syntactic list List
17536 procedure Visit_Node
(N
: Node_Id
);
17539 procedure Visit_Semantic_Fields
(Id
: Entity_Id
);
17540 pragma Inline
(Visit_Semantic_Fields
);
17541 -- Subsidiary to Visit_Entity and Visit_Itype. Visit common semantic
17542 -- fields of entity or itype Id.
17544 --------------------
17545 -- Add_New_Entity --
17546 --------------------
17548 procedure Add_New_Entity
(Old_Id
: Entity_Id
; New_Id
: Entity_Id
) is
17550 pragma Assert
(Present
(Old_Id
));
17551 pragma Assert
(Present
(New_Id
));
17552 pragma Assert
(Nkind
(Old_Id
) in N_Entity
);
17553 pragma Assert
(Nkind
(New_Id
) in N_Entity
);
17555 NCT_Tables_In_Use
:= True;
17557 -- Sanity check the NCT_New_Entities table. No previous mapping with
17558 -- key Old_Id should exist.
17560 pragma Assert
(No
(NCT_New_Entities
.Get
(Old_Id
)));
17562 -- Establish the mapping
17564 -- Old_Id -> New_Id
17566 NCT_New_Entities
.Set
(Old_Id
, New_Id
);
17567 end Add_New_Entity
;
17569 -----------------------
17570 -- Add_Pending_Itype --
17571 -----------------------
17573 procedure Add_Pending_Itype
(Assoc_Nod
: Node_Id
; Itype
: Entity_Id
) is
17577 pragma Assert
(Present
(Assoc_Nod
));
17578 pragma Assert
(Present
(Itype
));
17579 pragma Assert
(Nkind
(Itype
) in N_Entity
);
17580 pragma Assert
(Is_Itype
(Itype
));
17582 NCT_Tables_In_Use
:= True;
17584 -- It is not possible to sanity check the NCT_Pendint_Itypes table
17585 -- directly because a single node may act as the associated node for
17586 -- multiple itypes.
17588 Itypes
:= NCT_Pending_Itypes
.Get
(Assoc_Nod
);
17590 if No
(Itypes
) then
17591 Itypes
:= New_Elmt_List
;
17592 NCT_Pending_Itypes
.Set
(Assoc_Nod
, Itypes
);
17595 -- Establish the mapping
17597 -- Assoc_Nod -> (Itype, ...)
17599 -- Avoid inserting the same itype multiple times. This involves a
17600 -- linear search, however the set of itypes with the same associated
17601 -- node is very small.
17603 Append_Unique_Elmt
(Itype
, Itypes
);
17604 end Add_Pending_Itype
;
17606 ----------------------
17607 -- Build_NCT_Tables --
17608 ----------------------
17610 procedure Build_NCT_Tables
(Entity_Map
: Elist_Id
) is
17612 Old_Id
: Entity_Id
;
17613 New_Id
: Entity_Id
;
17616 -- Nothing to do when there is no entity map
17618 if No
(Entity_Map
) then
17622 Elmt
:= First_Elmt
(Entity_Map
);
17623 while Present
(Elmt
) loop
17625 -- Extract the (Old_Id, New_Id) pair from the entity map
17627 Old_Id
:= Node
(Elmt
);
17630 New_Id
:= Node
(Elmt
);
17633 -- Establish the following mapping within table NCT_New_Entities
17635 -- Old_Id -> New_Id
17637 Add_New_Entity
(Old_Id
, New_Id
);
17639 -- Establish the following mapping within table NCT_Pending_Itypes
17640 -- when the new entity is an itype.
17642 -- Assoc_Nod -> (New_Id, ...)
17644 -- IMPORTANT: the associated node is that of the old itype because
17645 -- the node will be replicated in Phase 2.
17647 if Is_Itype
(Old_Id
) then
17649 (Assoc_Nod
=> Associated_Node_For_Itype
(Old_Id
),
17653 end Build_NCT_Tables
;
17655 ------------------------------------
17656 -- Copy_Any_Node_With_Replacement --
17657 ------------------------------------
17659 function Copy_Any_Node_With_Replacement
17660 (N
: Node_Or_Entity_Id
) return Node_Or_Entity_Id
17663 if Nkind
(N
) in N_Entity
then
17664 return Corresponding_Entity
(N
);
17666 return Copy_Node_With_Replacement
(N
);
17668 end Copy_Any_Node_With_Replacement
;
17670 ---------------------------------
17671 -- Copy_Elist_With_Replacement --
17672 ---------------------------------
17674 function Copy_Elist_With_Replacement
(List
: Elist_Id
) return Elist_Id
is
17679 -- Copy the contents of the old list. Note that the list itself may
17680 -- be empty, in which case the routine returns a new empty list. This
17681 -- avoids sharing lists between subtrees. The element of an entity
17682 -- list could be an entity or a node, hence the invocation of routine
17683 -- Copy_Any_Node_With_Replacement.
17685 if Present
(List
) then
17686 Result
:= New_Elmt_List
;
17688 Elmt
:= First_Elmt
(List
);
17689 while Present
(Elmt
) loop
17691 (Copy_Any_Node_With_Replacement
(Node
(Elmt
)), Result
);
17696 -- Otherwise the list does not exist
17699 Result
:= No_Elist
;
17703 end Copy_Elist_With_Replacement
;
17705 ---------------------------------
17706 -- Copy_Field_With_Replacement --
17707 ---------------------------------
17709 function Copy_Field_With_Replacement
17711 Old_Par
: Node_Id
:= Empty
;
17712 New_Par
: Node_Id
:= Empty
;
17713 Semantic
: Boolean := False) return Union_Id
17716 -- The field is empty
17718 if Field
= Union_Id
(Empty
) then
17721 -- The field is an entity/itype/node
17723 elsif Field
in Node_Range
then
17725 Old_N
: constant Node_Id
:= Node_Id
(Field
);
17726 Syntactic
: constant Boolean := Parent
(Old_N
) = Old_Par
;
17731 -- The field is an entity/itype
17733 if Nkind
(Old_N
) in N_Entity
then
17735 -- An entity/itype is always replicated
17737 New_N
:= Corresponding_Entity
(Old_N
);
17739 -- Update the parent pointer when the entity is a syntactic
17740 -- field. Note that itypes do not have parent pointers.
17742 if Syntactic
and then New_N
/= Old_N
then
17743 Set_Parent
(New_N
, New_Par
);
17746 -- The field is a node
17749 -- A node is replicated when it is either a syntactic field
17750 -- or when the caller treats it as a semantic attribute.
17752 if Syntactic
or else Semantic
then
17753 New_N
:= Copy_Node_With_Replacement
(Old_N
);
17755 -- Update the parent pointer when the node is a syntactic
17758 if Syntactic
and then New_N
/= Old_N
then
17759 Set_Parent
(New_N
, New_Par
);
17762 -- Otherwise the node is returned unchanged
17769 return Union_Id
(New_N
);
17772 -- The field is an entity list
17774 elsif Field
in Elist_Range
then
17775 return Union_Id
(Copy_Elist_With_Replacement
(Elist_Id
(Field
)));
17777 -- The field is a syntactic list
17779 elsif Field
in List_Range
then
17781 Old_List
: constant List_Id
:= List_Id
(Field
);
17782 Syntactic
: constant Boolean := Parent
(Old_List
) = Old_Par
;
17784 New_List
: List_Id
;
17787 -- A list is replicated when it is either a syntactic field or
17788 -- when the caller treats it as a semantic attribute.
17790 if Syntactic
or else Semantic
then
17791 New_List
:= Copy_List_With_Replacement
(Old_List
);
17793 -- Update the parent pointer when the list is a syntactic
17796 if Syntactic
and then New_List
/= Old_List
then
17797 Set_Parent
(New_List
, New_Par
);
17800 -- Otherwise the list is returned unchanged
17803 New_List
:= Old_List
;
17806 return Union_Id
(New_List
);
17809 -- Otherwise the field denotes an attribute that does not need to be
17810 -- replicated (Chars, literals, etc).
17815 end Copy_Field_With_Replacement
;
17817 --------------------------------
17818 -- Copy_List_With_Replacement --
17819 --------------------------------
17821 function Copy_List_With_Replacement
(List
: List_Id
) return List_Id
is
17826 -- Copy the contents of the old list. Note that the list itself may
17827 -- be empty, in which case the routine returns a new empty list. This
17828 -- avoids sharing lists between subtrees. The element of a syntactic
17829 -- list is always a node, never an entity or itype, hence the call to
17830 -- routine Copy_Node_With_Replacement.
17832 if Present
(List
) then
17833 Result
:= New_List
;
17835 Elmt
:= First
(List
);
17836 while Present
(Elmt
) loop
17837 Append
(Copy_Node_With_Replacement
(Elmt
), Result
);
17842 -- Otherwise the list does not exist
17849 end Copy_List_With_Replacement
;
17851 --------------------------------
17852 -- Copy_Node_With_Replacement --
17853 --------------------------------
17855 function Copy_Node_With_Replacement
(N
: Node_Id
) return Node_Id
is
17859 -- Assume that the node must be returned unchanged
17863 if N
> Empty_Or_Error
then
17864 pragma Assert
(Nkind
(N
) not in N_Entity
);
17866 Result
:= New_Copy
(N
);
17868 Set_Field1
(Result
,
17869 Copy_Field_With_Replacement
17870 (Field
=> Field1
(Result
),
17872 New_Par
=> Result
));
17874 Set_Field2
(Result
,
17875 Copy_Field_With_Replacement
17876 (Field
=> Field2
(Result
),
17878 New_Par
=> Result
));
17880 Set_Field3
(Result
,
17881 Copy_Field_With_Replacement
17882 (Field
=> Field3
(Result
),
17884 New_Par
=> Result
));
17886 Set_Field4
(Result
,
17887 Copy_Field_With_Replacement
17888 (Field
=> Field4
(Result
),
17890 New_Par
=> Result
));
17892 Set_Field5
(Result
,
17893 Copy_Field_With_Replacement
17894 (Field
=> Field5
(Result
),
17896 New_Par
=> Result
));
17898 -- Update the Comes_From_Source and Sloc attributes of the node
17899 -- in case the caller has supplied new values.
17901 Update_CFS_Sloc
(Result
);
17903 -- Update the Associated_Node_For_Itype attribute of all itypes
17904 -- created during Phase 1 whose associated node is N. As a result
17905 -- the Associated_Node_For_Itype refers to the replicated node.
17906 -- No action needs to be taken when the Associated_Node_For_Itype
17907 -- refers to an entity because this was already handled during
17908 -- Phase 1, in Visit_Itype.
17910 Update_Pending_Itypes
17912 New_Assoc
=> Result
);
17914 -- Update the First/Next_Named_Association chain for a replicated
17917 if Nkind_In
(N
, N_Entry_Call_Statement
,
17919 N_Procedure_Call_Statement
)
17921 Update_Named_Associations
17923 New_Call
=> Result
);
17925 -- Update the Renamed_Object attribute of a replicated object
17928 elsif Nkind
(N
) = N_Object_Renaming_Declaration
then
17929 Set_Renamed_Object
(Defining_Entity
(Result
), Name
(Result
));
17931 -- Update the First_Real_Statement attribute of a replicated
17932 -- handled sequence of statements.
17934 elsif Nkind
(N
) = N_Handled_Sequence_Of_Statements
then
17935 Update_First_Real_Statement
17937 New_HSS
=> Result
);
17942 end Copy_Node_With_Replacement
;
17944 --------------------------
17945 -- Corresponding_Entity --
17946 --------------------------
17948 function Corresponding_Entity
(Id
: Entity_Id
) return Entity_Id
is
17949 New_Id
: Entity_Id
;
17950 Result
: Entity_Id
;
17953 -- Assume that the entity must be returned unchanged
17957 if Id
> Empty_Or_Error
then
17958 pragma Assert
(Nkind
(Id
) in N_Entity
);
17960 -- Determine whether the entity has a corresponding new entity
17961 -- generated during Phase 1 and if it does, use it.
17963 if NCT_Tables_In_Use
then
17964 New_Id
:= NCT_New_Entities
.Get
(Id
);
17966 if Present
(New_Id
) then
17973 end Corresponding_Entity
;
17975 -------------------
17976 -- In_Entity_Map --
17977 -------------------
17979 function In_Entity_Map
17981 Entity_Map
: Elist_Id
) return Boolean
17984 Old_Id
: Entity_Id
;
17987 -- The entity map contains pairs (Old_Id, New_Id). The advancement
17988 -- step always skips the New_Id portion of the pair.
17990 if Present
(Entity_Map
) then
17991 Elmt
:= First_Elmt
(Entity_Map
);
17992 while Present
(Elmt
) loop
17993 Old_Id
:= Node
(Elmt
);
17995 if Old_Id
= Id
then
18007 ---------------------
18008 -- Update_CFS_Sloc --
18009 ---------------------
18011 procedure Update_CFS_Sloc
(N
: Node_Or_Entity_Id
) is
18013 -- A new source location defaults the Comes_From_Source attribute
18015 if New_Sloc
/= No_Location
then
18016 Set_Comes_From_Source
(N
, Default_Node
.Comes_From_Source
);
18017 Set_Sloc
(N
, New_Sloc
);
18019 end Update_CFS_Sloc
;
18021 ---------------------------------
18022 -- Update_First_Real_Statement --
18023 ---------------------------------
18025 procedure Update_First_Real_Statement
18026 (Old_HSS
: Node_Id
;
18029 Old_First_Stmt
: constant Node_Id
:= First_Real_Statement
(Old_HSS
);
18031 New_Stmt
: Node_Id
;
18032 Old_Stmt
: Node_Id
;
18035 -- Recreate the First_Real_Statement attribute of a handled sequence
18036 -- of statements by traversing the statement lists of both sequences
18039 if Present
(Old_First_Stmt
) then
18040 New_Stmt
:= First
(Statements
(New_HSS
));
18041 Old_Stmt
:= First
(Statements
(Old_HSS
));
18042 while Present
(Old_Stmt
) and then Old_Stmt
/= Old_First_Stmt
loop
18047 pragma Assert
(Present
(New_Stmt
));
18048 pragma Assert
(Present
(Old_Stmt
));
18050 Set_First_Real_Statement
(New_HSS
, New_Stmt
);
18052 end Update_First_Real_Statement
;
18054 -------------------------------
18055 -- Update_Named_Associations --
18056 -------------------------------
18058 procedure Update_Named_Associations
18059 (Old_Call
: Node_Id
;
18060 New_Call
: Node_Id
)
18063 New_Next
: Node_Id
;
18065 Old_Next
: Node_Id
;
18068 -- Recreate the First/Next_Named_Actual chain of a call by traversing
18069 -- the chains of both the old and new calls in parallel.
18071 New_Act
:= First
(Parameter_Associations
(New_Call
));
18072 Old_Act
:= First
(Parameter_Associations
(Old_Call
));
18073 while Present
(Old_Act
) loop
18074 if Nkind
(Old_Act
) = N_Parameter_Association
18075 and then Present
(Next_Named_Actual
(Old_Act
))
18077 if First_Named_Actual
(Old_Call
) =
18078 Explicit_Actual_Parameter
(Old_Act
)
18080 Set_First_Named_Actual
(New_Call
,
18081 Explicit_Actual_Parameter
(New_Act
));
18084 -- Scan the actual parameter list to find the next suitable
18085 -- named actual. Note that the list may be out of order.
18087 New_Next
:= First
(Parameter_Associations
(New_Call
));
18088 Old_Next
:= First
(Parameter_Associations
(Old_Call
));
18089 while Nkind
(Old_Next
) /= N_Parameter_Association
18090 or else Explicit_Actual_Parameter
(Old_Next
) /=
18091 Next_Named_Actual
(Old_Act
)
18097 Set_Next_Named_Actual
(New_Act
,
18098 Explicit_Actual_Parameter
(New_Next
));
18104 end Update_Named_Associations
;
18106 -------------------------
18107 -- Update_New_Entities --
18108 -------------------------
18110 procedure Update_New_Entities
(Entity_Map
: Elist_Id
) is
18111 New_Id
: Entity_Id
:= Empty
;
18112 Old_Id
: Entity_Id
:= Empty
;
18115 if NCT_Tables_In_Use
then
18116 NCT_New_Entities
.Get_First
(Old_Id
, New_Id
);
18118 -- Update the semantic fields of all new entities created during
18119 -- Phase 1 which were not supplied via an entity map.
18120 -- ??? Is there a better way of distinguishing those?
18122 while Present
(Old_Id
) and then Present
(New_Id
) loop
18123 if not (Present
(Entity_Map
)
18124 and then In_Entity_Map
(Old_Id
, Entity_Map
))
18126 Update_Semantic_Fields
(New_Id
);
18129 NCT_New_Entities
.Get_Next
(Old_Id
, New_Id
);
18132 end Update_New_Entities
;
18134 ---------------------------
18135 -- Update_Pending_Itypes --
18136 ---------------------------
18138 procedure Update_Pending_Itypes
18139 (Old_Assoc
: Node_Id
;
18140 New_Assoc
: Node_Id
)
18146 if NCT_Tables_In_Use
then
18147 Itypes
:= NCT_Pending_Itypes
.Get
(Old_Assoc
);
18149 -- Update the Associated_Node_For_Itype attribute for all itypes
18150 -- which originally refer to Old_Assoc to designate New_Assoc.
18152 if Present
(Itypes
) then
18153 Item
:= First_Elmt
(Itypes
);
18154 while Present
(Item
) loop
18155 Set_Associated_Node_For_Itype
(Node
(Item
), New_Assoc
);
18161 end Update_Pending_Itypes
;
18163 ----------------------------
18164 -- Update_Semantic_Fields --
18165 ----------------------------
18167 procedure Update_Semantic_Fields
(Id
: Entity_Id
) is
18169 -- Discriminant_Constraint
18171 if Has_Discriminants
(Base_Type
(Id
)) then
18172 Set_Discriminant_Constraint
(Id
, Elist_Id
(
18173 Copy_Field_With_Replacement
18174 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
18175 Semantic
=> True)));
18180 Set_Etype
(Id
, Node_Id
(
18181 Copy_Field_With_Replacement
18182 (Field
=> Union_Id
(Etype
(Id
)),
18183 Semantic
=> True)));
18186 -- Packed_Array_Impl_Type
18188 if Is_Array_Type
(Id
) then
18189 if Present
(First_Index
(Id
)) then
18190 Set_First_Index
(Id
, First
(List_Id
(
18191 Copy_Field_With_Replacement
18192 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
18193 Semantic
=> True))));
18196 if Is_Packed
(Id
) then
18197 Set_Packed_Array_Impl_Type
(Id
, Node_Id
(
18198 Copy_Field_With_Replacement
18199 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
18200 Semantic
=> True)));
18206 Set_Next_Entity
(Id
, Node_Id
(
18207 Copy_Field_With_Replacement
18208 (Field
=> Union_Id
(Next_Entity
(Id
)),
18209 Semantic
=> True)));
18213 if Is_Discrete_Type
(Id
) then
18214 Set_Scalar_Range
(Id
, Node_Id
(
18215 Copy_Field_With_Replacement
18216 (Field
=> Union_Id
(Scalar_Range
(Id
)),
18217 Semantic
=> True)));
18222 -- Update the scope when the caller specified an explicit one
18224 if Present
(New_Scope
) then
18225 Set_Scope
(Id
, New_Scope
);
18227 Set_Scope
(Id
, Node_Id
(
18228 Copy_Field_With_Replacement
18229 (Field
=> Union_Id
(Scope
(Id
)),
18230 Semantic
=> True)));
18232 end Update_Semantic_Fields
;
18234 --------------------
18235 -- Visit_Any_Node --
18236 --------------------
18238 procedure Visit_Any_Node
(N
: Node_Or_Entity_Id
) is
18240 if Nkind
(N
) in N_Entity
then
18241 if Is_Itype
(N
) then
18249 end Visit_Any_Node
;
18255 procedure Visit_Elist
(List
: Elist_Id
) is
18259 -- The element of an entity list could be an entity, itype, or a
18260 -- node, hence the call to Visit_Any_Node.
18262 if Present
(List
) then
18263 Elmt
:= First_Elmt
(List
);
18264 while Present
(Elmt
) loop
18265 Visit_Any_Node
(Node
(Elmt
));
18276 procedure Visit_Entity
(Id
: Entity_Id
) is
18277 New_Id
: Entity_Id
;
18280 pragma Assert
(Nkind
(Id
) in N_Entity
);
18281 pragma Assert
(not Is_Itype
(Id
));
18283 -- Nothing to do if the entity is not defined in the Actions list of
18284 -- an N_Expression_With_Actions node.
18286 if EWA_Level
= 0 then
18289 -- Nothing to do if the entity is defined within a scoping construct
18290 -- of an N_Expression_With_Actions node.
18292 elsif EWA_Inner_Scope_Level
> 0 then
18295 -- Nothing to do if the entity is not an object or a type. Relaxing
18296 -- this restriction leads to a performance penalty.
18298 elsif not Ekind_In
(Id
, E_Constant
, E_Variable
)
18299 and then not Is_Type
(Id
)
18303 -- Nothing to do if the entity was already visited
18305 elsif NCT_Tables_In_Use
18306 and then Present
(NCT_New_Entities
.Get
(Id
))
18310 -- Nothing to do if the declaration node of the entity is not within
18311 -- the subtree being replicated.
18313 elsif not In_Subtree
18315 N
=> Declaration_Node
(Id
))
18320 -- Create a new entity by directly copying the old entity. This
18321 -- action causes all attributes of the old entity to be inherited.
18323 New_Id
:= New_Copy
(Id
);
18325 -- Create a new name for the new entity because the back end needs
18326 -- distinct names for debugging purposes.
18328 Set_Chars
(New_Id
, New_Internal_Name
('T'));
18330 -- Update the Comes_From_Source and Sloc attributes of the entity in
18331 -- case the caller has supplied new values.
18333 Update_CFS_Sloc
(New_Id
);
18335 -- Establish the following mapping within table NCT_New_Entities:
18339 Add_New_Entity
(Id
, New_Id
);
18341 -- Deal with the semantic fields of entities. The fields are visited
18342 -- because they may mention entities which reside within the subtree
18345 Visit_Semantic_Fields
(Id
);
18352 procedure Visit_Field
18354 Par_Nod
: Node_Id
:= Empty
;
18355 Semantic
: Boolean := False)
18358 -- The field is empty
18360 if Field
= Union_Id
(Empty
) then
18363 -- The field is an entity/itype/node
18365 elsif Field
in Node_Range
then
18367 N
: constant Node_Id
:= Node_Id
(Field
);
18370 -- The field is an entity/itype
18372 if Nkind
(N
) in N_Entity
then
18374 -- Itypes are always visited
18376 if Is_Itype
(N
) then
18379 -- An entity is visited when it is either a syntactic field
18380 -- or when the caller treats it as a semantic attribute.
18382 elsif Parent
(N
) = Par_Nod
or else Semantic
then
18386 -- The field is a node
18389 -- A node is visited when it is either a syntactic field or
18390 -- when the caller treats it as a semantic attribute.
18392 if Parent
(N
) = Par_Nod
or else Semantic
then
18398 -- The field is an entity list
18400 elsif Field
in Elist_Range
then
18401 Visit_Elist
(Elist_Id
(Field
));
18403 -- The field is a syntax list
18405 elsif Field
in List_Range
then
18407 List
: constant List_Id
:= List_Id
(Field
);
18410 -- A syntax list is visited when it is either a syntactic field
18411 -- or when the caller treats it as a semantic attribute.
18413 if Parent
(List
) = Par_Nod
or else Semantic
then
18418 -- Otherwise the field denotes information which does not need to be
18419 -- visited (chars, literals, etc.).
18430 procedure Visit_Itype
(Itype
: Entity_Id
) is
18431 New_Assoc
: Node_Id
;
18432 New_Itype
: Entity_Id
;
18433 Old_Assoc
: Node_Id
;
18436 pragma Assert
(Nkind
(Itype
) in N_Entity
);
18437 pragma Assert
(Is_Itype
(Itype
));
18439 -- Itypes that describe the designated type of access to subprograms
18440 -- have the structure of subprogram declarations, with signatures,
18441 -- etc. Either we duplicate the signatures completely, or choose to
18442 -- share such itypes, which is fine because their elaboration will
18443 -- have no side effects.
18445 if Ekind
(Itype
) = E_Subprogram_Type
then
18448 -- Nothing to do if the itype was already visited
18450 elsif NCT_Tables_In_Use
18451 and then Present
(NCT_New_Entities
.Get
(Itype
))
18455 -- Nothing to do if the associated node of the itype is not within
18456 -- the subtree being replicated.
18458 elsif not In_Subtree
18460 N
=> Associated_Node_For_Itype
(Itype
))
18465 -- Create a new itype by directly copying the old itype. This action
18466 -- causes all attributes of the old itype to be inherited.
18468 New_Itype
:= New_Copy
(Itype
);
18470 -- Create a new name for the new itype because the back end requires
18471 -- distinct names for debugging purposes.
18473 Set_Chars
(New_Itype
, New_Internal_Name
('T'));
18475 -- Update the Comes_From_Source and Sloc attributes of the itype in
18476 -- case the caller has supplied new values.
18478 Update_CFS_Sloc
(New_Itype
);
18480 -- Establish the following mapping within table NCT_New_Entities:
18482 -- Itype -> New_Itype
18484 Add_New_Entity
(Itype
, New_Itype
);
18486 -- The new itype must be unfrozen because the resulting subtree may
18487 -- be inserted anywhere and cause an earlier or later freezing.
18489 if Present
(Freeze_Node
(New_Itype
)) then
18490 Set_Freeze_Node
(New_Itype
, Empty
);
18491 Set_Is_Frozen
(New_Itype
, False);
18494 -- If a record subtype is simply copied, the entity list will be
18495 -- shared. Thus cloned_Subtype must be set to indicate the sharing.
18496 -- ??? What does this do?
18498 if Ekind_In
(Itype
, E_Class_Wide_Subtype
, E_Record_Subtype
) then
18499 Set_Cloned_Subtype
(New_Itype
, Itype
);
18502 -- The associated node may denote an entity, in which case it may
18503 -- already have a new corresponding entity created during a prior
18504 -- call to Visit_Entity or Visit_Itype for the same subtree.
18507 -- Old_Assoc ---------> New_Assoc
18509 -- Created by Visit_Itype
18510 -- Itype -------------> New_Itype
18511 -- ANFI = Old_Assoc ANFI = Old_Assoc < must be updated
18513 -- In the example above, Old_Assoc is an arbitrary entity that was
18514 -- already visited for the same subtree and has a corresponding new
18515 -- entity New_Assoc. Old_Assoc was inherited by New_Itype by virtue
18516 -- of copying entities, however it must be updated to New_Assoc.
18518 Old_Assoc
:= Associated_Node_For_Itype
(Itype
);
18520 if Nkind
(Old_Assoc
) in N_Entity
then
18521 if NCT_Tables_In_Use
then
18522 New_Assoc
:= NCT_New_Entities
.Get
(Old_Assoc
);
18524 if Present
(New_Assoc
) then
18525 Set_Associated_Node_For_Itype
(New_Itype
, New_Assoc
);
18529 -- Otherwise the associated node denotes a node. Postpone the update
18530 -- until Phase 2 when the node is replicated. Establish the following
18531 -- mapping within table NCT_Pending_Itypes:
18533 -- Old_Assoc -> (New_Type, ...)
18536 Add_Pending_Itype
(Old_Assoc
, New_Itype
);
18539 -- Deal with the semantic fields of itypes. The fields are visited
18540 -- because they may mention entities that reside within the subtree
18543 Visit_Semantic_Fields
(Itype
);
18550 procedure Visit_List
(List
: List_Id
) is
18554 -- Note that the element of a syntactic list is always a node, never
18555 -- an entity or itype, hence the call to Visit_Node.
18557 if Present
(List
) then
18558 Elmt
:= First
(List
);
18559 while Present
(Elmt
) loop
18571 procedure Visit_Node
(N
: Node_Or_Entity_Id
) is
18573 pragma Assert
(Nkind
(N
) not in N_Entity
);
18575 if Nkind
(N
) = N_Expression_With_Actions
then
18576 EWA_Level
:= EWA_Level
+ 1;
18578 elsif EWA_Level
> 0
18579 and then Nkind_In
(N
, N_Block_Statement
,
18581 N_Subprogram_Declaration
)
18583 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
+ 1;
18587 (Field
=> Field1
(N
),
18591 (Field
=> Field2
(N
),
18595 (Field
=> Field3
(N
),
18599 (Field
=> Field4
(N
),
18603 (Field
=> Field5
(N
),
18607 and then Nkind_In
(N
, N_Block_Statement
,
18609 N_Subprogram_Declaration
)
18611 EWA_Inner_Scope_Level
:= EWA_Inner_Scope_Level
- 1;
18613 elsif Nkind
(N
) = N_Expression_With_Actions
then
18614 EWA_Level
:= EWA_Level
- 1;
18618 ---------------------------
18619 -- Visit_Semantic_Fields --
18620 ---------------------------
18622 procedure Visit_Semantic_Fields
(Id
: Entity_Id
) is
18624 pragma Assert
(Nkind
(Id
) in N_Entity
);
18626 -- Discriminant_Constraint
18628 if Has_Discriminants
(Base_Type
(Id
)) then
18630 (Field
=> Union_Id
(Discriminant_Constraint
(Id
)),
18637 (Field
=> Union_Id
(Etype
(Id
)),
18641 -- Packed_Array_Impl_Type
18643 if Is_Array_Type
(Id
) then
18644 if Present
(First_Index
(Id
)) then
18646 (Field
=> Union_Id
(List_Containing
(First_Index
(Id
))),
18650 if Is_Packed
(Id
) then
18652 (Field
=> Union_Id
(Packed_Array_Impl_Type
(Id
)),
18659 if Is_Discrete_Type
(Id
) then
18661 (Field
=> Union_Id
(Scalar_Range
(Id
)),
18664 end Visit_Semantic_Fields
;
18666 -- Start of processing for New_Copy_Tree
18669 -- Routine New_Copy_Tree performs a deep copy of a subtree by creating
18670 -- shallow copies for each node within, and then updating the child and
18671 -- parent pointers accordingly. This process is straightforward, however
18672 -- the routine must deal with the following complications:
18674 -- * Entities defined within N_Expression_With_Actions nodes must be
18675 -- replicated rather than shared to avoid introducing two identical
18676 -- symbols within the same scope. Note that no other expression can
18677 -- currently define entities.
18680 -- Source_Low : ...;
18681 -- Source_High : ...;
18683 -- <reference to Source_Low>
18684 -- <reference to Source_High>
18687 -- New_Copy_Tree handles this case by first creating new entities
18688 -- and then updating all existing references to point to these new
18695 -- <reference to New_Low>
18696 -- <reference to New_High>
18699 -- * Itypes defined within the subtree must be replicated to avoid any
18700 -- dependencies on invalid or inaccessible data.
18702 -- subtype Source_Itype is ... range Source_Low .. Source_High;
18704 -- New_Copy_Tree handles this case by first creating a new itype in
18705 -- the same fashion as entities, and then updating various relevant
18708 -- subtype New_Itype is ... range New_Low .. New_High;
18710 -- * The Associated_Node_For_Itype field of itypes must be updated to
18711 -- reference the proper replicated entity or node.
18713 -- * Semantic fields of entities such as Etype and Scope must be
18714 -- updated to reference the proper replicated entities.
18716 -- * Semantic fields of nodes such as First_Real_Statement must be
18717 -- updated to reference the proper replicated nodes.
18719 -- To meet all these demands, routine New_Copy_Tree is split into two
18722 -- Phase 1 traverses the tree in order to locate entities and itypes
18723 -- defined within the subtree. New entities are generated and saved in
18724 -- table NCT_New_Entities. The semantic fields of all new entities and
18725 -- itypes are then updated accordingly.
18727 -- Phase 2 traverses the tree in order to replicate each node. Various
18728 -- semantic fields of nodes and entities are updated accordingly.
18730 -- Preparatory phase. Clear the contents of tables NCT_New_Entities and
18731 -- NCT_Pending_Itypes in case a previous call to New_Copy_Tree left some
18734 if NCT_Tables_In_Use
then
18735 NCT_Tables_In_Use
:= False;
18737 NCT_New_Entities
.Reset
;
18738 NCT_Pending_Itypes
.Reset
;
18741 -- Populate tables NCT_New_Entities and NCT_Pending_Itypes with data
18742 -- supplied by a linear entity map. The tables offer faster access to
18745 Build_NCT_Tables
(Map
);
18747 -- Execute Phase 1. Traverse the subtree and generate new entities for
18748 -- the following cases:
18750 -- * An entity defined within an N_Expression_With_Actions node
18752 -- * An itype referenced within the subtree where the associated node
18753 -- is also in the subtree.
18755 -- All new entities are accessible via table NCT_New_Entities, which
18756 -- contains mappings of the form:
18758 -- Old_Entity -> New_Entity
18759 -- Old_Itype -> New_Itype
18761 -- In addition, the associated nodes of all new itypes are mapped in
18762 -- table NCT_Pending_Itypes:
18764 -- Assoc_Nod -> (New_Itype1, New_Itype2, .., New_ItypeN)
18766 Visit_Any_Node
(Source
);
18768 -- Update the semantic attributes of all new entities generated during
18769 -- Phase 1 before starting Phase 2. The updates could be performed in
18770 -- routine Corresponding_Entity, however this may cause the same entity
18771 -- to be updated multiple times, effectively generating useless nodes.
18772 -- Keeping the updates separates from Phase 2 ensures that only one set
18773 -- of attributes is generated for an entity at any one time.
18775 Update_New_Entities
(Map
);
18777 -- Execute Phase 2. Replicate the source subtree one node at a time.
18778 -- The following transformations take place:
18780 -- * References to entities and itypes are updated to refer to the
18781 -- new entities and itypes generated during Phase 1.
18783 -- * All Associated_Node_For_Itype attributes of itypes are updated
18784 -- to refer to the new replicated Associated_Node_For_Itype.
18786 return Copy_Node_With_Replacement
(Source
);
18789 -------------------------
18790 -- New_External_Entity --
18791 -------------------------
18793 function New_External_Entity
18794 (Kind
: Entity_Kind
;
18795 Scope_Id
: Entity_Id
;
18796 Sloc_Value
: Source_Ptr
;
18797 Related_Id
: Entity_Id
;
18798 Suffix
: Character;
18799 Suffix_Index
: Nat
:= 0;
18800 Prefix
: Character := ' ') return Entity_Id
18802 N
: constant Entity_Id
:=
18803 Make_Defining_Identifier
(Sloc_Value
,
18805 (Chars
(Related_Id
), Suffix
, Suffix_Index
, Prefix
));
18808 Set_Ekind
(N
, Kind
);
18809 Set_Is_Internal
(N
, True);
18810 Append_Entity
(N
, Scope_Id
);
18811 Set_Public_Status
(N
);
18813 if Kind
in Type_Kind
then
18814 Init_Size_Align
(N
);
18818 end New_External_Entity
;
18820 -------------------------
18821 -- New_Internal_Entity --
18822 -------------------------
18824 function New_Internal_Entity
18825 (Kind
: Entity_Kind
;
18826 Scope_Id
: Entity_Id
;
18827 Sloc_Value
: Source_Ptr
;
18828 Id_Char
: Character) return Entity_Id
18830 N
: constant Entity_Id
:= Make_Temporary
(Sloc_Value
, Id_Char
);
18833 Set_Ekind
(N
, Kind
);
18834 Set_Is_Internal
(N
, True);
18835 Append_Entity
(N
, Scope_Id
);
18837 if Kind
in Type_Kind
then
18838 Init_Size_Align
(N
);
18842 end New_Internal_Entity
;
18848 function Next_Actual
(Actual_Id
: Node_Id
) return Node_Id
is
18852 -- If we are pointing at a positional parameter, it is a member of a
18853 -- node list (the list of parameters), and the next parameter is the
18854 -- next node on the list, unless we hit a parameter association, then
18855 -- we shift to using the chain whose head is the First_Named_Actual in
18856 -- the parent, and then is threaded using the Next_Named_Actual of the
18857 -- Parameter_Association. All this fiddling is because the original node
18858 -- list is in the textual call order, and what we need is the
18859 -- declaration order.
18861 if Is_List_Member
(Actual_Id
) then
18862 N
:= Next
(Actual_Id
);
18864 if Nkind
(N
) = N_Parameter_Association
then
18865 return First_Named_Actual
(Parent
(Actual_Id
));
18871 return Next_Named_Actual
(Parent
(Actual_Id
));
18875 procedure Next_Actual
(Actual_Id
: in out Node_Id
) is
18877 Actual_Id
:= Next_Actual
(Actual_Id
);
18880 ----------------------------------
18881 -- New_Requires_Transient_Scope --
18882 ----------------------------------
18884 function New_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
18885 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean;
18886 -- This is called for untagged records and protected types, with
18887 -- nondefaulted discriminants. Returns True if the size of function
18888 -- results is known at the call site, False otherwise. Returns False
18889 -- if there is a variant part that depends on the discriminants of
18890 -- this type, or if there is an array constrained by the discriminants
18891 -- of this type. ???Currently, this is overly conservative (the array
18892 -- could be nested inside some other record that is constrained by
18893 -- nondiscriminants). That is, the recursive calls are too conservative.
18895 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean;
18896 -- Returns True if Typ is a nonlimited record with defaulted
18897 -- discriminants whose max size makes it unsuitable for allocating on
18898 -- the primary stack.
18900 ------------------------------
18901 -- Caller_Known_Size_Record --
18902 ------------------------------
18904 function Caller_Known_Size_Record
(Typ
: Entity_Id
) return Boolean is
18905 pragma Assert
(Typ
= Underlying_Type
(Typ
));
18908 if Has_Variant_Part
(Typ
) and then not Is_Definite_Subtype
(Typ
) then
18916 Comp
:= First_Entity
(Typ
);
18917 while Present
(Comp
) loop
18919 -- Only look at E_Component entities. No need to look at
18920 -- E_Discriminant entities, and we must ignore internal
18921 -- subtypes generated for constrained components.
18923 if Ekind
(Comp
) = E_Component
then
18925 Comp_Type
: constant Entity_Id
:=
18926 Underlying_Type
(Etype
(Comp
));
18929 if Is_Record_Type
(Comp_Type
)
18931 Is_Protected_Type
(Comp_Type
)
18933 if not Caller_Known_Size_Record
(Comp_Type
) then
18937 elsif Is_Array_Type
(Comp_Type
) then
18938 if Size_Depends_On_Discriminant
(Comp_Type
) then
18945 Next_Entity
(Comp
);
18950 end Caller_Known_Size_Record
;
18952 ------------------------------
18953 -- Large_Max_Size_Mutable --
18954 ------------------------------
18956 function Large_Max_Size_Mutable
(Typ
: Entity_Id
) return Boolean is
18957 pragma Assert
(Typ
= Underlying_Type
(Typ
));
18959 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean;
18960 -- Returns true if the discrete type T has a large range
18962 ----------------------------
18963 -- Is_Large_Discrete_Type --
18964 ----------------------------
18966 function Is_Large_Discrete_Type
(T
: Entity_Id
) return Boolean is
18967 Threshold
: constant Int
:= 16;
18968 -- Arbitrary threshold above which we consider it "large". We want
18969 -- a fairly large threshold, because these large types really
18970 -- shouldn't have default discriminants in the first place, in
18974 return UI_To_Int
(RM_Size
(T
)) > Threshold
;
18975 end Is_Large_Discrete_Type
;
18977 -- Start of processing for Large_Max_Size_Mutable
18980 if Is_Record_Type
(Typ
)
18981 and then not Is_Limited_View
(Typ
)
18982 and then Has_Defaulted_Discriminants
(Typ
)
18984 -- Loop through the components, looking for an array whose upper
18985 -- bound(s) depends on discriminants, where both the subtype of
18986 -- the discriminant and the index subtype are too large.
18992 Comp
:= First_Entity
(Typ
);
18993 while Present
(Comp
) loop
18994 if Ekind
(Comp
) = E_Component
then
18996 Comp_Type
: constant Entity_Id
:=
18997 Underlying_Type
(Etype
(Comp
));
19004 if Is_Array_Type
(Comp_Type
) then
19005 Indx
:= First_Index
(Comp_Type
);
19007 while Present
(Indx
) loop
19008 Ityp
:= Etype
(Indx
);
19009 Hi
:= Type_High_Bound
(Ityp
);
19011 if Nkind
(Hi
) = N_Identifier
19012 and then Ekind
(Entity
(Hi
)) = E_Discriminant
19013 and then Is_Large_Discrete_Type
(Ityp
)
19014 and then Is_Large_Discrete_Type
19015 (Etype
(Entity
(Hi
)))
19026 Next_Entity
(Comp
);
19032 end Large_Max_Size_Mutable
;
19034 -- Local declarations
19036 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
19038 -- Start of processing for New_Requires_Transient_Scope
19041 -- This is a private type which is not completed yet. This can only
19042 -- happen in a default expression (of a formal parameter or of a
19043 -- record component). Do not expand transient scope in this case.
19048 -- Do not expand transient scope for non-existent procedure return or
19049 -- string literal types.
19051 elsif Typ
= Standard_Void_Type
19052 or else Ekind
(Typ
) = E_String_Literal_Subtype
19056 -- If Typ is a generic formal incomplete type, then we want to look at
19057 -- the actual type.
19059 elsif Ekind
(Typ
) = E_Record_Subtype
19060 and then Present
(Cloned_Subtype
(Typ
))
19062 return New_Requires_Transient_Scope
(Cloned_Subtype
(Typ
));
19064 -- Functions returning specific tagged types may dispatch on result, so
19065 -- their returned value is allocated on the secondary stack, even in the
19066 -- definite case. We must treat nondispatching functions the same way,
19067 -- because access-to-function types can point at both, so the calling
19068 -- conventions must be compatible. Is_Tagged_Type includes controlled
19069 -- types and class-wide types. Controlled type temporaries need
19072 -- ???It's not clear why we need to return noncontrolled types with
19073 -- controlled components on the secondary stack.
19075 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
19078 -- Untagged definite subtypes are known size. This includes all
19079 -- elementary [sub]types. Tasks are known size even if they have
19080 -- discriminants. So we return False here, with one exception:
19081 -- For a type like:
19082 -- type T (Last : Natural := 0) is
19083 -- X : String (1 .. Last);
19085 -- we return True. That's because for "P(F(...));", where F returns T,
19086 -- we don't know the size of the result at the call site, so if we
19087 -- allocated it on the primary stack, we would have to allocate the
19088 -- maximum size, which is way too big.
19090 elsif Is_Definite_Subtype
(Typ
) or else Is_Task_Type
(Typ
) then
19091 return Large_Max_Size_Mutable
(Typ
);
19093 -- Indefinite (discriminated) untagged record or protected type
19095 elsif Is_Record_Type
(Typ
) or else Is_Protected_Type
(Typ
) then
19096 return not Caller_Known_Size_Record
(Typ
);
19098 -- Unconstrained array
19101 pragma Assert
(Is_Array_Type
(Typ
) and not Is_Definite_Subtype
(Typ
));
19104 end New_Requires_Transient_Scope
;
19106 --------------------------
19107 -- No_Heap_Finalization --
19108 --------------------------
19110 function No_Heap_Finalization
(Typ
: Entity_Id
) return Boolean is
19112 if Ekind_In
(Typ
, E_Access_Type
, E_General_Access_Type
)
19113 and then Is_Library_Level_Entity
(Typ
)
19115 -- A global No_Heap_Finalization pragma applies to all library-level
19116 -- named access-to-object types.
19118 if Present
(No_Heap_Finalization_Pragma
) then
19121 -- The library-level named access-to-object type itself is subject to
19122 -- pragma No_Heap_Finalization.
19124 elsif Present
(Get_Pragma
(Typ
, Pragma_No_Heap_Finalization
)) then
19130 end No_Heap_Finalization
;
19132 -----------------------
19133 -- Normalize_Actuals --
19134 -----------------------
19136 -- Chain actuals according to formals of subprogram. If there are no named
19137 -- associations, the chain is simply the list of Parameter Associations,
19138 -- since the order is the same as the declaration order. If there are named
19139 -- associations, then the First_Named_Actual field in the N_Function_Call
19140 -- or N_Procedure_Call_Statement node points to the Parameter_Association
19141 -- node for the parameter that comes first in declaration order. The
19142 -- remaining named parameters are then chained in declaration order using
19143 -- Next_Named_Actual.
19145 -- This routine also verifies that the number of actuals is compatible with
19146 -- the number and default values of formals, but performs no type checking
19147 -- (type checking is done by the caller).
19149 -- If the matching succeeds, Success is set to True and the caller proceeds
19150 -- with type-checking. If the match is unsuccessful, then Success is set to
19151 -- False, and the caller attempts a different interpretation, if there is
19154 -- If the flag Report is on, the call is not overloaded, and a failure to
19155 -- match can be reported here, rather than in the caller.
19157 procedure Normalize_Actuals
19161 Success
: out Boolean)
19163 Actuals
: constant List_Id
:= Parameter_Associations
(N
);
19164 Actual
: Node_Id
:= Empty
;
19165 Formal
: Entity_Id
;
19166 Last
: Node_Id
:= Empty
;
19167 First_Named
: Node_Id
:= Empty
;
19170 Formals_To_Match
: Integer := 0;
19171 Actuals_To_Match
: Integer := 0;
19173 procedure Chain
(A
: Node_Id
);
19174 -- Add named actual at the proper place in the list, using the
19175 -- Next_Named_Actual link.
19177 function Reporting
return Boolean;
19178 -- Determines if an error is to be reported. To report an error, we
19179 -- need Report to be True, and also we do not report errors caused
19180 -- by calls to init procs that occur within other init procs. Such
19181 -- errors must always be cascaded errors, since if all the types are
19182 -- declared correctly, the compiler will certainly build decent calls.
19188 procedure Chain
(A
: Node_Id
) is
19192 -- Call node points to first actual in list
19194 Set_First_Named_Actual
(N
, Explicit_Actual_Parameter
(A
));
19197 Set_Next_Named_Actual
(Last
, Explicit_Actual_Parameter
(A
));
19201 Set_Next_Named_Actual
(Last
, Empty
);
19208 function Reporting
return Boolean is
19213 elsif not Within_Init_Proc
then
19216 elsif Is_Init_Proc
(Entity
(Name
(N
))) then
19224 -- Start of processing for Normalize_Actuals
19227 if Is_Access_Type
(S
) then
19229 -- The name in the call is a function call that returns an access
19230 -- to subprogram. The designated type has the list of formals.
19232 Formal
:= First_Formal
(Designated_Type
(S
));
19234 Formal
:= First_Formal
(S
);
19237 while Present
(Formal
) loop
19238 Formals_To_Match
:= Formals_To_Match
+ 1;
19239 Next_Formal
(Formal
);
19242 -- Find if there is a named association, and verify that no positional
19243 -- associations appear after named ones.
19245 if Present
(Actuals
) then
19246 Actual
:= First
(Actuals
);
19249 while Present
(Actual
)
19250 and then Nkind
(Actual
) /= N_Parameter_Association
19252 Actuals_To_Match
:= Actuals_To_Match
+ 1;
19256 if No
(Actual
) and Actuals_To_Match
= Formals_To_Match
then
19258 -- Most common case: positional notation, no defaults
19263 elsif Actuals_To_Match
> Formals_To_Match
then
19265 -- Too many actuals: will not work
19268 if Is_Entity_Name
(Name
(N
)) then
19269 Error_Msg_N
("too many arguments in call to&", Name
(N
));
19271 Error_Msg_N
("too many arguments in call", N
);
19279 First_Named
:= Actual
;
19281 while Present
(Actual
) loop
19282 if Nkind
(Actual
) /= N_Parameter_Association
then
19284 ("positional parameters not allowed after named ones", Actual
);
19289 Actuals_To_Match
:= Actuals_To_Match
+ 1;
19295 if Present
(Actuals
) then
19296 Actual
:= First
(Actuals
);
19299 Formal
:= First_Formal
(S
);
19300 while Present
(Formal
) loop
19302 -- Match the formals in order. If the corresponding actual is
19303 -- positional, nothing to do. Else scan the list of named actuals
19304 -- to find the one with the right name.
19306 if Present
(Actual
)
19307 and then Nkind
(Actual
) /= N_Parameter_Association
19310 Actuals_To_Match
:= Actuals_To_Match
- 1;
19311 Formals_To_Match
:= Formals_To_Match
- 1;
19314 -- For named parameters, search the list of actuals to find
19315 -- one that matches the next formal name.
19317 Actual
:= First_Named
;
19319 while Present
(Actual
) loop
19320 if Chars
(Selector_Name
(Actual
)) = Chars
(Formal
) then
19323 Actuals_To_Match
:= Actuals_To_Match
- 1;
19324 Formals_To_Match
:= Formals_To_Match
- 1;
19332 if Ekind
(Formal
) /= E_In_Parameter
19333 or else No
(Default_Value
(Formal
))
19336 if (Comes_From_Source
(S
)
19337 or else Sloc
(S
) = Standard_Location
)
19338 and then Is_Overloadable
(S
)
19342 Nkind_In
(Parent
(N
), N_Procedure_Call_Statement
,
19344 N_Parameter_Association
)
19345 and then Ekind
(S
) /= E_Function
19347 Set_Etype
(N
, Etype
(S
));
19350 Error_Msg_Name_1
:= Chars
(S
);
19351 Error_Msg_Sloc
:= Sloc
(S
);
19353 ("missing argument for parameter & "
19354 & "in call to % declared #", N
, Formal
);
19357 elsif Is_Overloadable
(S
) then
19358 Error_Msg_Name_1
:= Chars
(S
);
19360 -- Point to type derivation that generated the
19363 Error_Msg_Sloc
:= Sloc
(Parent
(S
));
19366 ("missing argument for parameter & "
19367 & "in call to % (inherited) #", N
, Formal
);
19371 ("missing argument for parameter &", N
, Formal
);
19379 Formals_To_Match
:= Formals_To_Match
- 1;
19384 Next_Formal
(Formal
);
19387 if Formals_To_Match
= 0 and then Actuals_To_Match
= 0 then
19394 -- Find some superfluous named actual that did not get
19395 -- attached to the list of associations.
19397 Actual
:= First
(Actuals
);
19398 while Present
(Actual
) loop
19399 if Nkind
(Actual
) = N_Parameter_Association
19400 and then Actual
/= Last
19401 and then No
(Next_Named_Actual
(Actual
))
19403 -- A validity check may introduce a copy of a call that
19404 -- includes an extra actual (for example for an unrelated
19405 -- accessibility check). Check that the extra actual matches
19406 -- some extra formal, which must exist already because
19407 -- subprogram must be frozen at this point.
19409 if Present
(Extra_Formals
(S
))
19410 and then not Comes_From_Source
(Actual
)
19411 and then Nkind
(Actual
) = N_Parameter_Association
19412 and then Chars
(Extra_Formals
(S
)) =
19413 Chars
(Selector_Name
(Actual
))
19418 ("unmatched actual & in call", Selector_Name
(Actual
));
19430 end Normalize_Actuals
;
19432 --------------------------------
19433 -- Note_Possible_Modification --
19434 --------------------------------
19436 procedure Note_Possible_Modification
(N
: Node_Id
; Sure
: Boolean) is
19437 Modification_Comes_From_Source
: constant Boolean :=
19438 Comes_From_Source
(Parent
(N
));
19444 -- Loop to find referenced entity, if there is one
19450 if Is_Entity_Name
(Exp
) then
19451 Ent
:= Entity
(Exp
);
19453 -- If the entity is missing, it is an undeclared identifier,
19454 -- and there is nothing to annotate.
19460 elsif Nkind
(Exp
) = N_Explicit_Dereference
then
19462 P
: constant Node_Id
:= Prefix
(Exp
);
19465 -- In formal verification mode, keep track of all reads and
19466 -- writes through explicit dereferences.
19468 if GNATprove_Mode
then
19469 SPARK_Specific
.Generate_Dereference
(N
, 'm');
19472 if Nkind
(P
) = N_Selected_Component
19473 and then Present
(Entry_Formal
(Entity
(Selector_Name
(P
))))
19475 -- Case of a reference to an entry formal
19477 Ent
:= Entry_Formal
(Entity
(Selector_Name
(P
)));
19479 elsif Nkind
(P
) = N_Identifier
19480 and then Nkind
(Parent
(Entity
(P
))) = N_Object_Declaration
19481 and then Present
(Expression
(Parent
(Entity
(P
))))
19482 and then Nkind
(Expression
(Parent
(Entity
(P
)))) =
19485 -- Case of a reference to a value on which side effects have
19488 Exp
:= Prefix
(Expression
(Parent
(Entity
(P
))));
19496 elsif Nkind_In
(Exp
, N_Type_Conversion
,
19497 N_Unchecked_Type_Conversion
)
19499 Exp
:= Expression
(Exp
);
19502 elsif Nkind_In
(Exp
, N_Slice
,
19503 N_Indexed_Component
,
19504 N_Selected_Component
)
19506 -- Special check, if the prefix is an access type, then return
19507 -- since we are modifying the thing pointed to, not the prefix.
19508 -- When we are expanding, most usually the prefix is replaced
19509 -- by an explicit dereference, and this test is not needed, but
19510 -- in some cases (notably -gnatc mode and generics) when we do
19511 -- not do full expansion, we need this special test.
19513 if Is_Access_Type
(Etype
(Prefix
(Exp
))) then
19516 -- Otherwise go to prefix and keep going
19519 Exp
:= Prefix
(Exp
);
19523 -- All other cases, not a modification
19529 -- Now look for entity being referenced
19531 if Present
(Ent
) then
19532 if Is_Object
(Ent
) then
19533 if Comes_From_Source
(Exp
)
19534 or else Modification_Comes_From_Source
19536 -- Give warning if pragma unmodified is given and we are
19537 -- sure this is a modification.
19539 if Has_Pragma_Unmodified
(Ent
) and then Sure
then
19541 -- Note that the entity may be present only as a result
19542 -- of pragma Unused.
19544 if Has_Pragma_Unused
(Ent
) then
19545 Error_Msg_NE
("??pragma Unused given for &!", N
, Ent
);
19548 ("??pragma Unmodified given for &!", N
, Ent
);
19552 Set_Never_Set_In_Source
(Ent
, False);
19555 Set_Is_True_Constant
(Ent
, False);
19556 Set_Current_Value
(Ent
, Empty
);
19557 Set_Is_Known_Null
(Ent
, False);
19559 if not Can_Never_Be_Null
(Ent
) then
19560 Set_Is_Known_Non_Null
(Ent
, False);
19563 -- Follow renaming chain
19565 if (Ekind
(Ent
) = E_Variable
or else Ekind
(Ent
) = E_Constant
)
19566 and then Present
(Renamed_Object
(Ent
))
19568 Exp
:= Renamed_Object
(Ent
);
19570 -- If the entity is the loop variable in an iteration over
19571 -- a container, retrieve container expression to indicate
19572 -- possible modification.
19574 if Present
(Related_Expression
(Ent
))
19575 and then Nkind
(Parent
(Related_Expression
(Ent
))) =
19576 N_Iterator_Specification
19578 Exp
:= Original_Node
(Related_Expression
(Ent
));
19583 -- The expression may be the renaming of a subcomponent of an
19584 -- array or container. The assignment to the subcomponent is
19585 -- a modification of the container.
19587 elsif Comes_From_Source
(Original_Node
(Exp
))
19588 and then Nkind_In
(Original_Node
(Exp
), N_Selected_Component
,
19589 N_Indexed_Component
)
19591 Exp
:= Prefix
(Original_Node
(Exp
));
19595 -- Generate a reference only if the assignment comes from
19596 -- source. This excludes, for example, calls to a dispatching
19597 -- assignment operation when the left-hand side is tagged. In
19598 -- GNATprove mode, we need those references also on generated
19599 -- code, as these are used to compute the local effects of
19602 if Modification_Comes_From_Source
or GNATprove_Mode
then
19603 Generate_Reference
(Ent
, Exp
, 'm');
19605 -- If the target of the assignment is the bound variable
19606 -- in an iterator, indicate that the corresponding array
19607 -- or container is also modified.
19609 if Ada_Version
>= Ada_2012
19610 and then Nkind
(Parent
(Ent
)) = N_Iterator_Specification
19613 Domain
: constant Node_Id
:= Name
(Parent
(Ent
));
19616 -- TBD : in the full version of the construct, the
19617 -- domain of iteration can be given by an expression.
19619 if Is_Entity_Name
(Domain
) then
19620 Generate_Reference
(Entity
(Domain
), Exp
, 'm');
19621 Set_Is_True_Constant
(Entity
(Domain
), False);
19622 Set_Never_Set_In_Source
(Entity
(Domain
), False);
19631 -- If we are sure this is a modification from source, and we know
19632 -- this modifies a constant, then give an appropriate warning.
19635 and then Modification_Comes_From_Source
19636 and then Overlays_Constant
(Ent
)
19637 and then Address_Clause_Overlay_Warnings
19640 Addr
: constant Node_Id
:= Address_Clause
(Ent
);
19645 Find_Overlaid_Entity
(Addr
, O_Ent
, Off
);
19647 Error_Msg_Sloc
:= Sloc
(Addr
);
19649 ("??constant& may be modified via address clause#",
19660 end Note_Possible_Modification
;
19666 function Null_Status
(N
: Node_Id
) return Null_Status_Kind
is
19667 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean;
19668 -- Determine whether definition Def carries a null exclusion
19670 function Null_Status_Of_Entity
(Id
: Entity_Id
) return Null_Status_Kind
;
19671 -- Determine the null status of arbitrary entity Id
19673 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
;
19674 -- Determine the null status of type Typ
19676 ---------------------------
19677 -- Is_Null_Excluding_Def --
19678 ---------------------------
19680 function Is_Null_Excluding_Def
(Def
: Node_Id
) return Boolean is
19683 Nkind_In
(Def
, N_Access_Definition
,
19684 N_Access_Function_Definition
,
19685 N_Access_Procedure_Definition
,
19686 N_Access_To_Object_Definition
,
19687 N_Component_Definition
,
19688 N_Derived_Type_Definition
)
19689 and then Null_Exclusion_Present
(Def
);
19690 end Is_Null_Excluding_Def
;
19692 ---------------------------
19693 -- Null_Status_Of_Entity --
19694 ---------------------------
19696 function Null_Status_Of_Entity
19697 (Id
: Entity_Id
) return Null_Status_Kind
19699 Decl
: constant Node_Id
:= Declaration_Node
(Id
);
19703 -- The value of an imported or exported entity may be set externally
19704 -- regardless of a null exclusion. As a result, the value cannot be
19705 -- determined statically.
19707 if Is_Imported
(Id
) or else Is_Exported
(Id
) then
19710 elsif Nkind_In
(Decl
, N_Component_Declaration
,
19711 N_Discriminant_Specification
,
19712 N_Formal_Object_Declaration
,
19713 N_Object_Declaration
,
19714 N_Object_Renaming_Declaration
,
19715 N_Parameter_Specification
)
19717 -- A component declaration yields a non-null value when either
19718 -- its component definition or access definition carries a null
19721 if Nkind
(Decl
) = N_Component_Declaration
then
19722 Def
:= Component_Definition
(Decl
);
19724 if Is_Null_Excluding_Def
(Def
) then
19725 return Is_Non_Null
;
19728 Def
:= Access_Definition
(Def
);
19730 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
19731 return Is_Non_Null
;
19734 -- A formal object declaration yields a non-null value if its
19735 -- access definition carries a null exclusion. If the object is
19736 -- default initialized, then the value depends on the expression.
19738 elsif Nkind
(Decl
) = N_Formal_Object_Declaration
then
19739 Def
:= Access_Definition
(Decl
);
19741 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
19742 return Is_Non_Null
;
19745 -- A constant may yield a null or non-null value depending on its
19746 -- initialization expression.
19748 elsif Ekind
(Id
) = E_Constant
then
19749 return Null_Status
(Constant_Value
(Id
));
19751 -- The construct yields a non-null value when it has a null
19754 elsif Null_Exclusion_Present
(Decl
) then
19755 return Is_Non_Null
;
19757 -- An object renaming declaration yields a non-null value if its
19758 -- access definition carries a null exclusion. Otherwise the value
19759 -- depends on the renamed name.
19761 elsif Nkind
(Decl
) = N_Object_Renaming_Declaration
then
19762 Def
:= Access_Definition
(Decl
);
19764 if Present
(Def
) and then Is_Null_Excluding_Def
(Def
) then
19765 return Is_Non_Null
;
19768 return Null_Status
(Name
(Decl
));
19773 -- At this point the declaration of the entity does not carry a null
19774 -- exclusion and lacks an initialization expression. Check the status
19777 return Null_Status_Of_Type
(Etype
(Id
));
19778 end Null_Status_Of_Entity
;
19780 -------------------------
19781 -- Null_Status_Of_Type --
19782 -------------------------
19784 function Null_Status_Of_Type
(Typ
: Entity_Id
) return Null_Status_Kind
is
19789 -- Traverse the type chain looking for types with null exclusion
19792 while Present
(Curr
) and then Etype
(Curr
) /= Curr
loop
19793 Decl
:= Parent
(Curr
);
19795 -- Guard against itypes which do not always have declarations. A
19796 -- type yields a non-null value if it carries a null exclusion.
19798 if Present
(Decl
) then
19799 if Nkind
(Decl
) = N_Full_Type_Declaration
19800 and then Is_Null_Excluding_Def
(Type_Definition
(Decl
))
19802 return Is_Non_Null
;
19804 elsif Nkind
(Decl
) = N_Subtype_Declaration
19805 and then Null_Exclusion_Present
(Decl
)
19807 return Is_Non_Null
;
19811 Curr
:= Etype
(Curr
);
19814 -- The type chain does not contain any null excluding types
19817 end Null_Status_Of_Type
;
19819 -- Start of processing for Null_Status
19822 -- An allocator always creates a non-null value
19824 if Nkind
(N
) = N_Allocator
then
19825 return Is_Non_Null
;
19827 -- Taking the 'Access of something yields a non-null value
19829 elsif Nkind
(N
) = N_Attribute_Reference
19830 and then Nam_In
(Attribute_Name
(N
), Name_Access
,
19831 Name_Unchecked_Access
,
19832 Name_Unrestricted_Access
)
19834 return Is_Non_Null
;
19836 -- "null" yields null
19838 elsif Nkind
(N
) = N_Null
then
19841 -- Check the status of the operand of a type conversion
19843 elsif Nkind
(N
) = N_Type_Conversion
then
19844 return Null_Status
(Expression
(N
));
19846 -- The input denotes a reference to an entity. Determine whether the
19847 -- entity or its type yields a null or non-null value.
19849 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
19850 return Null_Status_Of_Entity
(Entity
(N
));
19853 -- Otherwise it is not possible to determine the null status of the
19854 -- subexpression at compile time without resorting to simple flow
19860 --------------------------------------
19861 -- Null_To_Null_Address_Convert_OK --
19862 --------------------------------------
19864 function Null_To_Null_Address_Convert_OK
19866 Typ
: Entity_Id
:= Empty
) return Boolean
19869 if not Relaxed_RM_Semantics
then
19873 if Nkind
(N
) = N_Null
then
19874 return Present
(Typ
) and then Is_Descendant_Of_Address
(Typ
);
19876 elsif Nkind_In
(N
, N_Op_Eq
, N_Op_Ge
, N_Op_Gt
, N_Op_Le
, N_Op_Lt
, N_Op_Ne
)
19879 L
: constant Node_Id
:= Left_Opnd
(N
);
19880 R
: constant Node_Id
:= Right_Opnd
(N
);
19883 -- We check the Etype of the complementary operand since the
19884 -- N_Null node is not decorated at this stage.
19887 ((Nkind
(L
) = N_Null
19888 and then Is_Descendant_Of_Address
(Etype
(R
)))
19890 (Nkind
(R
) = N_Null
19891 and then Is_Descendant_Of_Address
(Etype
(L
))));
19896 end Null_To_Null_Address_Convert_OK
;
19898 -------------------------
19899 -- Object_Access_Level --
19900 -------------------------
19902 -- Returns the static accessibility level of the view denoted by Obj. Note
19903 -- that the value returned is the result of a call to Scope_Depth. Only
19904 -- scope depths associated with dynamic scopes can actually be returned.
19905 -- Since only relative levels matter for accessibility checking, the fact
19906 -- that the distance between successive levels of accessibility is not
19907 -- always one is immaterial (invariant: if level(E2) is deeper than
19908 -- level(E1), then Scope_Depth(E1) < Scope_Depth(E2)).
19910 function Object_Access_Level
(Obj
: Node_Id
) return Uint
is
19911 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean;
19912 -- Determine whether N is a construct of the form
19913 -- Some_Type (Operand._tag'Address)
19914 -- This construct appears in the context of dispatching calls.
19916 function Reference_To
(Obj
: Node_Id
) return Node_Id
;
19917 -- An explicit dereference is created when removing side-effects from
19918 -- expressions for constraint checking purposes. In this case a local
19919 -- access type is created for it. The correct access level is that of
19920 -- the original source node. We detect this case by noting that the
19921 -- prefix of the dereference is created by an object declaration whose
19922 -- initial expression is a reference.
19924 -----------------------------
19925 -- Is_Interface_Conversion --
19926 -----------------------------
19928 function Is_Interface_Conversion
(N
: Node_Id
) return Boolean is
19930 return Nkind
(N
) = N_Unchecked_Type_Conversion
19931 and then Nkind
(Expression
(N
)) = N_Attribute_Reference
19932 and then Attribute_Name
(Expression
(N
)) = Name_Address
;
19933 end Is_Interface_Conversion
;
19939 function Reference_To
(Obj
: Node_Id
) return Node_Id
is
19940 Pref
: constant Node_Id
:= Prefix
(Obj
);
19942 if Is_Entity_Name
(Pref
)
19943 and then Nkind
(Parent
(Entity
(Pref
))) = N_Object_Declaration
19944 and then Present
(Expression
(Parent
(Entity
(Pref
))))
19945 and then Nkind
(Expression
(Parent
(Entity
(Pref
)))) = N_Reference
19947 return (Prefix
(Expression
(Parent
(Entity
(Pref
)))));
19957 -- Start of processing for Object_Access_Level
19960 if Nkind
(Obj
) = N_Defining_Identifier
19961 or else Is_Entity_Name
(Obj
)
19963 if Nkind
(Obj
) = N_Defining_Identifier
then
19969 if Is_Prival
(E
) then
19970 E
:= Prival_Link
(E
);
19973 -- If E is a type then it denotes a current instance. For this case
19974 -- we add one to the normal accessibility level of the type to ensure
19975 -- that current instances are treated as always being deeper than
19976 -- than the level of any visible named access type (see 3.10.2(21)).
19978 if Is_Type
(E
) then
19979 return Type_Access_Level
(E
) + 1;
19981 elsif Present
(Renamed_Object
(E
)) then
19982 return Object_Access_Level
(Renamed_Object
(E
));
19984 -- Similarly, if E is a component of the current instance of a
19985 -- protected type, any instance of it is assumed to be at a deeper
19986 -- level than the type. For a protected object (whose type is an
19987 -- anonymous protected type) its components are at the same level
19988 -- as the type itself.
19990 elsif not Is_Overloadable
(E
)
19991 and then Ekind
(Scope
(E
)) = E_Protected_Type
19992 and then Comes_From_Source
(Scope
(E
))
19994 return Type_Access_Level
(Scope
(E
)) + 1;
19997 -- Aliased formals of functions take their access level from the
19998 -- point of call, i.e. require a dynamic check. For static check
19999 -- purposes, this is smaller than the level of the subprogram
20000 -- itself. For procedures the aliased makes no difference.
20003 and then Is_Aliased
(E
)
20004 and then Ekind
(Scope
(E
)) = E_Function
20006 return Type_Access_Level
(Etype
(E
));
20009 return Scope_Depth
(Enclosing_Dynamic_Scope
(E
));
20013 elsif Nkind_In
(Obj
, N_Indexed_Component
, N_Selected_Component
) then
20014 if Is_Access_Type
(Etype
(Prefix
(Obj
))) then
20015 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
20017 return Object_Access_Level
(Prefix
(Obj
));
20020 elsif Nkind
(Obj
) = N_Explicit_Dereference
then
20022 -- If the prefix is a selected access discriminant then we make a
20023 -- recursive call on the prefix, which will in turn check the level
20024 -- of the prefix object of the selected discriminant.
20026 -- In Ada 2012, if the discriminant has implicit dereference and
20027 -- the context is a selected component, treat this as an object of
20028 -- unknown scope (see below). This is necessary in compile-only mode;
20029 -- otherwise expansion will already have transformed the prefix into
20032 if Nkind
(Prefix
(Obj
)) = N_Selected_Component
20033 and then Ekind
(Etype
(Prefix
(Obj
))) = E_Anonymous_Access_Type
20035 Ekind
(Entity
(Selector_Name
(Prefix
(Obj
)))) = E_Discriminant
20037 (not Has_Implicit_Dereference
20038 (Entity
(Selector_Name
(Prefix
(Obj
))))
20039 or else Nkind
(Parent
(Obj
)) /= N_Selected_Component
)
20041 return Object_Access_Level
(Prefix
(Obj
));
20043 -- Detect an interface conversion in the context of a dispatching
20044 -- call. Use the original form of the conversion to find the access
20045 -- level of the operand.
20047 elsif Is_Interface
(Etype
(Obj
))
20048 and then Is_Interface_Conversion
(Prefix
(Obj
))
20049 and then Nkind
(Original_Node
(Obj
)) = N_Type_Conversion
20051 return Object_Access_Level
(Original_Node
(Obj
));
20053 elsif not Comes_From_Source
(Obj
) then
20055 Ref
: constant Node_Id
:= Reference_To
(Obj
);
20057 if Present
(Ref
) then
20058 return Object_Access_Level
(Ref
);
20060 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
20065 return Type_Access_Level
(Etype
(Prefix
(Obj
)));
20068 elsif Nkind_In
(Obj
, N_Type_Conversion
, N_Unchecked_Type_Conversion
) then
20069 return Object_Access_Level
(Expression
(Obj
));
20071 elsif Nkind
(Obj
) = N_Function_Call
then
20073 -- Function results are objects, so we get either the access level of
20074 -- the function or, in the case of an indirect call, the level of the
20075 -- access-to-subprogram type. (This code is used for Ada 95, but it
20076 -- looks wrong, because it seems that we should be checking the level
20077 -- of the call itself, even for Ada 95. However, using the Ada 2005
20078 -- version of the code causes regressions in several tests that are
20079 -- compiled with -gnat95. ???)
20081 if Ada_Version
< Ada_2005
then
20082 if Is_Entity_Name
(Name
(Obj
)) then
20083 return Subprogram_Access_Level
(Entity
(Name
(Obj
)));
20085 return Type_Access_Level
(Etype
(Prefix
(Name
(Obj
))));
20088 -- For Ada 2005, the level of the result object of a function call is
20089 -- defined to be the level of the call's innermost enclosing master.
20090 -- We determine that by querying the depth of the innermost enclosing
20094 Return_Master_Scope_Depth_Of_Call
: declare
20095 function Innermost_Master_Scope_Depth
20096 (N
: Node_Id
) return Uint
;
20097 -- Returns the scope depth of the given node's innermost
20098 -- enclosing dynamic scope (effectively the accessibility
20099 -- level of the innermost enclosing master).
20101 ----------------------------------
20102 -- Innermost_Master_Scope_Depth --
20103 ----------------------------------
20105 function Innermost_Master_Scope_Depth
20106 (N
: Node_Id
) return Uint
20108 Node_Par
: Node_Id
:= Parent
(N
);
20111 -- Locate the nearest enclosing node (by traversing Parents)
20112 -- that Defining_Entity can be applied to, and return the
20113 -- depth of that entity's nearest enclosing dynamic scope.
20115 while Present
(Node_Par
) loop
20116 case Nkind
(Node_Par
) is
20117 when N_Abstract_Subprogram_Declaration
20118 | N_Block_Statement
20120 | N_Component_Declaration
20122 | N_Entry_Declaration
20123 | N_Exception_Declaration
20124 | N_Formal_Object_Declaration
20125 | N_Formal_Package_Declaration
20126 | N_Formal_Subprogram_Declaration
20127 | N_Formal_Type_Declaration
20128 | N_Full_Type_Declaration
20129 | N_Function_Specification
20130 | N_Generic_Declaration
20131 | N_Generic_Instantiation
20132 | N_Implicit_Label_Declaration
20133 | N_Incomplete_Type_Declaration
20134 | N_Loop_Parameter_Specification
20135 | N_Number_Declaration
20136 | N_Object_Declaration
20137 | N_Package_Declaration
20138 | N_Package_Specification
20139 | N_Parameter_Specification
20140 | N_Private_Extension_Declaration
20141 | N_Private_Type_Declaration
20142 | N_Procedure_Specification
20144 | N_Protected_Type_Declaration
20145 | N_Renaming_Declaration
20146 | N_Single_Protected_Declaration
20147 | N_Single_Task_Declaration
20148 | N_Subprogram_Declaration
20149 | N_Subtype_Declaration
20151 | N_Task_Type_Declaration
20154 (Nearest_Dynamic_Scope
20155 (Defining_Entity
(Node_Par
)));
20161 Node_Par
:= Parent
(Node_Par
);
20164 pragma Assert
(False);
20166 -- Should never reach the following return
20168 return Scope_Depth
(Current_Scope
) + 1;
20169 end Innermost_Master_Scope_Depth
;
20171 -- Start of processing for Return_Master_Scope_Depth_Of_Call
20174 return Innermost_Master_Scope_Depth
(Obj
);
20175 end Return_Master_Scope_Depth_Of_Call
;
20178 -- For convenience we handle qualified expressions, even though they
20179 -- aren't technically object names.
20181 elsif Nkind
(Obj
) = N_Qualified_Expression
then
20182 return Object_Access_Level
(Expression
(Obj
));
20184 -- Ditto for aggregates. They have the level of the temporary that
20185 -- will hold their value.
20187 elsif Nkind
(Obj
) = N_Aggregate
then
20188 return Object_Access_Level
(Current_Scope
);
20190 -- Otherwise return the scope level of Standard. (If there are cases
20191 -- that fall through to this point they will be treated as having
20192 -- global accessibility for now. ???)
20195 return Scope_Depth
(Standard_Standard
);
20197 end Object_Access_Level
;
20199 ----------------------------------
20200 -- Old_Requires_Transient_Scope --
20201 ----------------------------------
20203 function Old_Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
20204 Typ
: constant Entity_Id
:= Underlying_Type
(Id
);
20207 -- This is a private type which is not completed yet. This can only
20208 -- happen in a default expression (of a formal parameter or of a
20209 -- record component). Do not expand transient scope in this case.
20214 -- Do not expand transient scope for non-existent procedure return
20216 elsif Typ
= Standard_Void_Type
then
20219 -- Elementary types do not require a transient scope
20221 elsif Is_Elementary_Type
(Typ
) then
20224 -- Generally, indefinite subtypes require a transient scope, since the
20225 -- back end cannot generate temporaries, since this is not a valid type
20226 -- for declaring an object. It might be possible to relax this in the
20227 -- future, e.g. by declaring the maximum possible space for the type.
20229 elsif not Is_Definite_Subtype
(Typ
) then
20232 -- Functions returning tagged types may dispatch on result so their
20233 -- returned value is allocated on the secondary stack. Controlled
20234 -- type temporaries need finalization.
20236 elsif Is_Tagged_Type
(Typ
) or else Has_Controlled_Component
(Typ
) then
20241 elsif Is_Record_Type
(Typ
) then
20246 Comp
:= First_Entity
(Typ
);
20247 while Present
(Comp
) loop
20248 if Ekind
(Comp
) = E_Component
then
20250 -- ???It's not clear we need a full recursive call to
20251 -- Old_Requires_Transient_Scope here. Note that the
20252 -- following can't happen.
20254 pragma Assert
(Is_Definite_Subtype
(Etype
(Comp
)));
20255 pragma Assert
(not Has_Controlled_Component
(Etype
(Comp
)));
20257 if Old_Requires_Transient_Scope
(Etype
(Comp
)) then
20262 Next_Entity
(Comp
);
20268 -- String literal types never require transient scope
20270 elsif Ekind
(Typ
) = E_String_Literal_Subtype
then
20273 -- Array type. Note that we already know that this is a constrained
20274 -- array, since unconstrained arrays will fail the indefinite test.
20276 elsif Is_Array_Type
(Typ
) then
20278 -- If component type requires a transient scope, the array does too
20280 if Old_Requires_Transient_Scope
(Component_Type
(Typ
)) then
20283 -- Otherwise, we only need a transient scope if the size depends on
20284 -- the value of one or more discriminants.
20287 return Size_Depends_On_Discriminant
(Typ
);
20290 -- All other cases do not require a transient scope
20293 pragma Assert
(Is_Protected_Type
(Typ
) or else Is_Task_Type
(Typ
));
20296 end Old_Requires_Transient_Scope
;
20298 ---------------------------------
20299 -- Original_Aspect_Pragma_Name --
20300 ---------------------------------
20302 function Original_Aspect_Pragma_Name
(N
: Node_Id
) return Name_Id
is
20304 Item_Nam
: Name_Id
;
20307 pragma Assert
(Nkind_In
(N
, N_Aspect_Specification
, N_Pragma
));
20311 -- The pragma was generated to emulate an aspect, use the original
20312 -- aspect specification.
20314 if Nkind
(Item
) = N_Pragma
and then From_Aspect_Specification
(Item
) then
20315 Item
:= Corresponding_Aspect
(Item
);
20318 -- Retrieve the name of the aspect/pragma. Note that Pre, Pre_Class,
20319 -- Post and Post_Class rewrite their pragma identifier to preserve the
20321 -- ??? this is kludgey
20323 if Nkind
(Item
) = N_Pragma
then
20324 Item_Nam
:= Chars
(Original_Node
(Pragma_Identifier
(Item
)));
20327 pragma Assert
(Nkind
(Item
) = N_Aspect_Specification
);
20328 Item_Nam
:= Chars
(Identifier
(Item
));
20331 -- Deal with 'Class by converting the name to its _XXX form
20333 if Class_Present
(Item
) then
20334 if Item_Nam
= Name_Invariant
then
20335 Item_Nam
:= Name_uInvariant
;
20337 elsif Item_Nam
= Name_Post
then
20338 Item_Nam
:= Name_uPost
;
20340 elsif Item_Nam
= Name_Pre
then
20341 Item_Nam
:= Name_uPre
;
20343 elsif Nam_In
(Item_Nam
, Name_Type_Invariant
,
20344 Name_Type_Invariant_Class
)
20346 Item_Nam
:= Name_uType_Invariant
;
20348 -- Nothing to do for other cases (e.g. a Check that derived from
20349 -- Pre_Class and has the flag set). Also we do nothing if the name
20350 -- is already in special _xxx form.
20356 end Original_Aspect_Pragma_Name
;
20358 --------------------------------------
20359 -- Original_Corresponding_Operation --
20360 --------------------------------------
20362 function Original_Corresponding_Operation
(S
: Entity_Id
) return Entity_Id
20364 Typ
: constant Entity_Id
:= Find_Dispatching_Type
(S
);
20367 -- If S is an inherited primitive S2 the original corresponding
20368 -- operation of S is the original corresponding operation of S2
20370 if Present
(Alias
(S
))
20371 and then Find_Dispatching_Type
(Alias
(S
)) /= Typ
20373 return Original_Corresponding_Operation
(Alias
(S
));
20375 -- If S overrides an inherited subprogram S2 the original corresponding
20376 -- operation of S is the original corresponding operation of S2
20378 elsif Present
(Overridden_Operation
(S
)) then
20379 return Original_Corresponding_Operation
(Overridden_Operation
(S
));
20381 -- otherwise it is S itself
20386 end Original_Corresponding_Operation
;
20388 -------------------
20389 -- Output_Entity --
20390 -------------------
20392 procedure Output_Entity
(Id
: Entity_Id
) is
20396 Scop
:= Scope
(Id
);
20398 -- The entity may lack a scope when it is in the process of being
20399 -- analyzed. Use the current scope as an approximation.
20402 Scop
:= Current_Scope
;
20405 Output_Name
(Chars
(Id
), Scop
);
20412 procedure Output_Name
(Nam
: Name_Id
; Scop
: Entity_Id
:= Current_Scope
) is
20416 (Get_Qualified_Name
20423 ----------------------
20424 -- Policy_In_Effect --
20425 ----------------------
20427 function Policy_In_Effect
(Policy
: Name_Id
) return Name_Id
is
20428 function Policy_In_List
(List
: Node_Id
) return Name_Id
;
20429 -- Determine the mode of a policy in a N_Pragma list
20431 --------------------
20432 -- Policy_In_List --
20433 --------------------
20435 function Policy_In_List
(List
: Node_Id
) return Name_Id
is
20442 while Present
(Prag
) loop
20443 Arg1
:= First
(Pragma_Argument_Associations
(Prag
));
20444 Arg2
:= Next
(Arg1
);
20446 Arg1
:= Get_Pragma_Arg
(Arg1
);
20447 Arg2
:= Get_Pragma_Arg
(Arg2
);
20449 -- The current Check_Policy pragma matches the requested policy or
20450 -- appears in the single argument form (Assertion, policy_id).
20452 if Nam_In
(Chars
(Arg1
), Name_Assertion
, Policy
) then
20453 return Chars
(Arg2
);
20456 Prag
:= Next_Pragma
(Prag
);
20460 end Policy_In_List
;
20466 -- Start of processing for Policy_In_Effect
20469 if not Is_Valid_Assertion_Kind
(Policy
) then
20470 raise Program_Error
;
20473 -- Inspect all policy pragmas that appear within scopes (if any)
20475 Kind
:= Policy_In_List
(Check_Policy_List
);
20477 -- Inspect all configuration policy pragmas (if any)
20479 if Kind
= No_Name
then
20480 Kind
:= Policy_In_List
(Check_Policy_List_Config
);
20483 -- The context lacks policy pragmas, determine the mode based on whether
20484 -- assertions are enabled at the configuration level. This ensures that
20485 -- the policy is preserved when analyzing generics.
20487 if Kind
= No_Name
then
20488 if Assertions_Enabled_Config
then
20489 Kind
:= Name_Check
;
20491 Kind
:= Name_Ignore
;
20496 end Policy_In_Effect
;
20498 ----------------------------------
20499 -- Predicate_Tests_On_Arguments --
20500 ----------------------------------
20502 function Predicate_Tests_On_Arguments
(Subp
: Entity_Id
) return Boolean is
20504 -- Always test predicates on indirect call
20506 if Ekind
(Subp
) = E_Subprogram_Type
then
20509 -- Do not test predicates on call to generated default Finalize, since
20510 -- we are not interested in whether something we are finalizing (and
20511 -- typically destroying) satisfies its predicates.
20513 elsif Chars
(Subp
) = Name_Finalize
20514 and then not Comes_From_Source
(Subp
)
20518 -- Do not test predicates on any internally generated routines
20520 elsif Is_Internal_Name
(Chars
(Subp
)) then
20523 -- Do not test predicates on call to Init_Proc, since if needed the
20524 -- predicate test will occur at some other point.
20526 elsif Is_Init_Proc
(Subp
) then
20529 -- Do not test predicates on call to predicate function, since this
20530 -- would cause infinite recursion.
20532 elsif Ekind
(Subp
) = E_Function
20533 and then (Is_Predicate_Function
(Subp
)
20535 Is_Predicate_Function_M
(Subp
))
20539 -- For now, no other exceptions
20544 end Predicate_Tests_On_Arguments
;
20546 -----------------------
20547 -- Private_Component --
20548 -----------------------
20550 function Private_Component
(Type_Id
: Entity_Id
) return Entity_Id
is
20551 Ancestor
: constant Entity_Id
:= Base_Type
(Type_Id
);
20553 function Trace_Components
20555 Check
: Boolean) return Entity_Id
;
20556 -- Recursive function that does the work, and checks against circular
20557 -- definition for each subcomponent type.
20559 ----------------------
20560 -- Trace_Components --
20561 ----------------------
20563 function Trace_Components
20565 Check
: Boolean) return Entity_Id
20567 Btype
: constant Entity_Id
:= Base_Type
(T
);
20568 Component
: Entity_Id
;
20570 Candidate
: Entity_Id
:= Empty
;
20573 if Check
and then Btype
= Ancestor
then
20574 Error_Msg_N
("circular type definition", Type_Id
);
20578 if Is_Private_Type
(Btype
) and then not Is_Generic_Type
(Btype
) then
20579 if Present
(Full_View
(Btype
))
20580 and then Is_Record_Type
(Full_View
(Btype
))
20581 and then not Is_Frozen
(Btype
)
20583 -- To indicate that the ancestor depends on a private type, the
20584 -- current Btype is sufficient. However, to check for circular
20585 -- definition we must recurse on the full view.
20587 Candidate
:= Trace_Components
(Full_View
(Btype
), True);
20589 if Candidate
= Any_Type
then
20599 elsif Is_Array_Type
(Btype
) then
20600 return Trace_Components
(Component_Type
(Btype
), True);
20602 elsif Is_Record_Type
(Btype
) then
20603 Component
:= First_Entity
(Btype
);
20604 while Present
(Component
)
20605 and then Comes_From_Source
(Component
)
20607 -- Skip anonymous types generated by constrained components
20609 if not Is_Type
(Component
) then
20610 P
:= Trace_Components
(Etype
(Component
), True);
20612 if Present
(P
) then
20613 if P
= Any_Type
then
20621 Next_Entity
(Component
);
20629 end Trace_Components
;
20631 -- Start of processing for Private_Component
20634 return Trace_Components
(Type_Id
, False);
20635 end Private_Component
;
20637 ---------------------------
20638 -- Primitive_Names_Match --
20639 ---------------------------
20641 function Primitive_Names_Match
(E1
, E2
: Entity_Id
) return Boolean is
20642 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
;
20643 -- Given an internal name, returns the corresponding non-internal name
20645 ------------------------
20646 -- Non_Internal_Name --
20647 ------------------------
20649 function Non_Internal_Name
(E
: Entity_Id
) return Name_Id
is
20651 Get_Name_String
(Chars
(E
));
20652 Name_Len
:= Name_Len
- 1;
20654 end Non_Internal_Name
;
20656 -- Start of processing for Primitive_Names_Match
20659 pragma Assert
(Present
(E1
) and then Present
(E2
));
20661 return Chars
(E1
) = Chars
(E2
)
20663 (not Is_Internal_Name
(Chars
(E1
))
20664 and then Is_Internal_Name
(Chars
(E2
))
20665 and then Non_Internal_Name
(E2
) = Chars
(E1
))
20667 (not Is_Internal_Name
(Chars
(E2
))
20668 and then Is_Internal_Name
(Chars
(E1
))
20669 and then Non_Internal_Name
(E1
) = Chars
(E2
))
20671 (Is_Predefined_Dispatching_Operation
(E1
)
20672 and then Is_Predefined_Dispatching_Operation
(E2
)
20673 and then Same_TSS
(E1
, E2
))
20675 (Is_Init_Proc
(E1
) and then Is_Init_Proc
(E2
));
20676 end Primitive_Names_Match
;
20678 -----------------------
20679 -- Process_End_Label --
20680 -----------------------
20682 procedure Process_End_Label
20691 Label_Ref
: Boolean;
20692 -- Set True if reference to end label itself is required
20695 -- Gets set to the operator symbol or identifier that references the
20696 -- entity Ent. For the child unit case, this is the identifier from the
20697 -- designator. For other cases, this is simply Endl.
20699 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
);
20700 -- N is an identifier node that appears as a parent unit reference in
20701 -- the case where Ent is a child unit. This procedure generates an
20702 -- appropriate cross-reference entry. E is the corresponding entity.
20704 -------------------------
20705 -- Generate_Parent_Ref --
20706 -------------------------
20708 procedure Generate_Parent_Ref
(N
: Node_Id
; E
: Entity_Id
) is
20710 -- If names do not match, something weird, skip reference
20712 if Chars
(E
) = Chars
(N
) then
20714 -- Generate the reference. We do NOT consider this as a reference
20715 -- for unreferenced symbol purposes.
20717 Generate_Reference
(E
, N
, 'r', Set_Ref
=> False, Force
=> True);
20719 if Style_Check
then
20720 Style
.Check_Identifier
(N
, E
);
20723 end Generate_Parent_Ref
;
20725 -- Start of processing for Process_End_Label
20728 -- If no node, ignore. This happens in some error situations, and
20729 -- also for some internally generated structures where no end label
20730 -- references are required in any case.
20736 -- Nothing to do if no End_Label, happens for internally generated
20737 -- constructs where we don't want an end label reference anyway. Also
20738 -- nothing to do if Endl is a string literal, which means there was
20739 -- some prior error (bad operator symbol)
20741 Endl
:= End_Label
(N
);
20743 if No
(Endl
) or else Nkind
(Endl
) = N_String_Literal
then
20747 -- Reference node is not in extended main source unit
20749 if not In_Extended_Main_Source_Unit
(N
) then
20751 -- Generally we do not collect references except for the extended
20752 -- main source unit. The one exception is the 'e' entry for a
20753 -- package spec, where it is useful for a client to have the
20754 -- ending information to define scopes.
20760 Label_Ref
:= False;
20762 -- For this case, we can ignore any parent references, but we
20763 -- need the package name itself for the 'e' entry.
20765 if Nkind
(Endl
) = N_Designator
then
20766 Endl
:= Identifier
(Endl
);
20770 -- Reference is in extended main source unit
20775 -- For designator, generate references for the parent entries
20777 if Nkind
(Endl
) = N_Designator
then
20779 -- Generate references for the prefix if the END line comes from
20780 -- source (otherwise we do not need these references) We climb the
20781 -- scope stack to find the expected entities.
20783 if Comes_From_Source
(Endl
) then
20784 Nam
:= Name
(Endl
);
20785 Scop
:= Current_Scope
;
20786 while Nkind
(Nam
) = N_Selected_Component
loop
20787 Scop
:= Scope
(Scop
);
20788 exit when No
(Scop
);
20789 Generate_Parent_Ref
(Selector_Name
(Nam
), Scop
);
20790 Nam
:= Prefix
(Nam
);
20793 if Present
(Scop
) then
20794 Generate_Parent_Ref
(Nam
, Scope
(Scop
));
20798 Endl
:= Identifier
(Endl
);
20802 -- If the end label is not for the given entity, then either we have
20803 -- some previous error, or this is a generic instantiation for which
20804 -- we do not need to make a cross-reference in this case anyway. In
20805 -- either case we simply ignore the call.
20807 if Chars
(Ent
) /= Chars
(Endl
) then
20811 -- If label was really there, then generate a normal reference and then
20812 -- adjust the location in the end label to point past the name (which
20813 -- should almost always be the semicolon).
20815 Loc
:= Sloc
(Endl
);
20817 if Comes_From_Source
(Endl
) then
20819 -- If a label reference is required, then do the style check and
20820 -- generate an l-type cross-reference entry for the label
20823 if Style_Check
then
20824 Style
.Check_Identifier
(Endl
, Ent
);
20827 Generate_Reference
(Ent
, Endl
, 'l', Set_Ref
=> False);
20830 -- Set the location to point past the label (normally this will
20831 -- mean the semicolon immediately following the label). This is
20832 -- done for the sake of the 'e' or 't' entry generated below.
20834 Get_Decoded_Name_String
(Chars
(Endl
));
20835 Set_Sloc
(Endl
, Sloc
(Endl
) + Source_Ptr
(Name_Len
));
20838 -- In SPARK mode, no missing label is allowed for packages and
20839 -- subprogram bodies. Detect those cases by testing whether
20840 -- Process_End_Label was called for a body (Typ = 't') or a package.
20842 if Restriction_Check_Required
(SPARK_05
)
20843 and then (Typ
= 't' or else Ekind
(Ent
) = E_Package
)
20845 Error_Msg_Node_1
:= Endl
;
20846 Check_SPARK_05_Restriction
20847 ("`END &` required", Endl
, Force
=> True);
20851 -- Now generate the e/t reference
20853 Generate_Reference
(Ent
, Endl
, Typ
, Set_Ref
=> False, Force
=> True);
20855 -- Restore Sloc, in case modified above, since we have an identifier
20856 -- and the normal Sloc should be left set in the tree.
20858 Set_Sloc
(Endl
, Loc
);
20859 end Process_End_Label
;
20861 --------------------------------
20862 -- Propagate_Concurrent_Flags --
20863 --------------------------------
20865 procedure Propagate_Concurrent_Flags
20867 Comp_Typ
: Entity_Id
)
20870 if Has_Task
(Comp_Typ
) then
20871 Set_Has_Task
(Typ
);
20874 if Has_Protected
(Comp_Typ
) then
20875 Set_Has_Protected
(Typ
);
20878 if Has_Timing_Event
(Comp_Typ
) then
20879 Set_Has_Timing_Event
(Typ
);
20881 end Propagate_Concurrent_Flags
;
20883 ------------------------------
20884 -- Propagate_DIC_Attributes --
20885 ------------------------------
20887 procedure Propagate_DIC_Attributes
20889 From_Typ
: Entity_Id
)
20891 DIC_Proc
: Entity_Id
;
20894 if Present
(Typ
) and then Present
(From_Typ
) then
20895 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
20897 -- Nothing to do if both the source and the destination denote the
20900 if From_Typ
= Typ
then
20904 DIC_Proc
:= DIC_Procedure
(From_Typ
);
20906 -- The setting of the attributes is intentionally conservative. This
20907 -- prevents accidental clobbering of enabled attributes.
20909 if Has_Inherited_DIC
(From_Typ
)
20910 and then not Has_Inherited_DIC
(Typ
)
20912 Set_Has_Inherited_DIC
(Typ
);
20915 if Has_Own_DIC
(From_Typ
) and then not Has_Own_DIC
(Typ
) then
20916 Set_Has_Own_DIC
(Typ
);
20919 if Present
(DIC_Proc
) and then No
(DIC_Procedure
(Typ
)) then
20920 Set_DIC_Procedure
(Typ
, DIC_Proc
);
20923 end Propagate_DIC_Attributes
;
20925 ------------------------------------
20926 -- Propagate_Invariant_Attributes --
20927 ------------------------------------
20929 procedure Propagate_Invariant_Attributes
20931 From_Typ
: Entity_Id
)
20933 Full_IP
: Entity_Id
;
20934 Part_IP
: Entity_Id
;
20937 if Present
(Typ
) and then Present
(From_Typ
) then
20938 pragma Assert
(Is_Type
(Typ
) and then Is_Type
(From_Typ
));
20940 -- Nothing to do if both the source and the destination denote the
20943 if From_Typ
= Typ
then
20947 Full_IP
:= Invariant_Procedure
(From_Typ
);
20948 Part_IP
:= Partial_Invariant_Procedure
(From_Typ
);
20950 -- The setting of the attributes is intentionally conservative. This
20951 -- prevents accidental clobbering of enabled attributes.
20953 if Has_Inheritable_Invariants
(From_Typ
)
20954 and then not Has_Inheritable_Invariants
(Typ
)
20956 Set_Has_Inheritable_Invariants
(Typ
, True);
20959 if Has_Inherited_Invariants
(From_Typ
)
20960 and then not Has_Inherited_Invariants
(Typ
)
20962 Set_Has_Inherited_Invariants
(Typ
, True);
20965 if Has_Own_Invariants
(From_Typ
)
20966 and then not Has_Own_Invariants
(Typ
)
20968 Set_Has_Own_Invariants
(Typ
, True);
20971 if Present
(Full_IP
) and then No
(Invariant_Procedure
(Typ
)) then
20972 Set_Invariant_Procedure
(Typ
, Full_IP
);
20975 if Present
(Part_IP
) and then No
(Partial_Invariant_Procedure
(Typ
))
20977 Set_Partial_Invariant_Procedure
(Typ
, Part_IP
);
20980 end Propagate_Invariant_Attributes
;
20982 ---------------------------------------
20983 -- Record_Possible_Part_Of_Reference --
20984 ---------------------------------------
20986 procedure Record_Possible_Part_Of_Reference
20987 (Var_Id
: Entity_Id
;
20990 Encap
: constant Entity_Id
:= Encapsulating_State
(Var_Id
);
20994 -- The variable is a constituent of a single protected/task type. Such
20995 -- a variable acts as a component of the type and must appear within a
20996 -- specific region (SPARK RM 9.3). Instead of recording the reference,
20997 -- verify its legality now.
20999 if Present
(Encap
) and then Is_Single_Concurrent_Object
(Encap
) then
21000 Check_Part_Of_Reference
(Var_Id
, Ref
);
21002 -- The variable is subject to pragma Part_Of and may eventually become a
21003 -- constituent of a single protected/task type. Record the reference to
21004 -- verify its placement when the contract of the variable is analyzed.
21006 elsif Present
(Get_Pragma
(Var_Id
, Pragma_Part_Of
)) then
21007 Refs
:= Part_Of_References
(Var_Id
);
21010 Refs
:= New_Elmt_List
;
21011 Set_Part_Of_References
(Var_Id
, Refs
);
21014 Append_Elmt
(Ref
, Refs
);
21016 end Record_Possible_Part_Of_Reference
;
21022 function Referenced
(Id
: Entity_Id
; Expr
: Node_Id
) return Boolean is
21023 Seen
: Boolean := False;
21025 function Is_Reference
(N
: Node_Id
) return Traverse_Result
;
21026 -- Determine whether node N denotes a reference to Id. If this is the
21027 -- case, set global flag Seen to True and stop the traversal.
21033 function Is_Reference
(N
: Node_Id
) return Traverse_Result
is
21035 if Is_Entity_Name
(N
)
21036 and then Present
(Entity
(N
))
21037 and then Entity
(N
) = Id
21046 procedure Inspect_Expression
is new Traverse_Proc
(Is_Reference
);
21048 -- Start of processing for Referenced
21051 Inspect_Expression
(Expr
);
21055 ------------------------------------
21056 -- References_Generic_Formal_Type --
21057 ------------------------------------
21059 function References_Generic_Formal_Type
(N
: Node_Id
) return Boolean is
21061 function Process
(N
: Node_Id
) return Traverse_Result
;
21062 -- Process one node in search for generic formal type
21068 function Process
(N
: Node_Id
) return Traverse_Result
is
21070 if Nkind
(N
) in N_Has_Entity
then
21072 E
: constant Entity_Id
:= Entity
(N
);
21074 if Present
(E
) then
21075 if Is_Generic_Type
(E
) then
21077 elsif Present
(Etype
(E
))
21078 and then Is_Generic_Type
(Etype
(E
))
21089 function Traverse
is new Traverse_Func
(Process
);
21090 -- Traverse tree to look for generic type
21093 if Inside_A_Generic
then
21094 return Traverse
(N
) = Abandon
;
21098 end References_Generic_Formal_Type
;
21100 -------------------
21101 -- Remove_Entity --
21102 -------------------
21104 procedure Remove_Entity
(Id
: Entity_Id
) is
21105 Scop
: constant Entity_Id
:= Scope
(Id
);
21106 Prev_Id
: Entity_Id
;
21109 -- Remove the entity from the homonym chain. When the entity is the
21110 -- head of the chain, associate the entry in the name table with its
21111 -- homonym effectively making it the new head of the chain.
21113 if Current_Entity
(Id
) = Id
then
21114 Set_Name_Entity_Id
(Chars
(Id
), Homonym
(Id
));
21116 -- Otherwise link the previous and next homonyms
21119 Prev_Id
:= Current_Entity
(Id
);
21120 while Present
(Prev_Id
) and then Homonym
(Prev_Id
) /= Id
loop
21121 Prev_Id
:= Homonym
(Prev_Id
);
21124 Set_Homonym
(Prev_Id
, Homonym
(Id
));
21127 -- Remove the entity from the scope entity chain. When the entity is
21128 -- the head of the chain, set the next entity as the new head of the
21131 if First_Entity
(Scop
) = Id
then
21133 Set_First_Entity
(Scop
, Next_Entity
(Id
));
21135 -- Otherwise the entity is either in the middle of the chain or it acts
21136 -- as its tail. Traverse and link the previous and next entities.
21139 Prev_Id
:= First_Entity
(Scop
);
21140 while Present
(Prev_Id
) and then Next_Entity
(Prev_Id
) /= Id
loop
21141 Next_Entity
(Prev_Id
);
21144 Set_Next_Entity
(Prev_Id
, Next_Entity
(Id
));
21147 -- Handle the case where the entity acts as the tail of the scope entity
21150 if Last_Entity
(Scop
) = Id
then
21151 Set_Last_Entity
(Scop
, Prev_Id
);
21155 --------------------
21156 -- Remove_Homonym --
21157 --------------------
21159 procedure Remove_Homonym
(E
: Entity_Id
) is
21160 Prev
: Entity_Id
:= Empty
;
21164 if E
= Current_Entity
(E
) then
21165 if Present
(Homonym
(E
)) then
21166 Set_Current_Entity
(Homonym
(E
));
21168 Set_Name_Entity_Id
(Chars
(E
), Empty
);
21172 H
:= Current_Entity
(E
);
21173 while Present
(H
) and then H
/= E
loop
21178 -- If E is not on the homonym chain, nothing to do
21180 if Present
(H
) then
21181 Set_Homonym
(Prev
, Homonym
(E
));
21184 end Remove_Homonym
;
21186 ------------------------------
21187 -- Remove_Overloaded_Entity --
21188 ------------------------------
21190 procedure Remove_Overloaded_Entity
(Id
: Entity_Id
) is
21191 procedure Remove_Primitive_Of
(Typ
: Entity_Id
);
21192 -- Remove primitive subprogram Id from the list of primitives that
21193 -- belong to type Typ.
21195 -------------------------
21196 -- Remove_Primitive_Of --
21197 -------------------------
21199 procedure Remove_Primitive_Of
(Typ
: Entity_Id
) is
21203 if Is_Tagged_Type
(Typ
) then
21204 Prims
:= Direct_Primitive_Operations
(Typ
);
21206 if Present
(Prims
) then
21207 Remove
(Prims
, Id
);
21210 end Remove_Primitive_Of
;
21214 Formal
: Entity_Id
;
21216 -- Start of processing for Remove_Overloaded_Entity
21219 -- Remove the entity from both the homonym and scope chains
21221 Remove_Entity
(Id
);
21223 -- The entity denotes a primitive subprogram. Remove it from the list of
21224 -- primitives of the associated controlling type.
21226 if Ekind_In
(Id
, E_Function
, E_Procedure
) and then Is_Primitive
(Id
) then
21227 Formal
:= First_Formal
(Id
);
21228 while Present
(Formal
) loop
21229 if Is_Controlling_Formal
(Formal
) then
21230 Remove_Primitive_Of
(Etype
(Formal
));
21234 Next_Formal
(Formal
);
21237 if Ekind
(Id
) = E_Function
and then Has_Controlling_Result
(Id
) then
21238 Remove_Primitive_Of
(Etype
(Id
));
21241 end Remove_Overloaded_Entity
;
21243 ---------------------
21244 -- Rep_To_Pos_Flag --
21245 ---------------------
21247 function Rep_To_Pos_Flag
(E
: Entity_Id
; Loc
: Source_Ptr
) return Node_Id
is
21249 return New_Occurrence_Of
21250 (Boolean_Literals
(not Range_Checks_Suppressed
(E
)), Loc
);
21251 end Rep_To_Pos_Flag
;
21253 --------------------
21254 -- Require_Entity --
21255 --------------------
21257 procedure Require_Entity
(N
: Node_Id
) is
21259 if Is_Entity_Name
(N
) and then No
(Entity
(N
)) then
21260 if Total_Errors_Detected
/= 0 then
21261 Set_Entity
(N
, Any_Id
);
21263 raise Program_Error
;
21266 end Require_Entity
;
21268 ------------------------------
21269 -- Requires_Transient_Scope --
21270 ------------------------------
21272 -- A transient scope is required when variable-sized temporaries are
21273 -- allocated on the secondary stack, or when finalization actions must be
21274 -- generated before the next instruction.
21276 function Requires_Transient_Scope
(Id
: Entity_Id
) return Boolean is
21277 Old_Result
: constant Boolean := Old_Requires_Transient_Scope
(Id
);
21280 if Debug_Flag_QQ
then
21285 New_Result
: constant Boolean := New_Requires_Transient_Scope
(Id
);
21288 -- Assert that we're not putting things on the secondary stack if we
21289 -- didn't before; we are trying to AVOID secondary stack when
21292 if not Old_Result
then
21293 pragma Assert
(not New_Result
);
21297 if New_Result
/= Old_Result
then
21298 Results_Differ
(Id
, Old_Result
, New_Result
);
21303 end Requires_Transient_Scope
;
21305 --------------------
21306 -- Results_Differ --
21307 --------------------
21309 procedure Results_Differ
21315 if False then -- False to disable; True for debugging
21316 Treepr
.Print_Tree_Node
(Id
);
21318 if Old_Val
= New_Val
then
21319 raise Program_Error
;
21322 end Results_Differ
;
21324 --------------------------
21325 -- Reset_Analyzed_Flags --
21326 --------------------------
21328 procedure Reset_Analyzed_Flags
(N
: Node_Id
) is
21329 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
;
21330 -- Function used to reset Analyzed flags in tree. Note that we do
21331 -- not reset Analyzed flags in entities, since there is no need to
21332 -- reanalyze entities, and indeed, it is wrong to do so, since it
21333 -- can result in generating auxiliary stuff more than once.
21335 --------------------
21336 -- Clear_Analyzed --
21337 --------------------
21339 function Clear_Analyzed
(N
: Node_Id
) return Traverse_Result
is
21341 if Nkind
(N
) not in N_Entity
then
21342 Set_Analyzed
(N
, False);
21346 end Clear_Analyzed
;
21348 procedure Reset_Analyzed
is new Traverse_Proc
(Clear_Analyzed
);
21350 -- Start of processing for Reset_Analyzed_Flags
21353 Reset_Analyzed
(N
);
21354 end Reset_Analyzed_Flags
;
21356 ------------------------
21357 -- Restore_SPARK_Mode --
21358 ------------------------
21360 procedure Restore_SPARK_Mode
21361 (Mode
: SPARK_Mode_Type
;
21365 SPARK_Mode
:= Mode
;
21366 SPARK_Mode_Pragma
:= Prag
;
21367 end Restore_SPARK_Mode
;
21369 --------------------------------
21370 -- Returns_Unconstrained_Type --
21371 --------------------------------
21373 function Returns_Unconstrained_Type
(Subp
: Entity_Id
) return Boolean is
21375 return Ekind
(Subp
) = E_Function
21376 and then not Is_Scalar_Type
(Etype
(Subp
))
21377 and then not Is_Access_Type
(Etype
(Subp
))
21378 and then not Is_Constrained
(Etype
(Subp
));
21379 end Returns_Unconstrained_Type
;
21381 ----------------------------
21382 -- Root_Type_Of_Full_View --
21383 ----------------------------
21385 function Root_Type_Of_Full_View
(T
: Entity_Id
) return Entity_Id
is
21386 Rtyp
: constant Entity_Id
:= Root_Type
(T
);
21389 -- The root type of the full view may itself be a private type. Keep
21390 -- looking for the ultimate derivation parent.
21392 if Is_Private_Type
(Rtyp
) and then Present
(Full_View
(Rtyp
)) then
21393 return Root_Type_Of_Full_View
(Full_View
(Rtyp
));
21397 end Root_Type_Of_Full_View
;
21399 ---------------------------
21400 -- Safe_To_Capture_Value --
21401 ---------------------------
21403 function Safe_To_Capture_Value
21406 Cond
: Boolean := False) return Boolean
21409 -- The only entities for which we track constant values are variables
21410 -- which are not renamings, constants, out parameters, and in out
21411 -- parameters, so check if we have this case.
21413 -- Note: it may seem odd to track constant values for constants, but in
21414 -- fact this routine is used for other purposes than simply capturing
21415 -- the value. In particular, the setting of Known[_Non]_Null.
21417 if (Ekind
(Ent
) = E_Variable
and then No
(Renamed_Object
(Ent
)))
21419 Ekind_In
(Ent
, E_Constant
, E_Out_Parameter
, E_In_Out_Parameter
)
21423 -- For conditionals, we also allow loop parameters and all formals,
21424 -- including in parameters.
21426 elsif Cond
and then Ekind_In
(Ent
, E_Loop_Parameter
, E_In_Parameter
) then
21429 -- For all other cases, not just unsafe, but impossible to capture
21430 -- Current_Value, since the above are the only entities which have
21431 -- Current_Value fields.
21437 -- Skip if volatile or aliased, since funny things might be going on in
21438 -- these cases which we cannot necessarily track. Also skip any variable
21439 -- for which an address clause is given, or whose address is taken. Also
21440 -- never capture value of library level variables (an attempt to do so
21441 -- can occur in the case of package elaboration code).
21443 if Treat_As_Volatile
(Ent
)
21444 or else Is_Aliased
(Ent
)
21445 or else Present
(Address_Clause
(Ent
))
21446 or else Address_Taken
(Ent
)
21447 or else (Is_Library_Level_Entity
(Ent
)
21448 and then Ekind
(Ent
) = E_Variable
)
21453 -- OK, all above conditions are met. We also require that the scope of
21454 -- the reference be the same as the scope of the entity, not counting
21455 -- packages and blocks and loops.
21458 E_Scope
: constant Entity_Id
:= Scope
(Ent
);
21459 R_Scope
: Entity_Id
;
21462 R_Scope
:= Current_Scope
;
21463 while R_Scope
/= Standard_Standard
loop
21464 exit when R_Scope
= E_Scope
;
21466 if not Ekind_In
(R_Scope
, E_Package
, E_Block
, E_Loop
) then
21469 R_Scope
:= Scope
(R_Scope
);
21474 -- We also require that the reference does not appear in a context
21475 -- where it is not sure to be executed (i.e. a conditional context
21476 -- or an exception handler). We skip this if Cond is True, since the
21477 -- capturing of values from conditional tests handles this ok.
21490 -- Seems dubious that case expressions are not handled here ???
21493 while Present
(P
) loop
21494 if Nkind
(P
) = N_If_Statement
21495 or else Nkind
(P
) = N_Case_Statement
21496 or else (Nkind
(P
) in N_Short_Circuit
21497 and then Desc
= Right_Opnd
(P
))
21498 or else (Nkind
(P
) = N_If_Expression
21499 and then Desc
/= First
(Expressions
(P
)))
21500 or else Nkind
(P
) = N_Exception_Handler
21501 or else Nkind
(P
) = N_Selective_Accept
21502 or else Nkind
(P
) = N_Conditional_Entry_Call
21503 or else Nkind
(P
) = N_Timed_Entry_Call
21504 or else Nkind
(P
) = N_Asynchronous_Select
21512 -- A special Ada 2012 case: the original node may be part
21513 -- of the else_actions of a conditional expression, in which
21514 -- case it might not have been expanded yet, and appears in
21515 -- a non-syntactic list of actions. In that case it is clearly
21516 -- not safe to save a value.
21519 and then Is_List_Member
(Desc
)
21520 and then No
(Parent
(List_Containing
(Desc
)))
21528 -- OK, looks safe to set value
21531 end Safe_To_Capture_Value
;
21537 function Same_Name
(N1
, N2
: Node_Id
) return Boolean is
21538 K1
: constant Node_Kind
:= Nkind
(N1
);
21539 K2
: constant Node_Kind
:= Nkind
(N2
);
21542 if (K1
= N_Identifier
or else K1
= N_Defining_Identifier
)
21543 and then (K2
= N_Identifier
or else K2
= N_Defining_Identifier
)
21545 return Chars
(N1
) = Chars
(N2
);
21547 elsif (K1
= N_Selected_Component
or else K1
= N_Expanded_Name
)
21548 and then (K2
= N_Selected_Component
or else K2
= N_Expanded_Name
)
21550 return Same_Name
(Selector_Name
(N1
), Selector_Name
(N2
))
21551 and then Same_Name
(Prefix
(N1
), Prefix
(N2
));
21562 function Same_Object
(Node1
, Node2
: Node_Id
) return Boolean is
21563 N1
: constant Node_Id
:= Original_Node
(Node1
);
21564 N2
: constant Node_Id
:= Original_Node
(Node2
);
21565 -- We do the tests on original nodes, since we are most interested
21566 -- in the original source, not any expansion that got in the way.
21568 K1
: constant Node_Kind
:= Nkind
(N1
);
21569 K2
: constant Node_Kind
:= Nkind
(N2
);
21572 -- First case, both are entities with same entity
21574 if K1
in N_Has_Entity
and then K2
in N_Has_Entity
then
21576 EN1
: constant Entity_Id
:= Entity
(N1
);
21577 EN2
: constant Entity_Id
:= Entity
(N2
);
21579 if Present
(EN1
) and then Present
(EN2
)
21580 and then (Ekind_In
(EN1
, E_Variable
, E_Constant
)
21581 or else Is_Formal
(EN1
))
21589 -- Second case, selected component with same selector, same record
21591 if K1
= N_Selected_Component
21592 and then K2
= N_Selected_Component
21593 and then Chars
(Selector_Name
(N1
)) = Chars
(Selector_Name
(N2
))
21595 return Same_Object
(Prefix
(N1
), Prefix
(N2
));
21597 -- Third case, indexed component with same subscripts, same array
21599 elsif K1
= N_Indexed_Component
21600 and then K2
= N_Indexed_Component
21601 and then Same_Object
(Prefix
(N1
), Prefix
(N2
))
21606 E1
:= First
(Expressions
(N1
));
21607 E2
:= First
(Expressions
(N2
));
21608 while Present
(E1
) loop
21609 if not Same_Value
(E1
, E2
) then
21620 -- Fourth case, slice of same array with same bounds
21623 and then K2
= N_Slice
21624 and then Nkind
(Discrete_Range
(N1
)) = N_Range
21625 and then Nkind
(Discrete_Range
(N2
)) = N_Range
21626 and then Same_Value
(Low_Bound
(Discrete_Range
(N1
)),
21627 Low_Bound
(Discrete_Range
(N2
)))
21628 and then Same_Value
(High_Bound
(Discrete_Range
(N1
)),
21629 High_Bound
(Discrete_Range
(N2
)))
21631 return Same_Name
(Prefix
(N1
), Prefix
(N2
));
21633 -- All other cases, not clearly the same object
21644 function Same_Type
(T1
, T2
: Entity_Id
) return Boolean is
21649 elsif not Is_Constrained
(T1
)
21650 and then not Is_Constrained
(T2
)
21651 and then Base_Type
(T1
) = Base_Type
(T2
)
21655 -- For now don't bother with case of identical constraints, to be
21656 -- fiddled with later on perhaps (this is only used for optimization
21657 -- purposes, so it is not critical to do a best possible job)
21668 function Same_Value
(Node1
, Node2
: Node_Id
) return Boolean is
21670 if Compile_Time_Known_Value
(Node1
)
21671 and then Compile_Time_Known_Value
(Node2
)
21673 -- Handle properly compile-time expressions that are not
21676 if Is_String_Type
(Etype
(Node1
)) then
21677 return Expr_Value_S
(Node1
) = Expr_Value_S
(Node2
);
21680 return Expr_Value
(Node1
) = Expr_Value
(Node2
);
21683 elsif Same_Object
(Node1
, Node2
) then
21690 --------------------
21691 -- Set_SPARK_Mode --
21692 --------------------
21694 procedure Set_SPARK_Mode
(Context
: Entity_Id
) is
21696 -- Do not consider illegal or partially decorated constructs
21698 if Ekind
(Context
) = E_Void
or else Error_Posted
(Context
) then
21701 elsif Present
(SPARK_Pragma
(Context
)) then
21703 (Mode
=> Get_SPARK_Mode_From_Annotation
(SPARK_Pragma
(Context
)),
21704 Prag
=> SPARK_Pragma
(Context
));
21706 end Set_SPARK_Mode
;
21708 -------------------------
21709 -- Scalar_Part_Present --
21710 -------------------------
21712 function Scalar_Part_Present
(T
: Entity_Id
) return Boolean is
21716 if Is_Scalar_Type
(T
) then
21719 elsif Is_Array_Type
(T
) then
21720 return Scalar_Part_Present
(Component_Type
(T
));
21722 elsif Is_Record_Type
(T
) or else Has_Discriminants
(T
) then
21723 C
:= First_Component_Or_Discriminant
(T
);
21724 while Present
(C
) loop
21725 if Scalar_Part_Present
(Etype
(C
)) then
21728 Next_Component_Or_Discriminant
(C
);
21734 end Scalar_Part_Present
;
21736 ------------------------
21737 -- Scope_Is_Transient --
21738 ------------------------
21740 function Scope_Is_Transient
return Boolean is
21742 return Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
;
21743 end Scope_Is_Transient
;
21749 function Scope_Within
(Scope1
, Scope2
: Entity_Id
) return Boolean is
21754 while Scop
/= Standard_Standard
loop
21755 Scop
:= Scope
(Scop
);
21757 if Scop
= Scope2
then
21765 --------------------------
21766 -- Scope_Within_Or_Same --
21767 --------------------------
21769 function Scope_Within_Or_Same
(Scope1
, Scope2
: Entity_Id
) return Boolean is
21774 while Scop
/= Standard_Standard
loop
21775 if Scop
= Scope2
then
21778 Scop
:= Scope
(Scop
);
21783 end Scope_Within_Or_Same
;
21785 --------------------
21786 -- Set_Convention --
21787 --------------------
21789 procedure Set_Convention
(E
: Entity_Id
; Val
: Snames
.Convention_Id
) is
21791 Basic_Set_Convention
(E
, Val
);
21794 and then Is_Access_Subprogram_Type
(Base_Type
(E
))
21795 and then Has_Foreign_Convention
(E
)
21798 -- A pragma Convention in an instance may apply to the subtype
21799 -- created for a formal, in which case we have already verified
21800 -- that conventions of actual and formal match and there is nothing
21801 -- to flag on the subtype.
21803 if In_Instance
then
21806 Set_Can_Use_Internal_Rep
(E
, False);
21810 -- If E is an object or component, and the type of E is an anonymous
21811 -- access type with no convention set, then also set the convention of
21812 -- the anonymous access type. We do not do this for anonymous protected
21813 -- types, since protected types always have the default convention.
21815 if Present
(Etype
(E
))
21816 and then (Is_Object
(E
)
21817 or else Ekind
(E
) = E_Component
21819 -- Allow E_Void (happens for pragma Convention appearing
21820 -- in the middle of a record applying to a component)
21822 or else Ekind
(E
) = E_Void
)
21825 Typ
: constant Entity_Id
:= Etype
(E
);
21828 if Ekind_In
(Typ
, E_Anonymous_Access_Type
,
21829 E_Anonymous_Access_Subprogram_Type
)
21830 and then not Has_Convention_Pragma
(Typ
)
21832 Basic_Set_Convention
(Typ
, Val
);
21833 Set_Has_Convention_Pragma
(Typ
);
21835 -- And for the access subprogram type, deal similarly with the
21836 -- designated E_Subprogram_Type if it is also internal (which
21839 if Ekind
(Typ
) = E_Anonymous_Access_Subprogram_Type
then
21841 Dtype
: constant Entity_Id
:= Designated_Type
(Typ
);
21843 if Ekind
(Dtype
) = E_Subprogram_Type
21844 and then Is_Itype
(Dtype
)
21845 and then not Has_Convention_Pragma
(Dtype
)
21847 Basic_Set_Convention
(Dtype
, Val
);
21848 Set_Has_Convention_Pragma
(Dtype
);
21855 end Set_Convention
;
21857 ------------------------
21858 -- Set_Current_Entity --
21859 ------------------------
21861 -- The given entity is to be set as the currently visible definition of its
21862 -- associated name (i.e. the Node_Id associated with its name). All we have
21863 -- to do is to get the name from the identifier, and then set the
21864 -- associated Node_Id to point to the given entity.
21866 procedure Set_Current_Entity
(E
: Entity_Id
) is
21868 Set_Name_Entity_Id
(Chars
(E
), E
);
21869 end Set_Current_Entity
;
21871 ---------------------------
21872 -- Set_Debug_Info_Needed --
21873 ---------------------------
21875 procedure Set_Debug_Info_Needed
(T
: Entity_Id
) is
21877 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
);
21878 pragma Inline
(Set_Debug_Info_Needed_If_Not_Set
);
21879 -- Used to set debug info in a related node if not set already
21881 --------------------------------------
21882 -- Set_Debug_Info_Needed_If_Not_Set --
21883 --------------------------------------
21885 procedure Set_Debug_Info_Needed_If_Not_Set
(E
: Entity_Id
) is
21887 if Present
(E
) and then not Needs_Debug_Info
(E
) then
21888 Set_Debug_Info_Needed
(E
);
21890 -- For a private type, indicate that the full view also needs
21891 -- debug information.
21894 and then Is_Private_Type
(E
)
21895 and then Present
(Full_View
(E
))
21897 Set_Debug_Info_Needed
(Full_View
(E
));
21900 end Set_Debug_Info_Needed_If_Not_Set
;
21902 -- Start of processing for Set_Debug_Info_Needed
21905 -- Nothing to do if argument is Empty or has Debug_Info_Off set, which
21906 -- indicates that Debug_Info_Needed is never required for the entity.
21907 -- Nothing to do if entity comes from a predefined file. Library files
21908 -- are compiled without debug information, but inlined bodies of these
21909 -- routines may appear in user code, and debug information on them ends
21910 -- up complicating debugging the user code.
21913 or else Debug_Info_Off
(T
)
21917 elsif In_Inlined_Body
and then In_Predefined_Unit
(T
) then
21918 Set_Needs_Debug_Info
(T
, False);
21921 -- Set flag in entity itself. Note that we will go through the following
21922 -- circuitry even if the flag is already set on T. That's intentional,
21923 -- it makes sure that the flag will be set in subsidiary entities.
21925 Set_Needs_Debug_Info
(T
);
21927 -- Set flag on subsidiary entities if not set already
21929 if Is_Object
(T
) then
21930 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
21932 elsif Is_Type
(T
) then
21933 Set_Debug_Info_Needed_If_Not_Set
(Etype
(T
));
21935 if Is_Record_Type
(T
) then
21937 Ent
: Entity_Id
:= First_Entity
(T
);
21939 while Present
(Ent
) loop
21940 Set_Debug_Info_Needed_If_Not_Set
(Ent
);
21945 -- For a class wide subtype, we also need debug information
21946 -- for the equivalent type.
21948 if Ekind
(T
) = E_Class_Wide_Subtype
then
21949 Set_Debug_Info_Needed_If_Not_Set
(Equivalent_Type
(T
));
21952 elsif Is_Array_Type
(T
) then
21953 Set_Debug_Info_Needed_If_Not_Set
(Component_Type
(T
));
21956 Indx
: Node_Id
:= First_Index
(T
);
21958 while Present
(Indx
) loop
21959 Set_Debug_Info_Needed_If_Not_Set
(Etype
(Indx
));
21960 Indx
:= Next_Index
(Indx
);
21964 -- For a packed array type, we also need debug information for
21965 -- the type used to represent the packed array. Conversely, we
21966 -- also need it for the former if we need it for the latter.
21968 if Is_Packed
(T
) then
21969 Set_Debug_Info_Needed_If_Not_Set
(Packed_Array_Impl_Type
(T
));
21972 if Is_Packed_Array_Impl_Type
(T
) then
21973 Set_Debug_Info_Needed_If_Not_Set
(Original_Array_Type
(T
));
21976 elsif Is_Access_Type
(T
) then
21977 Set_Debug_Info_Needed_If_Not_Set
(Directly_Designated_Type
(T
));
21979 elsif Is_Private_Type
(T
) then
21981 FV
: constant Entity_Id
:= Full_View
(T
);
21984 Set_Debug_Info_Needed_If_Not_Set
(FV
);
21986 -- If the full view is itself a derived private type, we need
21987 -- debug information on its underlying type.
21990 and then Is_Private_Type
(FV
)
21991 and then Present
(Underlying_Full_View
(FV
))
21993 Set_Needs_Debug_Info
(Underlying_Full_View
(FV
));
21997 elsif Is_Protected_Type
(T
) then
21998 Set_Debug_Info_Needed_If_Not_Set
(Corresponding_Record_Type
(T
));
22000 elsif Is_Scalar_Type
(T
) then
22002 -- If the subrange bounds are materialized by dedicated constant
22003 -- objects, also include them in the debug info to make sure the
22004 -- debugger can properly use them.
22006 if Present
(Scalar_Range
(T
))
22007 and then Nkind
(Scalar_Range
(T
)) = N_Range
22010 Low_Bnd
: constant Node_Id
:= Type_Low_Bound
(T
);
22011 High_Bnd
: constant Node_Id
:= Type_High_Bound
(T
);
22014 if Is_Entity_Name
(Low_Bnd
) then
22015 Set_Debug_Info_Needed_If_Not_Set
(Entity
(Low_Bnd
));
22018 if Is_Entity_Name
(High_Bnd
) then
22019 Set_Debug_Info_Needed_If_Not_Set
(Entity
(High_Bnd
));
22025 end Set_Debug_Info_Needed
;
22027 ----------------------------
22028 -- Set_Entity_With_Checks --
22029 ----------------------------
22031 procedure Set_Entity_With_Checks
(N
: Node_Id
; Val
: Entity_Id
) is
22032 Val_Actual
: Entity_Id
;
22034 Post_Node
: Node_Id
;
22037 -- Unconditionally set the entity
22039 Set_Entity
(N
, Val
);
22041 -- The node to post on is the selector in the case of an expanded name,
22042 -- and otherwise the node itself.
22044 if Nkind
(N
) = N_Expanded_Name
then
22045 Post_Node
:= Selector_Name
(N
);
22050 -- Check for violation of No_Fixed_IO
22052 if Restriction_Check_Required
(No_Fixed_IO
)
22054 ((RTU_Loaded
(Ada_Text_IO
)
22055 and then (Is_RTE
(Val
, RE_Decimal_IO
)
22057 Is_RTE
(Val
, RE_Fixed_IO
)))
22060 (RTU_Loaded
(Ada_Wide_Text_IO
)
22061 and then (Is_RTE
(Val
, RO_WT_Decimal_IO
)
22063 Is_RTE
(Val
, RO_WT_Fixed_IO
)))
22066 (RTU_Loaded
(Ada_Wide_Wide_Text_IO
)
22067 and then (Is_RTE
(Val
, RO_WW_Decimal_IO
)
22069 Is_RTE
(Val
, RO_WW_Fixed_IO
))))
22071 -- A special extra check, don't complain about a reference from within
22072 -- the Ada.Interrupts package itself!
22074 and then not In_Same_Extended_Unit
(N
, Val
)
22076 Check_Restriction
(No_Fixed_IO
, Post_Node
);
22079 -- Remaining checks are only done on source nodes. Note that we test
22080 -- for violation of No_Fixed_IO even on non-source nodes, because the
22081 -- cases for checking violations of this restriction are instantiations
22082 -- where the reference in the instance has Comes_From_Source False.
22084 if not Comes_From_Source
(N
) then
22088 -- Check for violation of No_Abort_Statements, which is triggered by
22089 -- call to Ada.Task_Identification.Abort_Task.
22091 if Restriction_Check_Required
(No_Abort_Statements
)
22092 and then (Is_RTE
(Val
, RE_Abort_Task
))
22094 -- A special extra check, don't complain about a reference from within
22095 -- the Ada.Task_Identification package itself!
22097 and then not In_Same_Extended_Unit
(N
, Val
)
22099 Check_Restriction
(No_Abort_Statements
, Post_Node
);
22102 if Val
= Standard_Long_Long_Integer
then
22103 Check_Restriction
(No_Long_Long_Integers
, Post_Node
);
22106 -- Check for violation of No_Dynamic_Attachment
22108 if Restriction_Check_Required
(No_Dynamic_Attachment
)
22109 and then RTU_Loaded
(Ada_Interrupts
)
22110 and then (Is_RTE
(Val
, RE_Is_Reserved
) or else
22111 Is_RTE
(Val
, RE_Is_Attached
) or else
22112 Is_RTE
(Val
, RE_Current_Handler
) or else
22113 Is_RTE
(Val
, RE_Attach_Handler
) or else
22114 Is_RTE
(Val
, RE_Exchange_Handler
) or else
22115 Is_RTE
(Val
, RE_Detach_Handler
) or else
22116 Is_RTE
(Val
, RE_Reference
))
22118 -- A special extra check, don't complain about a reference from within
22119 -- the Ada.Interrupts package itself!
22121 and then not In_Same_Extended_Unit
(N
, Val
)
22123 Check_Restriction
(No_Dynamic_Attachment
, Post_Node
);
22126 -- Check for No_Implementation_Identifiers
22128 if Restriction_Check_Required
(No_Implementation_Identifiers
) then
22130 -- We have an implementation defined entity if it is marked as
22131 -- implementation defined, or is defined in a package marked as
22132 -- implementation defined. However, library packages themselves
22133 -- are excluded (we don't want to flag Interfaces itself, just
22134 -- the entities within it).
22136 if (Is_Implementation_Defined
(Val
)
22138 (Present
(Scope
(Val
))
22139 and then Is_Implementation_Defined
(Scope
(Val
))))
22140 and then not (Ekind_In
(Val
, E_Package
, E_Generic_Package
)
22141 and then Is_Library_Level_Entity
(Val
))
22143 Check_Restriction
(No_Implementation_Identifiers
, Post_Node
);
22147 -- Do the style check
22150 and then not Suppress_Style_Checks
(Val
)
22151 and then not In_Instance
22153 if Nkind
(N
) = N_Identifier
then
22155 elsif Nkind
(N
) = N_Expanded_Name
then
22156 Nod
:= Selector_Name
(N
);
22161 -- A special situation arises for derived operations, where we want
22162 -- to do the check against the parent (since the Sloc of the derived
22163 -- operation points to the derived type declaration itself).
22166 while not Comes_From_Source
(Val_Actual
)
22167 and then Nkind
(Val_Actual
) in N_Entity
22168 and then (Ekind
(Val_Actual
) = E_Enumeration_Literal
22169 or else Is_Subprogram_Or_Generic_Subprogram
(Val_Actual
))
22170 and then Present
(Alias
(Val_Actual
))
22172 Val_Actual
:= Alias
(Val_Actual
);
22175 -- Renaming declarations for generic actuals do not come from source,
22176 -- and have a different name from that of the entity they rename, so
22177 -- there is no style check to perform here.
22179 if Chars
(Nod
) = Chars
(Val_Actual
) then
22180 Style
.Check_Identifier
(Nod
, Val_Actual
);
22184 Set_Entity
(N
, Val
);
22185 end Set_Entity_With_Checks
;
22187 ------------------------
22188 -- Set_Name_Entity_Id --
22189 ------------------------
22191 procedure Set_Name_Entity_Id
(Id
: Name_Id
; Val
: Entity_Id
) is
22193 Set_Name_Table_Int
(Id
, Int
(Val
));
22194 end Set_Name_Entity_Id
;
22196 ---------------------
22197 -- Set_Next_Actual --
22198 ---------------------
22200 procedure Set_Next_Actual
(Ass1_Id
: Node_Id
; Ass2_Id
: Node_Id
) is
22202 if Nkind
(Parent
(Ass1_Id
)) = N_Parameter_Association
then
22203 Set_First_Named_Actual
(Parent
(Ass1_Id
), Ass2_Id
);
22205 end Set_Next_Actual
;
22207 ----------------------------------
22208 -- Set_Optimize_Alignment_Flags --
22209 ----------------------------------
22211 procedure Set_Optimize_Alignment_Flags
(E
: Entity_Id
) is
22213 if Optimize_Alignment
= 'S' then
22214 Set_Optimize_Alignment_Space
(E
);
22215 elsif Optimize_Alignment
= 'T' then
22216 Set_Optimize_Alignment_Time
(E
);
22218 end Set_Optimize_Alignment_Flags
;
22220 -----------------------
22221 -- Set_Public_Status --
22222 -----------------------
22224 procedure Set_Public_Status
(Id
: Entity_Id
) is
22225 S
: constant Entity_Id
:= Current_Scope
;
22227 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean;
22228 -- Determines if E is defined within handled statement sequence or
22229 -- an if statement, returns True if so, False otherwise.
22231 ----------------------
22232 -- Within_HSS_Or_If --
22233 ----------------------
22235 function Within_HSS_Or_If
(E
: Entity_Id
) return Boolean is
22238 N
:= Declaration_Node
(E
);
22245 elsif Nkind_In
(N
, N_Handled_Sequence_Of_Statements
,
22251 end Within_HSS_Or_If
;
22253 -- Start of processing for Set_Public_Status
22256 -- Everything in the scope of Standard is public
22258 if S
= Standard_Standard
then
22259 Set_Is_Public
(Id
);
22261 -- Entity is definitely not public if enclosing scope is not public
22263 elsif not Is_Public
(S
) then
22266 -- An object or function declaration that occurs in a handled sequence
22267 -- of statements or within an if statement is the declaration for a
22268 -- temporary object or local subprogram generated by the expander. It
22269 -- never needs to be made public and furthermore, making it public can
22270 -- cause back end problems.
22272 elsif Nkind_In
(Parent
(Id
), N_Object_Declaration
,
22273 N_Function_Specification
)
22274 and then Within_HSS_Or_If
(Id
)
22278 -- Entities in public packages or records are public
22280 elsif Ekind
(S
) = E_Package
or Is_Record_Type
(S
) then
22281 Set_Is_Public
(Id
);
22283 -- The bounds of an entry family declaration can generate object
22284 -- declarations that are visible to the back-end, e.g. in the
22285 -- the declaration of a composite type that contains tasks.
22287 elsif Is_Concurrent_Type
(S
)
22288 and then not Has_Completion
(S
)
22289 and then Nkind
(Parent
(Id
)) = N_Object_Declaration
22291 Set_Is_Public
(Id
);
22293 end Set_Public_Status
;
22295 -----------------------------
22296 -- Set_Referenced_Modified --
22297 -----------------------------
22299 procedure Set_Referenced_Modified
(N
: Node_Id
; Out_Param
: Boolean) is
22303 -- Deal with indexed or selected component where prefix is modified
22305 if Nkind_In
(N
, N_Indexed_Component
, N_Selected_Component
) then
22306 Pref
:= Prefix
(N
);
22308 -- If prefix is access type, then it is the designated object that is
22309 -- being modified, which means we have no entity to set the flag on.
22311 if No
(Etype
(Pref
)) or else Is_Access_Type
(Etype
(Pref
)) then
22314 -- Otherwise chase the prefix
22317 Set_Referenced_Modified
(Pref
, Out_Param
);
22320 -- Otherwise see if we have an entity name (only other case to process)
22322 elsif Is_Entity_Name
(N
) and then Present
(Entity
(N
)) then
22323 Set_Referenced_As_LHS
(Entity
(N
), not Out_Param
);
22324 Set_Referenced_As_Out_Parameter
(Entity
(N
), Out_Param
);
22326 end Set_Referenced_Modified
;
22332 procedure Set_Rep_Info
(T1
: Entity_Id
; T2
: Entity_Id
) is
22334 Set_Is_Atomic
(T1
, Is_Atomic
(T2
));
22335 Set_Is_Independent
(T1
, Is_Independent
(T2
));
22336 Set_Is_Volatile_Full_Access
(T1
, Is_Volatile_Full_Access
(T2
));
22338 if Is_Base_Type
(T1
) then
22339 Set_Is_Volatile
(T1
, Is_Volatile
(T2
));
22343 ----------------------------
22344 -- Set_Scope_Is_Transient --
22345 ----------------------------
22347 procedure Set_Scope_Is_Transient
(V
: Boolean := True) is
22349 Scope_Stack
.Table
(Scope_Stack
.Last
).Is_Transient
:= V
;
22350 end Set_Scope_Is_Transient
;
22352 -------------------
22353 -- Set_Size_Info --
22354 -------------------
22356 procedure Set_Size_Info
(T1
, T2
: Entity_Id
) is
22358 -- We copy Esize, but not RM_Size, since in general RM_Size is
22359 -- subtype specific and does not get inherited by all subtypes.
22361 Set_Esize
(T1
, Esize
(T2
));
22362 Set_Has_Biased_Representation
(T1
, Has_Biased_Representation
(T2
));
22364 if Is_Discrete_Or_Fixed_Point_Type
(T1
)
22366 Is_Discrete_Or_Fixed_Point_Type
(T2
)
22368 Set_Is_Unsigned_Type
(T1
, Is_Unsigned_Type
(T2
));
22371 Set_Alignment
(T1
, Alignment
(T2
));
22374 ------------------------------
22375 -- Should_Ignore_Pragma_Par --
22376 ------------------------------
22378 function Should_Ignore_Pragma_Par
(Prag_Name
: Name_Id
) return Boolean is
22379 pragma Assert
(Compiler_State
= Parsing
);
22380 -- This one can't work during semantic analysis, because we don't have a
22381 -- correct Current_Source_File.
22383 Result
: constant Boolean :=
22384 Get_Name_Table_Boolean3
(Prag_Name
)
22385 and then not Is_Internal_File_Name
22386 (File_Name
(Current_Source_File
));
22389 end Should_Ignore_Pragma_Par
;
22391 ------------------------------
22392 -- Should_Ignore_Pragma_Sem --
22393 ------------------------------
22395 function Should_Ignore_Pragma_Sem
(N
: Node_Id
) return Boolean is
22396 pragma Assert
(Compiler_State
= Analyzing
);
22397 Prag_Name
: constant Name_Id
:= Pragma_Name
(N
);
22398 Result
: constant Boolean :=
22399 Get_Name_Table_Boolean3
(Prag_Name
)
22400 and then not In_Internal_Unit
(N
);
22404 end Should_Ignore_Pragma_Sem
;
22406 --------------------
22407 -- Static_Boolean --
22408 --------------------
22410 function Static_Boolean
(N
: Node_Id
) return Uint
is
22412 Analyze_And_Resolve
(N
, Standard_Boolean
);
22415 or else Error_Posted
(N
)
22416 or else Etype
(N
) = Any_Type
22421 if Is_OK_Static_Expression
(N
) then
22422 if not Raises_Constraint_Error
(N
) then
22423 return Expr_Value
(N
);
22428 elsif Etype
(N
) = Any_Type
then
22432 Flag_Non_Static_Expr
22433 ("static boolean expression required here", N
);
22436 end Static_Boolean
;
22438 --------------------
22439 -- Static_Integer --
22440 --------------------
22442 function Static_Integer
(N
: Node_Id
) return Uint
is
22444 Analyze_And_Resolve
(N
, Any_Integer
);
22447 or else Error_Posted
(N
)
22448 or else Etype
(N
) = Any_Type
22453 if Is_OK_Static_Expression
(N
) then
22454 if not Raises_Constraint_Error
(N
) then
22455 return Expr_Value
(N
);
22460 elsif Etype
(N
) = Any_Type
then
22464 Flag_Non_Static_Expr
22465 ("static integer expression required here", N
);
22468 end Static_Integer
;
22470 --------------------------
22471 -- Statically_Different --
22472 --------------------------
22474 function Statically_Different
(E1
, E2
: Node_Id
) return Boolean is
22475 R1
: constant Node_Id
:= Get_Referenced_Object
(E1
);
22476 R2
: constant Node_Id
:= Get_Referenced_Object
(E2
);
22478 return Is_Entity_Name
(R1
)
22479 and then Is_Entity_Name
(R2
)
22480 and then Entity
(R1
) /= Entity
(R2
)
22481 and then not Is_Formal
(Entity
(R1
))
22482 and then not Is_Formal
(Entity
(R2
));
22483 end Statically_Different
;
22485 --------------------------------------
22486 -- Subject_To_Loop_Entry_Attributes --
22487 --------------------------------------
22489 function Subject_To_Loop_Entry_Attributes
(N
: Node_Id
) return Boolean is
22495 -- The expansion mechanism transform a loop subject to at least one
22496 -- 'Loop_Entry attribute into a conditional block. Infinite loops lack
22497 -- the conditional part.
22499 if Nkind_In
(Stmt
, N_Block_Statement
, N_If_Statement
)
22500 and then Nkind
(Original_Node
(N
)) = N_Loop_Statement
22502 Stmt
:= Original_Node
(N
);
22506 Nkind
(Stmt
) = N_Loop_Statement
22507 and then Present
(Identifier
(Stmt
))
22508 and then Present
(Entity
(Identifier
(Stmt
)))
22509 and then Has_Loop_Entry_Attributes
(Entity
(Identifier
(Stmt
)));
22510 end Subject_To_Loop_Entry_Attributes
;
22512 -----------------------------
22513 -- Subprogram_Access_Level --
22514 -----------------------------
22516 function Subprogram_Access_Level
(Subp
: Entity_Id
) return Uint
is
22518 if Present
(Alias
(Subp
)) then
22519 return Subprogram_Access_Level
(Alias
(Subp
));
22521 return Scope_Depth
(Enclosing_Dynamic_Scope
(Subp
));
22523 end Subprogram_Access_Level
;
22525 ---------------------
22526 -- Subprogram_Name --
22527 ---------------------
22529 function Subprogram_Name
(N
: Node_Id
) return String is
22530 Buf
: Bounded_String
;
22531 Ent
: Node_Id
:= N
;
22534 while Present
(Ent
) loop
22535 case Nkind
(Ent
) is
22536 when N_Subprogram_Body
=>
22537 Ent
:= Defining_Unit_Name
(Specification
(Ent
));
22540 when N_Package_Body
22541 | N_Package_Specification
22542 | N_Subprogram_Specification
22544 Ent
:= Defining_Unit_Name
(Ent
);
22547 when N_Protected_Body
22548 | N_Protected_Type_Declaration
22557 Ent
:= Parent
(Ent
);
22561 return "unknown subprogram";
22564 Append_Entity_Name
(Buf
, Ent
);
22566 end Subprogram_Name
;
22568 -------------------------------
22569 -- Support_Atomic_Primitives --
22570 -------------------------------
22572 function Support_Atomic_Primitives
(Typ
: Entity_Id
) return Boolean is
22576 -- Verify the alignment of Typ is known
22578 if not Known_Alignment
(Typ
) then
22582 if Known_Static_Esize
(Typ
) then
22583 Size
:= UI_To_Int
(Esize
(Typ
));
22585 -- If the Esize (Object_Size) is unknown at compile time, look at the
22586 -- RM_Size (Value_Size) which may have been set by an explicit rep item.
22588 elsif Known_Static_RM_Size
(Typ
) then
22589 Size
:= UI_To_Int
(RM_Size
(Typ
));
22591 -- Otherwise, the size is considered to be unknown.
22597 -- Check that the size of the component is 8, 16, 32, or 64 bits and
22598 -- that Typ is properly aligned.
22601 when 8 |
16 |
32 |
64 =>
22602 return Size
= UI_To_Int
(Alignment
(Typ
)) * 8;
22607 end Support_Atomic_Primitives
;
22613 procedure Trace_Scope
(N
: Node_Id
; E
: Entity_Id
; Msg
: String) is
22615 if Debug_Flag_W
then
22616 for J
in 0 .. Scope_Stack
.Last
loop
22621 Write_Name
(Chars
(E
));
22622 Write_Str
(" from ");
22623 Write_Location
(Sloc
(N
));
22628 -----------------------
22629 -- Transfer_Entities --
22630 -----------------------
22632 procedure Transfer_Entities
(From
: Entity_Id
; To
: Entity_Id
) is
22633 procedure Set_Public_Status_Of
(Id
: Entity_Id
);
22634 -- Set the Is_Public attribute of arbitrary entity Id by calling routine
22635 -- Set_Public_Status. If successful and Id denotes a record type, set
22636 -- the Is_Public attribute of its fields.
22638 --------------------------
22639 -- Set_Public_Status_Of --
22640 --------------------------
22642 procedure Set_Public_Status_Of
(Id
: Entity_Id
) is
22646 if not Is_Public
(Id
) then
22647 Set_Public_Status
(Id
);
22649 -- When the input entity is a public record type, ensure that all
22650 -- its internal fields are also exposed to the linker. The fields
22651 -- of a class-wide type are never made public.
22654 and then Is_Record_Type
(Id
)
22655 and then not Is_Class_Wide_Type
(Id
)
22657 Field
:= First_Entity
(Id
);
22658 while Present
(Field
) loop
22659 Set_Is_Public
(Field
);
22660 Next_Entity
(Field
);
22664 end Set_Public_Status_Of
;
22668 Full_Id
: Entity_Id
;
22671 -- Start of processing for Transfer_Entities
22674 Id
:= First_Entity
(From
);
22676 if Present
(Id
) then
22678 -- Merge the entity chain of the source scope with that of the
22679 -- destination scope.
22681 if Present
(Last_Entity
(To
)) then
22682 Set_Next_Entity
(Last_Entity
(To
), Id
);
22684 Set_First_Entity
(To
, Id
);
22687 Set_Last_Entity
(To
, Last_Entity
(From
));
22689 -- Inspect the entities of the source scope and update their Scope
22692 while Present
(Id
) loop
22693 Set_Scope
(Id
, To
);
22694 Set_Public_Status_Of
(Id
);
22696 -- Handle an internally generated full view for a private type
22698 if Is_Private_Type
(Id
)
22699 and then Present
(Full_View
(Id
))
22700 and then Is_Itype
(Full_View
(Id
))
22702 Full_Id
:= Full_View
(Id
);
22704 Set_Scope
(Full_Id
, To
);
22705 Set_Public_Status_Of
(Full_Id
);
22711 Set_First_Entity
(From
, Empty
);
22712 Set_Last_Entity
(From
, Empty
);
22714 end Transfer_Entities
;
22716 -----------------------
22717 -- Type_Access_Level --
22718 -----------------------
22720 function Type_Access_Level
(Typ
: Entity_Id
) return Uint
is
22724 Btyp
:= Base_Type
(Typ
);
22726 -- Ada 2005 (AI-230): For most cases of anonymous access types, we
22727 -- simply use the level where the type is declared. This is true for
22728 -- stand-alone object declarations, and for anonymous access types
22729 -- associated with components the level is the same as that of the
22730 -- enclosing composite type. However, special treatment is needed for
22731 -- the cases of access parameters, return objects of an anonymous access
22732 -- type, and, in Ada 95, access discriminants of limited types.
22734 if Is_Access_Type
(Btyp
) then
22735 if Ekind
(Btyp
) = E_Anonymous_Access_Type
then
22737 -- If the type is a nonlocal anonymous access type (such as for
22738 -- an access parameter) we treat it as being declared at the
22739 -- library level to ensure that names such as X.all'access don't
22740 -- fail static accessibility checks.
22742 if not Is_Local_Anonymous_Access
(Typ
) then
22743 return Scope_Depth
(Standard_Standard
);
22745 -- If this is a return object, the accessibility level is that of
22746 -- the result subtype of the enclosing function. The test here is
22747 -- little complicated, because we have to account for extended
22748 -- return statements that have been rewritten as blocks, in which
22749 -- case we have to find and the Is_Return_Object attribute of the
22750 -- itype's associated object. It would be nice to find a way to
22751 -- simplify this test, but it doesn't seem worthwhile to add a new
22752 -- flag just for purposes of this test. ???
22754 elsif Ekind
(Scope
(Btyp
)) = E_Return_Statement
22757 and then Nkind
(Associated_Node_For_Itype
(Btyp
)) =
22758 N_Object_Declaration
22759 and then Is_Return_Object
22760 (Defining_Identifier
22761 (Associated_Node_For_Itype
(Btyp
))))
22767 Scop
:= Scope
(Scope
(Btyp
));
22768 while Present
(Scop
) loop
22769 exit when Ekind
(Scop
) = E_Function
;
22770 Scop
:= Scope
(Scop
);
22773 -- Treat the return object's type as having the level of the
22774 -- function's result subtype (as per RM05-6.5(5.3/2)).
22776 return Type_Access_Level
(Etype
(Scop
));
22781 Btyp
:= Root_Type
(Btyp
);
22783 -- The accessibility level of anonymous access types associated with
22784 -- discriminants is that of the current instance of the type, and
22785 -- that's deeper than the type itself (AARM 3.10.2 (12.3.21)).
22787 -- AI-402: access discriminants have accessibility based on the
22788 -- object rather than the type in Ada 2005, so the above paragraph
22791 -- ??? Needs completion with rules from AI-416
22793 if Ada_Version
<= Ada_95
22794 and then Ekind
(Typ
) = E_Anonymous_Access_Type
22795 and then Present
(Associated_Node_For_Itype
(Typ
))
22796 and then Nkind
(Associated_Node_For_Itype
(Typ
)) =
22797 N_Discriminant_Specification
22799 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
)) + 1;
22803 -- Return library level for a generic formal type. This is done because
22804 -- RM(10.3.2) says that "The statically deeper relationship does not
22805 -- apply to ... a descendant of a generic formal type". Rather than
22806 -- checking at each point where a static accessibility check is
22807 -- performed to see if we are dealing with a formal type, this rule is
22808 -- implemented by having Type_Access_Level and Deepest_Type_Access_Level
22809 -- return extreme values for a formal type; Deepest_Type_Access_Level
22810 -- returns Int'Last. By calling the appropriate function from among the
22811 -- two, we ensure that the static accessibility check will pass if we
22812 -- happen to run into a formal type. More specifically, we should call
22813 -- Deepest_Type_Access_Level instead of Type_Access_Level whenever the
22814 -- call occurs as part of a static accessibility check and the error
22815 -- case is the case where the type's level is too shallow (as opposed
22818 if Is_Generic_Type
(Root_Type
(Btyp
)) then
22819 return Scope_Depth
(Standard_Standard
);
22822 return Scope_Depth
(Enclosing_Dynamic_Scope
(Btyp
));
22823 end Type_Access_Level
;
22825 ------------------------------------
22826 -- Type_Without_Stream_Operation --
22827 ------------------------------------
22829 function Type_Without_Stream_Operation
22831 Op
: TSS_Name_Type
:= TSS_Null
) return Entity_Id
22833 BT
: constant Entity_Id
:= Base_Type
(T
);
22834 Op_Missing
: Boolean;
22837 if not Restriction_Active
(No_Default_Stream_Attributes
) then
22841 if Is_Elementary_Type
(T
) then
22842 if Op
= TSS_Null
then
22844 No
(TSS
(BT
, TSS_Stream_Read
))
22845 or else No
(TSS
(BT
, TSS_Stream_Write
));
22848 Op_Missing
:= No
(TSS
(BT
, Op
));
22857 elsif Is_Array_Type
(T
) then
22858 return Type_Without_Stream_Operation
(Component_Type
(T
), Op
);
22860 elsif Is_Record_Type
(T
) then
22866 Comp
:= First_Component
(T
);
22867 while Present
(Comp
) loop
22868 C_Typ
:= Type_Without_Stream_Operation
(Etype
(Comp
), Op
);
22870 if Present
(C_Typ
) then
22874 Next_Component
(Comp
);
22880 elsif Is_Private_Type
(T
) and then Present
(Full_View
(T
)) then
22881 return Type_Without_Stream_Operation
(Full_View
(T
), Op
);
22885 end Type_Without_Stream_Operation
;
22887 ----------------------------
22888 -- Unique_Defining_Entity --
22889 ----------------------------
22891 function Unique_Defining_Entity
(N
: Node_Id
) return Entity_Id
is
22893 return Unique_Entity
(Defining_Entity
(N
));
22894 end Unique_Defining_Entity
;
22896 -------------------
22897 -- Unique_Entity --
22898 -------------------
22900 function Unique_Entity
(E
: Entity_Id
) return Entity_Id
is
22901 U
: Entity_Id
:= E
;
22907 if Present
(Full_View
(E
)) then
22908 U
:= Full_View
(E
);
22912 if Nkind
(Parent
(E
)) = N_Entry_Body
then
22914 Prot_Item
: Entity_Id
;
22915 Prot_Type
: Entity_Id
;
22918 if Ekind
(E
) = E_Entry
then
22919 Prot_Type
:= Scope
(E
);
22921 -- Bodies of entry families are nested within an extra scope
22922 -- that contains an entry index declaration.
22925 Prot_Type
:= Scope
(Scope
(E
));
22928 -- A protected type may be declared as a private type, in
22929 -- which case we need to get its full view.
22931 if Is_Private_Type
(Prot_Type
) then
22932 Prot_Type
:= Full_View
(Prot_Type
);
22935 -- Full view may not be present on error, in which case
22936 -- return E by default.
22938 if Present
(Prot_Type
) then
22939 pragma Assert
(Ekind
(Prot_Type
) = E_Protected_Type
);
22941 -- Traverse the entity list of the protected type and
22942 -- locate an entry declaration which matches the entry
22945 Prot_Item
:= First_Entity
(Prot_Type
);
22946 while Present
(Prot_Item
) loop
22947 if Ekind
(Prot_Item
) in Entry_Kind
22948 and then Corresponding_Body
(Parent
(Prot_Item
)) = E
22954 Next_Entity
(Prot_Item
);
22960 when Formal_Kind
=>
22961 if Present
(Spec_Entity
(E
)) then
22962 U
:= Spec_Entity
(E
);
22965 when E_Package_Body
=>
22968 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
22972 if Nkind
(P
) = N_Package_Body
22973 and then Present
(Corresponding_Spec
(P
))
22975 U
:= Corresponding_Spec
(P
);
22977 elsif Nkind
(P
) = N_Package_Body_Stub
22978 and then Present
(Corresponding_Spec_Of_Stub
(P
))
22980 U
:= Corresponding_Spec_Of_Stub
(P
);
22983 when E_Protected_Body
=>
22986 if Nkind
(P
) = N_Protected_Body
22987 and then Present
(Corresponding_Spec
(P
))
22989 U
:= Corresponding_Spec
(P
);
22991 elsif Nkind
(P
) = N_Protected_Body_Stub
22992 and then Present
(Corresponding_Spec_Of_Stub
(P
))
22994 U
:= Corresponding_Spec_Of_Stub
(P
);
22996 if Is_Single_Protected_Object
(U
) then
23001 if Is_Private_Type
(U
) then
23002 U
:= Full_View
(U
);
23005 when E_Subprogram_Body
=>
23008 if Nkind
(P
) = N_Defining_Program_Unit_Name
then
23014 if Nkind
(P
) = N_Subprogram_Body
23015 and then Present
(Corresponding_Spec
(P
))
23017 U
:= Corresponding_Spec
(P
);
23019 elsif Nkind
(P
) = N_Subprogram_Body_Stub
23020 and then Present
(Corresponding_Spec_Of_Stub
(P
))
23022 U
:= Corresponding_Spec_Of_Stub
(P
);
23024 elsif Nkind
(P
) = N_Subprogram_Renaming_Declaration
then
23025 U
:= Corresponding_Spec
(P
);
23028 when E_Task_Body
=>
23031 if Nkind
(P
) = N_Task_Body
23032 and then Present
(Corresponding_Spec
(P
))
23034 U
:= Corresponding_Spec
(P
);
23036 elsif Nkind
(P
) = N_Task_Body_Stub
23037 and then Present
(Corresponding_Spec_Of_Stub
(P
))
23039 U
:= Corresponding_Spec_Of_Stub
(P
);
23041 if Is_Single_Task_Object
(U
) then
23046 if Is_Private_Type
(U
) then
23047 U
:= Full_View
(U
);
23051 if Present
(Full_View
(E
)) then
23052 U
:= Full_View
(E
);
23066 function Unique_Name
(E
: Entity_Id
) return String is
23068 -- Names in E_Subprogram_Body or E_Package_Body entities are not
23069 -- reliable, as they may not include the overloading suffix. Instead,
23070 -- when looking for the name of E or one of its enclosing scope, we get
23071 -- the name of the corresponding Unique_Entity.
23073 U
: constant Entity_Id
:= Unique_Entity
(E
);
23075 function This_Name
return String;
23081 function This_Name
return String is
23083 return Get_Name_String
(Chars
(U
));
23086 -- Start of processing for Unique_Name
23089 if E
= Standard_Standard
23090 or else Has_Fully_Qualified_Name
(E
)
23094 elsif Ekind
(E
) = E_Enumeration_Literal
then
23095 return Unique_Name
(Etype
(E
)) & "__" & This_Name
;
23099 S
: constant Entity_Id
:= Scope
(U
);
23100 pragma Assert
(Present
(S
));
23103 -- Prefix names of predefined types with standard__, but leave
23104 -- names of user-defined packages and subprograms without prefix
23105 -- (even if technically they are nested in the Standard package).
23107 if S
= Standard_Standard
then
23108 if Ekind
(U
) = E_Package
or else Is_Subprogram
(U
) then
23111 return Unique_Name
(S
) & "__" & This_Name
;
23114 -- For intances of generic subprograms use the name of the related
23115 -- instace and skip the scope of its wrapper package.
23117 elsif Is_Wrapper_Package
(S
) then
23118 pragma Assert
(Scope
(S
) = Scope
(Related_Instance
(S
)));
23119 -- Wrapper package and the instantiation are in the same scope
23122 Enclosing_Name
: constant String :=
23123 Unique_Name
(Scope
(S
)) & "__" &
23124 Get_Name_String
(Chars
(Related_Instance
(S
)));
23127 if Is_Subprogram
(U
)
23128 and then not Is_Generic_Actual_Subprogram
(U
)
23130 return Enclosing_Name
;
23132 return Enclosing_Name
& "__" & This_Name
;
23137 return Unique_Name
(S
) & "__" & This_Name
;
23143 ---------------------
23144 -- Unit_Is_Visible --
23145 ---------------------
23147 function Unit_Is_Visible
(U
: Entity_Id
) return Boolean is
23148 Curr
: constant Node_Id
:= Cunit
(Current_Sem_Unit
);
23149 Curr_Entity
: constant Entity_Id
:= Cunit_Entity
(Current_Sem_Unit
);
23151 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean;
23152 -- For a child unit, check whether unit appears in a with_clause
23155 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean;
23156 -- Scan the context clause of one compilation unit looking for a
23157 -- with_clause for the unit in question.
23159 ----------------------------
23160 -- Unit_In_Parent_Context --
23161 ----------------------------
23163 function Unit_In_Parent_Context
(Par_Unit
: Node_Id
) return Boolean is
23165 if Unit_In_Context
(Par_Unit
) then
23168 elsif Is_Child_Unit
(Defining_Entity
(Unit
(Par_Unit
))) then
23169 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Par_Unit
)));
23174 end Unit_In_Parent_Context
;
23176 ---------------------
23177 -- Unit_In_Context --
23178 ---------------------
23180 function Unit_In_Context
(Comp_Unit
: Node_Id
) return Boolean is
23184 Clause
:= First
(Context_Items
(Comp_Unit
));
23185 while Present
(Clause
) loop
23186 if Nkind
(Clause
) = N_With_Clause
then
23187 if Library_Unit
(Clause
) = U
then
23190 -- The with_clause may denote a renaming of the unit we are
23191 -- looking for, eg. Text_IO which renames Ada.Text_IO.
23194 Renamed_Entity
(Entity
(Name
(Clause
))) =
23195 Defining_Entity
(Unit
(U
))
23205 end Unit_In_Context
;
23207 -- Start of processing for Unit_Is_Visible
23210 -- The currrent unit is directly visible
23215 elsif Unit_In_Context
(Curr
) then
23218 -- If the current unit is a body, check the context of the spec
23220 elsif Nkind
(Unit
(Curr
)) = N_Package_Body
23222 (Nkind
(Unit
(Curr
)) = N_Subprogram_Body
23223 and then not Acts_As_Spec
(Unit
(Curr
)))
23225 if Unit_In_Context
(Library_Unit
(Curr
)) then
23230 -- If the spec is a child unit, examine the parents
23232 if Is_Child_Unit
(Curr_Entity
) then
23233 if Nkind
(Unit
(Curr
)) in N_Unit_Body
then
23235 Unit_In_Parent_Context
23236 (Parent_Spec
(Unit
(Library_Unit
(Curr
))));
23238 return Unit_In_Parent_Context
(Parent_Spec
(Unit
(Curr
)));
23244 end Unit_Is_Visible
;
23246 ------------------------------
23247 -- Universal_Interpretation --
23248 ------------------------------
23250 function Universal_Interpretation
(Opnd
: Node_Id
) return Entity_Id
is
23251 Index
: Interp_Index
;
23255 -- The argument may be a formal parameter of an operator or subprogram
23256 -- with multiple interpretations, or else an expression for an actual.
23258 if Nkind
(Opnd
) = N_Defining_Identifier
23259 or else not Is_Overloaded
(Opnd
)
23261 if Etype
(Opnd
) = Universal_Integer
23262 or else Etype
(Opnd
) = Universal_Real
23264 return Etype
(Opnd
);
23270 Get_First_Interp
(Opnd
, Index
, It
);
23271 while Present
(It
.Typ
) loop
23272 if It
.Typ
= Universal_Integer
23273 or else It
.Typ
= Universal_Real
23278 Get_Next_Interp
(Index
, It
);
23283 end Universal_Interpretation
;
23289 function Unqualify
(Expr
: Node_Id
) return Node_Id
is
23291 -- Recurse to handle unlikely case of multiple levels of qualification
23293 if Nkind
(Expr
) = N_Qualified_Expression
then
23294 return Unqualify
(Expression
(Expr
));
23296 -- Normal case, not a qualified expression
23307 function Unqual_Conv
(Expr
: Node_Id
) return Node_Id
is
23309 -- Recurse to handle unlikely case of multiple levels of qualification
23310 -- and/or conversion.
23312 if Nkind_In
(Expr
, N_Qualified_Expression
,
23314 N_Unchecked_Type_Conversion
)
23316 return Unqual_Conv
(Expression
(Expr
));
23318 -- Normal case, not a qualified expression
23325 -----------------------
23326 -- Visible_Ancestors --
23327 -----------------------
23329 function Visible_Ancestors
(Typ
: Entity_Id
) return Elist_Id
is
23335 pragma Assert
(Is_Record_Type
(Typ
) and then Is_Tagged_Type
(Typ
));
23337 -- Collect all the parents and progenitors of Typ. If the full-view of
23338 -- private parents and progenitors is available then it is used to
23339 -- generate the list of visible ancestors; otherwise their partial
23340 -- view is added to the resulting list.
23345 Use_Full_View
=> True);
23349 Ifaces_List
=> List_2
,
23350 Exclude_Parents
=> True,
23351 Use_Full_View
=> True);
23353 -- Join the two lists. Avoid duplications because an interface may
23354 -- simultaneously be parent and progenitor of a type.
23356 Elmt
:= First_Elmt
(List_2
);
23357 while Present
(Elmt
) loop
23358 Append_Unique_Elmt
(Node
(Elmt
), List_1
);
23363 end Visible_Ancestors
;
23365 ----------------------
23366 -- Within_Init_Proc --
23367 ----------------------
23369 function Within_Init_Proc
return Boolean is
23373 S
:= Current_Scope
;
23374 while not Is_Overloadable
(S
) loop
23375 if S
= Standard_Standard
then
23382 return Is_Init_Proc
(S
);
23383 end Within_Init_Proc
;
23385 ---------------------------
23386 -- Within_Protected_Type --
23387 ---------------------------
23389 function Within_Protected_Type
(E
: Entity_Id
) return Boolean is
23390 Scop
: Entity_Id
:= Scope
(E
);
23393 while Present
(Scop
) loop
23394 if Ekind
(Scop
) = E_Protected_Type
then
23398 Scop
:= Scope
(Scop
);
23402 end Within_Protected_Type
;
23408 function Within_Scope
(E
: Entity_Id
; S
: Entity_Id
) return Boolean is
23410 return Scope_Within_Or_Same
(Scope
(E
), S
);
23417 procedure Wrong_Type
(Expr
: Node_Id
; Expected_Type
: Entity_Id
) is
23418 Found_Type
: constant Entity_Id
:= First_Subtype
(Etype
(Expr
));
23419 Expec_Type
: constant Entity_Id
:= First_Subtype
(Expected_Type
);
23421 Matching_Field
: Entity_Id
;
23422 -- Entity to give a more precise suggestion on how to write a one-
23423 -- element positional aggregate.
23425 function Has_One_Matching_Field
return Boolean;
23426 -- Determines if Expec_Type is a record type with a single component or
23427 -- discriminant whose type matches the found type or is one dimensional
23428 -- array whose component type matches the found type. In the case of
23429 -- one discriminant, we ignore the variant parts. That's not accurate,
23430 -- but good enough for the warning.
23432 ----------------------------
23433 -- Has_One_Matching_Field --
23434 ----------------------------
23436 function Has_One_Matching_Field
return Boolean is
23440 Matching_Field
:= Empty
;
23442 if Is_Array_Type
(Expec_Type
)
23443 and then Number_Dimensions
(Expec_Type
) = 1
23444 and then Covers
(Etype
(Component_Type
(Expec_Type
)), Found_Type
)
23446 -- Use type name if available. This excludes multidimensional
23447 -- arrays and anonymous arrays.
23449 if Comes_From_Source
(Expec_Type
) then
23450 Matching_Field
:= Expec_Type
;
23452 -- For an assignment, use name of target
23454 elsif Nkind
(Parent
(Expr
)) = N_Assignment_Statement
23455 and then Is_Entity_Name
(Name
(Parent
(Expr
)))
23457 Matching_Field
:= Entity
(Name
(Parent
(Expr
)));
23462 elsif not Is_Record_Type
(Expec_Type
) then
23466 E
:= First_Entity
(Expec_Type
);
23471 elsif not Ekind_In
(E
, E_Discriminant
, E_Component
)
23472 or else Nam_In
(Chars
(E
), Name_uTag
, Name_uParent
)
23481 if not Covers
(Etype
(E
), Found_Type
) then
23484 elsif Present
(Next_Entity
(E
))
23485 and then (Ekind
(E
) = E_Component
23486 or else Ekind
(Next_Entity
(E
)) = E_Discriminant
)
23491 Matching_Field
:= E
;
23495 end Has_One_Matching_Field
;
23497 -- Start of processing for Wrong_Type
23500 -- Don't output message if either type is Any_Type, or if a message
23501 -- has already been posted for this node. We need to do the latter
23502 -- check explicitly (it is ordinarily done in Errout), because we
23503 -- are using ! to force the output of the error messages.
23505 if Expec_Type
= Any_Type
23506 or else Found_Type
= Any_Type
23507 or else Error_Posted
(Expr
)
23511 -- If one of the types is a Taft-Amendment type and the other it its
23512 -- completion, it must be an illegal use of a TAT in the spec, for
23513 -- which an error was already emitted. Avoid cascaded errors.
23515 elsif Is_Incomplete_Type
(Expec_Type
)
23516 and then Has_Completion_In_Body
(Expec_Type
)
23517 and then Full_View
(Expec_Type
) = Etype
(Expr
)
23521 elsif Is_Incomplete_Type
(Etype
(Expr
))
23522 and then Has_Completion_In_Body
(Etype
(Expr
))
23523 and then Full_View
(Etype
(Expr
)) = Expec_Type
23527 -- In an instance, there is an ongoing problem with completion of
23528 -- type derived from private types. Their structure is what Gigi
23529 -- expects, but the Etype is the parent type rather than the
23530 -- derived private type itself. Do not flag error in this case. The
23531 -- private completion is an entity without a parent, like an Itype.
23532 -- Similarly, full and partial views may be incorrect in the instance.
23533 -- There is no simple way to insure that it is consistent ???
23535 -- A similar view discrepancy can happen in an inlined body, for the
23536 -- same reason: inserted body may be outside of the original package
23537 -- and only partial views are visible at the point of insertion.
23539 elsif In_Instance
or else In_Inlined_Body
then
23540 if Etype
(Etype
(Expr
)) = Etype
(Expected_Type
)
23542 (Has_Private_Declaration
(Expected_Type
)
23543 or else Has_Private_Declaration
(Etype
(Expr
)))
23544 and then No
(Parent
(Expected_Type
))
23548 elsif Nkind
(Parent
(Expr
)) = N_Qualified_Expression
23549 and then Entity
(Subtype_Mark
(Parent
(Expr
))) = Expected_Type
23553 elsif Is_Private_Type
(Expected_Type
)
23554 and then Present
(Full_View
(Expected_Type
))
23555 and then Covers
(Full_View
(Expected_Type
), Etype
(Expr
))
23559 -- Conversely, type of expression may be the private one
23561 elsif Is_Private_Type
(Base_Type
(Etype
(Expr
)))
23562 and then Full_View
(Base_Type
(Etype
(Expr
))) = Expected_Type
23568 -- An interesting special check. If the expression is parenthesized
23569 -- and its type corresponds to the type of the sole component of the
23570 -- expected record type, or to the component type of the expected one
23571 -- dimensional array type, then assume we have a bad aggregate attempt.
23573 if Nkind
(Expr
) in N_Subexpr
23574 and then Paren_Count
(Expr
) /= 0
23575 and then Has_One_Matching_Field
23577 Error_Msg_N
("positional aggregate cannot have one component", Expr
);
23579 if Present
(Matching_Field
) then
23580 if Is_Array_Type
(Expec_Type
) then
23582 ("\write instead `&''First ='> ...`", Expr
, Matching_Field
);
23585 ("\write instead `& ='> ...`", Expr
, Matching_Field
);
23589 -- Another special check, if we are looking for a pool-specific access
23590 -- type and we found an E_Access_Attribute_Type, then we have the case
23591 -- of an Access attribute being used in a context which needs a pool-
23592 -- specific type, which is never allowed. The one extra check we make
23593 -- is that the expected designated type covers the Found_Type.
23595 elsif Is_Access_Type
(Expec_Type
)
23596 and then Ekind
(Found_Type
) = E_Access_Attribute_Type
23597 and then Ekind
(Base_Type
(Expec_Type
)) /= E_General_Access_Type
23598 and then Ekind
(Base_Type
(Expec_Type
)) /= E_Anonymous_Access_Type
23600 (Designated_Type
(Expec_Type
), Designated_Type
(Found_Type
))
23602 Error_Msg_N
-- CODEFIX
23603 ("result must be general access type!", Expr
);
23604 Error_Msg_NE
-- CODEFIX
23605 ("add ALL to }!", Expr
, Expec_Type
);
23607 -- Another special check, if the expected type is an integer type,
23608 -- but the expression is of type System.Address, and the parent is
23609 -- an addition or subtraction operation whose left operand is the
23610 -- expression in question and whose right operand is of an integral
23611 -- type, then this is an attempt at address arithmetic, so give
23612 -- appropriate message.
23614 elsif Is_Integer_Type
(Expec_Type
)
23615 and then Is_RTE
(Found_Type
, RE_Address
)
23616 and then Nkind_In
(Parent
(Expr
), N_Op_Add
, N_Op_Subtract
)
23617 and then Expr
= Left_Opnd
(Parent
(Expr
))
23618 and then Is_Integer_Type
(Etype
(Right_Opnd
(Parent
(Expr
))))
23621 ("address arithmetic not predefined in package System",
23624 ("\possible missing with/use of System.Storage_Elements",
23628 -- If the expected type is an anonymous access type, as for access
23629 -- parameters and discriminants, the error is on the designated types.
23631 elsif Ekind
(Expec_Type
) = E_Anonymous_Access_Type
then
23632 if Comes_From_Source
(Expec_Type
) then
23633 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
23636 ("expected an access type with designated}",
23637 Expr
, Designated_Type
(Expec_Type
));
23640 if Is_Access_Type
(Found_Type
)
23641 and then not Comes_From_Source
(Found_Type
)
23644 ("\\found an access type with designated}!",
23645 Expr
, Designated_Type
(Found_Type
));
23647 if From_Limited_With
(Found_Type
) then
23648 Error_Msg_NE
("\\found incomplete}!", Expr
, Found_Type
);
23649 Error_Msg_Qual_Level
:= 99;
23650 Error_Msg_NE
-- CODEFIX
23651 ("\\missing `WITH &;", Expr
, Scope
(Found_Type
));
23652 Error_Msg_Qual_Level
:= 0;
23654 Error_Msg_NE
("found}!", Expr
, Found_Type
);
23658 -- Normal case of one type found, some other type expected
23661 -- If the names of the two types are the same, see if some number
23662 -- of levels of qualification will help. Don't try more than three
23663 -- levels, and if we get to standard, it's no use (and probably
23664 -- represents an error in the compiler) Also do not bother with
23665 -- internal scope names.
23668 Expec_Scope
: Entity_Id
;
23669 Found_Scope
: Entity_Id
;
23672 Expec_Scope
:= Expec_Type
;
23673 Found_Scope
:= Found_Type
;
23675 for Levels
in Nat
range 0 .. 3 loop
23676 if Chars
(Expec_Scope
) /= Chars
(Found_Scope
) then
23677 Error_Msg_Qual_Level
:= Levels
;
23681 Expec_Scope
:= Scope
(Expec_Scope
);
23682 Found_Scope
:= Scope
(Found_Scope
);
23684 exit when Expec_Scope
= Standard_Standard
23685 or else Found_Scope
= Standard_Standard
23686 or else not Comes_From_Source
(Expec_Scope
)
23687 or else not Comes_From_Source
(Found_Scope
);
23691 if Is_Record_Type
(Expec_Type
)
23692 and then Present
(Corresponding_Remote_Type
(Expec_Type
))
23694 Error_Msg_NE
("expected}!", Expr
,
23695 Corresponding_Remote_Type
(Expec_Type
));
23697 Error_Msg_NE
("expected}!", Expr
, Expec_Type
);
23700 if Is_Entity_Name
(Expr
)
23701 and then Is_Package_Or_Generic_Package
(Entity
(Expr
))
23703 Error_Msg_N
("\\found package name!", Expr
);
23705 elsif Is_Entity_Name
(Expr
)
23706 and then Ekind_In
(Entity
(Expr
), E_Procedure
, E_Generic_Procedure
)
23708 if Ekind
(Expec_Type
) = E_Access_Subprogram_Type
then
23710 ("found procedure name, possibly missing Access attribute!",
23714 ("\\found procedure name instead of function!", Expr
);
23717 elsif Nkind
(Expr
) = N_Function_Call
23718 and then Ekind
(Expec_Type
) = E_Access_Subprogram_Type
23719 and then Etype
(Designated_Type
(Expec_Type
)) = Etype
(Expr
)
23720 and then No
(Parameter_Associations
(Expr
))
23723 ("found function name, possibly missing Access attribute!",
23726 -- Catch common error: a prefix or infix operator which is not
23727 -- directly visible because the type isn't.
23729 elsif Nkind
(Expr
) in N_Op
23730 and then Is_Overloaded
(Expr
)
23731 and then not Is_Immediately_Visible
(Expec_Type
)
23732 and then not Is_Potentially_Use_Visible
(Expec_Type
)
23733 and then not In_Use
(Expec_Type
)
23734 and then Has_Compatible_Type
(Right_Opnd
(Expr
), Expec_Type
)
23737 ("operator of the type is not directly visible!", Expr
);
23739 elsif Ekind
(Found_Type
) = E_Void
23740 and then Present
(Parent
(Found_Type
))
23741 and then Nkind
(Parent
(Found_Type
)) = N_Full_Type_Declaration
23743 Error_Msg_NE
("\\found premature usage of}!", Expr
, Found_Type
);
23746 Error_Msg_NE
("\\found}!", Expr
, Found_Type
);
23749 -- A special check for cases like M1 and M2 = 0 where M1 and M2 are
23750 -- of the same modular type, and (M1 and M2) = 0 was intended.
23752 if Expec_Type
= Standard_Boolean
23753 and then Is_Modular_Integer_Type
(Found_Type
)
23754 and then Nkind_In
(Parent
(Expr
), N_Op_And
, N_Op_Or
, N_Op_Xor
)
23755 and then Nkind
(Right_Opnd
(Parent
(Expr
))) in N_Op_Compare
23758 Op
: constant Node_Id
:= Right_Opnd
(Parent
(Expr
));
23759 L
: constant Node_Id
:= Left_Opnd
(Op
);
23760 R
: constant Node_Id
:= Right_Opnd
(Op
);
23763 -- The case for the message is when the left operand of the
23764 -- comparison is the same modular type, or when it is an
23765 -- integer literal (or other universal integer expression),
23766 -- which would have been typed as the modular type if the
23767 -- parens had been there.
23769 if (Etype
(L
) = Found_Type
23771 Etype
(L
) = Universal_Integer
)
23772 and then Is_Integer_Type
(Etype
(R
))
23775 ("\\possible missing parens for modular operation", Expr
);
23780 -- Reset error message qualification indication
23782 Error_Msg_Qual_Level
:= 0;
23786 --------------------------------
23787 -- Yields_Synchronized_Object --
23788 --------------------------------
23790 function Yields_Synchronized_Object
(Typ
: Entity_Id
) return Boolean is
23791 Has_Sync_Comp
: Boolean := False;
23795 -- An array type yields a synchronized object if its component type
23796 -- yields a synchronized object.
23798 if Is_Array_Type
(Typ
) then
23799 return Yields_Synchronized_Object
(Component_Type
(Typ
));
23801 -- A descendant of type Ada.Synchronous_Task_Control.Suspension_Object
23802 -- yields a synchronized object by default.
23804 elsif Is_Descendant_Of_Suspension_Object
(Typ
) then
23807 -- A protected type yields a synchronized object by default
23809 elsif Is_Protected_Type
(Typ
) then
23812 -- A record type or type extension yields a synchronized object when its
23813 -- discriminants (if any) lack default values and all components are of
23814 -- a type that yelds a synchronized object.
23816 elsif Is_Record_Type
(Typ
) then
23818 -- Inspect all entities defined in the scope of the type, looking for
23819 -- components of a type that does not yeld a synchronized object or
23820 -- for discriminants with default values.
23822 Id
:= First_Entity
(Typ
);
23823 while Present
(Id
) loop
23824 if Comes_From_Source
(Id
) then
23825 if Ekind
(Id
) = E_Component
then
23826 if Yields_Synchronized_Object
(Etype
(Id
)) then
23827 Has_Sync_Comp
:= True;
23829 -- The component does not yield a synchronized object
23835 elsif Ekind
(Id
) = E_Discriminant
23836 and then Present
(Expression
(Parent
(Id
)))
23845 -- Ensure that the parent type of a type extension yields a
23846 -- synchronized object.
23848 if Etype
(Typ
) /= Typ
23849 and then not Yields_Synchronized_Object
(Etype
(Typ
))
23854 -- If we get here, then all discriminants lack default values and all
23855 -- components are of a type that yields a synchronized object.
23857 return Has_Sync_Comp
;
23859 -- A synchronized interface type yields a synchronized object by default
23861 elsif Is_Synchronized_Interface
(Typ
) then
23864 -- A task type yelds a synchronized object by default
23866 elsif Is_Task_Type
(Typ
) then
23869 -- Otherwise the type does not yield a synchronized object
23874 end Yields_Synchronized_Object
;
23876 ---------------------------
23877 -- Yields_Universal_Type --
23878 ---------------------------
23880 function Yields_Universal_Type
(N
: Node_Id
) return Boolean is
23882 -- Integer and real literals are of a universal type
23884 if Nkind_In
(N
, N_Integer_Literal
, N_Real_Literal
) then
23887 -- The values of certain attributes are of a universal type
23889 elsif Nkind
(N
) = N_Attribute_Reference
then
23891 Universal_Type_Attribute
(Get_Attribute_Id
(Attribute_Name
(N
)));
23893 -- ??? There are possibly other cases to consider
23898 end Yields_Universal_Type
;
23901 Erroutc
.Subprogram_Name_Ptr
:= Subprogram_Name
'Access;